mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-16 22:10:31 +00:00
UI more user friendly, still needs completion
This commit is contained in:
parent
0b582244e3
commit
ca2f6e06ff
18 changed files with 1311 additions and 1147 deletions
|
|
@ -470,12 +470,13 @@ commandFunctions =
|
||||||
else
|
else
|
||||||
hookid
|
hookid
|
||||||
hookid = genHookID arrHooks
|
hookid = genHookID arrHooks
|
||||||
db.createWebhook user.username, oBody.hookname, hookid
|
db.createWebhook user.username, hookid, oBody.hookname
|
||||||
rh.activateWebhook hookid, oBody.hookname
|
rh.activateWebhook user.username, hookid, oBody.hookname
|
||||||
callback
|
callback
|
||||||
code: 200
|
code: 200
|
||||||
message: JSON.stringify
|
message: JSON.stringify
|
||||||
hookid: hookid
|
hookid: hookid
|
||||||
|
hookname: oBody.hookname
|
||||||
|
|
||||||
get_all_webhooks: ( user, oBody, callback ) ->
|
get_all_webhooks: ( user, oBody, callback ) ->
|
||||||
db.getAllUserWebhooks user.username, ( err, data ) ->
|
db.getAllUserWebhooks user.username, ( err, data ) ->
|
||||||
|
|
@ -484,9 +485,10 @@ commandFunctions =
|
||||||
code: 400
|
code: 400
|
||||||
message: "We didn't like your request!"
|
message: "We didn't like your request!"
|
||||||
else
|
else
|
||||||
|
data = JSON.stringify data || ''
|
||||||
callback
|
callback
|
||||||
code: 200
|
code: 200
|
||||||
message: JSON.stringify data
|
message: data
|
||||||
|
|
||||||
delete_webhook: ( user, oBody, callback ) ->
|
delete_webhook: ( user, oBody, callback ) ->
|
||||||
answ = hasRequiredParams [ 'hookid' ], oBody
|
answ = hasRequiredParams [ 'hookid' ], oBody
|
||||||
|
|
|
||||||
|
|
@ -272,9 +272,8 @@ processEvent = ( evt ) =>
|
||||||
else
|
else
|
||||||
fSearchAndInvokeAction node[arrPath[depth]], arrPath, funcName, evt, depth + 1
|
fSearchAndInvokeAction node[arrPath[depth]], arrPath, funcName, evt, depth + 1
|
||||||
|
|
||||||
@log.info 'EN | processing event: ' + evt.eventname
|
@log.info 'EN | Processing event: ' + evt.eventname
|
||||||
for userName, oUser of listUserRules
|
fCheckEventForUser = ( userName, oUser ) ->
|
||||||
|
|
||||||
for ruleName, oMyRule of oUser
|
for ruleName, oMyRule of oUser
|
||||||
|
|
||||||
ruleEvent = oMyRule.rule.eventname
|
ruleEvent = oMyRule.rule.eventname
|
||||||
|
|
@ -288,6 +287,14 @@ processEvent = ( evt ) =>
|
||||||
arr = action.split ' -> '
|
arr = action.split ' -> '
|
||||||
fSearchAndInvokeAction listUserRules, [ userName, ruleName, 'actions', arr[0]], arr[1], evt, 0
|
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 = () ->
|
exports.shutDown = () ->
|
||||||
isRunning = false
|
isRunning = false
|
||||||
listUserRules = {}
|
listUserRules = {}
|
||||||
|
|
|
||||||
|
|
@ -797,16 +797,16 @@ exports.removeUserRole = ( userId, role ) =>
|
||||||
###
|
###
|
||||||
Creates and stores a webhook.
|
Creates and stores a webhook.
|
||||||
|
|
||||||
@public createWebhook( *userId, hookname* )
|
@public createWebhook( *username, hookname* )
|
||||||
@param {String} userId
|
@param {String} username
|
||||||
@param {String} hookname
|
@param {String} hookname
|
||||||
###
|
###
|
||||||
exports.createWebhook = ( userId, hookname, hookid ) =>
|
exports.createWebhook = ( username, hookid, hookname ) =>
|
||||||
@db.sadd "webhooks", hookid, replyHandler "sadd 'webhooks' -> '#{ hookid }'"
|
@db.sadd "webhooks", hookid, replyHandler "sadd 'webhooks' -> '#{ hookid }'"
|
||||||
@db.sadd "user:#{ userId }:webhooks", hookid,
|
@db.sadd "user:#{ username }:webhooks", hookid,
|
||||||
replyHandler "sadd 'user:#{ userId }:webhooks' -> '#{ hookid }'"
|
replyHandler "sadd 'user:#{ username }:webhooks' -> '#{ hookid }'"
|
||||||
@db.set "webhook:#{ hookid }", hookname,
|
@db.hmset "webhook:#{ hookid }", 'hookname', hookname, 'username', username,
|
||||||
replyHandler "set webhook:#{ hookid } -> #{ hookname }"
|
replyHandler "set webhook:#{ hookid } -> [#{ hookname }, #{ username }]"
|
||||||
|
|
||||||
###
|
###
|
||||||
Returns a webhook name.
|
Returns a webhook name.
|
||||||
|
|
@ -815,25 +815,34 @@ Returns a webhook name.
|
||||||
@param {String} hookid
|
@param {String} hookid
|
||||||
###
|
###
|
||||||
exports.getWebhookName = ( hookid, cb ) =>
|
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.
|
Returns all the user's webhooks by ID.
|
||||||
|
|
||||||
@public getUserWebhookIDs( *userId* )
|
@public getUserWebhookIDs( *username* )
|
||||||
@param {String} userId
|
@param {String} username
|
||||||
###
|
###
|
||||||
exports.getUserWebhookIDs = ( userId, cb ) =>
|
exports.getUserWebhookIDs = ( username, cb ) =>
|
||||||
@db.smembers "user:#{ userId }:webhooks", cb
|
@db.smembers "user:#{ username }:webhooks", cb
|
||||||
|
|
||||||
###
|
###
|
||||||
Gets all the user's webhooks with names.
|
Gets all the user's webhooks with names.
|
||||||
|
|
||||||
@public getAllUserWebhooks( *userId* )
|
@public getAllUserWebhooks( *username* )
|
||||||
@param {String} userId
|
@param {String} username
|
||||||
###
|
###
|
||||||
exports.getAllUserWebhooks = ( userId, cb ) =>
|
exports.getAllUserWebhooks = ( username, cb ) =>
|
||||||
getSetRecords "user:#{ userId }:webhooks", exports.getWebhookName, cb
|
getSetRecords "user:#{ username }:webhooks", exports.getWebhookName, cb
|
||||||
|
|
||||||
###
|
###
|
||||||
Returns all webhook IDs.
|
Returns all webhook IDs.
|
||||||
|
|
@ -849,19 +858,19 @@ Returns all webhooks with names.
|
||||||
@public getAllWebhooks()
|
@public getAllWebhooks()
|
||||||
###
|
###
|
||||||
exports.getAllWebhooks = ( cb ) =>
|
exports.getAllWebhooks = ( cb ) =>
|
||||||
getSetRecords "webhooks", exports.getWebhookName, cb
|
getSetRecords "webhooks", exports.getFullWebhook, cb
|
||||||
|
|
||||||
###
|
###
|
||||||
Delete a webhook.
|
Delete a webhook.
|
||||||
|
|
||||||
@public deleteWebhook( *userId, hookid* )
|
@public deleteWebhook( *username, hookid* )
|
||||||
@param {String} userId
|
@param {String} username
|
||||||
@param {String} hookid
|
@param {String} hookid
|
||||||
###
|
###
|
||||||
exports.deleteWebhook = ( userId, hookid ) =>
|
exports.deleteWebhook = ( username, hookid ) =>
|
||||||
@db.srem "webhooks", hookid, replyHandler "srem 'webhooks' -> '#{ hookid }'"
|
@db.srem "webhooks", hookid, replyHandler "srem 'webhooks' -> '#{ hookid }'"
|
||||||
@db.srem "user:#{ userId }:webhooks", hookid,
|
@db.srem "user:#{ username }:webhooks", hookid,
|
||||||
replyHandler "srem 'user:#{ userId }:webhooks' -> '#{ hookid }'"
|
replyHandler "srem 'user:#{ username }:webhooks' -> '#{ hookid }'"
|
||||||
@db.del "webhook:#{ hookid }", replyHandler "del webhook:#{ hookid }"
|
@db.del "webhook:#{ hookid }", replyHandler "del webhook:#{ hookid }"
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
|
||||||
|
|
@ -354,7 +354,8 @@ exports.handleAdminCommand = ( req, resp ) =>
|
||||||
resp.send 401, 'You need to be logged in as admin!'
|
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'
|
if typeof body is 'string'
|
||||||
try
|
try
|
||||||
body = JSON.parse body
|
body = JSON.parse body
|
||||||
|
|
@ -367,8 +368,12 @@ indexEvent = ( eventname, body, resp ) ->
|
||||||
obj =
|
obj =
|
||||||
eventname: eventname
|
eventname: eventname
|
||||||
body: body
|
body: body
|
||||||
|
if username
|
||||||
|
obj.username = username
|
||||||
db.pushEvent obj
|
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
|
obj
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -381,7 +386,7 @@ exports.handleMeasurements = ( req, resp ) =>
|
||||||
body += data
|
body += data
|
||||||
|
|
||||||
req.on 'end', ->
|
req.on 'end', ->
|
||||||
obj = indexEvent name, body, resp
|
obj = parsePushAndAnswerEvent name, null, body, resp
|
||||||
if obj.eventname is 'uptimestatistics'
|
if obj.eventname is 'uptimestatistics'
|
||||||
# This is a hack to quickly allow storing of public accessible data
|
# This is a hack to quickly allow storing of public accessible data
|
||||||
fPath = path.resolve __dirname, '..', 'webpages', 'public', 'data', 'histochart.json'
|
fPath = path.resolve __dirname, '..', 'webpages', 'public', 'data', 'histochart.json'
|
||||||
|
|
@ -392,22 +397,24 @@ Handles webhook posts
|
||||||
###
|
###
|
||||||
exports.handleWebhooks = ( req, resp ) =>
|
exports.handleWebhooks = ( req, resp ) =>
|
||||||
hookid = req.url.substring( 10 ).split( '/' )[ 0 ]
|
hookid = req.url.substring( 10 ).split( '/' )[ 0 ]
|
||||||
hookname = @allowedHooks[ hookid ]
|
oHook = @allowedHooks[ hookid ]
|
||||||
if hookname
|
if oHook
|
||||||
body = ''
|
body = ''
|
||||||
req.on 'data', ( data ) ->
|
req.on 'data', ( data ) ->
|
||||||
body += data
|
body += data
|
||||||
req.on 'end', () ->
|
req.on 'end', () ->
|
||||||
obj = indexEvent hookname, body, resp
|
parsePushAndAnswerEvent oHook.hookname, oHook.username, body, resp
|
||||||
else
|
else
|
||||||
resp.send 404, "Webhook not existing!"
|
resp.send 404, "Webhook not existing!"
|
||||||
|
|
||||||
|
|
||||||
# Activate a webhook. the body will be JSON parsed, the name of the webhook will
|
# 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
|
# 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"
|
@log.info "HL | Webhook '#{ hookid }' activated"
|
||||||
@allowedHooks[ hookid ] = name
|
@allowedHooks[ hookid ] =
|
||||||
|
hookname: name
|
||||||
|
username: user
|
||||||
|
|
||||||
# Deactivate a webhook
|
# Deactivate a webhook
|
||||||
exports.deactivateWebhook = ( hookid ) =>
|
exports.deactivateWebhook = ( hookid ) =>
|
||||||
|
|
|
||||||
|
|
@ -592,12 +592,13 @@ Components Manager
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
hookid = genHookID(arrHooks);
|
hookid = genHookID(arrHooks);
|
||||||
db.createWebhook(user.username, oBody.hookname, hookid);
|
db.createWebhook(user.username, hookid, oBody.hookname);
|
||||||
rh.activateWebhook(hookid, oBody.hookname);
|
rh.activateWebhook(user.username, hookid, oBody.hookname);
|
||||||
return callback({
|
return callback({
|
||||||
code: 200,
|
code: 200,
|
||||||
message: JSON.stringify({
|
message: JSON.stringify({
|
||||||
hookid: hookid
|
hookid: hookid,
|
||||||
|
hookname: oBody.hookname
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -614,9 +615,10 @@ Components Manager
|
||||||
message: "We didn't like your request!"
|
message: "We didn't like your request!"
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
data = JSON.stringify(data || '');
|
||||||
return callback({
|
return callback({
|
||||||
code: 200,
|
code: 200,
|
||||||
message: JSON.stringify(data)
|
message: data
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
71
js/engine.js
71
js/engine.js
|
|
@ -298,7 +298,7 @@ Engine
|
||||||
|
|
||||||
processEvent = (function(_this) {
|
processEvent = (function(_this) {
|
||||||
return function(evt) {
|
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) {
|
fSearchAndInvokeAction = function(node, arrPath, funcName, evt, depth) {
|
||||||
var argument, arrArgs, arrSelectors, data, err, oArg, sel, selector, _i, _j, _len, _len1, _ref;
|
var argument, arrArgs, arrSelectors, data, err, oArg, sel, selector, _i, _j, _len, _len1, _ref;
|
||||||
if (!node) {
|
if (!node) {
|
||||||
|
|
@ -346,40 +346,45 @@ Engine
|
||||||
return fSearchAndInvokeAction(node[arrPath[depth]], arrPath, funcName, evt, depth + 1);
|
return fSearchAndInvokeAction(node[arrPath[depth]], arrPath, funcName, evt, depth + 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_this.log.info('EN | processing event: ' + evt.eventname);
|
_this.log.info('EN | Processing event: ' + evt.eventname);
|
||||||
_results = [];
|
fCheckEventForUser = function(userName, oUser) {
|
||||||
for (userName in listUserRules) {
|
var action, arr, oMyRule, ruleEvent, ruleName, _results;
|
||||||
oUser = listUserRules[userName];
|
_results = [];
|
||||||
_results.push((function() {
|
for (ruleName in oUser) {
|
||||||
var _results1;
|
oMyRule = oUser[ruleName];
|
||||||
_results1 = [];
|
ruleEvent = oMyRule.rule.eventname;
|
||||||
for (ruleName in oUser) {
|
if (oMyRule.rule.timestamp) {
|
||||||
oMyRule = oUser[ruleName];
|
ruleEvent += '_created:' + oMyRule.rule.timestamp;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return _results1;
|
if (evt.eventname === ruleEvent && validConditions(evt, oMyRule.rule, userName, ruleName)) {
|
||||||
}).call(_this));
|
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);
|
})(this);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1038,16 +1038,16 @@ Persistence
|
||||||
/*
|
/*
|
||||||
Creates and stores a webhook.
|
Creates and stores a webhook.
|
||||||
|
|
||||||
@public createWebhook( *userId, hookname* )
|
@public createWebhook( *username, hookname* )
|
||||||
@param {String} userId
|
@param {String} username
|
||||||
@param {String} hookname
|
@param {String} hookname
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.createWebhook = (function(_this) {
|
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("webhooks", hookid, replyHandler("sadd 'webhooks' -> '" + hookid + "'"));
|
||||||
_this.db.sadd("user:" + userId + ":webhooks", hookid, replyHandler("sadd 'user:" + userId + ":webhooks' -> '" + hookid + "'"));
|
_this.db.sadd("user:" + username + ":webhooks", hookid, replyHandler("sadd 'user:" + username + ":webhooks' -> '" + hookid + "'"));
|
||||||
return _this.db.set("webhook:" + hookid, hookname, replyHandler("set webhook:" + hookid + " -> " + hookname));
|
return _this.db.hmset("webhook:" + hookid, 'hookname', hookname, 'username', username, replyHandler("set webhook:" + hookid + " -> [" + hookname + ", " + username + "]"));
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
||||||
|
|
@ -1061,7 +1061,21 @@ Persistence
|
||||||
|
|
||||||
exports.getWebhookName = (function(_this) {
|
exports.getWebhookName = (function(_this) {
|
||||||
return function(hookid, cb) {
|
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);
|
})(this);
|
||||||
|
|
||||||
|
|
@ -1069,13 +1083,13 @@ Persistence
|
||||||
/*
|
/*
|
||||||
Returns all the user's webhooks by ID.
|
Returns all the user's webhooks by ID.
|
||||||
|
|
||||||
@public getUserWebhookIDs( *userId* )
|
@public getUserWebhookIDs( *username* )
|
||||||
@param {String} userId
|
@param {String} username
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getUserWebhookIDs = (function(_this) {
|
exports.getUserWebhookIDs = (function(_this) {
|
||||||
return function(userId, cb) {
|
return function(username, cb) {
|
||||||
return _this.db.smembers("user:" + userId + ":webhooks", cb);
|
return _this.db.smembers("user:" + username + ":webhooks", cb);
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
||||||
|
|
@ -1083,13 +1097,13 @@ Persistence
|
||||||
/*
|
/*
|
||||||
Gets all the user's webhooks with names.
|
Gets all the user's webhooks with names.
|
||||||
|
|
||||||
@public getAllUserWebhooks( *userId* )
|
@public getAllUserWebhooks( *username* )
|
||||||
@param {String} userId
|
@param {String} username
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getAllUserWebhooks = (function(_this) {
|
exports.getAllUserWebhooks = (function(_this) {
|
||||||
return function(userId, cb) {
|
return function(username, cb) {
|
||||||
return getSetRecords("user:" + userId + ":webhooks", exports.getWebhookName, cb);
|
return getSetRecords("user:" + username + ":webhooks", exports.getWebhookName, cb);
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
||||||
|
|
@ -1115,7 +1129,7 @@ Persistence
|
||||||
|
|
||||||
exports.getAllWebhooks = (function(_this) {
|
exports.getAllWebhooks = (function(_this) {
|
||||||
return function(cb) {
|
return function(cb) {
|
||||||
return getSetRecords("webhooks", exports.getWebhookName, cb);
|
return getSetRecords("webhooks", exports.getFullWebhook, cb);
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
||||||
|
|
@ -1123,15 +1137,15 @@ Persistence
|
||||||
/*
|
/*
|
||||||
Delete a webhook.
|
Delete a webhook.
|
||||||
|
|
||||||
@public deleteWebhook( *userId, hookid* )
|
@public deleteWebhook( *username, hookid* )
|
||||||
@param {String} userId
|
@param {String} username
|
||||||
@param {String} hookid
|
@param {String} hookid
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.deleteWebhook = (function(_this) {
|
exports.deleteWebhook = (function(_this) {
|
||||||
return function(userId, hookid) {
|
return function(username, hookid) {
|
||||||
_this.db.srem("webhooks", hookid, replyHandler("srem 'webhooks' -> '" + 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));
|
return _this.db.del("webhook:" + hookid, replyHandler("del webhook:" + hookid));
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ Request Handler
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(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');
|
db = require('./persistence');
|
||||||
|
|
||||||
|
|
@ -433,8 +433,8 @@ Request Handler
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
||||||
indexEvent = function(eventname, body, resp) {
|
parsePushAndAnswerEvent = function(eventname, username, body, resp) {
|
||||||
var err, msg, obj;
|
var err, obj;
|
||||||
if (typeof body === 'string') {
|
if (typeof body === 'string') {
|
||||||
try {
|
try {
|
||||||
body = JSON.parse(body);
|
body = JSON.parse(body);
|
||||||
|
|
@ -453,8 +453,14 @@ Request Handler
|
||||||
eventname: eventname,
|
eventname: eventname,
|
||||||
body: body
|
body: body
|
||||||
};
|
};
|
||||||
|
if (username) {
|
||||||
|
obj.username = username;
|
||||||
|
}
|
||||||
db.pushEvent(obj);
|
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;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -472,7 +478,7 @@ Request Handler
|
||||||
});
|
});
|
||||||
return req.on('end', function() {
|
return req.on('end', function() {
|
||||||
var fPath, obj;
|
var fPath, obj;
|
||||||
obj = indexEvent(name, body, resp);
|
obj = parsePushAndAnswerEvent(name, null, body, resp);
|
||||||
if (obj.eventname === 'uptimestatistics') {
|
if (obj.eventname === 'uptimestatistics') {
|
||||||
fPath = path.resolve(__dirname, '..', 'webpages', 'public', 'data', 'histochart.json');
|
fPath = path.resolve(__dirname, '..', 'webpages', 'public', 'data', 'histochart.json');
|
||||||
return fs.writeFile(fPath, JSON.stringify(JSON.parse(body), void 0, 2), 'utf8');
|
return fs.writeFile(fPath, JSON.stringify(JSON.parse(body), void 0, 2), 'utf8');
|
||||||
|
|
@ -488,17 +494,16 @@ Request Handler
|
||||||
|
|
||||||
exports.handleWebhooks = (function(_this) {
|
exports.handleWebhooks = (function(_this) {
|
||||||
return function(req, resp) {
|
return function(req, resp) {
|
||||||
var body, hookid, hookname;
|
var body, hookid, oHook;
|
||||||
hookid = req.url.substring(10).split('/')[0];
|
hookid = req.url.substring(10).split('/')[0];
|
||||||
hookname = _this.allowedHooks[hookid];
|
oHook = _this.allowedHooks[hookid];
|
||||||
if (hookname) {
|
if (oHook) {
|
||||||
body = '';
|
body = '';
|
||||||
req.on('data', function(data) {
|
req.on('data', function(data) {
|
||||||
return body += data;
|
return body += data;
|
||||||
});
|
});
|
||||||
return req.on('end', function() {
|
return req.on('end', function() {
|
||||||
var obj;
|
return parsePushAndAnswerEvent(oHook.hookname, oHook.username, body, resp);
|
||||||
return obj = indexEvent(hookname, body, resp);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return resp.send(404, "Webhook not existing!");
|
return resp.send(404, "Webhook not existing!");
|
||||||
|
|
@ -507,9 +512,12 @@ Request Handler
|
||||||
})(this);
|
})(this);
|
||||||
|
|
||||||
exports.activateWebhook = (function(_this) {
|
exports.activateWebhook = (function(_this) {
|
||||||
return function(hookid, name) {
|
return function(user, hookid, name) {
|
||||||
_this.log.info("HL | Webhook '" + hookid + "' activated");
|
_this.log.info("HL | Webhook '" + hookid + "' activated");
|
||||||
return _this.allowedHooks[hookid] = name;
|
return _this.allowedHooks[hookid] = {
|
||||||
|
hookname: name,
|
||||||
|
username: user
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,9 @@
|
||||||
|
#
|
||||||
|
# General Helper Fucntions
|
||||||
|
#
|
||||||
|
|
||||||
|
strPublicKey = ''
|
||||||
|
|
||||||
# Fetch the search string and transform it into an object for easy access
|
# Fetch the search string and transform it into an object for easy access
|
||||||
arrParams = window.location.search.substring(1).split '&'
|
arrParams = window.location.search.substring(1).split '&'
|
||||||
oParams = {}
|
oParams = {}
|
||||||
|
|
@ -8,15 +14,6 @@ for param in arrParams
|
||||||
if oParams.id
|
if oParams.id
|
||||||
oParams.id = decodeURIComponent 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 ) ->
|
fDisplayError = ( msg ) ->
|
||||||
window.scrollTo 0, 0
|
window.scrollTo 0, 0
|
||||||
$( '#info' ).text "Error: #{ msg }"
|
$( '#info' ).text "Error: #{ msg }"
|
||||||
|
|
@ -34,7 +31,380 @@ fIssueRequest = ( args ) ->
|
||||||
$.post( '/usercommand', args.body )
|
$.post( '/usercommand', args.body )
|
||||||
.done args.done
|
.done args.done
|
||||||
.fail args.fail
|
.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 = () ->
|
fOnLoad = () ->
|
||||||
# Fetch the public key from the engine
|
# Fetch the public key from the engine
|
||||||
|
|
@ -58,83 +428,31 @@ fOnLoad = () ->
|
||||||
|
|
||||||
$( '#input_id' ).focus()
|
$( '#input_id' ).focus()
|
||||||
|
|
||||||
|
|
||||||
# EVENT
|
# 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
|
# Event type is changed, changes the whole event section
|
||||||
$( '#select_event_type' ).change () ->
|
$( '#select_event_type' ).change () ->
|
||||||
$( '#event_parameters *' ).remove()
|
fPrepareEventType $( this ).val()
|
||||||
switch $( this ).val()
|
|
||||||
|
|
||||||
# The user wants to act on a custom event
|
# If the user is coming from an event UI he wants a rule to be setup for him
|
||||||
when 'Custom Event'
|
switch oParams.eventtype
|
||||||
inpEvt = $( '<input>' ).attr( 'type', 'text' )
|
when 'custom'
|
||||||
.attr( 'style', 'font-size:1em' ).attr 'id', 'input_eventname'
|
$( '#input_id' ).val "My '#{ oParams.eventname }' Rule"
|
||||||
$( '#event_parameters' ).append $( '<h4>' ).text( 'Event Name : ' ).append inpEvt
|
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'
|
||||||
when 'Webhook'
|
$( '#input_id' ).val "My '#{ oParams.hookname }' Rule"
|
||||||
fIssueRequest
|
fPrepareEventType 'Webhook'
|
||||||
body: command: 'get_webhooks'
|
$( 'select_eventhook' ).val oParams.hookname
|
||||||
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 'Event Poller'
|
when 'poller'
|
||||||
fIssueRequest
|
$( '#input_id' ).val "My '#{ oParams.eventpoller }' Rule"
|
||||||
body: command: 'get_event_pollers'
|
fPrepareEventType 'Event Poller'
|
||||||
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
|
|
||||||
|
|
||||||
$( '#input_event' ).change () ->
|
$( '#input_event' ).change () ->
|
||||||
$( '#select_event' ).val ''
|
$( '#select_event' ).val ''
|
||||||
|
|
@ -146,107 +464,9 @@ fOnLoad = () ->
|
||||||
else
|
else
|
||||||
fPlaceAndPaintInterval()
|
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
|
# ACTIONS
|
||||||
|
|
||||||
|
|
||||||
# <b>Selected Actions:</b>
|
# <b>Selected Actions:</b>
|
||||||
# <table id="selected_actions"></table>
|
# <table id="selected_actions"></table>
|
||||||
# <br><br>
|
# <br><br>
|
||||||
|
|
@ -255,11 +475,10 @@ fOnLoad = () ->
|
||||||
# <div id="action_params"></div>
|
# <div id="action_params"></div>
|
||||||
# <br><br>
|
# <br><br>
|
||||||
|
|
||||||
obj =
|
fIssueRequest
|
||||||
command: 'get_action_invokers'
|
body:
|
||||||
$.post( '/usercommand', obj )
|
command: 'get_action_invokers'
|
||||||
|
done: ( data ) ->
|
||||||
.done ( data ) ->
|
|
||||||
try
|
try
|
||||||
oAis = JSON.parse data.message
|
oAis = JSON.parse data.message
|
||||||
catch err
|
catch err
|
||||||
|
|
@ -273,120 +492,8 @@ fOnLoad = () ->
|
||||||
if arrEls.length is 0
|
if arrEls.length is 0
|
||||||
$( '#select_actions' ).append $( '<option>' ).text module + ' -> ' + act
|
$( '#select_actions' ).append $( '<option>' ).text module + ' -> ' + act
|
||||||
fAppendActions module, actions for module, actions of oAis
|
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', () ->
|
$( '#select_actions' ).on 'change', () ->
|
||||||
opt = $ 'option:selected', this
|
opt = $ 'option:selected', this
|
||||||
|
|
@ -422,33 +529,45 @@ fOnLoad = () ->
|
||||||
$( '#input_id' ).focus()
|
$( '#input_id' ).focus()
|
||||||
throw new Error 'Please enter a rule name!'
|
throw new Error 'Please enter a rule name!'
|
||||||
|
|
||||||
eventId = $( '#input_event' ).val()
|
eventtype = $( '#select_event_type' ).val()
|
||||||
if eventId is ''
|
switch eventtype
|
||||||
$( '#input_event' ).focus()
|
when ''
|
||||||
throw new Error 'Please assign an event!'
|
$( '#select_event_type' ).focus()
|
||||||
|
throw new Error 'Please choose an event type!'
|
||||||
|
|
||||||
ep = {}
|
when 'Custom Event'
|
||||||
$( "#event_poller_params tr" ).each () ->
|
el = $( '#input_eventname' )
|
||||||
key = $( this ).children( '.key' ).text()
|
if el.val() is ''
|
||||||
val = $( 'input', this ).val()
|
el.focus()
|
||||||
if val is ''
|
throw new Error 'Please assign an Event Name!'
|
||||||
$( 'input', this ).focus()
|
eventname = el.val()
|
||||||
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 = {}
|
when 'Webhook'
|
||||||
evtFuncs[ eventId ] = []
|
eventname = $( '#select_eventhook' ).val()
|
||||||
$( '#event_poller_params tr.funcMappings' ).each () ->
|
|
||||||
evtFuncs[ eventId ].push
|
when 'Event Poller'
|
||||||
argument: $( 'div.funcarg', this ).text()
|
ep = {}
|
||||||
value: $( 'input[type=text]', this ).val()
|
$( "#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
|
if $( '#selected_actions tr' ).length is 0
|
||||||
throw new Error 'Please select at least one action or create one!'
|
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!"
|
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 ) ->
|
fCheckOverwrite = ( obj ) ->
|
||||||
( err ) ->
|
( err ) ->
|
||||||
if err.status is 409
|
if err.status is 409
|
||||||
|
|
@ -572,13 +629,17 @@ fOnLoad = () ->
|
||||||
payl = JSON.parse obj.body
|
payl = JSON.parse obj.body
|
||||||
payl.overwrite = true
|
payl.overwrite = true
|
||||||
obj.body = JSON.stringify payl
|
obj.body = JSON.stringify payl
|
||||||
$.post( '/usercommand', obj )
|
fIssueRequest
|
||||||
.done ( data ) ->
|
body: obj
|
||||||
|
done: ( data ) ->
|
||||||
$( '#info' ).text data.message
|
$( '#info' ).text data.message
|
||||||
$( '#info' ).attr 'class', 'success'
|
$( '#info' ).attr 'class', 'success'
|
||||||
.fail fFailedRequest "#{ obj.id } not stored!"
|
fail: fFailedRequest "#{ obj.id } not stored!"
|
||||||
else
|
else
|
||||||
fFailedRequest( "#{ obj.id } not stored!" ) err
|
fFailedRequest( "#{ obj.id } not stored!" ) err
|
||||||
|
|
||||||
|
start = fConvertTimeToDate
|
||||||
|
mins = fConvertDayHourToMinutes
|
||||||
if $( '#select_event' ).val() is ''
|
if $( '#select_event' ).val() is ''
|
||||||
start = null
|
start = null
|
||||||
mins = null
|
mins = null
|
||||||
|
|
@ -597,25 +658,28 @@ fOnLoad = () ->
|
||||||
actions: acts
|
actions: acts
|
||||||
actionparams: ap
|
actionparams: ap
|
||||||
actionfunctions: actFuncs
|
actionfunctions: actFuncs
|
||||||
$.post( '/usercommand', obj )
|
console.log obj
|
||||||
.done ( data ) ->
|
fIssueRequest
|
||||||
|
body: obj
|
||||||
|
done: ( data ) ->
|
||||||
$( '#info' ).text data.message
|
$( '#info' ).text data.message
|
||||||
$( '#info' ).attr 'class', 'success'
|
$( '#info' ).attr 'class', 'success'
|
||||||
.fail fCheckOverwrite obj
|
fail: fCheckOverwrite obj
|
||||||
catch err
|
catch err
|
||||||
console.log err
|
|
||||||
$( '#info' ).text 'Error in upload: ' + err.message
|
$( '#info' ).text 'Error in upload: ' + err.message
|
||||||
$( '#info' ).attr 'class', 'error'
|
$( '#info' ).attr 'class', 'error'
|
||||||
alert err.message
|
alert err.message
|
||||||
throw err
|
|
||||||
|
|
||||||
|
# Edit a Rule
|
||||||
|
# -----------
|
||||||
if oParams.id
|
if oParams.id
|
||||||
obj =
|
obj =
|
||||||
command: 'get_rule'
|
command: 'get_rule'
|
||||||
body: JSON.stringify
|
body: JSON.stringify
|
||||||
id: oParams.id
|
id: oParams.id
|
||||||
$.post( '/usercommand', obj )
|
fIssueRequest
|
||||||
.done ( data ) ->
|
body: obj
|
||||||
|
done: ( data ) ->
|
||||||
oRule = JSON.parse data.message
|
oRule = JSON.parse data.message
|
||||||
if oRule
|
if oRule
|
||||||
$( '#input_id' ).val oRule.id
|
$( '#input_id' ).val oRule.id
|
||||||
|
|
@ -642,7 +706,7 @@ fOnLoad = () ->
|
||||||
arrName = action.split ' -> '
|
arrName = action.split ' -> '
|
||||||
fAddSelectedAction action
|
fAddSelectedAction action
|
||||||
|
|
||||||
.fail ( err ) ->
|
fail: ( err ) ->
|
||||||
if err.responseText is ''
|
if err.responseText is ''
|
||||||
msg = 'No Response from Server!'
|
msg = 'No Response from Server!'
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -41,19 +41,20 @@ fUpdateWebhookList = () ->
|
||||||
|
|
||||||
|
|
||||||
fProcessWebhookList = ( data ) ->
|
fProcessWebhookList = ( data ) ->
|
||||||
$( '#table_webhooks tr' ).remove()
|
$( '#table_webhooks *' ).remove()
|
||||||
oHooks = JSON.parse data.message
|
if data.message
|
||||||
console.log hostUrl
|
oHooks = JSON.parse data.message
|
||||||
for hookid, hookname of oHooks
|
$( '#table_webhooks' ).append $( '<h3>' ).text 'Your existing Webhooks:'
|
||||||
tr = $( '<tr>' )
|
for hookid, hookname of oHooks
|
||||||
tdName = $( '<div>' ).text hookname
|
tr = $( '<tr>' )
|
||||||
tdUrl = $( '<input>' ).attr( 'style', 'width:600px' ).val "#{ hostUrl }/webhooks/#{ hookid }"
|
tdName = $( '<div>' ).text hookname
|
||||||
img = $( '<img>' ).attr( 'class', 'del' )
|
tdUrl = $( '<input>' ).attr( 'style', 'width:600px' ).val "#{ hostUrl }/webhooks/#{ hookid }"
|
||||||
.attr( 'title', 'Delete Module' ).attr 'src', 'red_cross_small.png'
|
img = $( '<img>' ).attr( 'class', 'del' )
|
||||||
tr.append( $( '<td>' ).append img )
|
.attr( 'title', 'Delete Module' ).attr 'src', 'red_cross_small.png'
|
||||||
tr.append( $( '<td>' ).attr( 'style', 'padding-left:10px' ).append tdName )
|
tr.append( $( '<td>' ).append img )
|
||||||
tr.append( $( '<td>' ).attr( 'style', 'padding-left:10px' ).append tdUrl )
|
tr.append( $( '<td>' ).attr( 'style', 'padding-left:10px' ).append tdName )
|
||||||
$( '#table_webhooks' ).append tr
|
tr.append( $( '<td>' ).attr( 'style', 'padding-left:10px' ).append tdUrl )
|
||||||
|
$( '#table_webhooks' ).append tr
|
||||||
|
|
||||||
|
|
||||||
fOnLoad = () ->
|
fOnLoad = () ->
|
||||||
|
|
@ -71,7 +72,7 @@ fOnLoad = () ->
|
||||||
fDisplayError 'Please provide an Event Name for your new Webhook!'
|
fDisplayError 'Please provide an Event Name for your new Webhook!'
|
||||||
|
|
||||||
else
|
else
|
||||||
$( '#display_hookurl *' ).remove()
|
# $( '#display_hookurl *' ).remove()
|
||||||
fIssueRequest
|
fIssueRequest
|
||||||
body:
|
body:
|
||||||
command: 'create_webhook'
|
command: 'create_webhook'
|
||||||
|
|
@ -79,8 +80,7 @@ fOnLoad = () ->
|
||||||
hookname: hookname
|
hookname: hookname
|
||||||
done: ( data ) ->
|
done: ( data ) ->
|
||||||
oAnsw = JSON.parse data.message
|
oAnsw = JSON.parse data.message
|
||||||
|
b = $( '<b>' ).text "This is the Webhook Url you can use for your Event '#{ oAnsw.hookname }' : "
|
||||||
b = $( '<b>' ).text "This is the Webhook Url you will use for your Event : "
|
|
||||||
$( '#display_hookurl' ).append b
|
$( '#display_hookurl' ).append b
|
||||||
$( '#display_hookurl' ).append $('<br>')
|
$( '#display_hookurl' ).append $('<br>')
|
||||||
inp = $('<input>').attr( 'type', 'text' ).attr( 'style', 'width:600px' )
|
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\"
|
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>"
|
href=\"forge?page=forge_rule&eventtype=webhook&hookname=#{ hookname }\">a Rule for this Event!</a>"
|
||||||
$( '#display_hookurl' ).append div
|
$( '#display_hookurl' ).append div
|
||||||
|
fUpdateWebhookList()
|
||||||
fail: ( err ) ->
|
fail: ( err ) ->
|
||||||
if err.status is 409
|
if err.status is 409
|
||||||
fFailedRequest( 'Webhook Event Name already existing!' ) err
|
fFailedRequest( 'Webhook Event Name already existing!' ) err
|
||||||
else
|
else
|
||||||
fFailedRequest( 'Unable to create Webhook! ' + err.message ) err
|
fFailedRequest( 'Unable to create Webhook! ' + err.message ) err
|
||||||
|
fUpdateWebhookList()
|
||||||
|
|
||||||
$( '#table_webhooks' ).on 'click', 'img', () ->
|
$( '#table_webhooks' ).on 'click', 'img', () ->
|
||||||
if confirm "Do you really want to delete this webhook?"
|
if confirm "Do you really want to delete this webhook?"
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -51,22 +51,24 @@
|
||||||
|
|
||||||
fProcessWebhookList = function(data) {
|
fProcessWebhookList = function(data) {
|
||||||
var hookid, hookname, img, oHooks, tdName, tdUrl, tr, _results;
|
var hookid, hookname, img, oHooks, tdName, tdUrl, tr, _results;
|
||||||
$('#table_webhooks tr').remove();
|
$('#table_webhooks *').remove();
|
||||||
oHooks = JSON.parse(data.message);
|
if (data.message) {
|
||||||
console.log(hostUrl);
|
oHooks = JSON.parse(data.message);
|
||||||
_results = [];
|
$('#table_webhooks').append($('<h3>').text('Your existing Webhooks:'));
|
||||||
for (hookid in oHooks) {
|
_results = [];
|
||||||
hookname = oHooks[hookid];
|
for (hookid in oHooks) {
|
||||||
tr = $('<tr>');
|
hookname = oHooks[hookid];
|
||||||
tdName = $('<div>').text(hookname);
|
tr = $('<tr>');
|
||||||
tdUrl = $('<input>').attr('style', 'width:600px').val("" + hostUrl + "/webhooks/" + hookid);
|
tdName = $('<div>').text(hookname);
|
||||||
img = $('<img>').attr('class', 'del').attr('title', 'Delete Module').attr('src', 'red_cross_small.png');
|
tdUrl = $('<input>').attr('style', 'width:600px').val("" + hostUrl + "/webhooks/" + hookid);
|
||||||
tr.append($('<td>').append(img));
|
img = $('<img>').attr('class', 'del').attr('title', 'Delete Module').attr('src', 'red_cross_small.png');
|
||||||
tr.append($('<td>').attr('style', 'padding-left:10px').append(tdName));
|
tr.append($('<td>').append(img));
|
||||||
tr.append($('<td>').attr('style', 'padding-left:10px').append(tdUrl));
|
tr.append($('<td>').attr('style', 'padding-left:10px').append(tdName));
|
||||||
_results.push($('#table_webhooks').append(tr));
|
tr.append($('<td>').attr('style', 'padding-left:10px').append(tdUrl));
|
||||||
|
_results.push($('#table_webhooks').append(tr));
|
||||||
|
}
|
||||||
|
return _results;
|
||||||
}
|
}
|
||||||
return _results;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fOnLoad = function() {
|
fOnLoad = function() {
|
||||||
|
|
@ -79,7 +81,6 @@
|
||||||
if (hookname === '') {
|
if (hookname === '') {
|
||||||
return fDisplayError('Please provide an Event Name for your new Webhook!');
|
return fDisplayError('Please provide an Event Name for your new Webhook!');
|
||||||
} else {
|
} else {
|
||||||
$('#display_hookurl *').remove();
|
|
||||||
return fIssueRequest({
|
return fIssueRequest({
|
||||||
body: {
|
body: {
|
||||||
command: 'create_webhook',
|
command: 'create_webhook',
|
||||||
|
|
@ -90,7 +91,7 @@
|
||||||
done: function(data) {
|
done: function(data) {
|
||||||
var b, div, inp, oAnsw;
|
var b, div, inp, oAnsw;
|
||||||
oAnsw = JSON.parse(data.message);
|
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(b);
|
||||||
$('#display_hookurl').append($('<br>'));
|
$('#display_hookurl').append($('<br>'));
|
||||||
inp = $('<input>').attr('type', 'text').attr('style', 'width:600px').val("" + hostUrl + "/webhooks/" + oAnsw.hookid);
|
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($('<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($('<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>"));
|
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) {
|
fail: function(err) {
|
||||||
if (err.status === 409) {
|
if (err.status === 409) {
|
||||||
return fFailedRequest('Webhook Event Name already existing!')(err);
|
fFailedRequest('Webhook Event Name already existing!')(err);
|
||||||
} else {
|
} else {
|
||||||
return fFailedRequest('Unable to create Webhook! ' + err.message)(err);
|
fFailedRequest('Unable to create Webhook! ' + err.message)(err);
|
||||||
}
|
}
|
||||||
|
return fUpdateWebhookList();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
{{{script}}}
|
{{{script}}}
|
||||||
</script>
|
</script>
|
||||||
{{{remote_scripts}}}
|
{{{remote_scripts}}}
|
||||||
|
<script src="js/menubar.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
<h2>Create your own Webhooks</h2>
|
<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>
|
<input type="text" id="inp_hookname" style="font-size:1em;width:300px" /></h3>
|
||||||
<button type="button" id="but_submit">Create Webhook!</button>
|
<button type="button" id="but_submit">Create Webhook!</button>
|
||||||
<br><br>
|
<br><br>
|
||||||
<div id="display_hookurl" />
|
<div id="display_hookurl"></div>
|
||||||
<div id="table_webhooks" />
|
<br>
|
||||||
|
<div id="table_webhooks"></div>
|
||||||
|
|
|
||||||
|
|
@ -1,44 +1 @@
|
||||||
<div id="menubar">
|
<table id="menubar"><tr></tr></table>
|
||||||
<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>
|
|
||||||
|
|
|
||||||
|
|
@ -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=Roboto:300' rel='stylesheet' type='text/css'>
|
||||||
<link href='http://fonts.googleapis.com/css?family=Nunito' 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">
|
<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='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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="menubar">
|
<table id="menubar"><tr></tr></table>
|
||||||
<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>
|
|
||||||
|
|
||||||
<div id="info"></div>
|
<div id="info"></div>
|
||||||
<div id="mainbody">
|
<div id="mainbody">
|
||||||
|
|
|
||||||
41
webpages/public/js/menubar.js
Normal file
41
webpages/public/js/menubar.js
Normal 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 ) );
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -38,27 +38,25 @@ input[type=password]:focus {
|
||||||
#menubar {
|
#menubar {
|
||||||
/*font-size: 0.85em;*/
|
/*font-size: 0.85em;*/
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
padding: 2px 2px 4px 2px;
|
padding: 0px;
|
||||||
height: 1em;
|
width: 100%;
|
||||||
background-color: #DDD;
|
background-color: #DDD;
|
||||||
}
|
}
|
||||||
|
|
||||||
#menubar div {
|
#menubar td {
|
||||||
height: 100%;
|
|
||||||
float: left;
|
float: left;
|
||||||
padding-left: 10px;
|
margin: 0px 5px 0px 5px;
|
||||||
padding-right: 10px;
|
padding: 0px 10px 2px 10px;
|
||||||
padding-bottom: 2px;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
-moz-border-radius: 5px;
|
-moz-border-radius: 5px;
|
||||||
border-radius: 5px;
|
border-radius: 10px;
|
||||||
-webkit-transition: all 0.30s ease-in-out;
|
-webkit-transition: all 0.30s ease-in-out;
|
||||||
-moz-transition: all 0.30s ease-in-out;
|
-moz-transition: all 0.30s ease-in-out;
|
||||||
-ms-transition: all 0.30s ease-in-out;
|
-ms-transition: all 0.30s ease-in-out;
|
||||||
-o-transition: all 0.30s ease-in-out;
|
-o-transition: all 0.30s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
#menubar div:hover {
|
#menubar td:hover {
|
||||||
background-color: #AAA;
|
background-color: #AAA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue