ADD: Profile management functionality & store
This commit is contained in:
44
src/main.js
44
src/main.js
@@ -1,26 +1,39 @@
|
||||
import './assets/main.css'
|
||||
import Axios from 'axios'
|
||||
|
||||
import { createApp } from 'vue'
|
||||
import { createStore } from 'vuex'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import en from './lang/en.json'
|
||||
import en from '@/lang/en.json'
|
||||
|
||||
import App from './App.vue'
|
||||
import App from '@/App.vue'
|
||||
|
||||
import { store } from '@/store.js'
|
||||
|
||||
import Ajv from 'ajv'
|
||||
import schema from '@/data/profileSchema.json'
|
||||
|
||||
// Create a new store instance
|
||||
const store = createStore({
|
||||
state() {
|
||||
return {
|
||||
device: {
|
||||
connected: false,
|
||||
profiles: [],
|
||||
},
|
||||
const ajv = new Ajv()
|
||||
|
||||
Axios.get('http://localhost:3001/profiles').then((res) => {
|
||||
const profiles = res.data
|
||||
console.log(profiles)
|
||||
const ids = new Set()
|
||||
const validate = ajv.compile(schema)
|
||||
store.device.profiles = profiles.filter((profile) => {
|
||||
if (!validate(profile)) {
|
||||
console.error('Failed to validate profile: ' + profile.name, validate.errors)
|
||||
return false
|
||||
}
|
||||
},
|
||||
mutations: {},
|
||||
if (ids.has(profile.id)) {
|
||||
console.error('Duplicate profile id: ' + profile.id + ' for profile: ' + profile.name)
|
||||
return false
|
||||
}
|
||||
ids.add(profile.id)
|
||||
return true
|
||||
})
|
||||
}).catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
|
||||
// Create VueI18n instance with locales loaded from /lang directory
|
||||
@@ -31,10 +44,5 @@ const i18n = createI18n({
|
||||
})
|
||||
|
||||
const app = createApp(App)
|
||||
|
||||
app.use(i18n)
|
||||
app.use(store)
|
||||
|
||||
app.provide('ajv', new Ajv())
|
||||
|
||||
app.mount('#app')
|
||||
Reference in New Issue
Block a user