git ssb

30+

cel / git-ssb-web



Commit ba02aa5007c20a431511f04d41c9928886e6a166

Factor out nav links generation

Charles Lehner committed on 3/30/2016, 10:17:40 PM
Parent: 7de0259e18a5afbfea5e9cb0ce2545040440b56e

Files changed

index.jschanged
index.jsView
@@ -151,8 +151,17 @@
151151 ])
152152 }
153153 }
154154
155+function nav(links, page, after) {
156+ return ['<nav>'].concat(
157+ links.map(function (link) {
158+ var href = typeof link[0] == 'string' ? link[0] : encodeLink(link[0])
159+ var props = link[2] == page ? ' class="active"' : ''
160+ return '<a href="' + href + '"' + props + '>' + link[1] + '</a>'
161+ }), after || '', '</nav>').join('')
162+}
163+
155164 function renderNameForm(enabled, id, name, action, inputId, title, header) {
156165 if (!inputId) inputId = action
157166 return '<form class="petname" action="" method="post">' +
158167 (enabled ?
@@ -709,14 +718,12 @@
709718 readOnce(function (cb) {
710719 about.getName(feedId, function (err, name) {
711720 cb(null, '<h2>' + link([feedId], name) +
712721 '<code class="user-id">' + feedId + '</code></h2>' +
713- '<nav>' +
714- link([feedId], 'Activity', true,
715- page == 'activity' ? ' class="active"' : '') +
716- link([feedId, 'repos'], 'Repos', true,
717- page == 'repos' ? ' class="active"' : '') +
718- '</nav>')
722+ nav([
723+ [[feedId], 'Activity', 'activity'],
724+ [[feedId, 'repos'], 'Repos', 'repos']
725+ ], page))
719726 })
720727 }),
721728 body,
722729 ]))
@@ -913,19 +920,15 @@
913920 renderNameForm(!isPublic, repo.id, repoName, 'repo-name', null,
914921 'Rename the repo',
915922 '<h2>' + link([repo.feed], authorName) + ' / ' +
916923 link([repo.id], repoName) + '</h2>') +
917- '</div><nav>' +
918- link([repo.id], 'Code', true,
919- page == 'code' ? ' class="active"' : '') +
920- link([repo.id, 'activity'], 'Activity', true,
921- page == 'activity' ? ' class="active"' : '') +
922- link([repo.id, 'commits', branch || ''], 'Commits', true,
923- page == 'commits' ? ' class="active"' : '') +
924- link([repo.id, 'issues'], 'Issues', true,
925- page == 'issues' ? ' class="active"' : '') +
926- gitLink +
927- '</nav>'),
924+ '</div>' +
925+ nav([
926+ [[repo.id], 'Code', 'code'],
927+ [[repo.id, 'activity'], 'Activity', 'activity'],
928+ [[repo.id, 'commits', branch || ''], 'Commits', 'commits'],
929+ [[repo.id, 'issues'], 'Issues', 'issues']
930+ ], page, gitLink)),
928931 body
929932 ])))
930933 })
931934 })
@@ -1380,16 +1383,13 @@
13801383 '<div class="right-bar">' + link([repo.id, 'issues', 'new'],
13811384 '<button class="btn">&plus; New Issue</button>', true) +
13821385 '</div>') +
13831386 '<h3>Issues</h3>' +
1384- '<nav>' +
1385- '<a href="?state=open"' +
1386- (state == 'open' ? ' class="active"' : '') + '>Open</a>' +
1387- '<a href="?state=closed"' +
1388- (state == 'closed' ? ' class="active"' : '') + '>Closed</a>' +
1389- '<a href="?state=all"' +
1390- (state == 'all' ? ' class="active"' : '') + '>All</a>' +
1391- '</nav>'),
1387+ nav([
1388+ ['?state=open', 'Open', 'open'],
1389+ ['?state=closed', 'Closed', 'closed'],
1390+ ['?state=all', 'All', 'all']
1391+ ], state)),
13921392 pull(
13931393 issues.createFeedStream({ project: repo.id }),
13941394 pull.filter(function (issue) {
13951395 return state == 'all' ? true : (state == 'closed') == !issue.open

Built with git-ssb-web