summaryrefslogtreecommitdiff
path: root/www/js/TimelineModalCtrl.js
diff options
context:
space:
mode:
authorpliablepixels <pliablepixels@gmail.com>2016-03-24 10:48:19 -0400
committerpliablepixels <pliablepixels@gmail.com>2016-03-24 10:48:19 -0400
commit525040ea685a0b7db5a406617613a26a9396db0b (patch)
tree9ea4646bfeb294f255a24cb54316007428a828e5 /www/js/TimelineModalCtrl.js
parentfad1846bc42f42e81c471099eb9ebd5be717e7be (diff)
#209 - initial code
Former-commit-id: 29fa2335ee0ee56c063d69feeb6a299b9f74bcf8
Diffstat (limited to 'www/js/TimelineModalCtrl.js')
-rw-r--r--www/js/TimelineModalCtrl.js239
1 files changed, 239 insertions, 0 deletions
diff --git a/www/js/TimelineModalCtrl.js b/www/js/TimelineModalCtrl.js
new file mode 100644
index 00000000..7f41dc54
--- /dev/null
+++ b/www/js/TimelineModalCtrl.js
@@ -0,0 +1,239 @@
+// Common Controller for the montage view
+/* jshint -W041 */
+/* jslint browser: true*/
+/* global saveAs, cordova,StatusBar,angular,console,ionic, moment */
+
+
+
+
+angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '$rootScope', 'zm', 'ZMDataModel', '$ionicSideMenuDelegate', '$timeout', '$interval', '$ionicModal', '$ionicLoading', '$http', '$state', '$stateParams', '$ionicHistory', '$ionicScrollDelegate', '$q', '$sce', 'carouselUtils', '$ionicPopup', function ($scope, $rootScope, zm, ZMDataModel, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http, $state, $stateParams, $ionicHistory, $ionicScrollDelegate, $q, $sce, carouselUtils, $ionicPopup) {
+
+
+ //----------------------------------------------------------------
+ // Alarm notification handling
+ //----------------------------------------------------------------
+ $scope.handleAlarms = function () {
+ $rootScope.isAlarm = !$rootScope.isAlarm;
+ if (!$rootScope.isAlarm) {
+ $rootScope.alarmCount = "0";
+ $ionicHistory.nextViewOptions({
+ disableBack: true
+ });
+ $state.go("events", {
+ "id": 0
+ }, {
+ reload: true
+ });
+ }
+ };
+
+
+
+ //-------------------------------------------------------
+ // we use this to reload the connkey if authkey changed
+ //------------------------------------------------------
+
+
+ $rootScope.$on("auth-success", function () {
+
+ ZMDataModel.zmDebug("EventModalCtrl: Re-login detected, resetting everything & re-generating connkey");
+
+
+ });
+
+
+
+ $scope.$on('modal.removed', function () {
+
+
+ // Execute action
+ });
+
+ $scope.$on('modal.shown', function () {
+
+ $scope.dataReady = false;
+
+ $scope.eventdetails = "loading...";
+ processEvent();
+ //$scope.eventdetails = JSON.stringify($scope.event);
+ });
+
+
+ function processEvent()
+ {
+ var eid = $scope.event.Event.Id;
+ var ld = ZMDataModel.getLogin();
+ var apiurl = ld.apiurl + "/events/"+eid+".json";
+ ZMDataModel.zmLog ("Getting " + apiurl);
+ $http.get (apiurl)
+ .then (function (success)
+ {
+ $scope.eventdetails = JSON.stringify(success);
+ drawGraph(success);
+ },
+ function (error)
+ {
+ $scope.eventdetails = JSON.stringify(error);
+ });
+ }
+
+
+ function drawGraph(event)
+ {
+ // Chart.js Data
+ $scope.data = {
+ labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
+ datasets: [
+ {
+ label: 'My First dataset',
+ fillColor: 'rgba(220,220,220,0.2)',
+ strokeColor: 'rgba(220,220,220,1)',
+ pointColor: 'rgba(220,220,220,1)',
+ pointStrokeColor: '#fff',
+ pointHighlightFill: '#fff',
+ pointHighlightStroke: 'rgba(220,220,220,1)',
+ data: [65, 59, 80, 81, 56, 55, 40]
+ },
+ {
+ label: 'My Second dataset',
+ fillColor: 'rgba(151,187,205,0.2)',
+ strokeColor: 'rgba(151,187,205,1)',
+ pointColor: 'rgba(151,187,205,1)',
+ pointStrokeColor: '#fff',
+ pointHighlightFill: '#fff',
+ pointHighlightStroke: 'rgba(151,187,205,1)',
+ data: [28, 48, 40, 19, 86, 27, 90]
+ }
+ ]
+ };
+
+ // Chart.js Options
+ $scope.options = {
+
+ // Sets the chart to be responsive
+ responsive: true,
+
+ ///Boolean - Whether grid lines are shown across the chart
+ scaleShowGridLines : true,
+
+ //String - Colour of the grid lines
+ scaleGridLineColor : "rgba(0,0,0,.05)",
+
+ //Number - Width of the grid lines
+ scaleGridLineWidth : 1,
+
+ //Boolean - Whether the line is curved between points
+ bezierCurve : true,
+
+ //Number - Tension of the bezier curve between points
+ bezierCurveTension : 0.4,
+
+ //Boolean - Whether to show a dot for each point
+ pointDot : true,
+
+ //Number - Radius of each point dot in pixels
+ pointDotRadius : 4,
+
+ //Number - Pixel width of point dot stroke
+ pointDotStrokeWidth : 1,
+
+ //Number - amount extra to add to the radius to cater for hit detection outside the drawn point
+ pointHitDetectionRadius : 20,
+
+ //Boolean - Whether to show a stroke for datasets
+ datasetStroke : true,
+
+ //Number - Pixel width of dataset stroke
+ datasetStrokeWidth : 2,
+
+ //Boolean - Whether to fill the dataset with a colour
+ datasetFill : true,
+
+ // Function - on animation progress
+ onAnimationProgress: function(){},
+
+ // Function - on animation complete
+ onAnimationComplete: function(){},
+
+ //String - A legend template
+ legendTemplate : '<ul class="tc-chart-js-legend"><% for (var i=0; i<datasets.length; i++){%><li><span style="background-color:<%=datasets[i].strokeColor%>"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>'
+ };
+ $scope.json_data = JSON.stringify($scope.data);
+ $scope.dataReady = true;
+
+ }
+
+ //--------------------------------------------------------
+ // utility function
+ //--------------------------------------------------------
+
+ function computeRelativePath(event) {
+ var relativePath = "";
+ var loginData = ZMDataModel.getLogin();
+ var str = event.Event.StartTime;
+ var yy = moment(str).format('YY');
+ var mm = moment(str).format('MM');
+ var dd = moment(str).format('DD');
+ var hh = moment(str).format('HH');
+ var min = moment(str).format('mm');
+ var sec = moment(str).format('ss');
+ relativePath = event.Event.MonitorId + "/" +
+ yy + "/" +
+ mm + "/" +
+ dd + "/" +
+ hh + "/" +
+ min + "/" +
+ sec + "/";
+ return relativePath;
+
+ }
+
+ //--------------------------------------------------------
+ // utility function
+ //--------------------------------------------------------
+
+ function computeBasePath(event) {
+ var basePath = "";
+ var loginData = ZMDataModel.getLogin();
+ var str = event.Event.StartTime;
+ var yy = moment(str).format('YY');
+ var mm = moment(str).format('MM');
+ var dd = moment(str).format('DD');
+ var hh = moment(str).format('HH');
+ var min = moment(str).format('mm');
+ var sec = moment(str).format('ss');
+
+ basePath = loginData.url + "/events/" +
+ event.Event.MonitorId + "/" +
+ yy + "/" +
+ mm + "/" +
+ dd + "/" +
+ hh + "/" +
+ min + "/" +
+ sec + "/";
+ return basePath;
+ }
+
+
+
+ function padToN(number, digits) {
+
+ var i;
+ var stringMax = "";
+ var stringLeading = "";
+ for (i = 1; i <= digits; i++) {
+ stringMax = stringMax + "9";
+ if (i != digits) stringLeading = stringLeading + "0";
+ }
+ var numMax = parseInt(stringMax);
+
+ if (number <= numMax) {
+ number = (stringLeading + number).slice(-digits);
+ }
+ //console.log ("PADTON: returning " + number);
+ return number;
+ }
+
+
+
+}]);