Skip to content

Commit

Permalink
Export fixes (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchop authored Apr 3, 2024
1 parent b64823b commit 5d028b6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
24 changes: 19 additions & 5 deletions src/components/TaskList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
</td>

<td v-if="displayColumn('frequency')">
{{ moment.duration(item.frequency).humanize().replace("an ", "1 ").replace("a ", "1 ") }}
{{ moment.duration(item.frequency).humanize() }}
</td>
<td v-if="displayColumn('last_run')">
{{ item.last_run }}
{{ moment(item.last_run).format("YYYY-MM-DD HH:mm:ss") }}
</td>
<td v-if="displayColumn('description')">{{ item.description }}</td>

Expand All @@ -73,6 +73,16 @@
<td v-if="displayColumn('refresh')">
<v-btn @click="refresh(item)" icon="mdi-refresh" size="x-small" variant="tonal" :disabled="!item.enabled">
</v-btn>
<v-btn
v-if="downloadableTasks"
class="ml-2"
@click="$emit('taskDownload', item)"
icon="mdi-download"
size="x-small"
variant="tonal"
:disabled="!item.enabled"
>
</v-btn>
</td>
</tr>
</template>
Expand Down Expand Up @@ -117,6 +127,10 @@ export default {
selectableTasks: {
type: Boolean,
default: false
},
downloadableTasks: {
type: Boolean,
default: false
}
},
data() {
Expand All @@ -128,11 +142,11 @@ export default {
{ key: "name", title: "Name", sortable: true },
{ key: "acts_on", title: "Acts On" },
{ key: "frequency", title: "Runs every", sortable: true },
{ key: "last_run", title: "Last Run", width: "180px", sortable: true },
{ key: "last_run", title: "Last run", width: "180px", sortable: true },
{ key: "description", title: "Description" },
{ key: "status", title: "Status", width: "120px", sortable: true },
{ key: "toggle", title: "Toggle", width: "80px" },
{ key: "refresh", title: "", width: "80px" }
{ key: "refresh", title: "", width: "110px" }
],
sortBy: [{ key: "name", order: "asc" }],
selectedTask: null,
Expand All @@ -147,7 +161,7 @@ export default {
this.timer = setInterval(this.listTasks, 5000);
this.$eventBus.on("taskUpdated", this.listTasks);
},
beforeDestroy() {
unmounted() {
clearInterval(this.timer);
},
methods: {
Expand Down
43 changes: 35 additions & 8 deletions src/views/ExportList.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<template>
<task-list selectable-tasks task-type="export" ref="exportList" @taskSelected="task => (this.selectedExport = task)">
<task-list
selectable-tasks
downloadable-tasks
task-type="export"
ref="exportList"
@taskSelected="task => selectExport(task)"
@taskDownload="task => downloadExport(task)"
>
</task-list>

<v-navigation-drawer permament location="right" width="400" ref="drawer">
Expand Down Expand Up @@ -57,6 +64,17 @@
required
ref="exportTemplate"
></v-autocomplete>
<div class="d-flex">
<v-text-field
class="w-50"
density="compact"
label="Run every"
v-model="selectedExport.human_frequency"
></v-text-field>
<!-- select hours, days, minutes, etc -->
<v-select density="compact" v-model="frequencyUnit" :items="['hours', 'days', 'minutes', 'seconds']"></v-select>
</div>

<v-btn-group rounded="1" density="compact">
<v-btn color="primary" density="compact" v-if="selectedExport.id" @click="updateExport">Save changes</v-btn>
<v-btn color="error" density="compact" v-if="selectedExport.id" @click="confirmDeleteExport">Delete</v-btn>
Expand All @@ -81,6 +99,7 @@
import { OBSERVABLE_TYPES } from "@/definitions/observableDefinitions.js";
import axios from "axios";
import TaskList from "@/components/TaskList.vue";
import moment from "moment";
</script>

<script lang="ts">
Expand All @@ -97,16 +116,17 @@ export default {
exports: [],
exportTemplates: [],
selectedExport: {},
timerListTemplates: null
timerListTemplates: null,
frequencyUnit: "hours"
};
},
mounted() {
this.listTemplates();
},
created() {
this.timerListTemplates = setInterval(this.listTemplates, 2000);
this.timerListTemplates = setInterval(this.listTemplates, 5000);
},
beforeDestroy() {
unmounted() {
clearInterval(this.timerListTemplates);
},
methods: {
Expand All @@ -119,6 +139,11 @@ export default {
})
.finally(() => {});
},
selectExport(task) {
this.selectedExport = task;
this.selectedExport.human_frequency = moment.duration(task.frequency).asHours();
this.frequencyUnit = "hours";
},
updateExport() {
let exportTask = {
id: this.selectedExport.id,
Expand All @@ -128,7 +153,8 @@ export default {
ignore_tags: this.selectedExport.ignore_tags,
exclude_tags: this.selectedExport.exclude_tags,
acts_on: this.selectedExport.acts_on,
template_name: this.selectedExport.template_name
template_name: this.selectedExport.template_name,
frequency: moment.duration(this.selectedExport.human_frequency, this.frequencyUnit)
};
axios
Expand All @@ -152,7 +178,8 @@ export default {
template_name: this.selectedExport.template_name,
exclude_tags: this.selectedExport.exclude_tags,
ignore_tags: this.selectedExport.ignore_tags,
include_tags: this.selectedExport.include_tags
include_tags: this.selectedExport.include_tags,
frequency: moment.duration(this.selectedExport.human_frequency, this.frequencyUnit)
};
axios
.post(`/api/v2/tasks/export/new`, { export: exportTask })
Expand Down Expand Up @@ -192,9 +219,9 @@ export default {
.then(response => {
var fileURL = window.URL.createObjectURL(new Blob([response.data]));
var fileLink = document.createElement("a");
var fileName = response.headers["content-disposition"].split("filename=")[1];
let fileName = `${singleExport.name}_${singleExport.last_run}.txt`;
fileLink.href = fileURL;
fileLink.setAttribute("download", fileName);
fileLink.download = fileName;
document.body.appendChild(fileLink);
fileLink.click();
})
Expand Down
2 changes: 1 addition & 1 deletion src/views/ExportTemplates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default {
templates: [],
defaultTemplate: {
name: "",
template: ""
template: `value,tags\n{% for obj in data %}{{obj.value}},{{";".join(obj.tags.keys())}}\n{% endfor %}`
},
selectedTemplate: null,
headers: [
Expand Down

0 comments on commit 5d028b6

Please sign in to comment.