diff --git a/src/css/error.css b/src/css/error.css new file mode 100644 index 0000000000000000000000000000000000000000..4717ad4b94f6dfedd27029b8432f7e5a458597a8 --- /dev/null +++ b/src/css/error.css @@ -0,0 +1,3 @@ +h1 { + color: red; +} \ No newline at end of file diff --git a/src/css/style.css b/src/css/style.css index 6592b988928f3e3adb0082290bda5b7562903ed2..6d221f40c5dbfc53357d8384995e700f2ca55023 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -1,7 +1,60 @@ +* { + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif +} + body { - padding: 2em + padding: 3em; + background-color: #f4f4f4; } -* { - font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif -} \ No newline at end of file +form { + margin-bottom: 1em; +} + +.form-group { + margin-top: 0.7em; + margin-bottom: 0.7em; +} + +.form-group label { + margin-right: 1em; +} + +input.form-control { + width: auto; + background: none; + border: none; + padding-bottom: 2px; + border-bottom: solid 1.3px rgba(0, 0, 0, 0.2); + transition: border 0.2s ease-out; + font-family: "Segoe UI"; +} + +input.form-control:focus { + outline: none; + border-bottom-color: rgba(1, 40, 148, 0.842); +} + +button.form-control { + display: block; + color: white; + width: 80px; + height: 30px; + background-color: rgba(0, 2, 138, 0.767); + border: solid 1px rgba(117, 117, 117, 0.226); + border-radius: 4px; +} + +.form-group button { + margin-top: 0; + margin-left: 0.6em +} + +button.form-control:hover { + background-color: rgba(37, 0, 138, 0.87); +} + +button.form-control:active { + box-shadow: inset 0 8px 6px -6px black; + transition: background-color; +} diff --git a/src/index.js b/src/index.js index 9bf29f3623c7206320a7da09f39200de6df300cd..7e96a3e7db96a0f30d3a057e9903e7c6018563ba 100644 --- a/src/index.js +++ b/src/index.js @@ -3,6 +3,7 @@ import colors from 'colors'; import { graphqlExpress, graphiqlExpress } from 'graphql-server-express'; import makeExecutableSchema from 'graphql-tools'; import knex from '../db/knex_router'; +import path from 'path'; /** * @function Home @@ -10,7 +11,14 @@ import knex from '../db/knex_router'; */ server.get('/', function(req, res) { console.log('Connecting to '+req.url); - res.render('home'); + res.render('home', {title: 'Home', port: port}); +}); + +server.get('/db?', function(req, res) { + let table_name = req.query.table; + let columns = req.query.columns; + + res.redirect(`db/${table_name}?columns=${columns}`); }); /** @@ -34,8 +42,11 @@ server.get('/db/:table_name?', function(req, res) { res.write(JSON.stringify(table,null,2)); res.end(); },function() { - res.status(404); - res.write(`Error: Relation ${req.params.table_name} does not exist`); + res.status(400); + res.render('error', { + status: res.statusCode, + error_message: "Bad request: can't find table " + req.params.table_name + }); res.end(); } ); @@ -60,10 +71,11 @@ server.use((err, req, res, next) => { res.locals.message = err.message; res.status(err.status || 500); - res.write(`Error 404 - - Not found.`); - res.end(); + let error_message = res.statusCode == 404 ? 'Not found.' : 'Internal server error.'; + res.render('error', { + status: res.statusCode, + error_message: error_message + }); }); // define port server is to listen on diff --git a/src/views/error.pug b/src/views/error.pug index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..598246c580aaa28d55d856f59d5e3bce60547637 100644 --- a/src/views/error.pug +++ b/src/views/error.pug @@ -0,0 +1,9 @@ +extends layout.pug + +block extraStyles + include ../css/error.css + +block content + h1 Error #{status} + p #{error_message} + a(href="/") Go back \ No newline at end of file diff --git a/src/views/head.pug b/src/views/head.pug deleted file mode 100644 index f9958268117dccfb5634a284a39caedbec4a1718..0000000000000000000000000000000000000000 --- a/src/views/head.pug +++ /dev/null @@ -1,2 +0,0 @@ -style - include ../css/style.css \ No newline at end of file diff --git a/src/views/home.pug b/src/views/home.pug index ca31811b5fe17a644dbb9fc10acb91cd9c1d1f9e..7835d6bbb2fa47bc8639a56d45e0373c45de791b 100644 --- a/src/views/home.pug +++ b/src/views/home.pug @@ -1,9 +1,15 @@ -block title - include head.pug - title Accueil - +extends layout.pug block content - h1 Welcome to API server - p Hello, world ! This is server talking to you live on port 3000 ! - a(href="db/groups") Groups \ No newline at end of file + h1 Welcome to API server + p Hello, world ! This is server talking to you live on port #{port} ! + form(action="/db", method="get") + div.form-group + label(for="table") Table + input.form-control(type="search", name="table") + div.form-group + label(for="columns") Columns + input.form-control(type="search", name="columns") + button.form-control(type="submit") Search + | + a(href="/graphql") Check GraphQL \ No newline at end of file diff --git a/src/views/layout.pug b/src/views/layout.pug index 6e390136253f3258a05752a78f8748f44b479a2a..bfc94ddd789ba757fa4d14356642cf0d63f63c67 100644 --- a/src/views/layout.pug +++ b/src/views/layout.pug @@ -4,6 +4,9 @@ html(lang="en") meta(charset="UTF-8") meta(name="viewport", content="width=device-width, initial-scale=1.0") meta(http-equiv="X-UA-Compatible", content="ie=edge") - block title + style + include ../css/style.css + block extraStyles + title API server - #{title} body block content