Skip to content

Commit 10f9df7

Browse files
committed
Renaming variables that refers to HTML Elements + changing updateStore
1 parent 15e6810 commit 10f9df7

3 files changed

Lines changed: 112 additions & 105 deletions

File tree

src/acl/access-controller.ts

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
import { adoptACLDefault, getProspectiveHolder, makeACLGraphbyCombo, sameACL } from './acl'
22
import { graph, NamedNode, UpdateManager } from 'rdflib'
3-
import ns from '../ns'
43
import { AccessGroups } from './access-groups'
54
import { DataBrowserContext } from 'pane-registry'
65
import { shortNameForFolder } from './acl-control'
76
import utils from '../utils.js'
87

9-
const ACL = ns.acl
10-
118
export 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!')

src/acl/access-groups.ts

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,41 +43,53 @@ export class AccessGroups {
4343
public byCombo: ComboList
4444
public aclMap: AgentMapMap
4545
private readonly addAgentButton: AddAgentButtons
46-
private readonly root: HTMLElement
46+
private readonly rootElement: HTMLElement
47+
private _store: IndexedFormula
4748

4849
constructor (
4950
private doc: NamedNode,
5051
private aclDoc: NamedNode,
5152
public controller: AccessController,
52-
public store: IndexedFormula,
53+
store: IndexedFormula,
5354
private options: AccessGroupsOptions = {}
5455
) {
5556
this.defaults = options.defaults || false
57+
this._store = store
5658
this.aclMap = readACL(doc, aclDoc, store, this.defaults)
5759
this.byCombo = ACLbyCombination(this.aclMap)
5860
this.addAgentButton = new AddAgentButtons(this)
59-
this.root = this.controller.dom.createElement('div')
60-
this.root.classList.add(this.controller.classes.accessGroupList)
61+
this.rootElement = this.controller.dom.createElement('div')
62+
this.rootElement.classList.add(this.controller.classes.accessGroupList)
63+
}
64+
65+
public get store () {
66+
return this._store
67+
}
68+
69+
public set store (store) {
70+
this._store = store
71+
this.aclMap = readACL(this.doc, this.aclDoc, store, this.defaults)
72+
this.byCombo = ACLbyCombination(this.aclMap)
6173
}
6274

6375
public render (): HTMLElement {
64-
this.root.innerHTML = ''
65-
this.renderGroups().forEach(group => this.root.appendChild(group))
76+
this.rootElement.innerHTML = ''
77+
this.renderGroups().forEach(group => this.rootElement.appendChild(group))
6678
if (this.controller.isEditable) {
67-
this.root.appendChild(this.addAgentButton.render())
79+
this.rootElement.appendChild(this.addAgentButton.render())
6880
}
69-
return this.root
81+
return this.rootElement
7082
}
7183

7284
private renderGroups (): HTMLElement[] {
73-
const groups: HTMLElement[] = []
85+
const groupElements: HTMLElement[] = []
7486
for (let comboIndex = 15; comboIndex > 0; comboIndex--) {
7587
const combo = kToCombo(comboIndex)
7688
if ((this.controller.isEditable && RECOMMENDED[comboIndex]) || this.byCombo[combo]) {
77-
groups.push(this.renderGroup(comboIndex, combo))
89+
groupElements.push(this.renderGroup(comboIndex, combo))
7890
}
7991
}
80-
return groups
92+
return groupElements
8193
}
8294

8395
private renderGroup (comboIndex: number, combo: string): HTMLElement {
@@ -92,26 +104,26 @@ export class AccessGroups {
92104
}
93105

94106
private renderGroupElements (comboIndex, combo): HTMLElement[] {
95-
const groupName = this.controller.dom.createElement('div')
96-
groupName.classList.add(this.controller.classes.group)
97-
groupName.classList.toggle(this.controller.classes[`group-${comboIndex}`], this.controller.isEditable)
98-
groupName.innerText = COLLOQUIAL[comboIndex] || ktToList(comboIndex)
107+
const groupNameColumn = this.controller.dom.createElement('div')
108+
groupNameColumn.classList.add(this.controller.classes.group)
109+
groupNameColumn.classList.toggle(this.controller.classes[`group-${comboIndex}`], this.controller.isEditable)
110+
groupNameColumn.innerText = COLLOQUIAL[comboIndex] || ktToList(comboIndex)
99111

100-
const groupAgents = this.controller.dom.createElement('div')
101-
groupAgents.classList.add(this.controller.classes.group)
102-
groupAgents.classList.toggle(this.controller.classes[`group-${comboIndex}`], this.controller.isEditable)
103-
const groupAgentsTable = groupAgents.appendChild(this.controller.dom.createElement('table'))
112+
const groupAgentsColumn = this.controller.dom.createElement('div')
113+
groupAgentsColumn.classList.add(this.controller.classes.group)
114+
groupAgentsColumn.classList.toggle(this.controller.classes[`group-${comboIndex}`], this.controller.isEditable)
115+
const groupAgentsTable = groupAgentsColumn.appendChild(this.controller.dom.createElement('table'))
104116
const combos = this.byCombo[combo] || []
105117
combos
106118
.map(([pred, obj]) => this.renderAgent(groupAgentsTable, combo, pred, obj))
107119
.forEach(agentElement => groupAgentsTable.appendChild(agentElement))
108120

109-
const groupDescription = this.controller.dom.createElement('div')
110-
groupDescription.classList.add(this.controller.classes.group)
111-
groupDescription.classList.toggle(this.controller.classes[`group-${comboIndex}`], this.controller.isEditable)
112-
groupDescription.innerText = EXPLANATION[comboIndex] || 'Unusual combination'
121+
const groupDescriptionElement = this.controller.dom.createElement('div')
122+
groupDescriptionElement.classList.add(this.controller.classes.group)
123+
groupDescriptionElement.classList.toggle(this.controller.classes[`group-${comboIndex}`], this.controller.isEditable)
124+
groupDescriptionElement.innerText = EXPLANATION[comboIndex] || 'Unusual combination'
113125

114-
return [groupName, groupAgents, groupDescription]
126+
return [groupNameColumn, groupAgentsColumn, groupDescriptionElement]
115127
}
116128

117129
private renderAgent (groupAgentsTable, combo, pred, obj): HTMLElement {
@@ -132,12 +144,6 @@ export class AccessGroups {
132144
await this.controller.save()
133145
}
134146

135-
public updateStore (store: IndexedFormula): void {
136-
this.store = store
137-
this.aclMap = readACL(this.doc, this.aclDoc, store, this.defaults)
138-
this.byCombo = ACLbyCombination(this.aclMap)
139-
}
140-
141147
public async addNewURI (uri: string): Promise<void> {
142148
await this.handleDroppedUri(uri, kToCombo(1))
143149
await this.controller.save()

0 commit comments

Comments
 (0)