Files
sockeye-client/src/components/extension-close-cases-control.vue
2026-11-02 13:52:58 -07:00

130 lines
3.9 KiB
Vue

<template>
<!-- case 4742: close or reopen the selected cases in one go (Sockeye only, so plain English, no translation keys) -->
<v-expansion-panel v-if="available == true">
<v-expansion-panel-header
disable-icon-rotate
expand-icon="$sockiCheckCircle"
>Close / reopen cases</v-expansion-panel-header
>
<v-expansion-panel-content>
<!-- case 4745: closing sets this status; reopening sets New. Duplicate is one case at a time, on the case form -->
<v-radio-group
v-model="closeAs"
row
dense
:disabled="jobActive"
data-cy="extCloseCasesAs"
>
<v-radio label="Close as Done" :value="STATUS_DONE"></v-radio>
<v-radio label="Close as Never" :value="STATUS_NEVER"></v-radio>
</v-radio-group>
<v-btn
color="blue darken-1"
text
:disabled="jobActive"
:loading="jobActive && !opening"
data-cy="extCloseCases"
@click="doAction(false)"
>Close</v-btn
>
<v-btn
color="blue darken-1"
text
:disabled="jobActive"
:loading="jobActive && opening"
data-cy="extOpenCases"
@click="doAction(true)"
>Reopen</v-btn
>
<v-btn
v-if="jobActive"
color="red darken-1"
text
@click="requestCancel()"
>
{{ $sock.t("Cancel") }}</v-btn
><span v-if="jobActive">{{ progress }}</span>
</v-expansion-panel-content>
</v-expansion-panel>
</template>
<script>
export default {
props: {
dataListSelection: { type: Object, default: null }
},
data: () => ({
//case 4745: GZCaseStatus values
STATUS_DONE: 5,
STATUS_NEVER: 6,
closeAs: 5,
jobActive: false,
opening: false,
currentJobId: null,
progress: ""
}),
computed: {
available() {
return (
this.dataListSelection != null &&
this.dataListSelection.SockType == window.$gz.type.GZCase &&
window.$gz.role.getRights(window.$gz.type.GZCase).change
);
}
},
methods: {
async requestCancel() {
await window.$gz.api.upsert(
"job-operations/request-cancel",
this.currentJobId
);
},
async doAction(open) {
const vm = this;
//Clear any possible prior errors
vm.$emit("ext-show-job-log", "clear");
vm.opening = open;
const url = `job-operations/batch-close-cases?open=${open}&status=${this.closeAs}`;
try {
this.progress = "";
let jobId = await window.$gz.api.upsert(url, this.dataListSelection);
if (jobId.error) {
throw new Error(window.$gz.errorHandler.errorToString(jobId, vm));
}
this.currentJobId = jobId.jobId;
vm.jobActive = true;
let jobProgress = {};
while (vm.jobActive == true) {
await window.$gz.util.sleepAsync(2000);
jobProgress = await window.$gz.api.get(
`job-operations/progress/${this.currentJobId}`
);
if (jobProgress.error) {
throw new Error(
window.$gz.errorHandler.errorToString(jobProgress, vm)
);
}
jobProgress = jobProgress.data;
this.progress = jobProgress.progress;
if (jobProgress.jobStatus == 4 || jobProgress.jobStatus == 0) {
if (jobProgress.jobStatus == 4) {
//emit job id and event to parent for log viewing
vm.$emit("ext-show-job-log", jobId);
}
throw new Error("Job failed");
}
if (jobProgress.jobStatus == 3) {
vm.jobActive = false;
}
}
//Here if it's completed successfully
window.$gz.eventBus.$emit("notify-success", vm.$sock.t("JobCompleted"));
vm.$emit("ext-close-refresh");
} catch (error) {
vm.jobActive = false;
window.$gz.eventBus.$emit("notify-error", vm.$sock.t("JobFailed"));
}
}
}
};
</script>