Skip to content
This repository has been archived by the owner on Jun 21, 2018. It is now read-only.

Commit

Permalink
Add notifications page to remove failed
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlexx committed Apr 5, 2016
1 parent 2ab9386 commit f99911b
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
6 changes: 6 additions & 0 deletions static/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {EventsController} from './controllers/events';
import {PatternsController} from './controllers/patterns';
import {SettingsController} from './controllers/settings';
import {TagsController} from './controllers/tags';
import {NotificationsController} from './controllers/notifications';

import {ApiStatus} from './directives/apistatus';
import {NewContact} from './directives/newcontact';
Expand Down Expand Up @@ -56,6 +57,7 @@ app.controller('EventsController', EventsController);
app.controller('PatternsController', PatternsController);
app.controller('SettingsController', SettingsController);
app.controller('TagsController', TagsController);
app.controller('NotificationsController', NotificationsController);

app.config(['$routeProvider',
function ($routeProvider:ng.route.IRouteProvider) {
Expand Down Expand Up @@ -83,6 +85,10 @@ app.config(['$routeProvider',
template: require('../tags.html'),
controller: 'TagsController',
controllerAs: 'ctrl'
}).when('/notifications/', {
template: require('../notifications.html'),
controller: 'NotificationsController',
controllerAs: 'ctrl'
}).otherwise({
redirectTo: '/triggers/'
});
Expand Down
61 changes: 61 additions & 0 deletions static/app/controllers/notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {Api} from '../services/api';
import {UniqList} from '../models/core';
import {Timestamp} from '../models/timestamp';

export interface INotificationContact{
value: string;
type: string;
}

export interface INotification {
contact: INotificationContact;
throttled: boolean;
send_fail: number;
timestamp: number;
}

export class Notification {
throttled: boolean;
timestamp: Timestamp;
send_fail: number;
contact: INotificationContact;

constructor(public json: string){
var notification = <INotification>JSON.parse(json);
this.timestamp = new Timestamp(notification.timestamp);
this.send_fail = notification.send_fail;
this.throttled = notification.throttled;
this.contact = notification.contact;
}
}

export interface INotificationsScope extends ng.IScope {
total: number;
list: UniqList<Notification>;
}

export class NotificationsController {

static $inject = ['$scope', 'api'];

constructor(private $scope: INotificationsScope, private api: Api) {
api.config().then((config) => {
return api.notification.list()
.then((data) => {
$scope.total = data.total;
$scope.list = new UniqList<Notification>([]);
angular.forEach(data.list, (json) => {
$scope.list.push(new Notification(json));
});
});
});
}

remove(notification: Notification){
this.api.notification.remove(notification.json).then((data) => {
if(data.result > 0){
this.$scope.list.remove(notification);
}
});
}
}
14 changes: 14 additions & 0 deletions static/app/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {ISettingsJson} from '../models/settings';
import {ISubscriptionJson, Subscription} from '../models/subscription';
import {Config, IConfigJson} from '../models/config';

export interface INotificationsList{
total: number;
list: Array<string>;
}

export interface IContactsList {
list: Array<IContactJson>;
}
Expand Down Expand Up @@ -169,6 +174,15 @@ export class Api {
}
};

notification = {
list: ():ng.IPromise<INotificationsList> => {
return this._query("notification?start=0&end=-1", "GET");
},
remove: (json: string) => {
return this._query("notification?json=" + json, "DELETE");
}
};

contact = {
save: (data): ng.IPromise<IContactJson> => {
return this._query("contact", "PUT", data);
Expand Down
23 changes: 23 additions & 0 deletions static/notifications.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div class="container">
<table class="highlight bordered">
<tbody>
<tr>
<th>Timestamp</th>
<th colspan="2">Contact</th>
<th>Throttled</th>
<th>Fails</th>
<th>Remove</th>
</tr>
<tr ng-repeat="notification in list">
<td>
<moira-timestamp timestamp="notification.timestamp"></moira-timestamp>
</td>
<td ng-bind="notification.contact.type"></td>
<td ng-bind="notification.contact.value"></td>
<td ng-bind="notification.throttled"></td>
<td ng-bind="notification.send_fail"></td>
<td><i class="clickable material-icons" ng-click="ctrl.remove(notification)">delete</i></td>
</tr>
</tbody>
</table>
</div>

0 comments on commit f99911b

Please sign in to comment.