git ssb

30+

cel / git-ssb-web



Commit 682946ef9ff8ec327b436171254439b59dc3c365

Add issue commenting

Charles Lehner committed on 3/27/2016, 1:57:42 AM
Parent: 6cf9fab5fd8056dc21853b6d5c83622c45c2e853

Files changed

index.jschanged
package.jsonchanged
static/styles.csschanged
index.jsView
@@ -119,10 +119,10 @@
119119 '<input type="hidden" name="action" value="' + action + '">' +
120120 '<input type="hidden" name="id" value="' +
121121 escapeHTML(id) + '">' +
122122 '<label class="name-toggle" for="' + inputId + '" ' +
123- 'title="' + title + '"><i>✍</i></label>' +
124- '<input class="name-btn" type="submit" value="Rename">' +
123+ 'title="' + title + '"><i>✍</i></label> ' +
124+ '<input class="btn name-btn" type="submit" value="Rename">' +
125125 header :
126126 header + '<br clear="all"/>'
127127 ) +
128128 '</form>'
@@ -334,8 +334,22 @@
334334 if (err) return cb(null, serveError(err))
335335 cb(null, serveRedirect(req.url))
336336 })
337337
338+ case 'comment':
339+ if (!data.id)
340+ return cb(null, serveError(new Error('Missing id'), 400))
341+ // TODO: add ref mentions
342+ var msg = schemas.post(data.text, data.id, data.branch || data.id)
343+ if (data.open != null)
344+ Issues.schemas.opens(msg, data.id)
345+ if (data.close != null)
346+ Issues.schemas.closes(msg, data.id)
347+ return ssb.publish(msg, function (err) {
348+ if (err) return cb(null, serveError(err))
349+ cb(null, serveRedirect(req.url))
350+ })
351+
338352 default:
339353 if (path == 'issues,new') {
340354 issues.new({
341355 project: repo.id,
@@ -663,18 +677,17 @@
663677 cb(null, serveTemplate(repo.id)(cat([
664678 pull.once(
665679 '<div class="repo-title">' +
666680 '<form class="right-bar" action="" method="post">' +
667- (isPublic
668- ? '<button disabled="disabled"><i>✌</i> Dig</button> '
669- : '<input type="hidden" name="vote" value="' +
681+ '<button class="btn" ' +
682+ (isPublic ? 'disabled="disabled"' : ' type="submit"') + '>' +
683+ '<i>✌</i> ' + (!isPublic && upvoted ? 'Undig' : 'Dig') +
684+ '</button>' +
685+ (isPublic ? '<input type="hidden" name="vote" value="' +
670686 (upvoted ? '0' : '1') + '">' +
671687 '<input type="hidden" name="action" value="vote">' +
672688 '<input type="hidden" name="id" value="' +
673- escapeHTML(repo.id) + '">' +
674- '<button type="submit"><i>✌</i> ' +
675- (upvoted ? 'Undig' : 'Dig') +
676- '</button>') + ' ' +
689+ escapeHTML(repo.id) + '">' : '') + ' ' +
677690 '<strong>' + link(digsPath, votes.upvotes) + '</strong>' +
678691 '</form>' +
679692 renderNameForm(!isPublic, repo.id, repoName, 'repo-name', null,
680693 'Rename the repo',
@@ -1137,8 +1150,9 @@
11371150
11381151 /* Issue */
11391152
11401153 function serveRepoIssue(req, repo, issue, path) {
1154+ var isAuthor = (myId == issue.author) || (myId == repo.feed)
11411155 return renderRepoPage(repo, null, cat([
11421156 pull.once(
11431157 renderNameForm(!isPublic, issue.id, issue.title, 'issue-title', null,
11441158 'Rename the issue',
@@ -1172,34 +1186,51 @@
11721186 new Date(msg.value.timestamp).toLocaleString())
11731187 var c = msg.value.content
11741188 switch (c.type) {
11751189 case 'post':
1176- if (c.root == issue.id)
1190+ if (c.root == issue.id) {
1191+ var changed = issues.isStatusChanged(msg, issue)
11771192 return '<section class="collapse">' +
1178- authorLink + ' &middot; ' +
1179- msgTimeLink +
1193+ authorLink +
1194+ (changed == null ? '' : ' ' + (
1195+ changed ? 'reopened this issue' : 'closed this issue')) +
1196+ ' &middot; ' + msgTimeLink +
11801197 marked(c.text) +
11811198 '</section>'
1182- else
1199+ } else {
1200+ var text = c.text || (c.type + ' ' + msg.key)
11831201 return '<section class="collapse mention-preview">' +
11841202 authorLink + ' mentioned this issue in ' +
1185- link([msg.key], c.text || c.type) +
1203+ link([msg.key], String(text).substr(0, 140)) +
11861204 '</section>'
1205+ }
11871206 case 'issue-edit':
11881207 return '<section class="collapse">' +
11891208 (c.title == null ? '' :
11901209 authorLink + ' renamed this issue to <q>' +
11911210 escapeHTML(c.title) + '</q>') +
1211+ ' &middot; ' + msgTimeLink +
11921212 '</section>'
11931213 default:
11941214 return '<section class="collapse">' +
1195- authorLink + ' &middot; ' +
1196- msgTimeLink +
1215+ authorLink +
1216+ ' &middot; ' + msgTimeLink +
11971217 json(c) +
11981218 '</section>'
11991219 }
12001220 })
1201- )
1221+ ),
1222+ pull.once(isPublic ? '' : '<section><form action="" method="post">' +
1223+ '<input type="hidden" name="action" value="comment">' +
1224+ '<input type="hidden" name="id" value="' + issue.id + '">' +
1225+ '<textarea name="text" class="wide-input" rows="6" cols="69"></textarea>' +
1226+ (isAuthor ?
1227+ '<input type="submit" class="btn"' +
1228+ ' name="' + (issue.open ? 'close' : 'open') + '"' +
1229+ ' value="' + (issue.open ? 'Close issue' : 'Reopen issue') + '"' +
1230+ '/>' : '') +
1231+ '<input type="submit" class="btn open" value="Comment" />' +
1232+ '</form></section>')
12021233 ]))
12031234 }
12041235
12051236 }
package.jsonView
@@ -17,9 +17,9 @@
1717 "ssb-marked": "^0.5.4",
1818 "ssb-msg-schemas": "^6.1.0",
1919 "ssb-ref": "^2.2.2",
2020 "ssb-reconnect": "^0.1.0",
21- "ssb-issues": "^0.0.0",
21+ "ssb-issues": "^0.0.1",
2222 "stream-to-pull-stream": "^1.6.6"
2323 },
2424 "homepage": "http://git-ssb.celehner.com/%25q5d5Du%2B9WkaSdjc8aJPZm%2BjMrqgo0tmfR%2BRcX5ZZ6H4%3D.sha256",
2525 "repository": {
static/styles.cssView
@@ -90,9 +90,9 @@
9090 .repo-title .right-bar {
9191 margin-top: .25em;
9292 }
9393
94-.right-bar button {
94+.btn {
9595 font-size: 1em;
9696 border-radius: .5ex;
9797
9898 background-color: white;
@@ -100,9 +100,9 @@
100100 border-style: none solid solid none;
101101 border-radius: .5ex;
102102 cursor: pointer;
103103 }
104-.right-bar button:hover {
104+.btn:hover {
105105 background-color: #f6f6f6;
106106 }
107107
108108 .name {
@@ -212,17 +212,23 @@
212212 .issue-status {
213213 padding: .4ex .75ex;
214214 margin-right: .75ex;
215215 border-radius: .5ex;
216- color: white;
217216 }
218217
219218 .open {
220219 background-color: #38ae67;
220+ color: white;
221+ font-weight: bold;
221222 }
222223
224+.btn.open:hover {
225+ background-color: #2b9d58;
226+}
227+
223228 .closed {
224229 background-color: #d84a38;
230+ color: white;
225231 }
226232
227233 .mention-preview {
228234 overflow: hidden;

Built with git-ssb-web