Skip to content

Commit 9d5565a

Browse files
committed
fixed rdf input
1 parent 344b904 commit 9d5565a

4 files changed

Lines changed: 45 additions & 37 deletions

File tree

src/components/rdf-form/RDFForm.ts

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import '@/components/rdf-input'
1111
export default class RDFForm extends WebComponent {
1212
@state()
1313
private accessor _parsedUrl: URL | null = null
14+
1415
@state()
1516
private accessor _parsedUrl2: URL | null = null
1617

@@ -36,17 +37,6 @@ export default class RDFForm extends WebComponent {
3637
return this._parsedUrl ? this._parsedUrl.href : ''
3738
}
3839

39-
private defaultContexts = `
40-
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
41-
@prefix sched: <http://www.w3.org/ns/pim/schedule#>.
42-
@prefix cal: <http://www.w3.org/2002/12/cal/ical#>.
43-
@prefix dc: <http://purl.org/dc/elements/1.1/>.
44-
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
45-
@prefix ui: <http://www.w3.org/ns/ui#>.
46-
@prefix trip: <http://www.w3.org/ns/pim/trip#>.
47-
@prefix vcard: <http://www.w3.org/2006/vcard/ns#>.
48-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
49-
`
5040
@property({ type: String })
5141
accessor whichSubject = 'me'
5242

@@ -71,12 +61,11 @@ export default class RDFForm extends WebComponent {
7161

7262
render () {
7363
// TODO: detect format
74-
loadDocument(store, this.rdfTurtleFormatSource + this.defaultContexts, this.rdfName, this.rdfURI) // load form
75-
loadDocument(store, this.subjectTurtleFormatSource + this.defaultContexts, this.subjectName, this.subjectURI) // load data
64+
loadDocument(store, this.rdfTurtleFormatSource, this.rdfName, this.rdfURI) // load form
65+
loadDocument(store, this.subjectTurtleFormatSource, this.subjectName, this.subjectURI) // load data
7666
const document = sym(this.rdfURI) // rdflib NamedNode for the document
7767
const exactForm = this.whichForm // If there are more 'a ui:Form' elements in a form file
7868
const formThis = Namespace(this.rdfURI + '#')(exactForm) // NamedNode for #this in the form
79-
console.log('formThis:', formThis.value)
8069

8170
const parts = store.each(formThis, ns.ui('parts'), null, document)
8271
const partsBySequence = sortBySequence(store, parts)
@@ -91,18 +80,16 @@ export default class RDFForm extends WebComponent {
9180
const typeNode = types[0]
9281
const value = typeNode ? ((typeNode as any).value || String(typeNode)) : ((item as any).value || String(item))
9382
const hashIndex = value.lastIndexOf('#')
94-
return hashIndex >= 0 ? value.slice(hashIndex + 1) : value
83+
return {
84+
value: item,
85+
fieldValue: hashIndex >= 0 ? value.slice(hashIndex + 1) : value
86+
}
9587
})
96-
console.log('parts:', parts)
97-
console.log('partsBySequence:', partsBySequence)
98-
console.log('partItems:', partItems)
99-
console.log('document:', document)
100-
console.log('exactForm:', exactForm)
101-
console.log('uiFields:', uiFields)
88+
const me = Namespace(this.subjectURI + '#')(this.whichSubject)
10289

10390
return html`
10491
${uiFields.map(part => {
105-
switch (part) {
92+
switch (part.fieldValue) {
10693
case 'PhoneField':
10794
case 'EmailField':
10895
case 'ColorField':
@@ -115,8 +102,12 @@ export default class RDFForm extends WebComponent {
115102
case 'FloatField':
116103
case 'TextField':
117104
case 'SingleLineTextField':
118-
case 'NamedNodeURIField':
119-
return html` <solid-ui-rdf-input .store=${store} formSubject=${part} .inputSubject=${this.subjectURI}></solid-ui-rdf-input> `
105+
case 'NamedNodeURIField': {
106+
const formSubject = typeof part.value === 'string'
107+
? store.sym(part.value)
108+
: part.value
109+
return html` <solid-ui-rdf-input .store=${store} .formSubject=${formSubject} .inputSubject=${me}></solid-ui-rdf-input> `
110+
}
120111
case 'MultiLineTextField':
121112
return html`<input rdf=${part}></input>`
122113
case 'BooleanField':

src/components/rdf-form/RDForm.stories.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const meta = {
7575
whichSubject: 'me',
7676
subjectTurtleFormatSource: `
7777
@prefix : <https://solidos.solidcommunity.net/public/2021/alice.ttl#>.
78+
@prefix vcard: <http://www.w3.org/2006/vcard/ns#>.
7879
7980
:me a vcard:Individual ;
8081
vcard:fn "Alice" ;

src/components/rdf-input/RDFInput.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,44 @@ export default class RDFInput extends WebComponent {
2020
accessor store
2121

2222
// form here is the subject :nameField
23-
@property({ type: String })
23+
@property({ type: NamedNode })
2424
accessor formSubject
2525

26-
@property({ type: String })
26+
@property({ type: NamedNode })
2727
accessor inputSubject
2828

2929
render () {
30+
const formSubject = typeof this.formSubject === 'string'
31+
? this.store.sym(this.formSubject)
32+
: this.formSubject
33+
const inputSubject = typeof this.inputSubject === 'string'
34+
? this.store.sym(this.inputSubject)
35+
: this.inputSubject
36+
37+
const formGraph = formSubject.doc ? formSubject.doc() : undefined
38+
3039
// HTML input part
31-
const uiPropertyTerm = this.store.any(this.formSubject, ns.ui('property')) as NamedNode | undefined
40+
const uiPropertyTerm = this.store.any(formSubject, ns.ui('property'), null, formGraph) as NamedNode | undefined
3241
const uiProperty = uiPropertyTerm ? label(uiPropertyTerm, true) : ''
33-
const uiLabel = this.store.any(this.formSubject, ns.ui('label'))
42+
const uiLabel = this.store.any(formSubject, ns.ui('label'), null, formGraph)
3443
const inputLabel = uiLabel ? uiLabel.value : uiProperty
35-
// readonly
44+
3645
let readonly = false
3746
// TODO: I am not finding suppressEmptyUneditable in ui ontology
38-
const suppressEmptyUneditable = this.store.anyJS(this.formSubject, ns.ui('suppressEmptyUneditable'))
47+
const suppressEmptyUneditable = this.store.anyJS(formSubject, ns.ui('suppressEmptyUneditable'), null, formGraph)
3948
if (suppressEmptyUneditable) {
4049
readonly = true
4150
}
4251

43-
const uri = mostSpecificClassURI(this.store, this.formSubject)
52+
const uri = mostSpecificClassURI(this.store, formSubject)
4453
const params = fieldParams[uri] ?? {}
4554
const inputType: InputType = params.type ?? 'text'
4655

4756
// input values
48-
const defaultInputValueFromStore = this.store.any(this.formSubject, ns.ui('default'))
49-
const inputValueFromStore = this.store.any(this.inputSubject, ns.ui('property'))
57+
const defaultInputValueFromStore = this.store.any(formSubject, ns.ui('default'))
58+
const inputValueFromStore = uiPropertyTerm
59+
? this.store.any(inputSubject, uiPropertyTerm)
60+
: undefined
5061

5162
let inputTerm: string | undefined
5263

src/lib/forms/rdfFormsHelper.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ export function loadDocument (
1313
const finalDocumentUri = documentURI || baseUri + documentName // Full URI to the file
1414
const document = sym(finalDocumentUri) // rdflib NamedNode for the document
1515

16-
if (!store.holds(undefined, undefined, undefined, document)) {
17-
// we are using the social media form because it contains the information we need
18-
// the form can be used for both use cases: create UI for edit and render UI for display
19-
parse(documentSource, store, finalDocumentUri, 'text/turtle', () => null) // Load doc directly
16+
if (store.holds(undefined, undefined, undefined, document)) {
17+
store.removeStatements(store.statementsMatching(undefined, undefined, undefined, document))
2018
}
19+
// we are using the social media form because it contains the information we need
20+
// the form can be used for both use cases: create UI for edit and render UI for display
21+
parse(documentSource, store, finalDocumentUri, 'text/turtle', (err) => {
22+
if (err) {
23+
console.error('loadDocument parse error for', finalDocumentUri, err)
24+
}
25+
})
2126
}
2227

2328
export function sortBySequence (

0 commit comments

Comments
 (0)