From 8be93f6c70beb7dd9dc29c8129ea2d59db8c35b2 Mon Sep 17 00:00:00 2001 From: rr- Date: Wed, 6 Apr 2016 22:34:21 +0200 Subject: [PATCH] client/users: add user view prototype --- client/css/main.css | 7 +++ client/css/users.css | 24 ++++++++++ client/html/home.hbs | 2 +- client/html/user.hbs | 12 +++++ client/html/user_edit.hbs | 3 ++ client/html/user_summary.hbs | 29 ++++++++++++ client/js/controllers/users_controller.js | 47 +++++++++++++++----- client/js/util/handlebars-helpers.js | 14 +++--- client/js/views/user_edit_view.js | 16 +++++++ client/js/views/user_summary_view.js | 17 +++++++ client/js/views/user_view.js | 45 +++++++++++++++++++ config.yaml.dist | 10 +++++ server/szurubooru/api/user_api.py | 14 +++++- server/szurubooru/tests/api/test_user_api.py | 6 +++ 14 files changed, 225 insertions(+), 21 deletions(-) create mode 100644 client/html/user.hbs create mode 100644 client/html/user_edit.hbs create mode 100644 client/html/user_summary.hbs create mode 100644 client/js/views/user_edit_view.js create mode 100644 client/js/views/user_summary_view.js create mode 100644 client/js/views/user_view.js diff --git a/client/css/main.css b/client/css/main.css index 4e00500..db8fcfa 100644 --- a/client/css/main.css +++ b/client/css/main.css @@ -83,6 +83,13 @@ nav ul li img { vertical-align: top; /* fix ghost margin under the image */ } +nav.plain-nav ul li { + display: block; +} +nav.plain-nav ul li a { + display: inline; +} + nav.text-nav { margin: 1em 0; } diff --git a/client/css/users.css b/client/css/users.css index c28f5dc..7abbd7c 100644 --- a/client/css/users.css +++ b/client/css/users.css @@ -36,3 +36,27 @@ #login .buttons a { margin-left: 1em; } + +#user { + width: 30em; +} +#user .text-nav { + margin-bottom: 1.5em; +} +#user-summary img { + width: 6em; + margin: 0 1.5em 1.5em 0; + float: left; +} +#user-summary div { + clear: both; +} +#user-summary .basic-info { + list-style-type: none; + margin: 0; +} +#user-summary nav { + float: left; + width: 45%; + margin-right: 1em; +} diff --git a/client/html/home.hbs b/client/html/home.hbs index 3c7bcf9..6f428ff 100644 --- a/client/html/home.hbs +++ b/client/html/home.hbs @@ -1,5 +1,5 @@

{{name}}

-
Version: {{version}} (built {{#reltime}}{{buildDate}}{{/reltime}})
+
Version: {{version}} (built {{reltime buildDate}})
diff --git a/client/html/user.hbs b/client/html/user.hbs new file mode 100644 index 0000000..d4fe6f9 --- /dev/null +++ b/client/html/user.hbs @@ -0,0 +1,12 @@ +
+ +
+

{{this.name}}

+ +
+
diff --git a/client/html/user_edit.hbs b/client/html/user_edit.hbs new file mode 100644 index 0000000..bf3be1e --- /dev/null +++ b/client/html/user_edit.hbs @@ -0,0 +1,3 @@ +
+ Placeholder for account settings form +
diff --git a/client/html/user_summary.hbs b/client/html/user_summary.hbs new file mode 100644 index 0000000..7519f50 --- /dev/null +++ b/client/html/user_summary.hbs @@ -0,0 +1,29 @@ +
+ {{this.user.name}}’s avatar + + +
+ + + {{#if this.isPrivate}} + + {{/if}} +
+
diff --git a/client/js/controllers/users_controller.js b/client/js/controllers/users_controller.js index 9390e2a..b7d3e2b 100644 --- a/client/js/controllers/users_controller.js +++ b/client/js/controllers/users_controller.js @@ -18,10 +18,13 @@ class UsersController { page('/users', () => { this.listUsersRoute(); }); page( '/user/:name', - (ctx, next) => { this.showUserRoute(ctx.params.name); }); + (ctx, next) => { this.loadUserRoute(ctx, next); }, + (ctx, next) => { this.showUserRoute(ctx, next); }); page( '/user/:name/edit', - (ctx, next) => { this.editUserRoute(ctx.params.name); }); + (ctx, next) => { this.loadUserRoute(ctx, next); }, + (ctx, next) => { this.editUserRoute(ctx, next); }); + page.exit('/user/', (ctx, next) => { this.user = null; }); } listUsersRoute() { @@ -57,22 +60,42 @@ class UsersController { }); } - showUserRoute(name) { - if (api.isLoggedIn() && name == api.userName) { + loadUserRoute(ctx, next) { + if (ctx.state.user) { + next(); + } else if (this.user && this.user.name == ctx.params.name) { + ctx.state.user = this.user; + next(); + } else { + api.get('/user/' + ctx.params.name).then(response => { + ctx.state.user = response.user; + ctx.save(); + this.user = response.user; + next(); + }).catch(response => { + this.userView.empty(); + this.userView.notifyError(response.description); + }); + } + } + + _show(user, section) { + const isPrivate = api.isLoggedIn() && user.name == api.userName; + if (isPrivate) { topNavController.activate('account'); } else { topNavController.activate('users'); } - this.userView.empty(); - api.get('/user/' + name).then(response => { - this.userView.render({user: response.user}); - }).catch(response => { - this.userView.notifyError(response.description); - }); + this.userView.render({ + user: user, section: section, isPrivate: isPrivate}); } - editUserRoute(user) { - topNavController.activate('users'); + showUserRoute(ctx, next) { + this._show(ctx.state.user, 'summary'); + } + + editUserRoute(ctx, next) { + this._show(ctx.state.user, 'edit'); } } diff --git a/client/js/util/handlebars-helpers.js b/client/js/util/handlebars-helpers.js index 8d121d5..03eb7f1 100644 --- a/client/js/util/handlebars-helpers.js +++ b/client/js/util/handlebars-helpers.js @@ -3,13 +3,13 @@ const handlebars = require('handlebars'); const misc = require('./misc.js'); -handlebars.registerHelper('reltime', function(options) { +handlebars.registerHelper('reltime', function(time) { return new handlebars.SafeString( - '