2 * Copyright (c) 2016 highstreet technologies GmbH and others. All rights reserved.
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
9 define(['app/mwtnLog/mwtnLog.module',
10 'app/mwtnLog/mwtnLog.services',
11 'app/mwtnCommons/mwtnCommons.module'],
12 function(mwtnLogApp) {
14 mwtnLogApp.register.controller('mwtnLogCtrl', ['uiGridConstants', '$uibModal', '$scope', '$rootScope', '$mwtnCommons', '$mwtnLogView', '$mwtnLog' ,
15 function(uiGridConstants, $uibModal, $scope, $rootScope, $mwtnCommons, $mwtnLogView, $mwtnLog) {
17 var COMPONENT = 'mwtnLogCtrl';
18 $mwtnLog.info({component: COMPONENT, message: 'mwtnLogCtrl started!'});
19 // $mwtnLog.error({component: COMPONENT, message: 'Just a test of logging an error.'});
20 // $mwtnLog.warning({component: COMPONENT, message: 'Just a test of logging a warning.'});
21 // $mwtnLog.debug({component: COMPONENT, message: 'Just a test of logging debug information.'});
23 $rootScope.section_logo = 'src/app/mwtnLog/images/mwtnLog.png'; // Add your topbar logo location here such as 'assets/images/logo_topology.gif'
25 $scope.highlightFilteredHeader = $mwtnLogView.highlightFilteredHeader;
27 var rowTemplate = '<div ng-click="grid.appScope.fnOne(row)" ng-repeat="col in colContainer.renderedColumns track by col.colDef.name" ng-class="[\'ui-grid-cell\', row.entity.type]" ui-grid-cell></div>';
28 var iconCell = '<div class="ui-grid-cell-contents tooltip-uigrid" title="TOOLTIP"><i ng-class="{\'fa\':true, \'{{COL_FIELD}}\':true}" aria-hidden="true"></i></div>';
30 $scope.gridOptions = JSON.parse(JSON.stringify($mwtnLogView.gridOptions));
31 $scope.gridOptions.rowTemplate = rowTemplate;
32 $scope.gridOptions.columnDefs = [
33 // { field: 'id', type: 'number', displayName: 'No.', headerCellClass: $scope.highlightFilteredHeader, width : 50, cellClass: 'number', pinnedLeft : true },
34 { field: 'icon', type: 'string', displayName: '', headerCellClass: $scope.highlightFilteredHeader, width: 25, enableSorting: false, enableFiltering:false, cellTemplate: iconCell },
35 { field: 'timestamp', type: 'string', displayName: 'Timestamp', headerCellClass: $scope.highlightFilteredHeader, width : 200,sort: {
36 direction: uiGridConstants.DESC,
39 { field: 'type', type: 'string', displayName: 'Type', headerCellClass: $scope.highlightFilteredHeader, width: 70 },
40 { field: 'component', type: 'string', displayName: 'Component', headerCellClass: $scope.highlightFilteredHeader, width : 200 },
41 { field: 'message', type: 'string', displayName: 'Message', headerCellClass: $scope.highlightFilteredHeader, width : 500 }
50 $scope.clearLog = function () {
52 var modalInstance = $uibModal.open({
54 ariaLabelledBy: 'modal-title',
55 ariaDescribedBy: 'modal-body',
56 templateUrl: 'src/app/mwtnLog/templates/clearLogConfirmation.tpl.html',
57 controller: 'ClearLogCtrl',
61 return new Date().toISOString();
66 modalInstance.result.then(function () {
74 $mwtnLogView.deleteDocType(spec).then(function(deleted){
75 $scope.gridOptions.data = [];
76 $mwtnLog.info({component: COMPONENT, message: 'Log cleared!'});
78 $mwtnLog.error({component: COMPONENT, message:JSON.stringify(error)});
81 $mwtnLog.info({component: COMPONENT, message: 'Mount dismissed!'});
85 var getIconFromType = function(type) {
88 info : 'fa-info-circle',
89 warning : 'fa-exclamation-triangle',
90 error : 'fa-times-circle'
95 var processLogEntries = function(logEntries) {
96 if (logEntries.data.hits.hits) {
97 logEntries.data.hits.hits.map(function(entry){
100 icon: getIconFromType(entry._source.type),
101 timestamp: entry._source.timestamp,
102 type: entry._source.type,
103 component: entry._source.component,
104 message: entry._source.message,
106 $scope.gridOptions.data.push(log);
108 $scope.progress.max = logEntries.data.hits.total;
109 $scope.progress.value = $scope.gridOptions.data.length;
110 $scope.progress.show = $scope.gridOptions.data.length < logEntries.data.hits.total;
114 $scope.refreshLog = function() {
115 $scope.gridOptions.data = [];
118 $scope.processing = true;
119 $mwtnLogView.getAllLogEntries(from, size).then(function(logEntries){
120 $scope.processing = false;
121 processLogEntries(logEntries);
123 while (from < $scope.progress.max) {
124 $mwtnLogView.getAllLogEntries(from, size).then(function(logEntries){
125 processLogEntries(logEntries);
127 console.error(JSON.stringify(error));
132 console.error(JSON.stringify(error));
139 mwtnLogApp.register.controller('ClearLogCtrl', ['$scope', '$uibModalInstance',
140 function ($scope, $uibModalInstance) {
142 $scope.ok = function () {
143 $uibModalInstance.close('ok');
146 $scope.cancel = function () {
147 $uibModalInstance.dismiss('cancel');