mixit/main.js

70 lines
2.0 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,
2019-04-16 16:06:10 +00:00
options: {}, position: {}
2019-04-14 14:52:12 +00:00
})
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-16 16:06:10 +00:00
...this.services[id],
2019-04-14 14:52:12 +00:00
options: options
})
2019-04-15 16:01:30 +00:00
this.saveServices()
2019-04-14 14:52:12 +00:00
},
2019-04-17 08:22:45 +00:00
moveService(id, move) {
const service = { ...this.services[id] }
service.position[move.type] = Math.max(1, (service.position[move.type] || 1) + move.direction)
this.$set(this.services, id, service)
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-16 16:06:10 +00:00
},
gridPos(id, position = {}) {
return {
"grid-row": `${position.x || 1} / span ${position.h || 2}`,
"grid-column": `${position.y || id*2+1} / span ${position.w || 2}`
}
2019-04-14 14:52:12 +00:00
}
}
})