forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomePane.js
More file actions
216 lines (188 loc) · 7.44 KB
/
homePane.js
File metadata and controls
216 lines (188 loc) · 7.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/* Home Pane
**
** The home pane is avaiable everywhere and allows a user
** to
** - keep track of their stuff
** - make new things, and possibly
** - keep track of accounts and workspaces etc
**
*/
var UI = require('solid-ui')
module.exports = {
icon: UI.icons.iconBase + 'noun_547570.svg', // noun_25830
name: 'home',
// Does the subject deserve an home pane?
//
// yes, always!
//
label: function (subject) {
return "home"
},
render: function (subject, dom) {
// ////////////////////////////////////////////////////////////////////////////
var complain = function complain (message) {
var pre = dom.createElement('pre')
pre.setAttribute('style', 'background-color: pink')
div.appendChild(pre)
pre.appendChild(dom.createTextNode(message))
}
var newThingUI = function(context) {
var genericMaker = function(event, tool){
}
var toolIcons = [
{ icon: 'noun_339237.svg', maker: genericMaker, paneName: 'contact', hint: 'Make an address book', limit: 1 },
{ icon: 'noun_346777.svg', maker: genericMaker, paneName: 'schedule', hint: 'Make a poll to schedule a meeting'},
{ icon: 'noun_79217.svg', maker: genericMaker, paneName: 'pad', hint: 'Make a shared notepad'},
{ icon: 'noun_346319.svg', maker: genericMaker, paneName: 'chat', limit:1, hint: 'Create a chat channel'},
{ icon: 'noun_17020.svg', maker: genericMaker, paneName: 'issue', hint: 'Make an issue tracker'},
{ icon: 'noun_66617.svg', maker: genericMaker, paneName: 'meeting', hint: 'Make a new meeting', disabled: false}
] // 'noun_66617.svg'
var iconStyle = 'padding: 1em; width: 3em; height: 3em;'
var star = context.div.appendChild(dom.createElement('img'))
var visible = false; // the inividual tools tools
star.setAttribute('src', UI.icons.iconBase + 'noun_272948.svg')
star.setAttribute('style', iconStyle)
star.setAttribute('title', 'Add another tool to the meeting')
var selectNewTool = function(event){
visible = !visible
star.setAttribute('style', iconStyle + (visible? 'background-color: yellow;': ''));
styleTheIcons(visible? '' : 'display: none;')
}
star.addEventListener('click', selectNewTool)
var resetIcons = function(){
star.setAttribute('style', iconStyle)
}
var makeNewAppInstance = function (options) {
return new Promise(function(resolve, reject){
var kb = UI.store
var callbackWS = function(ws, newBase){
var newPaneOptions = {
newBase: newBase,
workspace: ws,
pane: options.pane
}
for (opt in options) {// get div, dom, me
newPaneOptions[opt] = options[opt]
}
options.pane.mintNew(newPaneOptions).then(function (newPaneOptions) {
var p = options.div.appendChild(dom.createElement('p'))
var newInstance
p.setAttribute('style', 'font-size: 120%;')
// Make link to new thing
p.innerHTML =
"Your <a target='_blank' href='" + newPaneOptions.newInstance.uri + "'><b>new " + options.noun + "</b></a> is ready to be set up. " +
"<br/><br/><a target='_blank' href='" + newPaneOptions.newInstance.uri + "'>Go to your new " + options.noun + ".</a>"
selectUI.parentNode.removeChild(selectUI) // Clean up
selectNewTool() // toggle star to plain and menu vanish again
}).catch(function (err) {
complain(err)
reject(err)
})
}
var pa = options.pane
options.appPathSegment = 'edu.mit.solid.pane.' + pa.name
options.noun = pa.mintClass ? UI.utils.label(pa.mintClass) : ( pa.name + ' @@' )
var selectUI = UI.widgets.selectWorkspace(dom, options, callbackWS)
options.div.appendChild(selectUI)
})
}
var iconArray = []
for (var pn in UI.panes){
var pane = UI.panes[pn]
if (pane.mintNew){
var icon = context.div.appendChild(dom.createElement('img'))
icon.setAttribute('src', pane.icon)
var noun = pane.mintClass ? UI.utils.label(pane.mintClass) : ( pane.name + ' @@' )
icon.setAttribute('title', 'Make new ' + noun)
icon.setAttribute('style', iconStyle + "display: none;")
iconArray.push(icon)
var foo = function(pane, icon, noun){
var iconEle = icon
var thisPane = pane
var thisNoun = noun
if (!icon.disabled){
icon.addEventListener('click', function(e){
selectTool(iconEle)
options = {event: e, iconEle:
iconEle, pane: thisPane,
noun: thisNoun,
noIndexHTML: true, // do NOT @@ for now write a HTML file
div: context.div,
me: context.me,
dom: context.dom}
makeNewAppInstance(options)
})
}
}// foo
foo(pane, icon, noun)
}
}
/*
for (var i=0; i< toolIcons.length; i++){
var foo = function() {
var tool = toolIcons[i]
var icon = context.div.appendChild(dom.createElement('img'))
icon.setAttribute('src', UI.icons.iconBase + tool.icon)
icon.setAttribute('title', tool.hint)
icon.setAttribute('style', iconStyle + "display: none;")
iconArray.push(icon)
icon.tool = tool
var maker = toolIcons[i].maker
if (!tool.disabled){
icon.addEventListener('click', function(e){
maker(e, tool)
})
}
}
foo()
}
*/
var styleTheIcons = function(style){
for (var i=0; i<iconArray.length; i++){
var st = iconStyle + style
if (toolIcons[i].disabled){
st += 'opacity: 0.3;'
}
iconArray[i].setAttribute('style', st) // eg 'background-color: #ccc;'
}
}
var resetTools = function(){
styleTheIcons('display: none;')
star.setAttribute('style', iconStyle)
}
var selectTool = function(icon){
styleTheIcons('display: none;') // 'background-color: #ccc;'
icon.setAttribute('style', iconStyle + 'background-color: yellow;')
}
}
var showContent = function(){
var context = {div: div, dom: dom, statusArea: div, me: me}
div.appendChild(dom.createElement('h4')).textContent = 'Private:'
UI.widgets.registrationList(context, { private: true}).then(function(context){
div.appendChild(dom.createElement('h4')).textContent = 'Public:'
UI.widgets.registrationList(context, { public: true}).then(function(context){
div.appendChild(dom.createElement('h4')).textContent = 'Make a new tool'
newThingUI(context)
})
})
}
var thisPane = this
var kb = UI.store
var ns = UI.ns
var div = dom.createElement('div')
var me = tabulator.preferences.get('me')
me = me? kb.sym(me) : null
if (!me) {
console.log('Waiting to find out id user users to access ' + subject.doc())
UI.widgets.checkUser(subject.doc(), function (webid) {
me = kb.sym(webid)
console.log('Got user id: ' + me)
showContent()
})
} else {
showContent()
}
return div
}
} // pane object
// ends