stash
This commit is contained in:
parent
4c9e8f942e
commit
23185e1721
13 changed files with 365 additions and 107 deletions
|
|
@ -55,6 +55,7 @@
|
|||
import * as BIcons from "bootstrap-icons-vue";
|
||||
import {mapActions, mapState} from "vuex";
|
||||
import BaseLayout from "@/components/BaseLayout.vue";
|
||||
import {decodeHandleFromUrl, ownerOverviewRoute} from "@/router";
|
||||
|
||||
export default {
|
||||
name: "StorageLocationEdit",
|
||||
|
|
@ -63,32 +64,56 @@ export default {
|
|||
...BIcons
|
||||
},
|
||||
props: {
|
||||
handle: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
id: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState(["storage_locations", "categories"]),
|
||||
location() {
|
||||
return {
|
||||
data() {
|
||||
return {
|
||||
location: {
|
||||
name: "",
|
||||
description: "",
|
||||
category: null,
|
||||
parent: null,
|
||||
...this.storage_locations.find(loc => loc.id === parseInt(this.id))
|
||||
}
|
||||
},
|
||||
// The location's own owner's full location list, for the parent dropdown - own
|
||||
// personal locations, or the owning group's own (see loadLocation).
|
||||
siblingLocations: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState(["categories"]),
|
||||
decodedHandle() {
|
||||
return decodeHandleFromUrl(this.handle)
|
||||
},
|
||||
availableParents() {
|
||||
// Filter out self and children to prevent circular references
|
||||
return this.storage_locations.filter(loc =>
|
||||
return this.siblingLocations.filter(loc =>
|
||||
loc.id !== parseInt(this.id) &&
|
||||
!this.isChildOf(loc, parseInt(this.id))
|
||||
)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions(["fetchStorageLocations", "updateStorageLocation", "fetchInfo"]),
|
||||
ownerOverviewRoute,
|
||||
...mapActions(["fetchStorageLocationByHandle", "updateStorageLocation", "fetchInfo",
|
||||
"fetchStorageLocations", "fetchGroupStorageLocations"]),
|
||||
async loadLocation() {
|
||||
const loaded = await this.fetchStorageLocationByHandle({handle: this.decodedHandle, id: this.id})
|
||||
if (loaded) {
|
||||
this.location = {...this.location, ...loaded}
|
||||
}
|
||||
if (this.decodedHandle.startsWith('#')) {
|
||||
this.siblingLocations = await this.fetchGroupStorageLocations({groupHandle: this.decodedHandle})
|
||||
} else {
|
||||
this.siblingLocations = await this.fetchStorageLocations()
|
||||
}
|
||||
},
|
||||
submitForm() {
|
||||
// Convert empty strings to null for ForeignKey fields
|
||||
const locationData = {
|
||||
|
|
@ -96,21 +121,25 @@ export default {
|
|||
category: this.location.category === "" ? null : this.location.category,
|
||||
parent: this.location.parent === "" ? null : this.location.parent
|
||||
};
|
||||
this.updateStorageLocation(locationData);
|
||||
this.updateStorageLocation(locationData).then(updated => this.$router.push(ownerOverviewRoute(updated)));
|
||||
},
|
||||
isChildOf(location, parentId) {
|
||||
// Simple check to prevent circular references
|
||||
let current = location;
|
||||
while (current && current.parent) {
|
||||
if (current.parent === parentId) return true;
|
||||
current = this.storage_locations.find(loc => loc.id === current.parent);
|
||||
current = this.siblingLocations.find(loc => loc.id === current.parent);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
handle: 'loadLocation',
|
||||
id: 'loadLocation'
|
||||
},
|
||||
async mounted() {
|
||||
await this.fetchInfo();
|
||||
await this.fetchStorageLocations();
|
||||
await this.loadLocation();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue