Actionbar: Added notifications

Change-Id: Ib6889e9097604dd05412dab07b3d12bd97560d96
This commit is contained in:
aviau 2015-05-19 15:27:28 -04:00
parent 7e1d9c1260
commit b9de9d7071
9 changed files with 80 additions and 41 deletions

View File

@ -361,8 +361,6 @@ angular.module('bansho.live', [])
url: '/surveil/v2/actions/acknowledge/',
method: 'POST',
data: data
}).error(function () {
throw new Error('acknowledge : POST Request failed');
});
};

View File

@ -0,0 +1,21 @@
'use strict';
angular.module('bansho.notifications', [])
.service('notifications', [
function () {
var push = function (type, title, message) {
$(function(){
new PNotify({
type: type,
title: title,
text: message,
styling: {},
});
});
};
return {
"push": push
};
}]);

View File

@ -1,6 +1,6 @@
'use strict';
angular.module('bansho.table.actionbar', ['bansho.table', 'bansho.live'])
angular.module('bansho.table.actionbar', ['bansho.table', 'bansho.live', 'bansho.notifications'])
.service('actionbarFilters', function () {
var actionbarFilters = {

View File

@ -14,28 +14,34 @@ angular.module('bansho.table.actionbar')
})
.controller('banshoAcknowledgeFormCtrl',
['$scope', '$filter', 'tablesConfig', 'actionbarFilters', 'backendClient',
function ($scope, $filter, tablesConfig, actionbarFilters, backendClient) {
['$scope', '$filter', 'tablesConfig', 'actionbarFilters', 'backendClient', 'notifications',
function ($scope, $filter, tablesConfig, actionbarFilters, backendClient, notifications) {
$scope.acknowledgeProblems = function () {
angular.forEach(tablesConfig, function (tableConfig) {
var entries = $filter('filter')(tableConfig.entries,
angular.forEach(tablesConfig, function (table) {
var entries = $filter('filter')(table.entries,
actionbarFilters.searchFilter);
table.isCheckAll = false;
angular.forEach(entries, function (entry) {
var service_description;
if (entry.is_checked) {
entry.is_checked = false;
if ('description' in entry) {
service_description = entry.description;
}
backendClient.acknowledge(entry.host_name, service_description, $scope.attrs).error(function (data) {
throw new Error('Acknowledge request failed');
});
backendClient.acknowledge(entry.host_name, service_description, $scope.attrs).then(function (data) {
notifications.push('success', 'Acknowledgement', 'Acknowledged ' + entry.host_name);
},
function (error) {
notifications.push('error', 'Acknowledgement', 'Could not acknowledge ' + entry.host_name);
});
}
});
});
$scope.isShown = false;
};
}])
@ -51,39 +57,33 @@ angular.module('bansho.table.actionbar')
})
.controller('banshoDowntimeFormCtrl',
['$scope', '$filter', 'tablesConfig', 'actionbarFilters', 'backendClient',
function ($scope, $filter, tablesConfig, actionbarFilters, backendClient) {
$scope.messages = [];
['$scope', '$filter', 'tablesConfig', 'actionbarFilters', 'backendClient', 'notifications',
function ($scope, $filter, tablesConfig, actionbarFilters, backendClient, notifications) {
$scope.sendDowntime = function () {
angular.forEach(tablesConfig, function (table) {
var entries = $filter('filter')(table.entries, actionbarFilters.searchFilter);
table.isCheckAll = false;
angular.forEach(entries, function (entry) {
var service_description;
if (entry.is_checked) {
entry.is_checked = false;
if ('description' in entry) {
service_description = entry.description;
}
backendClient.downtime(entry.host_name, service_description, $scope.attrs).then(function (data) {
$scope.messages.push({
text: entry.host_name + " success ",
type: "success"
});
$scope.isShown = false;
notifications.push('success', 'Downtime', 'Added downtime for ' + entry.host_name);
},
function (error) {
$scope.messages.push({
text: entry.host_name + " error",
type: "error"
});
notifications.push('error', 'Downtime', 'Could not add downtime for ' + entry.host_name);
});
}
});
});
$scope.isShown = false;
};
}])
@ -91,42 +91,33 @@ angular.module('bansho.table.actionbar')
return {
restrict: 'E',
templateUrl: 'components/table/actionbar/actions/recheck_button.html',
scope: {
isShown: '='
},
controller: 'banshoRecheckButtonCtrl'
};
})
.controller('banshoRecheckButtonCtrl',
['$scope', '$filter', 'tablesConfig', 'actionbarFilters', 'backendClient',
function ($scope, $filter, tablesConfig, actionbarFilters, backendClient) {
$scope.messages = [];
['$scope', '$filter', 'tablesConfig', 'actionbarFilters', 'backendClient', 'notifications',
function ($scope, $filter, tablesConfig, actionbarFilters, backendClient, notifications) {
$scope.sendRecheck = function () {
angular.forEach(tablesConfig, function (table) {
var entries = $filter('filter')(table.entries, actionbarFilters.searchFilter);
table.isCheckAll = false;
angular.forEach(entries, function (entry) {
var service_description;
if (entry.is_checked) {
entry.is_checked = false;
if ('description' in entry) {
service_description = entry.description;
}
backendClient.recheck(entry.host_name, service_description).then(function (data) {
$scope.messages.push({
text: entry.host_name + " success ",
type: "success"
});
notifications.push('success', 'Recheck', 'Scheduled recheck for ' + entry.host_name);
},
function (error) {
$scope.messages.push({
text: entry.host_name + " error",
type: "error"
});
notifications.push('error', 'Recheck', 'Could not schedule recheck for ' + entry.host_name);
});
}
});

View File

@ -1,4 +1,3 @@
<div ng-repeat="message in messages">{{message.text}} + {{message.type}}</div>
<h4>Downtime</h4>
<form ng-submit="sendDowntime()">
<div>

View File

@ -1,7 +1,7 @@
<table class="data-table" ng-controller="TableCtrl">
<thead>
<tr>
<th class="data-table__checkbox"><input type="checkbox"></th>
<th class="data-table__checkbox"><input type="checkbox" ng-click="onCheckChange()" ng-model="isCheckAll"></th>
<th ng-repeat="i in cellIndexes" class="data-table__{{cellsName[i]}}">
{{cellsText[i]}}
<i class="ico-up-dir"></i>

View File

@ -28,6 +28,20 @@ angular.module('bansho.table', ['bansho.live',
$scope.cellsText = conf.cells.text;
$scope.cellIndexes = [];
$scope.$watch(function () {
return conf.isCheckAll;
}, function () {
$scope.isCheckAll = conf.isCheckAll;
});
$scope.onCheckChange = function(){
conf.isCheckAll = $scope.isCheckAll;
angular.forEach(conf.entries, function (entry) {
entry.is_checked = $scope.isCheckAll;
});
};
for (i = 0; i < $scope.cellsName.length; i += 1) {
$scope.cellIndexes.push(i);
}

View File

@ -10,6 +10,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='http://fonts.googleapis.com/css?family=Roboto:400,700,400italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="assets/css/app.css">
<!-- pnotify css -->
<link href="bower_components/pnotify/pnotify.core.css" media="all" rel="stylesheet" type="text/css" />
<link href="bower_components/pnotify/pnotify.buttons.css" media="all" rel="stylesheet" type="text/css" />
<link href="bower_components/pnotify/pnotify.history.css" media="all" rel="stylesheet" type="text/css" />
<meta name="description" content="">
<!-- build:js js/app.min.js -->
@ -25,6 +31,14 @@
<script src="assets/js/scripts.js"></script>
<script src="bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js"></script>
<!-- pnotify js -->
<script src="bower_components/pnotify/pnotify.core.js"></script>
<script src="bower_components/pnotify/pnotify.buttons.js"></script>
<script src="bower_components/pnotify/pnotify.callbacks.js"></script>
<script src="bower_components/pnotify/pnotify.confirm.js"></script>
<script src="bower_components/pnotify/pnotify.desktop.js"></script>
<script src="bower_components/pnotify/pnotify.nonblock.js"></script>
<script src="app.js"></script>
<script src="components/config/config.js"></script>
<script src="components/utils/promise_manager.js"></script>
@ -32,6 +46,7 @@
<script src="components/authentication/authentication.js"></script>
<script src="components/ng-justgage/ng-justgage.js"></script>
<script src="components/filters/filters.js"></script>
<script src="components/notifications/notifications.js"></script>
<script src="components/sidebar/sidebar.js"></script>
<script src="components/topbar/topbar.js"></script>
<script src="components/tactical/tactical.js"></script>

View File

@ -15,6 +15,7 @@
"justgage-toorshia": "master",
"moment": "~2.9.0",
"angular-filter": "~0.5.4",
"angular-cookies": "~1.3.15"
"angular-cookies": "~1.3.15",
"pnotify": "~2.0.1"
}
}