Skip to content

Commit

Permalink
#48 add archive action
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcellino-Palerme committed Jul 19, 2024
1 parent 40b6a40 commit dbb3f01
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
46 changes: 45 additions & 1 deletion components/ManageCalibCurve.async.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ function updateCalibCurve(){
});
}


/**
* Confirm the delete of calibration curve
* @param item {id:String, name:String} calibration curves information
*/
function deleteCalibCurveAction(item: {id: string, name: string}){
// ask user to confirm the delete of calibration curve
useConfirmBox(t("message.confirm.deleteCalibCurve"))
Expand Down Expand Up @@ -282,6 +285,46 @@ function deleteCalibCurve(item: {id: string, name: string}){
error(t("message.error.deleteCalibCurve"));
});
}

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

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

</script>

<template>
Expand All @@ -292,6 +335,7 @@ function deleteCalibCurve(item: {id: string, name: string}){
:view="view"
:modify="modify"
:delete="deleteCalibCurveAction"
:archive="achiveCalibCurveAction"
:update="rUpload"
/>
<!-- Dialog Box to add / view and modify calibration curve -->
Expand Down
26 changes: 26 additions & 0 deletions components/TableDbAction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,31 @@ function launchAction(action:{name:string}, item:object) {
rfUpdate.value = !rfUpdate.value;
}
}
/**
* Disable actions
* Archive when item is archived
* Delete when item is archived or used
* Modify when item is archived or used
* @param action string name of action
* @param item {date_achieve?: any, used?: any} item information
*/
function disableAction(action:string,
item:{ date_achieve?: any, used?: any }):boolean{
// View action is always available
if(action == "view"){
return false;
}
// Check if item is archived
if(item.date_achieve){
return true;
}
// Check if item is used
if(item.used){
return true;
}
return false;

}
</script>

<template>
Expand Down Expand Up @@ -179,6 +204,7 @@ function launchAction(action:{name:string}, item:object) {
density="compact"
size="small"
variant="text"
:disabled="disableAction(action.name, item)"
@click="() => launchAction(action, item)"
/>
<!-- </div>
Expand Down
1 change: 1 addition & 0 deletions db/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ SELECT calib_curves.id AS id, calib_curves.name, array_agg(ratio.id_mol) AS meta
calib_curves.date_create, calib_curves.date_achieve
FROM calib_curves, ratio
WHERE calib_curves.id = ratio.id_calib_curves
AND calib_curves.date_achieve IS NULL
GROUP BY calib_curves.id;

CREATE VIEW view_show_calib_curve AS
Expand Down
3 changes: 3 additions & 0 deletions lang/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ export default {
badProjectName: "Project's name have to contain 3 character (without count space)",
confDelProject: "You can't back to delete a project!",
confirm:{
archiveCalibCurve: "Are you sure to archive the calibration curve?",
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:{
archiveCalibCurve: "Failed to archive calibration curve",
createCalibCurve: "Failed to create calibration curve",
deleteCalibCurve: "Failed to delete calibration curve",
},
Expand All @@ -113,6 +115,7 @@ export default {
noEmpty: "Can't be empty",
okDelProject: "We deleted, the named project",
success:{
archiveCalibCurve: "The calibration curve has been archived",
createCalibCurve: "The calibration curve has been created",
deleteCalibCurve: "The calibration curve has been deleted"
},
Expand Down
3 changes: 3 additions & 0 deletions lang/fr-FR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ export default {
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:{
archiveCalibCurve: "Voulez-vous vraiment archiver cette gamme ?",
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:{
archiveCalibCurve: "Echec de l'archivage de la gamme",
createCalibCurve: "Echech de la création de la gamme",
deleteCalibCurve: "Echec de la suppression de la gamme",
},
Expand All @@ -112,6 +114,7 @@ export default {
okDelProject: "Nous avons supprimé le projet",
required: "Champ obligatoire",
success:{
archiveCalibCurve: "La gamme a été archivée",
createCalibCurve: "La gamme a été créée",
deleteCalibCurve: "La gamme a été supprimée"
},
Expand Down
4 changes: 1 addition & 3 deletions server/api/class/tableClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ export default class Table {
query = query.slice(0,-1);

query += ` WHERE id = ${id} `;

console.log(query);


const client = new pg.Client();
await client.connect();
await client.query(query);
Expand Down

0 comments on commit dbb3f01

Please sign in to comment.