94aeb93521fad1656d3895c50e167cba98cc66ac
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / ux / mwtnPerformanceHistory / mwtnPerformanceHistory-module / src / main / resources / mwtnPerformanceHistory / mwtnPerformanceHistory.services.js
1 /*
2  * Copyright (c) 2016 HCL Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 define(['app/mwtnCommons/mwtnCommons.module', 'app/mwtnPerformanceHistory/mwtnPerformanceHistory.module'], function (mwtnPerformanceHistoryoryApp) {
10
11   mwtnPerformanceHistoryoryApp.register.factory('$mwtnPerformanceHistory', function ($q, $mwtnCommons, $mwtnDatabase, $mwtnLog) {
12
13     var COMPONENT = '$mwtnPerformanceHistory';
14     $mwtnLog.info({ component: COMPONENT, message: '$mwtnPerformanceHistory started!' });
15
16     var service = {};
17     service.formatTimeStamp = $mwtnCommons.formatTimeStamp;
18     service.getMountPoints = $mwtnCommons.getMountPoints;
19     service.getPacParts = $mwtnCommons.getPacParts;
20     service.layerProtocolNameOrder = $mwtnCommons.layerProtocolNameOrder;
21     
22     service.yangifyObject = $mwtnCommons.yangifyObject;
23
24     service.TimeStampToONFFormat = function (timestamp) {
25       timestamp = timestamp.split('-').join('');
26       timestamp = timestamp.split(':').join('');
27       timestamp = timestamp.split(' ').join('');
28       timestamp = timestamp.replace('UTC', 'Z');
29       return timestamp;
30     };
31
32     service.getFilteredSortedData = function (from, size, sort, query, selected15minPeriod) {
33       var func = function () {
34         if (selected15minPeriod) {
35           return $mwtnDatabase.getFilteredSortedData('sdnperformance', 'historicalperformance15min', from, size, sort, query);
36         } else {
37           return $mwtnDatabase.getFilteredSortedData('sdnperformance', 'historicalperformance24h', from, size, sort, query);
38         }
39       };
40       var deferred = $q.defer();
41       func().then(function (success) {
42         deferred.resolve(success);
43       }, function (error) {
44         $mwtnLog.error({ component: '$mwtnHistPerformance.getFilteredSortedData', message: JSON.stringify(error.data) });
45         deferred.reject(error)
46       });
47       return deferred.promise;
48
49     };
50
51     return service;
52   });
53
54 });