refactoring events api

application-manager-new
Rasika Perera 9 years ago
parent 42a04c2660
commit dfed7671bf

@ -25,60 +25,17 @@ var log = new Log("api/event-api.jag");
var constants = require("/modules/constants.js");
var dcProps = require('/config/dc-props.js').config();
var eventModule = require("/modules/event.js").eventModule;
var result;
if (uriMatcher.match("/{context}/api/event/list")) {
var user = session.get(constants.USER_SESSION_KEY);
if (!user) {
response.sendRedirect(dcProps.appContext + "login?#login-required");
exit();//stop execution
}
var result;
if (uriMatcher.match("/{context}/api/event/list")) {
/*
var timeInterval = 30;
var i, rnd;
result = [];
var currentDay = new Date();
var startDate = currentDay.getTime() - (60 * 60 * 24 * 100);
var endDate = currentDay.getTime();
var i = parseInt(startDate / 1000);
while (i < parseInt(endDate / 1000)) {
rnd = rnd = Math.random() * 50;
result.push({time: i * 1000, deviceName: 'device' + rnd, activity:'Event number ' + rnd});
i += timeInterval;
}
*/
try {
result = statsClient.getRecentDeviceStats(user, 10);
} catch (error) {
log.error(error);
}
<<<<<<< HEAD
var eventsData = [];
if (fetchedData == null) return [];
for (var i = 0; i < fetchedData.size(); i++) {
//eventsData.push({
// time: fetchedData.get(i).getTime(),
// deviceName: fetchedData.get(i).getDeviceName(),
// activity: fetchedData.get(i).getDeviceActivity()
//});
eventsData.push({
time: 234234,
deviceName: "my device",
activity: "test"
});
}
return eventsData;
=======
>>>>>>> 91ab732dba19d87bc74860cfc7eca8953beb2120
result = eventModule.getEventsData(user.username, 10);
}
// returning the result.

@ -0,0 +1,74 @@
/*
* 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 eventModule;
eventModule = function () {
var log = new Log("modules/event.js");
var constants = require("/modules/constants.js");
var utility = require("/modules/utility.js").utility;
var publicMethods = {};
var privateMethods = {};
var statsClient = new Packages.org.wso2.carbon.device.mgt.iot.common.analytics.statistics.IoTEventsStatisticsClient;
publicMethods.getEventsData = function (username, recordLimit) {
var fetchedData = null;
try {
fetchedData = statsClient.getRecentDeviceStats(username, recordLimit);
} catch (error) {
log.error(error);
}
var eventsData = [];
// -- start of dummy data
var timeInterval = 30;
var i, rnd;
var currentDay = new Date();
var startDate = currentDay.getTime() - (60 * 60 * 24 * 5);
var endDate = currentDay.getTime();
var i = parseInt(startDate / 1000);
while (i < parseInt(endDate / 1000)) {
rnd = rnd = Math.random() * 50;
eventsData.push({time: i*1000, deviceName: 'device' + rnd, activity:'Event number ' + rnd});
i += timeInterval;
}
// -- end of dummy data
// for (var i = 0; i < fetchedData.size(); i++) {
// eventsData.push({
// time: fetchedData.get(i).getTime(),
// deviceName: fetchedData.get(i).getDeviceName(),
// activity: fetchedData.get(i).getDeviceActivity()
// });
// };
return eventsData;
};
return publicMethods;
}();

@ -3,7 +3,7 @@
<div class=" margin-top-double">
<div class="row row padding-top-double padding-bottom-double margin-bottom-double">
<div class="col-lg-12 margin-top-double">
<h1 class="grey ">Events</h1>
<h1 class="grey ">Device Events Stream</h1>
<hr>
<p class="margin-bottom-double light-grey ">Events Analyzer </p>
</div>

@ -1,10 +1,3 @@
<div class="col-lg-12 wr-secondary-bar" style="width: inherit;">
<label class="device-id device-select" style="font-size: 20px; margin-bottom: 0px;">
Device Events Stream
</label>
</div>
<br/>
<div style="padding: 15px;">
<table class="table table-striped table-bordered">
<thead>

Loading…
Cancel
Save