Skip to content

Commit 119ca85

Browse files
author
Tim Berners-Lee
committed
start writing folder delete function with UI
1 parent de2f94a commit 119ca85

4 files changed

Lines changed: 102 additions & 21 deletions

File tree

src/folders.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/** UI To Delete Folder and content
2+
*
3+
*/
4+
5+
var UI = {
6+
icons: require('./iconBase'),
7+
log: require('./log'),
8+
ns: require('./ns'),
9+
pad: require('./'),
10+
rdf: require('rdflib'),
11+
store: require('./store'),
12+
widgets: require('./widgets'),
13+
utils: require('./utils')
14+
}
15+
16+
/** Delete Folder and contents
17+
*
18+
* @param {NamedNode} folder - The LDP container to be deleted
19+
* @param {DOMElement} containingElement - Where to put the user interface
20+
* @param {IndexedForumula} store - Quadstore (optional)
21+
* @param {Document} dom - The browser 'document' gloabl or equivalent (or iuse global)
22+
* @returns {DOMElement} - The control which has eben inserted in the
23+
*/
24+
/* global document */
25+
module.exports.deleteFolder(folder, containingElement, store, dom) {
26+
store = store || UI.store
27+
if (typeof docuent !=== 'undefined') {
28+
dom = dom || document
29+
}
30+
const table = dom.createElement('table')
31+
const mainTR = table.appendChild(dom.createElement('tr'))
32+
const mainTD = mainTR.appendChild(dom.createElement('td'))
33+
34+
const p = mainTR.appendChild(dom.createElement('p'))
35+
p.textContent = `Are you sure you want to delete the folder ${folder}? This cannot be undone.`
36+
const buttonsTR = table.appendChild(dom.createElement('tr'))
37+
const buttonsTD1 = buttonsTR.appendChild(dom.createElement('td'))
38+
const buttonsTD2 = buttonsTR.appendChild(dom.createElement('td'))
39+
const buttonsTD3 = buttonsTR.appendChild(dom.createElement('td'))
40+
41+
42+
return table
43+
}

src/pad.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

2-
/// /////////////////////////////////////////////
3-
//
4-
// The pad widget
5-
//
6-
// See notepad for the main widget
2+
/** **************
3+
* Notepad Widget
4+
*/
5+
6+
/** @module UI.pad
7+
*/
78

89
const $rdf = require('rdflib')
910
var padModule = module.exports = {}
@@ -22,8 +23,11 @@ const ns = UI.ns
2223

2324
const utils = require('./utils')
2425

25-
// Figure out a random color from my webid
26-
26+
/** Figure out a random color from my webid
27+
*
28+
* @param {NamedNode} author - The author of text being displayed
29+
* @returns {String} The CSS color generated, constrained to be light for a background color
30+
*/
2731
UI.pad.lightColorHash = function (author) {
2832
var hash = function (x) { return x.split('').reduce(function (a, b) { a = ((a << 5) - a) + b.charCodeAt(0); return a & a }, 0) }
2933
return author && author.uri ? '#' + ((hash(author.uri) & 0xffffff) | 0xc0c0c0).toString(16) : '#ffffff' // c0c0c0 forces pale
@@ -64,7 +68,15 @@ UI.pad.renderPartipants = function (dom, table, padDoc, subject, me, options) {
6468
return table
6569
}
6670

67-
// Record or find an old Particpation objects
71+
/** Record, or find old, Particpation object
72+
*
73+
* A particpaption object is a place to record things specifically about
74+
* subject and the user, such as preferences, start of membership, etc
75+
* @param {Node} subject - The thing in which the participation is happening
76+
* @param {NamedNode} document - Where to record the data
77+
* @param {NamedNode} me - The logged in user
78+
*
79+
*/
6880
UI.pad.participationObject = function (subject, padDoc, me) {
6981
return new Promise(function (resolve, reject) {
7082
if (!me) {
@@ -94,15 +106,19 @@ UI.pad.participationObject = function (subject, padDoc, me) {
94106
} else {
95107
resolve(participation)
96108
}
97-
// UI.pad.renderPartipants(dom, table, padDoc, subject, me, options)
98109
})
99110
resolve(participation)
100111
}
101112
})
102113
}
103114

104-
// Record my participation and display participants
105-
//
115+
/** Record my participation and display participants
116+
*
117+
* @param {NamedNode} subject - the thing in which participation is happening
118+
* @param {NamedNode} padDoc - The document into which the particpation should be recorded
119+
* @param {DOMNode} refreshable - A DOM element whose refresh() is to be called if the change works
120+
*
121+
*/
106122
UI.pad.recordParticipation = function (subject, padDoc, refreshable) {
107123
var me = UI.authn.currentUser()
108124
if (!me) return // Not logged in

src/utils.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ function genUuid () { // http://stackoverflow.com/questions/105034/create-guid-u
105105
})
106106
}
107107

108-
// Sync a DOM table with an array of things
109-
//
110-
// table - will have a tr for each thing
111-
// things - ORDERED array of NamedNode objects
112-
// createNewRow(thing) returns a TR table row for that thing
113-
//
114-
// Tolerates out of order elements but puts new ones in order.
115-
//
108+
/** Sync a DOM table with an array of things
109+
*
110+
* @param {DomElement} table - will have a tr for each thing
111+
* @param {Array<NamedNode>} things - ORDERED array of NamedNode objects
112+
* @param {function({NamedNode})} createNewRow(thing) returns a TR table row for a new thing
113+
*
114+
* Tolerates out of order elements but puts new ones in order.
115+
*/
116116
function syncTableToArray (table, things, createNewRow) {
117117
let foundOne
118118
let row

src/widgets/index.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,30 @@ UI.widgets.field[UI.ns.ui('PhoneField').uri] =
900900
result = new $rdf.Literal(field.value)
901901
}
902902
}
903-
var is = $rdf.st(subject, property, result, store) // @@ Explicitly put the datatype in.
904-
kb.updater.update(ds, is, function (uri, ok, body) {
903+
var is = ds.map(st => $rdf.st(st.subject, st.predicate, result, st.why)) // cqn include >1 doc
904+
905+
function updateMany(ds, is, callback) {
906+
var docs = []
907+
is.forEach(st => if (!docs.includes(st.why.uri) docs.push(st.why.uri))
908+
if (docs.length === 1) return kb.updater.update(ds, is, callback)
909+
console.log('Update many: ' + docs)
910+
let doc = docs.pop()
911+
is1 = is.filter(st => st.why.uri === doc)
912+
is2 = is.filter(st => st.why.uri !== doc)
913+
ds1 = ds.filter(st => st.why.uri === doc)
914+
ds2 = ds.filter(st => st.why.uri !== doc)
915+
kb.update.update(ds1, is1, function (uri, ok, body) {
916+
if (ok) {
917+
updateMany(ds2, is2, callback)
918+
} else {
919+
console.log('Update many failed on: ' + doc)
920+
callback(uri, ok, body)
921+
}
922+
}
923+
}
924+
925+
updateMany(ds, is, function (uri, ok, body) {
926+
// kb.updater.update(ds, is, function (uri, ok, body) {
905927
if (ok) {
906928
field.disabled = false
907929
field.setAttribute('style', style)

0 commit comments

Comments
 (0)