From 0dfde40b7cb76e64c0e00117030e0915dd81f4eb Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Thu, 24 Nov 2016 17:59:30 +0530 Subject: [PATCH] IOTS-296: Generalizing policy UI for policy create wizard This commit is done to seperate policy related client side logic and UIs from device type specific logics. This is a part of creating self contained plugins for device types. This commit generalizes the policy creation wizard in the CDMF core and removes device type specific UIs and client side logic from the core. Also, this introduces a generic policy configuration UI in a new unit. --- .../wizard.json | 4 +- .../policy-wizard.hbs | 14 + .../policy-wizard.json | 3 + .../public/css/codemirror.css | 0 .../public/js/codemirror.js | 0 .../public/js/editor.js | 37 + .../public/js/sql.js | 0 .../public/js/utils.js | 24 +- .../units/cdmf.unit.policy.create/create.hbs | 327 ++++++-- .../public/js/policy-create.js | 532 +++++++++++++ .../public/js/policy-create.js | 701 ++++++------------ .../units/cdmf.unit.policy.wizard/wizard.hbs | 53 +- .../units/cdmf.unit.policy.wizard/wizard.js | 16 +- 13 files changed, 1135 insertions(+), 576 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.json rename components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/{cdmf.unit.policy.wizard => cdmf.unit.device.type.generic.policy-wizard}/public/css/codemirror.css (100%) rename components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/{cdmf.unit.policy.wizard => cdmf.unit.device.type.generic.policy-wizard}/public/js/codemirror.js (100%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/editor.js rename components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/{cdmf.unit.policy.wizard => cdmf.unit.device.type.generic.policy-wizard}/public/js/sql.js (100%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.create.wizard/wizard.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.create.wizard/wizard.json index 13574a2cb48..5322b6ff2bd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.create.wizard/wizard.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.create.wizard/wizard.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "1.0.0", "uri": "/policy/add/{deviceType}", - "layout": "cdmf.layout.default" + "layout": "cdmf.layout.default" } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.hbs new file mode 100644 index 00000000000..20db2036a40 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.hbs @@ -0,0 +1,14 @@ +{{#zone "topCss"}} + {{css "css/codemirror.css"}} +{{/zone}} +
+
+ +
+
+
+{{#zone "bottomJs"}} + {{js "js/codemirror.js"}} + {{js "js/sql.js"}} + {{js "js/editor.js"}} +{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.json new file mode 100644 index 00000000000..b88788f78bc --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.json @@ -0,0 +1,3 @@ +{ + "version" : "1.0.0" +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/css/codemirror.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/css/codemirror.css similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/css/codemirror.css rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/css/codemirror.css diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/codemirror.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/codemirror.js similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/codemirror.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/codemirror.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/editor.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/editor.js new file mode 100644 index 00000000000..aca1bf0a7ce --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/editor.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +window.queryEditor = CodeMirror.fromTextArea(document.getElementById('policy-definition-input'), { + mode: MIME_TYPE_SIDDHI_QL, + indentWithTabs: true, + smartIndent: true, + lineNumbers: true, + matchBrackets: true, + autofocus: true, + extraKeys: { + "Shift-2": function (cm) { + insertStr(cm, cm.getCursor(), '@'); + CodeMirror.showHint(cm, getAnnotationHints); + }, + "Ctrl-Space": "autocomplete" + } +}); + +var validatePolicyProfile = function () { + return true; +}; \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/sql.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/sql.js similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/sql.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/sql.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.handlebars/public/js/utils.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.handlebars/public/js/utils.js index e64704b078f..4e99b801b9d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.handlebars/public/js/utils.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.handlebars/public/js/utils.js @@ -33,12 +33,26 @@ callback(template); } }; + + $.isResourceExists = function (location, callback) { + $.ajax({ + url: location, + type: 'HEAD', + success: function () { + callback(true); + }, + error: function () { + callback(false); + } + }); + }; + $.registerPartial = function (name, location, callback) { - $.get(location, function (data) { - Handlebars.registerPartial( name, data); - console.log("Partial " + name + " has been registered"); - callback(); - }); + $.get(location, function (data) { + Handlebars.registerPartial(name, data); + console.log("Partial " + name + " has been registered"); + callback(); + }); }; })(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs index 6ca4a632859..50d5548c1dd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs @@ -1,74 +1,293 @@ -{{! - Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - - WSO2 Inc. licenses this file to you under the Apache License, - Version 2.0 (the "License"); you may not use this file except - in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -}} {{#zone "content"}} {{#if isAuthorized}}
-
+ + + +