mixit/main.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-04-16 12:04:25 +00:00
//TODO: discord
2019-04-14 14:52:12 +00:00
const servicesStorage = 'services'
var app = new Vue({
el: '#app',
data: {
showManager: false,
newService: '',
services: [],
errors: []
},
mounted() {
2019-04-15 11:13:20 +00:00
if (localStorage.getItem(servicesStorage)) {
2019-04-14 14:52:12 +00:00
try {
2019-04-15 11:13:20 +00:00
this.services = JSON.parse(localStorage.getItem(servicesStorage))
2019-04-14 14:52:12 +00:00
} catch (e) {
2019-04-15 11:13:20 +00:00
localStorage.removeItem(servicesStorage)
2019-04-14 14:52:12 +00:00
}
}
},
methods: {
addError(err) {
this.errors.push(err)
},
removeError(id) {
this.errors.splice(id, 1)
},
addService() {
// ensure they actually typed something
if (!this.newService) {
return;
}
this.services.push({
type: this.newService,
options: {}
})
this.newService = ''
this.showManager = false
this.saveServices()
},
setService(id, options) {
2019-04-15 16:01:30 +00:00
this.$set(this.services, id, {
2019-04-14 14:52:12 +00:00
type: this.services[id].type,
options: options
})
2019-04-15 16:01:30 +00:00
this.saveServices()
2019-04-14 14:52:12 +00:00
},
removeService(id) {
this.services.splice(id, 1)
this.saveServices()
},
saveServices() {
2019-04-15 11:13:20 +00:00
localStorage.setItem(servicesStorage, JSON.stringify(this.services))
2019-04-15 16:01:30 +00:00
this.$forceUpdate()
2019-04-14 14:52:12 +00:00
}
}
})