Commit c79d74a8 authored by Adam Procter's avatar Adam Procter

newstuff

parent 2486a4f3
Pipeline #188 failed with stages
in 1 minute and 21 seconds
...@@ -29,8 +29,10 @@ export default { ...@@ -29,8 +29,10 @@ export default {
}, },
methods: { methods: {
login() { login() {
//FIXME check this.input.email against pouch valid accounts
//FIXME generate token, save to remote and local session stores
this.$store.dispatch("login", { this.$store.dispatch("login", {
email: this.email email: this.input.email
}).then(() => { }).then(() => {
this.$router.push("/home") this.$router.push("/home")
}); });
......
...@@ -18,92 +18,94 @@ import { mapGetters } from 'vuex'; ...@@ -18,92 +18,94 @@ import { mapGetters } from 'vuex';
import styledviewer from "@/components/styled-viewer.vue"; import styledviewer from "@/components/styled-viewer.vue";
export default { export default {
name: 'user-interface', name: 'user-interface',
components: {
components: { styledviewer: styledviewer
styledviewer: styledviewer },
data:{
}, },
methods: {
data:{ ...mapGetters([
'allObjects'
])
}, },
props: {
methods: { object: Object
...mapGetters([ },
'allObjects' mounted: function() {
]) // SVG UI next
}, var draw = SVG('user-interface').size(600, 300)
props: { var data = [];
object: Object
},
mounted: function() {
// SVG UI next
var draw = SVG('user-interface').size(600, 300)
var data = [];
let objects = this.allObjects()
objects.forEach((element) => {
data.push(element.__ob__.value.doc)
})
var links = draw.group()
var markers = draw.group()
var nodes = draw.group()
var index = 0
var colours = [
'red',
'green',
'blue',
'yellow',
'cyan',
];
data.forEach(element => {
//index = index + 20
var knowledgeObj = nodes.group().translate(element.xpos, element.ypos).draggy({minX: 0,
minY: 0,
maxX: 600,
maxY: 300})
if (element.type == "projecttxt"){ let objects = this.allObjects()
objects.forEach((element) => {
knowledgeObj.rect(60, 40).attr({ data.push(element.__ob__.value.doc)
fill: colours[Math.floor(Math.random() * colours.length)] })
})
}else if (element.type == "slidedeck"){ var links = draw.group()
knowledgeObj.circle(30, 30).attr({ var markers = draw.group()
fill: colours[Math.floor(Math.random() * colours.length)] var nodes = draw.group()
})
var index = 0
var colours = [
} 'red',
var type = knowledgeObj.text(element.type) 'green',
var owner = knowledgeObj.text(element.owner) 'blue',
'yellow',
owner.move(0,40) 'cyan',
];
// rect_1.connectable({
// container: links, data.forEach(element => {
// markers: markers //index = index + 20
// }, rect_2).setLineColor("#000000");
}) var knowledgeObj = nodes.group().translate(element.xpos, element.ypos).draggy({minX: 0,
minY: 0,
nodes.click(node => { maxX: 600,
console.log("start connect") maxY: 300})
if (element.type == "projecttxt"){
knowledgeObj.rect(60, 40).attr({
fill: colours[Math.floor(Math.random() * colours.length)]
})
} else if (element.type == "slidedeck"){
knowledgeObj.circle(30, 30).attr({
fill: colours[Math.floor(Math.random() * colours.length)]
})
}
var type = knowledgeObj.text(element.type)
var owner = knowledgeObj.text(element.owner)
console.log(knowledgeObj)
owner.move(0,40)
// rect_1.connectable({
// container: links,
// markers: markers
// }, rect_2).setLineColor("#000000");
}) })
// mousedown is capturing a single mouse press
nodes.dblclick(node => { // possibly useful for drawing connections between objects
console.log("open styled viewer component") nodes.mousedown(node => {
// component styled-viewer console.log("start connect")
}) })
// mouseup is where we capture position of objects after they have been moved
}, // FIXME: determine unique ID of the node that has been moved
// FIXME: associate each node with a knowledge object in the db
// so we have a mapping to record these movements
nodes.mouseup(node => {
//console.log(node)
console.log("x: "+node.clientX)
console.log("y: "+node.clientY)
})
nodes.dblclick(node => {
console.log("open styled viewer component")
// component styled-viewer
})
},
} }
</script> </script>
......
...@@ -27,6 +27,8 @@ new Vue({ ...@@ -27,6 +27,8 @@ new Vue({
render: h => h(App) render: h => h(App)
}).$mount('#app') }).$mount('#app')
//store.dispatch("db_init");
{ {
require('@/assets/js/custom') require('@/assets/js/custom')
} }
......
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import pouchdb from 'pouchdb'
const accounts_db = new pouchdb('accounts');
const knowledge_db = new pouchdb('knowledge');
// server admin has to create DB first and CORS allows specific domains.
var remote_accounts_db = new pouchdb('https://nn.adamprocter.co.uk/accounts');
var remote_knowledge_db = new pouchdb('https://nn.adamprocter.co.uk/knowledge');
Vue.use(Vuex) Vue.use(Vuex)
...@@ -10,6 +17,7 @@ const LOGOUT = "LOGOUT"; ...@@ -10,6 +17,7 @@ const LOGOUT = "LOGOUT";
export default new Vuex.Store({ export default new Vuex.Store({
state: { state: {
allobjects: [], allobjects: [],
database: null,
isLoggedIn: !!localStorage.getItem("token"), isLoggedIn: !!localStorage.getItem("token"),
}, },
getters: { getters: {
...@@ -21,6 +29,9 @@ export default new Vuex.Store({ ...@@ -21,6 +29,9 @@ export default new Vuex.Store({
}, },
}, },
mutations: { mutations: {
DB_INIT(state, data) {
state.database = data.database;
},
ADD_KNOWLEDGE_OBJECT (state, payload) { ADD_KNOWLEDGE_OBJECT (state, payload) {
var ids = []; var ids = [];
state.allobjects.forEach(item => {ids.push(item.id)}) state.allobjects.forEach(item => {ids.push(item.id)})
...@@ -40,14 +51,29 @@ export default new Vuex.Store({ ...@@ -40,14 +51,29 @@ export default new Vuex.Store({
} }
}, },
actions: { actions: {
// https://www.nativescript.org/blog/data-management-with-sqlite-and-vuex-in-a-nativescript-vue-app
// db initialisation, query, and write need to flow through vuex
// db should be stored in store
db_init(context) {
(new pouchdb('accounts')).then(db => {
console.log("Initiated local pouch")
db.execSQL("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY AUTOINCREMENT, firstname TEXT, lastname TEXT)").then(id => {
context.commit("DB_INIT", { database: db });
}, error => {
console.log("CREATE TABLE ERROR", error);
});
}, error => {
console.log("OPEN DB ERROR", error);
});
},
addKnowledgeObject({ commit }, payload) { addKnowledgeObject({ commit }, payload) {
commit('ADD_KNOWLEDGE_OBJECT', payload) commit('ADD_KNOWLEDGE_OBJECT', payload)
}, },
login({ commit }) { login({ commit }, payload) {
commit(LOGIN); commit(LOGIN, payload);
return new Promise(resolve => { return new Promise(resolve => {
setTimeout(() => { setTimeout(() => {
localStorage.setItem("token", "JWT"); localStorage.setItem("token", payload.email);
commit(LOGIN_SUCCESS); commit(LOGIN_SUCCESS);
resolve(); resolve();
}, 1000); }, 1000);
...@@ -58,4 +84,4 @@ export default new Vuex.Store({ ...@@ -58,4 +84,4 @@ export default new Vuex.Store({
commit(LOGOUT); commit(LOGOUT);
} }
} }
}) })
\ No newline at end of file
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<option value="plaintxt">Plain Text</option> <option value="plaintxt">Plain Text</option>
</select> </select>
<input v-model="owner" placeholder="Author" /> <input v-model="owner" placeholder="Owner" />
<textarea v-model="metadata.mdtxt" type="text" placeholder="Enter text here" rows="10"></textarea> <textarea v-model="metadata.mdtxt" type="text" placeholder="Enter text here" rows="10"></textarea>
<button type="submit"><font-awesome-icon icon="save" size="2x"/></button> <button type="submit"><font-awesome-icon icon="save" size="2x"/></button>
...@@ -38,6 +38,7 @@ name: 'editor', ...@@ -38,6 +38,7 @@ name: 'editor',
data() { data() {
return { return {
type:'', type:'',
author:'',
owner:'', owner:'',
connections:[], connections:[],
metadata:{}, metadata:{},
...@@ -57,6 +58,7 @@ name: 'editor', ...@@ -57,6 +58,7 @@ name: 'editor',
localdb.put({ localdb.put({
_id:uniqueid, _id:uniqueid,
type:this.type, type:this.type,
author:localStorage.getItem("token"),
owner:this.owner, owner:this.owner,
connections:this.connections, connections:this.connections,
metadata:this.metadata, metadata:this.metadata,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment