diff --git a/hal-core/resource/resource/web/api/openapi.json b/hal-core/resource/resource/web/api/openapi.json index 1fd17ddc..796d91da 100644 --- a/hal-core/resource/resource/web/api/openapi.json +++ b/hal-core/resource/resource/web/api/openapi.json @@ -170,7 +170,7 @@ "min", "hour", "day", - "week", + "week" ] }, "in": "query", diff --git a/hal-core/resource/resource/web/js/hal.js b/hal-core/resource/resource/web/js/hal.js index 0781738f..22be52e3 100644 --- a/hal-core/resource/resource/web/js/hal.js +++ b/hal-core/resource/resource/web/js/hal.js @@ -153,8 +153,9 @@ function initDynamicModalForm(modalId, formTemplateId = null, templateID = null) if (formTemplateId != null) { dynamicConf[formTemplateId] = []; $("#" + templateID + " div").each(function(){ - dynamicConf[formTemplateId][$(this).attr("id")] = $(this).html(); + dynamicConf[formTemplateId][$(this).prop("id")] = $(this).html(); }); + // Update dynamic inputs $("#" + modalId + " select[name=type]").change(function(){ $("#" + modalId + " #" + formTemplateId).html(dynamicConf[formTemplateId][$(this).val()]); @@ -170,26 +171,36 @@ function initDynamicModalForm(modalId, formTemplateId = null, templateID = null) if (formTemplateId != null) modal.find("#" + formTemplateId).empty(); // clear form div - // select dynamic form - var selector = modal.find("select[name=type]"); - selector.val(button.data("type")); - selector.change(); // Update dynamic inputs // set dynamic form data $.each(button.attr(), function(fieldName, value) { if(fieldName.startsWith("data-")) { - fieldName = fieldName.substring(5); + fieldName = fieldName.substring(5); // remove prefix data- + // case insensitive search - input = modal.find("input").filter(function() { - return this.name.toLowerCase() == fieldName; + var input = modal.find("input, select").filter(function() { + if (this.name.toLowerCase() == fieldName) { + if (this.type == "hidden" && modal.find("input[type=checkbox][name=" + fieldName + "]") != null) + return false; // Workaround for the default(false) boolean input + return true; + } + return false; }); - if (input.attr("type") == "checkbox") { // special handling for checkboxes - input.attr("value", "true"); - if (value=="true") input.attr("checked", "true"); - else input.removeAttr("checked"); - // Add default false value as a unchecked checkbox is not included in the post - input.parent().prepend(""); - } else { - input.val(value); + + if (input != null) { + if (input.prop("type") == "checkbox") { // special handling for checkboxes + input.prop("value", "true"); + input.prop("checked", value == "true"); + + if (modal.find("input[type=hidden][name=" + fieldName + "]") == null) { + // Add default false value as a unchecked checkbox is not included in the post + input.parent().prepend(""); + } + } else { + input.val(value); + + if (input.prop("tagName") == "SELECT") + input.change(); // required for select elements to update properly + } } } }); diff --git a/hal-core/resource/resource/web/trigger.tmpl b/hal-core/resource/resource/web/trigger.tmpl index 13b594b0..b14aed79 100644 --- a/hal-core/resource/resource/web/trigger.tmpl +++ b/hal-core/resource/resource/web/trigger.tmpl @@ -14,15 +14,23 @@
{{.getName()}} -
- -
+
+ + +
+ + + +
+
diff --git a/hal-core/src/se/hal/action/AlertAction.java b/hal-core/src/se/hal/action/AlertAction.java new file mode 100644 index 00000000..5bf0528c --- /dev/null +++ b/hal-core/src/se/hal/action/AlertAction.java @@ -0,0 +1,36 @@ +package se.hal.action; + +import se.hal.intf.HalAction; +import se.hal.page.HalAlertManager; +import zutil.log.LogUtil; +import zutil.ui.UserMessageManager.MessageTTL; +import zutil.ui.conf.Configurator; + +import java.util.logging.Logger; + +import static zutil.ui.UserMessageManager.*; + +/** + * Action that will alert users with a message + */ +public class AlertAction implements HalAction { + private static final Logger logger = LogUtil.getLogger(); + + @Configurator.Configurable("Alert Severity") + private MessageLevel severity = MessageLevel.INFO; + @Configurator.Configurable("Alert Message") + private MessageTTL ttl = MessageTTL.ONE_VIEW; + @Configurator.Configurable("Alert Message") + private String message = ""; + + + @Override + public void execute() { + HalAlertManager.getInstance().addAlert(new UserMessage(severity, message, ttl)); + } + + + public String toString(){ + return "Send Alert: " + severity + ": " + message; + } +} diff --git a/hal-core/src/se/hal/page/TriggerWebPage.java b/hal-core/src/se/hal/page/TriggerWebPage.java index 51fcf77e..63893676 100644 --- a/hal-core/src/se/hal/page/TriggerWebPage.java +++ b/hal-core/src/se/hal/page/TriggerWebPage.java @@ -64,17 +64,21 @@ public class TriggerWebPage extends HalWebPage { break; case "modify_flow": - logger.info("Modifying flow: " + flow.getName()); + logger.info("Modifying flow(id: " + flow.getId() + "): " + flow.getName()); flow.setEnabled("on".equals(request.get("enabled"))); flow.setName(request.get("name")); flow.save(db); break; case "remove_flow": - logger.info("Removing flow: " + flow.getName()); + logger.info("Removing flow(id: " + flow.getId() + "): " + flow.getName()); flow.delete(db); break; + case "execute_flow": + flow.execute(); + break; + // Triggers case "create_trigger": if (flow == null) { diff --git a/hal-core/src/se/hal/plugin.json b/hal-core/src/se/hal/plugin.json index 26962511..37eab4fd 100644 --- a/hal-core/src/se/hal/plugin.json +++ b/hal-core/src/se/hal/plugin.json @@ -32,6 +32,7 @@ {"se.hal.intf.HalTrigger": "se.hal.trigger.SensorTrigger"}, {"se.hal.intf.HalTrigger": "se.hal.trigger.TimerTrigger"}, + {"se.hal.intf.HalAction": "se.hal.action.AlertAction"}, {"se.hal.intf.HalAction": "se.hal.action.SendEventAction"} ] } diff --git a/hal-core/src/se/hal/struct/TriggerFlow.java b/hal-core/src/se/hal/struct/TriggerFlow.java index 98da2b4e..2526c76d 100644 --- a/hal-core/src/se/hal/struct/TriggerFlow.java +++ b/hal-core/src/se/hal/struct/TriggerFlow.java @@ -114,6 +114,9 @@ public class TriggerFlow extends DBBean { public void execute(){ if (!enabled) return; + + logger.info("Executing flow(id: " + getId() + "): " + getName()); + for (Action action : actionList){ action.execute(); }