git ssb

30+

cel / git-ssb-web



Commit dcaef795f59bc5e84215b51bc26bbaf77972e711

first-pass refactor

mix irving committed on 11/3/2016, 7:20:47 AM
Parent: 5da7f6c737d6456f6e702d4a2fa0bee6b9217a5c

Files changed

lib/forms.jschanged
lib/repos/index.jschanged
lib/util.jschanged
lib/forms.jsView
@@ -1,4 +1,5 @@
1 +var h = require('pull-hyperscript')
12 var u = require('./util')
23 var forms = exports
34
45 forms.post = function (req, repo, placeholder, rows) {
@@ -20,28 +21,36 @@
2021 '<div class="preview-text tab2" id="preview-tab"></div>' +
2122 '<script>' + issueCommentScript + '</script>'
2223 }
2324
24-forms.name = function (req, enabled, id, name, action, inputId,
25- title, header) {
25 +forms.name = function (req, enabled, id, name, action, inputId, title, header) {
2626 if (!inputId) inputId = action
27- return '<form class="petname" action="" method="post">' +
28- (enabled ?
29- '<input type="checkbox" class="name-checkbox" id="' + inputId + '" ' +
30- 'onfocus="this.form.name.focus()" />' +
31- '<input name="name" class="name" value="' + u.escape(name) + '" ' +
32- 'onkeyup="if (event.keyCode == 27) this.form.reset()" />' +
33- '<input type="hidden" name="action" value="' + action + '">' +
34- '<input type="hidden" name="id" value="' +
35- u.escape(id) + '">' +
36- '<label class="name-toggle" for="' + inputId + '" ' +
37- 'title="' + title + '"><i>✍</i></label> ' +
38- '<input class="btn name-btn" type="submit" value="' +
39- req._t('Rename') + '">' +
40- header :
41- header + '<br clear="all"/>'
42- ) +
43- '</form>'
27 +
28 + if (!enabled) {
29 + return h('form', {class: 'petname', action: '', method: 'post'}, [
30 + header,
31 + h('br', {clear: 'all'}, [])
32 + ])
33 + }
34 +
35 + return h('form', {class: 'petname', action: '', method: 'post'}, [
36 + h('input', {
37 + type: 'checkbox', class: 'name-checkbox', id: inputId,
38 + onfocus: 'this.form.name.focus()'
39 + }, []),
40 + h('input', {
41 + class: 'name', name: 'name', value: u.escape(name),
42 + onkeyup: 'if (event.keyCode == 27) this.form.reset()'
43 + }, []),
44 + h('input', {type: 'hidden', name: 'action', value: action}, []),
45 + h('input', {type: 'hidden', name: 'id', value: u.escape(id)}, []),
46 + h('label', {class: 'name-toggle', for: inputId, title: title}, [
47 + h('i', '✍')
48 + ]),
49 + h('input', {class: 'btn name-btn', type: 'submit', value: req._t('Rename')}, []),
50 + // NB this needs an empty 3rd arg to render for some reason?
51 + header
52 + ])
4453 }
4554
4655 var issueCommentScript = '(' + function () {
4756 var $ = document.getElementById.bind(document)
lib/repos/index.jsView
@@ -14,8 +14,9 @@
1414 var ssbRef = require('ssb-ref')
1515 var zlib = require('zlib')
1616 var toPull = require('stream-to-pull-stream')
1717 var h = require('pull-hyperscript')
18 +var extend = require('xtend')
1819
1920 module.exports = function (web) {
2021 return new RepoRoutes(web)
2122 }
@@ -197,10 +198,9 @@
197198 self.web.about.getName(repo.upstream.feed, done())
198199 }
199200
200201 return u.readNext(function (cb) {
201- done(function (err, repoName, authorName, votes,
202- upstreamName, upstreamAuthorName) {
202 + done(function (err, repoName, authorName, votes, upstreamName, upstreamAuthorName) {
203203 if (err) return cb(null, self.web.serveError(req, err))
204204 var upvoted = votes.upvoters[self.web.myId] > 0
205205 var upstreamLink = !repo.upstream ? '' :
206206 u.link([repo.upstream])
@@ -208,46 +208,57 @@
208208 .replace(/%\{repo\}/g, repoName)
209209 .replace(/%\{author\}/g, authorName)
210210 : authorName + '/' + repoName
211211 var isPublic = self.web.isPublic
212 + var isPrivate = !isPublic //TODO use this with u.when(isPrivate, h())
212213 cb(null, self.web.serveTemplate(req, title)(cat([
213- pull.once(
214- '<div class="repo-title">' +
215- '<form class="right-bar" action="" method="post">' +
216- '<button class="btn" name="action" value="vote" ' +
217- (isPublic ? 'disabled="disabled"' : ' type="submit"') + '>' +
218- '<i>✌</i> ' + req._t(!isPublic && upvoted ? 'Undig' : 'Dig') +
219- '</button>' +
220- (isPublic ? '' : '<input type="hidden" name="value" value="' +
221- (upvoted ? '0' : '1') + '">' +
222- '<input type="hidden" name="id" value="' +
223- u.escape(repo.id) + '">') + ' ' +
224- '<strong>' + u.link(digsPath, votes.upvotes) + '</strong> ' +
225- (isPublic ? '' : '<button class="btn" type="submit" ' +
226- ' name="action" value="fork-prompt">' +
227- '<i>⑂</i> ' + req._t('Fork') +
228- '</button>') + ' ' +
229- u.link([repo.id, 'forks'], '+', false, ' title="' +
230- req._t('Forks') + '"') +
231- '</form>' +
232- forms.name(req, !isPublic, repo.id, repoName, 'repo-name',
233- null, req._t('repo.Rename'),
234- '<h2 class="bgslash">' + u.link([repo.feed], authorName) + ' / ' +
235- u.link([repo.id], repoName) + '</h2>') +
236- '</div>' +
237- (repo.upstream ? '<small class="bgslash">' + req._t('ForkedFrom', {
238- repo: u.link([repo.upstream.feed], upstreamAuthorName) + '/' +
239- u.link([repo.upstream.id], upstreamName)
240- }) + '</small>' : '') +
241- u.nav([
242- [[repo.id], req._t('Code'), 'code'],
243- [[repo.id, 'activity'], req._t('Activity'), 'activity'],
244- [[repo.id, 'commits', branch||''], req._t('Commits'), 'commits'],
245- [[repo.id, 'issues'], req._t('Issues'), 'issues'],
246- [[repo.id, 'pulls'], req._t('PullRequests'), 'pulls']
247- ], page, cloneUrls)),
214 + h('div', {class: 'repo-title'}, [
215 + h('form', {class: 'right-bar', action: '', method: 'post'}, [
216 + h('button',
217 + extend({class: 'btn', name: 'action', value: 'vote'},
218 + (isPublic ? {disabled: 'disabled'} : {type: 'submit'})
219 + ), [
220 + h('i', '✌'),
221 + h('span', req._t(!isPublic && upvoted ? 'Undig' : 'Dig'))
222 + ]
223 + ),
224 + (isPublic
225 + ? once('')
226 + : cat([
227 + h('input', {type: 'hidden', name: 'value', value: (upvoted ? '0' : '1')}, []),
228 + h('input', {type: 'hidden', name: 'id', value: u.escape(repo.id)}, [])
229 + ])
230 + ),
231 + h('strong', u.link(digsPath, votes.upvotes)),
232 + (isPublic
233 + ? once('')
234 + : h('button', {class: 'btn', type: 'submit', name: 'action', value: 'fork-prompt'}, [
235 + h('i', '⑂'),
236 + once(req._t('Fork'))
237 + ])
238 + ),
239 + h('a', {href: u.encodeLink([repo.id, 'forks']), title: req._t('Forks')}, '+')
240 + ]),
241 + forms.name(req, !isPublic, repo.id, repoName, 'repo-name', null, req._t('repo.Rename'),
242 + h('h2', {class: 'bgslash'}, `${u.link([repo.feed], authorName)} / ${u.link([repo.id], repoName)}`)
243 + ),
244 + ]),
245 + (!repo.upstream
246 + ? once('')
247 + : h('small', {class: 'bgslash'}, req._t('ForkedFrom', {
248 + repo: `${u.link([repo.upstream.feed], upstreamAuthorName)} / ${u.link([repo.upstream.id], upstreamName)}`
249 + }))
250 + ),
251 + u.nav([
252 + [[repo.id], req._t('Code'), 'code'],
253 + [[repo.id, 'activity'], req._t('Activity'), 'activity'],
254 + [[repo.id, 'commits', branch||''], req._t('Commits'), 'commits'],
255 + [[repo.id, 'issues'], req._t('Issues'), 'issues'],
256 + [[repo.id, 'pulls'], req._t('PullRequests'), 'pulls']
257 + ], page, cloneUrls),
248258 body
249- ])))
259 + ])
260 + ))
250261 })
251262 })
252263 }
253264
lib/util.jsView
@@ -77,14 +77,15 @@
7777 d.toLocaleString(req._locale) + '</span>'
7878 }
7979
8080 u.nav = function (links, page, after) {
81- return ['<nav>'].concat(
81 + return pull.once(['<nav>'].concat(
8282 links.map(function (link) {
8383 var href = typeof link[0] == 'string' ? link[0] : u.encodeLink(link[0])
8484 var props = link[2] == page ? ' class="active"' : ''
8585 return '<a href="' + href + '"' + props + '>' + link[1] + '</a>'
8686 }), after || '', '</nav>').join('')
87 + )
8788 }
8889
8990 u.hiddenInputs = function (values) {
9091 return Object.keys(values).map(function (key) {

Built with git-ssb-web