Commit 36056767 authored by Adam Procter's avatar Adam Procter

store changes

parent fabc4f33
Pipeline #198 failed with stages
in 1 minute and 7 seconds
This diff is collapsed.
<template>
<section class="register">
<h1>Register</h1>
<form @submit.prevent="register()">
<form @submit.prevent="registeraccount()">
<input type="text" name="name" v-model="name" placeholder="Name" />
<input type="text" name="email" v-model="email" placeholder="Email" />
<input type="text" name="domain" v-model="domain" placeholder="Domain" />
......@@ -20,20 +20,22 @@ export default {
name: 'register-account',
data() {
return {
name:'',
email:'',
domain:'',
permissions:1,
token:'',
verified:false
input :{
name:'',
email:'',
domain:'',
permissions:1,
token:'',
verified:false
}
}
},
mounted() {
// this.syncData();
},
methods: {
register() {
this.$store.dispatch('register')
registeraccount() {
this.$store.dispatch('registeraccount',this.input)
}
}
// var uniqueid = Math.random().toString(36).substring(2, 15)
......
......@@ -17,7 +17,6 @@ const LOGOUT = "LOGOUT";
export default new Vuex.Store({
state: {
allobjects: [],
registeraccount:[],
database: null,
isLoggedIn: !!localStorage.getItem("token"),
},
......@@ -26,21 +25,7 @@ export default new Vuex.Store({
DB_INIT(state, data) {
state.database = data.database;
},
REGISTER_ACCOUNT(state, data){
state.registeraccount = data.registeraccount;
//state.accounts.push(payload);
if (remote_accounts_db) {
accounts_db.sync(remote_accounts_db)
}
},
SHOW_KNOWLEDGE_OBJECTS (state, payload) {
var ids = [];
state.allobjects.forEach(item => {ids.push(item.id)})
if (!ids.includes(payload.id)){
state.allobjects.push(payload);
}
},
LOGIN (state) {
state.pending = true;
},
......@@ -50,41 +35,49 @@ export default new Vuex.Store({
},
LOGOUT (state) {
state.isLoggedIn = false;
}
},
actions: {
register({commit}) {
},
REGISTER_ACCOUNT(data){
var uniqueid = Math.random().toString(36).substring(2, 15)
+ Math.random().toString(36).substring(2, 15);
// before : is the couch name to the right is data from component
accounts_db.put({
_id:uniqueid,
name:this.name,
email:this.email,
domain:this.domain,
permissions:this.permissions,
token:this.token,
verified:this.verified
})
//this.syncData()
// syncData(){
// if (remote_accounts_db) {
// accounts_db.sync(remote_accounts_db)
// }
// },
+ Math.random().toString(36).substring(2, 15);
// state.data.push({
// before : is the couch name to the right is data from component
accounts_db.put
({
_id:uniqueid,
name:data.name,
email:data.email,
domain:data.domain,
permissions:data.permissions,
token:data.token,
verified:data.verified
})
// })
// syncData()
// syncData(){
// if (remote_accounts_db) {
// accounts_db.sync(remote_accounts_db)
// }
// }
},
// checkData(){
// // ???
// }
commit('REGISTER_ACCOUNT')
SHOW_KNOWLEDGE_OBJECTS (state, payload) {
var ids = [];
state.allobjects.forEach(item => {ids.push(item.id)})
if (!ids.includes(payload.id)){
state.allobjects.push(payload);
}
}
},
// https://www.nativescript.org/blog/data-management-with-sqlite-and-vuex-in-a-nativescript-vue-app
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 => {
//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 });
......@@ -95,6 +88,12 @@ export default new Vuex.Store({
// console.log("OPEN DB ERROR", error);
// });
// },
registeraccount({ commit }, data) {
commit('REGISTER_ACCOUNT')
},
showKnowledgeObjects({ commit }, payload) {
commit('SHOW_KNOWLEDGE_OBJECTS', payload)
},
......
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