Initial Commit, basic functionality
This commit is contained in:
commit
e684dfcd04
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@ -0,0 +1,9 @@
|
||||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/.cache/
|
||||
/dist/
|
||||
/node_modules/
|
||||
/package-lock.json
|
||||
/src/credentials.json
|
3
.prettierrc
Normal file
3
.prettierrc
Normal file
@ -0,0 +1,3 @@
|
||||
trailingComma: es5
|
||||
singleQuote: true
|
||||
jsxBracketSameLine: true
|
21
package.json
Normal file
21
package.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "saltstatus",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"vue": "^2.6.10",
|
||||
"vue-hot-reload-api": "^2.3.4",
|
||||
"vue-property-decorator": "^8.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/component-compiler-utils": "^3.0.2",
|
||||
"typescript": "^3.7.3",
|
||||
"vue-template-compiler": "^2.6.10"
|
||||
}
|
||||
}
|
99
src/App.vue
Normal file
99
src/App.vue
Normal file
@ -0,0 +1,99 @@
|
||||
<template>
|
||||
<div>
|
||||
<div v-for="(minions, jid) in jobs" :key="jid">
|
||||
<h3>{{ jid }}</h3>
|
||||
<div v-for="(minion_events, minion) in minions" :key="minion">
|
||||
<details class="minion">
|
||||
<summary>
|
||||
{{ minion }}
|
||||
<span v-for="(event, index) in minion_events" :key="index">
|
||||
{{ event_symbol(event) }}
|
||||
</span>
|
||||
</summary>
|
||||
<details
|
||||
class="event"
|
||||
v-for="(event, index) in minion_events"
|
||||
:key="index"
|
||||
>
|
||||
<summary>{{ event.tag }}</summary>
|
||||
<pre>{{ JSON.stringify(event, null, 2) }}</pre>
|
||||
</details>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop, Ref } from 'vue-property-decorator';
|
||||
|
||||
import credentials from './credentials.json';
|
||||
|
||||
const BASE_URL = 'https://salt.sawtooth.claremontmakerspace.org:8000/';
|
||||
|
||||
@Component
|
||||
export default class App extends Vue {
|
||||
evtSource: EventSource | null = null;
|
||||
events: any[] = [];
|
||||
|
||||
mounted() {
|
||||
fetch(BASE_URL + 'login', {
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
body: JSON.stringify(credentials),
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(r => {
|
||||
const token = r.return[0].token;
|
||||
this.evtSource = new EventSource(BASE_URL + 'events?token=' + token);
|
||||
this.evtSource.onmessage = e => {
|
||||
this.events.push(JSON.parse(e.data));
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
parse_tag(tag) {
|
||||
// todo: would probably be easier as string splitting at this point
|
||||
const match = tag.match(/salt\/job\/([^\/]*)\/(prog|ret)\/([^\/]*)\/?(.*)/);
|
||||
if (!match) return null;
|
||||
return {
|
||||
jid: match[1],
|
||||
type: match[2],
|
||||
minion: match[3],
|
||||
prog_id: match.length >= 5 ? match[4] : null,
|
||||
};
|
||||
}
|
||||
|
||||
event_symbol(event) {
|
||||
const tag = this.parse_tag(event.tag);
|
||||
if (tag.type === 'prog') {
|
||||
const ret = event.data.data.ret;
|
||||
if (!ret.result) return '✗';
|
||||
else if ('ret' in ret.changes) return 'Δ';
|
||||
else return '✓';
|
||||
} else if (tag.type === 'ret') {
|
||||
return event.data.success ? '✓' : '✗';
|
||||
}
|
||||
|
||||
return '?';
|
||||
}
|
||||
|
||||
get jobs() {
|
||||
return this.events.reduce((acc, e) => {
|
||||
const tag = this.parse_tag(e.tag);
|
||||
if (tag) {
|
||||
if (!(tag.jid in acc)) acc[tag.jid] = {};
|
||||
if (!(tag.minion in acc[tag.jid])) acc[tag.jid][tag.minion] = [];
|
||||
acc[tag.jid][tag.minion].push(e);
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.minion .event {
|
||||
margin-left: 2ex;
|
||||
}
|
||||
</style>
|
4
src/index.html
Normal file
4
src/index.html
Normal file
@ -0,0 +1,4 @@
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="text/javascript" src="index.ts"></script>
|
||||
</body>
|
7
src/index.ts
Normal file
7
src/index.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import Vue from 'vue';
|
||||
|
||||
import App from './App';
|
||||
|
||||
let app = new Vue({
|
||||
render: h => h(App),
|
||||
}).$mount('#app');
|
8
tsconfig.json
Normal file
8
tsconfig.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"strict": true,
|
||||
"module": "es2015",
|
||||
"moduleResolution": "node"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user