client/general: ditch underscore for loops
This commit is contained in:
parent
abd679888a
commit
0842d90ca2
8 changed files with 56 additions and 52 deletions
|
@ -11,7 +11,7 @@
|
|||
</a>
|
||||
</li>
|
||||
|
||||
<% _.each(ctx.pages, page => { %>
|
||||
<% for (let page of ctx.pages) { %>
|
||||
<% if (page.ellipsis) { %>
|
||||
<li>…</li>
|
||||
<% } else { %>
|
||||
|
@ -23,7 +23,7 @@
|
|||
<a href='<%= page.link %>'><%= page.number %></a>
|
||||
</li>
|
||||
<% } %>
|
||||
<% }) %>
|
||||
<% } %>
|
||||
|
||||
<li>
|
||||
<% if (ctx.nextLinkActive) { %>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div class='post-list'>
|
||||
<% if (ctx.results.length) { %>
|
||||
<ul>
|
||||
<% _.each(ctx.results, post => { %>
|
||||
<% for (let post of ctx.results) { %>
|
||||
<li>
|
||||
<a href='/post/<%= post.id %>' title='@<%= post.id %> (<%= post.type %>) Tags: <%= post.tags.map(tag => '#' + tag).join(' ') %>'>
|
||||
<%= ctx.makeThumbnail(post.thumbnailUrl) %>
|
||||
|
@ -32,7 +32,7 @@
|
|||
<% } %>
|
||||
</a>
|
||||
</li>
|
||||
<% }) %>
|
||||
<% } %>
|
||||
<%= ctx.makeFlexboxAlign() %>
|
||||
</ul>
|
||||
<% } %>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% _.each(ctx.tagCategories, category => { %>
|
||||
<% for (let category of ctx.tagCategories) { %>
|
||||
<% if (category.default) { %>
|
||||
<tr data-category='<%= category.name %>' class='default'>
|
||||
<% } else { %>
|
||||
|
@ -50,7 +50,7 @@
|
|||
</td>
|
||||
<% } %>
|
||||
</tr>
|
||||
<% }) %>
|
||||
<% } %>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr class='add-template'>
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
<div class='tag-relations'>
|
||||
<% if (ctx.suggestions.length) { %>
|
||||
<ul class='tag-suggestions'>
|
||||
<% _.each(ctx.suggestions.slice(0, 20), tagName => { %>
|
||||
<% for (let tagName of ctx.suggestions.slice(0, 20)) { %>
|
||||
<li><%= ctx.makeTagLink(tagName) %></li>
|
||||
<% }) %>
|
||||
<% } %>
|
||||
</ul>
|
||||
<% } %>
|
||||
<% if (ctx.siblings.length) { %>
|
||||
<ul class='tag-siblings'>
|
||||
<% _.each(ctx.siblings.slice(0, 20), tagName => { %>
|
||||
<% for (let tagName of ctx.siblings.slice(0, 20)) { %>
|
||||
<li><%= ctx.makeTagLink(tagName) %></li>
|
||||
<% }) %>
|
||||
<% } %>
|
||||
</ul>
|
||||
<% } %>
|
||||
</div>
|
||||
|
|
|
@ -39,21 +39,21 @@
|
|||
</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% _.each(ctx.results, tag => { %>
|
||||
<% for (let tag of ctx.results) { %>
|
||||
<tr>
|
||||
<td class='names'>
|
||||
<ul>
|
||||
<% _.each(tag.names, name => { %>
|
||||
<% for (let name of tag.names) { %>
|
||||
<li><%= ctx.makeTagLink(name) %></li>
|
||||
<% }) %>
|
||||
<% } %>
|
||||
</ul>
|
||||
</td>
|
||||
<td class='implications'>
|
||||
<% if (tag.implications.length) { %>
|
||||
<ul>
|
||||
<% _.each(tag.implications, name => { %>
|
||||
<% for (let name of tag.implications) { %>
|
||||
<li><%= ctx.makeTagLink(name) %></li>
|
||||
<% }) %>
|
||||
<% } %>
|
||||
</ul>
|
||||
<% } else { %>
|
||||
-
|
||||
|
@ -62,9 +62,9 @@
|
|||
<td class='suggestions'>
|
||||
<% if (tag.suggestions.length) { %>
|
||||
<ul>
|
||||
<% _.each(tag.suggestions, name => { %>
|
||||
<% for (let name of tag.suggestions) { %>
|
||||
<li><%= ctx.makeTagLink(name) %></li>
|
||||
<% }) %>
|
||||
<% } %>
|
||||
</ul>
|
||||
<% } else { %>
|
||||
-
|
||||
|
@ -77,7 +77,7 @@
|
|||
<%= ctx.makeRelativeTime(tag.lastEditTime) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% }) %>
|
||||
<% } %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% } %>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<nav id='top-nav' class='buttons'>
|
||||
<ul><!--
|
||||
--><% _.each(ctx.items, (item, key) => { %><!--
|
||||
--><% for (let [key, item] of ctx.items) { %><!--
|
||||
--><% if (item.available) { %><!--
|
||||
--><li data-name='<%= key %>'><!--
|
||||
--><a href='<%= item.url %>' accesskey='<%= item.accessKey %>'><!--
|
||||
|
@ -9,6 +9,6 @@
|
|||
--></a><!--
|
||||
--></li><!--
|
||||
--><% } %><!--
|
||||
--><% }) %><!--
|
||||
--><% } %><!--
|
||||
--></ul>
|
||||
</nav>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div class='user-list'>
|
||||
<ul><!--
|
||||
--><% _.each(ctx.results, user => { %><!--
|
||||
--><% for (let user of ctx.results) { %><!--
|
||||
--><li>
|
||||
<div class='wrapper'>
|
||||
<a class='image' href='/user/<%= user.name %>'><%= ctx.makeThumbnail(user.avatarUrl) %></a>
|
||||
|
@ -11,7 +11,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</li><!--
|
||||
--><% }) %><!--
|
||||
--><% } %><!--
|
||||
--><%= ctx.makeFlexboxAlign() %><!--
|
||||
--></ul>
|
||||
</div>
|
||||
|
|
|
@ -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, '<i class=\'fa fa-cog\'></i>', '/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, '<i class=\'fa fa-cog\'></i>', '/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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue