diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag new file mode 100644 index 00000000..fb9535c1 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag @@ -0,0 +1,200 @@ +<% +/* + * 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/group-api.jag"); + +var constants = require("/modules/constants.js"); +var dcProps = require('/config/dc-props.js').config(); + +var carbon = require('carbon'); +var carbonHttpsServletTransport = carbon.server.address('https'); +var deviceCloudService = carbonHttpsServletTransport + "/devicecloud/group_manager"; + +var user = session.get(constants.USER_SESSION_KEY); +if (!user) { + response.sendRedirect(dcProps.appContext + "login?#login-required"); + exit();//stop execution +} + +var result; +var endPoint; +var data; +var groupId; + +if (uriMatcher.match("/{context}/api/group/add")) { + + var name = request.getParameter("name"); + var description = request.getParameter("description"); + + //URL: POST https://localhost:9443/devicecloud/group_manager/group/add + endPoint = deviceCloudService + "/group/add"; + data = {"name": name, "username": user.username, "description": description}; + result = post(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/update")) { + + groupId = uriMatcher.elements().groupId; + name = request.getParameter("name"); + description = request.getParameter("description"); + + //URL: PUT https://localhost:9443/devicecloud/group_manager/group/id/{groupId} + endPoint = deviceCloudService + "id/" + groupId; + data = {"name": name, "username": user.username, "description": description}; + result = put(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/remove")) { + + groupId = uriMatcher.elements().groupId; + + //URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId} + endPoint = deviceCloudService + "id/" + groupId; + data = {"username": user.username}; + result = del(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}")) { + + groupId = uriMatcher.elements().groupId; + + //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId} + endPoint = deviceCloudService + "id/" + groupId; + data = {"username": user.username}; + result = get(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/name/{groupName}")) { + + //URL: GET https://localhost:9443/devicecloud/group_manager/group/name/{name} + endPoint = deviceCloudService + "name/" + uriMatcher.elements().groupName; + data = {"username": user.username}; + result = get(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/all")) { + + //URL: GET https://localhost:9443/devicecloud/group_manager/group/all + endPoint = deviceCloudService + "/group/all"; + data = {"username": user.username}; + result = get(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/all/count")) { + + //URL: GET https://localhost:9443/devicecloud/group_manager/group/all/count + endPoint = deviceCloudService + "/group/all/count"; + data = {"username": user.username}; + result = get(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/share")) { + + groupId = uriMatcher.elements().groupId; + var shareUser = request.getParameter("shareUser"); + role = request.getParameter("role"); + + //URL: PUT https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share + endPoint = deviceCloudService + "/group/id/" + groupId + "/share"; + data = {"username": user.username, "shareUser":shareUser, "role":role}; + result = post(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/share")) { + + groupId = uriMatcher.elements().groupId; + var unShareUser = request.getParameter("unShareUser"); + role = request.getParameter("role"); + + //URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share + endPoint = deviceCloudService + "/group/id/" + groupId + "/share"; + data = {"username": user.username, "unShareUser":unShareUser, "role":role}; + result = del(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/add")) { + + groupId = uriMatcher.elements().groupId; + var permissions = request.getParameter("permissions"); + role = request.getParameter("role"); + + //URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role + endPoint = deviceCloudService + "/group/id/" + groupId + "/role"; + data = {"username": user.username, "permissions":permissions, "role":role}; + result = post(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/delete")) { + + groupId = uriMatcher.elements().groupId; + role = request.getParameter("role"); + + //URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role + endPoint = deviceCloudService + "/group/id/" + groupId + "/role"; + data = {"username": user.username, "role":role}; + result = del(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/all")) { + + groupId = uriMatcher.elements().groupId; + + //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role/all + endPoint = deviceCloudService + "/group/id/" + groupId + "/role/all"; + data = {"username": user.username}; + result = get(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/{userId}/role/all")) { + + groupId = uriMatcher.elements().groupId; + var userId = uriMatcher.elements().userId; + + //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/{user}/role/all + endPoint = deviceCloudService + "/group/id/" + groupId + "/" + userId +"/role/all"; + data = {"username": user.username}; + result = get(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/user/all")) { + + groupId = uriMatcher.elements().groupId; + + //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/user/all + endPoint = deviceCloudService + "/group/id/" + groupId + "/user/all"; + data = {"username": user.username}; + result = get(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/device/all")) { + + groupId = uriMatcher.elements().groupId; + + //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/all + endPoint = deviceCloudService + "/group/id/" + groupId + "/device/all"; + data = {"username": user.username}; + result = get(endPoint, data, "json"); + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/device/assign")) { + + groupId = uriMatcher.elements().groupId; + var deviceId = request.getParameter("deviceId"); + var deviceType = request.getParameter("deviceType"); + + //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/assign + endPoint = deviceCloudService + "/group/id/" + groupId + "/device/assign"; + data = {"username": user.username, "deviceId":deviceId, "deviceType":deviceType}; + result = put(endPoint, data, "json"); + +} + +// returning the result. +if (result) { + print(result); +} +%> diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf b/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf index 420fe87e..2771f3c3 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf @@ -19,6 +19,10 @@ "url": "/api/devices/*", "path": "/api/device-api.jag" }, + { + "url": "/api/group/*", + "path": "/api/group-api.jag" + }, { "url": "/api/operation/*", "path": "/api/operation-api.jag" diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/index.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/index.hbs index ea9cd1a3..c2ec062f 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/index.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/index.hbs @@ -5,7 +5,7 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="device-mgt" title="My Devices"}} - {{unit "extended-search-box"}} + {{unit "extended-search-box" item="Device"}} {{unit "operation-mod"}}
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/group.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/group.hbs new file mode 100644 index 00000000..3246f4c5 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/group.hbs @@ -0,0 +1,23 @@ +{{authorized}} +{{layout "fluid"}} +{{#zone "title"}} + Groups +{{/zone}} +{{#zone "body"}} + {{unit "appbar" link="group-mgt" title="My Groups"}} + {{unit "extended-search-box" item="Group"}} + {{unit "operation-mod"}} +
+
+ +
+
+ +
+ {{unit "operation-bar"}} + {{unit "group-listing"}} +
+ +
+
+{{/zone}} \ No newline at end of file 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 381b757a..56288fb8 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js @@ -7,6 +7,7 @@ function onRequest(context) { "policies": [], "profiles": [], "device-mgt": [], + "group-mgt": [], "store": [], "dashboard": [], "analytics" : [] @@ -37,6 +38,7 @@ function onRequest(context) { links.store.push(storeLink); links.analytics.push(deviceMgtLink); links['device-mgt'].push(dashboardLink); + links['group-mgt'].push(dashboardLink); if (!carbonUser) { //user is not logged in @@ -74,6 +76,13 @@ function onRequest(context) { url: "/iotserver/devices/add-device" }); } + if (permissions.ADD_DEVICE) { + links["group-mgt"].push({ + title: "Add Group", + icon: "fw-add", + url: "/iotserver/group#add-device" + }); + } }// end-if-user context.currentActions = links[context.link]; diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/extended-search-box/extended-search-box.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/extended-search-box/extended-search-box.hbs index 62bace1d..edad07c6 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/extended-search-box/extended-search-box.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/extended-search-box/extended-search-box.hbs @@ -71,7 +71,7 @@
- +
@@ -79,9 +79,9 @@
- Select All Devices - - + Select All {{item}}s + +
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/extended-search-box/public/js/extended-search-box.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/extended-search-box/public/js/extended-search-box.js index 3f6ea637..3ba305e0 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/extended-search-box/public/js/extended-search-box.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/extended-search-box/public/js/extended-search-box.js @@ -51,7 +51,7 @@ $(document).ready(function(){ $(searchBtn).click(function(){ var input = $(searchField).html(); var searchType = $(searchField).data("search-type"); - loadDevices(searchType, input); + loadGroups(searchType, input); }); }); @@ -123,7 +123,7 @@ function containerUpdate(asset){ function selectAsset(asset){ var platformType = $(asset).data("type"); loadOperationBar(platformType); - loadDevices("type", platformType); + loadGroups("type", platformType); //$(tagsContainer +' span').each(function(){ // if($(this).attr('level') == $(asset).attr('level')){ // removeTags(this); @@ -218,5 +218,5 @@ function removeTags(tag){ $(this).remove(); }); unloadOperationBar(); - loadDevices(); + loadGroups(); } diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.hbs new file mode 100644 index 00000000..92c4f7e4 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.hbs @@ -0,0 +1,174 @@ +{{#zone "main"}} +
+
+ +
+
+
+
+ +
+
+ {{unit "operation-bar"}} +
+
+ + + +
+
+
+ +
+
+
Owner: {{group.ownerId}}
+
Date of Enrollment:
{{group.enrollment}}
+
+
+
+ +
+ + +
+ +
+ {{#if group.viewModel.BatteryLevel}} +
+
+
BATTERY
+
+
+
{{group.viewModel.BatteryLevel}}%
+
+
+
+ {{/if}} + + {{#if group.viewModel.DeviceCapacity}} +
+
+
STORAGE
+
+
+
{{group.viewModel.DeviceCapacityPercentage}}%{{group.viewModel.DeviceCapacityUsed}} GB Free
+
+
+
+ {{/if}} + {{#if group.viewModel.internal_memory.FreeCapacity}} +
+
+
LOCAL STORAGE
+
+
+
{{group.viewModel.internal_memory.DeviceCapacityPercentage}}%{{group.viewModel.internal_memory.FreeCapacity}} GB Free
+
+
+
+ {{/if}} + {{#if group.viewModel.external_memory.FreeCapacity}} +
+
+
EXTERNAL STORAGE
+
+
+
{{group.viewModel.external_memory.DeviceCapacityPercentage}}%{{group.viewModel.external_memory.FreeCapacity}} GB Free
+
+
+
+ {{/if}} +
+ +
+ + +
+ + + + + +
+ +
+
+ Not available yet +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+
+
+
+ +{{/zone}} +{{#zone "bottomJs"}} + + +{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.js new file mode 100644 index 00000000..ac6935bd --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.js @@ -0,0 +1,55 @@ +function onRequest(context) { + var uri = request.getRequestURI(); + var uriMatcher = new URIMatcher(String(uri)); + var isMatched = uriMatcher.match("/{context}/group/id/{groupId}"); + if (isMatched) { + var matchedElements = uriMatcher.elements(); + var groupId = matchedElements.groupId; + context.groupId = groupId; + //var group = deviceModule.viewDevice(deviceType, deviceId); + //if (device){ + // var viewModel = {}; + // var deviceInfo = device.properties.DEVICE_INFO; + // if (deviceInfo != undefined && String(deviceInfo.toString()).length > 0){ + // deviceInfo = JSON.parse(deviceInfo); + // if (device.type == "ios"){ + // viewModel.imei = device.properties.IMEI; + // viewModel.phoneNumber = deviceInfo.PhoneNumber; + // viewModel.udid = deviceInfo.UDID; + // viewModel.BatteryLevel = Math.round(deviceInfo.BatteryLevel * 100); + // viewModel.DeviceCapacity = Math.round(deviceInfo.DeviceCapacity * 100) / 100; + // viewModel.AvailableDeviceCapacity = Math.round(deviceInfo.AvailableDeviceCapacity * 100) / 100; + // viewModel.DeviceCapacityUsed = Math.round((viewModel.DeviceCapacity + // - viewModel.AvailableDeviceCapacity) * 100) / 100; + // viewModel.DeviceCapacityPercentage = Math.round(viewModel.DeviceCapacityUsed + // / viewModel.DeviceCapacity * 10000) /100; + // }else if(device.type == "android"){ + // viewModel.imei = device.properties.IMEI; + // viewModel.model = device.properties.DEVICE_MODEL; + // viewModel.vendor = device.properties.VENDOR; + // viewModel.internal_memory = {}; + // viewModel.external_memory = {}; + // viewModel.location = { + // latitude: device.properties.LATITUDE, + // longitude: device.properties.LONGITUDE + // }; + // viewModel.BatteryLevel = deviceInfo.BATTERY_LEVEL; + // viewModel.internal_memory.FreeCapacity = Math.round((deviceInfo.INTERNAL_TOTAL_MEMORY - + // deviceInfo.INTERNAL_AVAILABLE_MEMORY) * 100) / 100; + // viewModel.internal_memory.DeviceCapacityPercentage = Math.round(deviceInfo.INTERNAL_AVAILABLE_MEMORY + // / deviceInfo.INTERNAL_TOTAL_MEMORY * 10000) / 100; + // viewModel.external_memory.FreeCapacity = Math.round((deviceInfo.EXTERNAL_TOTAL_MEMORY - + // deviceInfo.EXTERNAL_AVAILABLE_MEMORY) * 100) / 100; + // viewModel.external_memory.DeviceCapacityPercentage = Math.round(deviceInfo.EXTERNAL_AVAILABLE_MEMORY + // /deviceInfo.EXTERNAL_TOTAL_MEMORY * 10000) /100; + // } + // viewModel.enrollment = device.enrollment; + // device.viewModel = viewModel; + // } + //} + context.group = groupId; + } else { + response.sendError(404); + } + return context; +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.json new file mode 100644 index 00000000..3dbff381 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.json @@ -0,0 +1,3 @@ +{ + "predicate": "false" +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/public/img/graph.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/public/img/graph.png new file mode 100644 index 00000000..dd819ef4 Binary files /dev/null and b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/public/img/graph.png differ diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/public/img/group-icon.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/public/img/group-icon.png new file mode 100644 index 00000000..ac34c1b2 Binary files /dev/null and b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/public/img/group-icon.png differ diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/public/js/group-detail.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/public/js/group-detail.js new file mode 100644 index 00000000..c453c889 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/public/js/group-detail.js @@ -0,0 +1,69 @@ +/* + * 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 formatDates(){ + $(".formatDate").each(function(){ + var timeStamp = $(this).html(); + $(this).html(new Date(parseInt(timeStamp)).toUTCString()); + }); +} + +(function () { + var deviceId = $(".device-id"); + var deviceIdentifier = deviceId.data("deviceid"); + var deviceType = deviceId.data("type"); + var payload = [deviceIdentifier]; + if (deviceType == "ios") { + var serviceUrl = "/ios/operation/deviceinfo"; + } else if (deviceType == "android") { + var serviceUrl = "/mdm-android-agent/operation/device-info"; + } + invokerUtil.post(serviceUrl, payload, + function(message){ + console.log(message); + }, function (message) { + console.log(message); + }); + $(document).ready(function(){ + loadOperationBar(deviceType); + loadMap(); + formatDates(); + }); + function loadMap(){ + var map; + function initialize() { + var mapOptions = { + zoom: 18 + }; + var lat = 6.9098591; + var long = 79.8523753; + map = new google.maps.Map(document.getElementById('device-location'), + mapOptions); + + var pos = new google.maps.LatLng(lat, + long); + var marker = new google.maps.Marker({ + position: pos, + map: map + }); + + map.setCenter(pos); + } + google.maps.event.addDomListener(window, 'load', initialize); + } +}()); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.hbs new file mode 100644 index 00000000..18d3f6a3 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.hbs @@ -0,0 +1,168 @@ +{{#zone "main"}} + + +
+ +
+
+

Loading...

+
+
+ +
+ +
+ +
+
+

You don't have any Groups registered at the moment.

+

+ + + + + + Add New Group + +

+
+
+ +
+ +
+
+
+
+

Do you really want to remove this group from your Group List?

+ +
+
+
+
+ +
+
+
+
+

Group was successfully removed.

+ +
+
+
+
+ +
+
+
+
+

Please enter new name for the group?

+
+
+ +
+ +
+
+
+
+ +
+
+
+
+

Group was successfully updated.

+ +
+
+
+
+ +
+
+
+
+

Exception at backend. Try Later.

+ +
+
+
+
+ +
+
+
+
+

Action not permitted.

+ +
+
+
+
+ +
+
+
+
+

Group does not exist.

+ +
+
+
+
+ +
+
+
+
+

Group does not exist.

+ +
+
+
+
+{{/zone}} +{{#zone "bottomJs"}} + + +{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.js new file mode 100644 index 00000000..96820097 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.js @@ -0,0 +1,12 @@ +function onRequest(context){ + //var userModule = require("/modules/user.js").userModule; + var permissions = []; + //if(userModule.isAuthorized("/permission/device-mgt/admin/devices/list")){ + // permissions.push("LIST_GROUPS"); + //}else if(userModule.isAuthorized("/permission/device-mgt/user/devices/list")){ + // permissions.push("LIST_OWN_GROUPS"); + //} + permissions.push("LIST_GROUPS"); + context.permissions = stringify(permissions); + return context; +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.json new file mode 100644 index 00000000..3dbff381 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.json @@ -0,0 +1,3 @@ +{ + "predicate": "false" +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/images/group-icon.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/images/group-icon.png new file mode 100644 index 00000000..ac34c1b2 Binary files /dev/null and b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/images/group-icon.png differ diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js new file mode 100644 index 00000000..bcf97385 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js @@ -0,0 +1,343 @@ +/* + * 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("groupMap", function (group) { + group.ownerId = validateAndReturn(group.ownerId); + }); + + //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 groupCheckbox = "#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 */ + $(groupCheckbox).each(function () { + addGroupSelectedClass(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(); + } + }); + changeGroupView('grid', this); +}); + +/* + * On Select All Group button click function. + * + * @param button: Select All Group button + */ +function selectAllGroups(button) { + if (!$(button).data('select')) { + $(groupCheckbox).each(function (index) { + $(this).prop('checked', true); + addGroupSelectedClass(this); + }); + $(button).data('select', true); + $(button).html('Deselect All Groups'); + } else { + $(groupCheckbox).each(function (index) { + $(this).prop('checked', false); + addGroupSelectedClass(this); + }); + $(button).data('select', false); + $(button).html('Select All Groups'); + } +} + +/* + * On listing layout toggle buttons click function. + * + * @param view: Selected view type + * @param selection: Selection button + */ +function changeGroupView(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 addGroupSelectedClass(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 loadGroups(searchType, searchParam) { + var groupListing = $("#group-listing"); + var groupListingSrc = groupListing.attr("src"); + var imageResource = groupListing.data("image-resource"); + $.template("group-listing", groupListingSrc, function (template) { + var serviceURL; + if ($.hasPermission("LIST_GROUPS")) { + serviceURL = "/iotserver/api/group/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.groups = data.data; + viewModel.imageLocation = imageResource; + if(!data.data || data.data.length <= 0){ + $("#ast-container").html($("#no-groups-div-content").html()); + } else { + var content = template(viewModel); + $("#ast-container").html(content); + /* + * On group checkbox select add parent selected style class + */ + $(groupCheckbox).click(function () { + addGroupSelectedClass(this); + }); + attachEvents(); + formatDates(); + } + }; + invokerUtil.get(serviceURL, + successCallback, function (message) { + console.log(message); + }); + }); +} +$(document).ready(function () { + loadGroups(); +}); + +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-group-link").click(function () { + var groupId = $(this).data("groupid"); + var removeGroupApi = "/iotserver/api/group/id/" + groupId + "/remove"; + + $(modalPopupContent).html($('#remove-group-modal-content').html()); + showPopup(); + + $("a#remove-group-yes-link").click(function () { + invokerUtil.get( + removeGroupApi, + function (data,txtStatus,jqxhr) { + var status = jqxhr.status; + if (status == 200) { + $(modalPopupContent).html($('#remove-group-200-content').html()); + $('div[data-group="' + groupId + '"]').remove(); + $("a#remove-group-200-link").click(function () { + hidePopup(); + }); + } else if (status == 400) { + $(modalPopupContent).html($('#remove-group-400-content').html()); + $("a#remove-group-400-link").click(function () { + hidePopup(); + }); + } else if (status == 403) { + $(modalPopupContent).html($('#remove-group-403-content').html()); + $("a#remove-group-403-link").click(function () { + hidePopup(); + }); + } else if (status == 409) { + $(modalPopupContent).html($('#remove-group-409-content').html()); + $("a#remove-group-409-link").click(function () { + hidePopup(); + }); + } + }, + function () { + $(modalPopupContent).html($('#remove-group-unexpected-error-content').html()); + $("a#remove-group-unexpected-error-link").click(function () { + hidePopup(); + }); + } + ); + }); + + $("a#remove-group-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-group-link").click(function () { + var groupId = $(this).data("groupid"); + var groupName = $(this).data("groupname"); + var editGroupApi = "/iotserver/api/group/id/" + groupId + "/update"; + + $(modalPopupContent).html($('#edit-group-modal-content').html()); + $('#edit-group-name').val(groupName); + showPopup(); + + $("a#edit-group-yes-link").click(function () { + var newGroupName = $('#edit-group-name').val(); + var group={"group":{"name" : newGroupName}}; + invokerUtil.post( + editGroupApi, + group, + function (data,txtStatus,jqxhr) { + var status = jqxhr.status; + if (status == 200) { + $(modalPopupContent).html($('#edit-group-200-content').html()); + $("div[data-groupid='"+groupId+"'] .ast-name").html(newGroupName); + $("a#edit-group-200-link").click(function () { + hidePopup(); + }); + } else if (status == 400) { + $(modalPopupContent).html($('#edit-group-400-content').html()); + $("a#edit-group-400-link").click(function () { + hidePopup(); + }); + } else if (status == 403) { + $(modalPopupContent).html($('#edit-group-403-content').html()); + $("a#edit-group-403-link").click(function () { + hidePopup(); + }); + } else if (status == 409) { + $(modalPopupContent).html($('#edit-group-409-content').html()); + $("a#edit-group-409-link").click(function () { + hidePopup(); + }); + } + }, + function () { + $(modalPopupContent).html($('#edit-group-unexpected-error-content').html()); + $("a#edit-group-unexpected-error-link").click(function () { + hidePopup(); + }); + } + ); + }); + + $("a#edit-group-cancel-link").click(function () { + hidePopup(); + }); + }); +} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/templates/group-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/templates/group-listing.hbs new file mode 100644 index 00000000..9bba907c --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/templates/group-listing.hbs @@ -0,0 +1,54 @@ +{{#each groups}} + {{groupMap this}} +
+
+ +
+
+ +
+
+
+ +
+
+ +{{/each}} + +
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/custom-desktop.css b/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/custom-desktop.css index 1f361a96..beed45c6 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/custom-desktop.css +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/custom-desktop.css @@ -250,23 +250,23 @@ a.ast-type-item:hover { } @media (min-width: 768px){ - .ctrl-wr-asset { width: 24%; } + .ctrl-wr-asset { width: 30%; } } @media (min-width: 992px){ - .ctrl-wr-asset { width: 19%; } + .ctrl-wr-asset { width: 25%; } } @media (min-width:1300px){ - .ctrl-wr-asset { width: 13%; } + .ctrl-wr-asset { width: 19%; } } @media (min-width:1500px){ - .ctrl-wr-asset { width: 11.5%; } + .ctrl-wr-asset { width: 17.5%; } } @media (min-width:1800px){ - .ctrl-wr-asset { width: 9%; } + .ctrl-wr-asset { width: 15%; } } .ctrl-wr-asset.selected {