This commit is contained in:
2020-06-30 13:59:50 +00:00
parent 1325e45a15
commit f8e649c313

View File

@@ -1,14 +1,25 @@
<template> <template>
<gz-data-table <div>
formKey="adm-attachments" <gz-data-table
:dataListKey="dataListKey" v-if="!jobActive"
:dataListFilter="dataListFilter" formKey="adm-attachments"
:dataListSort="dataListSort" :dataListKey="dataListKey"
:showSelect="false" :dataListFilter="dataListFilter"
:singleSelect="false" :dataListSort="dataListSort"
v-on:update:selected="handleSelected" :showSelect="false"
> :singleSelect="false"
</gz-data-table> :reload="reload"
v-on:update:selected="handleSelected"
>
</gz-data-table>
<template v-if="jobActive">
<v-progress-circular
indeterminate
color="primary"
:size="60"
></v-progress-circular>
</template>
</div>
</template> </template>
<script> <script>
@@ -25,6 +36,8 @@ export default {
}, },
data() { data() {
return { return {
jobActive: false,
reload: false,
currentListViewId: 1, currentListViewId: 1,
dataListKey: "AttachmentDataList", dataListKey: "AttachmentDataList",
dataListFilter: "", dataListFilter: "",
@@ -35,6 +48,69 @@ export default {
methods: { methods: {
handleSelected(selectedItems) { handleSelected(selectedItems) {
console.log(selectedItems); console.log(selectedItems);
},
async startMaintenanceJob() {
let vm = this;
try {
//warning about job exclusivity
let dialogResult = await window.$gz.dialog.confirmGeneric(
"JobExclusiveWarning",
"warning"
);
if (dialogResult == false) {
return;
}
//call seed route
let jobId = await window.$gz.api.upsert("attachment/maintenance");
if (jobId.error) {
throw jobId.error;
}
jobId = jobId.jobId; //it's in a sub key
vm.jobActive = true;
/* /// <summary>
/// Job status for opsjobs
/// </summary>
public enum JobStatus : int
{
Absent=0,
Sleeping = 1,
Running = 2,
Completed = 3,
Failed = 4
} */
let jobStatus = 1;
//get status
while (vm.jobActive == true) {
await window.$gz.util.sleepAsync(1000);
//check if done
jobStatus = await window.$gz.api.get(
`job-operations/status/${jobId}`
);
if (jobStatus.error) {
throw jobStatus.error;
}
jobStatus = jobStatus.data;
if (jobStatus == 4 || jobStatus == 0) {
throw "Seeding job failed";
}
if (jobStatus == 3) {
vm.jobActive = false;
}
}
//Here if it's completed successfully
window.$gz.eventBus.$emit("notify-success", vm.$ay.t("JobCompleted"));
this.reload = !this.reload;
} catch (error) {
vm.jobActive = false;
window.$gz.errorHandler.handleFormError(error, vm);
window.$gz.eventBus.$emit("notify-error", vm.$ay.t("JobFailed"));
}
} }
} }
}; };
@@ -49,12 +125,9 @@ function clickHandler(menuItem) {
let m = window.$gz.menu.parseMenuItem(menuItem); let m = window.$gz.menu.parseMenuItem(menuItem);
if (m.owner == FORM_KEY && !m.disabled) { if (m.owner == FORM_KEY && !m.disabled) {
switch (m.key) { switch (m.key) {
// case "new": case "START_MAINTENANCE_JOB":
// m.vm.$router.push({ m.vm.startMaintenanceJob();
// name: "widget-edit", break;
// params: { recordid: 0 }
// });
// break;
default: default:
window.$gz.eventBus.$emit( window.$gz.eventBus.$emit(
"notify-warning", "notify-warning",
@@ -92,6 +165,16 @@ function generateMenu(vm) {
vm: vm vm: vm
}); });
if (vm.rights.change) {
menuOptions.menuItems.push({
title: "StartAttachmentMaintenanceJob",
icon: "fa-robot",
surface: false,
key: FORM_KEY + ":START_MAINTENANCE_JOB",
vm: vm
});
}
window.$gz.eventBus.$emit("menu-change", menuOptions); window.$gz.eventBus.$emit("menu-change", menuOptions);
} }
@@ -101,7 +184,8 @@ function generateMenu(vm) {
// //
async function fetchTranslatedText(vm) { async function fetchTranslatedText(vm) {
await window.$gz.translation.cacheTranslations([ await window.$gz.translation.cacheTranslations([
"StartAttachmentMaintenanceJob" "StartAttachmentMaintenanceJob",
"JobExclusiveWarning"
]); ]);
} }
</script> </script>