stash
This commit is contained in:
parent
4c9e8f942e
commit
23185e1721
13 changed files with 365 additions and 107 deletions
|
|
@ -26,12 +26,21 @@
|
|||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="owner" class="form-label">Owner</label>
|
||||
<select class="form-select" id="owner" name="owner" v-model="location.owner_group">
|
||||
<option :value="null">Myself</option>
|
||||
<option v-for="group in ownerGroups" :value="group.handle" :key="group.handle">
|
||||
{{ group.handle }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="parent" class="form-label">Parent Location</label>
|
||||
<select class="form-select" id="parent" name="parent"
|
||||
v-model="location.parent">
|
||||
<option value="">No Parent</option>
|
||||
<option v-for="parent in storage_locations" :value="parent.id">
|
||||
<option v-for="parent in availableParents" :value="parent.id">
|
||||
{{ parent.path }}
|
||||
</option>
|
||||
</select>
|
||||
|
|
@ -53,6 +62,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: "StorageLocationNew",
|
||||
|
|
@ -66,12 +76,27 @@ export default {
|
|||
name: "",
|
||||
description: "",
|
||||
category: null,
|
||||
parent: null
|
||||
}
|
||||
parent: null,
|
||||
// The group's own "#name@domain" handle once picked, or null for a personal
|
||||
// location - createStorageLocation resolves the target domain from it directly.
|
||||
owner_group: null
|
||||
},
|
||||
// The selected owner's own location list, for the parent dropdown - own personal
|
||||
// locations, or the chosen group's own (see loadParentOptionsForOwner).
|
||||
groupLocations: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions(['createStorageLocation', 'fetchInfo', 'fetchStorageLocations']),
|
||||
ownerOverviewRoute,
|
||||
...mapActions(['createStorageLocation', 'fetchInfo', 'fetchStorageLocations', 'fetchGroups',
|
||||
'fetchGroupMemberships', 'fetchGroupStorageLocations']),
|
||||
async loadParentOptionsForOwner() {
|
||||
if (!this.location.owner_group) {
|
||||
this.groupLocations = []
|
||||
return
|
||||
}
|
||||
this.groupLocations = await this.fetchGroupStorageLocations({groupHandle: this.location.owner_group})
|
||||
},
|
||||
submitForm() {
|
||||
// Convert empty strings to null for ForeignKey fields
|
||||
const locationData = {
|
||||
|
|
@ -79,15 +104,37 @@ export default {
|
|||
category: this.location.category === "" ? null : this.location.category,
|
||||
parent: this.location.parent === "" ? null : this.location.parent
|
||||
};
|
||||
this.createStorageLocation(locationData).then(() => this.$router.push('/storage-location'));
|
||||
this.createStorageLocation(locationData).then(created => this.$router.push(ownerOverviewRoute(created)));
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState(["categories", "storage_locations"]),
|
||||
...mapState(["categories", "storage_locations", "groups", "groupMemberships"]),
|
||||
// Groups hosted here plus groups only known via a GroupMembership pointer (see
|
||||
// Groups.vue's allGroups for the same merge/dedupe).
|
||||
ownerGroups() {
|
||||
const hostedHandles = new Set(this.groups.map(group => group.handle))
|
||||
const foreign = this.groupMemberships.filter(m => !hostedHandles.has(m.handle))
|
||||
return [...this.groups, ...foreign].sort((a, b) => a.handle.localeCompare(b.handle))
|
||||
},
|
||||
availableParents() {
|
||||
return this.location.owner_group ? this.groupLocations : this.storage_locations
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'location.owner_group'() {
|
||||
// Previously-selected parent likely doesn't belong to the newly-chosen owner.
|
||||
this.location.parent = null
|
||||
this.loadParentOptionsForOwner()
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
await this.fetchInfo();
|
||||
await this.fetchStorageLocations();
|
||||
await this.fetchGroups();
|
||||
await this.fetchGroupMemberships();
|
||||
if (this.$route.query.group) {
|
||||
this.location.owner_group = decodeHandleFromUrl(this.$route.query.group)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue