1717 * * `containers` An array of nodes of containers of instances
1818 * * `div` A DOM element where UI can be displayed
1919 * * `statusArea` A DOM element (opt) progress stuff can be displayed, or error messages
20+ * *
21+ * * Vocabulary: "load" loads a file if it exists;
22+ * * 'Ensure" CREATES the file if it does not exist (if it can) and then loads it.
2023 * @packageDocumentation
2124 */
2225import { PaneDefinition } from 'pane-registry'
23- import { BlankNode , IndexedFormula , NamedNode , st , Statement } from 'rdflib'
26+ import { BlankNode , NamedNode , st , Statement } from 'rdflib'
2427// eslint-disable-next-line camelcase
2528import { Quad_Object } from 'rdflib/lib/tf-types'
2629import { AppDetails , AuthenticationContext , loadIndex , authn , authSession , CrossOriginForbiddenError , ensureTypeIndexes , FetchError , getSuggestedIssuers , NotFoundError , offlineTestID , SameOriginForbiddenError , solidLogicSingleton , UnauthorizedError } from 'solid-logic'
@@ -247,107 +250,118 @@ export async function findAppInstances (
247250/**
248251 * UI to control registration of instance
249252 */
250- export function registrationControl (
253+ export async function registrationControl (
251254 context : AuthenticationContext ,
252255 instance ,
253256 theClass
254257) : Promise < AuthenticationContext | void > {
255258 const dom = context . dom
256259 if ( ! dom || ! context . div ) {
257- return Promise . resolve ( )
260+ return context
258261 }
259262 const box = dom . createElement ( 'div' )
260263 context . div . appendChild ( box )
264+ context . me = authn . currentUser ( ) // @@
265+ if ( ! context . me ) {
266+ box . innerHTML = '<p style="margin:2em;">(Log in to save a link to this)</p>'
267+ return context
268+ }
261269
262- return ensureTypeIndexes ( context )
263- . then ( function ( ) {
264- box . innerHTML = '<table><tbody><tr></tr><tr></tr></tbody></table>' // tbody will be inserted anyway
265- box . setAttribute ( 'style' , 'font-size: 120%; text-align: right; padding: 1em; border: solid gray 0.05em;' )
266- const tbody = box . children [ 0 ] . children [ 0 ]
267- const form = new BlankNode ( ) // @@ say for now
268-
269- const registrationStatements = function ( index ) {
270- const registrations = solidLogicSingleton . getRegistrations ( instance , theClass )
271- const reg = registrations . length
272- ? registrations [ 0 ]
273- : widgets . newThing ( index )
274- return [
275- st ( reg , ns . solid ( 'instance' ) , instance , index ) ,
276- st ( reg , ns . solid ( 'forClass' ) , theClass , index )
277- ]
278- }
270+ let context2 // @@ const
271+ try {
272+ context2 = await ensureTypeIndexes ( context )
273+ } catch ( e ) {
274+ let msg
275+ if ( context . div && context . preferencesFileError ) {
276+ msg = '(Preferences not available)'
277+ context . div . appendChild ( dom . createElement ( 'p' ) ) . textContent = msg
278+ } else if ( context . div ) {
279+ msg = `registrationControl: Type indexes not available: ${ e } `
280+ context . div . appendChild ( widgets . errorMessageBlock ( context . dom , e ) )
281+ }
282+ debug . log ( msg )
283+ }
279284
280- let index , statements
281-
282- if ( context . index && context . index . public && context . index . public . length > 0 ) {
283- index = context . index . public [ 0 ]
284- statements = registrationStatements ( index )
285- tbody . children [ 0 ] . appendChild (
286- widgets . buildCheckBoxForm (
287- context . dom ,
288- solidLogicSingleton . store ,
289- `Public link to this ${ context . noun } ` ,
290- null ,
291- statements ,
292- form ,
293- index
294- )
285+ box . innerHTML = '<table><tbody><tr></tr><tr></tr></tbody></table>' // tbody will be inserted anyway
286+ box . setAttribute ( 'style' , 'font-size: 120%; text-align: right; padding: 1em; border: solid gray 0.05em;' )
287+ const tbody = box . children [ 0 ] . children [ 0 ]
288+ const form = new BlankNode ( ) // @@ say for now
289+
290+ const registrationStatements = function ( index ) {
291+ const registrations = solidLogicSingleton . getRegistrations ( instance , theClass )
292+ const reg = registrations . length
293+ ? registrations [ 0 ]
294+ : widgets . newThing ( index )
295+ return [
296+ st ( reg , ns . solid ( 'instance' ) , instance , index ) ,
297+ st ( reg , ns . solid ( 'forClass' ) , theClass , index )
298+ ]
299+ }
300+
301+ let index , statements
302+
303+ try {
304+ if ( context2 . index && context2 . index . public && context2 . index . public . length > 0 ) {
305+ index = context2 . index . public [ 0 ]
306+ statements = registrationStatements ( index )
307+ tbody . children [ 0 ] . appendChild (
308+ widgets . buildCheckboxForm (
309+ context2 . dom ,
310+ solidLogicSingleton . store ,
311+ `Public link to this ${ context2 . noun } ` ,
312+ null ,
313+ statements ,
314+ form ,
315+ index
295316 )
296- }
317+ )
318+ }
297319
298- if ( context . index && context . index . private && context . index . private . length > 0 ) {
299- index = context . index . private [ 0 ]
300- statements = registrationStatements ( index )
301- tbody . children [ 1 ] . appendChild (
302- widgets . buildCheckBoxForm (
303- context . dom ,
304- solidLogicSingleton . store ,
305- `Personal note of this ${ context . noun } ` ,
306- null ,
307- statements ,
308- form ,
309- index
310- )
320+ if ( context2 . index && context2 . index . private && context2 . index . private . length > 0 ) {
321+ index = context2 . index . private [ 0 ]
322+ statements = registrationStatements ( index )
323+ tbody . children [ 1 ] . appendChild (
324+ widgets . buildCheckboxForm (
325+ context2 . dom ,
326+ solidLogicSingleton . store ,
327+ `Personal note of this ${ context2 . noun } ` ,
328+ null ,
329+ statements ,
330+ form ,
331+ index
311332 )
312- }
313- return context
314- } ,
315- function ( e ) {
316- let msg
317- if ( context . div && context . preferencesFileError ) {
318- msg = '(Preferences not available)'
319- context . div . appendChild ( dom . createElement ( 'p' ) ) . textContent = msg
320- } else if ( context . div ) {
321- msg = `registrationControl: Type indexes not available: ${ e } `
322- context . div . appendChild ( widgets . errorMessageBlock ( context . dom , e ) )
323- }
324- debug . log ( msg )
333+ )
325334 }
326- )
327- . catch ( function ( e ) {
328- const msg = `registrationControl: Error making panel: ${ e } `
329- if ( context . div ) {
330- context . div . appendChild ( widgets . errorMessageBlock ( context . dom , e ) )
331- }
332- debug . log ( msg )
333- } )
335+ } catch ( e ) {
336+ const msg = `registrationControl: Error making panel: ${ e } `
337+ if ( context . div ) {
338+ context . div . appendChild ( widgets . errorMessageBlock ( context . dom , e ) )
339+ }
340+ debug . log ( msg )
341+ }
342+ return context2
334343}
335344
336345/**
337346 * UI to List at all registered things
338347 */
339- export function registrationList ( context : AuthenticationContext , options : {
348+ export async function registrationList ( context0 : AuthenticationContext , options : {
340349 private ?: boolean
341350 public ?: boolean
342351 type ?: NamedNode
343352 } ) : Promise < AuthenticationContext > {
344- const dom = context . dom as HTMLDocument
345- const div = context . div as HTMLElement
353+ const dom = context0 . dom as HTMLDocument
354+ const div = context0 . div as HTMLElement
346355
347356 const box = dom . createElement ( 'div' )
348357 div . appendChild ( box )
358+ context0 . me = authn . currentUser ( ) // @@
359+ if ( ! context0 . me ) {
360+ box . innerHTML = '<p style="margin:2em;">(Log in list your stuff)</p>'
361+ return context0
362+ }
349363
350- return ensureTypeIndexes ( context ) . then ( _indexes => {
364+ return ensureTypeIndexes ( context0 ) . then ( context => {
351365 box . innerHTML = '<table><tbody></tbody></table>' // tbody will be inserted anyway
352366 box . setAttribute ( 'style' , 'font-size: 120%; text-align: right; padding: 1em; border: solid #eee 0.5em;' )
353367 const table = box . firstChild as HTMLElement
@@ -356,10 +370,10 @@ export function registrationList (context: AuthenticationContext, options: {
356370 let sts : Statement [ ] = [ ]
357371 const vs = [ 'private' , 'public' ]
358372 vs . forEach ( function ( visibility ) {
359- if ( context . index && options [ visibility ] ) {
373+ if ( context . index && context . index [ visibility ] . length > 0 && options [ visibility ] ) {
360374 ix = ix . concat ( context . index [ visibility ] [ 0 ] )
361375 sts = sts . concat (
362- ( solidLogicSingleton . store as unknown as IndexedFormula ) . statementsMatching (
376+ solidLogicSingleton . store . statementsMatching (
363377 undefined ,
364378 ns . solid ( 'instance' ) ,
365379 undefined ,
0 commit comments