From 0842d90ca2cebda8d85a39f504e1f7cd79a167d1 Mon Sep 17 00:00:00 2001 From: rr- Date: Sat, 11 Jun 2016 09:59:06 +0200 Subject: [PATCH] client/general: ditch underscore for loops --- client/html/manual_pager_nav.tpl | 4 +- client/html/posts_page.tpl | 4 +- client/html/tag_categories.tpl | 4 +- client/html/tag_relations.tpl | 8 +-- client/html/tags_page.tpl | 16 +++--- client/html/top_nav.tpl | 4 +- client/html/users_page.tpl | 4 +- client/js/controllers/top_nav_controller.js | 64 +++++++++++---------- 8 files changed, 56 insertions(+), 52 deletions(-) diff --git a/client/html/manual_pager_nav.tpl b/client/html/manual_pager_nav.tpl index 67c995b..e061887 100644 --- a/client/html/manual_pager_nav.tpl +++ b/client/html/manual_pager_nav.tpl @@ -11,7 +11,7 @@ - <% _.each(ctx.pages, page => { %> + <% for (let page of ctx.pages) { %> <% if (page.ellipsis) { %>
  • <% } else { %> @@ -23,7 +23,7 @@ <%= page.number %> <% } %> - <% }) %> + <% } %>
  • <% if (ctx.nextLinkActive) { %> diff --git a/client/html/posts_page.tpl b/client/html/posts_page.tpl index 1518980..97a4b65 100644 --- a/client/html/posts_page.tpl +++ b/client/html/posts_page.tpl @@ -1,7 +1,7 @@
    <% if (ctx.results.length) { %> <% } %> diff --git a/client/html/tag_categories.tpl b/client/html/tag_categories.tpl index 5abd0f5..cc8fe6a 100644 --- a/client/html/tag_categories.tpl +++ b/client/html/tag_categories.tpl @@ -10,7 +10,7 @@ - <% _.each(ctx.tagCategories, category => { %> + <% for (let category of ctx.tagCategories) { %> <% if (category.default) { %> <% } else { %> @@ -50,7 +50,7 @@ <% } %> - <% }) %> + <% } %> diff --git a/client/html/tag_relations.tpl b/client/html/tag_relations.tpl index 39c09d4..1d35463 100644 --- a/client/html/tag_relations.tpl +++ b/client/html/tag_relations.tpl @@ -1,16 +1,16 @@
    <% if (ctx.suggestions.length) { %>
      - <% _.each(ctx.suggestions.slice(0, 20), tagName => { %> + <% for (let tagName of ctx.suggestions.slice(0, 20)) { %>
    • <%= ctx.makeTagLink(tagName) %>
    • - <% }) %> + <% } %>
    <% } %> <% if (ctx.siblings.length) { %>
      - <% _.each(ctx.siblings.slice(0, 20), tagName => { %> + <% for (let tagName of ctx.siblings.slice(0, 20)) { %>
    • <%= ctx.makeTagLink(tagName) %>
    • - <% }) %> + <% } %>
    <% } %>
    diff --git a/client/html/tags_page.tpl b/client/html/tags_page.tpl index 774ff61..cca8daa 100644 --- a/client/html/tags_page.tpl +++ b/client/html/tags_page.tpl @@ -39,21 +39,21 @@ - <% _.each(ctx.results, tag => { %> + <% for (let tag of ctx.results) { %>
      - <% _.each(tag.names, name => { %> + <% for (let name of tag.names) { %>
    • <%= ctx.makeTagLink(name) %>
    • - <% }) %> + <% } %>
    <% if (tag.implications.length) { %>
      - <% _.each(tag.implications, name => { %> + <% for (let name of tag.implications) { %>
    • <%= ctx.makeTagLink(name) %>
    • - <% }) %> + <% } %>
    <% } else { %> - @@ -62,9 +62,9 @@ <% if (tag.suggestions.length) { %>
      - <% _.each(tag.suggestions, name => { %> + <% for (let name of tag.suggestions) { %>
    • <%= ctx.makeTagLink(name) %>
    • - <% }) %> + <% } %>
    <% } else { %> - @@ -77,7 +77,7 @@ <%= ctx.makeRelativeTime(tag.lastEditTime) %> - <% }) %> + <% } %> <% } %> diff --git a/client/html/top_nav.tpl b/client/html/top_nav.tpl index 75a7ad1..860b5f8 100644 --- a/client/html/top_nav.tpl +++ b/client/html/top_nav.tpl @@ -1,6 +1,6 @@ diff --git a/client/html/users_page.tpl b/client/html/users_page.tpl index 6c145c8..a906828 100644 --- a/client/html/users_page.tpl +++ b/client/html/users_page.tpl @@ -1,6 +1,6 @@
  • <% }) %><% } %><%= ctx.makeFlexboxAlign() %> diff --git a/client/js/controllers/top_nav_controller.js b/client/js/controllers/top_nav_controller.js index f030770..1548558 100644 --- a/client/js/controllers/top_nav_controller.js +++ b/client/js/controllers/top_nav_controller.js @@ -4,6 +4,25 @@ const api = require('../api.js'); const events = require('../events.js'); const TopNavView = require('../views/top_nav_view.js'); +function _createNavigationItemMap() { + const ret = new Map(); + ret.set('home', new NavigationItem('H', 'Home', '/')); + ret.set('posts', new NavigationItem('P', 'Posts', '/posts')); + ret.set('upload', new NavigationItem('U', 'Upload', '/upload')); + ret.set('comments', new NavigationItem('C', 'Comments', '/comments')); + ret.set('tags', new NavigationItem('T', 'Tags', '/tags')); + ret.set('users', new NavigationItem('S', 'Users', '/users')); + ret.set('account', new NavigationItem('A', 'Account', '/user/{me}')); + ret.set('register', new NavigationItem('R', 'Register', '/register')); + ret.set('login', new NavigationItem('L', 'Log in', '/login')); + ret.set('logout', new NavigationItem('O', 'Logout', '/logout')); + ret.set('help', new NavigationItem('E', 'Help', '/help')); + ret.set( + 'settings', + new NavigationItem(null, '', '/settings')); + return ret; +} + class NavigationItem { constructor(accessKey, name, url) { this.accessKey = accessKey; @@ -18,22 +37,7 @@ class TopNavController { constructor() { this._topNavView = new TopNavView(); this._activeItem = null; - - this._items = { - 'home': new NavigationItem('H', 'Home', '/'), - 'posts': new NavigationItem('P', 'Posts', '/posts'), - 'upload': new NavigationItem('U', 'Upload', '/upload'), - 'comments': new NavigationItem('C', 'Comments', '/comments'), - 'tags': new NavigationItem('T', 'Tags', '/tags'), - 'users': new NavigationItem('S', 'Users', '/users'), - 'account': new NavigationItem('A', 'Account', '/user/{me}'), - 'register': new NavigationItem('R', 'Register', '/register'), - 'login': new NavigationItem('L', 'Log in', '/login'), - 'logout': new NavigationItem('O', 'Logout', '/logout'), - 'help': new NavigationItem('E', 'Help', '/help'), - 'settings': new NavigationItem( - null, '', '/settings'), - }; + this._items = _createNavigationItemMap(); const rerender = () => { this._updateVisibility(); @@ -50,34 +54,34 @@ class TopNavController { } _updateVisibility() { - this._items.account.url = '/user/' + api.userName; - this._items.account.imageUrl = api.user ? api.user.avatarUrl : null; + this._items.get('account').url = '/user/' + api.userName; + this._items.get('account').imageUrl = api.user ? + api.user.avatarUrl : null; - const b = Object.keys(this._items); - for (let key of b) { - this._items[key].available = true; + for (let [key, item] of this._items) { + item.available = true; } if (!api.hasPrivilege('posts:list')) { - this._items.posts.available = false; + this._items.get('posts').available = false; } if (!api.hasPrivilege('posts:create')) { - this._items.upload.available = false; + this._items.get('upload').available = false; } if (!api.hasPrivilege('comments:list')) { - this._items.comments.available = false; + this._items.get('comments').available = false; } if (!api.hasPrivilege('tags:list')) { - this._items.tags.available = false; + this._items.get('tags').available = false; } if (!api.hasPrivilege('users:list')) { - this._items.users.available = false; + this._items.get('users').available = false; } if (api.isLoggedIn()) { - this._items.register.available = false; - this._items.login.available = false; + this._items.get('register').available = false; + this._items.get('login').available = false; } else { - this._items.account.available = false; - this._items.logout.available = false; + this._items.get('account').available = false; + this._items.get('logout').available = false; } }