@igea/oac_frontend 1.0.52 → 1.0.54

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igea/oac_frontend",
3
- "version": "1.0.52",
3
+ "version": "1.0.54",
4
4
  "description": "Frontend service for the OAC project",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -18,7 +18,7 @@ module.exports = function(serviceName) {
18
18
  }
19
19
 
20
20
  router.get('/form', (req, res) => {
21
- renderForm(req, res, null);
21
+ renderForm(req, res, '');
22
22
  });
23
23
 
24
24
  router.get('/form/:uuid', (req, res) => {
@@ -85,7 +85,7 @@
85
85
  "max_files": "You can upload up to 5 files at a time",
86
86
  "max_size": "Each file must be less than 10MB",
87
87
  "select_vocabolary": "Select a vocabolary to view its items",
88
- "terms": "Terms"
88
+ "terms": "Vocabulary entries"
89
89
  }
90
90
  },
91
91
  "investigation":{
@@ -95,9 +95,12 @@
95
95
  "form_invalid": "The form contains errors. Please correct them before submitting.",
96
96
  "submit": "Save",
97
97
  "reset": "Reset",
98
+ "validate": "Validate",
98
99
  "show_more": "Show more",
99
100
  "confirm": "Confirm",
100
- "download": "Download"
101
+ "download": "Download",
102
+ "select_instance": "Select an instance",
103
+ "generated_output": "Generated output"
101
104
  }
102
105
  },
103
106
  "search": {
@@ -88,7 +88,7 @@
88
88
  "upload_error": "Errore durante il caricamento dei file",
89
89
  "invalid_file": "Tipo di file non valido",
90
90
  "select_vocabolary": "Seleziona un vocabolario per visualizzarne gli elementi",
91
- "terms": "Termini"
91
+ "terms": "Voci del vocabolario"
92
92
  }
93
93
  },
94
94
  "investigation": {
@@ -98,9 +98,12 @@
98
98
  "form_invalid": "La scheda contiene errori. Correggerli per poterla salvare correttamente.",
99
99
  "submit": "Invia",
100
100
  "reset": "Reimposta",
101
+ "validate": "Valida",
101
102
  "show_more": "Mostra di più",
102
103
  "confirm": "Conferma",
103
- "download": "Scarica"
104
+ "download": "Scarica",
105
+ "select_instance": "Seleziona un'istanza",
106
+ "generated_output": "Output generato"
104
107
  }
105
108
  },
106
109
  "search": {
@@ -2,8 +2,10 @@ const {createApp} = Vue;
2
2
 
3
3
  const appId = 'investigation-app';
4
4
  const shaclId = 'shacl-form';
5
+
6
+ const templateIRIOfIndagine = "http://diagnostica/indagine/$UUID$";
5
7
  const templateIRIToExcludeFromSearch = [
6
- "http://diagnostica/indagine/$UUID$"
8
+ templateIRIOfIndagine
7
9
  ];
8
10
 
9
11
  document.addEventListener('DOMContentLoaded', () => {
@@ -14,7 +16,7 @@ document.addEventListener('DOMContentLoaded', () => {
14
16
  data() {
15
17
  return {
16
18
  cur_role: parseInt(el.dataset.cur_role),
17
- uuid: parseInt(el.dataset.uuid) || null,
19
+ uuid: el.dataset.uuid || null,
18
20
  form: null,
19
21
  enabled: el.dataset.editing == "true",
20
22
  serializedForm: "",
@@ -35,7 +37,6 @@ document.addEventListener('DOMContentLoaded', () => {
35
37
  },
36
38
  mounted() {
37
39
  this.initShaclForm();
38
- this.load();
39
40
  },
40
41
  computed:{
41
42
  outputStyle(){
@@ -77,23 +78,30 @@ document.addEventListener('DOMContentLoaded', () => {
77
78
  },
78
79
  initShaclForm() {
79
80
  var _this = this;
80
- this.form = document.querySelector("shacl-form");
81
- const output = document.getElementById("shacl-output")
82
- this.form.addEventListener('change', event => {
83
- // check if form data validates according to the SHACL shapes
84
- _this.validForm = event.detail?.valid;
85
- _this.serializedForm = _this.form.serialize();
86
- });
87
- this.form.addEventListener("ready", () => {
88
- var intervalId = setInterval(() => {
89
- if(_this.form.shadowRoot){
90
- clearInterval(intervalId);
91
- _this.inputIdentifizier();
92
- if(!_this.enabled)
93
- _this.disableInteractions(_this.form);
94
- }
95
- }, 100);
96
- });
81
+ setTimeout(async ()=>{
82
+ _this.form = document.querySelector("shacl-form");
83
+ const output = document.getElementById("shacl-output")
84
+
85
+ //await _this.load(this.uuid);
86
+
87
+ _this.form.addEventListener('change', event => {
88
+ // check if form data validates according to the SHACL shapes
89
+ _this.validForm = event.detail?.valid;
90
+ _this.serializedForm = _this.form.serialize();
91
+ });
92
+
93
+ _this.form.addEventListener("ready", () => {
94
+ var intervalId = setInterval(() => {
95
+ if(_this.form.shadowRoot){
96
+ clearInterval(intervalId);
97
+ _this.inputIdentifizier();
98
+ if(!_this.enabled)
99
+ _this.disableInteractions(_this.form);
100
+ }
101
+ }, 100);
102
+ });
103
+
104
+ })
97
105
  },
98
106
  searchByPrefixStart(rokitInput, prefix){
99
107
  this.search.offset = 0;
@@ -167,15 +175,17 @@ document.addEventListener('DOMContentLoaded', () => {
167
175
  // Disabilita rokit-input
168
176
  const rokitInput = container.querySelector("rokit-input");
169
177
  if (rokitInput) {
178
+ var isIndagineIdField = templateIRIOfIndagine === rokitInput.placeholder;
170
179
  if(rokitInput.value == ""){
171
- rokitInput.value = _this.generateIRI(rokitInput.placeholder);
180
+ rokitInput.value = _this.generateIRI(rokitInput, isIndagineIdField);
172
181
  }
182
+
173
183
  rokitInput.setAttribute("disabled", "true");
174
184
  rokitInput.style.opacity = "0.6";
175
185
  rokitInput.style.pointerEvents = "none";
176
186
 
177
187
  var escludeSearchButton = templateIRIToExcludeFromSearch.includes(rokitInput.placeholder);
178
-
188
+
179
189
  if(_this.enabled && !escludeSearchButton){
180
190
  // Aggiungo bottone IMG per la ricerca
181
191
  let next = label.nextElementSibling;
@@ -254,15 +264,81 @@ document.addEventListener('DOMContentLoaded', () => {
254
264
  }
255
265
  }
256
266
  },
257
- generateIRI(template, uuid){
258
- var _uuid = uuid || crypto.randomUUID();
259
- return template.replace("$uuid$", _uuid).replace("$UUID$", _uuid);
267
+ generateIRI(input, isIndagne){
268
+ var template = input.placeholder;
269
+ setTimeout((async function(){
270
+ var _uuid = crypto.randomUUID();
271
+ template = template.replace("$uuid$", _uuid).replace("$UUID$", _uuid);
272
+ for(var i=1; i<=9; i++){
273
+ var seq = "seq" + i;
274
+ var searchStr = "$" + seq + "$";
275
+ var searchStrUpp = searchStr.toUpperCase();
276
+ if(template.toLowerCase().includes(searchStr)){
277
+ var response = await fetch('/backend/ontology/counter/' + seq ).then(resp => resp.json());
278
+ if(response.success && response.data){
279
+ var counter = response.data;
280
+ template = template.replace(searchStr, counter).replace(searchStrUpp, counter);
281
+ }
282
+ }
283
+ }
284
+ input.value = template;
285
+ if(isIndagne){
286
+ this.uuid = input.value.split("/").pop();
287
+ }
288
+ }).bind(this));
260
289
  },
261
- load() {
262
-
290
+ async load(uuid) {
291
+ if(uuid){
292
+ const dataTTL = await fetch("/backend/ontology/form/" + uuid).then(resp => resp.text())
293
+ this.form.dataset['values'] = dataTTL;
294
+ }
263
295
  },
296
+
297
+ async load_(uuid, callback){
298
+ this.form.setClassInstanceProvider((clazz) => {
299
+ if (clazz === 'http://example.org/Material') {
300
+ return `
301
+ <http://example.org/steel> a <http://example.org/Material>; <http://www.w3.org/2000/01/rdf-schema#label> "Steel".
302
+ <http://example.org/wood> a <http://example.org/Material>; <http://www.w3.org/2000/01/rdf-schema#label> "Wood".
303
+ <http://example.org/alloy> a <http://example.org/Material>; <http://www.w3.org/2000/01/rdf-schema#label> "Alloy".
304
+ <http://example.org/plaster> a <http://example.org/Material>; <http://www.w3.org/2000/01/rdf-schema#label> "Plaster".
305
+ `
306
+ }
307
+ });
308
+ const shapesTTL = await fetch("https://ulb-darmstadt.github.io/shacl-form/complex-example.ttl").then(resp => resp.text())
309
+ const dataTTL = await fetch("https://ulb-darmstadt.github.io/shacl-form/complex-example-data.ttl").then(resp => resp.text())
310
+ this.form.dataset['shapes'] = shapesTTL
311
+ this.form.dataset['values'] = dataTTL
312
+ callback()
313
+ },
314
+
264
315
  save() {
265
-
316
+ var request = axios.post("/backend/ontology/form/save", {
317
+ turtle: this.serializedForm,
318
+ uuid: this.uuid
319
+ });
320
+ request.then(response => {
321
+ var obj = response.data;
322
+ if(obj.success)
323
+ alert("Saved: OK")
324
+ else
325
+ alert("Error: " + obj.message)
326
+ }).catch(error => {
327
+ console.log(error);
328
+ });
329
+ },
330
+ validate() {
331
+ var request = axios.post("/backend/ontology/validate", {
332
+ turtle: this.serializedForm
333
+ });
334
+ request.then(response => {
335
+ var obj = response.data;
336
+ var data = obj.data
337
+ console.log(data.conforms);
338
+ console.log(data.details);
339
+ }).catch(error => {
340
+ console.log(error);
341
+ });
266
342
  },
267
343
  reset() {
268
344
  window.location.reload();