This commit is contained in:
2020-12-09 15:01:24 +00:00
parent b6510d03d6
commit 56aa8a8993
2 changed files with 156 additions and 1 deletions

View File

@@ -0,0 +1,152 @@
<template>
<v-expansion-panel v-if="available == true">
<v-expansion-panel-header disable-icon-rotate expand-icon="$ayiTrashAlt">{{
$ay.t("Delete")
}}</v-expansion-panel-header>
<v-expansion-panel-content>
<v-btn icon @click="goHelp()"><v-icon>$ayiQuestionCircle</v-icon></v-btn>
<v-btn
:disabled="!canDoAction()"
color="blue darken-1"
text
@click="doAction()"
:loading="jobActive"
>{{ $ay.t("StartJob") }}</v-btn
>
</v-expansion-panel-content>
</v-expansion-panel>
</template>
<script>
export default {
created() {
let vm = this;
//NOTE: if extension doesn't support a particular object add it here to the NoType default
if (vm.dataListSelection.ObjectType != 0) {
vm.rights = window.$gz.role.getRights(vm.dataListSelection.ObjectType);
}
vm.available = vm.rights.change;
},
data: () => ({
jobActive: false,
rights: window.$gz.role.defaultRightsObject(),
available: false
}),
methods: {
goHelp() {
window.open(this.$store.state.helpUrl + "ay-ex-delete", "_blank");
},
canDoAction() {
let vm = this;
if (vm.action == "Replace" && !vm.replace) {
return false;
}
if (vm.tag) {
return true;
}
return false;
},
async doAction() {
//do the bulk action
let vm = this;
let url = "tag-list/";
let body = this.dataListSelection;
switch (vm.action) {
case "Add":
url += `bulk-add/${vm.tag}`;
break;
case "Remove":
url += `bulk-remove/${vm.tag}`;
break;
case "Replace":
url += `bulk-replace/${vm.tag}?toTag=${vm.replace}`;
break;
}
try {
//call api route
let jobId = await window.$gz.api.upsert(url, body);
if (jobId.error) {
//throw new Error(jobId.error);
throw new Error(window.$gz.errorHandler.errorToString(jobId, vm));
}
jobId = jobId.jobId; //it's in a sub key
//indicate loading by setting on button
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 new Error(jobStatus.error);
throw new Error(
window.$gz.errorHandler.errorToString(jobStatus, vm)
);
}
jobStatus = jobStatus.data;
if (jobStatus == 4 || jobStatus == 0) {
throw new Error("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"));
} catch (error) {
vm.jobActive = false;
window.$gz.errorHandler.handleFormError(error, vm);
window.$gz.eventBus.$emit("notify-error", vm.$ay.t("JobFailed"));
}
},
normalize(value) {
if (!value) {
return null;
}
//Must be lowercase per rules
//This may be naive when we get international cust omers but for now supporting utf-8 and it appears it's safe to do this with unicode
value = value.toLowerCase();
//No spaces in tags, replace with dashes
value = value.split(" ").join("-");
//Remove multiple dash sequences
value = value.replace(/-+/g, "-");
//Ensure doesn't start or end with a dash
value = value.replace(/^\-+-\-+$/g, "");
// inObj = inObj.Trim("-");
//No longer than 255 characters
// inObj = StringUtil.MaxLength(inObj, 255);
return value;
},
normalizeTag(value) {
value = this.normalize(value);
this.tag = value;
},
normalizeReplace(value) {
value = this.normalize(value);
this.replace = value;
}
},
props: {
dataListSelection: Object
}
};
</script>

View File

@@ -7,6 +7,7 @@
<v-expansion-panels focusable>
<ExtensionTags :dataListSelection="dataListSelection" />
<ExtensionExport :dataListSelection="dataListSelection" />
<ExtensionDelete :dataListSelection="dataListSelection" />
</v-expansion-panels>
</v-card-text>
<v-card-actions>
@@ -20,10 +21,12 @@
<script>
import ExtensionTags from "./extension-tags-control.vue";
import ExtensionExport from "./extension-export-control.vue";
import ExtensionDelete from "./extension-delete-control.vue";
export default {
components: {
ExtensionTags,
ExtensionExport
ExtensionExport,
ExtensionDelete
},
data: () => ({
isVisible: false,