Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/copy laboratory #311

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions src/components/laboratories-edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
</v-card-text>
<v-card-actions>
<v-btn type="submit" form="laboratories-form">{{ $t('save') }}</v-btn>
<v-btn v-if="laboratoryId" @click="createCopy">{{ $t('copy') }}</v-btn>
</v-card-actions>
</v-card>
</div>
Expand All @@ -294,7 +295,6 @@
import {
Laboratory,
LaboratoryExperimentalGovernance,
LaboratoryId,
LaboratorySector,
LaboratoryStakeholderCategory,
LaboratoryStakeholderType,
Expand Down Expand Up @@ -354,6 +354,10 @@ export default Vue.extend({
type: String,
required: false
},
basePath: {
type: String,
required: false
},
returnTo: {
type: String,
required: true
Expand Down Expand Up @@ -381,19 +385,31 @@ export default Vue.extend({
computed: {
...(mapState as MapStateToComputed)('root', ['laboratories']),
laboratory(): Laboratory | null {
return (
(this.laboratoryId && this.laboratories[this.laboratoryId]) || null
);
const id = this.laboratoryId || (this.$route.query.id as string) || null;
plumdumpling marked this conversation as resolved.
Show resolved Hide resolved
const lab = (id && this.laboratories[id]) || null;

if (lab && this.$route.query.id) {
// Remove location information of copied laboratory
lab.location = '';
}

return lab;
}
},
watch: {
laboratoryId(newLaboratoryId: LaboratoryId) {
if (newLaboratoryId && !this.laboratories[newLaboratoryId]) {
laboratory(newLaboratory) {
if (newLaboratory) {
// Fill form with laboratory data
this.updateLaboratoryData(newLaboratory);
} else if (this.laboratoryId) {
// Return to laboratories list if there's no laboratory with the given id found
this.$router.push(this.returnTo);
} else {
this.updateLaboratoryData(this.laboratories[newLaboratoryId]);
}
},
$route() {
// Reset drawing source on route change
this.source.clear();
},
addCustomSector(newAddCustomSector: boolean) {
if (!newAddCustomSector) {
this.customSector = '';
Expand Down Expand Up @@ -567,6 +583,12 @@ export default Vue.extend({
if (category !== 'other') {
this.customStakeholderCategory[index] = '';
}
},
createCopy() {
this.$router.push({
path: `${this.basePath}/new`,
query: {id: this.laboratoryId}
});
}
},
created() {
Expand All @@ -582,11 +604,6 @@ export default Vue.extend({
this.source.on('clear', () => {
this.hasFeature = false;
});

// Set laboratory data for the current route
if (this.laboratory) {
this.updateLaboratoryData(this.laboratory);
}
},
destroyed() {
// Reset drawing source
Expand Down
3 changes: 3 additions & 0 deletions src/components/map-component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ export default Vue.extend({
highlightedFeatureIds() {
this.handleAdminAreaSelectionAndHighlighting();
},
$route() {
this.updateLaboratoriesFeatures();
},
laboratories() {
this.updateLaboratoriesFeatures();
},
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"cancel": "Cancel",
"save": "Save",
"create": "Create",
"copy": "Create a Copy",
"saving": "Saving...",
"loading": "Loading...",
"notAvailable": "n/a",
Expand Down
1 change: 1 addition & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const routes = [
props: (route: Route) => ({
laboratoryType: route.params.laboratoryType,
laboratoryId: route.params.laboratoryId,
basePath: `/urban-testbeds/${route.params.laboratoryType}`,
returnTo: `/urban-testbeds/${route.params.laboratoryType}/list`
})
}
Expand Down