commit
770ce0f71e
@ -0,0 +1,252 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* 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 group = request.getContent();
|
||||||
|
var name = group["name"];
|
||||||
|
var description = group["description"];
|
||||||
|
//URL: POST https://localhost:9443/devicecloud/group_manager/group
|
||||||
|
endPoint = deviceCloudService + "/group";
|
||||||
|
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;
|
||||||
|
group = request.getContent();
|
||||||
|
name = group["name"];
|
||||||
|
description = group["description"];
|
||||||
|
|
||||||
|
//URL: PUT https://localhost:9443/devicecloud/group_manager/group/id/{groupId}
|
||||||
|
endPoint = deviceCloudService + "/group/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 + "/group/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 + "/group/id/" + groupId;
|
||||||
|
log.info(endPoint);
|
||||||
|
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 + "/group/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.getContent()["shareUser"];
|
||||||
|
role = request.getContent()["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}/unshare")) {
|
||||||
|
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
var unShareUser = request.getContent()["unShareUser"];
|
||||||
|
role = request.getContent()["role"];
|
||||||
|
|
||||||
|
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/unshare
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/unshare";
|
||||||
|
data = {"username": user.username, "unShareUser": unShareUser, "role": role};
|
||||||
|
result = post(endPoint, data, "json");
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/add")) {
|
||||||
|
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
var permissions = request.getContent()["permissions"];
|
||||||
|
role = request.getContent()["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.getContent()["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}/{userId}/rolemapping")) {
|
||||||
|
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
userId = uriMatcher.elements().userId;
|
||||||
|
|
||||||
|
data = {"username": user.username};
|
||||||
|
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role/all
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/role/all";
|
||||||
|
var allRoles = get(endPoint, data, "json").data;
|
||||||
|
|
||||||
|
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/{user}/role/all
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/" + userId + "/role/all";
|
||||||
|
var userRolesObj = get(endPoint, data, "json");
|
||||||
|
var userRoles = userRolesObj.data;
|
||||||
|
var roleMap = [];
|
||||||
|
for (var role in allRoles) {
|
||||||
|
var objRole = {"role": allRoles[role], "assigned": false};
|
||||||
|
for (var usrRole in userRoles) {
|
||||||
|
if (allRoles[role] == userRoles[usrRole]) {
|
||||||
|
objRole.assigned = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
roleMap.push(objRole);
|
||||||
|
}
|
||||||
|
result = {};
|
||||||
|
result.data = roleMap;
|
||||||
|
result.xhr = userRolesObj.xhr;
|
||||||
|
|
||||||
|
} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/{userId}/roleupdate")) {
|
||||||
|
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
userId = uriMatcher.elements().userId;
|
||||||
|
roleMap = request.getContent();
|
||||||
|
|
||||||
|
for (role in roleMap) {
|
||||||
|
if (roleMap[role].assigned == true) {
|
||||||
|
//URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/share";
|
||||||
|
data = {"username": user.username, "shareUser": userId, "role": roleMap[role].role};
|
||||||
|
result = post(endPoint, data, "json");
|
||||||
|
} else {
|
||||||
|
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/unshare
|
||||||
|
endPoint = deviceCloudService + "/group/id/" + groupId + "/unshare";
|
||||||
|
data = {"username": user.username, "unShareUser": userId, "role": roleMap[role].role};
|
||||||
|
result = post(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}/assign")) {
|
||||||
|
|
||||||
|
groupId = uriMatcher.elements().groupId;
|
||||||
|
var deviceId = request.getContent()["deviceId"];
|
||||||
|
var deviceType = request.getContent()["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) {
|
||||||
|
response.status = result.xhr.status;
|
||||||
|
print(result.data);
|
||||||
|
}
|
||||||
|
%>
|
@ -0,0 +1,12 @@
|
|||||||
|
{{authorized}}
|
||||||
|
{{layout "fluid"}}
|
||||||
|
{{#zone "title"}}
|
||||||
|
Group Management
|
||||||
|
{{/zone}}
|
||||||
|
{{#zone "body"}}
|
||||||
|
{{unit "operation-mod"}}
|
||||||
|
{{unit "appbar" enableBack=true title="Group"}}
|
||||||
|
|
||||||
|
{{unit "group-detail"}}
|
||||||
|
|
||||||
|
{{/zone}}
|
@ -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}}
|
@ -0,0 +1,116 @@
|
|||||||
|
{{#zone "main"}}
|
||||||
|
<div class="row wr-device-board">
|
||||||
|
<div class="col-lg-12 wr-secondary-bar">
|
||||||
|
<label class="device-id device-select" data-groupid="{{group.id}}">
|
||||||
|
Group: {{group.name}}
|
||||||
|
</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>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<div class="col-lg-12 col-sm-4 ast-desc">
|
||||||
|
<div class="ast-group-desc"><b>Description</b><br/> <span>{{group.description}}</span>
|
||||||
|
</div>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<div class="ast-group-desc"><b>No. of Devices:</b> {{group.deviceCount}}</div>
|
||||||
|
<div class="ast-group-desc"><b>Users:</b> {{group.users}}</div>
|
||||||
|
<div class="ast-group-desc"><b>Created on:</b> <span
|
||||||
|
class="formatDate">{{group.dateOfCreation}}</span></div>
|
||||||
|
<div class="ast-group-desc"><b>Modified on:</b> <span
|
||||||
|
class="formatDate">{{group.dateOfLastUpdate}}</span></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-10 tiles">
|
||||||
|
|
||||||
|
<!-- group summary -->
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="col-lg-6 col-md-6">
|
||||||
|
</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="/iotserver/groups/analytics?groupId={{group.id}}"><i class="fw fw-charts"></i>
|
||||||
|
Show Statistics</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- devices -->
|
||||||
|
<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>
|
||||||
|
Group Devices
|
||||||
|
</a>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel"
|
||||||
|
aria-labelledby="headingTwo">
|
||||||
|
<div class="panel-body">
|
||||||
|
<a href="/iotserver/devices?groupId={{group.id}}"><i class="fw fw-charts"></i> Show Devices
|
||||||
|
in Group</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- /content -->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{/zone}}
|
||||||
|
{{#zone "bottomJs"}}
|
||||||
|
<script src="{{self.publicURL}}/js/group-detail.js"></script>
|
||||||
|
{{/zone}}
|
@ -0,0 +1,21 @@
|
|||||||
|
var log = new Log("modules/group-detail.js");
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var uri = request.getRequestURI();
|
||||||
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
var isMatched = uriMatcher.match("/{context}/group/{groupId}");
|
||||||
|
if (isMatched) {
|
||||||
|
var group = {};
|
||||||
|
group.id = uriMatcher.elements().groupId;
|
||||||
|
group.name = request.getParameter("name");
|
||||||
|
group.deviceCount = request.getParameter("deviceCount");
|
||||||
|
group.dateOfCreation = request.getParameter("dateOfCreation");
|
||||||
|
group.dateOfLastUpdate = request.getParameter("dateOfLastUpdate");
|
||||||
|
group.description = request.getParameter("description");
|
||||||
|
group.users = request.getParameter("users");
|
||||||
|
context.group =group;
|
||||||
|
} else {
|
||||||
|
response.sendError(404);
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"predicate": "false"
|
||||||
|
}
|
After Width: | Height: | Size: 5.3 KiB |
After Width: | Height: | Size: 6.0 KiB |
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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 () {
|
||||||
|
$(document).ready(function(){
|
||||||
|
formatDates();
|
||||||
|
});
|
||||||
|
}());
|
@ -0,0 +1,289 @@
|
|||||||
|
{{#zone "main"}}
|
||||||
|
<span id="permission" data-permission="{{permissions}}"></span>
|
||||||
|
<span id="user-details" data-username="{{user.username}}"></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 groups 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 href="#" class="cu-btn add-group-link">
|
||||||
|
<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 groups found -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="share-group-w1-modal-content" class="hide">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>Select user to manage group sharing</h3>
|
||||||
|
<div id="user-names">Loading...</div>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="share-group-w1-cancel-link" class="btn-operations">
|
||||||
|
Cancel
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="#" id="share-group-next-link" class="btn-operations">
|
||||||
|
Next
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="share-group-w2-modal-content" class="hide">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>Select sharing roles</h3>
|
||||||
|
<br />
|
||||||
|
<div id="user-roles">Loading...</div>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="share-group-w2-cancel-link" class="btn-operations">
|
||||||
|
Cancel
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="#" id="share-group-yes-link" class="btn-operations">
|
||||||
|
OK
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="share-group-200-content" class="hide">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>Group sharing updated successfully.</h3>
|
||||||
|
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="share-group-200-link" class="btn-operations">
|
||||||
|
Ok
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</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">
|
||||||
|
Yes
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="#" id="remove-group-cancel-link" class="btn-operations">
|
||||||
|
Cancel
|
||||||
|
</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">
|
||||||
|
Ok
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="add-group-modal-content" class="hide">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>Please enter name and description for new group</h3>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<input id="add-group-name" style="color:#3f3f3f;padding:5px" type="text" value=""
|
||||||
|
placeholder="Group Name" size="60">
|
||||||
|
</div>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<input id="add-group-description" style="color:#3f3f3f;padding:5px" type="text" value=""
|
||||||
|
placeholder="Group Description" size="60">
|
||||||
|
</div>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="add-group-yes-link" class="btn-operations">
|
||||||
|
Add Group
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="#" id="add-group-cancel-link" class="btn-operations">
|
||||||
|
Cancel
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="add-group-200-content" class="hide">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>Group successfully added.</h3>
|
||||||
|
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="add-group-200-link" class="btn-operations">
|
||||||
|
Ok
|
||||||
|
</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 and description for the group</h3>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<input id="edit-group-name" style="color:#3f3f3f;padding:5px" type="text" value=""
|
||||||
|
placeholder="Group Name" size="60">
|
||||||
|
</div>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<input id="edit-group-description" style="color:#3f3f3f;padding:5px" type="text" value=""
|
||||||
|
placeholder="Group Description" size="60">
|
||||||
|
</div>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="#" id="edit-group-yes-link" class="btn-operations">
|
||||||
|
Update
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="#" id="edit-group-cancel-link" class="btn-operations">
|
||||||
|
Cancel
|
||||||
|
</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">
|
||||||
|
Ok
|
||||||
|
</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="group-400-link" class="btn-operations">
|
||||||
|
Ok
|
||||||
|
</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="group-403-link" class="btn-operations">
|
||||||
|
Ok
|
||||||
|
</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="group-409-link" class="btn-operations">
|
||||||
|
Ok
|
||||||
|
</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="group-unexpected-error-link" class="btn-operations">
|
||||||
|
Ok
|
||||||
|
</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,21 @@
|
|||||||
|
var log = new Log("modules/group-listing.js");
|
||||||
|
|
||||||
|
function onRequest(context){
|
||||||
|
var constants = require("/modules/constants.js");
|
||||||
|
var permissions = [];
|
||||||
|
//var userModule = require("/modules/user.js").userModule;
|
||||||
|
//if(userModule.isAuthorized("/permission/device-mgt/admin/groups/list")){
|
||||||
|
// permissions.push("LIST_GROUPS");
|
||||||
|
//}else if(userModule.isAuthorized("/permission/device-mgt/groups/remove")){
|
||||||
|
// permissions.push("REMOVE_GROUPS");
|
||||||
|
//}else if(userModule.isAuthorized("/permission/device-mgt/groups/share")){
|
||||||
|
// permissions.push("SHARE_GROUPS");
|
||||||
|
//}
|
||||||
|
permissions.push("LIST_GROUPS");
|
||||||
|
permissions.push("ADD_GROUPS");
|
||||||
|
permissions.push("SHARE_GROUPS");
|
||||||
|
context.permissions = stringify(permissions);
|
||||||
|
context.SHARE_GROUPS = true;
|
||||||
|
context.user = session.get(constants.USER_SESSION_KEY);
|
||||||
|
return context;
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"predicate": "false"
|
||||||
|
}
|
After Width: | Height: | Size: 6.0 KiB |
@ -0,0 +1,531 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
viewModel.imageLocation = imageResource;
|
||||||
|
if (!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();
|
||||||
|
}
|
||||||
|
attachGroupAdding();
|
||||||
|
};
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
var errorHandler = function () {
|
||||||
|
$(modalPopupContent).html($('#add-group-unexpected-error-content').html());
|
||||||
|
$("a#group-unexpected-error-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function attachGroupAdding() {
|
||||||
|
/**
|
||||||
|
* Following click function would execute
|
||||||
|
* when a user clicks on "Remove" link
|
||||||
|
* on Group Management page in WSO2 IoT Server Console.
|
||||||
|
*/
|
||||||
|
$("a.add-group-link").click(function () {
|
||||||
|
var addGroupApi = "/iotserver/api/group/add";
|
||||||
|
$(modalPopupContent).html($('#add-group-modal-content').html());
|
||||||
|
showPopup();
|
||||||
|
|
||||||
|
$("a#add-group-yes-link").click(function () {
|
||||||
|
var newGroupName = $('#add-group-name').val();
|
||||||
|
var newGroupDescription = $('#add-group-description').val();
|
||||||
|
var group = {"name": newGroupName, "description": newGroupDescription};
|
||||||
|
invokerUtil.post(
|
||||||
|
addGroupApi,
|
||||||
|
group,
|
||||||
|
function (data, txtStatus, jqxhr) {
|
||||||
|
var status = jqxhr.status;
|
||||||
|
if (status == 200) {
|
||||||
|
if (data != "false") {
|
||||||
|
$(modalPopupContent).html($('#add-group-200-content').html());
|
||||||
|
$("a#add-group-200-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$(modalPopupContent).html($('#group-400-content').html());
|
||||||
|
$("a#group-400-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (status == 400) {
|
||||||
|
$(modalPopupContent).html($('#group-400-content').html());
|
||||||
|
$("a#group-400-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
} else if (status == 403) {
|
||||||
|
$(modalPopupContent).html($('#agroup-403-content').html());
|
||||||
|
$("a#group-403-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
} else if (status == 409) {
|
||||||
|
$(modalPopupContent).html($('#group-409-content').html());
|
||||||
|
$("a#group-409-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, errorHandler
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("a#add-group-cancel-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Following functions should be triggered after AJAX request is made.
|
||||||
|
*/
|
||||||
|
function attachEvents() {
|
||||||
|
/**
|
||||||
|
* Following click function would execute
|
||||||
|
* when a user clicks on "Share" link
|
||||||
|
* on Group Management page in WSO2 IoT Server Console.
|
||||||
|
*/
|
||||||
|
$("a.view-group-link").click(function () {
|
||||||
|
$("#group_data").closest('form').submit();
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Following click function would execute
|
||||||
|
* when a user clicks on "Share" link
|
||||||
|
* on Group Management page in WSO2 IoT Server Console.
|
||||||
|
*/
|
||||||
|
$("a.share-group-link").click(function () {
|
||||||
|
var groupId = $(this).data("groupid");
|
||||||
|
var username = $("#user-details").data("username");
|
||||||
|
$(modalPopupContent).html($('#share-group-w1-modal-content').html());
|
||||||
|
$('#user-names').html('Loading...');
|
||||||
|
showPopup();
|
||||||
|
$("a#share-group-next-link").hide();
|
||||||
|
invokerUtil.get("/iotserver/api/users",
|
||||||
|
function (data, txtStatus, jqxhr) {
|
||||||
|
var users = JSON.parse(data);
|
||||||
|
var status = jqxhr.status;
|
||||||
|
if (status == 200) {
|
||||||
|
var str = '<br /><select id="share-user-selector" style="color:#3f3f3f;padding:5px;width:250px;">';
|
||||||
|
var hasUsers = false;
|
||||||
|
for (var user in users) {
|
||||||
|
if (users[user].username != username) {
|
||||||
|
str += '<option value="' + users[user].username + '">' + users[user].username + '</option>';
|
||||||
|
hasUsers = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
str += '</select>';
|
||||||
|
if (!hasUsers) {
|
||||||
|
str = "There is no any other users registered";
|
||||||
|
$('#user-names').html(str);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$('#user-names').html(str);
|
||||||
|
$("a#share-group-next-link").show();
|
||||||
|
$("a#share-group-next-link").click(function () {
|
||||||
|
var selectedUser = $('#share-user-selector').val();
|
||||||
|
$(modalPopupContent).html($('#share-group-w2-modal-content').html());
|
||||||
|
$('#user-roles').html('Loading...');
|
||||||
|
$("a#share-group-yes-link").hide();
|
||||||
|
invokerUtil.get("/iotserver/api/group/id/" + groupId + "/" + selectedUser + "/rolemapping",
|
||||||
|
function (data, txtStatus, jqxhr) {
|
||||||
|
var roleMap = JSON.parse(data);
|
||||||
|
var status = jqxhr.status;
|
||||||
|
if (status == 200) {
|
||||||
|
var str = '';
|
||||||
|
var isChecked = '';
|
||||||
|
var hasRoles = false;
|
||||||
|
for (var role in roleMap) {
|
||||||
|
if (roleMap[role].assigned == true) {
|
||||||
|
isChecked = 'checked';
|
||||||
|
}
|
||||||
|
str += '<label class="checkbox-text"><input type="checkbox" id="user-role-' + roleMap[role].role + '" value="' + roleMap[role].role
|
||||||
|
+ '" ' + isChecked + '/>' + roleMap[role].role + '</label> ';
|
||||||
|
hasRoles = true;
|
||||||
|
}
|
||||||
|
if (!hasRoles) {
|
||||||
|
str = "There is no any roles for this group";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$('#user-roles').html(str);
|
||||||
|
$("a#share-group-yes-link").show();
|
||||||
|
$("a#share-group-yes-link").click(function () {
|
||||||
|
var updatedRoleMap = [];
|
||||||
|
for (var role in roleMap) {
|
||||||
|
if ($('#user-role-' + roleMap[role].role).is(':checked') != roleMap[role].assigned){
|
||||||
|
roleMap[role].assigned = $('#user-role-' + roleMap[role].role).is(':checked');
|
||||||
|
updatedRoleMap.push(roleMap[role]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
invokerUtil.post("/iotserver/api/group/id/" + groupId + "/" + selectedUser + "/roleupdate",
|
||||||
|
updatedRoleMap,
|
||||||
|
function (data, txtStatus, jqxhr) {
|
||||||
|
var status = jqxhr.status;
|
||||||
|
if (status == 200) {
|
||||||
|
$(modalPopupContent).html($('#share-group-200-content').html());
|
||||||
|
$("a#share-group-200-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
}else {
|
||||||
|
displayErrors(status);
|
||||||
|
}
|
||||||
|
}, errorHandler);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
displayErrors(status);
|
||||||
|
}
|
||||||
|
}, errorHandler);
|
||||||
|
$("a#share-group-w2-cancel-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
displayErrors(status);
|
||||||
|
}
|
||||||
|
}, errorHandler);
|
||||||
|
|
||||||
|
$("a#share-group-w1-cancel-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Following click function would execute
|
||||||
|
* when a user clicks on "Remove" link
|
||||||
|
* on Group Management page in WSO2 IoT Server 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.delete(
|
||||||
|
removeGroupApi,
|
||||||
|
function (data, txtStatus, jqxhr) {
|
||||||
|
var status = jqxhr.status;
|
||||||
|
if (status == 200) {
|
||||||
|
if (data != "false") {
|
||||||
|
$(modalPopupContent).html($('#remove-group-200-content').html());
|
||||||
|
$('div[data-group="' + groupId + '"]').remove();
|
||||||
|
$("a#remove-group-200-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$(modalPopupContent).html($('#group-409-content').html());
|
||||||
|
$("a#group-409-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
displayErrors(status);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
$(modalPopupContent).html($('#group-unexpected-error-content').html());
|
||||||
|
$("a#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 groupDescription = $(this).data("groupdescription");
|
||||||
|
var editGroupApi = "/iotserver/api/group/id/" + groupId + "/update";
|
||||||
|
|
||||||
|
$(modalPopupContent).html($('#edit-group-modal-content').html());
|
||||||
|
$('#edit-group-name').val(groupName);
|
||||||
|
$('#edit-group-description').val(groupDescription);
|
||||||
|
showPopup();
|
||||||
|
|
||||||
|
$("a#edit-group-yes-link").click(function () {
|
||||||
|
var newGroupName = $('#edit-group-name').val();
|
||||||
|
var newGroupDescription = $('#edit-group-description').val();
|
||||||
|
var group = {"name": newGroupName, "description": newGroupDescription};
|
||||||
|
invokerUtil.post(
|
||||||
|
editGroupApi,
|
||||||
|
group,
|
||||||
|
function (data, txtStatus, jqxhr) {
|
||||||
|
var status = jqxhr.status;
|
||||||
|
if (status == 200) {
|
||||||
|
if (data != "false") {
|
||||||
|
$(modalPopupContent).html($('#edit-group-200-content').html());
|
||||||
|
$("div[data-groupid='" + groupId + "'] .ast-name").html(newGroupName);
|
||||||
|
$("a#edit-group-200-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$(modalPopupContent).html($('#group-409-content').html());
|
||||||
|
$("a#group-409-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
displayErrors(status);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
$(modalPopupContent).html($('#group-unexpected-error-content').html());
|
||||||
|
$("a#group-unexpected-error-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("a#edit-group-cancel-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayErrors(status) {
|
||||||
|
if (status == 400) {
|
||||||
|
$(modalPopupContent).html($('#group-400-content').html());
|
||||||
|
$("a#group-400-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
} else if (status == 403) {
|
||||||
|
$(modalPopupContent).html($('#group-403-content').html());
|
||||||
|
$("a#group-403-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
} else if (status == 409) {
|
||||||
|
$(modalPopupContent).html($('#group-409-content').html());
|
||||||
|
$("a#group-409-link").click(function () {
|
||||||
|
hidePopup();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
{{#each groups}}
|
||||||
|
{{groupMap this}}
|
||||||
|
<form action="/iotserver/group/{{id}}" method="POST" id="group_data" >
|
||||||
|
<input type="hidden" name="name" value="{{name}}">
|
||||||
|
<input type="hidden" name="deviceCount" value="{{deviceCount}}">
|
||||||
|
<input type="hidden" name="dateOfCreation" value="{{dateOfCreation}}">
|
||||||
|
<input type="hidden" name="dateOfLastUpdate" value="{{dateOfLastUpdate}}">
|
||||||
|
<input type="hidden" name="description" value="{{description}}">
|
||||||
|
<input type="hidden" name="users" value="{{users}}">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="ctrl-wr-asset" data-groupid="{{id}}">
|
||||||
|
<div class="itm-select">
|
||||||
|
<label class="wr-input-control checkbox">
|
||||||
|
<input type="checkbox"/>
|
||||||
|
<span class="helper"></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="itm-ast">
|
||||||
|
<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 href="#" class="ast-btn-group">
|
||||||
|
<a class="view-group-link" data-group="{{this}}">
|
||||||
|
<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="share-group-link" data-groupid="{{id}}">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-share fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
<span class="lbl-action">Share</span>
|
||||||
|
</a>
|
||||||
|
<a href="#" class="edit-group-link" data-groupid="{{id}}" data-groupname="{{name}}"
|
||||||
|
data-groupdescription="{{description}}">
|
||||||
|
<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="{{id}}">
|
||||||
|
<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"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
<br class="c-both"/>
|
@ -1,4 +1,3 @@
|
|||||||
function onRequest(context){
|
function onRequest(context){
|
||||||
var log = new Log();
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
function onRequest(context){
|
||||||
|
return context;
|
||||||
|
}
|
Loading…
Reference in new issue