forked from community/device-mgt-core
parent
2a89a2fb23
commit
3df2912a6a
@ -0,0 +1,77 @@
|
|||||||
|
<%
|
||||||
|
/*
|
||||||
|
* 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/stats-api.jag");
|
||||||
|
|
||||||
|
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||||
|
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||||
|
|
||||||
|
if (uriMatcher.match("/{context}/api/stats/paginate")) {
|
||||||
|
var deviceType = request.getParameter("deviceType");
|
||||||
|
var deviceId = request.getParameter("deviceId");
|
||||||
|
var from = request.getParameter("from");
|
||||||
|
var to = request.getParameter("to");
|
||||||
|
var index = request.getParameter("start");
|
||||||
|
var length = request.getParameter("length");
|
||||||
|
var keys = request.getParameter("attributes");
|
||||||
|
keys = JSON.parse(keys);
|
||||||
|
var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/events/"
|
||||||
|
+ deviceType + "/" + deviceId + "?offset=" + index +"&limit=" + length + "&from="+ from + "&to=" + to;
|
||||||
|
serviceInvokers.XMLHttp.get(
|
||||||
|
restAPIEndpoint,
|
||||||
|
function (restAPIResponse) {
|
||||||
|
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
|
||||||
|
var responsePayload = parse(restAPIResponse["responseText"]);
|
||||||
|
|
||||||
|
var paginatedResult = {};
|
||||||
|
paginatedResult["recordsTotal"] = responsePayload["count"];
|
||||||
|
paginatedResult["recordsFiltered"] = responsePayload["count"];
|
||||||
|
var records = responsePayload["records"];
|
||||||
|
var dataSet = [];
|
||||||
|
for (var i = 0; i < records.length; i++){
|
||||||
|
var record = records[i];
|
||||||
|
var timestamp = record["timestamp"];
|
||||||
|
var dataRow = [];
|
||||||
|
dataRow.push(timestamp);
|
||||||
|
for (var j = 0; j < keys.length; j++) {
|
||||||
|
var key = keys[j];
|
||||||
|
dataRow.push(record.values[key]);
|
||||||
|
}
|
||||||
|
//dataSet.push(dataRow);
|
||||||
|
dataSet.push(dataRow);
|
||||||
|
}
|
||||||
|
paginatedResult["data"] = dataSet;
|
||||||
|
response["status"] = restAPIResponse["status"];
|
||||||
|
response["content"] = paginatedResult;
|
||||||
|
} else {
|
||||||
|
response["status"] = 204;
|
||||||
|
var paginatedResult = {};
|
||||||
|
var dataSet = [];
|
||||||
|
paginatedResult["recordsTotal"] = 0;
|
||||||
|
paginatedResult["recordsFiltered"] = 0;
|
||||||
|
paginatedResult["data"] = dataSet;
|
||||||
|
response["content"] = paginatedResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
%>
|
@ -0,0 +1,114 @@
|
|||||||
|
{{!
|
||||||
|
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
|
||||||
|
WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
Version 2.0 (the "License"); you may not use this file except
|
||||||
|
in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
}}
|
||||||
|
<span id="operation-details" data-endpoint="{{operationEndpoint}}" data-deviceid="{{device.deviceIdentifier}}">
|
||||||
|
{{#if control_operations}}
|
||||||
|
<div class="wr-operations" style="height: 87px; display: block;">
|
||||||
|
<style>
|
||||||
|
::-webkit-input-placeholder {
|
||||||
|
color: #B8B8B8;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-moz-placeholder {
|
||||||
|
color: #B8B8B8;
|
||||||
|
}
|
||||||
|
|
||||||
|
:-ms-input-placeholder {
|
||||||
|
color: #B8B8B8;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:-moz-placeholder {
|
||||||
|
color: #B8B8B8;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{{#each control_operations}}
|
||||||
|
<a href="javascript:operationSelect('{{operation}}')">
|
||||||
|
<i class="fw fw-service"></i>
|
||||||
|
<span>{{name}}</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div class="operation" data-operation-code="{{operation}}">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-service fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
{{name}}
|
||||||
|
<br>
|
||||||
|
</h3>
|
||||||
|
<h4>
|
||||||
|
{{description}}
|
||||||
|
<br>
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
<form id="form-{{operation}}" style="padding-bottom: 20px;"-->
|
||||||
|
<select id="operation-type" class="form-control" onChange="operationTypeChage(this)">
|
||||||
|
<option value="CONFIG">Config</option>
|
||||||
|
<option value="COMMAND">Command</option>
|
||||||
|
</select>
|
||||||
|
<br />
|
||||||
|
<input type="hidden" id="operation-code" value="{{operation}}" />
|
||||||
|
<textarea id="operation-payload" placeholder="payload" class="form-control" rows="10" cols="70"></textarea>
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<button id="btnSend" type="button" onclick="submitForm('form-{{operation}}')" class="btn btn-default"> Send
|
||||||
|
to Device </button>
|
||||||
|
<label id="lblSending" class="wr-input-label hidden"><i
|
||||||
|
class="fw fw-lifecycle fw-spin fw-2x"></i> Sending..</label>
|
||||||
|
<label id="lblSent" class="wr-input-label hidden"><i
|
||||||
|
class="fw fw-check fw-2x"></i> Sent</label>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<div align="center">
|
||||||
|
<h4 style="color: #D8000C"><i class="icon fw fw-error" style="color: #D8000C"></i>
|
||||||
|
Operations Loading Failed!</h4>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
<div id="operation-response-template" style="display: none">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-5 col-md-6 col-centered">
|
||||||
|
<h3>
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||||
|
<i id="status-icon" class="fw fw-error fw-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
<br>
|
||||||
|
</h3>
|
||||||
|
<h4>
|
||||||
|
<span id="title"></span>
|
||||||
|
<br>
|
||||||
|
</h4>
|
||||||
|
<span id="description"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{#zone "bottomJs"}}
|
||||||
|
{{js "js/operation-bar.js"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var log = new Log("operation.js");
|
||||||
|
var deviceType = context.uriParams.deviceType;
|
||||||
|
var operationModule = require("/app/modules/business-controllers/operation.js")["operationModule"];
|
||||||
|
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||||
|
var restAPIEndpoint = devicemgtProps["backendRestEndpoints"]["deviceMgt"]
|
||||||
|
+ "/devices/" + deviceType + "/operations";
|
||||||
|
var device = context.unit.params.device;
|
||||||
|
var features = context.unit.params.features;
|
||||||
|
return {"control_operations": features, "device": device, "operationEndpoint": restAPIEndpoint};
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* On operation click function.
|
||||||
|
* @param selection: Selected operation
|
||||||
|
*/
|
||||||
|
function operationSelect(selection) {
|
||||||
|
$(modalPopupContent).addClass("operation-data");
|
||||||
|
$(modalPopupContent).html($(" .operation[data-operation-code=" + selection + "]").html());
|
||||||
|
$(modalPopupContent).data("operation-code", selection);
|
||||||
|
showPopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitForm(formId) {
|
||||||
|
var form = $("#" + formId);
|
||||||
|
var operationDetails = $("#operation-details");
|
||||||
|
var deviceId = operationDetails.data("deviceid");
|
||||||
|
var operationEndpoint = operationDetails.data("endpoint");
|
||||||
|
console.log(deviceId);
|
||||||
|
console.log(operationEndpoint);
|
||||||
|
|
||||||
|
var contentType = "application/json";
|
||||||
|
|
||||||
|
var payload = {};
|
||||||
|
var devices=[];
|
||||||
|
devices.push(deviceId);
|
||||||
|
payload["deviceIdentifiers"] = devices;
|
||||||
|
var operation = {};
|
||||||
|
operation["code"] = form.find("#operation-code").val();
|
||||||
|
operation["type"]= form.find("#operation-type").val();
|
||||||
|
operation["status"] = "IN_PROGRESS";
|
||||||
|
operation["control"] = "REPEAT";
|
||||||
|
operation["payLoad"] = form.find("#operation-payload").val();
|
||||||
|
operation["enabled"] = true;
|
||||||
|
payload["operation"] = operation;
|
||||||
|
|
||||||
|
//setting responses callbacks
|
||||||
|
var defaultStatusClasses = "fw fw-stack-1x";
|
||||||
|
var content = $("#operation-response-template").find(".content");
|
||||||
|
var title = content.find("#title");
|
||||||
|
var statusIcon = content.find("#status-icon");
|
||||||
|
var description = content.find("#description");
|
||||||
|
var successCallBack = function (response) {
|
||||||
|
var res = response;
|
||||||
|
try {
|
||||||
|
res = JSON.parse(response).messageFromServer;
|
||||||
|
} catch (err) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
title.html("Operation Triggered!");
|
||||||
|
statusIcon.attr("class", defaultStatusClasses + " fw-check");
|
||||||
|
description.html(res);
|
||||||
|
$(modalPopupContent).html(content.html());
|
||||||
|
};
|
||||||
|
var errorCallBack = function (response) {
|
||||||
|
console.log(response);
|
||||||
|
title.html("An Error Occurred!");
|
||||||
|
statusIcon.attr("class", defaultStatusClasses + " fw-error");
|
||||||
|
var reason = (response.responseText == "null")?response.statusText:response.responseText;
|
||||||
|
description.html(reason);
|
||||||
|
$(modalPopupContent).html(content.html());
|
||||||
|
};
|
||||||
|
invokerUtil.post(operationEndpoint, payload, successCallBack, errorCallBack, contentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).on('submit', 'form', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var postOperationRequest = $.ajax({
|
||||||
|
url: $(this).attr("action") + '&' + $(this).serialize(),
|
||||||
|
method: "post"
|
||||||
|
});
|
||||||
|
|
||||||
|
var btnSubmit = $('#btnSend', this);
|
||||||
|
btnSubmit.addClass('hidden');
|
||||||
|
|
||||||
|
var lblSending = $('#lblSending', this);
|
||||||
|
lblSending.removeClass('hidden');
|
||||||
|
|
||||||
|
var lblSent = $('#lblSent', this);
|
||||||
|
postOperationRequest.done(function (data) {
|
||||||
|
lblSending.addClass('hidden');
|
||||||
|
lblSent.removeClass('hidden');
|
||||||
|
setTimeout(function () {
|
||||||
|
hidePopup();
|
||||||
|
}, 3000);
|
||||||
|
});
|
||||||
|
|
||||||
|
postOperationRequest.fail(function (jqXHR, textStatus) {
|
||||||
|
lblSending.addClass('hidden');
|
||||||
|
lblSent.addClass('hidden');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function operationTypeChage(selectElement) {
|
||||||
|
if (selectElement.value == "COMMAND") {
|
||||||
|
$("#operation-payload").hide();
|
||||||
|
} else {
|
||||||
|
$("#operation-payload").show();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
{{!
|
||||||
|
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
|
||||||
|
WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
Version 2.0 (the "License"); you may not use this file except
|
||||||
|
in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
}}
|
||||||
|
<table class="table table-responsive table-striped" id="members">
|
||||||
|
<tbody>
|
||||||
|
<tr role="row" class="odd">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px;">Model</td>
|
||||||
|
<td style="padding:10px 15px;">TODO</td>
|
||||||
|
</tr>
|
||||||
|
<tr role="row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px;">Status</td>
|
||||||
|
<td style="padding:10px 15px;">
|
||||||
|
{{#if permissions.CHANGE_DEVICE_STATUS}}
|
||||||
|
{{#equal device.status "ACTIVE"}}<span><i id="statusIcon"
|
||||||
|
class="fw fw-success icon-success"></i>
|
||||||
|
<a href="#" id="status" data-type="select" data-pk="1"
|
||||||
|
data-title="Select status"
|
||||||
|
selectedValue="Active"></a>
|
||||||
|
</span>{{/equal}}
|
||||||
|
{{#equal device.status "INACTIVE"}}<span><i id="statusIcon"
|
||||||
|
class="fw fw-warning icon-warning"></i>
|
||||||
|
<a href="#" id="status" data-type="select" data-pk="1"
|
||||||
|
data-title="Select status"
|
||||||
|
selectedValue="Inactive"></a>
|
||||||
|
</span>{{/equal}}
|
||||||
|
{{#equal device.status "BLOCKED"}}<span><i id="statusIcon"
|
||||||
|
class="fw fw-remove icon-danger"></i>
|
||||||
|
<a href="#" id="status" data-type="select" data-pk="1"
|
||||||
|
data-title="Select status"
|
||||||
|
selectedValue="Blocked"></a>
|
||||||
|
</span>{{/equal}}
|
||||||
|
{{#equal device.status "REMOVED"}}<span><i id="statusIcon"
|
||||||
|
class="fw fw-delete icon-danger"></i>
|
||||||
|
<a href="#" id="status" data-type="select" data-pk="1"
|
||||||
|
data-title="Select status"
|
||||||
|
selectedValue="Removed"></a>
|
||||||
|
</span>{{/equal}}
|
||||||
|
{{else}}
|
||||||
|
{{#equal device.status "ACTIVE"}}<span><i
|
||||||
|
class="fw fw-success icon-success"></i> Active</span>{{/equal}}
|
||||||
|
{{#equal device.status "INACTIVE"}}<span><i
|
||||||
|
class="fw fw-warning icon-warning"></i> Inactive</span>{{/equal}}
|
||||||
|
{{#equal device.status "BLOCKED"}}<span><i
|
||||||
|
class="fw fw-remove icon-danger"></i> Blocked</span>{{/equal}}
|
||||||
|
{{#equal device.status "REMOVED"}}<span><i
|
||||||
|
class="fw fw-delete icon-danger"></i> Removed</span>{{/equal}}
|
||||||
|
{{/if}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest (context) {
|
||||||
|
var log = new Log("overview-section.js");
|
||||||
|
var device = context.unit.params.device;
|
||||||
|
return {"device" : device};
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
{{!
|
||||||
|
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
|
||||||
|
WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
Version 2.0 (the "License"); you may not use this file except
|
||||||
|
in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{unit "cdmf.unit.data-tables-extended"}}
|
||||||
|
|
||||||
|
<span id="device-details" data-devices="{{devices}}" data-devicename="{{device.name}}"
|
||||||
|
data-deviceid="{{device.deviceIdentifier}}"
|
||||||
|
data-devicetype="{{device.type}}"
|
||||||
|
data-appcontext="{{@app.context}}" data-attributes="{{attributes}}"></span>
|
||||||
|
<div id="device-div-chart" data-backend-api-url= {{backendApiUri}}>
|
||||||
|
{{#if attributes}}
|
||||||
|
<table class="table table-striped table-hover table-bordered display data-table"
|
||||||
|
id="stats-table">
|
||||||
|
<thead>
|
||||||
|
<tr id="header-rows">
|
||||||
|
<td>Timestamp</td>
|
||||||
|
{{#each attributes}}
|
||||||
|
<td>{{this}}</td>
|
||||||
|
{{/each}}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{{else}}
|
||||||
|
<div id="warn-config"><h1>Analytics Not Configured</h1> </div>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{#zone "bottomJs"}}
|
||||||
|
{{js "js/device.js"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
|
||||||
|
var deviceType = context.uriParams.deviceType;
|
||||||
|
var deviceId = request.getParameter("deviceId");
|
||||||
|
var keys = [];
|
||||||
|
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||||
|
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||||
|
|
||||||
|
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
||||||
|
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
||||||
|
var device = deviceModule.viewDevice(deviceType, deviceId);
|
||||||
|
|
||||||
|
var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
|
||||||
|
+ "/events/" + deviceType;
|
||||||
|
serviceInvokers.XMLHttp.get(
|
||||||
|
restAPIEndpoint,
|
||||||
|
function (restAPIResponse) {
|
||||||
|
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
|
||||||
|
var eventAttributes = parse(restAPIResponse["responseText"]);
|
||||||
|
if (eventAttributes.attributes.length > 0) {
|
||||||
|
for (var i = 0; i < eventAttributes.attributes.length; i++) {
|
||||||
|
var attribute = eventAttributes.attributes[i];
|
||||||
|
if (attribute['name'] == "deviceId") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
keys.push(attribute['name']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (device && device.status != "error") {
|
||||||
|
if (keys.length === 0 || keys.length === undefined) {
|
||||||
|
return {
|
||||||
|
"device": device.content,
|
||||||
|
"backendApiUri": "/api/device-mgt/v1.0/events/" + deviceType
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return {
|
||||||
|
"device": device.content,
|
||||||
|
"backendApiUri": "/api/device-mgt/v1.0/events/" + deviceType,
|
||||||
|
"attributes": keys
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var InitiateViewOption = null;
|
||||||
|
var deviceId = null;
|
||||||
|
var deviceType = null;
|
||||||
|
var fromTime = null;
|
||||||
|
var toTime = null;
|
||||||
|
var keys = null;
|
||||||
|
|
||||||
|
function drawTable(from, to) {
|
||||||
|
var device = $("#device-details");
|
||||||
|
deviceId = device.data("deviceid");
|
||||||
|
deviceType = device.data("devicetype");
|
||||||
|
keys = device.data("attributes").split(",");
|
||||||
|
fromTime = from * 1000;
|
||||||
|
toTime = to * 1000;
|
||||||
|
if ( $.fn.dataTable.isDataTable( '#stats-table' ) ) {
|
||||||
|
var table = $('#stats-table').DataTable();
|
||||||
|
table.clear().draw();
|
||||||
|
table.ajax.reload();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$("#stats-table").datatables_extended({
|
||||||
|
serverSide: true,
|
||||||
|
processing: false,
|
||||||
|
searching: false,
|
||||||
|
ordering: false,
|
||||||
|
pageLength: 100,
|
||||||
|
order: [],
|
||||||
|
ajax: {
|
||||||
|
url: "/devicemgt/api/stats/paginate",
|
||||||
|
data: buildAjaxData
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildAjaxData (){
|
||||||
|
var settings = $("#stats-table").dataTable().fnSettings();
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
//default params
|
||||||
|
"draw" : settings.iDraw,
|
||||||
|
"start" : settings._iDisplayStart,
|
||||||
|
"length" : settings._iDisplayLength,
|
||||||
|
"columns" : "",
|
||||||
|
"order": "",
|
||||||
|
"deviceType" : deviceType,
|
||||||
|
"deviceId" : deviceId,
|
||||||
|
"from": fromTime,
|
||||||
|
"to" : toTime,
|
||||||
|
"attributes" : JSON.stringify(keys)
|
||||||
|
};
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
{{!
|
||||||
|
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
|
||||||
|
WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
Version 2.0 (the "License"); you may not use this file except
|
||||||
|
in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
}}
|
||||||
|
{{unit "cdmf.unit.lib.rickshaw-graph"}}
|
||||||
|
|
||||||
|
<div id="div-chart" data-websocketurl="{{websocketEndpoint}}" data-attributes="{{attributes}}">
|
||||||
|
<table class="table table-responsive table-striped" id="members">
|
||||||
|
<tbody>
|
||||||
|
{{#each attributes}}
|
||||||
|
<tr role="row" class="odd">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px;">{{this}}</td>
|
||||||
|
<td id="{{this}}-value" style="padding:10px 15px;">-</td>
|
||||||
|
</tr>
|
||||||
|
{{/each}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<a class="padding-left"
|
||||||
|
href="{{@app.context}}/device/{{device.type}}/analytics?deviceId={{device.deviceIdentifier}}&deviceName={{device.name}}">
|
||||||
|
<span class="fw-stack">
|
||||||
|
<i class="fw fw-circle-outline fw-stack-2x"></i>
|
||||||
|
<i class="fw fw-statistics fw-stack-1x"></i>
|
||||||
|
</span> View Device Analytics
|
||||||
|
</a>
|
||||||
|
<!-- /statistics -->
|
||||||
|
{{#zone "bottomJs"}}
|
||||||
|
{{js "js/moment.min.js"}}
|
||||||
|
{{js "js/socket.io.min.js"}}
|
||||||
|
{{js "js/device-stats.js"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var log = new Log("stats.js");
|
||||||
|
var carbonServer = require("carbon").server;
|
||||||
|
var device = context.unit.params.device;
|
||||||
|
var attributes = context.unit.params.attributes;
|
||||||
|
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||||
|
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
var websocketEndpoint = devicemgtProps["wssURL"].replace("https", "wss");
|
||||||
|
var jwtService = carbonServer.osgiService(
|
||||||
|
'org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService');
|
||||||
|
var jwtClient = jwtService.getJWTClient();
|
||||||
|
var encodedClientKeys = session.get(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"]);
|
||||||
|
var token = "";
|
||||||
|
var user = userModule.getCarbonUser();
|
||||||
|
var tenantDomain = user.domain;
|
||||||
|
if (encodedClientKeys) {
|
||||||
|
var tokenUtil = require("/app/modules/oauth/token-handler-utils.js")["utils"];
|
||||||
|
var resp = tokenUtil.decode(encodedClientKeys).split(":");
|
||||||
|
var tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username,"default", {});
|
||||||
|
if (tokenPair) {
|
||||||
|
token = tokenPair.accessToken;
|
||||||
|
}
|
||||||
|
if (tenantDomain == "carbon.super") {
|
||||||
|
websocketEndpoint = websocketEndpoint + "/secured-websocket/" + tenantDomain + "." + device.type + "/1.0.0?"
|
||||||
|
+ "deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type + "&websocketToken=" + token;
|
||||||
|
} else {
|
||||||
|
websocketEndpoint = websocketEndpoint + "/t/" + tenantDomain + "/secured-websocket/" + tenantDomain
|
||||||
|
+ "." + device.type + "/1.0.0?" + "deviceId=" + device.deviceIdentifier + "&deviceType="
|
||||||
|
+ device.type + "&websocketToken=" + token;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return {"device": device, "websocketEndpoint": websocketEndpoint, "attributes": attributes};
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var ws;
|
||||||
|
var attributes = null;
|
||||||
|
$(window).load(function () {
|
||||||
|
var div = $("#div-chart");
|
||||||
|
var websocketUrl = div.data("websocketurl");
|
||||||
|
attributes = div.data("attributes").split(",");
|
||||||
|
connect(websocketUrl)
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).unload(function () {
|
||||||
|
disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
|
//websocket connection
|
||||||
|
function connect(target) {
|
||||||
|
if ('WebSocket' in window) {
|
||||||
|
ws = new WebSocket(target);
|
||||||
|
} else if ('MozWebSocket' in window) {
|
||||||
|
ws = new MozWebSocket(target);
|
||||||
|
} else {
|
||||||
|
console.log('WebSocket is not supported by this browser.');
|
||||||
|
}
|
||||||
|
if (ws) {
|
||||||
|
ws.onmessage = function (webSocketData) {
|
||||||
|
var data = JSON.parse(webSocketData.data);
|
||||||
|
var payloadData = data["event"]["payloadData"];
|
||||||
|
for (var i = 0; i < attributes.length; i++){
|
||||||
|
$("#" + attributes[i] +"-value").text(payloadData[attributes[i]]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function disconnect() {
|
||||||
|
if (ws != null) {
|
||||||
|
ws.close();
|
||||||
|
ws = null;
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue