Skip to content

Commit

Permalink
#48 Add delete action for calibration curve
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcellino-Palerme committed Jul 19, 2024
1 parent ee655d8 commit 40b6a40
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ SPDX-License-Identifier: MIT
<NuxtPage />
</Suspense>
</NuxtLayout>
<state-message />
<confirm-box />
</template>
41 changes: 41 additions & 0 deletions components/ConfirmBox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script setup lang="ts">
// token to save the state of the dialog box
const openConfirmBox = useState<boolean>("openConfirmBox", () => false);
// message to display in the dialog box
const msgConfirmBox = useState<string>("msgConfirmBox", () => "");
// token to save the answer of the dialog box
const answerConfirmBox = useState<boolean>("answerConfirmBox", () => false);
// function to internationalize the text
const {t} = useI18n();
</script>

<template>
<!-- Confirm Box -->
<v-dialog
id="confirm-box"
v-model="openConfirmBox"
max-width="40%"
>
<v-card>
<!-- title of confirm box -->
<v-card-title>{{ t('title.confirmBox') }}</v-card-title>
<!-- message of confirm box -->
<v-card-text>{{ msgConfirmBox }}</v-card-text>
<v-card-actions>
<!-- buttons of confirm box -->
<!-- NO or cancel -->
<v-btn
:text="t('button.cancel')"
@click="openConfirmBox = false; answerConfirmBox = false"
/>
<!-- YES or ok -->
<v-btn
:text="t('button.yes')"
@click="openConfirmBox = false; answerConfirmBox = true"
/>
</v-card-actions>
</v-card>
</v-dialog>
</template>
38 changes: 38 additions & 0 deletions components/ManageCalibCurve.async.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SPDX-License-Identifier: MIT
<!-- This module manage calibration curves add / view / delete / archive / modify -->
<script setup lang="ts">
import * as v from 'valibot';
import { useConfirmBox } from '~/composables/useConfirmBox';
import { useMessage } from '~/composables/useMessage';


Expand Down Expand Up @@ -245,6 +246,42 @@ function updateCalibCurve(){
});
}


function deleteCalibCurveAction(item: {id: string, name: string}){
// ask user to confirm the delete of calibration curve
useConfirmBox(t("message.confirm.deleteCalibCurve"))
.then((answer) => {
// if user confirm the delete of calibration curve
if (answer) {
// delete calibration curve
deleteCalibCurve(item);
}
});
}

/**
* Delete calibration curve
*/
function deleteCalibCurve(item: {id: string, name: string}){
// send calibration curve id to delete
$fetch('/api/manageControl/delete',{
method: 'POST',
body: {
nameTable: "calib_curves",
id: item.id,
},
})
.then(() => {
// We update the daughter table
rUpload.value = !rUpload.value;
// show message whose say the delete of calibration curve is a success
success(t("message.success.deleteCalibCurve"));
})
.catch(() => {
// show message whose say the delete of calibration curve is a failure
error(t("message.error.deleteCalibCurve"));
});
}
</script>

<template>
Expand All @@ -254,6 +291,7 @@ function updateCalibCurve(){
:add="add"
:view="view"
:modify="modify"
:delete="deleteCalibCurveAction"
:update="rUpload"
/>
<!-- Dialog Box to add / view and modify calibration curve -->
Expand Down
31 changes: 31 additions & 0 deletions composables/useConfirmBox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* SPDX-FileCopyrightText: 2024 Marcellino Palerme <[email protected]>
* SPDX-License-Identifier: MIT
*
* Manage the display and answer of a confirm box
*/

import { waitElemtDom } from "./waitElemtDom";

/**
* Display a confirm box with a message and wait user answer
* @param message : string : message to display in confirm box
* @returns Promise<boolean> : true if user click on "yes" button,
* false if user click on "no/cancel" button
*/

export function useConfirmBox(message: string): Promise<boolean> {
// Token to dysplay confirm box
const openConfirmBox = useState<boolean>("openConfirmBox",);
// Token to store message to display in confirm box
const msgConfirmBox = useState<string>("msgConfirmBox");

// Add message to confirm box
msgConfirmBox.value=message;
// Open confirm box
openConfirmBox.value=true;

return waitElemtDom("#confirm-box",true) // wait confirm box open
.then(()=>waitElemtDom("#confirm-box",false)) // wait confirm box close
.then(()=>useState<boolean>("answerConfirmBox").value); // return answer
}
43 changes: 43 additions & 0 deletions composables/waitElemtDom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* SPDX-FileCopyrightText: 2024 Marcellino Palerme <[email protected]>
* SPDX-License-Identifier: MIT
*
* Wait changing of element in DOM
*/

/**
* Wait changing of element in DOM
* @param selector string : css selector of element to follow
* @param adding true: wait adding element in Dow; false: wait removing in Dom
* @returns Promise<HTMLElement> : resolve when element is added or
* removed in DOM
*/
// thx https://stackoverflow.com/a/61511955
export function waitElemtDom(selector:string, adding:boolean = true) {
return new Promise(resolve => {
// element already in DOM
if (document.querySelector(selector) && adding) {
return resolve(0);
}

const observer = new MutationObserver(() => {
// Check if the element now exists in the DOM
if(adding){
if (document.querySelector(selector)) {
observer.disconnect();
resolve(0);
}
// Check if the element no longer exists in the DOM
} else if (document.querySelector(selector) == null) {
observer.disconnect();
resolve(0);
}
});

// Start observing the DOM for the element
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
17 changes: 12 additions & 5 deletions lang/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default {
addmachine: "Add machine",
addview_calibCurve: "Add calibration curve",
archive: "Archive",
cancel: "Cancel",
control: "Manage control samples",
create: "Create",
delete: "Delete",
Expand All @@ -21,8 +22,8 @@ export default {
help: "Help",
home: "Home",
lang: "Change langage",
modify: "Modify",
logout: "Logout",
modify: "Modify",
no: "No",
submit: "Submit",
topProfOut: "Profile under menu and logout",
Expand Down Expand Up @@ -75,7 +76,7 @@ export default {
files: "Files",
logout: "Logout",
m_type: "type",
nameCalibCurve: "Serie's name",
nameCalibCurve: "Calibration curve's name",
nbFile: "File's number",
noFile: "No file",
noProject: "No projet",
Expand All @@ -95,20 +96,25 @@ export default {
addIssue: "There is a bug",
badProjectName: "Project's name have to contain 3 character (without count space)",
confDelProject: "You can't back to delete a project!",
confirm:{
deleteCalibCurve: "Are you sure to delete the calibration curve?",
},
confLoseModif: "You'll lose all modifications.",
confQuestion: "Are you sure to continue?",
created: "created",
createdFail: "Project's creation failed",
error:{
createCalibCurve: "Failed to create calibration curve"
createCalibCurve: "Failed to create calibration curve",
deleteCalibCurve: "Failed to delete calibration curve",
},
fitting: "The fitting ",
koDelProject: "We didn't delete, the named project",
loading: "Loading",
noEmpty: "Can't be empty",
okDelProject: "We deleted, the named project",
success:{
createCalibCurve: "La gamme a été créée"
createCalibCurve: "The calibration curve has been created",
deleteCalibCurve: "The calibration curve has been deleted"
},
updateFail: "Update fail",
updateInProgress: "Update of project in progress",
Expand All @@ -117,7 +123,7 @@ export default {
},
page:{
'index': 'Project',
'calibCurve': 'Serie',
'calibCurve': 'Calibration curve',
},
tab:{
base: "Bases",
Expand All @@ -131,6 +137,7 @@ export default {
},
title:{
compoundName:"Reference name",
confirmBox: "Confirmation",
daughter:"Daughter solution",
machine:"Machine",
mother:"Mother solution",
Expand Down
13 changes: 10 additions & 3 deletions lang/fr-FR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default {
addmachine: "Ajout d'une machine",
addview_calibCurve: "Ajouter une gamme",
archive: "Archiver",
cancel: "Annuler",
control: "Gestion témoins",
create: "Créer",
delete: "Supprimer",
Expand All @@ -21,8 +22,8 @@ export default {
help: "Aide",
home: "Accueil",
lang: "Changer de langue",
modify: "Modifier",
logout: "Déconnexion",
modify: "Modifier",
no: "Non",
submit: "Valider",
topProfOut: "Accéder au sous-menu profile et déconnection",
Expand Down Expand Up @@ -93,12 +94,16 @@ export default {
addIssue: "Un problème dit le",
badProjectName: "Le nom de project doit contenir au moins 3 caractère (hors les espaces)",
confDelProject: "La suppresion d'un projet est irréversible!",
confirm:{
deleteCalibCurve: "Voulez-vous vraiment supprimer cette gamme ?",
},
confLoseModif: "Attention tous les modifications seront perdues.",
confQuestion: "Êtes-vous sûr de vouloir continuer ?",
created: "a été créé",
createdFail: "La création du projet a échoué",
error:{
createCalibCurve: "Echech de la création de la gamme"
createCalibCurve: "Echech de la création de la gamme",
deleteCalibCurve: "Echec de la suppression de la gamme",
},
fitting: "L'ajustement ",
koDelProject: "Nous n'avons pas supprimé le projet",
Expand All @@ -107,7 +112,8 @@ export default {
okDelProject: "Nous avons supprimé le projet",
required: "Champ obligatoire",
success:{
createCalibCurve: "La gamme a été créée"
createCalibCurve: "La gamme a été créée",
deleteCalibCurve: "La gamme a été supprimée"
},
updateFail: "Échec de la mise à jour",
updateInProgress: "Le project est en cours de mise à jour",
Expand All @@ -131,6 +137,7 @@ export default {
title: {
addCalibCurve: "Ajout d'une gamme",
compoundName:"Nom du témoin",
confirmBox: "Confirmation",
daughter:"Solution fille",
machine:"Machine",
mother:"Solution mère",
Expand Down
1 change: 0 additions & 1 deletion pages/calibCurve.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ const ListComp : {[key:string]: string | ConcreteComponent} = {
</v-window>
</v-col>
</v-row>
<state-message />
</NuxtLayout>
</template>

0 comments on commit 40b6a40

Please sign in to comment.