Skip to content

Commit 979f9e8

Browse files
committed
Fix job export and show
1 parent d4dedb8 commit 979f9e8

File tree

2 files changed

+86
-61
lines changed

2 files changed

+86
-61
lines changed

src/adabas/jobs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,7 @@ export async function loadExecutions(jobName: string, from: Date, to: Date): Pro
161161
});
162162
return executions;
163163
}
164+
165+
export async function loadJobDefinition(jobName: string): Promise<any> {
166+
return await triggerCall("/scheduler/job/" + jobName);
167+
}

src/components/JobList.vue

Lines changed: 82 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,21 @@
3030
<Url url="/scheduler/jobs" />
3131
<b-row>
3232
<b-col sm="5">
33-
<b-pagination
34-
v-model="currentPage"
35-
:total-rows="jobs.length"
36-
:per-page="perPage"
37-
aria-controls="my-table"
38-
></b-pagination></b-col>
33+
<b-pagination
34+
v-model="currentPage"
35+
:total-rows="jobs.length"
36+
:per-page="perPage"
37+
aria-controls="my-table"
38+
></b-pagination
39+
></b-col>
3940
<b-col sm="1">
40-
<b-form-select v-model="perPage" :options="perPageOptions" size="sm" class="mt-3"></b-form-select>
41-
</b-col></b-row>
41+
<b-form-select
42+
v-model="perPage"
43+
:options="perPageOptions"
44+
size="sm"
45+
class="mt-3"
46+
></b-form-select> </b-col
47+
></b-row>
4248
<b-row>
4349
<b-col sm="6">
4450
<b-table
@@ -72,17 +78,9 @@
7278
<b-button
7379
variant="outline-primary"
7480
class="mr-2"
75-
v-b-modal="'modal-definition-' + row.item.status.Job.Name"
81+
v-on:click="viewJob(row.item.status)"
7682
>Show</b-button
7783
>
78-
<b-modal
79-
size="xl"
80-
:id="'modal-definition-' + row.item.status.Job.Name"
81-
title="Job definition"
82-
ok-only
83-
>
84-
<pre class="my-4">{{ row.item.status.Job }}</pre>
85-
</b-modal>
8684
<b-button
8785
variant="outline-primary"
8886
id="expJob"
@@ -156,18 +154,26 @@
156154
</b-row>
157155
</b-card-body>
158156
</b-card>
157+
<b-modal
158+
size="xl"
159+
id="modal-definition-job"
160+
:title="'Job definition ' + currentJob.Name"
161+
ok-only
162+
>
163+
<pre class="my-4">{{ currentJob }}</pre>
164+
</b-modal>
159165
<StatusBar />
160166
</div>
161167
</template>
162168

163169
<script lang="ts">
164-
import { Component, Prop, Vue } from "vue-property-decorator";
165-
import { JobAdmin, loadExecutions } from "../adabas/jobs";
166-
import { userService } from "../user/service";
167-
import store from "../store/index";
168-
import CreateJob from "./CreateJob.vue";
169-
import StatusBar from "./StatusBar.vue";
170-
import Url from "./Url.vue";
170+
import { Component, Prop, Vue } from 'vue-property-decorator';
171+
import { JobAdmin, loadExecutions, loadJobDefinition } from '../adabas/jobs';
172+
import { userService } from '../user/service';
173+
import store from '../store/index';
174+
import CreateJob from './CreateJob.vue';
175+
import StatusBar from './StatusBar.vue';
176+
import Url from './Url.vue';
171177
172178
@Component({
173179
components: {
@@ -183,26 +189,27 @@ export default class JobList extends Vue {
183189
return {
184190
perPage: 10,
185191
currentPage: 1,
186-
perPageOptions: [10,20,50,100],
192+
perPageOptions: [10, 20, 50, 100],
187193
selectedJob: null,
188194
selectedExecution: null,
189195
fields: [
190-
{ key: "status.Job.Name", label: "Name" },
191-
{ key: "status.Job.User", label: "User" },
192-
{ key: "status.Job.Utility", label: "Utility" },
193-
{ key: "status.Status", label: "Status" },
194-
{ key: "status.Job.Description", label: "Description" },
195-
"info",
196+
{ key: 'status.Job.Name', label: 'Name' },
197+
{ key: 'status.Job.User', label: 'User' },
198+
{ key: 'status.Job.Utility', label: 'Utility' },
199+
{ key: 'status.Status', label: 'Status' },
200+
{ key: 'status.Job.Description', label: 'Description' },
201+
'info',
196202
],
197-
execFields: ["Id", "Scheduled", "Ended", "ExitCode", "log"],
203+
execFields: ['Id', 'Scheduled', 'Ended', 'ExitCode', 'log'],
198204
jobs: [] as JobAdmin[],
199-
currentId: "",
205+
currentId: '',
200206
executions: [],
201-
timer: "",
207+
timer: '',
202208
max: maxDate,
203-
log: "",
209+
log: '',
204210
from: null,
205211
to: null,
212+
currentJob: {} as any,
206213
};
207214
}
208215
created(): void {
@@ -214,35 +221,43 @@ export default class JobList extends Vue {
214221
}
215222
convertDate(currentdate: Date): string {
216223
return (
217-
new String(currentdate.getFullYear()).padStart(4, "0") +
218-
"-" +
219-
new String(currentdate.getMonth() + 1).padStart(2, "0") +
220-
"-" +
221-
new String(currentdate.getDate()).padStart(2, "0")
224+
new String(currentdate.getFullYear()).padStart(4, '0') +
225+
'-' +
226+
new String(currentdate.getMonth() + 1).padStart(2, '0') +
227+
'-' +
228+
new String(currentdate.getDate()).padStart(2, '0')
222229
);
223230
}
224231
convertTime(currentdate: Date): string {
225232
return (
226-
new String(currentdate.getHours()).padStart(2, "0") +
227-
":" +
228-
new String(currentdate.getMinutes()).padStart(2, "0") +
229-
":" +
230-
new String(currentdate.getSeconds()).padStart(2, "0")
233+
new String(currentdate.getHours()).padStart(2, '0') +
234+
':' +
235+
new String(currentdate.getMinutes()).padStart(2, '0') +
236+
':' +
237+
new String(currentdate.getSeconds()).padStart(2, '0')
231238
);
232239
}
233240
convertDateTime(d: string): string {
234241
var de = new Date(d);
235242
return de.toUTCString();
236243
}
244+
viewJob(item: any): void {
245+
console.log('View job ' + JSON.stringify(item));
246+
loadJobDefinition(item.Job.Name).then((result: any) => {
247+
console.log('Return ' + JSON.stringify(result));
248+
this.$data.currentJob = result;
249+
this.$bvModal.show('modal-definition-job');
250+
});
251+
}
237252
retrieveJobs(): void {
238253
store
239-
.dispatch("SYNC_ADMIN_JOBS")
254+
.dispatch('SYNC_ADMIN_JOBS')
240255
.then((response: any) => {
241256
if (this.$data.selectedJob != null) {
242257
const name = this.$data.selectedJob.status.Job.Name;
243258
let x = response.find((j: JobAdmin) => j.name() === name);
244259
if (!x) {
245-
console.log("No name found");
260+
console.log('No name found');
246261
return;
247262
}
248263
this.$data.selectedJob = x;
@@ -251,22 +266,22 @@ export default class JobList extends Vue {
251266
this.$data.jobs = response;
252267
})
253268
.catch((error: any) => {
254-
console.log("ERROR JOBLIST: " + JSON.stringify(error));
269+
console.log('ERROR JOBLIST: ' + JSON.stringify(error));
255270
if (error.response) {
256-
store.commit("SET_STATUS", JSON.stringify(error.response));
271+
store.commit('SET_STATUS', JSON.stringify(error.response));
257272
if (error.response.status == 401 || error.response.status == 403) {
258273
userService.logout();
259274
location.reload();
260275
}
261276
} else {
262-
store.commit("SET_STATUS", JSON.stringify(error));
277+
store.commit('SET_STATUS', JSON.stringify(error));
263278
userService.logout();
264279
location.reload();
265280
}
266281
throw error;
267282
});
268283
if (this.$data.selectedJob != null) {
269-
console.log(this.$data.from)
284+
console.log(this.$data.from);
270285
loadExecutions(
271286
this.$data.selectedJob.status.Job.Name,
272287
this.$data.from,
@@ -289,7 +304,7 @@ export default class JobList extends Vue {
289304
if (items.length == 0) {
290305
return;
291306
}
292-
this.$data.log = "";
307+
this.$data.log = '';
293308
this.$data.selectedJob = items[0];
294309
loadExecutions(
295310
items[0].status.Job.Name,
@@ -317,23 +332,29 @@ export default class JobList extends Vue {
317332
const jobToDelete = this.$data.jobs.find(
318333
(j: JobAdmin) => j.name() === name
319334
);
320-
console.log("Job to delete: " + name);
335+
console.log('Job to delete: ' + name);
321336
jobToDelete.delete();
322337
}
323338
exportJob(name: string): void {
324-
const jobToExport = this.$data.jobs.find(
325-
(j: JobAdmin) => j.name() === name
326-
);
327-
console.log(
328-
"Job to export: " + name + " " + JSON.stringify(jobToExport.status.Job)
329-
);
339+
loadJobDefinition(name).then((result: any) => {
340+
var filename = 'job.json';
341+
const a = document.createElement('a');
342+
const type = filename.split('.').pop();
343+
a.href = URL.createObjectURL(
344+
new Blob([JSON.stringify(result)], {
345+
type: `text/${type === 'txt' ? 'plain' : type}`,
346+
})
347+
);
348+
a.download = filename;
349+
a.click();
350+
});
330351
}
331352
delExecution(id: string): void {
332-
console.log("Delete id " + id);
353+
console.log('Delete id ' + id);
333354
this.$data.selectedJob.delete_execution(id);
334355
}
335356
showLog(item: any): void {
336-
console.log("Show log id " + JSON.stringify(item));
357+
console.log('Show log id ' + JSON.stringify(item));
337358
this.$data.currentId = item.ID;
338359
this.$data.log = item.Log;
339360
}

0 commit comments

Comments
 (0)