Skip to content

Commit

Permalink
business logic processing
Browse files Browse the repository at this point in the history
  • Loading branch information
dragos-eu committed Nov 7, 2024
1 parent 978be3c commit e14c50e
Show file tree
Hide file tree
Showing 7 changed files with 1,184 additions and 697 deletions.
2 changes: 1 addition & 1 deletion ESPD/examples/espd.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"D": ["C61"]
},
"partIII": {
"A": ["C1", "C2", "C3", "C4", "C5", "C6"],
"A": ["C1", "C2", "C3", "C4", "C5", "C6"],
"B": ["C7", "C8"],
"C": ["C9", "C10", "C11", "C12", "C13", "C14", "C15", "C16", "C17", "C18", "C19", "C20", "C21", "C22", "C23"],
"D": ["C24"]
Expand Down
6 changes: 3 additions & 3 deletions ESPD/examples/startComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Vue.component("startComponent", {
if (thecall.ok) {
window.espd_model = data
//build the components for this version on demand
//factoryComponents()
componentsFactory()
}
} catch (error) {
console.log(error)
Expand All @@ -43,8 +43,8 @@ Vue.component("startComponent", {
},

updated(){
saveData(this.exp)
this.$store.commit('savekv', {key:'start', value:this.exp})
window.espd_doc = this.exp
},

created(){
Expand Down Expand Up @@ -75,7 +75,7 @@ Vue.component("startComponent", {
window.espd_model = data
window.espd_data = {}
//create the components for this version based on the model
//factoryComponents()
componentsFactory()
}
}
} catch (error) {
Expand Down
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@

<!-- Translation file -->
<script src="src/js/messages.js"></script>
<!-- Vuejs utility functions -->

<!-- Utility library and functions -->
<script src="src/js/utils.js"></script>
<script src="src/js/pdb.js"></script>
<script src="src/js/espd.js"></script>

<!-- Vue components and application logic -->
<script src="ESPD/model/espd_common.js"></script>
Expand Down Expand Up @@ -122,7 +125,7 @@
</b-nav>
</div>
<!-- Main content here -->
<component v-bind:is="mainComponent"></component>
<component v-bind:is="mainComponent" ref="mainComponent"></component>
</main>
<!--<footer class="footer">-->
<!-- We want footer content here -->
Expand Down
1,024 changes: 1,024 additions & 0 deletions src/js/espd.js

Large diffs are not rendered by default.

95 changes: 95 additions & 0 deletions src/js/pdb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* PouchDB Utils
*/


/**
* PouchDB global variable - browser persistent storage
*/

var GlobalPouchDB = new PouchDB('espd_demo')

/**
* Upsert document in PouchDB
* - update if existing
* - insert if not existing
*
* @param {string} docid - _id of the document
* @param {*} docdata - object containing data
* @returns OK | NOK
*/
const pdb_upsert = async (docid, docdata) => {
try {
const tmp_doc = await GlobalPouchDB.get(docid)
const response = await GlobalPouchDB.put({ _id: docid, _rev: tmp_doc._rev, data: docdata })
console.log(response)
return 'OK'
} catch (error) {
if (error.status == '404') {
try {
const response = await GlobalPouchDB.put({ _id: docid, data: docdata })
console.log(response)
return 'OK'
} catch (err) {
console.log(err)
return 'KO'
}
}
console.log(error)
return 'KO'
}
}

/**
* Load data - the general structure
* {
* _id: [code_lists | espd_meta | espd_edm_v3.3.0 | espd_edm_v4.0.0 | uuid]
* data: <object with specific data>
* }
*/
const loadData = async () => {
try {

let myCall = await fetch('ESPD/codelists/codelist.json')
let data = await myCall.json()
if (myCall.ok) {
//store code_lists in PouchDB
const response = await pdb_upsert('code_lists', data.code_lists)
console.log(response);
}

myCall = await fetch('ESPD/examples/espd.json')
data = await myCall.json()
if (myCall.ok) {
const response = await pdb_upsert('espd_meta', data.versions)
console.log(response)
}

myCall = await fetch('ESPD/model/espd_edm_v3.3.0.json')
data = await myCall.json()
if (myCall.ok) {
const response = await pdb_upsert('espd_edm_v3.3.0', data)
console.log(response)
}

myCall = await fetch('ESPD/model/espd_edm_v4.0.0.json')
data = await myCall.json()
if (myCall.ok) {
const response = await pdb_upsert('espd_edm_v4.0.0', data)
console.log(response)
}

myCall = await fetch('ESPD/uuid/uuid.json')
data = await myCall.json()
if (myCall.ok) {
const response = await pdb_upsert('uuid', data.uuid_files)
console.log(response)
}
} catch (error) {
console.log(error)

}
}

//Initialize PouchDB with data from server - no remote database
//loadData()
23 changes: 0 additions & 23 deletions src/js/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,6 @@ Vue.component("service", {

methods: {
nextStep() {
//Get the data from child components using $refs, check and merge with data from window
/*
let key = this.steps[this.crt_step].component
switch (key) {
case 'startComponent':
console.log(this.$refs[key]._data)
break;
case 'procedureComponent': case 'exclusionGrounds': case 'selectionCriteria': case 'ESPDdownload':
console.log(this.$refs[key]._data)
for (const el in window.espd_model) {
if (Object.hasOwn(window.espd_model, el)) {
const element = window.espd_model[el];
if(Object.hasOwn(this.$refs[key].$refs, `${window.espd_doc.espd_version}-${el}`))
console.log(this.$refs[key]?.$refs[`${window.espd_doc.espd_version}-${el}`][0]._data)
}
}
break
default:
console.log(key)
break;
}
*/
this.crt_step = Math.min(this.crt_step + 1, this.steps.length - 1)

},
Expand All @@ -47,7 +25,6 @@ Vue.component("service", {
},

created() {
if (window.espd_doc) delete window.espd_doc
window.espd_doc = {}
},

Expand Down
Loading

0 comments on commit e14c50e

Please sign in to comment.