UI more user friendly, still needs completion

This commit is contained in:
Dominic Bosch 2014-04-26 16:01:33 +02:00
parent 0b582244e3
commit ca2f6e06ff
18 changed files with 1311 additions and 1147 deletions

View file

@ -470,12 +470,13 @@ commandFunctions =
else
hookid
hookid = genHookID arrHooks
db.createWebhook user.username, oBody.hookname, hookid
rh.activateWebhook hookid, oBody.hookname
db.createWebhook user.username, hookid, oBody.hookname
rh.activateWebhook user.username, hookid, oBody.hookname
callback
code: 200
message: JSON.stringify
hookid: hookid
hookname: oBody.hookname
get_all_webhooks: ( user, oBody, callback ) ->
db.getAllUserWebhooks user.username, ( err, data ) ->
@ -484,9 +485,10 @@ commandFunctions =
code: 400
message: "We didn't like your request!"
else
data = JSON.stringify data || ''
callback
code: 200
message: JSON.stringify data
message: data
delete_webhook: ( user, oBody, callback ) ->
answ = hasRequiredParams [ 'hookid' ], oBody

View file

@ -272,9 +272,8 @@ processEvent = ( evt ) =>
else
fSearchAndInvokeAction node[arrPath[depth]], arrPath, funcName, evt, depth + 1
@log.info 'EN | processing event: ' + evt.eventname
for userName, oUser of listUserRules
@log.info 'EN | Processing event: ' + evt.eventname
fCheckEventForUser = ( userName, oUser ) ->
for ruleName, oMyRule of oUser
ruleEvent = oMyRule.rule.eventname
@ -288,6 +287,14 @@ processEvent = ( evt ) =>
arr = action.split ' -> '
fSearchAndInvokeAction listUserRules, [ userName, ruleName, 'actions', arr[0]], arr[1], evt, 0
# If the event is bound to a user, we only process it for him
if evt.username
fCheckEventForUser evt.username, listUserRules[ evt.username ]
# Else we loop through all users
else
fCheckEventForUser userName, oUser for userName, oUser of listUserRules
exports.shutDown = () ->
isRunning = false
listUserRules = {}

View file

@ -797,16 +797,16 @@ exports.removeUserRole = ( userId, role ) =>
###
Creates and stores a webhook.
@public createWebhook( *userId, hookname* )
@param {String} userId
@public createWebhook( *username, hookname* )
@param {String} username
@param {String} hookname
###
exports.createWebhook = ( userId, hookname, hookid ) =>
exports.createWebhook = ( username, hookid, hookname ) =>
@db.sadd "webhooks", hookid, replyHandler "sadd 'webhooks' -> '#{ hookid }'"
@db.sadd "user:#{ userId }:webhooks", hookid,
replyHandler "sadd 'user:#{ userId }:webhooks' -> '#{ hookid }'"
@db.set "webhook:#{ hookid }", hookname,
replyHandler "set webhook:#{ hookid } -> #{ hookname }"
@db.sadd "user:#{ username }:webhooks", hookid,
replyHandler "sadd 'user:#{ username }:webhooks' -> '#{ hookid }'"
@db.hmset "webhook:#{ hookid }", 'hookname', hookname, 'username', username,
replyHandler "set webhook:#{ hookid } -> [#{ hookname }, #{ username }]"
###
Returns a webhook name.
@ -815,25 +815,34 @@ Returns a webhook name.
@param {String} hookid
###
exports.getWebhookName = ( hookid, cb ) =>
@db.get "webhook:#{ hookid }", cb
@db.hget "webhook:#{ hookid }", "hookname", cb
###
Returns all webhook properties.
@public getFullWebhookName( *hookid* )
@param {String} hookid
###
exports.getFullWebhook = ( hookid, cb ) =>
@db.hgetall "webhook:#{ hookid }", cb
###
Returns all the user's webhooks by ID.
@public getUserWebhookIDs( *userId* )
@param {String} userId
@public getUserWebhookIDs( *username* )
@param {String} username
###
exports.getUserWebhookIDs = ( userId, cb ) =>
@db.smembers "user:#{ userId }:webhooks", cb
exports.getUserWebhookIDs = ( username, cb ) =>
@db.smembers "user:#{ username }:webhooks", cb
###
Gets all the user's webhooks with names.
@public getAllUserWebhooks( *userId* )
@param {String} userId
@public getAllUserWebhooks( *username* )
@param {String} username
###
exports.getAllUserWebhooks = ( userId, cb ) =>
getSetRecords "user:#{ userId }:webhooks", exports.getWebhookName, cb
exports.getAllUserWebhooks = ( username, cb ) =>
getSetRecords "user:#{ username }:webhooks", exports.getWebhookName, cb
###
Returns all webhook IDs.
@ -849,19 +858,19 @@ Returns all webhooks with names.
@public getAllWebhooks()
###
exports.getAllWebhooks = ( cb ) =>
getSetRecords "webhooks", exports.getWebhookName, cb
getSetRecords "webhooks", exports.getFullWebhook, cb
###
Delete a webhook.
@public deleteWebhook( *userId, hookid* )
@param {String} userId
@public deleteWebhook( *username, hookid* )
@param {String} username
@param {String} hookid
###
exports.deleteWebhook = ( userId, hookid ) =>
exports.deleteWebhook = ( username, hookid ) =>
@db.srem "webhooks", hookid, replyHandler "srem 'webhooks' -> '#{ hookid }'"
@db.srem "user:#{ userId }:webhooks", hookid,
replyHandler "srem 'user:#{ userId }:webhooks' -> '#{ hookid }'"
@db.srem "user:#{ username }:webhooks", hookid,
replyHandler "srem 'user:#{ username }:webhooks' -> '#{ hookid }'"
@db.del "webhook:#{ hookid }", replyHandler "del webhook:#{ hookid }"
###

View file

@ -354,7 +354,8 @@ exports.handleAdminCommand = ( req, resp ) =>
resp.send 401, 'You need to be logged in as admin!'
indexEvent = ( eventname, body, resp ) ->
# Parse events and register to user if it's a user specific event
parsePushAndAnswerEvent = ( eventname, username, body, resp ) ->
if typeof body is 'string'
try
body = JSON.parse body
@ -367,8 +368,12 @@ indexEvent = ( eventname, body, resp ) ->
obj =
eventname: eventname
body: body
if username
obj.username = username
db.pushEvent obj
msg = "Thank you for the event: '#{ eventname }'"
resp.send 200, JSON.stringify
message: "Thank you for the event: '#{ eventname }'"
evt: obj
obj
@ -381,7 +386,7 @@ exports.handleMeasurements = ( req, resp ) =>
body += data
req.on 'end', ->
obj = indexEvent name, body, resp
obj = parsePushAndAnswerEvent name, null, body, resp
if obj.eventname is 'uptimestatistics'
# This is a hack to quickly allow storing of public accessible data
fPath = path.resolve __dirname, '..', 'webpages', 'public', 'data', 'histochart.json'
@ -392,22 +397,24 @@ Handles webhook posts
###
exports.handleWebhooks = ( req, resp ) =>
hookid = req.url.substring( 10 ).split( '/' )[ 0 ]
hookname = @allowedHooks[ hookid ]
if hookname
oHook = @allowedHooks[ hookid ]
if oHook
body = ''
req.on 'data', ( data ) ->
body += data
req.on 'end', () ->
obj = indexEvent hookname, body, resp
parsePushAndAnswerEvent oHook.hookname, oHook.username, body, resp
else
resp.send 404, "Webhook not existing!"
# Activate a webhook. the body will be JSON parsed, the name of the webhook will
# be the event name given to the event object, a timestamp will be added
exports.activateWebhook = ( hookid, name ) =>
exports.activateWebhook = ( user, hookid, name ) =>
@log.info "HL | Webhook '#{ hookid }' activated"
@allowedHooks[ hookid ] = name
@allowedHooks[ hookid ] =
hookname: name
username: user
# Deactivate a webhook
exports.deactivateWebhook = ( hookid ) =>

View file

@ -592,12 +592,13 @@ Components Manager
}
};
hookid = genHookID(arrHooks);
db.createWebhook(user.username, oBody.hookname, hookid);
rh.activateWebhook(hookid, oBody.hookname);
db.createWebhook(user.username, hookid, oBody.hookname);
rh.activateWebhook(user.username, hookid, oBody.hookname);
return callback({
code: 200,
message: JSON.stringify({
hookid: hookid
hookid: hookid,
hookname: oBody.hookname
})
});
});
@ -614,9 +615,10 @@ Components Manager
message: "We didn't like your request!"
});
} else {
data = JSON.stringify(data || '');
return callback({
code: 200,
message: JSON.stringify(data)
message: data
});
}
});

View file

@ -298,7 +298,7 @@ Engine
processEvent = (function(_this) {
return function(evt) {
var action, arr, fSearchAndInvokeAction, oMyRule, oUser, ruleEvent, ruleName, userName, _results;
var fCheckEventForUser, fSearchAndInvokeAction, oUser, userName, _results;
fSearchAndInvokeAction = function(node, arrPath, funcName, evt, depth) {
var argument, arrArgs, arrSelectors, data, err, oArg, sel, selector, _i, _j, _len, _len1, _ref;
if (!node) {
@ -346,40 +346,45 @@ Engine
return fSearchAndInvokeAction(node[arrPath[depth]], arrPath, funcName, evt, depth + 1);
}
};
_this.log.info('EN | processing event: ' + evt.eventname);
_results = [];
for (userName in listUserRules) {
oUser = listUserRules[userName];
_results.push((function() {
var _results1;
_results1 = [];
for (ruleName in oUser) {
oMyRule = oUser[ruleName];
ruleEvent = oMyRule.rule.eventname;
if (oMyRule.rule.timestamp) {
ruleEvent += '_created:' + oMyRule.rule.timestamp;
}
if (evt.eventname === ruleEvent && validConditions(evt, oMyRule.rule, userName, ruleName)) {
this.log.info('EN | EVENT FIRED: ' + evt.eventname + ' for rule ' + ruleName);
_results1.push((function() {
var _i, _len, _ref, _results2;
_ref = oMyRule.rule.actions;
_results2 = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
action = _ref[_i];
arr = action.split(' -> ');
_results2.push(fSearchAndInvokeAction(listUserRules, [userName, ruleName, 'actions', arr[0]], arr[1], evt, 0));
}
return _results2;
})());
} else {
_results1.push(void 0);
}
_this.log.info('EN | Processing event: ' + evt.eventname);
fCheckEventForUser = function(userName, oUser) {
var action, arr, oMyRule, ruleEvent, ruleName, _results;
_results = [];
for (ruleName in oUser) {
oMyRule = oUser[ruleName];
ruleEvent = oMyRule.rule.eventname;
if (oMyRule.rule.timestamp) {
ruleEvent += '_created:' + oMyRule.rule.timestamp;
}
return _results1;
}).call(_this));
if (evt.eventname === ruleEvent && validConditions(evt, oMyRule.rule, userName, ruleName)) {
this.log.info('EN | EVENT FIRED: ' + evt.eventname + ' for rule ' + ruleName);
_results.push((function() {
var _i, _len, _ref, _results1;
_ref = oMyRule.rule.actions;
_results1 = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
action = _ref[_i];
arr = action.split(' -> ');
_results1.push(fSearchAndInvokeAction(listUserRules, [userName, ruleName, 'actions', arr[0]], arr[1], evt, 0));
}
return _results1;
})());
} else {
_results.push(void 0);
}
}
return _results;
};
if (evt.username) {
return fCheckEventForUser(evt.username, listUserRules[evt.username]);
} else {
_results = [];
for (userName in listUserRules) {
oUser = listUserRules[userName];
_results.push(fCheckEventForUser(userName, oUser));
}
return _results;
}
return _results;
};
})(this);

View file

@ -1038,16 +1038,16 @@ Persistence
/*
Creates and stores a webhook.
@public createWebhook( *userId, hookname* )
@param {String} userId
@public createWebhook( *username, hookname* )
@param {String} username
@param {String} hookname
*/
exports.createWebhook = (function(_this) {
return function(userId, hookname, hookid) {
return function(username, hookid, hookname) {
_this.db.sadd("webhooks", hookid, replyHandler("sadd 'webhooks' -> '" + hookid + "'"));
_this.db.sadd("user:" + userId + ":webhooks", hookid, replyHandler("sadd 'user:" + userId + ":webhooks' -> '" + hookid + "'"));
return _this.db.set("webhook:" + hookid, hookname, replyHandler("set webhook:" + hookid + " -> " + hookname));
_this.db.sadd("user:" + username + ":webhooks", hookid, replyHandler("sadd 'user:" + username + ":webhooks' -> '" + hookid + "'"));
return _this.db.hmset("webhook:" + hookid, 'hookname', hookname, 'username', username, replyHandler("set webhook:" + hookid + " -> [" + hookname + ", " + username + "]"));
};
})(this);
@ -1061,7 +1061,21 @@ Persistence
exports.getWebhookName = (function(_this) {
return function(hookid, cb) {
return _this.db.get("webhook:" + hookid, cb);
return _this.db.hget("webhook:" + hookid, "hookname", cb);
};
})(this);
/*
Returns all webhook properties.
@public getFullWebhookName( *hookid* )
@param {String} hookid
*/
exports.getFullWebhook = (function(_this) {
return function(hookid, cb) {
return _this.db.hgetall("webhook:" + hookid, cb);
};
})(this);
@ -1069,13 +1083,13 @@ Persistence
/*
Returns all the user's webhooks by ID.
@public getUserWebhookIDs( *userId* )
@param {String} userId
@public getUserWebhookIDs( *username* )
@param {String} username
*/
exports.getUserWebhookIDs = (function(_this) {
return function(userId, cb) {
return _this.db.smembers("user:" + userId + ":webhooks", cb);
return function(username, cb) {
return _this.db.smembers("user:" + username + ":webhooks", cb);
};
})(this);
@ -1083,13 +1097,13 @@ Persistence
/*
Gets all the user's webhooks with names.
@public getAllUserWebhooks( *userId* )
@param {String} userId
@public getAllUserWebhooks( *username* )
@param {String} username
*/
exports.getAllUserWebhooks = (function(_this) {
return function(userId, cb) {
return getSetRecords("user:" + userId + ":webhooks", exports.getWebhookName, cb);
return function(username, cb) {
return getSetRecords("user:" + username + ":webhooks", exports.getWebhookName, cb);
};
})(this);
@ -1115,7 +1129,7 @@ Persistence
exports.getAllWebhooks = (function(_this) {
return function(cb) {
return getSetRecords("webhooks", exports.getWebhookName, cb);
return getSetRecords("webhooks", exports.getFullWebhook, cb);
};
})(this);
@ -1123,15 +1137,15 @@ Persistence
/*
Delete a webhook.
@public deleteWebhook( *userId, hookid* )
@param {String} userId
@public deleteWebhook( *username, hookid* )
@param {String} username
@param {String} hookid
*/
exports.deleteWebhook = (function(_this) {
return function(userId, hookid) {
return function(username, hookid) {
_this.db.srem("webhooks", hookid, replyHandler("srem 'webhooks' -> '" + hookid + "'"));
_this.db.srem("user:" + userId + ":webhooks", hookid, replyHandler("srem 'user:" + userId + ":webhooks' -> '" + hookid + "'"));
_this.db.srem("user:" + username + ":webhooks", hookid, replyHandler("srem 'user:" + username + ":webhooks' -> '" + hookid + "'"));
return _this.db.del("webhook:" + hookid, replyHandler("del webhook:" + hookid));
};
})(this);

View file

@ -11,7 +11,7 @@ Request Handler
*/
(function() {
var crypto, db, dirHandlers, exports, fs, getHandlerPath, getRemoteScripts, getScript, getTemplate, indexEvent, mustache, path, pathUsers, qs, renderPage;
var crypto, db, dirHandlers, exports, fs, getHandlerPath, getRemoteScripts, getScript, getTemplate, mustache, parsePushAndAnswerEvent, path, pathUsers, qs, renderPage;
db = require('./persistence');
@ -433,8 +433,8 @@ Request Handler
};
})(this);
indexEvent = function(eventname, body, resp) {
var err, msg, obj;
parsePushAndAnswerEvent = function(eventname, username, body, resp) {
var err, obj;
if (typeof body === 'string') {
try {
body = JSON.parse(body);
@ -453,8 +453,14 @@ Request Handler
eventname: eventname,
body: body
};
if (username) {
obj.username = username;
}
db.pushEvent(obj);
msg = "Thank you for the event: '" + eventname + "'";
resp.send(200, JSON.stringify({
message: "Thank you for the event: '" + eventname + "'",
evt: obj
}));
return obj;
};
@ -472,7 +478,7 @@ Request Handler
});
return req.on('end', function() {
var fPath, obj;
obj = indexEvent(name, body, resp);
obj = parsePushAndAnswerEvent(name, null, body, resp);
if (obj.eventname === 'uptimestatistics') {
fPath = path.resolve(__dirname, '..', 'webpages', 'public', 'data', 'histochart.json');
return fs.writeFile(fPath, JSON.stringify(JSON.parse(body), void 0, 2), 'utf8');
@ -488,17 +494,16 @@ Request Handler
exports.handleWebhooks = (function(_this) {
return function(req, resp) {
var body, hookid, hookname;
var body, hookid, oHook;
hookid = req.url.substring(10).split('/')[0];
hookname = _this.allowedHooks[hookid];
if (hookname) {
oHook = _this.allowedHooks[hookid];
if (oHook) {
body = '';
req.on('data', function(data) {
return body += data;
});
return req.on('end', function() {
var obj;
return obj = indexEvent(hookname, body, resp);
return parsePushAndAnswerEvent(oHook.hookname, oHook.username, body, resp);
});
} else {
return resp.send(404, "Webhook not existing!");
@ -507,9 +512,12 @@ Request Handler
})(this);
exports.activateWebhook = (function(_this) {
return function(hookid, name) {
return function(user, hookid, name) {
_this.log.info("HL | Webhook '" + hookid + "' activated");
return _this.allowedHooks[hookid] = name;
return _this.allowedHooks[hookid] = {
hookname: name,
username: user
};
};
})(this);

View file

@ -1,3 +1,9 @@
#
# General Helper Fucntions
#
strPublicKey = ''
# Fetch the search string and transform it into an object for easy access
arrParams = window.location.search.substring(1).split '&'
oParams = {}
@ -8,15 +14,6 @@ for param in arrParams
if oParams.id
oParams.id = decodeURIComponent oParams.id
strPublicKey = ''
# fPlaceAndPaintInterval = () ->
# $( '#event_start' ).html 'Start Time:
# <input id="input_start" type="text" />
# <b>"hh:mm"</b>, default = 12:00'
# $( '#event_interval' ).html 'Interval:
# <input id="input_interval" type="text" />
# <b>"days hours:minutes"</b>, default = 10 minutes'
fDisplayError = ( msg ) ->
window.scrollTo 0, 0
$( '#info' ).text "Error: #{ msg }"
@ -34,7 +31,380 @@ fIssueRequest = ( args ) ->
$.post( '/usercommand', args.body )
.done args.done
.fail args.fail
# Convert a time string ( d h:m ) to a date
fConvertTimeToDate = ( str ) ->
txtStart = $( '#input_start' ).val()
dateConv = new Date()
if not txtStart
dateConv.setHours 12
dateConv.setMinutes 0
else
arrInp = txtStart.split ':'
# There's only one string entered: hour
if arrInp.length is 1
txtHr = txtStart
dateConv.setMinutes 0
else
txtHr = arrInp[ 0 ]
intMin = parseInt( arrInp[ 1 ] ) || 0
m = Math.max 0, Math.min intMin, 59
dateConv.setMinutes m
intHour = parseInt( txtHr ) || 12
h = Math.max 0, Math.min intHour, 24
dateConv.setHours h
dateConv.setSeconds 0
dateConv.setMilliseconds 0
if dateConv < new Date()
dateConv.setDate dateConv.getDate() + 17
dateConv
# Convert a day hour string ( h:m ) to minutes
fConvertDayHourToMinutes = ( strDayHour ) ->
# Parse a time string
fParseTime = ( str, hasDay ) ->
arrTime = str.split ':'
# If there's only one entry, this is the amount of minutes
if hasDay
def = 0
else
def = 10
if arrTime.length is 1
time = parseInt( str ) || def
if hasDay
time * 60
else
time
else
h = parseInt( arrTime[ 0 ] ) || 0
if h > 0
def = 0
h * 60 + ( parseInt( arrTime[ 1 ] ) || def )
if not strDayHour
mins = 10
else
arrInp = strDayHour.split ' '
# There's only one string entered, either day or hour
if arrInp.length is 1
mins = fParseTime strDayHour
else
d = parseInt( arrInp[ 0 ] ) || 0
mins = d * 24 * 60 + fParseTime arrInp[ 1 ], true
# We have to limit this to 24 days because setTimeout only takes integer values
# until we implement a scheduler that deals with larger intervals
mins = Math.min mins, 35700
Math.max 1, mins
#
# EVENT Related Helper Functions
#
# fPlaceAndPaintInterval = () ->
# $( '#event_start' ).html 'Start Time:
# <input id="input_start" type="text" />
# <b>"hh:mm"</b>, default = 12:00'
# $( '#event_interval' ).html 'Interval:
# <input id="input_interval" type="text" />
# <b>"days hours:minutes"</b>, default = 10 minutes'
# Prepare the event section when a different event type is selected
fPrepareEventType = ( eventtype ) ->
$( '#select_event_type' ).val eventtype
$( '#event_parameters *' ).remove()
switch eventtype
# The user wants to react to custom event
when 'Custom Event'
inpEvt = $( '<input>' ).attr( 'type', 'text' )
.attr( 'style', 'font-size:1em' ).attr 'id', 'input_eventname'
$( '#event_parameters' ).append $( '<h4>' ).text( 'Event Name : ' ).append inpEvt
# The user wants a webhook as event producer
when 'Webhook'
fIssueRequest
body: command: 'get_all_webhooks'
done: ( data ) ->
try
oHooks = JSON.parse data.message
selHook = $( '<select>' ).attr( 'type', 'text' )
.attr( 'style', 'font-size:1em' ).attr 'id', 'select_eventhook'
i = 0
for hookid, hookname of oHooks
i++
selHook.append $( '<option>' ).text hookname
if i > 0
$( '#event_parameters' ).append $( '<h4>' ).text( 'Webhook Name : ' ).append selHook
else
fDisplayError 'No webhooks found! Choose another Event Type or create a Webhook.'
$( '#select_event_type' ).val ''
catch err
fDisplayError 'Badly formed webhooks!'
fail: fFailedRequest 'Unable to get webhooks!'
when 'Event Poller'
selPoller = $( '<select>' ).attr( 'type', 'text' )
.attr( 'style', 'font-size:1em' ).attr 'id', 'select_eventpoller'
$( '#event_parameters' ).append $( '<h4>' ).text( 'Event Poller Name : ' ).append selPoller
fIssueRequest
body: command: 'get_event_pollers'
done: ( data ) ->
try
oEps = JSON.parse data.message
fAppendEvents = ( id, events ) ->
fAppendEvent = ( evt ) ->
$( '#select_eventpoller' ).append $( '<option>' ).text id + ' -> ' + evt
fAppendEvent evt for evt in events
fAppendEvents id, events for id, events of oEps
fFetchEventParams $( '#select_eventpoller option:selected' ).text()
catch err
console.error 'ERROR: non-object received for event poller from server: ' + data.message
fail: fFailedRequest 'Error fetching Event Poller'
$( '#select_eventpoller' ).change () ->
evtFunc = $( this ).val()
if evtFunc is ''
$( '#event_start' ).html ''
$( '#event_interval' ).html ''
else
fPlaceAndPaintInterval()
$( '#input_event' ).val evtFunc
fFetchEventParams evtFunc
# Fetch the required Event Poller parameters
fFetchEventParams = ( name ) ->
console.log 'fetching event params'
console.log name
$( '#event_poller_params *' ).remove()
if name
arr = name.split ' -> '
fIssueRequest
body:
command: 'get_event_poller_params'
body: JSON.stringify
id: arr[ 0 ]
done: fAddEventParams arr[ 0 ]
fail: fFailedRequest 'Error fetching Event Poller params'
fFetchEventFunctionArgs arr
fAddEventParams = ( id ) ->
( data ) ->
if data.message
oParams = JSON.parse data.message
table = $ '<table>'
i = 0
fAppendParam = ( name, shielded ) ->
i++
tr = $( '<tr>' )
tr.append $( '<td>' ).css 'width', '20px'
tr.append $( '<td>' ).attr( 'class', 'key' ).text name
inp = $( '<input>' )
if shielded
inp.attr( 'type', 'password' )
tr.append $( '<td>' ).text( ' : ' ).append inp
table.append tr
fAppendParam name, shielded for name, shielded of oParams
if i > 0
$( '#event_poller_params' ).html '<b>Required Global Parameters:</b>'
$( '#event_poller_params' ).append table
fDelayed = () ->
fFillEventParams id
setTimeout fDelayed, 200
fFillEventParams = ( moduleId ) ->
obj =
command: 'get_event_poller_user_params'
body: JSON.stringify
id: moduleId
fIssueRequest
body: obj
done: ( data ) ->
oParams = JSON.parse data.message
for param, oParam of oParams
par = $( "#event_poller_params tr" ).filter () ->
$( 'td.key', this ).text() is param
$( 'input', par ).val oParam.value
$( 'input', par ).attr 'unchanged', 'true'
$( 'input', par ).change () ->
$( this ).attr 'unchanged', 'false'
obj.command = 'get_event_poller_user_arguments'
obj.body = JSON.stringify
ruleId: $( '#input_id' ).val()
moduleId: moduleId
fIssueRequest
body: obj
done: fAddEventUserArgs moduleId # FIXME this is wrong here
# Fetch function arguments required for an event polling function
fFetchEventFunctionArgs = ( arrName ) ->
# FIXME this data gets not populated sometimes!
fIssueRequest
body:
command: 'get_event_poller_function_arguments'
body: JSON.stringify
id: arrName[ 0 ]
done: ( data ) ->
if data.message
oParams = JSON.parse data.message
if oParams[ arrName[ 1 ] ]
if oParams[ arrName[ 1 ] ].length > 0
$( '#event_poller_params' ).append $( "<b>" ).text 'Required Function Parameters:'
table = $( '<table>' ).appendTo $( '#event_poller_params' )
for functionArgument in oParams[ arrName[ 1 ] ]
tr = $( '<tr>' ).attr( 'class', 'funcMappings' ).appendTo table
tr.append $( '<td>' ).css 'width', '20px'
td = $( '<td>' ).appendTo tr
td.append $( '<div>' ).attr( 'class', 'funcarg' ).text functionArgument
tr.append td
tr.append $( '<td>' ).text ' : '
td = $( '<td>' ).appendTo tr
td.append $( '<input>' ).attr 'type', 'text'
tr.append td
fail: fFailedRequest 'Error fetching action invoker function params'
fAddEventUserArgs = ( name ) ->
( data ) ->
for key, arrFuncs of data.message
par = $ "#event_poller_params"
for oFunc in JSON.parse arrFuncs
tr = $( "tr", par ).filter () ->
$( '.funcarg', this ).text() is "#{ oFunc.argument }"
$( "input[type=text]", tr ).val oFunc.value
# $( "input[type=checkbox]", tr ).prop 'checked', oFunc.jsselector
#
# ACTION Related Helper Functions
#
fAddSelectedAction = ( name ) ->
arrName = name.split ' -> '
arrEls = $( "#action_params div.modName" ).map( () ->
$( this ).text()
).get()
table = $( '#selected_actions' )
tr = $( '<tr>' ).appendTo table
img = $( '<img>' ).attr 'src', 'red_cross_small.png'
tr.append $( '<td>' ).css( 'width', '20px' ).append img
tr.append $( '<td>' ).attr( 'class', 'title').text name
td = $( '<td>' ).attr( 'class', 'funcMappings').appendTo tr
fFetchActionFunctionArgs td, arrName
if arrName[ 0 ] not in arrEls
div = $( '<div>' ).appendTo $( '#action_params' )
subdiv = $( '<div> ').appendTo div
subdiv.append $( '<div>' )
.attr( 'class', 'modName underlined' ).text arrName[ 0 ]
fFetchActionParams div, arrName[ 0 ]
$( "#select_actions option" ).each () ->
if $( this ).text() is name
$( this ).remove()
fDelayed = () ->
fFillActionFunction arrName[ 0 ]
setTimeout fDelayed, 300
fFetchActionParams = ( div, modName ) ->
obj =
command: 'get_action_invoker_params'
body: JSON.stringify
id: modName
fIssueRequest
body: obj
done: ( data ) ->
if data.message
oParams = JSON.parse data.message
table = $ '<table>'
div.append table
fAppendActionParam = ( name, shielded ) ->
tr = $( '<tr>' )
tr.append $( '<td>' ).css 'width', '20px'
tr.append $( '<td>' ).attr( 'class', 'key').text name
inp = $( '<input>' )
if shielded
inp.attr( 'type', 'password' )
else
inp.attr( 'type', 'text' )
tr.append $( '<td>' ).text(' : ').append inp
table.append tr
fAppendActionParam name, sh for name, sh of oParams
fail: fFailedRequest 'Error fetching action invoker params'
fFetchActionFunctionArgs = ( tag, arrName ) ->
fIssueRequest
body:
command: 'get_action_invoker_function_arguments'
body: JSON.stringify
id: arrName[ 0 ]
done: ( data ) ->
if data.message
oParams = JSON.parse data.message
if oParams[ arrName[ 1 ] ]
table = $( '<table>' ).appendTo tag
for functionArgument in oParams[ arrName[ 1 ] ]
tr = $( '<tr>' ).appendTo table
td = $( '<td>' ).appendTo tr
td.append $( '<div>' ).attr( 'class', 'funcarg' ).text functionArgument
tr.append td
td = $( '<td>' ).appendTo tr
td.append $( '<input>' ).attr 'type', 'text'
tr.append td
fail: fFailedRequest 'Error fetching action invoker function params'
fFillActionFunction = ( name ) ->
fIssueRequest
body:
command: 'get_action_invoker_user_params'
body: JSON.stringify
id: name
done: fAddActionUserParams name
fIssueRequest
body:
command: 'get_action_invoker_user_arguments'
body: JSON.stringify
ruleId: $( '#input_id' ).val()
moduleId: name
done: fAddActionUserArgs name
fAddActionUserParams = ( name ) ->
( data ) ->
oParams = JSON.parse data.message
domMod = $( "#action_params div" ).filter () ->
$( 'div.modName', this ).text() is name
for param, oParam of oParams
par = $( "tr", domMod ).filter () ->
$( 'td.key', this ).text() is param
$( 'input', par ).val oParam.value
$( 'input', par ).attr 'unchanged', 'true'
$( 'input', par ).change () ->
$( this ).attr 'unchanged', 'false'
fAddActionUserArgs = ( name ) ->
( data ) ->
for key, arrFuncs of data.message
par = $( "#selected_actions tr" ).filter () ->
$( 'td.title', this ).text() is "#{ name } -> #{ key }"
for oFunc in JSON.parse arrFuncs
tr = $( "tr", par ).filter () ->
$( '.funcarg', this ).text() is "#{ oFunc.argument }"
$( "input[type=text]", tr ).val oFunc.value
# $( "input[type=checkbox]", tr ).prop 'checked', oFunc.jsselector
# ONLOAD
# ------
#
# When the document has loaded we really start to execute some logic
fOnLoad = () ->
# Fetch the public key from the engine
@ -58,83 +428,31 @@ fOnLoad = () ->
$( '#input_id' ).focus()
# EVENT
# If the user is coming from an event he wants a rule to be setup for him
switch oParams.eventtype
when 'custom'
$( '#input_id' ).val "My '#{ oParams.eventname }' Rule"
$( '#select_event_type' ).val 'Custom Event'
inpEvt = $( '<input>' ).attr( 'type', 'text' )
.attr( 'style', 'font-size:1em' ).attr 'id', 'input_eventname'
inpEvt.val oParams.eventname
$( '#event_parameters' ).append $( '<h4>' ).text( 'Event Name : ' ).append inpEvt
inpEvt.focus()
editor.setValue "[\n\n]"
when 'webhook'
console.log 'webhook'
when 'poller'
console.log 'poller'
# -----
# Event type is changed, changes the whole event section
$( '#select_event_type' ).change () ->
$( '#event_parameters *' ).remove()
switch $( this ).val()
fPrepareEventType $( this ).val()
# The user wants to act on a custom event
when 'Custom Event'
inpEvt = $( '<input>' ).attr( 'type', 'text' )
.attr( 'style', 'font-size:1em' ).attr 'id', 'input_eventname'
$( '#event_parameters' ).append $( '<h4>' ).text( 'Event Name : ' ).append inpEvt
# If the user is coming from an event UI he wants a rule to be setup for him
switch oParams.eventtype
when 'custom'
$( '#input_id' ).val "My '#{ oParams.eventname }' Rule"
fPrepareEventType 'Custom Event'
$( '#input_eventname' ).val oParams.eventname
$( '#input_eventname' ).focus()
editor.setValue "[\n\n]" # For now we don't prepare conditions
# The user wants a webhook as event producer
when 'Webhook'
fIssueRequest
body: command: 'get_webhooks'
done: ( data ) ->
try
arrHooks = JSON.parse data.message
if arrHooks.length is 0
fDisplayError 'No webhooks found! Choose another Event Type or create a Webhook.'
$( '#select_event_type' ).val ''
else
selHook = $( '<select>' ).attr 'id', 'input_eventname'
for hook in arrHooks
selHook.append $( '<option>' ).text hook
$( '#event_parameters' ).append selHook
catch err
fDisplayError 'Badly formed webhooks!'
fail: fFailedRequest 'Unable to get webhooks!'
when 'webhook'
$( '#input_id' ).val "My '#{ oParams.hookname }' Rule"
fPrepareEventType 'Webhook'
$( 'select_eventhook' ).val oParams.hookname
when 'Event Poller'
fIssueRequest
body: command: 'get_event_pollers'
done: ( data ) ->
try
oEps = JSON.parse data.message
fAppendEvents = ( id, events ) ->
fAppendEvent = ( evt ) ->
$( '#select_event' ).append $( '<option>' ).text id + ' -> ' + evt
fAppendEvent evt for evt in events
fAppendEvents id, events for id, events of oEps
$( '#input_event' ).val $( '#select_event' ).val()
fFetchEventParams $( '#select_event option:selected' ).text()
catch err
console.error 'ERROR: non-object received from server: ' + data.message
fail: fFailedRequest 'Error fetching Event Poller'
$( '#select_event' ).change () ->
evtFunc = $( this ).val()
if evtFunc is ''
$( '#event_start' ).html ''
$( '#event_interval' ).html ''
else
fPlaceAndPaintInterval()
$( '#input_event' ).val evtFunc
fFetchEventParams evtFunc
when 'poller'
$( '#input_id' ).val "My '#{ oParams.eventpoller }' Rule"
fPrepareEventType 'Event Poller'
$( '#input_event' ).change () ->
$( '#select_event' ).val ''
@ -146,107 +464,9 @@ fOnLoad = () ->
else
fPlaceAndPaintInterval()
fFetchEventParams = ( name ) ->
$( '#event_poller_params *' ).remove()
if name
arr = name.split ' -> '
fIssueRequest
body:
command: 'get_event_poller_params'
body: JSON.stringify
id: arr[ 0 ]
done: fAddEventParams arr[ 0 ]
fail: fFailedRequest 'Error fetching Event Poller params'
fFetchEventFunctionArgs arr
fFetchEventFunctionArgs = ( arrName ) ->
# FIXME this data gets not populated sometimes!
fIssueRequest
body:
command: 'get_event_poller_function_arguments'
body: JSON.stringify
id: arrName[ 0 ]
$.post( '/usercommand', obj )
.done ( data ) ->
if data.message
oParams = JSON.parse data.message
if oParams[ arrName[ 1 ] ]
if oParams[ arrName[ 1 ] ].length > 0
$( '#event_poller_params' ).append $( "<b>" ).text 'Required Function Parameters:'
table = $( '<table>' ).appendTo $( '#event_poller_params' )
for functionArgument in oParams[ arrName[ 1 ] ]
tr = $( '<tr>' ).attr( 'class', 'funcMappings' ).appendTo table
tr.append $( '<td>' ).css 'width', '20px'
td = $( '<td>' ).appendTo tr
td.append $( '<div>' ).attr( 'class', 'funcarg' ).text functionArgument
tr.append td
tr.append $( '<td>' ).text ' : '
td = $( '<td>' ).appendTo tr
td.append $( '<input>' ).attr 'type', 'text'
tr.append td
.fail fFailedRequest 'Error fetching action invoker function params'
fAddEventParams = ( id ) ->
( data ) ->
if data.message
oParams = JSON.parse data.message
table = $ '<table>'
i = 0
fAppendParam = ( name, shielded ) ->
i++
tr = $( '<tr>' )
tr.append $( '<td>' ).css 'width', '20px'
tr.append $( '<td>' ).attr( 'class', 'key' ).text name
inp = $( '<input>' )
if shielded
inp.attr( 'type', 'password' )
tr.append $( '<td>' ).text( ' : ' ).append inp
table.append tr
fAppendParam name, shielded for name, shielded of oParams
if i > 0
$( '#event_poller_params' ).html '<b>Required Global Parameters:</b>'
$( '#event_poller_params' ).append table
fDelayed = () ->
fFillEventParams id
setTimeout fDelayed, 200
fFillEventParams = ( moduleId ) ->
obj =
command: 'get_event_poller_user_params'
body: JSON.stringify
id: moduleId
$.post( '/usercommand', obj )
.done ( data ) ->
oParams = JSON.parse data.message
for param, oParam of oParams
par = $( "#event_poller_params tr" ).filter () ->
$( 'td.key', this ).text() is param
$( 'input', par ).val oParam.value
$( 'input', par ).attr 'unchanged', 'true'
$( 'input', par ).change () ->
$( this ).attr 'unchanged', 'false'
obj.command = 'get_event_poller_user_arguments'
obj.body = JSON.stringify
ruleId: $( '#input_id' ).val()
moduleId: moduleId
$.post( '/usercommand', obj )
.done fAddEventUserArgs moduleId
fAddEventUserArgs = ( name ) ->
( data ) ->
for key, arrFuncs of data.message
par = $ "#event_poller_params"
for oFunc in JSON.parse arrFuncs
tr = $( "tr", par ).filter () ->
$( '.funcarg', this ).text() is "#{ oFunc.argument }"
$( "input[type=text]", tr ).val oFunc.value
# $( "input[type=checkbox]", tr ).prop 'checked', oFunc.jsselector
# ACTIONS
# <b>Selected Actions:</b>
# <table id="selected_actions"></table>
# <br><br>
@ -255,11 +475,10 @@ fOnLoad = () ->
# <div id="action_params"></div>
# <br><br>
obj =
command: 'get_action_invokers'
$.post( '/usercommand', obj )
.done ( data ) ->
fIssueRequest
body:
command: 'get_action_invokers'
done: ( data ) ->
try
oAis = JSON.parse data.message
catch err
@ -273,120 +492,8 @@ fOnLoad = () ->
if arrEls.length is 0
$( '#select_actions' ).append $( '<option>' ).text module + ' -> ' + act
fAppendActions module, actions for module, actions of oAis
.fail fFailedRequest 'Error fetching Event Poller'
fail: fFailedRequest 'Error fetching Event Poller'
fAddSelectedAction = ( name ) ->
arrName = name.split ' -> '
arrEls = $( "#action_params div.modName" ).map( () ->
$( this ).text()
).get()
table = $( '#selected_actions' )
tr = $( '<tr>' ).appendTo table
img = $( '<img>' ).attr 'src', 'red_cross_small.png'
tr.append $( '<td>' ).css( 'width', '20px' ).append img
tr.append $( '<td>' ).attr( 'class', 'title').text name
td = $( '<td>' ).attr( 'class', 'funcMappings').appendTo tr
fFetchActionFunctionArgs td, arrName
if arrName[ 0 ] not in arrEls
div = $( '<div>' ).appendTo $( '#action_params' )
subdiv = $( '<div> ').appendTo div
subdiv.append $( '<div>' )
.attr( 'class', 'modName underlined' ).text arrName[ 0 ]
fFetchActionParams div, arrName[ 0 ]
$( "#select_actions option" ).each () ->
if $( this ).text() is name
$( this ).remove()
fDelayed = () ->
fFillActionFunction arrName[ 0 ]
setTimeout fDelayed, 300
fFetchActionParams = ( div, modName ) ->
obj =
command: 'get_action_invoker_params'
body: JSON.stringify
id: modName
$.post( '/usercommand', obj )
.done ( data ) ->
if data.message
oParams = JSON.parse data.message
table = $ '<table>'
div.append table
fAppendActionParam = ( name, shielded ) ->
tr = $( '<tr>' )
tr.append $( '<td>' ).css 'width', '20px'
tr.append $( '<td>' ).attr( 'class', 'key').text name
inp = $( '<input>' )
if shielded
inp.attr( 'type', 'password' )
else
inp.attr( 'type', 'text' )
tr.append $( '<td>' ).text(' : ').append inp
table.append tr
fAppendActionParam name, sh for name, sh of oParams
.fail fFailedRequest 'Error fetching action invoker params'
fFetchActionFunctionArgs = ( tag, arrName ) ->
obj =
command: 'get_action_invoker_function_arguments'
body: JSON.stringify
id: arrName[ 0 ]
$.post( '/usercommand', obj )
.done ( data ) ->
if data.message
oParams = JSON.parse data.message
if oParams[ arrName[ 1 ] ]
table = $( '<table>' ).appendTo tag
for functionArgument in oParams[ arrName[ 1 ] ]
tr = $( '<tr>' ).appendTo table
td = $( '<td>' ).appendTo tr
td.append $( '<div>' ).attr( 'class', 'funcarg' ).text functionArgument
tr.append td
td = $( '<td>' ).appendTo tr
td.append $( '<input>' ).attr 'type', 'text'
tr.append td
# td = $( '<td>' ).appendTo tr
# td.append $( '<input>' ).attr( 'type', 'checkbox' )
# .attr 'title', 'js-select expression to be resolved on event?'
.fail fFailedRequest 'Error fetching action invoker function params'
fFillActionFunction = ( name ) ->
obj =
command: 'get_action_invoker_user_params'
body: JSON.stringify
id: name
$.post( '/usercommand', obj )
.done fAddActionUserParams name
obj.command = 'get_action_invoker_user_arguments'
obj.body = JSON.stringify
ruleId: $( '#input_id' ).val()
moduleId: name
$.post( '/usercommand', obj )
.done fAddActionUserArgs name
fAddActionUserParams = ( name ) ->
( data ) ->
oParams = JSON.parse data.message
domMod = $( "#action_params div" ).filter () ->
$( 'div.modName', this ).text() is name
for param, oParam of oParams
par = $( "tr", domMod ).filter () ->
$( 'td.key', this ).text() is param
$( 'input', par ).val oParam.value
$( 'input', par ).attr 'unchanged', 'true'
$( 'input', par ).change () ->
$( this ).attr 'unchanged', 'false'
fAddActionUserArgs = ( name ) ->
( data ) ->
for key, arrFuncs of data.message
par = $( "#selected_actions tr" ).filter () ->
$( 'td.title', this ).text() is "#{ name } -> #{ key }"
for oFunc in JSON.parse arrFuncs
tr = $( "tr", par ).filter () ->
$( '.funcarg', this ).text() is "#{ oFunc.argument }"
$( "input[type=text]", tr ).val oFunc.value
# $( "input[type=checkbox]", tr ).prop 'checked', oFunc.jsselector
$( '#select_actions' ).on 'change', () ->
opt = $ 'option:selected', this
@ -422,33 +529,45 @@ fOnLoad = () ->
$( '#input_id' ).focus()
throw new Error 'Please enter a rule name!'
eventId = $( '#input_event' ).val()
if eventId is ''
$( '#input_event' ).focus()
throw new Error 'Please assign an event!'
eventtype = $( '#select_event_type' ).val()
switch eventtype
when ''
$( '#select_event_type' ).focus()
throw new Error 'Please choose an event type!'
ep = {}
$( "#event_poller_params tr" ).each () ->
key = $( this ).children( '.key' ).text()
val = $( 'input', this ).val()
if val is ''
$( 'input', this ).focus()
throw new Error "Please enter a value for '#{ key }' in the event module!"
shielded = $( 'input', this ).attr( 'type' ) is 'password'
ep[ key ] =
shielded: shielded
if not shielded or $( 'input', this ).attr( 'unchanged' ) isnt 'true'
encryptedParam = cryptico.encrypt val, strPublicKey
ep[ key ].value = encryptedParam.cipher
else
ep[ key ].value = val
when 'Custom Event'
el = $( '#input_eventname' )
if el.val() is ''
el.focus()
throw new Error 'Please assign an Event Name!'
eventname = el.val()
evtFuncs = {}
evtFuncs[ eventId ] = []
$( '#event_poller_params tr.funcMappings' ).each () ->
evtFuncs[ eventId ].push
argument: $( 'div.funcarg', this ).text()
value: $( 'input[type=text]', this ).val()
when 'Webhook'
eventname = $( '#select_eventhook' ).val()
when 'Event Poller'
ep = {}
$( "#event_poller_params tr" ).each () ->
key = $( this ).children( '.key' ).text()
val = $( 'input', this ).val()
if val is ''
$( 'input', this ).focus()
throw new Error "Please enter a value for '#{ key }' in the event module!"
shielded = $( 'input', this ).attr( 'type' ) is 'password'
ep[ key ] =
shielded: shielded
if not shielded or $( 'input', this ).attr( 'unchanged' ) isnt 'true'
encryptedParam = cryptico.encrypt val, strPublicKey
ep[ key ].value = encryptedParam.cipher
else
ep[ key ].value = val
evtFuncs = {}
evtFuncs[ eventId ] = []
$( '#event_poller_params tr.funcMappings' ).each () ->
evtFuncs[ eventId ].push
argument: $( 'div.funcarg', this ).text()
value: $( 'input[type=text]', this ).val()
if $( '#selected_actions tr' ).length is 0
throw new Error 'Please select at least one action or create one!'
@ -503,68 +622,6 @@ fOnLoad = () ->
throw new Error "Conditions Invalid! Needs to be an Array of Strings!"
txtStart = $( '#input_start' ).val()
start = new Date()
if not txtStart
start.setHours 12
start.setMinutes 0
else
arrInp = txtStart.split ':'
# There's only one string entered: hour
if arrInp.length is 1
txtHr = txtStart
start.setMinutes 0
else
txtHr = arrInp[ 0 ]
intMin = parseInt( arrInp[ 1 ] ) || 0
m = Math.max 0, Math.min intMin, 59
start.setMinutes m
intHour = parseInt( txtHr ) || 12
h = Math.max 0, Math.min intHour, 24
start.setHours h
start.setSeconds 0
start.setMilliseconds 0
if start < new Date()
start.setDate start.getDate() + 1
# Parse a time string
fParseTime = ( str, hasDay ) ->
arrTime = str.split ':'
# If there's only one entry, this is the amount of minutes
if hasDay
def = 0
else
def = 10
if arrTime.length is 1
time = parseInt( str ) || def
if hasDay
time * 60
else
time
else
h = parseInt( arrTime[ 0 ] ) || 0
if h > 0
def = 0
h * 60 + ( parseInt( arrTime[ 1 ] ) || def )
txtInterval = $( '#input_interval' ).val()
if not txtInterval
mins = 10
else
arrInp = txtInterval.split ' '
# There's only one string entered, either day or hour
if arrInp.length is 1
mins = fParseTime txtInterval
else
d = parseInt( arrInp[ 0 ] ) || 0
mins = d * 24 * 60 + fParseTime arrInp[ 1 ], true
# We have to limit this to 24 days because setTimeout only takes integer values
# until we implement a scheduler that deals with larger intervals
mins = Math.min mins, 35700
mins = Math.max 1, mins
fCheckOverwrite = ( obj ) ->
( err ) ->
if err.status is 409
@ -572,13 +629,17 @@ fOnLoad = () ->
payl = JSON.parse obj.body
payl.overwrite = true
obj.body = JSON.stringify payl
$.post( '/usercommand', obj )
.done ( data ) ->
fIssueRequest
body: obj
done: ( data ) ->
$( '#info' ).text data.message
$( '#info' ).attr 'class', 'success'
.fail fFailedRequest "#{ obj.id } not stored!"
fail: fFailedRequest "#{ obj.id } not stored!"
else
fFailedRequest( "#{ obj.id } not stored!" ) err
start = fConvertTimeToDate
mins = fConvertDayHourToMinutes
if $( '#select_event' ).val() is ''
start = null
mins = null
@ -597,25 +658,28 @@ fOnLoad = () ->
actions: acts
actionparams: ap
actionfunctions: actFuncs
$.post( '/usercommand', obj )
.done ( data ) ->
console.log obj
fIssueRequest
body: obj
done: ( data ) ->
$( '#info' ).text data.message
$( '#info' ).attr 'class', 'success'
.fail fCheckOverwrite obj
fail: fCheckOverwrite obj
catch err
console.log err
$( '#info' ).text 'Error in upload: ' + err.message
$( '#info' ).attr 'class', 'error'
alert err.message
throw err
# Edit a Rule
# -----------
if oParams.id
obj =
command: 'get_rule'
body: JSON.stringify
id: oParams.id
$.post( '/usercommand', obj )
.done ( data ) ->
fIssueRequest
body: obj
done: ( data ) ->
oRule = JSON.parse data.message
if oRule
$( '#input_id' ).val oRule.id
@ -642,7 +706,7 @@ fOnLoad = () ->
arrName = action.split ' -> '
fAddSelectedAction action
.fail ( err ) ->
fail: ( err ) ->
if err.responseText is ''
msg = 'No Response from Server!'
else

View file

@ -41,19 +41,20 @@ fUpdateWebhookList = () ->
fProcessWebhookList = ( data ) ->
$( '#table_webhooks tr' ).remove()
oHooks = JSON.parse data.message
console.log hostUrl
for hookid, hookname of oHooks
tr = $( '<tr>' )
tdName = $( '<div>' ).text hookname
tdUrl = $( '<input>' ).attr( 'style', 'width:600px' ).val "#{ hostUrl }/webhooks/#{ hookid }"
img = $( '<img>' ).attr( 'class', 'del' )
.attr( 'title', 'Delete Module' ).attr 'src', 'red_cross_small.png'
tr.append( $( '<td>' ).append img )
tr.append( $( '<td>' ).attr( 'style', 'padding-left:10px' ).append tdName )
tr.append( $( '<td>' ).attr( 'style', 'padding-left:10px' ).append tdUrl )
$( '#table_webhooks' ).append tr
$( '#table_webhooks *' ).remove()
if data.message
oHooks = JSON.parse data.message
$( '#table_webhooks' ).append $( '<h3>' ).text 'Your existing Webhooks:'
for hookid, hookname of oHooks
tr = $( '<tr>' )
tdName = $( '<div>' ).text hookname
tdUrl = $( '<input>' ).attr( 'style', 'width:600px' ).val "#{ hostUrl }/webhooks/#{ hookid }"
img = $( '<img>' ).attr( 'class', 'del' )
.attr( 'title', 'Delete Module' ).attr 'src', 'red_cross_small.png'
tr.append( $( '<td>' ).append img )
tr.append( $( '<td>' ).attr( 'style', 'padding-left:10px' ).append tdName )
tr.append( $( '<td>' ).attr( 'style', 'padding-left:10px' ).append tdUrl )
$( '#table_webhooks' ).append tr
fOnLoad = () ->
@ -71,7 +72,7 @@ fOnLoad = () ->
fDisplayError 'Please provide an Event Name for your new Webhook!'
else
$( '#display_hookurl *' ).remove()
# $( '#display_hookurl *' ).remove()
fIssueRequest
body:
command: 'create_webhook'
@ -79,8 +80,7 @@ fOnLoad = () ->
hookname: hookname
done: ( data ) ->
oAnsw = JSON.parse data.message
b = $( '<b>' ).text "This is the Webhook Url you will use for your Event : "
b = $( '<b>' ).text "This is the Webhook Url you can use for your Event '#{ oAnsw.hookname }' : "
$( '#display_hookurl' ).append b
$( '#display_hookurl' ).append $('<br>')
inp = $('<input>').attr( 'type', 'text' ).attr( 'style', 'width:600px' )
@ -96,11 +96,13 @@ fOnLoad = () ->
div.append $( '<div>' ).html "2. Then you should setup <a target=\"_blank\"
href=\"forge?page=forge_rule&eventtype=webhook&hookname=#{ hookname }\">a Rule for this Event!</a>"
$( '#display_hookurl' ).append div
fUpdateWebhookList()
fail: ( err ) ->
if err.status is 409
fFailedRequest( 'Webhook Event Name already existing!' ) err
else
fFailedRequest( 'Unable to create Webhook! ' + err.message ) err
fUpdateWebhookList()
$( '#table_webhooks' ).on 'click', 'img', () ->
if confirm "Do you really want to delete this webhook?"

File diff suppressed because it is too large Load diff

View file

@ -51,22 +51,24 @@
fProcessWebhookList = function(data) {
var hookid, hookname, img, oHooks, tdName, tdUrl, tr, _results;
$('#table_webhooks tr').remove();
oHooks = JSON.parse(data.message);
console.log(hostUrl);
_results = [];
for (hookid in oHooks) {
hookname = oHooks[hookid];
tr = $('<tr>');
tdName = $('<div>').text(hookname);
tdUrl = $('<input>').attr('style', 'width:600px').val("" + hostUrl + "/webhooks/" + hookid);
img = $('<img>').attr('class', 'del').attr('title', 'Delete Module').attr('src', 'red_cross_small.png');
tr.append($('<td>').append(img));
tr.append($('<td>').attr('style', 'padding-left:10px').append(tdName));
tr.append($('<td>').attr('style', 'padding-left:10px').append(tdUrl));
_results.push($('#table_webhooks').append(tr));
$('#table_webhooks *').remove();
if (data.message) {
oHooks = JSON.parse(data.message);
$('#table_webhooks').append($('<h3>').text('Your existing Webhooks:'));
_results = [];
for (hookid in oHooks) {
hookname = oHooks[hookid];
tr = $('<tr>');
tdName = $('<div>').text(hookname);
tdUrl = $('<input>').attr('style', 'width:600px').val("" + hostUrl + "/webhooks/" + hookid);
img = $('<img>').attr('class', 'del').attr('title', 'Delete Module').attr('src', 'red_cross_small.png');
tr.append($('<td>').append(img));
tr.append($('<td>').attr('style', 'padding-left:10px').append(tdName));
tr.append($('<td>').attr('style', 'padding-left:10px').append(tdUrl));
_results.push($('#table_webhooks').append(tr));
}
return _results;
}
return _results;
};
fOnLoad = function() {
@ -79,7 +81,6 @@
if (hookname === '') {
return fDisplayError('Please provide an Event Name for your new Webhook!');
} else {
$('#display_hookurl *').remove();
return fIssueRequest({
body: {
command: 'create_webhook',
@ -90,7 +91,7 @@
done: function(data) {
var b, div, inp, oAnsw;
oAnsw = JSON.parse(data.message);
b = $('<b>').text("This is the Webhook Url you will use for your Event : ");
b = $('<b>').text("This is the Webhook Url you can use for your Event '" + oAnsw.hookname + "' : ");
$('#display_hookurl').append(b);
$('#display_hookurl').append($('<br>'));
inp = $('<input>').attr('type', 'text').attr('style', 'width:600px').val("" + hostUrl + "/webhooks/" + oAnsw.hookid);
@ -101,14 +102,16 @@
div.append($('<div>').html("1. Try it out and push your location to your new webhook via <a target=\"_blank\" href=\"" + hostUrl + "/mobile.html?hookid=" + oAnsw.hookid + "\">this page</a>."));
div.append($('<br>'));
div.append($('<div>').html("2. Then you should setup <a target=\"_blank\" href=\"forge?page=forge_rule&eventtype=webhook&hookname=" + hookname + "\">a Rule for this Event!</a>"));
return $('#display_hookurl').append(div);
$('#display_hookurl').append(div);
return fUpdateWebhookList();
},
fail: function(err) {
if (err.status === 409) {
return fFailedRequest('Webhook Event Name already existing!')(err);
fFailedRequest('Webhook Event Name already existing!')(err);
} else {
return fFailedRequest('Unable to create Webhook! ' + err.message)(err);
fFailedRequest('Unable to create Webhook! ' + err.message)(err);
}
return fUpdateWebhookList();
}
});
}

View file

@ -19,6 +19,7 @@
{{{script}}}
</script>
{{{remote_scripts}}}
<script src="js/menubar.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>

View file

@ -1,7 +1,8 @@
<h2>Create your own Webhooks</h2>
<h3>Provide your desired Event Name :
<h3>Choose a name for the Events that are pushed to the new Webhook :
<input type="text" id="inp_hookname" style="font-size:1em;width:300px" /></h3>
<button type="button" id="but_submit">Create Webhook!</button>
<br><br>
<div id="display_hookurl" />
<div id="table_webhooks" />
<div id="display_hookurl"></div>
<br>
<div id="table_webhooks"></div>

View file

@ -1,44 +1 @@
<div id="menubar">
<script>
var menubar = $( '#menubar' );
var fRedirect = function( url ) {
return function() {
window.location.href = url;
}
};
var fCreateLink = function( text, fAction ) {
var link = $( '<div>' ).text( text );
link.click( fAction );
menubar.append(link);
};
fCreateLink( 'Push Event',
fRedirect( 'forge?page=forge_event' )
);
fCreateLink( 'Create Rule',
fRedirect( 'forge?page=forge_rule' )
);
fCreateLink( 'Create Webhooks',
fRedirect( 'forge?page=forge_webhook' )
);
fCreateLink( 'Edit Rules',
fRedirect( 'forge?page=edit_rules' )
);
fCreateLink( 'Create EP',
fRedirect( 'forge?page=forge_module&type=event_poller' )
);
fCreateLink( 'Create AI',
fRedirect( 'forge?page=forge_module&type=action_invoker' )
);
fCreateLink( 'Edit EPs & AIs',
fRedirect( 'forge?page=edit_modules' )
);
// fCreateLink( 'admin', fRedirect( 'admin' ) );
fCreateLink( 'Logout', function() {
$.post( '/logout' ).done( fRedirect( document.URL ) );
});
</script>
</div>
<table id="menubar"><tr></tr></table>

View file

@ -5,51 +5,12 @@
<link href='http://fonts.googleapis.com/css?family=Roboto:300' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Nunito' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="js/cryptico.js" type="text/javascript" charset="utf-8"></script>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>
<script src="js/menubar.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="menubar">
<script>
var menubar = $( '#menubar' );
var fRedirect = function( url ) {
return function() {
window.location.href = url;
}
};
var fCreateLink = function( text, fAction ) {
var link = $( '<div>' ).text( text );
link.click( fAction );
menubar.append(link);
};
fCreateLink( 'Push Event',
fRedirect( 'forge?page=forge_event' )
);
fCreateLink( 'Create Rule',
fRedirect( 'forge?page=forge_rule' )
);
fCreateLink( 'Create Webhooks',
fRedirect( 'forge?page=forge_webhook' )
);
fCreateLink( 'Edit Rules',
fRedirect( 'forge?page=edit_rules' )
);
fCreateLink( 'Create EP',
fRedirect( 'forge?page=forge_module&type=event_poller' )
);
fCreateLink( 'Create AI',
fRedirect( 'forge?page=forge_module&type=action_invoker' )
);
fCreateLink( 'Edit EPs & AIs',
fRedirect( 'forge?page=edit_modules' )
);
fCreateLink( 'Logout', function() {
$.post( '/logout' ).done( fRedirect( document.URL ) );
});
</script>
</div>
<table id="menubar"><tr></tr></table>
<div id="info"></div>
<div id="mainbody">

View file

@ -0,0 +1,41 @@
$( document ).ready(function() {
var menubar = $( '#menubar tr' );
var fRedirect = function( url ) {
return function() {
window.location.href = url;
}
};
var fCreateLink = function( text, fAction ) {
var link = $( '<td>' ).text( text );
link.click( fAction );
menubar.append(link);
};
fCreateLink( 'Push Event',
fRedirect( 'forge?page=forge_event' )
);
fCreateLink( 'Create Rule',
fRedirect( 'forge?page=forge_rule' )
);
fCreateLink( 'Create Webhooks',
fRedirect( 'forge?page=forge_webhook' )
);
fCreateLink( 'Edit Rules',
fRedirect( 'forge?page=edit_rules' )
);
fCreateLink( 'Create EP',
fRedirect( 'forge?page=forge_module&type=event_poller' )
);
fCreateLink( 'Create AI',
fRedirect( 'forge?page=forge_module&type=action_invoker' )
);
fCreateLink( 'Edit EPs & AIs',
fRedirect( 'forge?page=edit_modules' )
);
// fCreateLink( 'admin', fRedirect( 'admin' ) );
fCreateLink( 'Logout', function() {
$.post( '/logout' ).done( fRedirect( document.URL ) );
});
});

View file

@ -38,27 +38,25 @@ input[type=password]:focus {
#menubar {
/*font-size: 0.85em;*/
font-weight: bold;
padding: 2px 2px 4px 2px;
height: 1em;
padding: 0px;
width: 100%;
background-color: #DDD;
}
#menubar div {
height: 100%;
#menubar td {
float: left;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 2px;
margin: 0px 5px 0px 5px;
padding: 0px 10px 2px 10px;
cursor: pointer;
-moz-border-radius: 5px;
border-radius: 5px;
border-radius: 10px;
-webkit-transition: all 0.30s ease-in-out;
-moz-transition: all 0.30s ease-in-out;
-ms-transition: all 0.30s ease-in-out;
-o-transition: all 0.30s ease-in-out;
}
#menubar div:hover {
#menubar td:hover {
background-color: #AAA;
}