11import { adoptACLDefault , getProspectiveHolder , makeACLGraphbyCombo , sameACL } from './acl'
22import { graph , NamedNode , UpdateManager } from 'rdflib'
3- import ns from '../ns'
43import { AccessGroups } from './access-groups'
54import { DataBrowserContext } from 'pane-registry'
65import { shortNameForFolder } from './acl-control'
76import utils from '../utils.js'
87
9- const ACL = ns . acl
10-
118export class AccessController {
129 public mainCombo : AccessGroups
1310 public defaultsCombo : AccessGroups | null
1411 private readonly isContainer : boolean
1512 private defaultsDiffer : boolean
16- private readonly root : HTMLElement
13+ private readonly rootElement : HTMLElement
1714 private isUsingDefaults : boolean
1815
1916 constructor (
2017 public subject : NamedNode ,
2118 public noun : string ,
2219 public context : DataBrowserContext ,
23- private status : HTMLElement ,
20+ private statusElement : HTMLElement ,
2421 public classes : Record < string , string > ,
2522 public targetIsProtected : boolean ,
2623 private targetDoc : NamedNode ,
@@ -31,8 +28,8 @@ export class AccessController {
3128 public store ,
3229 public dom
3330 ) {
34- this . root = dom . createElement ( 'div' )
35- this . root . classList . add ( classes . aclGroupContent )
31+ this . rootElement = dom . createElement ( 'div' )
32+ this . rootElement . classList . add ( classes . aclGroupContent )
3633 this . isContainer = targetDoc . uri . slice ( - 1 ) === '/' // Give default for all directories
3734 if ( defaultHolder && defaultACLDoc ) {
3835 this . isUsingDefaults = true
@@ -53,11 +50,11 @@ export class AccessController {
5350 }
5451
5552 public render ( ) : HTMLElement {
56- this . root . innerHTML = ''
53+ this . rootElement . innerHTML = ''
5754 if ( this . isUsingDefaults ) {
5855 this . renderStatus ( `The sharing for this ${ this . noun } is the default for folder ` )
5956 if ( this . defaultHolder ) {
60- const defaultHolderLink = this . status . appendChild ( this . dom . createElement ( 'a' ) )
57+ const defaultHolderLink = this . statusElement . appendChild ( this . dom . createElement ( 'a' ) )
6158 defaultHolderLink . href = this . defaultHolder . uri
6259 defaultHolderLink . innerText = shortNameForFolder ( this . defaultHolder )
6360 }
@@ -66,19 +63,19 @@ export class AccessController {
6663 } else {
6764 this . renderStatus ( '' )
6865 }
69- this . root . appendChild ( this . mainCombo . render ( ) )
66+ this . rootElement . appendChild ( this . mainCombo . render ( ) )
7067 if ( this . defaultsCombo && this . defaultsDiffer ) {
71- this . root . appendChild ( this . renderRemoveDefaultsController ( ) )
72- this . root . appendChild ( this . defaultsCombo . render ( ) )
68+ this . rootElement . appendChild ( this . renderRemoveDefaultsController ( ) )
69+ this . rootElement . appendChild ( this . defaultsCombo . render ( ) )
7370 } else if ( this . isEditable ) {
74- this . root . appendChild ( this . renderAddDefaultsController ( ) )
71+ this . rootElement . appendChild ( this . renderAddDefaultsController ( ) )
7572 }
7673 if ( ! this . targetIsProtected && this . isUsingDefaults ) {
77- this . root . appendChild ( this . renderAddAclsController ( ) )
74+ this . rootElement . appendChild ( this . renderAddAclsController ( ) )
7875 } else if ( ! this . targetIsProtected ) {
79- this . root . appendChild ( this . renderRemoveAclsController ( ) )
76+ this . rootElement . appendChild ( this . renderRemoveAclsController ( ) )
8077 }
81- return this . root
78+ return this . rootElement
8279 }
8380
8481 private renderRemoveAclsController ( ) : HTMLElement {
@@ -102,55 +99,55 @@ export class AccessController {
10299 }
103100
104101 private renderAddDefaultsController ( ) : HTMLElement {
105- const addDefaults = this . dom . createElement ( 'div' )
106- addDefaults . classList . add ( this . classes . defaultsController )
102+ const containerElement = this . dom . createElement ( 'div' )
103+ containerElement . classList . add ( this . classes . defaultsController )
107104
108- const notice = addDefaults . appendChild ( this . dom . createElement ( 'div' ) )
109- notice . innerText = 'Sharing for things within the folder currently tracks sharing for the folder.'
110- notice . classList . add ( this . classes . defaultsControllerNotice )
105+ const noticeElement = containerElement . appendChild ( this . dom . createElement ( 'div' ) )
106+ noticeElement . innerText = 'Sharing for things within the folder currently tracks sharing for the folder.'
107+ noticeElement . classList . add ( this . classes . defaultsControllerNotice )
111108
112- const button = addDefaults . appendChild ( this . dom . createElement ( 'button' ) )
109+ const button = containerElement . appendChild ( this . dom . createElement ( 'button' ) )
113110 button . innerText = 'Set the sharing of folder contents separately from the sharing for the folder'
114111 button . classList . add ( this . classes . bigButton )
115112 button . addEventListener ( 'click' , ( ) => this . addDefaults ( )
116113 . then ( ( ) => this . render ( ) ) )
117- return addDefaults
114+ return containerElement
118115 }
119116
120117 private renderRemoveDefaultsController ( ) : HTMLElement {
121- const removeDefaults = this . dom . createElement ( 'div' )
122- removeDefaults . classList . add ( this . classes . defaultsController )
118+ const containerElement = this . dom . createElement ( 'div' )
119+ containerElement . classList . add ( this . classes . defaultsController )
123120
124- const notice = removeDefaults . appendChild ( this . dom . createElement ( 'div' ) )
125- notice . innerText = 'Access to things within this folder:'
126- notice . classList . add ( this . classes . defaultsControllerNotice )
121+ const noticeElement = containerElement . appendChild ( this . dom . createElement ( 'div' ) )
122+ noticeElement . innerText = 'Access to things within this folder:'
123+ noticeElement . classList . add ( this . classes . defaultsControllerNotice )
127124
128- const button = removeDefaults . appendChild ( this . dom . createElement ( 'button' ) )
125+ const button = containerElement . appendChild ( this . dom . createElement ( 'button' ) )
129126 button . innerText = 'Set default for folder contents to just track the sharing for the folder'
130127 button . classList . add ( this . classes . bigButton )
131128 button . addEventListener ( 'click' , ( ) => this . removeDefaults ( )
132129 . then ( ( ) => this . render ( ) )
133130 . catch ( error => this . renderStatus ( error ) ) )
134- return removeDefaults
131+ return containerElement
135132 }
136133
137134 public renderTemporaryStatus ( message : string ) : void {
138135 // @@ TODO Introduce better system for error notification to user https://github.com/solid/mashlib/issues/87
139- this . status . classList . add ( this . classes . aclControlBoxStatusRevealed )
140- this . status . innerText = message
141- this . status . classList . add ( this . classes . temporaryStatusInit )
136+ this . statusElement . classList . add ( this . classes . aclControlBoxStatusRevealed )
137+ this . statusElement . innerText = message
138+ this . statusElement . classList . add ( this . classes . temporaryStatusInit )
142139 setTimeout ( ( ) => {
143- this . status . classList . add ( this . classes . temporaryStatusEnd )
140+ this . statusElement . classList . add ( this . classes . temporaryStatusEnd )
144141 } )
145142 setTimeout ( ( ) => {
146- this . status . innerText = ''
143+ this . statusElement . innerText = ''
147144 } , 5000 )
148145 }
149146
150147 public renderStatus ( message : string ) : void {
151148 // @@ TODO Introduce better system for error notification to user https://github.com/solid/mashlib/issues/87
152- this . status . classList . toggle ( this . classes . aclControlBoxStatusRevealed , ! ! message )
153- this . status . innerText = message
149+ this . statusElement . classList . toggle ( this . classes . aclControlBoxStatusRevealed , ! ! message )
150+ this . statusElement . innerText = message
154151 }
155152
156153 private async addAcls ( ) : Promise < void > {
@@ -160,7 +157,7 @@ export class AccessController {
160157 return Promise . reject ( message )
161158 }
162159 const aclGraph = adoptACLDefault ( this . targetDoc , this . targetACLDoc , this . defaultHolder , this . defaultACLDoc )
163- aclGraph . statements . forEach ( st => this . store . add ( st . subject , st . predicate as NamedNode , st . object , this . targetACLDoc ) )
160+ aclGraph . statements . forEach ( st => this . store . add ( st . subject , st . predicate , st . object , this . targetACLDoc ) )
164161 try {
165162 await this . store . fetcher . putBack ( this . targetACLDoc )
166163 this . isUsingDefaults = false
@@ -232,9 +229,9 @@ export class AccessController {
232229 this . store . fetcher . unload ( this . targetACLDoc )
233230 this . store . add ( newAClGraph . statements )
234231 this . store . fetcher . requested [ this . targetACLDoc . uri ] = 'done' // missing: save headers
235- this . mainCombo . updateStore ( this . store )
232+ this . mainCombo . store = this . store
236233 if ( this . defaultsCombo ) {
237- this . defaultsCombo . updateStore ( this . store )
234+ this . defaultsCombo . store = this . store
238235 }
239236 this . defaultsDiffer = ! ! this . defaultsCombo && ! sameACL ( this . mainCombo . aclMap , this . defaultsCombo . aclMap )
240237 console . log ( 'ACL modification: success!' )
0 commit comments