diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag
index 34eadba2..093c794e 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag
@@ -33,27 +33,88 @@ var carbonHttpsServletTransport = carbon.server.address('https');
var result;
-if (uriMatcher.match("/{context}/api/device/sketch/download")) {
- sketchType = request.getParameter("sketchType");
- deviceType = request.getParameter("deviceType");
+if (uriMatcher.match("/{context}/api/device/sketch/download/{downloadId}")) {
+ downloadId = uriMatcher.elements().downloadId;
+ if(downloadId){
+ //Just download the already created zip archive
+ var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils;
+ var sketchFolder = "repository/resources/sketches";
+ var archivesPath = "file://"+CarbonUtils.getCarbonHome() + "/" + sketchFolder + "/archives/" + downloadId + ".zip";
+ var zipFile = new File(archivesPath);
+ response.addHeader('Content-type', "application/zip, application/octet-stream");
+ response.addHeader('Cache-Control', 'public,max-age=12960000');
+ response.addHeader("Content-Disposition", "attachment; filename=\"" + downloadId + ".zip\"");
+
+ try {
+ zipFile.open('r');
+ var stream = zipFile.getStream();
+ print(stream);
+ }catch(err){
+
+ }finally{
+ if(zipFile!=null) {
+ zipFile.close();
+ }
+ }
- if (!sketchType) {
- log.error("Sketch Type is empty");
- }
+ }else {
+ //Create a new zip archive and register user calling endpoint
- var user = session.get(constants.USER_SESSION_KEY);
- if (!user) {
- response.sendRedirect(dcProps.appContext + "login?#login-required");
- exit();
+ /* This should match with $CARBON_HOME/repository/resources/sketches/{sketchType} */
+ sketchType = request.getParameter("sketchType");
+ /* This should be registered device type of the CDMF(Connected Device Management Framework) */
+ deviceType = request.getParameter("deviceType");
+
+ if (!sketchType) {
+ log.error("Sketch Type is empty!");
+ // http status code 400 refers to - Bad request.
+ result = 400;
+ } else {
+ var user = session.get(constants.USER_SESSION_KEY);
+
+ if (!user) {
+ response.sendRedirect(dcProps.appContext + "login?#login-required");
+ exit();
+ }
+
+ //URL: https://localhost:9443/{deviceType}/download?owner={username}
+ deviceManagerService = carbonHttpsServletTransport + "/" + deviceType + "/manager";
+
+ sketchDownloadEndPoint = deviceManagerService + "/device/" + sketchType + "/download";
+ response.sendRedirect(sketchDownloadEndPoint + "?owner=" + user.username);
+ exit();//stop execution
+
+ }
}
- //URL: https://localhost:9443/{deviceType}/download?owner={username}
- deviceManagerService = carbonHttpsServletTransport + "/" + deviceType + "/manager";
- sketchDownloadEndPoint = deviceManagerService + "/device/" + sketchType + "/download";
- response.sendRedirect(sketchDownloadEndPoint + "?owner=" + user.username);
- exit();//stop execution
+} else if (uriMatcher.match("/{context}/api/device/sketch/generate_link")) {
+
+ var contents = request.getContent();
+ sketchType = contents.sketchType;
+ deviceType = contents.deviceType;
+ generateLink = contents.generateLink;
+
+ if (!sketchType) {
+ log.error("Sketch Type is empty!");
+ // http status code 400 refers to - Bad request.
+ result = 400;
+ } else {
+ var user = session.get(constants.USER_SESSION_KEY);
+
+ if (!user) {
+ result = 403;
+ }else {
+ //URL: https://localhost:9443/{deviceType}/download?owner={username}
+ deviceManagerService = carbonHttpsServletTransport + "/" + deviceType + "/manager";
+
+ sketchGenerateLinkEndPoint = deviceManagerService + "/device/" + sketchType + "/generate_link";
+ var fileId = get(sketchGenerateLinkEndPoint + "?owner=" + user.username, null, "text");
+ result = carbonHttpsServletTransport + constants.WEB_APP_CONTEXT + "/api/device/sketch/download/" + fileId.data;
+ }
+ }
} else if (uriMatcher.match("/{context}/api/devices/all")) {
+
var user = session.get(constants.USER_SESSION_KEY);
if (!user) {
response.sendRedirect(dcProps.appContext + "login?#login-required");
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/operation-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/operation-api.jag
new file mode 100755
index 00000000..4fa85bfc
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/operation-api.jag
@@ -0,0 +1,31 @@
+<%
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+var uri = request.getRequestURI();
+var uriMatcher = new URIMatcher(String(uri));
+
+var log = new Log("api/operation-api.jag");
+
+var deviceModule = require("/modules/device.js").deviceModule;
+
+if (uriMatcher.match("/{context}/api/operation")) {
+ payload = request.getContent();
+ result = deviceModule.performOperation(payload.devices, payload.operation);
+}
+%>
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/policy-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/policy-api.jag
new file mode 100755
index 00000000..5615c877
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/policy-api.jag
@@ -0,0 +1,49 @@
+<%
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+var uri = request.getRequestURI();
+var uriMatcher = new URIMatcher(String(uri));
+
+var log = new Log("api/policy-api.jag");
+
+var constants = require("/modules/constants.js");
+var dcProps = require('/config/dc-props.js').config();
+var policyModule = require("/modules/policy.js").policyModule;
+
+var result;
+if (uriMatcher.match("/{context}/api/policies/update")) {
+ payload = request.getContent();
+ policyModule.updatePolicyPriorities(payload);
+} else if (uriMatcher.match("/{context}/api/policies/{id}/delete")) {
+ elements = uriMatcher.elements();
+ policyId = elements.id;
+ try {
+ result = policyModule.deletePolicy(policyId);
+ } catch (e) {
+ log.error("Exception occurred while trying to delete policy for id:" + policyId, e);
+ // http status code 500 refers to - Internal Server Error.
+ result = 500;
+ }
+}
+
+// returning the result.
+if (result) {
+ response.content = result;
+}
+%>
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag
index 95d29d05..c1af157b 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag
@@ -128,7 +128,7 @@ function getSensorData(table, column, user, deviceId, from, to) {
try {
fetchedData = statsClient.getDeviceStats(table, column, user, deviceId, from, to);
}catch(error){
- log.info(error);
+ log.error(error);
}
var sensorData = [];
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag
index 8586730a..2b5e8184 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag
@@ -25,7 +25,8 @@ var log = new Log("api/user-api.jag");
var constants = require("/modules/constants.js");
var dcProps = require('/config/dc-props.js').config();
var userModule = require("/modules/user.js").userModule;
-var utility = require("/modules/utility.js").utility;
+var deviceModule = require("/modules/device.js").deviceModule;
+var deviceManagementService = utility.getDeviceManagementService();
var result;
@@ -40,7 +41,15 @@ if (uriMatcher.match("/{context}/api/user/login/")) {
if (log.isDebugEnabled()) {
log.debug("User Logged In : " + user);
}
- response.sendRedirect(constants.WEB_APP_CONTEXT);
+
+ var hasDevcies = (deviceManagementService.getDeviceListOfUser(username).size() >= 1);
+
+ if(hasDevcies){
+ response.sendRedirect(constants.WEB_APP_CONTEXT+"/devices");
+ }else{
+ response.sendRedirect(constants.WEB_APP_CONTEXT);
+ }
+
}, function () {
response.sendRedirect(dcProps.appContext + "login?#auth-failed");
});
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/config/init.js b/modules/distribution/src/repository/jaggeryapps/iotserver/config/init.js
index d492ae79..5fd208f2 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/config/init.js
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/config/init.js
@@ -25,4 +25,4 @@ var carbonServer = new carbonModule.server.Server({
application.put("carbonServer", carbonServer);
var userModule = require("/modules/user.js").userModule;
var utility = require("/modules/utility.js").utility;
-utility.insertAppPermissions(userModule, "init");
\ No newline at end of file
+utility.insertAppPermissions(userModule, "init");
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf b/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf
old mode 100644
new mode 100755
index 9d723c35..420fe87e
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf
@@ -3,17 +3,25 @@
"logLevel": "info",
"initScripts": ["/config/init.js"],
"urlMappings": [
+ {
+ "url" : "/testb/*",
+ "path" : "test.jag"
+ },
{
"url" : "/test/*",
"path" : "test/testExecutor.jag"
},
{
- "url": "/api/device/*",
- "path": "/api/device-api.jag"
+ "url": "/api/device/*",
+ "path": "/api/device-api.jag"
+ },
+ {
+ "url": "/api/devices/*",
+ "path": "/api/device-api.jag"
},
{
- "url": "/api/devices/*",
- "path": "/api/device-api.jag"
+ "url": "/api/operation/*",
+ "path": "/api/operation-api.jag"
},
{
"url": "/api/user/*",
@@ -27,6 +35,10 @@
"url": "/api/stats/*",
"path": "/api/stats-api.jag"
},
+ {
+ "url": "/api/policies/*",
+ "path": "/api/policy-api.jag"
+ },
{
"url": "/sso/login",
"path": "/lib/login.jag"
@@ -44,4 +56,4 @@
"path": "/lib/fuse.jag"
}
]
-}
\ No newline at end of file
+}
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/enrollment.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/enrollment.hbs
old mode 100644
new mode 100755
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid-backup.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid-backup.hbs
new file mode 100755
index 00000000..6c9436ce
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid-backup.hbs
@@ -0,0 +1,44 @@
+
+
+
+
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/raspberrypi.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/raspberrypi.hbs
index 9025c456..11e7f64b 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/raspberrypi.hbs
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/raspberrypi.hbs
@@ -4,5 +4,5 @@
{{/zone}}
{{#zone "body"}}
{{unit "appbar" link="store" title="STORE"}}
- {{unit "devices/raspberrypi"}}
+ {{unit "raspberrypi"}}
{{/zone}}
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/sensebot.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/sensebot.hbs
index 4a4b58c1..a1b5049d 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/sensebot.hbs
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/sensebot.hbs
@@ -4,5 +4,5 @@
{{/zone}}
{{#zone "body"}}
{{unit "appbar" link="store" title="STORE"}}
- {{unit "devices/sensebot"}}
+ {{unit "sensebot"}}
{{/zone}}
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/windows.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/windows.hbs
index cdfa94ba..8b87456d 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/windows.hbs
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/windows.hbs
@@ -4,5 +4,5 @@
{{/zone}}
{{#zone "body"}}
{{unit "appbar" link="store" title="STORE"}}
- {{unit "devices/windows"}}
+ {{unit "windows"}}
{{/zone}}
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/test.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/test.jag
new file mode 100755
index 00000000..c0097b63
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/test.jag
@@ -0,0 +1,12 @@
+<%
+var userModule = require("/modules/user.js").userModule;
+userModule.addPermissions([{key: "device-mgt/", name: "Device Management"}], "");
+userModule.addPermissions([{key: "device-mgt/admin", name: "Device Management Admin"}], "");
+userModule.addPermissions([{key: "device-mgt/user", name: "Device Management User"}], "");
+
+userModule.addPermissions([{key: "devices", name: "Device"}], "device-mgt/admin");
+userModule.addPermissions([{key: "devices", name: "Device"}], "device-mgt/user");
+userModule.addPermissions([{key: "devices/list", name: "List all Devices"}], "device-mgt/admin");
+userModule.addPermissions([{key: "devices/list", name: "List own Devices"}], "device-mgt/user");
+new Log().info(userModule.isAuthorized("/permission/device-mgt/admin/devices/list"));
+%>
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/test/device-spec.js b/modules/distribution/src/repository/jaggeryapps/iotserver/test/device-spec.js
new file mode 100755
index 00000000..f8ce2f3e
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/test/device-spec.js
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+describe('Device Module', function () {
+ var log = new Log();
+ var mobileDB;
+ var cdmDB;
+ var deviceModule = require("/modules/device.js").deviceModule;
+
+ function tearUp() {
+ mobileDB = new Database("MobileDM_DS");
+ cdmDB = new Database("DM_DS");
+ cdmDB.query("insert into dm_device(description, name, date_of_enrollment, date_of_last_update, " +
+ "ownership,status, device_type_id, device_identification, owner, tenant_id ) " +
+ "values ('Galaxy Tab','Admin Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE'," +
+ " 1,'4892813d-0b18-4a02-b7b1-61775257488e', 'admin@wso2.com', '-1234');");
+ cdmDB.query("insert into dm_device(description, name, date_of_enrollment, date_of_last_update, " +
+ "ownership,status, device_type_id, device_identification, owner, tenant_id ) " +
+ "values ('Galaxy Tab','Admin Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE'," +
+ " 1,'4892813d-0b18-4a02-b7b1-61775257488F', 'mdm@wso2.com', '-1234');");
+
+ mobileDB.query("insert into mbl_device (mobile_device_id, push_token, imei ,imsi, os_version, " +
+ "device_model , vendor ,latitude ,longitude , challenge ,token, unlock_token ,serial ) " +
+ "values ('4892813d-0b18-4a02-b7b1-61775257488e', 'sdfsdf', 'cxv', 'vbcb', '4.1', " +
+ "'Galaxy Tab', 'Samsung', '234234234', '4345345234234', 'dfjsdlfk', 'wuweir234', " +
+ "'ksdfjlskfjwer', '234234');");
+ mobileDB.query("insert into mbl_device (mobile_device_id, push_token, imei ,imsi, os_version, " +
+ "device_model , vendor ,latitude ,longitude , challenge ,token, unlock_token ,serial ) " +
+ "values ('4892813d-0b18-4a02-b7b1-61775257488F', 'sdfsdf', 'cxv', 'vbcb', '4.1', " +
+ "'Galaxy Tab', 'Samsung', '234234234', '4345345234234', 'dfjsdlfk', 'wuweir234', " +
+ "'ksdfjlskfjwer', '234234');");
+ }
+
+ function tearDown() {
+ deleteData();
+ mobileDB.close();
+ cdmDB.close();
+ }
+
+ function deleteData(){
+ cdmDB.query("delete from dm_device where device_identification='4892813d-0b18-4a02-b7b1-61775257488e'");
+ cdmDB.query("delete from dm_device where device_identification='4892813d-0b18-4a02-b7b1-61775257488F'");
+ mobileDB.query("delete from mbl_device where mobile_device_id='4892813d-0b18-4a02-b7b1-61775257488e'");
+ mobileDB.query("delete from mbl_device where mobile_device_id='4892813d-0b18-4a02-b7b1-61775257488F'");
+ }
+
+ it('List all Devices - Device Module', function () {
+ try {
+ tearUp();
+ var results = deviceModule.listDevices();
+ expect(results.length).not.toBe(0);
+ } catch (e) {
+ log.error(e);
+ throw e;
+ } finally {
+ tearDown();
+ }
+ });
+ it('List Devices for User - Device Module', function () {
+ try {
+ tearUp();
+ var results = deviceModule.listDevicesForUser("mdm@wso2.com");
+ expect(results.length).toBe(1);
+ } catch (e) {
+ log.error(e);
+ throw e;
+ } finally {
+ tearDown();
+ }
+ });
+ it('Perform operation on the device', function(){
+ try {
+ tearUp();
+ var devices = [{"id": "4892813d-0b18-4a02-b7b1-61775257488e", "type": "android"}];
+ var operation = {"featureName": "DEVICE_LOCK", "type": "COMMAND", "properties": {"enabled": true}}
+ var results = deviceModule.performOperation(devices, operation);
+ expect(results.length).toBe(1);
+ } catch (e) {
+ log.error(e);
+ throw e;
+ } finally {
+ tearDown();
+ }
+ });
+});
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/test/testExecutor.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/test/testExecutor.jag
old mode 100644
new mode 100755
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/test/user-spec.js b/modules/distribution/src/repository/jaggeryapps/iotserver/test/user-spec.js
new file mode 100755
index 00000000..5bbf7444
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/test/user-spec.js
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+describe('Device Module', function () {
+ var log = new Log();
+ var mobileDB;
+ var cdmDB;
+ var deviceModule = require("/modules/device.js").deviceModule;
+ var userModule = require("/modules/user.js").userModule;
+ var constants = require("/modules/constants.js");
+ function tearUp() {
+ mobileDB = new Database("MobileDM_DS");
+ cdmDB = new Database("DM_DS");
+ cdmDB.query("insert into dm_device(description, name, date_of_enrollment, date_of_last_update, " +
+ "ownership,status, device_type_id, device_identification, owner, tenant_id ) " +
+ "values ('Galaxy Tab','Admin Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE'," +
+ " 1,'4892813d-0b18-4a02-b7b1-61775257488e', 'admin@wso2.com', '-1234');");
+ cdmDB.query("insert into dm_device(description, name, date_of_enrollment, date_of_last_update, " +
+ "ownership,status, device_type_id, device_identification, owner, tenant_id ) " +
+ "values ('Galaxy Tab','Admin Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE'," +
+ " 1,'4892813d-0b18-4a02-b7b1-61775257488F', 'mdm@wso2.com', '-1234');");
+
+ mobileDB.query("insert into mbl_device (mobile_device_id, push_token, imei ,imsi, os_version, " +
+ "device_model , vendor ,latitude ,longitude , challenge ,token, unlock_token ,serial ) " +
+ "values ('4892813d-0b18-4a02-b7b1-61775257488e', 'sdfsdf', 'cxv', 'vbcb', '4.1', " +
+ "'Galaxy Tab', 'Samsung', '234234234', '4345345234234', 'dfjsdlfk', 'wuweir234', " +
+ "'ksdfjlskfjwer', '234234');");
+ mobileDB.query("insert into mbl_device (mobile_device_id, push_token, imei ,imsi, os_version, " +
+ "device_model , vendor ,latitude ,longitude , challenge ,token, unlock_token ,serial ) " +
+ "values ('4892813d-0b18-4a02-b7b1-61775257488F', 'sdfsdf', 'cxv', 'vbcb', '4.1', " +
+ "'Galaxy Tab', 'Samsung', '234234234', '4345345234234', 'dfjsdlfk', 'wuweir234', " +
+ "'ksdfjlskfjwer', '234234');");
+ session.put(constants.USER_SESSION_KEY, {"username" : "admin", "domain": "carbon.super", "tenantId": "-1234"});
+ }
+
+ function tearDown() {
+ deleteData();
+ mobileDB.close();
+ cdmDB.close();
+ session.put(constants.USER_SESSION_KEY, null);
+ }
+
+ function deleteData(){
+ cdmDB.query("delete from dm_device where device_identification='4892813d-0b18-4a02-b7b1-61775257488e'");
+ cdmDB.query("delete from dm_device where device_identification='4892813d-0b18-4a02-b7b1-61775257488F'");
+ mobileDB.query("delete from mbl_device where mobile_device_id='4892813d-0b18-4a02-b7b1-61775257488e'");
+ mobileDB.query("delete from mbl_device where mobile_device_id='4892813d-0b18-4a02-b7b1-61775257488F'");
+ }
+
+ it('List all users', function () {
+ try {
+ tearUp();
+ var results = userModule.getUsers();
+ expect(results.length).not.toBe(0);
+ } catch (e) {
+ log.error(e);
+ throw e;
+ } finally {
+ tearDown();
+ }
+ });
+ it('Check permission for user', function () {
+ try {
+ tearUp();
+ expect(userModule.isAuthorized("/permission/device-mgt/user/devices/list")).toBe(true);
+ } catch (e) {
+ log.error(e);
+ throw e;
+ } finally {
+ tearDown();
+ }
+ });
+});
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/tmp/.gitignore b/modules/distribution/src/repository/jaggeryapps/iotserver/tmp/.gitignore
new file mode 100755
index 00000000..50e166d6
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/tmp/.gitignore
@@ -0,0 +1,5 @@
+# Ignore everything in this directory.
+# they are auto generated, should not be committed.
+*
+# Except this file
+!.gitignore
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/token.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/token.jag
new file mode 100755
index 00000000..77778307
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/token.jag
@@ -0,0 +1,4 @@
+<%
+var apiWrapperUtil = require("/modules/api-wrapper-util.js").apiWrapperUtil;
+apiWrapperUtil.refreshToken();
+%>
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.hbs
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.hbs
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.hbs
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.js
new file mode 100644
index 00000000..dae1a137
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.js
@@ -0,0 +1,4 @@
+function onRequest(context){
+ context.sketchPath = "api/device/sketch/download";
+ return context;
+}
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.json
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.json
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.json
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/images/android-thumb.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/images/android-thumb.png
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/images/android-thumb.png
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/images/android-thumb.png
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/images/android.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/images/android.png
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/images/android.png
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/images/android.png
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/store.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/store.json
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/store.json
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/store.json
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.hbs
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.hbs
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.hbs
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.js
new file mode 100644
index 00000000..dae1a137
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.js
@@ -0,0 +1,4 @@
+function onRequest(context){
+ context.sketchPath = "api/device/sketch/download";
+ return context;
+}
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.json
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.json
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.json
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/images/android_sense-thumb.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/images/android_sense-thumb.png
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/images/android_sense-thumb.png
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/images/android_sense-thumb.png
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/images/android_sense.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/images/android_sense.png
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/images/android_sense.png
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/images/android_sense.png
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/store.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/store.json
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/store.json
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/store.json
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs
index e82f3989..4067deba 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs
@@ -41,7 +41,7 @@
- - Device Management
+ - My Devices
{{#if permissions.ADD_USER}}
- User Management
{{/if}}
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js
index 7d0416b2..381b757a 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js
@@ -1,6 +1,6 @@
function onRequest(context) {
var constants = require("/modules/constants.js");
- var user = session.get(constants.USER_SESSION_KEY);
+ var carbonUser = session.get(constants.USER_SESSION_KEY);
var links = {
"users": [],
@@ -18,7 +18,7 @@ function onRequest(context) {
};
var deviceMgtLink = {
- title: "Go back to Device Management",
+ title: "Go back to My Devices",
icon: "fw-left-arrow",
url: "/iotserver/devices"
};
@@ -38,9 +38,12 @@ function onRequest(context) {
links.analytics.push(deviceMgtLink);
links['device-mgt'].push(dashboardLink);
- if (user) {
+ if (!carbonUser) {
+ //user is not logged in
+ }else{
var userModule = require("/modules/user.js").userModule;
var permissions = userModule.getUIPermissions();
+
context.permissions = permissions;
//if (permissions.ADD_USER) {
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/arduino.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.hbs
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/arduino.hbs
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.hbs
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.js
new file mode 100644
index 00000000..dae1a137
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.js
@@ -0,0 +1,4 @@
+function onRequest(context){
+ context.sketchPath = "api/device/sketch/download";
+ return context;
+}
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/arduino.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.json
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/arduino.json
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.json
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/public/images/arduino-thumb.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/public/images/arduino-thumb.png
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/public/images/arduino-thumb.png
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/public/images/arduino-thumb.png
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/public/images/arduino.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/public/images/arduino.png
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/public/images/arduino.png
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/public/images/arduino.png
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/public/store.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/public/store.json
similarity index 100%
rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/public/store.json
rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/public/store.json
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/device-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/device-listing.hbs
index 8dddd607..17444875 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/device-listing.hbs
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/device-listing.hbs
@@ -93,7 +93,7 @@
Device was successfully updated.
@@ -165,4 +165,4 @@
{{#zone "bottomJs"}}
-{{/zone}}
\ No newline at end of file
+{{/zone}}
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js
index 097882cd..b2663ec3 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js
@@ -253,24 +253,25 @@ function attachEvents() {
$("a#remove-device-yes-link").click(function () {
invokerUtil.get(
removeDeviceAPI,
- function (data) {
- if (data == 200) {
- $("#" + username).addClass("hide");
+ function (data,txtStatus,jqxhr) {
+ var status = jqxhr.status;
+ if (status == 200) {
$(modalPopupContent).html($('#remove-device-200-content').html());
- $("a#remove-device-200-link").click(function () {
+ $('div[data-deviceid="' + deviceId + '"]').remove();
+ $("a#remove-device-200-link").click(function () {
hidePopup();
});
- } else if (data == 400) {
+ } else if (status == 400) {
$(modalPopupContent).html($('#remove-device-400-content').html());
$("a#remove-device-400-link").click(function () {
hidePopup();
});
- } else if (data == 403) {
+ } else if (status == 403) {
$(modalPopupContent).html($('#remove-device-403-content').html());
$("a#remove-device-403-link").click(function () {
hidePopup();
});
- } else if (data == 409) {
+ } else if (status == 409) {
$(modalPopupContent).html($('#remove-device-409-content').html());
$("a#remove-device-409-link").click(function () {
hidePopup();
@@ -308,28 +309,31 @@ function attachEvents() {
showPopup();
$("a#edit-device-yes-link").click(function () {
- var device={"device":{"name" : $('#edit-device-name').val()}};
+ var newDeviceName = $('#edit-device-name').val();
+ var device={"device":{"name" : newDeviceName}};
invokerUtil.post(
editDeviceAPI,
device,
- function (data) {
- if (data == 200) {
- $("#" + username).addClass("hide");
+ function (data,txtStatus,jqxhr) {
+ var status = jqxhr.status;
+ if (status == 200) {
$(modalPopupContent).html($('#edit-device-200-content').html());
+ console.log("asdsdasda" + newDeviceName);
+ $("div[data-deviceid='"+deviceId+"'] .ast-name").html(newDeviceName);
$("a#edit-device-200-link").click(function () {
hidePopup();
});
- } else if (data == 400) {
+ } else if (status == 400) {
$(modalPopupContent).html($('#edit-device-400-content').html());
$("a#edit-device-400-link").click(function () {
hidePopup();
});
- } else if (data == 403) {
+ } else if (status == 403) {
$(modalPopupContent).html($('#edit-device-403-content').html());
$("a#edit-device-403-link").click(function () {
hidePopup();
});
- } else if (data == 409) {
+ } else if (status == 409) {
$(modalPopupContent).html($('#edit-device-409-content').html());
$("a#edit-device-409-link").click(function () {
hidePopup();
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js.save b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js.save
new file mode 100644
index 00000000..37be0302
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js.save
@@ -0,0 +1,353 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+(function () {
+ var cache = {};
+ var permissionSet = {};
+ var validateAndReturn = function (value) {
+ return (value == undefined || value == null) ? "Unspecified" : value;
+ };
+ Handlebars.registerHelper("deviceMap", function (device) {
+ device.owner = validateAndReturn(device.owner);
+ device.ownership = validateAndReturn(device.ownership);
+ var arr = device.properties;
+ if (arr) {
+ device.properties = arr.reduce(function (total, current) {
+ total[current.name] = validateAndReturn(current.value);
+ return total;
+ }, {});
+ }
+ });
+
+ //This method is used to setup permission for device listing
+ $.setPermission = function (permission) {
+ permissionSet[permission] = true;
+ };
+
+ $.hasPermission = function (permission) {
+ return permissionSet[permission];
+ };
+})();
+
+/*
+ * Setting-up global variables.
+ */
+var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
+var assetContainer = "#ast-container";
+
+/*
+ * DOM ready functions.
+ */
+$(document).ready(function () {
+ /* Adding selected class for selected devices */
+ $(deviceCheckbox).each(function () {
+ addDeviceSelectedClass(this);
+ });
+
+ var i;
+ var permissionList = $("#permission").data("permission");
+ for (i = 0; i < permissionList.length; i++) {
+ $.setPermission(permissionList[i]);
+ }
+
+ /* for device list sorting drop down */
+ $(".ctrl-filter-type-switcher").popover({
+ html: true,
+ content: function () {
+ return $("#content-filter-types").html();
+ }
+ });
+});
+
+/*
+ * On Select All Device button click function.
+ *
+ * @param button: Select All Device button
+ */
+function selectAllDevices(button) {
+ if (!$(button).data('select')) {
+ $(deviceCheckbox).each(function (index) {
+ $(this).prop('checked', true);
+ addDeviceSelectedClass(this);
+ });
+ $(button).data('select', true);
+ $(button).html('Deselect All Devices');
+ } else {
+ $(deviceCheckbox).each(function (index) {
+ $(this).prop('checked', false);
+ addDeviceSelectedClass(this);
+ });
+ $(button).data('select', false);
+ $(button).html('Select All Devices');
+ }
+}
+
+/*
+ * On listing layout toggle buttons click function.
+ *
+ * @param view: Selected view type
+ * @param selection: Selection button
+ */
+function changeDeviceView(view, selection) {
+ $(".view-toggle").each(function () {
+ $(this).removeClass("selected");
+ });
+ $(selection).addClass("selected");
+ if (view == "list") {
+ $(assetContainer).addClass("list-view");
+ } else {
+ $(assetContainer).removeClass("list-view");
+ }
+}
+
+/*
+ * Add selected style class to the parent element function.
+ *
+ * @param checkbox: Selected checkbox
+ */
+function addDeviceSelectedClass(checkbox) {
+ if ($(checkbox).is(":checked")) {
+ $(checkbox).closest(".ctrl-wr-asset").addClass("selected device-select");
+ } else {
+ $(checkbox).closest(".ctrl-wr-asset").removeClass("selected device-select");
+ }
+}
+function loadDevices(searchType, searchParam) {
+ var deviceListing = $("#device-listing");
+ var deviceListingSrc = deviceListing.attr("src");
+ var imageResource = deviceListing.data("image-resource");
+ $.template("device-listing", deviceListingSrc, function (template) {
+ var serviceURL;
+ if ($.hasPermission("LIST_DEVICES")) {
+ serviceURL = "/iotserver/api/devices/all";
+ } else if ($.hasPermission("LIST_OWN_DEVICES")) {
+ //Get authenticated users devices
+ serviceURL = "/iotserver/api/devices/all";
+ } else {
+ $("#ast-container").html("Permission denied");
+ return;
+ }
+ if (searchParam) {
+ if (searchType == "users") {
+ serviceURL = serviceURL + "?user=" + searchParam;
+ } else if (searchType == "user-roles") {
+ serviceURL = serviceURL + "?role=" + searchParam;
+ } else {
+ serviceURL = serviceURL + "?type=" + searchParam;
+ }
+ }
+ var successCallback = function (data) {
+ data = JSON.parse(data);
+ var viewModel = {};
+ viewModel.devices = data.data;
+ viewModel.imageLocation = imageResource;
+ if(!data.data || data.data.length <= 0){
+ $("#ast-container").html($("#no-devices-div-content").html());
+ } else {
+ var content = template(viewModel);
+ $("#ast-container").html(content);
+ /*
+ * On device checkbox select add parent selected style class
+ */
+ $(deviceCheckbox).click(function () {
+ addDeviceSelectedClass(this);
+ });
+ attachEvents();
+ formatDates();
+ }
+ };
+ invokerUtil.get(serviceURL,
+ successCallback, function (message) {
+ console.log(message);
+ });
+ });
+}
+$(document).ready(function () {
+ loadDevices();
+});
+
+function formatDates(){
+ $(".formatDate").each(function(){
+ var timeStamp = $(this).html();
+ $(this).html(new Date(parseInt(timeStamp)).toUTCString());
+ });
+}
+
+/**
+ * Sorting function of users
+ * listed on User Management page in WSO2 MDM Console.
+ */
+$(function () {
+ var sortableElem = '.wr-sortable';
+ $(sortableElem).sortable({
+ beforeStop: function () {
+ var sortedIDs = $(this).sortable('toArray');
+ console.log(sortedIDs);
+ }
+ });
+ $(sortableElem).disableSelection();
+});
+
+var modalPopup = ".wr-modalpopup";
+var modalPopupContainer = modalPopup + " .modalpopup-container";
+var modalPopupContent = modalPopup + " .modalpopup-content";
+var body = "body";
+
+/*
+ * set popup maximum height function.
+ */
+function setPopupMaxHeight() {
+ $(modalPopupContent).css('max-height', ($(body).height() - ($(body).height() / 100 * 30)));
+ $(modalPopupContainer).css('margin-top', (-($(modalPopupContainer).height() / 2)));
+}
+
+/*
+ * show popup function.
+ */
+function showPopup() {
+ $(modalPopup).show();
+ setPopupMaxHeight();
+}
+
+/*
+ * hide popup function.
+ */
+function hidePopup() {
+ $(modalPopupContent).html('');
+ $(modalPopup).hide();
+}
+
+
+/**
+ * Following functions should be triggered after AJAX request is made.
+ */
+function attachEvents() {
+ /**
+ * Following click function would execute
+ * when a user clicks on "Remove" link
+ * on Device Management page in WSO2 MDM Console.
+ */
+ $("a.remove-device-link").click(function () {
+ var deviceId = $(this).data("deviceid");
+ var deviceType = $(this).data("devicetype");
+ var removeDeviceAPI = "/iotserver/api/device/" + deviceType + "/" + deviceId + "/remove";
+
+ $(modalPopupContent).html($('#remove-device-modal-content').html());
+ showPopup();
+
+ $("a#remove-device-yes-link").click(function () {
+ invokerUtil.get(
+ removeDeviceAPI,
+ function (data,txtStatus,jqxhr) {
+ var status = jqxhr.status;
+ if (status == 200) {
+ $(modalPopupContent).html($('#remove-device-200-content').html());
+ $("a#remove-device-200-link").click(function () {
+ hidePopup();
+ });
+ $("")
+ } else if (status == 400) {
+ $(modalPopupContent).html($('#remove-device-400-content').html());
+ $("a#remove-device-400-link").click(function () {
+ hidePopup();
+ });
+ } else if (status == 403) {
+ $(modalPopupContent).html($('#remove-device-403-content').html());
+ $("a#remove-device-403-link").click(function () {
+ hidePopup();
+ });
+ } else if (status == 409) {
+ $(modalPopupContent).html($('#remove-device-409-content').html());
+ $("a#remove-device-409-link").click(function () {
+ hidePopup();
+ });
+ }
+ },
+ function () {
+ $(modalPopupContent).html($('#remove-device-unexpected-error-content').html());
+ $("a#remove-device-unexpected-error-link").click(function () {
+ hidePopup();
+ });
+ }
+ );
+ });
+
+ $("a#remove-device-cancel-link").click(function () {
+ hidePopup();
+ });
+
+ });
+
+ /**
+ * Following click function would execute
+ * when a user clicks on "Edit" link
+ * on Device Management page in WSO2 MDM Console.
+ */
+ $("a.edit-device-link").click(function () {
+ var deviceId = $(this).data("deviceid");
+ var deviceType = $(this).data("devicetype");
+ var deviceName = $(this).data("devicename");
+ var editDeviceAPI = "/iotserver/api/device/" + deviceType + "/" + deviceId + "/update";
+
+ $(modalPopupContent).html($('#edit-device-modal-content').html());
+ $('#edit-device-name').val(deviceName);
+ showPopup();
+
+ $("a#edit-device-yes-link").click(function () {
+ var device={"device":{"name" : $('#edit-device-name').val()}};
+ invokerUtil.post(
+ editDeviceAPI,
+ device,
+ function (data,txtStatus,jqxhr) {
+ var status = jqxhr.status;
+ if (status == 200) {
+ $(modalPopupContent).html($('#edit-device-200-content').html());
+ $("a#edit-device-200-link").click(function () {
+ hidePopup();
+ });
+ } else if (status == 400) {
+ $(modalPopupContent).html($('#edit-device-400-content').html());
+ $("a#edit-device-400-link").click(function () {
+ hidePopup();
+ });
+ } else if (status == 403) {
+ $(modalPopupContent).html($('#edit-device-403-content').html());
+ $("a#edit-device-403-link").click(function () {
+ hidePopup();
+ });
+ } else if (status == 409) {
+ $(modalPopupContent).html($('#edit-device-409-content').html());
+ $("a#edit-device-409-link").click(function () {
+ hidePopup();
+ });
+ }
+ },
+ function () {
+ $(modalPopupContent).html($('#edit-device-unexpected-error-content').html());
+ $("a#edit-device-unexpected-error-link").click(function () {
+ hidePopup();
+ });
+ }
+ );
+ });
+
+ $("a#edit-device-cancel-link").click(function () {
+ hidePopup();
+ });
+ });
+}
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/device-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/device-listing.hbs
index 767aab17..0ffc884e 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/device-listing.hbs
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/device-listing.hbs
@@ -1,6 +1,6 @@
{{#each devices}}
{{deviceMap this}}
-
+