@@ -186,44 +186,48 @@ UI.widgets.loadTypeIndexes = function(context) {
186186// index.public
187187//
188188UI . widgets . ensureTypeIndexes = function ( context ) {
189- return new Promise ( function ( resolve , reject ) {
190- var kb = UI . store , tns = UI . ns , me = context . me ;
191- return UI . widgets . loadTypeIndexes ( context )
192- . then ( function ( context ) {
193- var ns = UI . ns , kb = UI . store , me = context . me ;
194- var newIndex ;
195-
196- var makeIndex = function ( visibility ) {
197- var relevant = { 'private' : context . preferencesFile , 'public' : context . publicProfile } [ visibility ] ;
198- if ( context . index [ visibility ] . length == 0 ) {
199- newIndex = $rdf . sym ( context . preferencesFile . dir ( ) . uri + '/' + visibility + 'TypeIndex.ttl' ) ;
200- console . log ( "Creating new fresh type index " + newIndex )
201- return kb . fetcher . webOperation ( 'PUT' , newIndex , { data : '# Type index' } )
202- . then ( function ( xhr ) {
203- return new Promise ( function ( resolve , reject ) {
204- var ins = [ $rdf . st ( context . me , ns . solid ( visibility + 'TypeIndex' ) , newIndex , relevant ) ] ;
205- UI . store . updater . update ( [ ] , ins , function ( uri , ok , body ) {
206- if ( ok ) {
207- context . index [ visibility ] . push ( newIndex ) ;
208- resolve ( context ) ;
209- } else {
210- reject ( "Adding link to new index file in " + relevant ) ;
211- }
212- } )
213- } ) ;
214- } )
215- . catch ( function ( e ) { reject ( "Creating new index file " + e ) } )
216- } else {
217- return Promise . resolve ( context . index [ visibility ] [ 0 ] ) ; // exists
218- }
219- }
220- var ps = [ makeIndex ( 'private' ) , makeIndex ( 'public' ) ] ;
221- Promise . all ( ps ) . then ( function ( privPub ) {
222- resolve ( context )
223- } ) ;
224- } )
225- } ) ;
226- }
189+ return new Promise ( function ( resolve , reject ) {
190+ var kb = UI . store , tns = UI . ns , me = context . me ;
191+ return UI . widgets . loadTypeIndexes ( context )
192+ . then ( function ( context ) {
193+ var ns = UI . ns , kb = UI . store , me = context . me ;
194+ var newIndex ;
195+
196+ var makeIndex = function ( context , visibility ) {
197+ return new Promise ( function ( resolve , reject ) {
198+ var relevant = { 'private' : context . preferencesFile , 'public' : context . publicProfile } [ visibility ] ;
199+ if ( context . index [ visibility ] . length == 0 ) {
200+ newIndex = $rdf . sym ( context . preferencesFile . dir ( ) . uri + visibility + 'TypeIndex.ttl' ) ;
201+ console . log ( "Linking to new fresh type index " + newIndex )
202+ addMe = [ $rdf . st ( me , ns . solid ( visibility + 'TypeIndex' ) , newIndex , relevant ) ]
203+ UI . store . updater . update ( [ ] , addMe , function ( uri , ok , body ) {
204+ if ( ! ok ) {
205+ reject ( 'Error saving type index link saving back ' + uri + ': ' + body )
206+ } else {
207+ context . index [ visibility ] . push ( newIndex )
208+ console . log ( "Creating new fresh type index " + newIndex )
209+ if ( ! confirm ( "Creating new list of things " + newIndex ) ) {
210+ reject ( 'Cancelled by user: writing of ' + newIndex )
211+ }
212+ kb . fetcher . webOperation ( 'PUT' , newIndex , { data : '# ' + new Date ( ) + ' Blank initial Type index\n' } )
213+ . then ( function ( xhr ) {
214+ resolve ( context )
215+ } )
216+ . catch ( function ( e ) { reject ( "Creating new index file " + e ) } )
217+ }
218+ } )
219+ } else {
220+ resolve ( context ) ; // exists
221+ }
222+ } ) // promise
223+ } // makeIndex
224+ var ps = [ makeIndex ( context , 'private' ) , makeIndex ( context , 'public' ) ] ;
225+ Promise . all ( ps ) . then ( function ( privPub ) {
226+ resolve ( context )
227+ } ) ;
228+ } ) // .then
229+ } ) // Promise
230+ } // ensureTypeIndexes
227231
228232// Returns promise of array of symbols
229233//
@@ -263,7 +267,7 @@ UI.widgets.registrationControl = function(context, instance, klass) {
263267 var box = dom . createElement ( 'div' ) ;
264268 context . div . appendChild ( box ) ;
265269 return UI . widgets . ensureTypeIndexes ( context )
266- . then ( function ( indexes ) {
270+ . then ( function ( context ) {
267271 box . innerHTML = '<table><tbody><tr></tr><tr></tr></tbody></table>' ; // tbody will be inserted anyway
268272 box . setAttribute ( 'style' , 'font-size: 120%; text-align: right; padding: 1em; border: solid gray 0.05em;' )
269273 var tbody = box . children [ 0 ] . children [ 0 ] ;
@@ -282,8 +286,9 @@ UI.widgets.registrationControl = function(context, instance, klass) {
282286 tbody . children [ 1 ] . appendChild ( UI . widgets . buildCheckboxForm (
283287 context . dom , UI . store , "Personal note of this " + context . noun , null , statement , form , index ) ) ;
284288 }
289+
285290 // UI.widgets.buildCheckboxForm(dom, kb, lab, del, ins, form, store)
286- resolve ( box ) ;
291+ resolve ( context ) ;
287292 } ) . catch ( function ( e ) { reject ( e ) } ) ;
288293 } )
289294}
@@ -324,7 +329,7 @@ UI.widgets.registrationList = function(context, options) {
324329 anchor . textContent = UI . utils . label ( inst )
325330 } else {
326331 var deleteInstance = function ( x ) {
327- // @@@ TBD
332+ // @@@ TBD and added to opts
328333 }
329334 var opts = { }
330335 var tr = UI . widgets . personTR ( dom , ns . solid ( 'instance' ) , inst , opts )
@@ -344,7 +349,7 @@ UI.widgets.registrationList = function(context, options) {
344349 }
345350 */
346351
347- resolve ( box ) ;
352+ resolve ( context ) ;
348353 } ) . catch ( function ( e ) { reject ( e ) } ) ;
349354 } )
350355}
0 commit comments