Skip to content

Commit

Permalink
PATCH: fix(form): disable annotation button if no viewpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Jun 23, 2022
1 parent c1dde59 commit 0a3e118
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/components/bcf-topic-form/BcfTopicForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
<BIMDataIcon name="plus" size="xxxs" margin="0 6px 0 0" />
{{ $t("BcfComponents.BcfTopicForm.addObjectButton") }}
</BIMDataButton>
<BIMDataButton color="primary" fill radius @click="$emit('add-annotation', bcfTopic)">
<BIMDataButton
color="primary"
fill
radius
:disabled="viewpoints.length === 0 && viewpointsToCreate.length === 0"
@click="$emit('add-annotation', bcfTopic)"
>
<BIMDataIcon name="plus" size="xxxs" margin="0 6px 0 0" />
{{ $t("BcfComponents.BcfTopicForm.addAnnotationButton") }}
</BIMDataButton>
Expand Down Expand Up @@ -243,8 +249,9 @@ export default {
const topicLabels = ref([]);
const viewpoints = ref([]);
const viewpointsToCreate = [];
const viewpointsToDelete = [];
const viewpointsToCreate = ref([]);
const viewpointsToUpdate = ref([]);
const viewpointsToDelete = ref([]);
const loading = ref(false);
const isOpenModal = ref(false);
Expand Down Expand Up @@ -288,15 +295,15 @@ export default {
};
const addViewpoint = viewpoint => {
viewpointsToCreate.push(viewpoint);
viewpointsToCreate.value.push(viewpoint);
};
const delViewpoint = viewpoint => {
if (viewpoint.guid) {
viewpointsToDelete.push(viewpoint);
viewpointsToDelete.value.push(viewpoint);
} else {
let index = viewpointsToCreate.indexOf(viewpoint);
viewpointsToCreate.splice(index, 1);
let index = viewpointsToCreate.value.indexOf(viewpoint);
viewpointsToCreate.value.splice(index, 1);
}
};
Expand All @@ -314,23 +321,23 @@ export default {
// Avoid updating snapshots as it is not possible.
// (you can only create/delete snapshots)
const viewpointToUpdate = viewpoints.value.map(
viewpointsToUpdate.value = viewpoints.value.map(
viewpoint => ({ ...viewpoint, snapshot: undefined })
);
if (props.providedComponents) {
viewpointToUpdate.forEach(
viewpointsToUpdate.value.forEach(
viewpoint => viewpoint.components = props.providedComponents
);
viewpointsToCreate.forEach(
viewpointsToCreate.value.forEach(
viewpoint => viewpoint.components = props.providedComponents
);
}
if (props.providedPins) {
viewpointToUpdate.forEach(
viewpointsToUpdate.value.forEach(
viewpoint => viewpoint.pins = props.providedPins
);
viewpointsToCreate.forEach(
viewpointsToCreate.value.forEach(
viewpoint => viewpoint.pins = props.providedPins
);
}
Expand All @@ -347,7 +354,7 @@ export default {
dueDate: topicDate.value ? serialize(topicDate.value) : undefined,
description: topicDescription.value,
labels: topicLabels.value,
viewpoints: viewpointToUpdate,
viewpoints: viewpointsToUpdate.value,
};
let newTopic;
Expand All @@ -358,12 +365,12 @@ export default {
}
await Promise.all(
viewpointsToCreate.map(viewpoint =>
viewpointsToCreate.value.map(viewpoint =>
createViewpoint(props.project, newTopic, viewpoint)
)
);
await Promise.all(
viewpointsToDelete.map(viewpoint =>
viewpointsToDelete.value.map(viewpoint =>
deleteViewpoint(props.project, newTopic, viewpoint)
)
);
Expand Down Expand Up @@ -397,6 +404,7 @@ export default {
topicTitle,
topicType,
viewpoints,
viewpointsToCreate,
// Methods
addViewpoint,
delViewpoint,
Expand Down

0 comments on commit 0a3e118

Please sign in to comment.