diff --git a/src/App.vue b/src/App.vue index bbad93a..bd561b4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,40 +1,12 @@ @@ -44,34 +16,16 @@ import { Vue, Component, Prop, Ref } from 'vue-property-decorator'; import credentials from './credentials.json'; import * as salt from './salt'; +import Job from './Job'; const BASE_URL = 'https://salt.sawtooth.claremontmakerspace.org:8000/'; -type MinionJobEvent = salt.JobProgEvent | salt.JobRetEvent; - -class Job { - startEvent?: salt.JobNewEvent; - minionEvents: { [key: string]: MinionJobEvent[] } = {}; - jid: salt.JobID; - - constructor(jid: salt.JobID, startEvent?: salt.JobNewEvent) { - this.jid = jid; - this.startEvent = startEvent; - } - - addEvent(event: MinionJobEvent) { - if (!(event.data.id in this.minionEvents)) - Vue.set(this.minionEvents, event.data.id, []); - this.minionEvents[event.data.id].push(event); - } -} - -@Component +@Component({ components: { Job } }) export default class App extends Vue { evtSource: EventSource | null = null; events: salt.SaltEvent[] = []; - jobs: { [key: string]: Job } = {}; - rawEvents: boolean = false; + jobs: { [key: string]: salt.JobEvent[] } = {}; + showRawEvents: boolean = false; mounted(): void { fetch(BASE_URL + 'login', { @@ -89,17 +43,9 @@ export default class App extends Vue { this.events.push(event); if (this.isEventType(event, 'job')) { - if (this.isJobEventType(event, 'new')) { - this.$set( - this.jobs, - event.data.jid, - new Job(event.data.jid, event) - ); - } else { - if (!(event.data.jid in this.jobs)) - this.$set(this.jobs, event.data.jid, new Job(event.data.jid)); - this.jobs[event.data.jid].addEvent(event); - } + if (!(event.data.jid in this.jobs)) + this.$set(this.jobs, event.data.jid, []); + this.jobs[event.data.jid].push(event); } }; }); @@ -111,53 +57,5 @@ export default class App extends Vue { ): event is Extract { return event.splitTag[1] === type; } - - isJobEventType( - event: salt.SaltEvent, - type: T - ): event is Extract< - salt.SaltEvent, - { splitTag: ['salt', 'job', any, T, ...any[]] } - > { - return event.splitTag[3] === type; - } - - event_name(event: salt.JobEvent) { - if (this.isJobEventType(event, 'prog')) { - return `${this.event_symbol(event)} Progress: ${ - event.data.data.ret.name - }|${event.data.data.ret.duration} `; - } else if (this.isJobEventType(event, 'ret')) { - return `${this.event_symbol(event)} Return: ${event.data.fun} `; - } - } - - event_symbol(event: salt.JobEvent) { - if (this.isJobEventType(event, 'prog')) { - const ret = event.data.data.ret; - if (!ret.result) return '✗'; - else if (Object.keys(ret.changes).length !== 0) return 'Δ'; - else return '✓'; - } else if (this.isJobEventType(event, 'ret')) { - return event.data.success ? '✓' : '✗'; - } - - return '?'; - } } - - diff --git a/src/Job.vue b/src/Job.vue new file mode 100644 index 0000000..54aa6c3 --- /dev/null +++ b/src/Job.vue @@ -0,0 +1,119 @@ + + + + +