@@ -26,15 +26,19 @@ import { PaneDefinition } from 'pane-registry'
2626import { BlankNode , NamedNode , st , Statement } from 'rdflib'
2727// eslint-disable-next-line camelcase
2828import { Quad_Object } from 'rdflib/lib/tf-types'
29- import { AppDetails , AuthenticationContext , loadIndex , authn , authSession , CrossOriginForbiddenError , ensureTypeIndexes , FetchError , getSuggestedIssuers , NotFoundError , offlineTestID , SameOriginForbiddenError , solidLogicSingleton , UnauthorizedError } from 'solid-logic'
29+ import { AppDetails , AuthenticationContext , loadIndex , authn , authSession ,
30+ CrossOriginForbiddenError , ensureTypeIndexes , FetchError , getSuggestedIssuers ,
31+ discovery ,
32+ NotFoundError , offlineTestID , SameOriginForbiddenError , solidLogicSingleton , UnauthorizedError } from 'solid-logic'
3033import * as debug from '../debug'
3134import { alert } from '../log'
3235import * as ns from '../ns.js'
3336import { Signup } from '../signup/signup.js'
3437import { buttonStyle , commentStyle , textInputStyle } from '../style'
3538import { utils } from '../utils/index'
3639import * as widgets from '../widgets'
37-
40+ const { getScopedAppInstances, getAppInstances, registerInstanceInTypeIndex } = discovery
41+ const store = solidLogicSingleton . store
3842/**
3943 * Resolves with the logged in user's WebID
4044 *
@@ -187,8 +191,9 @@ export async function findAppInstances (
187191 // console.log('found public & private app instance', context)
188192 return context
189193 }
190-
191194 // Loading preferences is more than loading profile
195+
196+ console . log ( '@@ 192 ' , JSON . stringify ( context ) )
192197 try {
193198 // console.log('calling logInLoad', isPublic)
194199 await ( isPublic
@@ -205,30 +210,39 @@ export async function findAppInstances (
205210 } catch ( err ) {
206211 debug . error ( err )
207212 }
213+ console . log ( '@@ 209 ' , JSON . stringify ( context ) )
214+
208215 const index = context . index as { [ key : string ] : Array < NamedNode > }
209216 const thisIndex = index [ visibility ]
217+ console . log ( '@@ ' , visibility , ' thisIndex ' , JSON . stringify ( thisIndex ) )
218+
210219 const registrations = thisIndex
211220 . map ( ix => solidLogicSingleton . store . each ( undefined , ns . solid ( 'forClass' ) , theClass , ix ) )
212221 . reduce ( ( acc , curr ) => acc . concat ( curr ) , [ ] )
213222 const instances = registrations
214223 . map ( reg => solidLogicSingleton . store . each ( reg as NamedNode , ns . solid ( 'instance' ) ) )
215224 . reduce ( ( acc , curr ) => acc . concat ( curr ) , [ ] )
225+ console . log ( '@@ ' , visibility , ' context.index ' , JSON . stringify ( context . index ) )
226+
216227 const containers = registrations
217228 . map ( reg => solidLogicSingleton . store . each ( reg as NamedNode , ns . solid ( 'instanceContainer' ) ) )
218229 . reduce ( ( acc , curr ) => acc . concat ( curr ) , [ ] )
219-
230+ console . log ( '@@ ' , visibility , ' instances ' , JSON . stringify ( instances ) )
220231 function unique ( arr : NamedNode [ ] ) : NamedNode [ ] {
221232 return Array . from ( new Set ( arr ) )
222233 }
223234 context . instances = context . instances || [ ]
224235 context . instances = unique ( context . instances . concat ( instances as NamedNode [ ] ) )
225-
236+ console . log ( '@@ ' , visibility , ' context.index ' , JSON . stringify ( context . index ) )
237+ console . log ( '@@ ' , visibility , ' instances 3 ' , JSON . stringify ( context . instances ) )
226238 context . containers = context . containers || [ ]
227239 context . containers = unique ( context . containers . concat ( containers as NamedNode [ ] ) )
228240 if ( ! containers . length ) {
229241 return context
230242 }
231243 // If the index gives containers, then look up all things within them
244+ console . log ( '@@ CONTAINERS ' , JSON . stringify ( containers ) )
245+
232246 try {
233247 await solidLogicSingleton . load ( containers as NamedNode [ ] )
234248 } catch ( err ) {
@@ -266,14 +280,15 @@ export async function registrationControl (
266280 box . innerHTML = '<p style="margin:2em;">(Log in to save a link to this)</p>'
267281 return context
268282 }
283+ const user = context . me
269284
270- let context2 // @@ const
285+ let scopes // @@ const
271286 try {
272- context2 = await ensureTypeIndexes ( context )
287+ scopes = loadAllTypeIndexes ( store , me )
273288 } catch ( e ) {
274289 let msg
275290 if ( context . div && context . preferencesFileError ) {
276- msg = '(Preferences not available)'
291+ msg = '(Lists of stuff not available)'
277292 context . div . appendChild ( dom . createElement ( 'p' ) ) . textContent = msg
278293 } else if ( context . div ) {
279294 msg = `registrationControl: Type indexes not available: ${ e } `
@@ -282,12 +297,12 @@ export async function registrationControl (
282297 debug . log ( msg )
283298 }
284299
285- box . innerHTML = '<table><tbody><tr></tr><tr></tr>< /tbody></table>' // tbody will be inserted anyway
300+ box . innerHTML = '<table><tbody></tbody></table>' // tbody will be inserted anyway
286301 box . setAttribute ( 'style' , 'font-size: 120%; text-align: right; padding: 1em; border: solid gray 0.05em;' )
287302 const tbody = box . children [ 0 ] . children [ 0 ]
288303 const form = new BlankNode ( ) // @@ say for now
289304
290- const registrationStatements = function ( index ) {
305+ function registrationStatements ( index ) {
291306 const registrations = solidLogicSingleton . getRegistrations ( instance , theClass )
292307 const reg = registrations . length
293308 ? registrations [ 0 ]
@@ -298,23 +313,33 @@ export async function registrationControl (
298313 ]
299314 }
300315
301- let index , statements
316+ function renderScope ( scope ) {
317+ const statements = registrationStatements ( scope . index )
318+ const name = scope . agent . sameTerm ( me ) ? '' : label ( scope . agent ) + ' '
319+ widgets . buildCheckboxForm (
320+ context2 . dom ,
321+ solidLogicSingleton . store ,
322+ `${ name } ${ scope . label } link to this ${ context2 . noun } ` ,
323+ null ,
324+ statements ,
325+ form ,
326+ scope . index
327+ )
328+ }
302329
330+ for const scope of scopes {
331+ const row = tbody . appendChild ( dom . createElement ( 'tr' ) )
332+ row . appendChild ( renderScope ( scope ) ) // @@ index
333+ }
334+ /*
303335 try {
304336 if (context2.index && context2.index.public && context2.index.public.length > 0) {
305337 index = context2.index.public[0]
338+
339+
306340 statements = registrationStatements(index)
307341 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
316- )
317- )
342+
318343 }
319344
320345 if (context2.index && context2.index.private && context2.index.private.length > 0) {
@@ -339,6 +364,7 @@ export async function registrationControl (
339364 }
340365 debug.log(msg)
341366 }
367+ */
342368 return context2
343369}
344370
@@ -361,67 +387,67 @@ export async function registrationList (context0: AuthenticationContext, options
361387 return context0
362388 }
363389
364- return ensureTypeIndexes ( context0 ) . then ( context => {
365- box . innerHTML = '<table><tbody></tbody></table>' // tbody will be inserted anyway
366- box . setAttribute ( 'style' , 'font-size: 120%; text-align: right; padding: 1em; border: solid #eee 0.5em;' )
367- const table = box . firstChild as HTMLElement
368-
369- let ix : Array < NamedNode > = [ ]
370- let sts : Statement [ ] = [ ]
371- const vs = [ 'private' , 'public' ]
372- vs . forEach ( function ( visibility ) {
373- if ( context . index && context . index [ visibility ] . length > 0 && options [ visibility ] ) {
374- ix = ix . concat ( context . index [ visibility ] [ 0 ] )
375- sts = sts . concat (
376- solidLogicSingleton . store . statementsMatching (
377- undefined ,
378- ns . solid ( 'instance' ) ,
379- undefined ,
380- context . index [ visibility ] [ 0 ]
381- )
390+ const scopes = loadAllTypeIndexes ( store , me ) // includes community indexes
391+
392+ box . innerHTML = '<table><tbody></tbody></table>' // tbody will be inserted anyway
393+ box . setAttribute ( 'style' , 'font-size: 120%; text-align: right; padding: 1em; border: solid #eee 0.5em;' )
394+ const table = box . firstChild as HTMLElement
395+
396+ let ix : Array < NamedNode > = [ ]
397+ let sts : Statement [ ] = [ ]
398+ scopes . forEach ( function ( scope ) {
399+ if ( context . index && context . index [ visibility ] . length > 0 && options [ visibility ] ) {
400+ ix = ix . concat ( context . index [ visibility ] [ 0 ] )
401+ sts = sts . concat (
402+ solidLogicSingleton . store . statementsMatching (
403+ undefined ,
404+ ns . solid ( 'instance' ) ,
405+ undefined ,
406+ scope . index
382407 )
383- }
384- } )
408+ )
409+ }
410+ } )
385411
386- for ( let i = 0 ; i < sts . length ; i ++ ) {
387- const statement : Statement = sts [ i ]
388- if ( options . type ) { // now check terms:forClass
389- if ( ! solidLogicSingleton . store . holds ( statement . subject , ns . solid ( 'forClass' ) , options . type , statement . why ) ) {
390- continue // skip irrelevant ones
391- }
412+ for ( let i = 0 ; i < sts . length ; i ++ ) {
413+ const statement : Statement = sts [ i ]
414+ if ( options . type ) { // now check terms:forClass
415+ if ( ! solidLogicSingleton . store . holds ( statement . subject , ns . solid ( 'forClass' ) , options . type , statement . why ) ) {
416+ continue // skip irrelevant ones
392417 }
393- // const cla = statement.subject
394- const inst = statement . object
395- table . appendChild ( widgets . personTR ( dom , ns . solid ( 'instance' ) , inst , {
396- deleteFunction : function ( _x ) {
397- if ( ! solidLogicSingleton . store . updater ) {
398- throw new Error ( 'Cannot delete this, store has no updater' )
399- }
400- solidLogicSingleton . store . updater . update ( [ statement ] , [ ] , function ( uri , ok , errorBody ) {
401- if ( ok ) {
402- debug . log ( `Removed from index: ${ statement . subject } ` )
403- } else {
404- debug . log ( `Error: Cannot delete ${ statement } : ${ errorBody } ` )
405- }
406- } )
407- }
408- } ) )
409- } // registrationList
410-
411- /*
412- //const containers = solidLogicSingleton.store.each(theClass, ns.solid('instanceContainer'));
413- if (containers.length) {
414- fetcher.load(containers).then(function(xhrs){
415- for (const i=0; i<containers.length; i++) {
416- const cont = containers[i];
417- instances = instances.concat(solidLogicSingleton.store.each(cont, ns.ldp('contains')));
418- }
419- });
418+ }
419+ // const cla = statement.subject
420+ const inst = statement . object
421+ table . appendChild ( widgets . personTR ( dom , ns . solid ( 'instance' ) , inst , {
422+ deleteFunction : function ( _x ) {
423+ if ( ! solidLogicSingleton . store . updater ) {
424+ throw new Error ( 'Cannot delete this, store has no updater' )
420425 }
421- */
426+ solidLogicSingleton . store . updater . update ( [ statement ] , [ ] , function ( uri , ok , errorBody ) {
427+ if ( ok ) {
428+ debug . log ( `Removed from index: ${ statement . subject } ` )
429+ } else {
430+ debug . log ( `Error: Cannot delete ${ statement } : ${ errorBody } ` )
431+ }
432+ } )
433+ }
434+ } ) )
435+ } // registrationList
436+
437+ /*
438+ //const containers = solidLogicSingleton.store.each(theClass, ns.solid('instanceContainer'));
439+ if (containers.length) {
440+ fetcher.load(containers).then(function(xhrs){
441+ for (const i=0; i<containers.length; i++) {
442+ const cont = containers[i];
443+ instances = instances.concat(solidLogicSingleton.store.each(cont, ns.ldp('contains')));
444+ }
445+ });
446+ }
447+ */
448+
449+ return context
422450
423- return context
424- } )
425451}
426452
427453function getDefaultSignInButtonStyle ( ) : string {
0 commit comments