This commit is contained in:
@@ -6,48 +6,22 @@
|
|||||||
>{{ $ay.t("Export") }}</v-expansion-panel-header
|
>{{ $ay.t("Export") }}</v-expansion-panel-header
|
||||||
>
|
>
|
||||||
<v-expansion-panel-content>
|
<v-expansion-panel-content>
|
||||||
<v-radio-group v-model="action">
|
<v-radio-group v-model="exportFormat">
|
||||||
<v-radio :label="$ay.t('Add')" value="Add"></v-radio>
|
<v-radio label="JSON" value="json"></v-radio>
|
||||||
<v-radio :label="$ay.t('Remove')" value="Remove"></v-radio>
|
<v-radio label="CSV" value="csv"></v-radio>
|
||||||
<v-radio :label="$ay.t('Replace')" value="Replace"></v-radio>
|
|
||||||
</v-radio-group>
|
</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 icon @click="goHelp()"><v-icon>$ayiQuestionCircle</v-icon></v-btn>
|
||||||
<v-btn
|
<v-btn color="blue darken-1" text @click="doAction()">{{
|
||||||
:disabled="!canDoAction()"
|
$ay.t("Export")
|
||||||
color="blue darken-1"
|
}}</v-btn>
|
||||||
text
|
|
||||||
@click="doAction()"
|
|
||||||
:loading="jobActive"
|
|
||||||
>{{ $ay.t("StartJob") }}</v-btn
|
|
||||||
>
|
|
||||||
</v-expansion-panel-content>
|
</v-expansion-panel-content>
|
||||||
</v-expansion-panel>
|
</v-expansion-panel>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
data: () => ({
|
data: () => ({
|
||||||
action: "Add",
|
exportFormat: "json",
|
||||||
tag: null,
|
|
||||||
replace: null,
|
|
||||||
jobActive: false
|
jobActive: false
|
||||||
}),
|
}),
|
||||||
methods: {
|
methods: {
|
||||||
@@ -55,112 +29,33 @@ export default {
|
|||||||
return this.dataListSelection.ObjectType != 0;
|
return this.dataListSelection.ObjectType != 0;
|
||||||
},
|
},
|
||||||
goHelp() {
|
goHelp() {
|
||||||
window.open(this.$store.state.helpUrl + "ay-ex-tags", "_blank");
|
window.open(this.$store.state.helpUrl + "ay-ex-export", "_blank");
|
||||||
},
|
|
||||||
canDoAction() {
|
|
||||||
let vm = this;
|
|
||||||
if (vm.action == "Replace" && !vm.replace) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (vm.tag) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async doAction() {
|
async doAction() {
|
||||||
//do the bulk action
|
//do the export and trigger download
|
||||||
let vm = this;
|
let vm = this;
|
||||||
let url = "tag-list/";
|
let url = `export/render/${vm.exportFormat}`;
|
||||||
let body = this.dataListSelection;
|
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 {
|
try {
|
||||||
//call api route
|
//call api route
|
||||||
let jobId = await window.$gz.api.upsert(url, body);
|
let res = await window.$gz.api.upsert(url, body);
|
||||||
if (jobId.error) {
|
if (res.error) {
|
||||||
throw new Error(jobId.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>
|
let href = window.$gz.api.genericDownloadUrl(
|
||||||
/// Job status for opsjobs
|
"export/download/" + res.data
|
||||||
/// </summary>
|
);
|
||||||
public enum JobStatus : int
|
if (window.open(reportUrl, "DownloadExport") == null) {
|
||||||
{
|
throw new Error(
|
||||||
Absent=0,
|
"Unable to download, your browser rejected navigating to download url."
|
||||||
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);
|
|
||||||
}
|
|
||||||
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) {
|
} catch (error) {
|
||||||
vm.jobActive = false;
|
|
||||||
window.$gz.errorHandler.handleFormError(error, vm);
|
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: {
|
props: {
|
||||||
|
|||||||
Reference in New Issue
Block a user