diff --git a/src/App.vue b/src/App.vue index e918911af8638a9a169de436d239488cfc863583..625f7a73f4add4cf29ad9dc17a699d8c197886bc 100644 --- a/src/App.vue +++ b/src/App.vue @@ -261,6 +261,7 @@ export default { collection: "", sampleCollection: "", solrbaseurl: "https://app01.cc.univie.ac.at:8983/solr/phaidra_sandbox", + mongobaseurl: "http://localhost:8081", phaidrabaseurl: "phaidra-sandbox.univie.ac.at", trackerbaseurl: "www.univie.ac.at/phaidra-stat/piwik", siteid: 19, @@ -1193,6 +1194,7 @@ export default { suggester: "ols", url: "ols: 'http://www.ebi.ac.uk/ols/api/" }); + this.$store.commit("setInstanceMongo", this.mongobaseurl); this.$store.commit("initStore"); // this commits initStore in every store module which has it this.createContainerForm(); diff --git a/src/components/input/PhSubmit.vue b/src/components/input/PhSubmit.vue index 8cfce64843eb0c90fa135a7447771795c18bba31..08ba3544e1a0b4b983e2534c460821791eb642b3 100644 --- a/src/components/input/PhSubmit.vue +++ b/src/components/input/PhSubmit.vue @@ -10,6 +10,7 @@ </template> </v-tab> <v-tab ripple @click="updatePrettyPrint()">Metadata preview</v-tab> + <v-tab ripple @click="addPost()">Mongo</v-tab> <!-- <v-tab v-if="templating" ripple @click="loadTemplates()">Templates</v-tab>--> </v-tabs> @@ -46,14 +47,16 @@ import VueJsonPretty from "vue-json-pretty"; import arrays from "../../utils/arrays"; import jsonLd from "../../utils/json-ld"; import fields from "../../utils/fields"; - +import PostsService from "@/services/PostsService"; +import axios from "axios"; import PhInputForm from "./pharma-input-fields/PhInputForm"; +import { filterjsonfields } from "@/mixins/filterjsonfields"; export default { name: "ph-submit", + mixins: [filterjsonfields], components: { PhInputForm, - VueJsonPretty }, props: { @@ -128,7 +131,9 @@ export default { previewMember: "", searchfieldsinput: "", metadatapreview: {}, - ticked: [] + ticked: [], + title: "ICI", + description: "voila" }; }, methods: { @@ -239,6 +244,41 @@ export default { return "unknown"; } }, + submitMongo: async function() { + var self = this; + + //var httpFormData = new FormData(); + var myjson = { + title: "poupinette", + description: "mon poupie" + }; + //httpFormData.append(JSON.stringify(myjson)); + + //console.log("httpFormData", self.getMetadata()); + + axios.post( + self.$store.state.settings.instance.mongo + "/posts", + { + title: "NOW", + description: "NOWWWWWWWWWWWWWWWWWWWWWWW" + }, + { + headers: { + "Content-Type": "application/json" + } + } + ); + // fetch(self.$store.state.settings.instance.mongo, { + // method: "POST", + // headers: { + // "Content-Type": "application/json" + // }, + // body: JSON.stringify(myjson) + // }) + // .then(response => response.json()) + // .then(function(json) {}) + // .catch(function(error) {}); + }, submit: async function() { var self = this; this.loading = true; @@ -408,7 +448,36 @@ export default { self.loading = false; self.$store.commit("setAlerts", []); this.submit(); + //need to launch the script to mongodb + } + }, + async addPost() { + var self = this; + if (self.getMetadata().metadata["json-ld"].container) { + var myJson = self.getMetadata().metadata["json-ld"].container; + console.log(self.getField(myJson, "pharmaWien:disease")); + /*if ( + self.getMetadata().metadata["json-ld"].container["dcterms:subject"] + ) { + var pharmaMetada = self.getMetadata().metadata["json-ld"].container[ + "dcterms:subject" + ]; + //filter for all the @type which are relevant + var result = pharmaMetada.filter(obj => { + return obj["@type"] === "pharmaWien:disease"; + }); + console.log("results", result); + }*/ } + + var httpFormData = new FormData(); + //console.log("lalalal", self.getMetadata(), pharmaMetada); + + await PostsService.addPost({ + phaidraId: "objectID", + disease: this.description + }); + //this.$router.push({ name: 'Posts' }) } }, mounted: function() { diff --git a/src/mixins/filterjsonfields.js b/src/mixins/filterjsonfields.js new file mode 100644 index 0000000000000000000000000000000000000000..c6dbb7408ee486d144b14b16c435c60aa50c38fa --- /dev/null +++ b/src/mixins/filterjsonfields.js @@ -0,0 +1,20 @@ +export const filterjsonfields = { + methods: { + getField: function (jsonObject, type) { + console.log("in getfields", jsonObject) + if (jsonObject) { + if (jsonObject["dcterms:subject"]) { + var pharmaMetada = jsonObject["dcterms:subject"]; + //filter for all the @type which are relevant + var result = pharmaMetada.filter(obj => { + return obj["@type"] === type; + }); + console.log("results", result); + return result; + } + } + }, + + + } +}; diff --git a/src/services/Api.js b/src/services/Api.js new file mode 100644 index 0000000000000000000000000000000000000000..d2722d04dc557e6682b8c1691e6eba0fb71751b0 --- /dev/null +++ b/src/services/Api.js @@ -0,0 +1,8 @@ +import axios from "axios"; + +export default () => { + return axios.create({ + //baseURL: this.$store.state.settings.instance.mongo + baseURL: "http://localhost:8081" + }); +}; diff --git a/src/services/PostsService.js b/src/services/PostsService.js new file mode 100644 index 0000000000000000000000000000000000000000..5179471d8e9f7053c9e6a15eaa31232856d958c4 --- /dev/null +++ b/src/services/PostsService.js @@ -0,0 +1,12 @@ +import Api from "@/services/Api"; + +export default { + fetchPosts() { + console.log("in fetch posts", Api().get("posts")); + return Api().get("posts"); + }, + + addPost(params) { + return Api().post("posts", params); + } +}; diff --git a/src/store/index.js b/src/store/index.js index ce99f7b355e523ec56f90df66b86b4be899d302d..10107d6f1b1a3043bbabc70baf23c4f88f07d6c8 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -14,7 +14,8 @@ export default new Vuex.Store({ instance: { api: "", solr: "", - baseurl: "" + baseurl: "", + mongo: "" }, global: { suggesters: {} @@ -57,6 +58,9 @@ export default new Vuex.Store({ setInstanceSolr(state, solr) { state.settings.instance.solr = solr; }, + setInstanceMongo(state, mongo) { + state.settings.instance.mongo = mongo; + }, setInstancePhaidra(state, baseurl) { state.settings.instance.baseurl = baseurl; },