Commit before unified framework changes [Unstable]

application-manager-new
charithag 9 years ago
parent 4ee7427ec1
commit 35aaffd7e0

@ -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);
}
%>

@ -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"

@ -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"}}
<div class="wr-device-list row">
<div class="wr-hidden-operations wr-advance-operations">

@ -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"}}
<div class="wr-device-list row">
<div class="wr-hidden-operations wr-advance-operations">
</div>
<div class="col-md-12 wr-page-content">
<!-- content -->
<div>
{{unit "operation-bar"}}
{{unit "group-listing"}}
</div>
<!-- /content -->
</div>
</div>
{{/zone}}

@ -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];

@ -71,7 +71,7 @@
</div>
<div class="wr-search-tags"></div>
<a href="#" class="btn-search"><i class="fw fw-search"></i></a>
<div class="input" id="search" data-value="" data-placeholder="Search devices ..." contenteditable="true"></div>
<div class="input" id="search" data-value="" data-placeholder="Search {{item}}s ..." contenteditable="true"></div>
<div class="clearfix"></div>
</div>
<!-- /asset filter -->
@ -79,9 +79,9 @@
<div class="wr-filters col-xs-12 col-sm-5 col-md-4 wr-filters-right">
<div class="wr-filter-sort pull-right">
<a href="javascript:void(0)" onclick="selectAllDevices(this)" class="wr-btn">Select All Devices</a>
<a href="javascript:void(0)" onclick="changeDeviceView('grid', this)" class="ico-filter ctrl-filter-grid view-toggle"><i class="fw fw-grid"></i></a>
<a href="javascript:void(0)" onclick="changeDeviceView('list', this)" class="ico-filter ctrl-filter-list view-toggle selected"><i class="fw fw-list"></i></a>
<a href="javascript:void(0)" onclick="selectAll{{item}}s(this)" class="wr-btn">Select All {{item}}s</a>
<a href="javascript:void(0)" onclick="change{{item}}View('grid', this)" class="ico-filter ctrl-filter-grid view-toggle"><i class="fw fw-grid"></i></a>
<a href="javascript:void(0)" onclick="change{{item}}View('list', this)" class="ico-filter ctrl-filter-list view-toggle selected"><i class="fw fw-list"></i></a>
<span class="wr-filter-type-switcher"><a href="#" class="ico-filter ctrl-filter-type-switcher" data-placement="bottom" data-trigger="focus"><i class="fw fw-list-sort"></i></a></span>
</div>
</div>

@ -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();
}

@ -0,0 +1,174 @@
{{#zone "main"}}
<div class="row wr-group-board">
<div class="col-lg-12 wr-secondary-bar">
<label class="device-id device-select" data-groupid="{{group.groupId}}">
Group {{group.name}}
<span class="lbl-device">
{{#if group.viewModel.vendor}}
({{group.viewModel.vendor}} {{group.viewModel.model}})
{{/if}}
</span>
</label>
</div>
</div>
<div class="wr-group-list row">
<div class="wr-hidden-operations wr-advance-operations">
</div>
<div class="col-md-12 wr-page-content">
{{unit "operation-bar"}}
<div class="row">
<div class="col-md-12 wr-stats-board">
<!-- content -->
<div class="col-lg-2 ast-desc-image">
<div class="row">
<div class="col-lg-12 col-sm-4">
<img src="{{self.publicURL}}/img/group-icon.png" style="width:200px" />
</div>
<div class="col-lg-12 col-sm-4 ast-desc">
<div class="ast-group-desc"><b>Owner:</b> {{group.ownerId}}</div>
<div class="ast-group-desc"><b>Date of Enrollment:</b><br/> <span class="formatDate">{{group.enrollment}}</span></div>
</div>
</div>
</div>
<div class="col-lg-10 tiles">
<!-- group summary -->
<div class="row">
<div class="col-lg-6 col-md-6">
{{#if group.viewModel.BatteryLevel}}
<div class="col-lg-4">
<div class="wr-stats-board-tile">
<div class="tile-name">BATTERY</div>
<div>
<div class="tile-icon"><i class="fw fw-battery"></i></div>
<div class="tile-stats">{{group.viewModel.BatteryLevel}}%</div>
</div>
</div>
</div>
{{/if}}
{{#if group.viewModel.DeviceCapacity}}
<div class="col-lg-4">
<div class="wr-stats-board-tile">
<div class="tile-name">STORAGE</div>
<div>
<div class="tile-icon"><i class="fw fw-hdd"></i></div>
<div class="tile-stats">{{group.viewModel.DeviceCapacityPercentage}}%<span class="tile-stats-free">{{group.viewModel.DeviceCapacityUsed}} GB Free</span></div>
</div>
</div>
</div>
{{/if}}
{{#if group.viewModel.internal_memory.FreeCapacity}}
<div class="col-lg-4">
<div class="wr-stats-board-tile">
<div class="tile-name">LOCAL STORAGE</div>
<div>
<div class="tile-icon"><i class="fw fw-hdd"></i></div>
<div class="tile-stats">{{group.viewModel.internal_memory.DeviceCapacityPercentage}}%<span class="tile-stats-free">{{group.viewModel.internal_memory.FreeCapacity}} GB Free</span></div>
</div>
</div>
</div>
{{/if}}
{{#if group.viewModel.external_memory.FreeCapacity}}
<div class="col-lg-4">
<div class="wr-stats-board-tile">
<div class="tile-name">EXTERNAL STORAGE</div>
<div>
<div class="tile-icon"><i class="fw fw-hdd"></i></div>
<div class="tile-stats">{{group.viewModel.external_memory.DeviceCapacityPercentage}}%<span class="tile-stats-free">{{group.viewModel.external_memory.FreeCapacity}} GB Free</span></div>
</div>
</div>
</div>
{{/if}}
</div>
</div>
<!-- /group summary -->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<!-- statistics -->
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingFour">
<h2 class="sub-title panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseFour" aria-expanded="false" aria-controls="collapseFour">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-arrow fw-down-arrow fw-stack-1x"></i>
</span>
Group Statistics
</a>
</h2>
</div>
<div id="collapseFour" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingFour">
<div class="panel-body">
<a href="../../groups/analytics?groupId={{groupId}}" ><i class="fw fw-charts"></i> Show Statistics</a>
</div>
</div>
</div>
<!-- policies -->
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h2 class="sub-title panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-arrow fw-down-arrow fw-stack-1x"></i>
</span>
Policies
</a>
</h2>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
Not available yet
</div>
</div>
</div>
<!-- /policies -->
<!-- installed applications -->
<!--<div class="panel panel-default">-->
<!--<div class="panel-heading" role="tab" id="headingThree">-->
<!--<h2 class="sub-title panel-title">-->
<!--<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">-->
<!--<span class="fw-stack">-->
<!--<i class="fw fw-ring fw-stack-2x"></i>-->
<!--<i class="fw fw-arrow fw-down-arrow fw-stack-1x"></i>-->
<!--</span>-->
<!--Installed Applications-->
<!--</a>-->
<!--</h2>-->
<!--</div>-->
<!--<div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">-->
<!--<div class="panel-body">-->
<!--Not available yet-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!-- /installed applications -->
</div>
</div>
<!-- /content -->
</div>
</div>
</div>
</div>
{{/zone}}
{{#zone "bottomJs"}}
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
<script src="{{self.publicURL}}/js/group-detail.js"></script>
{{/zone}}

@ -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;
}

@ -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);
}
}());

@ -0,0 +1,168 @@
{{#zone "main"}}
<span id="permission" data-permission="{{permissions}}"></span>
<!-- form content placeholder -->
<div id="ast-container" class="ast-container list-view">
<!-- no devices found -->
<div class="container-fluid wr-content-alt">
<div class="ctrl-info-panel col-md-6 col-centered">
<h2>Loading...</h2>
</div>
</div>
<!-- /no groups found -->
</div>
<div id="no-groups-div-content" class="hide">
<!-- no devices found -->
<div class="container-fluid wr-content-alt">
<div class="ctrl-info-panel col-md-6 col-centered">
<h2>You don't have any Groups registered at the moment.</h2>
<p>
</a><a href="#" class="cu-btn">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add New Group
</a>
</p>
</div>
</div>
<!-- /no devices found -->
</div>
<div id="remove-group-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to remove this group from your Group List?</h3>
<div class="buttons">
<a href="#" id="remove-group-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Yes&nbsp;&nbsp;&nbsp;&nbsp;
</a>
&nbsp;&nbsp;
<a href="#" id="remove-group-cancel-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-group-200-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Group was successfully removed.</h3>
<div class="buttons">
<a href="#" id="remove-group-200-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="edit-group-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Please enter new name for the group?</h3>
<br/>
<div>
<input id="edit-device-name" style="color:#3f3f3f;padding:5px" type="text" value="" placeholder="Type here" size="60">
</div>
<div class="buttons">
<a href="#" id="edit-group-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Rename&nbsp;&nbsp;&nbsp;&nbsp;
</a>
&nbsp;&nbsp;
<a href="#" id="edit-group-cancel-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="edit-group-200-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Group was successfully updated.</h3>
<div class="buttons">
<a href="#" id="edit-group-200-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="group-400-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Exception at backend. Try Later.</h3>
<div class="buttons">
<a href="#" id="remove-group-400-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="group-403-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Action not permitted.</h3>
<div class="buttons">
<a href="#" id="remove-group-403-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="group-409-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Group does not exist.</h3>
<div class="buttons">
<a href="#" id="remove-group-409-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="group-unexpected-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Group does not exist.</h3>
<div class="buttons">
<a href="#" id="remove-group-unexpected-error-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
{{/zone}}
{{#zone "bottomJs"}}
<script id="group-listing" data-image-resource="{{self.publicURL}}/images/" src="{{self.publicURL}}/templates/group-listing.hbs" type="text/x-handlebars-template" ></script>
<script src="{{self.publicURL}}/js/group-listing.js"></script>
{{/zone}}

@ -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;
}

@ -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();
});
});
}

@ -0,0 +1,54 @@
{{#each groups}}
{{groupMap this}}
<div class="ctrl-wr-asset" data-groupid="{{groupId}}">
<div class="itm-select">
<label class="wr-input-control checkbox">
<input type="checkbox"/>
<span class="helper"></span>
</label>
</div>
<div class="itm-ast">
<a href="group/id/{{groupId}}">
<div class="ast-img"><img src="{{../imageLocation}}group-icon.png"/></div>
<div class="ast-desc">
<div class="ast-title">
<h3 class="ast-name">{{name}}</h3>
<span class="ast-auth">Device Count: {{deviceCount}}</span>
<span class="ast-auth">Created On: <span class="formatDate">{{dateOfCreation}}</span></span>
</div>
<div class="ast-model">
<span class="ast-ver">Shared with: {{users}}</span>
<div class="ast-btn-group">
<a href="/iotserver/group/id/{{groupId}}">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
</span>
<span class="lbl-action">View</span>
</a>
<a href="#" class="edit-group-link" data-groupid="{{groupId}}" data-groupname="{{name}}">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-edit fw-stack-1x"></i>
</span>
<span class="lbl-action">Edit</span>
</a>
<a href="#" class="remove-group-link" data-groupid="{{groupId}}">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-delete fw-stack-1x"></i>
</span>
<span class="lbl-action">Delete</span>
</a>
</div>
</div>
</div>
<br class="c-both"/>
</a>
</div>
</div>
{{/each}}
<br class="c-both"/>

@ -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 {

Loading…
Cancel
Save