From c594b1fca854a7b9fb73d854a9830143cd1032fc Mon Sep 17 00:00:00 2001 From: "bozo.kopic" Date: Thu, 24 Aug 2017 17:51:14 +0200 Subject: frontend --- src_js/hatter/common.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'src_js/hatter/common.js') 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') + })); +} -- cgit v1.2.3-70-g09d2