This commit is contained in:
2020-10-23 22:52:31 +00:00
parent 55ecf9f9e4
commit 5849e40c82

View File

@@ -6,48 +6,22 @@
>{{ $ay.t("Export") }}</v-expansion-panel-header
>
<v-expansion-panel-content>
<v-radio-group v-model="action">
<v-radio :label="$ay.t('Add')" value="Add"></v-radio>
<v-radio :label="$ay.t('Remove')" value="Remove"></v-radio>
<v-radio :label="$ay.t('Replace')" value="Replace"></v-radio>
<v-radio-group v-model="exportFormat">
<v-radio label="JSON" value="json"></v-radio>
<v-radio label="CSV" value="csv"></v-radio>
</v-radio-group>
<v-row>
<v-col cols="12">
<v-text-field
:value="tag"
:label="$ay.t('Tag')"
required
@input="normalizeTag"
></v-text-field>
</v-col>
<v-col cols="12" v-if="action == 'Replace'">
<v-text-field
:value="replace"
:label="$ay.t('Replace')"
@input="normalizeReplace"
required
></v-text-field>
</v-col>
</v-row>
<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-btn color="blue darken-1" text @click="doAction()">{{
$ay.t("Export")
}}</v-btn>
</v-expansion-panel-content>
</v-expansion-panel>
</template>
<script>
export default {
data: () => ({
action: "Add",
tag: null,
replace: null,
exportFormat: "json",
jobActive: false
}),
methods: {
@@ -55,112 +29,33 @@ export default {
return this.dataListSelection.ObjectType != 0;
},
goHelp() {
window.open(this.$store.state.helpUrl + "ay-ex-tags", "_blank");
},
canDoAction() {
let vm = this;
if (vm.action == "Replace" && !vm.replace) {
return false;
}
if (vm.tag) {
return true;
}
return false;
window.open(this.$store.state.helpUrl + "ay-ex-export", "_blank");
},
async doAction() {
//do the bulk action
//do the export and trigger download
let vm = this;
let url = "tag-list/";
let url = `export/render/${vm.exportFormat}`;
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);
let res = await window.$gz.api.upsert(url, body);
if (res.error) {
throw new Error(res.error);
}
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}`
let href = window.$gz.api.genericDownloadUrl(
"export/download/" + res.data
);
if (window.open(reportUrl, "DownloadExport") == null) {
throw new Error(
"Unable to download, your browser rejected navigating to download url."
);
if (jobStatus.error) {
throw new Error(jobStatus.error);
}
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: {