aboutsummaryrefslogtreecommitdiff
path: root/src_js/hatter/common.js
diff options
context:
space:
mode:
authorbozo.kopic <bozo.kopic@gmail.com>2017-08-24 17:51:14 +0200
committerbozo.kopic <bozo.kopic@gmail.com>2017-08-24 17:51:14 +0200
commitc594b1fca854a7b9fb73d854a9830143cd1032fc (patch)
tree8c8b63cb4899238cf0f73a3f7bd08d9b70b16e81 /src_js/hatter/common.js
parentd736cd1392a56ad5103867c72761cfcb4ccd4f1b (diff)
frontend
Diffstat (limited to 'src_js/hatter/common.js')
-rw-r--r--src_js/hatter/common.js66
1 files changed, 65 insertions, 1 deletions
diff --git a/src_js/hatter/common.js b/src_js/hatter/common.js
index 829685b..c6dcfcc 100644
--- a/src_js/hatter/common.js
+++ b/src_js/hatter/common.js
@@ -1,2 +1,66 @@
-export const defaultState = {};
+import r from 'hatter/renderer';
+import * as util from 'hatter/util';
+
+
+export const defaultState = {
+ conn: null,
+ log: {
+ offset: 0,
+ offsetText: '0',
+ limit: 0,
+ limitText: '0',
+ entries: []
+ },
+ job: {
+ active: null,
+ queue: []
+ },
+ repositories: []
+};
+
+
+export function processMsg(msg) {
+ if (msg.type == 'repositories') {
+ r.set('repositories', msg.repositories);
+ } else if (msg.type == 'active_job') {
+ r.set(['job', 'active'], msg.job);
+ } else if (msg.type == 'job_queue') {
+ r.set(['job', 'queue'], msg.jobs);
+ } else if (msg.type == 'log_entries') {
+ r.set(['log', 'entires'], msg.entries);
+ }
+}
+
+
+export function addJob(repository) {
+ r.get('conn').send(JSON.stringify({
+ type: 'add_job',
+ repository: repository,
+ commit: 'HEAD'
+ }));
+}
+
+
+bean.on(r, 'change', state => {
+ let newOffset = parseInt(state.log.offsetText);
+ let newLimit = parseInt(state.log.limitText);
+ if (util.isInteger(newOffset) && newOffset != state.log.offset) {
+ r.set(['log', 'offset'], newOffset).then(sendSetLog);
+ }
+ if (util.isInteger(newLimit) && newLimit != state.log.limit) {
+ r.set(['log', 'limit'], newLimit).then(sendSetLog);
+ }
+});
+
+
+function sendSetLog() {
+ let conn = r.get('conn');
+ if (!conn)
+ return;
+ conn.send(JSON.stringify({
+ type: 'set_log',
+ offset: r.get('offset'),
+ limit: r.get('limit')
+ }));
+}