K356/k356/items/templates/components/ItemDetail/vue.js

112 lines
3.5 KiB
JavaScript

ItemDetail = {
template: "#ItemDetail",
router_path: "/ItemDetail/:id",
delimiters: ["[[", "]]"],
computed: {
object: function() {
return this.$store.state.items.items.find(i => i.id == this.$route.params.id)
},
linked_properties: function() {
return this.$store.state.linkedProperties.items.filter(lp => lp.item == this.$route.params.id)
},
linked_properties_headers: function() {
return this.$store.state.linkedProperties.headers
},
properties: function() {
return this.$store.state.properties.items.filter(p => this.linked_properties.map(e => e.property).includes(p.id))
},
properties_headers: function() {
return this.$store.state.properties.headers
},
children: function() {
return this.$store.state.relations.items.filter(p => p.parent == this.$route.params.id)
},
parents: function() {
return this.$store.state.relations.items.filter(p => p.child == this.$route.params.id)
},
children_headers: function() {
return this.$store.state.relations.headers
},
headers: function() {
return this.$store.state.items.headers
},
all_items: function() {
return this.$store.state.items.items
},
all_properties: function() {
return this.$store.state.properties.items
},
},
methods: {
linkedPropertyEdition (method, item) {
return this.object_edit("items:linked.property.edit", "items:linked.property.create", 'linkedProperties', method, item)
},
relationPropertiesEdition (method, item) {
return this.object_edit("items:relation.property.edit", "items:relation.property.create", 'relationProperties', method, item)
},
relationEdition (method, item) {
return this.object_edit("items:relation.edit", "items:relation.create", 'relations', method, item)
},
async deleteLinkedProperty (item) {
await this.linkedPropertyEdition("delete", item)
this.$store.commit("linkedProperties/removeItem", item.id)
},
async createLinkedProperty (item) {
item.item = this.$route.params.id
const new_item = await this.linkedPropertyEdition("post", item)
this.$store.commit("linkedProperties/addItem", new_item)
},
async editLinkedProperty (item) {
item.item = this.$route.params.id
const new_item = await this.linkedPropertyEdition("post", item)
this.$store.commit("linkedProperties/editItem", new_item)
},
async deleteProperty (item) {
console.log(item)
},
async createProperty (item) {
console.log(item)
},
async editProperty (item) {
console.log(item)
},
async deleteRelation (item) {
await this.relationEdition("delete", item)
this.$store.commit("relations/removeItem", item.id)
},
async createRelation (item) {
const new_item = await this.relationEdition("post", item)
this.$store.commit("relations/addItem", new_item)
},
async editRelation (item) {
const new_item = await this.relationEdition("post", item)
this.$store.commit("relations/editItem", new_item)
},
}
}