Commit 627bb1ceef39b5cccd4915b82591d2b085d4716e
Merge remote-tracking branch 'dt/master' into git
Charles Lehner committed on 7/24/2016, 3:40:48 PMParent: e3d280e0a83dd60d5e5880b996b30782d4a68f67
Parent: bf5b79d17d7fcf89a7cb0ad35bff87d0c66f184a
Files changed
README.md | changed |
modules/avatar-profile.js | changed |
modules/index.js | changed |
modules/avatar-edit.js | added |
package.json | changed |
sbot-api.js | changed |
style.css | changed |
.gitignore | added |
bundle.js | deleted |
index.html | deleted |
README.md | ||
---|---|---|
@@ -69,8 +69,9 @@ | ||
69 | 69 | now clone and run patchboard. |
70 | 70 | ``` |
71 | 71 | git clone https://github.com/dominictarr/patchbay.git |
72 | 72 | cd patchbay |
73 | +npm intsall | |
73 | 74 | npm install electro electron-prebuilt -g |
74 | 75 | electro index.js |
75 | 76 | ``` |
76 | 77 |
modules/avatar-profile.js | ||
---|---|---|
@@ -1,13 +1,19 @@ | ||
1 | 1 | var h = require('hyperscript') |
2 | 2 | var plugs = require('../plugs') |
3 | 3 | |
4 | + | |
4 | 5 | var avatar_image = plugs.first(exports.avatar_image = []) |
6 | +var avatar_name = plugs.first(exports.avatar_name = []) | |
5 | 7 | var avatar_action = plugs.map(exports.avatar_action = []) |
8 | +var avatar_edit = plugs.first(exports.avatar_edit = []) | |
6 | 9 | |
7 | 10 | exports.avatar_profile = function (id) { |
11 | + return avatar_edit(id) | |
8 | 12 | |
9 | 13 | return h('div.row.profile', |
10 | 14 | avatar_image(id), |
11 | - h('div.column', avatar_action(id)) | |
15 | + h('div.profile__info', | |
16 | + h('strong', avatar_name(id)), | |
17 | + avatar_action(id)) | |
12 | 18 | ) |
13 | 19 | } |
modules/index.js | ||
---|---|---|
@@ -1,7 +1,8 @@ | ||
1 | 1 | module.exports = { |
2 | 2 | "_screen_view.js": require('./_screen_view.js'), |
3 | 3 | "about.js": require('./about.js'), |
4 | + "avatar-edit.js": require('./avatar-edit.js'), | |
4 | 5 | "avatar-image.js": require('./avatar-image.js'), |
5 | 6 | "avatar-profile.js": require('./avatar-profile.js'), |
6 | 7 | "avatar.js": require('./avatar.js'), |
7 | 8 | "blob-url.js": require('./blob-url.js'), |
modules/avatar-edit.js | ||
---|---|---|
@@ -1,0 +1,110 @@ | ||
1 | +var dataurl = require('dataurl') | |
2 | +var hyperfile = require('hyperfile') | |
3 | +var hypercrop = require('hypercrop') | |
4 | +var hyperlightbox = require('hyperlightbox') | |
5 | +var h = require('hyperscript') | |
6 | +var pull = require('pull-stream') | |
7 | +var getAvatar = require('ssb-avatar') | |
8 | +var plugs = require('../plugs') | |
9 | +var ref = require('ssb-ref') | |
10 | + | |
11 | +var self_id = require('../keys').id | |
12 | +var default_avatar = '&qjeAs8+uMXLlyovT4JnEpMwTNDx/QXHfOl2nv2u0VCM=.sha256' | |
13 | + | |
14 | +var confirm = plugs.first(exports.message_confirm = []) | |
15 | +var sbot_blobs_add = plugs.first(exports.sbot_blobs_add = []) | |
16 | +var blob_url = plugs.first(exports.blob_url = []) | |
17 | +var sbot_links = plugs.first(exports.sbot_links = []) | |
18 | +var avatar_name = plugs.first(exports.avatar_name = []) | |
19 | + | |
20 | +function crop (d, cb) { | |
21 | + var data | |
22 | + var canvas = hypercrop(h('img', {src: d})) | |
23 | + | |
24 | + return h('div.column.avatar_pic', | |
25 | + canvas, | |
26 | + //canvas.selection, | |
27 | + h('div.row.avatar_pic__controls', | |
28 | + h('button', 'okay', {onclick: function () { | |
29 | + cb(null, canvas.selection.toDataURL()) | |
30 | + }}), | |
31 | + h('button', 'cancel', {onclick: function () { | |
32 | + cb(new Error('canceled')) | |
33 | + }}) | |
34 | + ) | |
35 | + ) | |
36 | +} | |
37 | + | |
38 | +exports.avatar_edit = function (id) { | |
39 | + | |
40 | + var img = h('img', {src: blob_url(default_avatar)}) | |
41 | + var lb = hyperlightbox() | |
42 | + var name_input = h('input', {placeholder: 'rename'}) | |
43 | + var name = avatar_name(id) | |
44 | + var selected = null | |
45 | + | |
46 | + getAvatar({links: sbot_links}, self_id, id, function (err, avatar) { | |
47 | + if (err) return console.error(err) | |
48 | + //don't show user has already selected an avatar. | |
49 | + if(selected) return | |
50 | + if(ref.isBlob(avatar.image)) | |
51 | + img.src = blob_url(avatar.image) | |
52 | + }) | |
53 | + | |
54 | + return h('div.row.profile', | |
55 | + lb, | |
56 | + img, | |
57 | + h('div.column.profile__info', | |
58 | + h('strong', name), | |
59 | + name_input, | |
60 | + | |
61 | + hyperfile.asDataURL(function (data) { | |
62 | + var el = crop(data, function (err, data) { | |
63 | + if(data) { | |
64 | + img.src = data | |
65 | + selected = dataurl.parse(data) | |
66 | + } | |
67 | + lb.close() | |
68 | + }) | |
69 | + lb.show(el) | |
70 | + }), | |
71 | + h('button', 'update', {onclick: function () { | |
72 | + if(name_input.value) | |
73 | + name.textContent = name_input.value | |
74 | + | |
75 | + if(selected) { | |
76 | + pull( | |
77 | + pull.once(selected.data), | |
78 | + sbot_blobs_add(function (err, hash) { | |
79 | + //TODO. Alerts are EVIL. | |
80 | + //I use them only in a moment of weakness. | |
81 | + if(err) return alert(err.stack) | |
82 | + confirm({ | |
83 | + type: 'about', | |
84 | + about: id, | |
85 | + name: name_input.value || undefined, | |
86 | + image: { | |
87 | + link: hash, | |
88 | + size: selected.data.length, | |
89 | + type: selected.mimetype, | |
90 | + width: 512, | |
91 | + height: 512 | |
92 | + } | |
93 | + }) | |
94 | + }) | |
95 | + ) | |
96 | + } | |
97 | + else if(input.value) //name only | |
98 | + confirm({ | |
99 | + type: 'about', | |
100 | + about: id, | |
101 | + name: name_input.value || undefined, | |
102 | + }) | |
103 | + else | |
104 | + //another moment of weakness | |
105 | + alert('must select a name or image') | |
106 | + }}) | |
107 | + ) | |
108 | + ) | |
109 | +} | |
110 | + |
package.json | ||
---|---|---|
@@ -1,17 +1,20 @@ | ||
1 | 1 | { |
2 | 2 | "name": "patchbay", |
3 | 3 | "description": "a pluggable patchwork", |
4 | - "version": "1.8.4", | |
4 | + "version": "1.9.1", | |
5 | 5 | "homepage": "https://github.com/dominictarr/patchbay", |
6 | 6 | "repository": { |
7 | 7 | "type": "git", |
8 | 8 | "url": "git://github.com/dominictarr/patchbay.git" |
9 | 9 | }, |
10 | 10 | "dependencies": { |
11 | 11 | "cont": "^1.0.3", |
12 | + "dataurl": "^0.1.0", | |
12 | 13 | "depject": "^1.0.1", |
13 | - "hyperlightbox": "^0.1.0", | |
14 | + "hypercrop": "^1.0.1", | |
15 | + "hyperfile": "^1.1.0", | |
16 | + "hyperlightbox": "^0.1.1", | |
14 | 17 | "hyperscript": "^1.4.7", |
15 | 18 | "hypertabs": "^1.2.0", |
16 | 19 | "mime-types": "^2.1.11", |
17 | 20 | "moment": "^2.13.0", |
@@ -37,9 +40,9 @@ | ||
37 | 40 | "brfs": "^1.4.3", |
38 | 41 | "indexhtmlify": "^1.2.1" |
39 | 42 | }, |
40 | 43 | "scripts": { |
41 | - "build": "node build.js > modules/index.js && browserify -t brfs index.js > bundle.js && indexhtmlify < bundle.js > index.html", | |
44 | + "build": "node build.js > modules/index.js && mkdir -p build && browserify -t brfs index.js > build/bundle.js && indexhtmlify < build/bundle.js > build/index.html", | |
42 | 45 | "graph": "node index.js | dot -Tsvg > graph.svg", |
43 | 46 | "test": "set -e; for t in test/*.js; do node $t; done" |
44 | 47 | }, |
45 | 48 | "author": "Dominic Tarr <dominic.tarr@gmail.com> (http://dominictarr.com)", |
sbot-api.js | ||
---|---|---|
@@ -68,9 +68,22 @@ | ||
68 | 68 | |
69 | 69 | return { |
70 | 70 | sbot_blobs_add: rec.sink(function (cb) { |
71 | 71 | return pull( |
72 | - Hash(cb), | |
72 | + Hash(function (err, id) { | |
73 | + if(err) return cb(err) | |
74 | + //completely UGLY hack to tell when the blob has been sucessfully written... | |
75 | + var start = Date.now(), n = 5 | |
76 | + ;(function next () { | |
77 | + setTimeout(function () { | |
78 | + sbot.blobs.has(id, function (err, has) { | |
79 | + if(has) return cb(null, id) | |
80 | + if(n--) next() | |
81 | + else cb(new Error('write failed')) | |
82 | + }) | |
83 | + }, Date.now() - start) | |
84 | + })() | |
85 | + }), | |
73 | 86 | sbot.blobs.add() |
74 | 87 | ) |
75 | 88 | }), |
76 | 89 | sbot_links: rec.source(function (query) { |
@@ -108,4 +121,6 @@ | ||
108 | 121 | }) |
109 | 122 | } |
110 | 123 | } |
111 | 124 | |
125 | + | |
126 | + |
style.css | ||
---|---|---|
@@ -1,8 +1,10 @@ | ||
1 | 1 | body { |
2 | 2 | font-family: "Source Sans Pro", sans-serif; |
3 | 3 | } |
4 | 4 | |
5 | +p { margin-top: .35ex;} | |
6 | + | |
5 | 7 | .screen { |
6 | 8 | position: absolute; |
7 | 9 | top: 0px; bottom: 0px; |
8 | 10 | left: 0px; right: 0px; |
@@ -125,9 +127,9 @@ | ||
125 | 127 | /* messages */ |
126 | 128 | |
127 | 129 | .message { |
128 | 130 | border: 1px solid #eee; |
129 | - padding: 5px; | |
131 | + padding: 7px; | |
130 | 132 | margin-top: .5em; |
131 | 133 | background: white; |
132 | 134 | display: block; |
133 | 135 | flex-basis: 0; |
@@ -212,19 +214,22 @@ | ||
212 | 214 | } |
213 | 215 | |
214 | 216 | .profile { |
215 | 217 | background: #fff; |
218 | + padding: .5em; | |
216 | 219 | border: 1px solid #eee; |
217 | 220 | } |
218 | 221 | |
219 | 222 | .profile img { |
220 | - width: 150px; | |
221 | - height: 150px; | |
222 | - margin-right: 1em; | |
223 | - margin-bottom: 1em; | |
224 | - border: 1px solid #ccc; | |
223 | + width: 256px; | |
224 | + height: 256px; | |
225 | + border: 1px solid #eee; | |
225 | 226 | } |
226 | 227 | |
228 | +.profile__info { | |
229 | + margin-left: .5em; | |
230 | +} | |
231 | + | |
227 | 232 | /* lightbox - used in message-confirm */ |
228 | 233 | |
229 | 234 | .lightbox { |
230 | 235 | overflow: auto; |
@@ -263,4 +268,9 @@ | ||
263 | 268 | highlight { |
264 | 269 | background: yellow; |
265 | 270 | } |
266 | 271 | |
272 | +/* avatar editor */ | |
273 | + | |
274 | +.hypercrop__canvas { | |
275 | + width: 100%; | |
276 | +} |
bundle.js | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 2054582 bytes New file size: 0 bytes |
index.html | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 2054809 bytes New file size: 0 bytes |
Built with git-ssb-web