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>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<% _.each(ctx.pages, page => { %>
|
<% for (let page of ctx.pages) { %>
|
||||||
<% if (page.ellipsis) { %>
|
<% if (page.ellipsis) { %>
|
||||||
<li>…</li>
|
<li>…</li>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
<a href='<%= page.link %>'><%= page.number %></a>
|
<a href='<%= page.link %>'><%= page.number %></a>
|
||||||
</li>
|
</li>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% }) %>
|
<% } %>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<% if (ctx.nextLinkActive) { %>
|
<% if (ctx.nextLinkActive) { %>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<div class='post-list'>
|
<div class='post-list'>
|
||||||
<% if (ctx.results.length) { %>
|
<% if (ctx.results.length) { %>
|
||||||
<ul>
|
<ul>
|
||||||
<% _.each(ctx.results, post => { %>
|
<% for (let post of ctx.results) { %>
|
||||||
<li>
|
<li>
|
||||||
<a href='/post/<%= post.id %>' title='@<%= post.id %> (<%= post.type %>) Tags: <%= post.tags.map(tag => '#' + tag).join(' ') %>'>
|
<a href='/post/<%= post.id %>' title='@<%= post.id %> (<%= post.type %>) Tags: <%= post.tags.map(tag => '#' + tag).join(' ') %>'>
|
||||||
<%= ctx.makeThumbnail(post.thumbnailUrl) %>
|
<%= ctx.makeThumbnail(post.thumbnailUrl) %>
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
<% } %>
|
<% } %>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<% }) %>
|
<% } %>
|
||||||
<%= ctx.makeFlexboxAlign() %>
|
<%= ctx.makeFlexboxAlign() %>
|
||||||
</ul>
|
</ul>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% _.each(ctx.tagCategories, category => { %>
|
<% for (let category of ctx.tagCategories) { %>
|
||||||
<% if (category.default) { %>
|
<% if (category.default) { %>
|
||||||
<tr data-category='<%= category.name %>' class='default'>
|
<tr data-category='<%= category.name %>' class='default'>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
</td>
|
</td>
|
||||||
<% } %>
|
<% } %>
|
||||||
</tr>
|
</tr>
|
||||||
<% }) %>
|
<% } %>
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr class='add-template'>
|
<tr class='add-template'>
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
<div class='tag-relations'>
|
<div class='tag-relations'>
|
||||||
<% if (ctx.suggestions.length) { %>
|
<% if (ctx.suggestions.length) { %>
|
||||||
<ul class='tag-suggestions'>
|
<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>
|
<li><%= ctx.makeTagLink(tagName) %></li>
|
||||||
<% }) %>
|
<% } %>
|
||||||
</ul>
|
</ul>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% if (ctx.siblings.length) { %>
|
<% if (ctx.siblings.length) { %>
|
||||||
<ul class='tag-siblings'>
|
<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>
|
<li><%= ctx.makeTagLink(tagName) %></li>
|
||||||
<% }) %>
|
<% } %>
|
||||||
</ul>
|
</ul>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -39,21 +39,21 @@
|
||||||
</th>
|
</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% _.each(ctx.results, tag => { %>
|
<% for (let tag of ctx.results) { %>
|
||||||
<tr>
|
<tr>
|
||||||
<td class='names'>
|
<td class='names'>
|
||||||
<ul>
|
<ul>
|
||||||
<% _.each(tag.names, name => { %>
|
<% for (let name of tag.names) { %>
|
||||||
<li><%= ctx.makeTagLink(name) %></li>
|
<li><%= ctx.makeTagLink(name) %></li>
|
||||||
<% }) %>
|
<% } %>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td class='implications'>
|
<td class='implications'>
|
||||||
<% if (tag.implications.length) { %>
|
<% if (tag.implications.length) { %>
|
||||||
<ul>
|
<ul>
|
||||||
<% _.each(tag.implications, name => { %>
|
<% for (let name of tag.implications) { %>
|
||||||
<li><%= ctx.makeTagLink(name) %></li>
|
<li><%= ctx.makeTagLink(name) %></li>
|
||||||
<% }) %>
|
<% } %>
|
||||||
</ul>
|
</ul>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
-
|
-
|
||||||
|
@ -62,9 +62,9 @@
|
||||||
<td class='suggestions'>
|
<td class='suggestions'>
|
||||||
<% if (tag.suggestions.length) { %>
|
<% if (tag.suggestions.length) { %>
|
||||||
<ul>
|
<ul>
|
||||||
<% _.each(tag.suggestions, name => { %>
|
<% for (let name of tag.suggestions) { %>
|
||||||
<li><%= ctx.makeTagLink(name) %></li>
|
<li><%= ctx.makeTagLink(name) %></li>
|
||||||
<% }) %>
|
<% } %>
|
||||||
</ul>
|
</ul>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
-
|
-
|
||||||
|
@ -77,7 +77,7 @@
|
||||||
<%= ctx.makeRelativeTime(tag.lastEditTime) %>
|
<%= ctx.makeRelativeTime(tag.lastEditTime) %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% }) %>
|
<% } %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<nav id='top-nav' class='buttons'>
|
<nav id='top-nav' class='buttons'>
|
||||||
<ul><!--
|
<ul><!--
|
||||||
--><% _.each(ctx.items, (item, key) => { %><!--
|
--><% for (let [key, item] of ctx.items) { %><!--
|
||||||
--><% if (item.available) { %><!--
|
--><% if (item.available) { %><!--
|
||||||
--><li data-name='<%= key %>'><!--
|
--><li data-name='<%= key %>'><!--
|
||||||
--><a href='<%= item.url %>' accesskey='<%= item.accessKey %>'><!--
|
--><a href='<%= item.url %>' accesskey='<%= item.accessKey %>'><!--
|
||||||
|
@ -9,6 +9,6 @@
|
||||||
--></a><!--
|
--></a><!--
|
||||||
--></li><!--
|
--></li><!--
|
||||||
--><% } %><!--
|
--><% } %><!--
|
||||||
--><% }) %><!--
|
--><% } %><!--
|
||||||
--></ul>
|
--></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div class='user-list'>
|
<div class='user-list'>
|
||||||
<ul><!--
|
<ul><!--
|
||||||
--><% _.each(ctx.results, user => { %><!--
|
--><% for (let user of ctx.results) { %><!--
|
||||||
--><li>
|
--><li>
|
||||||
<div class='wrapper'>
|
<div class='wrapper'>
|
||||||
<a class='image' href='/user/<%= user.name %>'><%= ctx.makeThumbnail(user.avatarUrl) %></a>
|
<a class='image' href='/user/<%= user.name %>'><%= ctx.makeThumbnail(user.avatarUrl) %></a>
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</li><!--
|
</li><!--
|
||||||
--><% }) %><!--
|
--><% } %><!--
|
||||||
--><%= ctx.makeFlexboxAlign() %><!--
|
--><%= ctx.makeFlexboxAlign() %><!--
|
||||||
--></ul>
|
--></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,6 +4,25 @@ const api = require('../api.js');
|
||||||
const events = require('../events.js');
|
const events = require('../events.js');
|
||||||
const TopNavView = require('../views/top_nav_view.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 {
|
class NavigationItem {
|
||||||
constructor(accessKey, name, url) {
|
constructor(accessKey, name, url) {
|
||||||
this.accessKey = accessKey;
|
this.accessKey = accessKey;
|
||||||
|
@ -18,22 +37,7 @@ class TopNavController {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._topNavView = new TopNavView();
|
this._topNavView = new TopNavView();
|
||||||
this._activeItem = null;
|
this._activeItem = null;
|
||||||
|
this._items = _createNavigationItemMap();
|
||||||
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'),
|
|
||||||
};
|
|
||||||
|
|
||||||
const rerender = () => {
|
const rerender = () => {
|
||||||
this._updateVisibility();
|
this._updateVisibility();
|
||||||
|
@ -50,34 +54,34 @@ class TopNavController {
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateVisibility() {
|
_updateVisibility() {
|
||||||
this._items.account.url = '/user/' + api.userName;
|
this._items.get('account').url = '/user/' + api.userName;
|
||||||
this._items.account.imageUrl = api.user ? api.user.avatarUrl : null;
|
this._items.get('account').imageUrl = api.user ?
|
||||||
|
api.user.avatarUrl : null;
|
||||||
|
|
||||||
const b = Object.keys(this._items);
|
for (let [key, item] of this._items) {
|
||||||
for (let key of b) {
|
item.available = true;
|
||||||
this._items[key].available = true;
|
|
||||||
}
|
}
|
||||||
if (!api.hasPrivilege('posts:list')) {
|
if (!api.hasPrivilege('posts:list')) {
|
||||||
this._items.posts.available = false;
|
this._items.get('posts').available = false;
|
||||||
}
|
}
|
||||||
if (!api.hasPrivilege('posts:create')) {
|
if (!api.hasPrivilege('posts:create')) {
|
||||||
this._items.upload.available = false;
|
this._items.get('upload').available = false;
|
||||||
}
|
}
|
||||||
if (!api.hasPrivilege('comments:list')) {
|
if (!api.hasPrivilege('comments:list')) {
|
||||||
this._items.comments.available = false;
|
this._items.get('comments').available = false;
|
||||||
}
|
}
|
||||||
if (!api.hasPrivilege('tags:list')) {
|
if (!api.hasPrivilege('tags:list')) {
|
||||||
this._items.tags.available = false;
|
this._items.get('tags').available = false;
|
||||||
}
|
}
|
||||||
if (!api.hasPrivilege('users:list')) {
|
if (!api.hasPrivilege('users:list')) {
|
||||||
this._items.users.available = false;
|
this._items.get('users').available = false;
|
||||||
}
|
}
|
||||||
if (api.isLoggedIn()) {
|
if (api.isLoggedIn()) {
|
||||||
this._items.register.available = false;
|
this._items.get('register').available = false;
|
||||||
this._items.login.available = false;
|
this._items.get('login').available = false;
|
||||||
} else {
|
} else {
|
||||||
this._items.account.available = false;
|
this._items.get('account').available = false;
|
||||||
this._items.logout.available = false;
|
this._items.get('logout').available = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue