@startinblox/core 0.17.21-beta.10 → 0.17.21-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/solid-form.js +6 -2
- package/dist/components/solid-form.js.map +1 -1
- package/dist/components/solid-map.js +2 -2
- package/dist/components/solid-map.js.map +1 -1
- package/dist/libs/store/server-pagination.js +20 -0
- package/dist/libs/store/server-pagination.js.map +1 -0
- package/dist/libs/store/server-search.js +39 -0
- package/dist/libs/store/server-search.js.map +1 -0
- package/dist/libs/store/store.js +62 -30
- package/dist/libs/store/store.js.map +1 -1
- package/dist/mixins/attributeBinderMixin.js +3 -1
- package/dist/mixins/attributeBinderMixin.js.map +1 -1
- package/dist/mixins/federationMixin.js +3 -1
- package/dist/mixins/federationMixin.js.map +1 -1
- package/dist/mixins/filterMixin.js +45 -1
- package/dist/mixins/filterMixin.js.map +1 -1
- package/dist/mixins/interfaces.js.map +1 -1
- package/dist/mixins/listMixin.js +3 -1
- package/dist/mixins/listMixin.js.map +1 -1
- package/dist/mixins/paginateMixin.js.map +1 -1
- package/dist/mixins/serverPaginationMixin.js +130 -0
- package/dist/mixins/serverPaginationMixin.js.map +1 -0
- package/dist/mixins/storeMixin.js +27 -4
- package/dist/mixins/storeMixin.js.map +1 -1
- package/dist/mixins/widgetMixin.js +6 -2
- package/dist/mixins/widgetMixin.js.map +1 -1
- package/dist/widgets/baseWidget.js +3 -1
- package/dist/widgets/baseWidget.js.map +1 -1
- package/package.json +1 -1
|
@@ -148,6 +148,8 @@ export const SolidForm = {
|
|
|
148
148
|
},
|
|
149
149
|
|
|
150
150
|
get value() {
|
|
151
|
+
var _this$resource$isCont, _this$resource;
|
|
152
|
+
|
|
151
153
|
const values = {};
|
|
152
154
|
this.widgets.forEach(widget => {
|
|
153
155
|
const name = (widget.component || widget).name;
|
|
@@ -161,7 +163,7 @@ export const SolidForm = {
|
|
|
161
163
|
setDeepProperty(values, name.split('.'), value);
|
|
162
164
|
}); // add @id if edition
|
|
163
165
|
|
|
164
|
-
if (this.resource && !this.resource.isContainer()) values['@id'] = this.resourceId;
|
|
166
|
+
if (this.resource && !((_this$resource$isCont = (_this$resource = this.resource).isContainer) !== null && _this$resource$isCont !== void 0 && _this$resource$isCont.call(_this$resource))) values['@id'] = this.resourceId;
|
|
165
167
|
return values;
|
|
166
168
|
},
|
|
167
169
|
|
|
@@ -178,9 +180,11 @@ export const SolidForm = {
|
|
|
178
180
|
},
|
|
179
181
|
|
|
180
182
|
async getFormValue() {
|
|
183
|
+
var _this$resource$isCont2, _this$resource2;
|
|
184
|
+
|
|
181
185
|
let value = this.value;
|
|
182
186
|
|
|
183
|
-
if (this.resource && !this.resource.isContainer()) {
|
|
187
|
+
if (this.resource && !((_this$resource$isCont2 = (_this$resource2 = this.resource).isContainer) !== null && _this$resource$isCont2 !== void 0 && _this$resource$isCont2.call(_this$resource2))) {
|
|
184
188
|
for (let predicate of Object.keys(this.value)) {
|
|
185
189
|
// add @id for nested resources
|
|
186
190
|
const object = await this.resource[predicate];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["solid-form.ts"],"names":["Sib","WidgetMixin","StoreMixin","NextMixin","ValidationMixin","store","setDeepProperty","transformArrayToContainer","html","render","ifDefined","SolidForm","name","use","attributes","defaultWidget","type","String","default","naked","submitButton","undefined","callback","newValue","oldValue","noRender","populate","submitWidget","classSubmitButton","partial","Boolean","autosave","initialState","error","defaultMultipleWidget","defaultSetWidget","value","values","widgets","forEach","widget","component","getValue","JSON","parse","e","split","resource","isContainer","resourceId","isNaked","element","hasAttribute","isSavingAutomatically","isCreationForm","formValue","getFormValue","predicate","Object","keys","object","getWidget","field","isSet","tagName","widgetAttribute","getAttribute","widgetFromTagName","change","dispatchEvent","CustomEvent","bubbles","detail","save","toggleLoaderHidden","hideError","context","saved","put","post","patch","json","then","showError","id","submitForm","reset","goToNext","onInput","onChange","findErrorMessage","errors","errorFullName","errorsArray","member","errorNextName","errorAddName","concat","Array","isArray","errorMessage","errorGlobal","join","push","objectErrors","subErrors","entries","empty","filter","startsWith","errorTemplate","map","parentElement","querySelector","onSubmit","event","preventDefault","performAction","validateModal","onReset","setTimeout","getSubmitTemplate","t","oninput","onchange","fields","getFields","widgetTemplates","Promise","all","createWidgetTemplate","template","bind","getModalDialog","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,GAAT,QAAoB,aAApB;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,UAAT,QAA2B,sBAA3B;AACA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SAASC,eAAT,QAAgC,2BAAhC;AACA,SAASC,KAAT,QAAsB,qBAAtB;AACA,SAASC,eAAT,EAA0BC,yBAA1B,QAA2D,iBAA3D;AAGA,SAASC,IAAT,EAAeC,MAAf,QAA6B,UAA7B;AACA,SAASC,SAAT,QAA0B,gCAA1B;AAEA,OAAO,MAAMC,SAAS,GAAG;AACvBC,EAAAA,IAAI,EAAE,YADiB;AAEvBC,EAAAA,GAAG,EAAE,CAACZ,WAAD,EAAcC,UAAd,EAA0BC,SAA1B,EAAqCC,eAArC,CAFkB;AAGvBU,EAAAA,UAAU,EAAE;AACVC,IAAAA,aAAa,EAAE;AACbC,MAAAA,IAAI,EAAEC,MADO;AAEbC,MAAAA,OAAO,EAAE;AAFI,KADL;AAKVC,IAAAA,KAAK,EAAE;AACLH,MAAAA,IAAI,EAAEC,MADD;AAELC,MAAAA,OAAO,EAAE;AAFJ,KALG;AASVE,IAAAA,YAAY,EAAE;AACZJ,MAAAA,IAAI,EAAEC,MADM;AAEZC,MAAAA,OAAO,EAAEG,SAFG;AAGZC,MAAAA,QAAQ,EAAE,UAAUC,QAAV,EAA4BC,QAA5B,EAA8C;AACtD,YAAI,KAAKC,QAAL,IAAiB,IAAjB,IAAyBF,QAAQ,KAA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Ab","sourcesContent":["import { Sib } from '../libs/Sib';\nimport { WidgetMixin } from '../mixins/widgetMixin';\nimport { StoreMixin } from '../mixins/storeMixin';\nimport { NextMixin } from '../mixins/nextMixin';\nimport { ValidationMixin } from '../mixins/validationMixin';\nimport { store } from '../libs/store/store';\nimport { setDeepProperty, transformArrayToContainer } from '../libs/helpers';\nimport type { WidgetInterface } from '../mixins/interfaces';\n\nimport { html, render } from 'lit-html';\nimport { ifDefined } from 'lit-html/directives/if-defined';\n\nexport const SolidForm = {\n name: 'solid-form',\n use: [WidgetMixin, StoreMixin, NextMixin, ValidationMixin],\n attributes: {\n defaultWidget: {\n type: String,\n default: 'solid-form-label-text'\n },\n naked: {\n type: String,\n default: null\n },\n submitButton: {\n type: String,\n default: undefined,\n callback: function (newValue: string, oldValue: string) {\n if (this.noRender == null && newValue !== oldValue) this.populate();\n },\n },\n submitWidget: {\n type: String,\n default: null\n },\n classSubmitButton: {\n type: String,\n default: undefined,\n },\n partial: {\n type: Boolean,\n default: null\n },\n autosave: {\n type: Boolean,\n default: null\n },\n },\n initialState: {\n error: ''\n },\n get defaultMultipleWidget(): string {\n return 'solid-multiple-form';\n },\n get defaultSetWidget(): string {\n return 'solid-set-default';\n },\n get value(): object {\n const values = {};\n this.widgets.forEach((widget) => {\n const name = (widget.component || widget).name;\n if (name == null) return;\n let value = widget.component ? widget.component.getValue() : widget.value;\n try {\n value = JSON.parse(value);\n } catch (e) {}\n setDeepProperty(values, name.split('.'), value);\n });\n // add @id if edition\n if (this.resource && !this.resource.isContainer()) values['@id'] = this.resourceId;\n return values;\n },\n get isNaked(): boolean {\n return this.element.hasAttribute('naked');\n },\n get isSavingAutomatically(): boolean {\n return this.autosave !== null;\n },\n isCreationForm(formValue: object): boolean {\n return !('@id' in formValue);\n },\n async getFormValue() {\n let value = this.value;\n if (this.resource && !this.resource.isContainer()) {\n for (let predicate of Object.keys(this.value)) { // add @id for nested resources\n const object = await this.resource[predicate];\n if (object && object['@id'] && !value[predicate]['@id']) value[predicate]['@id'] = object['@id'];\n }\n }\n return transformArrayToContainer(value);\n },\n getWidget(field: string, isSet: boolean = false): WidgetInterface {\n let tagName = '';\n const widgetAttribute = this.element.getAttribute('widget-' + field);\n\n // Choose widget\n if (!widgetAttribute && this.element.hasAttribute('upload-url-' + field)) {\n tagName = 'solid-form-file'\n } else if (!widgetAttribute && (this.element.hasAttribute('range-' + field) || this.element.hasAttribute('enum-' + field))) {\n tagName = 'solid-form-dropdown'\n } else {\n tagName = widgetAttribute || (!isSet ? this.defaultWidget : this.defaultSetWidget);\n }\n // Create widget\n return this.widgetFromTagName(tagName);\n },\n change(resource: object): void {\n this.element.dispatchEvent(\n new CustomEvent('formChange', {\n bubbles: true,\n detail: { resource },\n }),\n );\n },\n async save(): Promise<object> {\n this.toggleLoaderHidden(false);\n this.hideError();\n const resource = await this.getFormValue();\n resource['@context'] = this.context;\n let saved;\n try {\n if (this.partial == null) {\n saved = resource['@id'] ?\n await store.put(resource, this.resourceId) :\n await store.post(resource, this.resourceId);\n } else {\n saved = await store.patch(resource, this.resourceId);\n }\n } catch (e) {\n this.toggleLoaderHidden(true);\n if (e) { // if server error\n e.json().then(error => this.showError(error));\n throw e;\n } // else, ldpframework error, we continue\n }\n this.element.dispatchEvent(\n new CustomEvent('save', {\n bubbles: true,\n detail: {\n resource: resource,\n id: saved || null\n },\n }),\n );\n this.toggleLoaderHidden(true);\n return saved;\n },\n async submitForm(): Promise<void> {\n let id: string;\n try {\n id = await this.save() || this.getFormValue()['@id'];\n } catch (e) { return; }\n this.reset();\n this.goToNext({'@id': id})\n },\n async onInput(): Promise<void> {\n const formValue = await this.getFormValue();\n this.change(formValue);\n },\n async onChange(): Promise<void> {\n const formValue = await this.getFormValue();\n if (!this.isCreationForm(formValue) && this.isSavingAutomatically)\n this.submitForm(); // if autosave, submitForm\n },\n findErrorMessage(errors: [string, any][], errorFullName: string = '') {\n let errorsArray: string[] = [];\n errors.forEach((member: [string, any]) => {\n let errorNextName: string = Object.values(member)[0];\n let errorAddName = (errorFullName === \"\" ? errorNextName : errorFullName.concat(' - ', errorNextName));\n if (Array.isArray(Object.values(member)[1]) === true) {\n let errorMessage: string[] = Object.values(member)[1];\n let errorGlobal = errorAddName.concat(': ', errorMessage.join(', '));\n errorsArray.push(errorGlobal);\n } else {\n let objectErrors = Object.values(member)[1];\n let subErrors = Object.entries(objectErrors);\n errorsArray = [...errorsArray, ...this.findErrorMessage(subErrors, errorAddName)];\n }\n });\n return errorsArray;\n },\n empty(): void {},\n showError(e: object) {\n let errors = Object.entries(e).filter(field => !field[0].startsWith('@context'));\n\n const errorTemplate = html`\n <p>A validation error occurred.</p>\n <ul>\n ${this.findErrorMessage(errors).map(field => html`\n <li>${field}</li>\n `)}\n </ul>\n `;\n // If field exists pick its label (unsure if that's easily possible)\n // In this.getFields() map with each field and get label\n // If it does not just add a notice as we do that it's missing that field\n\n // Validation message in english ?\n const parentElement = this.element.querySelector('[data-id=error]');\n if (parentElement) render(errorTemplate, parentElement);\n },\n hideError() {\n const parentElement = this.element.querySelector('[data-id=error]');\n if (parentElement) render('', parentElement);\n },\n reset() {\n if (!this.isNaked) this.element.querySelector('form').reset();\n },\n onSubmit(event: Event) {\n if (!this.isNaked) {\n event.preventDefault();\n this.performAction(); // In validationMixin, method defining what to do according to the present attributes\n }\n },\n validateModal() { //send method to validationMixin, used by the dialog modal and performAction method\n return this.submitForm();\n },\n onReset() {\n if (!this.isNaked) setTimeout(() => this.onInput())\n },\n getSubmitTemplate() {\n return html`\n <div class=${ifDefined(this.classSubmitButton)}>\n ${this.submitWidget === 'button' ? html`\n <button type=\"submit\">${this.submitButton || this.t(\"solid-form.submit-button\")}</button>\n ` : html`\n <input type=\"submit\" value=${this.submitButton || this.t(\"solid-form.submit-button\")}>\n `}\n </div>\n `\n },\n async populate(): Promise<void> {\n this.element.oninput = () => this.onInput(); // prevent from firing change multiple times\n this.element.onchange = () => this.onChange();\n const fields = await this.getFields();\n const widgetTemplates = await Promise.all(fields.map((field: string) => this.createWidgetTemplate(field)));\n const template = html`\n <div data-id=\"error\"></div>\n ${!this.isNaked ? html`\n <form\n @submit=${this.onSubmit.bind(this)}\n @reset=${this.onReset.bind(this)}\n >\n ${widgetTemplates}\n ${!this.isSavingAutomatically ? this.getSubmitTemplate() : ''}\n ${this.element.hasAttribute('reset')\n ? html`<input type=\"reset\" />` : ''}\n </form>\n ` : html`\n ${widgetTemplates}\n `\n }\n ${this.getModalDialog()}\n `;\n render(template, this.element);\n }\n};\n\nSib.register(SolidForm);"]}
|
|
1
|
+
{"version":3,"sources":["solid-form.ts"],"names":["Sib","WidgetMixin","StoreMixin","NextMixin","ValidationMixin","store","setDeepProperty","transformArrayToContainer","html","render","ifDefined","SolidForm","name","use","attributes","defaultWidget","type","String","default","naked","submitButton","undefined","callback","newValue","oldValue","noRender","populate","submitWidget","classSubmitButton","partial","Boolean","autosave","initialState","error","defaultMultipleWidget","defaultSetWidget","value","values","widgets","forEach","widget","component","getValue","JSON","parse","e","split","resource","isContainer","resourceId","isNaked","element","hasAttribute","isSavingAutomatically","isCreationForm","formValue","getFormValue","predicate","Object","keys","object","getWidget","field","isSet","tagName","widgetAttribute","getAttribute","widgetFromTagName","change","dispatchEvent","CustomEvent","bubbles","detail","save","toggleLoaderHidden","hideError","context","saved","put","post","patch","json","then","showError","id","submitForm","reset","goToNext","onInput","onChange","findErrorMessage","errors","errorFullName","errorsArray","member","errorNextName","errorAddName","concat","Array","isArray","errorMessage","errorGlobal","join","push","objectErrors","subErrors","entries","empty","filter","startsWith","errorTemplate","map","parentElement","querySelector","onSubmit","event","preventDefault","performAction","validateModal","onReset","setTimeout","getSubmitTemplate","t","oninput","onchange","fields","getFields","widgetTemplates","Promise","all","createWidgetTemplate","template","bind","getModalDialog","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,GAAT,QAAoB,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NvB,QAAMhG,QAAN,GAAgC;AAC9B,SAAKyB,OAAL,CAAawE,OAAb,GAAuB,MAAM,KAAKnC,OAAL,EAA7B,CAD8B,CACe;;;AAC7C,SAAKrC,OAAL,CAAayE,QAAb,GAAwB,MAAM,KAAKnC,QAAL,EAA9B;;AACA,UAAMoC,MAAM,GAAG,MAAM,KAAKC,SAAL,EAArB;AACA,UAAMC,eAAe,GAAG,MAAMC,OAAO,CAACC,GAAR,CAAYJ,MAAM,CAACd,GAAP,CAAYjD,KAAD,IAAmB,KAAKoE,oBAAL,CAA0BpE,KAA1B,CAA9B,CAAZ,CAA9B;AACA,UAAMqE,QAAQ,GAAG3H,IAAH,qBAEV,CAAC,KAAK0C,OAAN,GAAgB1C,IAAhB,qBAEY,KAAK0G,QAAL,CAAckB,IAAd,CAAmB,IAAnB,CAFZ,EAGW,KAAKb,OAAL,CAAaa,IAAb,CAAkB,IAAlB,CAHX,EAKIL,eALJ,EAMI,CAAC,KAAK1E,qBAAN,GAA8B,KAAKoE,iBAAL,EAA9B,GAAyD,EAN7D,EAOI,KAAKtE,OAAL,CAAaC,YAAb,CAA0B,OAA1B,IACE5C,IADF,uBACiC,EARrC,IAUEA,IAVF,qBAWEuH,eAXF,CAFU,EAgBV,KAAKM,cAAL,EAhBU,CAAd;AAkBA5H,IAAAA,MAAM,CAAC0H,QAAD,EAAW,KAAKhF,OAAhB,CAAN;AACD;;AAnPsB,CAAlB;AAsPPnD,GAAG,CAACsI,QAAJ,CAAa3H,SAAb","sourcesContent":["import { Sib } from '../libs/Sib';\nimport { WidgetMixin } from '../mixins/widgetMixin';\nimport { StoreMixin } from '../mixins/storeMixin';\nimport { NextMixin } from '../mixins/nextMixin';\nimport { ValidationMixin } from '../mixins/validationMixin';\nimport { store } from '../libs/store/store';\nimport { setDeepProperty, transformArrayToContainer } from '../libs/helpers';\nimport type { WidgetInterface } from '../mixins/interfaces';\n\nimport { html, render } from 'lit-html';\nimport { ifDefined } from 'lit-html/directives/if-defined';\n\nexport const SolidForm = {\n name: 'solid-form',\n use: [WidgetMixin, StoreMixin, NextMixin, ValidationMixin],\n attributes: {\n defaultWidget: {\n type: String,\n default: 'solid-form-label-text'\n },\n naked: {\n type: String,\n default: null\n },\n submitButton: {\n type: String,\n default: undefined,\n callback: function (newValue: string, oldValue: string) {\n if (this.noRender == null && newValue !== oldValue) this.populate();\n },\n },\n submitWidget: {\n type: String,\n default: null\n },\n classSubmitButton: {\n type: String,\n default: undefined,\n },\n partial: {\n type: Boolean,\n default: null\n },\n autosave: {\n type: Boolean,\n default: null\n },\n },\n initialState: {\n error: ''\n },\n get defaultMultipleWidget(): string {\n return 'solid-multiple-form';\n },\n get defaultSetWidget(): string {\n return 'solid-set-default';\n },\n get value(): object {\n const values = {};\n this.widgets.forEach((widget) => {\n const name = (widget.component || widget).name;\n if (name == null) return;\n let value = widget.component ? widget.component.getValue() : widget.value;\n try {\n value = JSON.parse(value);\n } catch (e) {}\n setDeepProperty(values, name.split('.'), value);\n });\n // add @id if edition\n if (this.resource && !this.resource.isContainer?.()) values['@id'] = this.resourceId;\n return values;\n },\n get isNaked(): boolean {\n return this.element.hasAttribute('naked');\n },\n get isSavingAutomatically(): boolean {\n return this.autosave !== null;\n },\n isCreationForm(formValue: object): boolean {\n return !('@id' in formValue);\n },\n async getFormValue() {\n let value = this.value;\n if (this.resource && !this.resource.isContainer?.()) {\n for (let predicate of Object.keys(this.value)) { // add @id for nested resources\n const object = await this.resource[predicate];\n if (object && object['@id'] && !value[predicate]['@id']) value[predicate]['@id'] = object['@id'];\n }\n }\n return transformArrayToContainer(value);\n },\n getWidget(field: string, isSet: boolean = false): WidgetInterface {\n let tagName = '';\n const widgetAttribute = this.element.getAttribute('widget-' + field);\n\n // Choose widget\n if (!widgetAttribute && this.element.hasAttribute('upload-url-' + field)) {\n tagName = 'solid-form-file'\n } else if (!widgetAttribute && (this.element.hasAttribute('range-' + field) || this.element.hasAttribute('enum-' + field))) {\n tagName = 'solid-form-dropdown'\n } else {\n tagName = widgetAttribute || (!isSet ? this.defaultWidget : this.defaultSetWidget);\n }\n // Create widget\n return this.widgetFromTagName(tagName);\n },\n change(resource: object): void {\n this.element.dispatchEvent(\n new CustomEvent('formChange', {\n bubbles: true,\n detail: { resource },\n }),\n );\n },\n async save(): Promise<object> {\n this.toggleLoaderHidden(false);\n this.hideError();\n const resource = await this.getFormValue();\n resource['@context'] = this.context;\n let saved;\n try {\n if (this.partial == null) {\n saved = resource['@id'] ?\n await store.put(resource, this.resourceId) :\n await store.post(resource, this.resourceId);\n } else {\n saved = await store.patch(resource, this.resourceId);\n }\n } catch (e) {\n this.toggleLoaderHidden(true);\n if (e) { // if server error\n e.json().then(error => this.showError(error));\n throw e;\n } // else, ldpframework error, we continue\n }\n this.element.dispatchEvent(\n new CustomEvent('save', {\n bubbles: true,\n detail: {\n resource: resource,\n id: saved || null\n },\n }),\n );\n this.toggleLoaderHidden(true);\n return saved;\n },\n async submitForm(): Promise<void> {\n let id: string;\n try {\n id = await this.save() || this.getFormValue()['@id'];\n } catch (e) { return; }\n this.reset();\n this.goToNext({'@id': id})\n },\n async onInput(): Promise<void> {\n const formValue = await this.getFormValue();\n this.change(formValue);\n },\n async onChange(): Promise<void> {\n const formValue = await this.getFormValue();\n if (!this.isCreationForm(formValue) && this.isSavingAutomatically)\n this.submitForm(); // if autosave, submitForm\n },\n findErrorMessage(errors: [string, any][], errorFullName: string = '') {\n let errorsArray: string[] = [];\n errors.forEach((member: [string, any]) => {\n let errorNextName: string = Object.values(member)[0];\n let errorAddName = (errorFullName === \"\" ? errorNextName : errorFullName.concat(' - ', errorNextName));\n if (Array.isArray(Object.values(member)[1]) === true) {\n let errorMessage: string[] = Object.values(member)[1];\n let errorGlobal = errorAddName.concat(': ', errorMessage.join(', '));\n errorsArray.push(errorGlobal);\n } else {\n let objectErrors = Object.values(member)[1];\n let subErrors = Object.entries(objectErrors);\n errorsArray = [...errorsArray, ...this.findErrorMessage(subErrors, errorAddName)];\n }\n });\n return errorsArray;\n },\n empty(): void {},\n showError(e: object) {\n let errors = Object.entries(e).filter(field => !field[0].startsWith('@context'));\n\n const errorTemplate = html`\n <p>A validation error occurred.</p>\n <ul>\n ${this.findErrorMessage(errors).map(field => html`\n <li>${field}</li>\n `)}\n </ul>\n `;\n // If field exists pick its label (unsure if that's easily possible)\n // In this.getFields() map with each field and get label\n // If it does not just add a notice as we do that it's missing that field\n\n // Validation message in english ?\n const parentElement = this.element.querySelector('[data-id=error]');\n if (parentElement) render(errorTemplate, parentElement);\n },\n hideError() {\n const parentElement = this.element.querySelector('[data-id=error]');\n if (parentElement) render('', parentElement);\n },\n reset() {\n if (!this.isNaked) this.element.querySelector('form').reset();\n },\n onSubmit(event: Event) {\n if (!this.isNaked) {\n event.preventDefault();\n this.performAction(); // In validationMixin, method defining what to do according to the present attributes\n }\n },\n validateModal() { //send method to validationMixin, used by the dialog modal and performAction method\n return this.submitForm();\n },\n onReset() {\n if (!this.isNaked) setTimeout(() => this.onInput())\n },\n getSubmitTemplate() {\n return html`\n <div class=${ifDefined(this.classSubmitButton)}>\n ${this.submitWidget === 'button' ? html`\n <button type=\"submit\">${this.submitButton || this.t(\"solid-form.submit-button\")}</button>\n ` : html`\n <input type=\"submit\" value=${this.submitButton || this.t(\"solid-form.submit-button\")}>\n `}\n </div>\n `\n },\n async populate(): Promise<void> {\n this.element.oninput = () => this.onInput(); // prevent from firing change multiple times\n this.element.onchange = () => this.onChange();\n const fields = await this.getFields();\n const widgetTemplates = await Promise.all(fields.map((field: string) => this.createWidgetTemplate(field)));\n const template = html`\n <div data-id=\"error\"></div>\n ${!this.isNaked ? html`\n <form\n @submit=${this.onSubmit.bind(this)}\n @reset=${this.onReset.bind(this)}\n >\n ${widgetTemplates}\n ${!this.isSavingAutomatically ? this.getSubmitTemplate() : ''}\n ${this.element.hasAttribute('reset')\n ? html`<input type=\"reset\" />` : ''}\n </form>\n ` : html`\n ${widgetTemplates}\n `\n }\n ${this.getModalDialog()}\n `;\n render(template, this.element);\n }\n};\n\nSib.register(SolidForm);"]}
|
|
@@ -33,9 +33,9 @@ import { store } from '../libs/store/store.js';
|
|
|
33
33
|
import { uniqID } from '../libs/helpers.js';
|
|
34
34
|
import { spread } from '../libs/lit-helpers.js'; //@ts-ignore
|
|
35
35
|
|
|
36
|
-
import L from 'https://cdn.skypack.dev/leaflet'; // TODO : revert to "leaflet" when apps up to date
|
|
36
|
+
import L from 'https://cdn.skypack.dev/leaflet@1.7.1'; // TODO : revert to "leaflet" when apps up to date
|
|
37
37
|
|
|
38
|
-
import 'https://cdn.skypack.dev/leaflet.markercluster'; // TODO : revert to "leaflet.markercluster" when apps up to date
|
|
38
|
+
import 'https://cdn.skypack.dev/leaflet.markercluster@1.4.1'; // TODO : revert to "leaflet.markercluster" when apps up to date
|
|
39
39
|
|
|
40
40
|
import { html, render } from '../_snowpack/pkg/lit-html.js';
|
|
41
41
|
import { ifDefined } from '../_snowpack/pkg/lit-html/directives/if-defined.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["solid-map.ts"],"names":["Sib","ListMixin","StoreMixin","WidgetMixin","CounterMixin","FilterMixin","FederationMixin","GrouperMixin","NextMixin","store","uniqID","spread","L","html","render","ifDefined","SolidMap","name","use","attributes","clustering","type","Boolean","default","initialState","markers","subscriptions","resetPlanned","hasBeenResetOnce","created","document","body","addEventListener","setTimeout","isVisible","reset","Map","element","offsetParent","attached","id","template","div","querySelector","map","tileLayer","addTo","markersCluster","markerClusterGroup","addLayer","invalidateSize","length","fitBounds","featureGroup","getBounds","fitWorld","planReset","dispatchSelect","event","target","resource","dispatchEvent","CustomEvent","detail","goToNext","appendChildElt","resourceId","groupClass","getData","context","get","set","PubSub","subscribe","updateDOM","lat","lng","icon","divIcon","className","iconSize","iconAnchor","popupAnchor","marker","toString","on","bind","fields","bindPopup","getPopupContent","minWidth","push","attr","startsWith","value","replace","createElement","empty","removeLayer","renderGroup","groupName","sanitizedGroupName","encodeURIComponent","toLowerCase","dataset","renderDOM","resources","listPostProcessors","Promise","all","nextProcessor","shift","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,GAAT,QAAoB,aAApB;AACA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SAASC,UAAT,QAA2B,sBAA3B;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,YAAT,QAA6B,wBAA7B;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,eAAT,QAAgC,2BAAhC;AACA,SAASC,YAAT,QAA6B,wBAA7B;AACA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SAASC,KAAT,QAAsB,qBAAtB;AACA,SAASC,MAAT,QAAuB,iBAAvB;AACA,SAASC,MAAT,QAAuB,qBAAvB,C,CAEA;;AACA,OAAOC,CAAP,MAAiC,iCAAjC,C,CAAoE;;AACpE,OAAO,+CAAP,C,CAAwD;;AAExD,SAASC,IAAT,EAAeC,MAAf,QAA6B,UAA7B;AACA,SAASC,SAAT,QAA0B,gCAA1B;AAEA,OAAO,MAAMC,QAAQ,GAAG;AACtBC,EAAAA,IAAI,EAAE,WADgB;AAEtBC,EAAAA,GAAG,EAAE,CACHf,WADG,EAEHF,SAFG,EAGHC,UAHG,EAIHK,YAJG,EAKHH,YALG,EAMHC,WANG,EAOHC,eAPG,EAQHE,SARG,CAFiB;AAYtBW,EAAAA,UAAU,EAAE;AACVC,IAAAA,UAAU,EAAE;AACVC,MAAAA,IAAI,EAAEC,OADI;AAEVC,MAAAA,OAAO,EAAE;AAFC;AADF,GAZU;AAkBtBC,EAAAA,YAAY,EAAE;AACZC,IAAAA,OAAO,EAAE;AACPF,MAAAA,OAAO,EAAE;AADF,KADG;AAIZG,IAAAA,aAAa,EAAE,IAJH;AAKZC,IAAAA,YAAY,EAAE,KALF;AAMZC,IAAAA,gBAAgB,EAAE;AANN,GAlBQ;;AA0BtBC,EAAAA,OAAO,GAAS;AACd;AACA,WAAO,0BAAP,EAFc,CAGd;;AACA,WAAO,4BAAP,EAJ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EA,UAAMsD,aAAa,GAAGH,kBAAkB,CAACI,KAAnB,EAAtB;AACA,QAAGD,aAAH,EAAkB,MAAMA,aAAa,CAACJ,SAAD,EAAYC,kBAAZ,EAAgCjE,GAAhC,EAAqC2B,OAArC,CAAnB;AACnB;;AAjNqB,CAAjB;AAoNPrE,GAAG,CAACgH,QAAJ,CAAahG,QAAb","sourcesContent":["import { Sib } from '../libs/Sib';\nimport { ListMixin } from '../mixins/listMixin';\nimport { StoreMixin } from '../mixins/storeMixin';\nimport { WidgetMixin } from '../mixins/widgetMixin';\nimport { CounterMixin } from '../mixins/counterMixin';\nimport { FilterMixin } from '../mixins/filterMixin';\nimport { FederationMixin } from '../mixins/federationMixin';\nimport { GrouperMixin } from '../mixins/grouperMixin';\nimport { NextMixin } from '../mixins/nextMixin';\nimport { store } from '../libs/store/store';\nimport { uniqID } from '../libs/helpers';\nimport { spread } from '../libs/lit-helpers';\n\n//@ts-ignore\nimport L, { MarkerOptions } from 'https://cdn.skypack.dev/leaflet'; // TODO : revert to \"leaflet\" when apps up to date\nimport 'https://cdn.skypack.dev/leaflet.markercluster'; // TODO : revert to \"leaflet.markercluster\" when apps up to date\n\nimport { html, render } from 'lit-html';\nimport { ifDefined } from 'lit-html/directives/if-defined';\n\nexport const SolidMap = {\n name: 'solid-map',\n use: [\n WidgetMixin,\n ListMixin,\n StoreMixin,\n GrouperMixin,\n CounterMixin,\n FilterMixin,\n FederationMixin,\n NextMixin,\n ],\n attributes: {\n clustering: {\n type: Boolean,\n default: null\n }\n },\n initialState: {\n markers: {\n default: null\n },\n subscriptions: null,\n resetPlanned: false,\n hasBeenResetOnce: false\n },\n created(): void {\n //@ts-ignore\n import('leaflet/dist/leaflet.css');\n //@ts-ignore\n import('../style/default-theme.css');\n //@ts-ignore\n import('leaflet.markercluster/dist/MarkerCluster.css');\n //@ts-ignore\n import('leaflet.markercluster/dist/MarkerCluster.Default.css');\n\n // reset when it becomes visible to prevent bug https://git.startinblox.com/framework/sib-core/issues/661\n document.body.addEventListener('navigate', () =>\n setTimeout(() => this.isVisible && !this.hasBeenResetOnce && this.reset())\n );\n this.markers = [];\n this.subscriptions = new Map();\n },\n get isVisible() {\n return this.element.offsetParent !== null\n },\n attached(): void {\n const id = uniqID();\n const template = html`\n <div id=${id} style=\"width:100%;height:100%;\"></div>\n `;\n render(template, this.element);\n\n const div = this.element.querySelector(`#${id}`);\n this.map = L.map(div);\n\n L.tileLayer(\n 'https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png'\n ).addTo(this.map);\n\n if (this.clustering !== null) {\n this.markersCluster = L.markerClusterGroup();\n this.map.addLayer(this.markersCluster);\n }\n },\n reset() {\n if (this.isVisible) { // reset only if visible\n this.map.invalidateSize();\n\n if (this.markers.length) {\n this.map.fitBounds(L.featureGroup(this.markers).getBounds()); // Center map on markers if some available\n } else {\n this.map.fitWorld(); // ... or on the world if not\n }\n this.hasBeenResetOnce = true;\n }\n },\n /**\n * Execute a reset only if none is planned already\n */\n planReset() {\n if (!this.resetPlanned) {\n this.resetPlanned = true;\n setTimeout(() => {\n this.reset();\n this.resetPlanned = false;\n })\n }\n },\n dispatchSelect(event: CustomEvent): void {\n const target = event.target as Element;\n const resource = target['options'].resource;\n this.element.dispatchEvent(\n new CustomEvent('resourceSelect', { detail: { resource: resource } })\n );\n this.goToNext(resource);\n },\n\n /**\n * Override listMixin method: initialize a marker on the map\n * @param resourceId: id of the resource to display\n * @param groupClass: class of the group of markers\n */\n async appendChildElt(resourceId: string, groupClass: string) {\n const resource = await store.getData(resourceId, this.context);\n if (!this.subscriptions.get(resourceId)) {\n this.subscriptions.set(resourceId, PubSub.subscribe(resourceId, () => this.updateDOM()))\n }\n if (!resource) return;\n const lat = await resource['lat'];\n const lng = await resource['lng'];\n\n if (lat && lng) {\n const icon = L.divIcon({ // create the icon, doc here: https://leafletjs.com/reference-1.6.0.html#icon\n className: 'sib-custom-marker ' + groupClass, // default class used for styling\n iconSize: [8, 8],\n iconAnchor: [12, 34],\n popupAnchor: [0,-34]\n });\n\n // create a marker, doc here: https://leafletjs.com/reference-1.6.0.html#marker\n const marker = L.marker(\n [lat.toString(), lng.toString()], \n {resource, icon} as MarkerOptions\n );\n if(this.clustering === null) marker.addTo(this.map);\n else this.markersCluster.addLayer(marker);\n marker.on('click', this.dispatchSelect.bind(this));\n\n if (this.fields !== null) { // show popups only if fields attribute\n marker.bindPopup(() => this.getPopupContent(resourceId), { minWidth: 150 }) // re-generate popup solid-display\n }\n\n this.markers.push(marker);\n }\n },\n /**\n * Generate the solid-display of the popup\n * @param resourceId: id of the popup clicked\n */\n getPopupContent(resourceId: string) {\n const attributes:{[key:string]: string} = {};\n\n for (let attr of this.element.attributes) {\n //copy widget and value attributes\n if (\n attr.name.startsWith('value-') ||\n attr.name.startsWith('label-') ||\n attr.name.startsWith('widget-') ||\n attr.name.startsWith('class-') ||\n attr.name.startsWith('multiple-') ||\n attr.name.startsWith('editable-') ||\n attr.name.startsWith('action-') ||\n attr.name.startsWith('default-') ||\n attr.name == 'extra-context'\n )\n attributes[attr.name] = attr.value;\n if (attr.name.startsWith('child-'))\n attributes[attr.name.replace(/^child-/, '')] = attr.value;\n }\n\n const div = document.createElement('div');\n const template = html`\n <solid-display\n fields=\"${ifDefined(this.fields)}\"\n data-src=\"${resourceId}\"\n ...=${spread(attributes)}\n ></solid-display>\n `;\n render(template, div);\n return div.querySelector('solid-display');\n },\n /**\n * Override widgetMixin method: empty the map\n */\n empty(): void {\n if (!this.map) return;\n if (this.markersCluster) this.map.removeLayer(this.markersCluster);\n for (let marker of this.markers) this.map.removeLayer(marker);\n if(this.clustering !== null) {\n this.markersCluster = L.markerClusterGroup();\n this.map.addLayer(this.markersCluster);\n }\n this.markers = [];\n },\n /**\n * Override groupMixin method\n * @param groupName: value of the group\n */\n renderGroup(groupName: string) {\n const sanitizedGroupName = encodeURIComponent(groupName.toLowerCase()).replace(/%[0-9A-F]{2}/gi, '');\n const div = document.createElement('div'); // used to pass group info to renderDOM\n div.dataset.groupClass = 'group-' + sanitizedGroupName;\n return div;\n },\n /**\n * Override listMixin method: display all the resources\n * @param resources\n * @param listPostProcessors\n * @param div\n * @param context\n */\n async renderDOM(resources: object[], listPostProcessors: Function[], div: HTMLElement, context: string) {\n const groupClass = div.dataset.groupClass || ''; // get the group class from the useless div element\n await Promise.all(resources.map(resource => this.appendChildElt(resource['@id'], groupClass)))\n this.planReset();\n\n const nextProcessor = listPostProcessors.shift();\n if(nextProcessor) await nextProcessor(resources, listPostProcessors, div, context);\n }\n};\n\nSib.register(SolidMap);"]}
|
|
1
|
+
{"version":3,"sources":["solid-map.ts"],"names":["Sib","ListMixin","StoreMixin","WidgetMixin","CounterMixin","FilterMixin","FederationMixin","GrouperMixin","NextMixin","store","uniqID","spread","L","html","render","ifDefined","SolidMap","name","use","attributes","clustering","type","Boolean","default","initialState","markers","subscriptions","resetPlanned","hasBeenResetOnce","created","document","body","addEventListener","setTimeout","isVisible","reset","Map","element","offsetParent","attached","id","template","div","querySelector","map","tileLayer","addTo","markersCluster","markerClusterGroup","addLayer","invalidateSize","length","fitBounds","featureGroup","getBounds","fitWorld","planReset","dispatchSelect","event","target","resource","dispatchEvent","CustomEvent","detail","goToNext","appendChildElt","resourceId","groupClass","getData","context","get","set","PubSub","subscribe","updateDOM","lat","lng","icon","divIcon","className","iconSize","iconAnchor","popupAnchor","marker","toString","on","bind","fields","bindPopup","getPopupContent","minWidth","push","attr","startsWith","value","replace","createElement","empty","removeLayer","renderGroup","groupName","sanitizedGroupName","encodeURIComponent","toLowerCase","dataset","renderDOM","resources","listPostProcessors","Promise","all","nextProcessor","shift","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,GAAT,QAAoB,aAApB;AACA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SAASC,UAAT,QAA2B,sBAA3B;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,YAAT,QAA6B,wBAA7B;AACA,SAASC,WAAT,QAA4B,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ib';\nimport { ListMixin } from '../mixins/listMixin';\nimport { StoreMixin } from '../mixins/storeMixin';\nimport { WidgetMixin } from '../mixins/widgetMixin';\nimport { CounterMixin } from '../mixins/counterMixin';\nimport { FilterMixin } from '../mixins/filterMixin';\nimport { FederationMixin } from '../mixins/federationMixin';\nimport { GrouperMixin } from '../mixins/grouperMixin';\nimport { NextMixin } from '../mixins/nextMixin';\nimport { store } from '../libs/store/store';\nimport { uniqID } from '../libs/helpers';\nimport { spread } from '../libs/lit-helpers';\n\n//@ts-ignore\nimport L, { MarkerOptions } from 'https://cdn.skypack.dev/leaflet@1.7.1'; // TODO : revert to \"leaflet\" when apps up to date\nimport 'https://cdn.skypack.dev/leaflet.markercluster@1.4.1'; // TODO : revert to \"leaflet.markercluster\" when apps up to date\n\nimport { html, render } from 'lit-html';\nimport { ifDefined } from 'lit-html/directives/if-defined';\n\nexport const SolidMap = {\n name: 'solid-map',\n use: [\n WidgetMixin,\n ListMixin,\n StoreMixin,\n GrouperMixin,\n CounterMixin,\n FilterMixin,\n FederationMixin,\n NextMixin,\n ],\n attributes: {\n clustering: {\n type: Boolean,\n default: null\n }\n },\n initialState: {\n markers: {\n default: null\n },\n subscriptions: null,\n resetPlanned: false,\n hasBeenResetOnce: false\n },\n created(): void {\n //@ts-ignore\n import('leaflet/dist/leaflet.css');\n //@ts-ignore\n import('../style/default-theme.css');\n //@ts-ignore\n import('leaflet.markercluster/dist/MarkerCluster.css');\n //@ts-ignore\n import('leaflet.markercluster/dist/MarkerCluster.Default.css');\n\n // reset when it becomes visible to prevent bug https://git.startinblox.com/framework/sib-core/issues/661\n document.body.addEventListener('navigate', () =>\n setTimeout(() => this.isVisible && !this.hasBeenResetOnce && this.reset())\n );\n this.markers = [];\n this.subscriptions = new Map();\n },\n get isVisible() {\n return this.element.offsetParent !== null\n },\n attached(): void {\n const id = uniqID();\n const template = html`\n <div id=${id} style=\"width:100%;height:100%;\"></div>\n `;\n render(template, this.element);\n\n const div = this.element.querySelector(`#${id}`);\n this.map = L.map(div);\n\n L.tileLayer(\n 'https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png'\n ).addTo(this.map);\n\n if (this.clustering !== null) {\n this.markersCluster = L.markerClusterGroup();\n this.map.addLayer(this.markersCluster);\n }\n },\n reset() {\n if (this.isVisible) { // reset only if visible\n this.map.invalidateSize();\n\n if (this.markers.length) {\n this.map.fitBounds(L.featureGroup(this.markers).getBounds()); // Center map on markers if some available\n } else {\n this.map.fitWorld(); // ... or on the world if not\n }\n this.hasBeenResetOnce = true;\n }\n },\n /**\n * Execute a reset only if none is planned already\n */\n planReset() {\n if (!this.resetPlanned) {\n this.resetPlanned = true;\n setTimeout(() => {\n this.reset();\n this.resetPlanned = false;\n })\n }\n },\n dispatchSelect(event: CustomEvent): void {\n const target = event.target as Element;\n const resource = target['options'].resource;\n this.element.dispatchEvent(\n new CustomEvent('resourceSelect', { detail: { resource: resource } })\n );\n this.goToNext(resource);\n },\n\n /**\n * Override listMixin method: initialize a marker on the map\n * @param resourceId: id of the resource to display\n * @param groupClass: class of the group of markers\n */\n async appendChildElt(resourceId: string, groupClass: string) {\n const resource = await store.getData(resourceId, this.context);\n if (!this.subscriptions.get(resourceId)) {\n this.subscriptions.set(resourceId, PubSub.subscribe(resourceId, () => this.updateDOM()))\n }\n if (!resource) return;\n const lat = await resource['lat'];\n const lng = await resource['lng'];\n\n if (lat && lng) {\n const icon = L.divIcon({ // create the icon, doc here: https://leafletjs.com/reference-1.6.0.html#icon\n className: 'sib-custom-marker ' + groupClass, // default class used for styling\n iconSize: [8, 8],\n iconAnchor: [12, 34],\n popupAnchor: [0,-34]\n });\n\n // create a marker, doc here: https://leafletjs.com/reference-1.6.0.html#marker\n const marker = L.marker(\n [lat.toString(), lng.toString()], \n {resource, icon} as MarkerOptions\n );\n if(this.clustering === null) marker.addTo(this.map);\n else this.markersCluster.addLayer(marker);\n marker.on('click', this.dispatchSelect.bind(this));\n\n if (this.fields !== null) { // show popups only if fields attribute\n marker.bindPopup(() => this.getPopupContent(resourceId), { minWidth: 150 }) // re-generate popup solid-display\n }\n\n this.markers.push(marker);\n }\n },\n /**\n * Generate the solid-display of the popup\n * @param resourceId: id of the popup clicked\n */\n getPopupContent(resourceId: string) {\n const attributes:{[key:string]: string} = {};\n\n for (let attr of this.element.attributes) {\n //copy widget and value attributes\n if (\n attr.name.startsWith('value-') ||\n attr.name.startsWith('label-') ||\n attr.name.startsWith('widget-') ||\n attr.name.startsWith('class-') ||\n attr.name.startsWith('multiple-') ||\n attr.name.startsWith('editable-') ||\n attr.name.startsWith('action-') ||\n attr.name.startsWith('default-') ||\n attr.name == 'extra-context'\n )\n attributes[attr.name] = attr.value;\n if (attr.name.startsWith('child-'))\n attributes[attr.name.replace(/^child-/, '')] = attr.value;\n }\n\n const div = document.createElement('div');\n const template = html`\n <solid-display\n fields=\"${ifDefined(this.fields)}\"\n data-src=\"${resourceId}\"\n ...=${spread(attributes)}\n ></solid-display>\n `;\n render(template, div);\n return div.querySelector('solid-display');\n },\n /**\n * Override widgetMixin method: empty the map\n */\n empty(): void {\n if (!this.map) return;\n if (this.markersCluster) this.map.removeLayer(this.markersCluster);\n for (let marker of this.markers) this.map.removeLayer(marker);\n if(this.clustering !== null) {\n this.markersCluster = L.markerClusterGroup();\n this.map.addLayer(this.markersCluster);\n }\n this.markers = [];\n },\n /**\n * Override groupMixin method\n * @param groupName: value of the group\n */\n renderGroup(groupName: string) {\n const sanitizedGroupName = encodeURIComponent(groupName.toLowerCase()).replace(/%[0-9A-F]{2}/gi, '');\n const div = document.createElement('div'); // used to pass group info to renderDOM\n div.dataset.groupClass = 'group-' + sanitizedGroupName;\n return div;\n },\n /**\n * Override listMixin method: display all the resources\n * @param resources\n * @param listPostProcessors\n * @param div\n * @param context\n */\n async renderDOM(resources: object[], listPostProcessors: Function[], div: HTMLElement, context: string) {\n const groupClass = div.dataset.groupClass || ''; // get the group class from the useless div element\n await Promise.all(resources.map(resource => this.appendChildElt(resource['@id'], groupClass)))\n this.planReset();\n\n const nextProcessor = listPostProcessors.shift();\n if(nextProcessor) await nextProcessor(resources, listPostProcessors, div, context);\n }\n};\n\nSib.register(SolidMap);"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function formatAttributesToServerPaginationOptions(elementAttributes) {
|
|
2
|
+
const attributes = new Map(Array.from(elementAttributes).map(({
|
|
3
|
+
name,
|
|
4
|
+
value
|
|
5
|
+
}) => [name, value]));
|
|
6
|
+
const limit = attributes.get('limit');
|
|
7
|
+
const offset = attributes.get('offset');
|
|
8
|
+
if (!offset || !limit) return;
|
|
9
|
+
return {
|
|
10
|
+
limit: limit,
|
|
11
|
+
offset: offset
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function appendServerPaginationToIri(iri, options) {
|
|
15
|
+
const first = iri.includes('?') ? '&' : '?';
|
|
16
|
+
const limit = options.limit;
|
|
17
|
+
const offset = options.offset;
|
|
18
|
+
return "".concat(iri).concat(first, "limit=").concat(limit, "&offset=").concat(offset);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=server-pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["server-pagination.ts"],"names":["formatAttributesToServerPaginationOptions","elementAttributes","attributes","Map","Array","from","map","name","value","limit","get","offset","appendServerPaginationToIri","iri","options","first","includes"],"mappings":"AAKA,OAAO,SAASA,yCAAT,CACHC,iBADG,EAEgC;AACnC,QAAMC,UAAU,GAAG,IAAIC,GAAJ,CAAQC,KAAK,CAACC,IAAN,CAAWJ,iBAAX,EAA8BK,GAA9B,CAAkC,CAAC;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,GAAD,KAAqB,CAACD,IAAD,EAAOC,KAAP,CAAvD,CAAR,CAAnB;AACA,QAAMC,KAAK,GAAGP,UAAU,CAACQ,GAAX,CAAe,OAAf,CAAd;AACA,QAAMC,MAAM,GAAGT,UAAU,CAACQ,GAAX,CAAe,QAAf,CAAf;AACA,MAAI,CAACC,MAAD,IAAW,CAACF,KAAhB,EAAuB;AACvB,SAAO;AACHA,IAAAA,KAAK,EAAEA,KADJ;AAEHE,IAAAA,MAAM,EAAEA;AAFL,GAAP;AAIH;AAED,OAAO,SAASC,2BAAT,CAAqCC,GAArC,EAAkDC,OAAlD,EAA4F;AAC/F,QAAMC,KAAK,GAAGF,GAAG,CAACG,QAAJ,CAAa,GAAb,IAAoB,GAApB,GAA0B,GAAxC;AACA,QAAMP,KAAK,GAAGK,OAAO,CAACL,KAAtB;AACA,QAAME,MAAM,GAAGG,OAAO,CAACH,MAAvB;AACA,mBAAUE,GAAV,SAAgBE,KAAhB,mBAA8BN,KAA9B,qBAA8CE,MAA9C;AACH","sourcesContent":["export interface ServerPaginationOptions {\n offset: number;\n limit: number;\n}\n\nexport function formatAttributesToServerPaginationOptions(\n elementAttributes: { name: string, value: number }[]\n): ServerPaginationOptions | undefined {\n const attributes = new Map(Array.from(elementAttributes).map(({ name, value }) => [name, value]))\n const limit = attributes.get('limit');\n const offset = attributes.get('offset');\n if (!offset || !limit) return;\n return {\n limit: limit,\n offset: offset,\n }\n}\n\nexport function appendServerPaginationToIri(iri: string, options: ServerPaginationOptions): string {\n const first = iri.includes('?') ? '&' : '?';\n const limit = options.limit;\n const offset = options.offset;\n return `${iri}${first}limit=${limit}&offset=${offset}`;\n}"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function formatAttributesToServerSearchOptions(elementAttributes) {
|
|
2
|
+
var _attributes$get, _attributes$get2, _attributes$get3;
|
|
3
|
+
|
|
4
|
+
const attributes = new Map(Array.from(elementAttributes).map(({
|
|
5
|
+
name,
|
|
6
|
+
value
|
|
7
|
+
}) => [name, value]));
|
|
8
|
+
const fields = (_attributes$get = attributes.get('server-search-fields')) === null || _attributes$get === void 0 ? void 0 : _attributes$get.split(",").map(field => field.trim());
|
|
9
|
+
const value = (_attributes$get2 = attributes.get('server-search-value')) === null || _attributes$get2 === void 0 ? void 0 : _attributes$get2.trim();
|
|
10
|
+
const method = (_attributes$get3 = attributes.get('server-search-method')) === null || _attributes$get3 === void 0 ? void 0 : _attributes$get3.trim();
|
|
11
|
+
return {
|
|
12
|
+
fields: fields && fields.length > 0 ? fields : undefined,
|
|
13
|
+
value: value ? value : undefined,
|
|
14
|
+
method: method ? method : undefined
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function mergeServerSearchOptions(attributesOptions, dynamicOptions) {
|
|
18
|
+
var _attributesOptions$fi, _dynamicOptions$value, _attributesOptions$me;
|
|
19
|
+
|
|
20
|
+
const fields = (_attributesOptions$fi = attributesOptions === null || attributesOptions === void 0 ? void 0 : attributesOptions.fields) !== null && _attributesOptions$fi !== void 0 ? _attributesOptions$fi : dynamicOptions === null || dynamicOptions === void 0 ? void 0 : dynamicOptions.fields;
|
|
21
|
+
const value = (_dynamicOptions$value = dynamicOptions === null || dynamicOptions === void 0 ? void 0 : dynamicOptions.value) !== null && _dynamicOptions$value !== void 0 ? _dynamicOptions$value : attributesOptions === null || attributesOptions === void 0 ? void 0 : attributesOptions.value;
|
|
22
|
+
const method = (_attributesOptions$me = attributesOptions === null || attributesOptions === void 0 ? void 0 : attributesOptions.method) !== null && _attributesOptions$me !== void 0 ? _attributesOptions$me : dynamicOptions === null || dynamicOptions === void 0 ? void 0 : dynamicOptions.method;
|
|
23
|
+
if (!fields || fields.length === 0 || !value) return;
|
|
24
|
+
return {
|
|
25
|
+
fields,
|
|
26
|
+
value,
|
|
27
|
+
method
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function appendServerSearchToIri(iri, options) {
|
|
31
|
+
var _options$method;
|
|
32
|
+
|
|
33
|
+
const first = iri.includes('?') ? '&' : '?';
|
|
34
|
+
const fields = options.fields.map(encodeURIComponent).join(',');
|
|
35
|
+
const value = encodeURIComponent(options.value);
|
|
36
|
+
const method = encodeURIComponent((_options$method = options.method) !== null && _options$method !== void 0 ? _options$method : 'ibasic');
|
|
37
|
+
return "".concat(iri).concat(first, "search-fields=").concat(fields, "&search-terms=").concat(value, "&search-method=").concat(method);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=server-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["server-search.ts"],"names":["formatAttributesToServerSearchOptions","elementAttributes","attributes","Map","Array","from","map","name","value","fields","get","split","field","trim","method","length","undefined","mergeServerSearchOptions","attributesOptions","dynamicOptions","appendServerSearchToIri","iri","options","first","includes","encodeURIComponent","join"],"mappings":"AAMA,OAAO,SAASA,qCAAT,CACLC,iBADK,EAEyB;AAAA;;AAC9B,QAAMC,UAAU,GAAG,IAAIC,GAAJ,CAAQC,KAAK,CAACC,IAAN,CAAWJ,iBAAX,EAA8BK,GAA9B,CAAkC,CAAC;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,GAAD,KAAqB,CAACD,IAAD,EAAOC,KAAP,CAAvD,CAAR,CAAnB;AACA,QAAMC,MAAM,sBAAGP,UAAU,CAACQ,GAAX,CAAe,sBAAf,CAAH,oDAAG,gBAAwCC,KAAxC,CAA8C,GAA9C,EAAmDL,GAAnD,CAAwDM,KAAD,IAAWA,KAAK,CAACC,IAAN,EAAlE,CAAf;AACA,QAAML,KAAK,uBAAGN,UAAU,CAACQ,GAAX,CAAe,qBAAf,CAAH,qDAAG,iBAAuCG,IAAvC,EAAd;AACA,QAAMC,MAAM,uBAAGZ,UAAU,CAACQ,GAAX,CAAe,sBAAf,CAAH,qDAAG,iBAAwCG,IAAxC,EAAf;AACA,SAAO;AACLJ,IAAAA,MAAM,EAAEA,MAAM,IAAIA,MAAM,CAACM,MAAP,GAAgB,CAA1B,GAA8BN,MAA9B,GAAuCO,SAD1C;AAELR,IAAAA,KAAK,EAAEA,KAAK,GAAGA,KAAH,GAAWQ,SAFlB;AAGLF,IAAAA,MAAM,EAAEA,MAAM,GAAGA,MAAH,GAAYE;AAHrB,GAAP;AAKD;AAED,OAAO,SAASC,wBAAT,CACLC,iBADK,EAELC,cAFK,EAG4B;AAAA;;AACjC,QAAMV,MAAM,4BAAGS,iBAAH,aAAGA,iBAAH,uBAAGA,iBAAiB,CAAET,MAAtB,yEAAgCU,cAAhC,aAAgCA,cAAhC,uBAAgCA,cAAc,CAAEV,MAA5D;AACA,QAAMD,KAAK,4BAAGW,cAAH,aAAGA,cAAH,uBAAGA,cAAc,CAAEX,KAAnB,yEAA4BU,iBAA5B,aAA4BA,iBAA5B,uBAA4BA,iBAAiB,CAAEV,KAA1D;AACA,QAAMM,MAAM,4BAAGI,iBAAH,aAAGA,iBAAH,uBAAGA,iBAAiB,CAAEJ,MAAtB,yEAAgCK,cAAhC,aAAgCA,cAAhC,uBAAgCA,cAAc,CAAEL,MAA5D;AACA,MAAI,CAACL,MAAD,IAAWA,MAAM,CAACM,MAAP,KAAkB,CAA7B,IAAkC,CAACP,KAAvC,EAA8C;AAC9C,SAAO;AAAEC,IAAAA,MAAF;AAAUD,IAAAA,KAAV;AAAiBM,IAAAA;AAAjB,GAAP;AACD;AAED,OAAO,SAASM,uBAAT,CAAiCC,GAAjC,EAA8CC,OAA9C,EAAoF;AAAA;;AACzF,QAAMC,KAAK,GAAGF,GAAG,CAACG,QAAJ,CAAa,GAAb,IAAoB,GAApB,GAA0B,GAAxC;AACA,QAAMf,MAAM,GAAGa,OAAO,CAACb,MAAR,CAAeH,GAAf,CAAmBmB,kBAAnB,EAAuCC,IAAvC,CAA4C,GAA5C,CAAf;AACA,QAAMlB,KAAK,GAAGiB,kBAAkB,CAACH,OAAO,CAACd,KAAT,CAAhC;AACA,QAAMM,MAAM,GAAGW,kBAAkB,oBAACH,OAAO,CAACR,MAAT,6DAAmB,QAAnB,CAAjC;AACA,mBAAUO,GAAV,SAAgBE,KAAhB,2BAAsCd,MAAtC,2BAA6DD,KAA7D,4BAAoFM,MAApF;AACD","sourcesContent":["export interface ServerSearchOptions {\n fields: string[];\n value: string;\n method?: string;\n}\n\nexport function formatAttributesToServerSearchOptions(\n elementAttributes: Iterable<Attr>\n): Partial<ServerSearchOptions> {\n const attributes = new Map(Array.from(elementAttributes).map(({ name, value }) => [name, value]));\n const fields = attributes.get('server-search-fields')?.split(\",\").map((field) => field.trim());\n const value = attributes.get('server-search-value')?.trim();\n const method = attributes.get('server-search-method')?.trim();\n return {\n fields: fields && fields.length > 0 ? fields : undefined,\n value: value ? value : undefined,\n method: method ? method : undefined\n }\n}\n\nexport function mergeServerSearchOptions(\n attributesOptions?: Partial<ServerSearchOptions>,\n dynamicOptions?: Partial<ServerSearchOptions>\n): ServerSearchOptions | undefined {\n const fields = attributesOptions?.fields ?? dynamicOptions?.fields;\n const value = dynamicOptions?.value ?? attributesOptions?.value;\n const method = attributesOptions?.method ?? dynamicOptions?.method;\n if (!fields || fields.length === 0 || !value) return;\n return { fields, value, method };\n}\n\nexport function appendServerSearchToIri(iri: string, options: ServerSearchOptions): string {\n const first = iri.includes('?') ? '&' : '?';\n const fields = options.fields.map(encodeURIComponent).join(',');\n const value = encodeURIComponent(options.value);\n const method = encodeURIComponent(options.method ?? 'ibasic');\n return `${iri}${first}search-fields=${fields}&search-terms=${value}&search-method=${method}`;\n}"]}
|
package/dist/libs/store/store.js
CHANGED
|
@@ -5,6 +5,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
5
5
|
import JSONLDContextParser from '../../_snowpack/pkg/jsonld-context-parser.js'; //@ts-ignore
|
|
6
6
|
|
|
7
7
|
import PubSub from 'https://cdn.skypack.dev/pubsub-js';
|
|
8
|
+
import { appendServerSearchToIri } from './server-search.js';
|
|
9
|
+
import { appendServerPaginationToIri } from './server-pagination.js';
|
|
8
10
|
const ContextParser = JSONLDContextParser.ContextParser;
|
|
9
11
|
const myParser = new ContextParser();
|
|
10
12
|
export const base_context = {
|
|
@@ -69,9 +71,11 @@ class Store {
|
|
|
69
71
|
* Fetch data and cache it
|
|
70
72
|
* @param id - uri of the resource to fetch
|
|
71
73
|
* @param context - context used to expand id and predicates when accessing the resource
|
|
72
|
-
* @param
|
|
74
|
+
* @param parentId - uri of the parent caller used to expand uri for local files
|
|
73
75
|
* @param localData - data to put in cache
|
|
74
76
|
* @param forceFetch - force the fetch of data
|
|
77
|
+
* @param serverPagination - Server pagination options
|
|
78
|
+
* @param serverSearch - Server search options
|
|
75
79
|
*
|
|
76
80
|
* @returns The fetched resource
|
|
77
81
|
*
|
|
@@ -79,16 +83,28 @@ class Store {
|
|
|
79
83
|
*/
|
|
80
84
|
|
|
81
85
|
|
|
82
|
-
async getData(id, context = {},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
async getData(id, context = {}, parentId = "", localData, forceFetch = false, serverPagination, serverSearch) {
|
|
87
|
+
let key = id;
|
|
88
|
+
|
|
89
|
+
if (serverPagination) {
|
|
90
|
+
key = id + "#p" + serverPagination.limit + "?o" + serverPagination.offset;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (serverSearch) {
|
|
94
|
+
key = appendServerSearchToIri(key, serverSearch);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (localData == null && this.cache.has(key) && !this.loadingList.has(key)) {
|
|
98
|
+
var _resource$isFullResou;
|
|
99
|
+
|
|
100
|
+
const resource = this.get(key);
|
|
101
|
+
if (resource && (_resource$isFullResou = resource.isFullResource) !== null && _resource$isFullResou !== void 0 && _resource$isFullResou.call(resource) && !forceFetch) return resource; // if resource is not complete, re-fetch it
|
|
86
102
|
}
|
|
87
103
|
|
|
88
104
|
return new Promise(async resolve => {
|
|
89
|
-
document.addEventListener('resourceReady', this.resolveResource(
|
|
90
|
-
if (this.loadingList.has(
|
|
91
|
-
this.loadingList.add(
|
|
105
|
+
document.addEventListener('resourceReady', this.resolveResource(key, resolve));
|
|
106
|
+
if (this.loadingList.has(key)) return;
|
|
107
|
+
this.loadingList.add(key); // Generate proxy
|
|
92
108
|
|
|
93
109
|
const clientContext = await myParser.parse(context);
|
|
94
110
|
let resource = null;
|
|
@@ -98,26 +114,26 @@ class Store {
|
|
|
98
114
|
localData["@id"] = id;
|
|
99
115
|
resource = localData;
|
|
100
116
|
} else try {
|
|
101
|
-
resource = localData || (await this.fetchData(id, clientContext,
|
|
117
|
+
resource = localData || (await this.fetchData(id, clientContext, parentId, serverPagination, serverSearch));
|
|
102
118
|
} catch (error) {
|
|
103
119
|
console.error(error);
|
|
104
120
|
}
|
|
105
121
|
|
|
106
122
|
if (!resource) {
|
|
107
|
-
this.loadingList.delete(
|
|
123
|
+
this.loadingList.delete(key);
|
|
108
124
|
resolve(null);
|
|
109
125
|
return;
|
|
110
126
|
}
|
|
111
127
|
|
|
112
128
|
const serverContext = await myParser.parse([resource['@context'] || {}]);
|
|
113
|
-
const resourceProxy = new CustomGetter(
|
|
129
|
+
const resourceProxy = new CustomGetter(key, resource, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch).getProxy(); // Cache proxy
|
|
114
130
|
|
|
115
|
-
await this.cacheGraph(
|
|
116
|
-
this.loadingList.delete(
|
|
131
|
+
await this.cacheGraph(key, resourceProxy, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch);
|
|
132
|
+
this.loadingList.delete(key);
|
|
117
133
|
document.dispatchEvent(new CustomEvent('resourceReady', {
|
|
118
134
|
detail: {
|
|
119
|
-
id:
|
|
120
|
-
resource: this.get(
|
|
135
|
+
id: key,
|
|
136
|
+
resource: this.get(key)
|
|
121
137
|
}
|
|
122
138
|
}));
|
|
123
139
|
});
|
|
@@ -144,13 +160,15 @@ class Store {
|
|
|
144
160
|
}
|
|
145
161
|
}
|
|
146
162
|
|
|
147
|
-
async fetchData(id, context = {},
|
|
148
|
-
|
|
163
|
+
async fetchData(id, context = {}, parentId = "", serverPagination, serverSearch) {
|
|
164
|
+
let iri = this._getAbsoluteIri(id, context, parentId);
|
|
149
165
|
|
|
166
|
+
if (serverPagination) iri = appendServerPaginationToIri(iri, serverPagination);
|
|
167
|
+
if (serverSearch) iri = appendServerSearchToIri(iri, serverSearch);
|
|
150
168
|
const headers = { ...this.headers,
|
|
151
|
-
'accept-language': this._getLanguage()
|
|
152
|
-
}; // console.log("Request Headers:", headers);
|
|
169
|
+
'accept-language': this._getLanguage() // 'Prefer' : 'return=representation; max-triple-count="100"' // Commenting out for now as it raises CORS errors
|
|
153
170
|
|
|
171
|
+
};
|
|
154
172
|
return this.fetchAuthn(iri, {
|
|
155
173
|
method: 'GET',
|
|
156
174
|
headers: headers,
|
|
@@ -161,12 +179,13 @@ class Store {
|
|
|
161
179
|
});
|
|
162
180
|
}
|
|
163
181
|
|
|
164
|
-
async cacheGraph(key, resource, clientContext, parentContext, parentId) {
|
|
182
|
+
async cacheGraph(key, resource, clientContext, parentContext, parentId, serverPagination, serverSearch) {
|
|
165
183
|
if (resource.properties) {
|
|
166
184
|
// if proxy, cache it
|
|
167
|
-
if (this.get(key)) {
|
|
185
|
+
if (this.get(key) && this.cache.get(key).merge) {
|
|
168
186
|
// if already cached, merge data
|
|
169
187
|
this.cache.get(key).merge(resource);
|
|
188
|
+
;
|
|
170
189
|
} else {
|
|
171
190
|
// else, put in cache
|
|
172
191
|
this.cache.set(key, resource);
|
|
@@ -183,17 +202,17 @@ class Store {
|
|
|
183
202
|
});
|
|
184
203
|
const resourceProxy = new CustomGetter(res['@id'], res, clientContext, newParentContext, parentId).getProxy(); // this.subscribeResourceTo(resource['@id'], res['@id']); // removed to prevent useless updates
|
|
185
204
|
|
|
186
|
-
await this.cacheGraph(res['@id'], resourceProxy, clientContext, parentContext, parentId);
|
|
205
|
+
await this.cacheGraph(res['@id'], resourceProxy, clientContext, parentContext, parentId, serverPagination, serverSearch);
|
|
187
206
|
}
|
|
188
207
|
} // Cache children of container
|
|
189
208
|
|
|
190
209
|
|
|
191
210
|
if (resource['@type'] == "ldp:Container" && resource.getChildren) {
|
|
192
|
-
const cacheChildrenPromises = [];
|
|
211
|
+
const cacheChildrenPromises = []; //TODO: return complete object without the need for the fetch data from the cacheGraph
|
|
193
212
|
|
|
194
|
-
for (let res of resource.getChildren()) {
|
|
213
|
+
for (let res of await resource.getChildren()) {
|
|
195
214
|
this.subscribeResourceTo(resource['@id'], res['@id']);
|
|
196
|
-
cacheChildrenPromises.push(this.cacheGraph(res['@id'], res, clientContext, parentContext, parentId));
|
|
215
|
+
cacheChildrenPromises.push(this.cacheGraph(res['@id'], res, clientContext, parentContext, parentId, serverPagination, serverSearch));
|
|
197
216
|
}
|
|
198
217
|
|
|
199
218
|
await Promise.all(cacheChildrenPromises);
|
|
@@ -212,7 +231,7 @@ class Store {
|
|
|
212
231
|
return;
|
|
213
232
|
}
|
|
214
233
|
|
|
215
|
-
const resourceProxy = new CustomGetter(
|
|
234
|
+
const resourceProxy = new CustomGetter(key, resource, clientContext, parentContext, parentId).getProxy();
|
|
216
235
|
await this.cacheGraph(key, resourceProxy, clientContext, parentContext, parentId);
|
|
217
236
|
}
|
|
218
237
|
}
|
|
@@ -319,8 +338,10 @@ class Store {
|
|
|
319
338
|
|
|
320
339
|
|
|
321
340
|
async getNestedResources(resource, id) {
|
|
341
|
+
var _cachedResource$isCon;
|
|
342
|
+
|
|
322
343
|
const cachedResource = store.get(id);
|
|
323
|
-
if (!cachedResource || cachedResource.isContainer()) return [];
|
|
344
|
+
if (!cachedResource || (_cachedResource$isCon = cachedResource.isContainer) !== null && _cachedResource$isCon !== void 0 && _cachedResource$isCon.call(cachedResource)) return [];
|
|
324
345
|
let nestedProperties = [];
|
|
325
346
|
const excludeKeys = ['@context'];
|
|
326
347
|
|
|
@@ -340,7 +361,11 @@ class Store {
|
|
|
340
361
|
*/
|
|
341
362
|
|
|
342
363
|
|
|
343
|
-
get(id) {
|
|
364
|
+
get(id, serverSearch) {
|
|
365
|
+
if (serverSearch) {
|
|
366
|
+
id = appendServerSearchToIri(id, serverSearch);
|
|
367
|
+
}
|
|
368
|
+
|
|
344
369
|
return this.cache.get(id) || null;
|
|
345
370
|
}
|
|
346
371
|
/**
|
|
@@ -420,7 +445,6 @@ class Store {
|
|
|
420
445
|
|
|
421
446
|
|
|
422
447
|
async purge(id) {
|
|
423
|
-
// console.log('Purging resource ' + id);
|
|
424
448
|
await this.fetchAuthn(id, {
|
|
425
449
|
method: "PURGE",
|
|
426
450
|
headers: this.headers
|
|
@@ -591,7 +615,9 @@ class CustomGetter {
|
|
|
591
615
|
// context given by the app
|
|
592
616
|
// context given by the server
|
|
593
617
|
// id of the parent resource, used to get the absolute url of the current resource
|
|
594
|
-
|
|
618
|
+
// pagination attributes to give to server
|
|
619
|
+
// search attributes to give to server
|
|
620
|
+
constructor(resourceId, resource, clientContext, serverContext = {}, parentId = "", serverPagination = {}, serverSearch = {}) {
|
|
595
621
|
_defineProperty(this, "resource", void 0);
|
|
596
622
|
|
|
597
623
|
_defineProperty(this, "resourceId", void 0);
|
|
@@ -602,12 +628,18 @@ class CustomGetter {
|
|
|
602
628
|
|
|
603
629
|
_defineProperty(this, "parentId", void 0);
|
|
604
630
|
|
|
631
|
+
_defineProperty(this, "serverPagination", void 0);
|
|
632
|
+
|
|
633
|
+
_defineProperty(this, "serverSearch", void 0);
|
|
634
|
+
|
|
605
635
|
this.clientContext = clientContext;
|
|
606
636
|
this.serverContext = serverContext;
|
|
607
637
|
this.parentId = parentId;
|
|
608
638
|
this.resource = this.expandProperties({ ...resource
|
|
609
639
|
}, serverContext);
|
|
610
640
|
this.resourceId = resourceId;
|
|
641
|
+
this.serverPagination = serverPagination;
|
|
642
|
+
this.serverSearch = serverSearch;
|
|
611
643
|
}
|
|
612
644
|
/**
|
|
613
645
|
* Expand all predicates of a resource with a given context
|