@@ -84,12 +84,6 @@ export function autocompleteField (
8484 const labelProperty = kb . any ( form , ns . ui ( 'labelProperty' ) ) || ns . schema ( 'name' )
8585 const size = kb . any ( form , ns . ui ( 'size' ) ) // may be undefined, let the widget decide
8686
87- const searchClass = kb . any ( form , ns . ui ( 'searchClass' ) )
88- if ( ! searchClass ) {
89- return box . appendChild (
90- widgets . errorMessageBlock ( dom , 'Error: No searchClass given for autocomplete field: ' + form )
91- )
92- }
9387 // Parse the data source into query options
9488
9589 const dataSource = kb . any ( form , ns . ui ( 'dataSource' ) ) as NamedNode | undefined
@@ -99,10 +93,18 @@ export function autocompleteField (
9993 )
10094 }
10195 const queryParams :QueryParameters = {
102- targetClass : kb . any ( dataSource , ns . ui ( 'targetClass' ) , null , dataSource . doc ( ) ) as NamedNode | undefined ,
96+ // targetClass: kb.any(dataSource, ns.ui('targetClass'), null, dataSource.doc()) as NamedNode | undefined,
10397 label : kb . anyJS ( dataSource , ns . schema ( 'name' ) , null , dataSource . doc ( ) ) ,
10498 logo : kb . anyJS ( dataSource , ns . schema ( 'logo' ) , null , dataSource . doc ( ) )
10599 }
100+
101+ // @@ Should we pass the target class in from the data source definition or use a current type of the subject
102+ const targetClass = ( kb . any ( form , ns . ui ( 'targetClass' ) , null , form . doc ( ) ) || // class in form takes pecedence
103+ kb . any ( dataSource , ns . ui ( 'targetClass' ) , null , dataSource . doc ( ) ) ) as NamedNode | undefined
104+ if ( targetClass ) {
105+ queryParams . targetClass = targetClass
106+ }
107+ /*
106108 if (!queryParams.targetClass) {
107109 const klass = kb.any(subject, ns.rdf('type')) as NamedNode | undefined
108110 // @@ be more selective of which class if many
@@ -111,31 +113,32 @@ export function autocompleteField (
111113 if (!klass) throw new Error('Autocomplete: No class specified or is current type of' + subject)
112114 queryParams.targetClass = klass
113115 }
114- const endPoint = kb . anyJS ( dataSource , ns . ui ( 'endPoint' ) , null , dataSource . doc ( ) ) as string | undefined
115- if ( endPoint ) { // SPARQL
116- queryParams . endpoint = endPoint
116+ */
117+ const endpoint = kb . anyJS ( dataSource , ns . ui ( 'endpoint' ) , null , dataSource . doc ( ) ) as string | undefined
118+ if ( endpoint ) { // SPARQL
119+ queryParams . endpoint = endpoint
117120
118121 queryParams . searchByNameQuery = kb . anyJS ( dataSource , ns . ui ( 'searchByNameQuery' ) , null , dataSource . doc ( ) )
119122 if ( ! queryParams . searchByNameQuery ) {
120123 return box . appendChild (
121- widgets . errorMessageBlock ( dom , 'Error: No searchByNameQuery given for data Source: ' + form ) )
124+ widgets . errorMessageBlock ( dom , 'Error: No searchByNameQuery given for endpoint data Source: ' + form ) )
122125 }
123126 queryParams . insitituteDetailsQuery = kb . anyJS ( dataSource , ns . ui ( 'insitituteDetailsQuery' ) , null , dataSource . doc ( ) )
124127 } else {
125- return box . appendChild (
126- widgets . errorMessageBlock ( dom , 'Error: No SPARQL endPoint given for autocomplete field: ' + form ) )
127- }
128- const queryTemplate = kb . any ( form , ns . ui ( 'queryTemplate' ) )
129- if ( ! queryTemplate ) {
130- return box . appendChild (
131- widgets . errorMessageBlock ( dom , 'Error: No queryTemplate given for autocomplete field: ' + form )
132- )
128+ // return box.appendChild(
129+ // widgets.errorMessageBlock(dom, 'Error: No SPARQL endpoint given for autocomplete field: ' + form))
130+ const searchByNameURI = kb . anyJS ( dataSource , ns . ui ( 'searchByNameURI' ) )
131+ if ( ! searchByNameURI ) {
132+ return box . appendChild (
133+ widgets . errorMessageBlock ( dom , 'Error: No searchByNameURI OR sparql endpoint given for dataSource: ' + dataSource )
134+ )
135+ }
136+ queryParams . searchByNameURI = searchByNameURI
133137 }
134138 // It can be cleaner to just remove empty fields if you can't edit them anyway
135139 const suppressEmptyUneditable = kb . anyJS ( form , ns . ui ( 'suppressEmptyUneditable' ) , null , formDoc )
136140 const editable = kb . updater . editable ( ( doc as NamedNode ) . uri )
137141
138- // @@ Should we pass the target class in from the data source definition or use a current type of the subject
139142 const autocompleteOptions :AutocompleteOptions = { // cancelButton?: HTMLElement,
140143 // acceptButton?: HTMLElement,
141144 targetClass : queryParams . targetClass , // @@ simplify?
@@ -163,10 +166,10 @@ export function autocompleteField (
163166 const barOptions = {
164167 editable : doc && doc . uri && kb . updater . editable ( doc . uri , kb ) ,
165168 permanent : true ,
166- dbLookup : false
169+ dbLookup : true
167170 }
168171 renderAutocompleteControl ( dom , subject as NamedNode , barOptions , autocompleteOptions , addOneIdAndRefresh ) . then ( ( control ) => {
169- // console. log('Async load of autocomplete field control finished:' + control)
172+ // log('Async load of autocomplete field control finished:' + control)
170173 rhs . appendChild ( control )
171174 } , ( err ) => {
172175 rhs . appendChild ( widgets . errorMessageBlock ( dom , `Error rendering autocomplete${ form } : ${ err } ` ) )
0 commit comments