Add more components + base for history
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
:items="items"
|
||||
:items_headers="items_headers"
|
||||
:items_relations="{'type': types}"
|
||||
:hidden_fields="[]"
|
||||
group_by="type__name"
|
||||
@deleteItem="deleteItem"
|
||||
@createItem="createItem"
|
||||
@@ -26,8 +25,6 @@
|
||||
<ItemList
|
||||
:items="types"
|
||||
:items_headers="types_headers"
|
||||
:items_relations="{}"
|
||||
:hidden_fields="[]"
|
||||
group_by="[]"
|
||||
@deleteItem="deleteType"
|
||||
@createItem="createType"
|
||||
|
||||
@@ -4,213 +4,53 @@ ItemView = {
|
||||
delimiters: ["[[", "]]"],
|
||||
props: [],
|
||||
|
||||
data: function() {
|
||||
return {
|
||||
items: [],
|
||||
items_headers: [],
|
||||
types: [],
|
||||
types_headers: [],
|
||||
}
|
||||
},
|
||||
|
||||
mounted: function() {
|
||||
this.reload()
|
||||
},
|
||||
|
||||
computed: {
|
||||
items_efields: function() {
|
||||
return this.items_headers.filter(e => e.encrypted).map(e => e.value)
|
||||
},
|
||||
|
||||
types_efields: function() {
|
||||
return this.types_headers.filter(e => e.encrypted).map(e => e.value)
|
||||
},
|
||||
...Vuex.mapState({
|
||||
items: state => state.items.items,
|
||||
items_headers: state => state.items.headers,
|
||||
types: state => state.types.items,
|
||||
types_headers: state => state.types.headers,
|
||||
}),
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
async reload () {
|
||||
|
||||
try {
|
||||
const response = await this.$http.get(Urls["items:list"]())
|
||||
|
||||
this.items_headers = response.data.result.items_headers
|
||||
this.types_headers = response.data.result.types_headers
|
||||
|
||||
// Decrypt all item the push
|
||||
response.data.result.items.forEach(async item => {
|
||||
const new_item = await this.decryptObject(this.items_efields, item)
|
||||
|
||||
this.items.push(new_item)
|
||||
})
|
||||
|
||||
// Decrypt all type the push
|
||||
response.data.result.types.forEach(async type => {
|
||||
const new_type = await this.decryptObject(this.types_efields, type)
|
||||
|
||||
this.types.push(new_type)
|
||||
})
|
||||
|
||||
} catch (err) {
|
||||
|
||||
Swal.fire({title: "{{_('Error during loading of items') | escapejs}}", icon: "error", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
async object_edit(url_edit, url_create, encrypted_fields, method, obj) {
|
||||
|
||||
let url = null
|
||||
|
||||
if (obj.id == undefined || obj.id == null) {
|
||||
url = Urls[url_create]()
|
||||
} else {
|
||||
url = Urls[url_edit](obj.id)
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
const newobj = await this.encryptObject(encrypted_fields, obj)
|
||||
const response = await this.$http[method](url, newobj)
|
||||
|
||||
if (method != "delete") {
|
||||
return await this.decryptObject(encrypted_fields, response.data.object)
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
let msg = "{{_('Error during edition') | escapejs}}"
|
||||
if (method == "delete") {
|
||||
msg = "{{_('Error during deletion') | escapejs}}"
|
||||
}
|
||||
|
||||
Swal.fire({title: msg, icon: "error", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
||||
|
||||
throw err
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
item_edition (method, item) {
|
||||
return this.object_edit("items:edit", "items:create", this.items_efields, method, item)
|
||||
return this.object_edit("items:edit", "items:create", 'items', method, item)
|
||||
},
|
||||
|
||||
type_edition (method, item) {
|
||||
return this.object_edit("items:type.edit", "items:type.create", this.types_efields, method, item)
|
||||
return this.object_edit("items:type.edit", "items:type.create", 'types', method, item)
|
||||
},
|
||||
|
||||
async createItem (item) {
|
||||
|
||||
try {
|
||||
|
||||
const new_item = await this.item_edition("post", item)
|
||||
this.items.push(new_item)
|
||||
|
||||
Swal.fire({title: "{{_('Item successfully created!') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
||||
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
|
||||
const new_item = await this.item_edition("post", item)
|
||||
this.$store.commit("items/addItem", new_item)
|
||||
},
|
||||
|
||||
async editItem (index, item) {
|
||||
|
||||
try {
|
||||
|
||||
// Remove the item
|
||||
this.items.splice(index, 1)
|
||||
|
||||
const new_item = await this.item_edition("post", item)
|
||||
|
||||
// Add the new item
|
||||
this.items.push(new_item)
|
||||
|
||||
Swal.fire({title: "{{_('Item successfully edited') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
||||
|
||||
} catch (err) {
|
||||
|
||||
this.items.push(item)
|
||||
|
||||
}
|
||||
|
||||
async editItem (item) {
|
||||
const new_item = await this.item_edition("post", item)
|
||||
this.$store.commit("items/editItem", new_item)
|
||||
},
|
||||
|
||||
async deleteItem (index) {
|
||||
|
||||
var item = this.items[index]
|
||||
|
||||
try {
|
||||
|
||||
// Remove the item
|
||||
this.items.splice(index, 1)
|
||||
await this.item_edition("delete", item)
|
||||
|
||||
Swal.fire({title: "{{_('Item successfully deleted!') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
||||
|
||||
} catch (err) {
|
||||
|
||||
this.items.push(item)
|
||||
|
||||
}
|
||||
|
||||
async deleteItem (item) {
|
||||
await this.item_edition("delete", item)
|
||||
this.$store.commit("items/removeItem", item.id)
|
||||
},
|
||||
|
||||
async createType (type) {
|
||||
|
||||
try {
|
||||
|
||||
const new_type = await this.type_edition("post", type)
|
||||
this.types.push(new_type)
|
||||
|
||||
Swal.fire({title: "{{_('Type successfully created!') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
||||
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
|
||||
const new_type = await this.type_edition("post", type)
|
||||
this.$store.commit("types/addItem", new_type)
|
||||
},
|
||||
|
||||
async editType (index, type) {
|
||||
|
||||
try {
|
||||
|
||||
this.types.splice(index, 1)
|
||||
|
||||
const new_type = await this.type_edition("post", type)
|
||||
|
||||
this.types.push(new_type)
|
||||
|
||||
Swal.fire({title: "{{_('Type successfully edited') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
||||
|
||||
} catch (err) {
|
||||
|
||||
this.types.push(type)
|
||||
|
||||
}
|
||||
|
||||
async editType (type) {
|
||||
const new_type = await this.type_edition("post", type)
|
||||
this.$store.commit("types/editItem", new_type)
|
||||
},
|
||||
|
||||
async deleteType (index) {
|
||||
|
||||
var type = this.types[index]
|
||||
|
||||
try {
|
||||
|
||||
// Remove the type
|
||||
this.types.splice(index, 1)
|
||||
|
||||
await this.type_edition("delete", type)
|
||||
|
||||
Swal.fire({title: "{{_('Type successfully deleted!') | escapejs}}", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000})
|
||||
|
||||
} catch (err) {
|
||||
|
||||
this.types.push(type)
|
||||
|
||||
}
|
||||
async deleteType (type) {
|
||||
await this.type_edition("delete", type)
|
||||
this.$store.commit("types/removeItem", type.id)
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user