git ssb

30+

cel / git-ssb-web



Commit 1610838e2f74772cb14e43fe47ee593084a17c3c

Add user repos list view

Close %sgKGvwK/Lzja3uvtQthhgi9He0mhSpCmASGpowRUOZw=.sha256
Charles Lehner committed on 3/27/2016, 3:13:18 PM
Parent: 89ce7442bb7d0a3e38e89aab3f493cba4140cba4

Files changed

index.jschanged
static/styles.csschanged
index.jsView
@@ -65,13 +65,15 @@
6565 function encodeLink(url) {
6666 return '/' + encodeURIComponent(url)
6767 }
6868
69-function link(parts, text, raw) {
69+function link(parts, text, raw, props) {
7070 var href = flattenPath(parts)
7171 if (text == null) text = parts[parts.length-1]
7272 if (!raw) text = escapeHTML(text)
73- return '<a href="' + escapeHTML(href) + '">' + text + '</a>'
73+ return '<a href="' + escapeHTML(href) + '"' +
74+ (props ? ' ' + props : '') +
75+ '>' + text + '</a>'
7476 }
7577
7678 function timestamp(time) {
7779 time = Number(time)
@@ -447,9 +449,9 @@
447449 return serveBlob(req, dir)
448450 else if (ref.isMsgId(dir))
449451 return serveMessage(req, dir, dirs.slice(1))
450452 else if (ref.isFeedId(dir))
451- return serveUserPage(dir)
453+ return serveUserPage(dir, dirs.slice(1))
452454 else
453455 return serveFile(req, dirs)
454456 }
455457
@@ -629,20 +631,62 @@
629631 function serveIndex() {
630632 return serveTemplate('git ssb')(renderFeed())
631633 }
632634
633- function serveUserPage(feedId) {
635+ function serveUserPage(feedId, dirs) {
636+ switch (dirs[0]) {
637+ case undefined:
638+ case '':
639+ case 'activity':
640+ return serveUserActivity(feedId)
641+ case 'repos':
642+ return serveUserRepos(feedId)
643+ }
644+ }
645+
646+ function renderUserPage(feedId, page, body) {
634647 return serveTemplate(feedId)(cat([
635648 readOnce(function (cb) {
636649 about.getName(feedId, function (err, name) {
637650 cb(null, '<h2>' + link([feedId], name) +
638- '<code class="user-id">' + feedId + '</code></h2>')
651+ '<code class="user-id">' + feedId + '</code></h2>' +
652+ '<nav>' +
653+ link([feedId], 'Activity', true,
654+ page == 'activity' ? ' class="active"' : '') +
655+ link([feedId, 'repos'], 'Repos', true,
656+ page == 'repos' ? ' class="active"' : '') +
657+ '</nav>')
639658 })
640659 }),
641- renderFeed(feedId),
660+ body,
642661 ]))
643662 }
644663
664+ function serveUserActivity(feedId) {
665+ return renderUserPage(feedId, 'activity', renderFeed(feedId))
666+ }
667+
668+ function serveUserRepos(feedId) {
669+ return renderUserPage(feedId, 'repos', pull(
670+ ssb.messagesByType({
671+ type: 'git-repo',
672+ reverse: true
673+ }),
674+ pull.filter(function (msg) {
675+ return msg.value.author == feedId
676+ }),
677+ pull.take(20),
678+ paramap(function (msg, cb) {
679+ getRepoName(about, feedId, msg.key, function (err, repoName) {
680+ if (err) return cb(err)
681+ cb(null, '<section class="collapse">' +
682+ link([msg.key], repoName) +
683+ '</section>')
684+ })
685+ }, 8)
686+ ))
687+ }
688+
645689 /* Message */
646690
647691 function serveMessage(req, id, path) {
648692 return readNext(function (cb) {
@@ -780,14 +824,14 @@
780824 renderNameForm(!isPublic, repo.id, repoName, 'repo-name', null,
781825 'Rename the repo',
782826 '<h2>' + link([repo.feed], authorName) + ' / ' +
783827 link([repo.id], repoName) + '</h2>') +
784- '</div><div class="repo-nav">' + link([repo.id], 'Code') +
828+ '</div><nav>' + link([repo.id], 'Code') +
785829 link([repo.id, 'activity'], 'Activity') +
786830 link([repo.id, 'commits', branch || ''], 'Commits') +
787831 link([repo.id, 'issues'], 'Issues') +
788832 gitLink +
789- '</div>'),
833+ '</nav>'),
790834 body
791835 ])))
792836 })
793837 })
static/styles.cssView
@@ -147,22 +147,26 @@
147147 .clone-url:hover {
148148 background-color: #f6f6f6;
149149 }
150150
151-.repo-nav {
152- margin: 1em 0 1ex 0;
151+nav {
152+ margin: .5em 0 1ex 0;
153153 }
154154
155-.repo-nav a {
155+nav a {
156156 border-radius: .5ex;
157157 padding: 0 .5ex;
158158 display: inline-block;
159159 margin-right: .5ex;
160160 }
161-.repo-nav a:hover {
161+nav a:hover {
162162 color: #1a86ff;
163163 }
164164
165+nav a.active {
166+ text-decoration: underline;
167+}
168+
165169 .raw-link {
166170 float: right;
167171 display: inline-block;
168172 }

Built with git-ssb-web