diff --git a/static/app/app.ts b/static/app/app.ts index bdb57b1..ba5461a 100644 --- a/static/app/app.ts +++ b/static/app/app.ts @@ -15,6 +15,7 @@ import {ApiStatus} from './directives/apistatus'; import {NewContact} from './directives/newcontact'; import {Contact} from './directives/contact'; import {Menu} from './directives/menu'; +import {Search} from './directives/search'; import {Selector} from './directives/selector'; import {Schedule} from './directives/schedule'; import {SubEditor} from './directives/subeditor'; @@ -47,6 +48,7 @@ app.directive('moiraMenu', Menu); app.directive('moiraSelector', Selector); app.directive('moiraSubEditor', SubEditor); app.directive('moiraSchedule', Schedule); +app.directive('moiraSearch', Search); app.directive('moiraTag', Tag); app.directive('moiraTagsFilterList', TagsFilterList); app.directive('moiraTimestamp', Timestamp); diff --git a/static/app/controllers/triggers.ts b/static/app/controllers/triggers.ts index b042dd3..dfbd043 100644 --- a/static/app/controllers/triggers.ts +++ b/static/app/controllers/triggers.ts @@ -20,6 +20,7 @@ export interface ITriggersScope extends ng.IScope, IPagingScope { show_trigger_metrics: Array; show_trigger: Trigger; show_maintenance_check: MetricCheck; + search_string: string; } export class TriggersController { @@ -35,15 +36,15 @@ export class TriggersController { var saved_tags = ($cookies.get(TriggersController.TagsFilterCookie) || "").split(',').filter(function (tag: string) { return tag != ""; }); + + $scope.search_string = ""; $scope.tags_filter = new TagFilter(new TagList(saved_tags)); $scope.ok_filter = $cookies.get(TriggersController.TagsOkFilterCookie) == "true"; $scope.metric_values = {}; - $scope.$watch('tags_filter.selection.length', (newValue: number, oldValue: number) => { + $scope.$watch('search_string.length', (newValue: number, oldValue: number) => { if (newValue != oldValue) { - $cookies.put(TriggersController.TagsFilterCookie, $scope.tags_filter.selection.to_string().join(), - { expires: new Date((new Date()).getTime() + TriggersController.CookieLiveSpan) }); this.$location.search({page: 0}); this.$scope.page = 0; this.load_triggers(); @@ -59,7 +60,7 @@ export class TriggersController { this.load_triggers(); } }); - + $scope.$on('$routeUpdate', (scope, next: ng.route.ICurrentRoute) => { if(this.$scope.page === parseInt(next.params['page'])) return; @@ -82,7 +83,7 @@ export class TriggersController { load_triggers() { var num = parseInt(this.$location.search()['page'] || 0); this.$scope.page = num; - this.api.trigger.page(num, this.$scope.size).then((data) => { + this.api.trigger.page(num, this.$scope.size, this.$scope.search_string).then((data) => { this.$scope.triggers = []; this.$scope.total = data.total; InitPagesList(this.$scope); @@ -138,8 +139,11 @@ export class TriggersController { tag.data = data; }); } else { - if (!this.$scope.tags_filter.selection.contains(tag) && this.$scope.tags.contains(tag)) { - this.$scope.tags_filter.selection.push(tag); + if (this.$scope.search_string === undefined) { + this.$scope.search_string = ""; + } + if (this.$scope.search_string.indexOf('#' + tag.value) == -1) { + this.$scope.search_string += ' #' + tag.value; } } }; diff --git a/static/app/directives/search.ts b/static/app/directives/search.ts new file mode 100644 index 0000000..c38917b --- /dev/null +++ b/static/app/directives/search.ts @@ -0,0 +1,28 @@ +declare function require(string): any; + +export interface ISearchScope extends ng.IScope{ + model:String; + clear(); +} + +export function Search(): ng.IDirective { + + const max_items:number = 99; + + return { + restrict: 'E', + template: require('./templates/search.html'), + + replace: true, + transclude: true, + scope: { + model:"=model", + placeholder:"@placeholder", + }, + link: function (scope:ISearchScope, element:JQuery, attrs:ng.IAttributes) { + scope.clear = () => { + scope.model = ""; + }; + } + }; +} diff --git a/static/app/directives/templates/search.html b/static/app/directives/templates/search.html new file mode 100644 index 0000000..806058e --- /dev/null +++ b/static/app/directives/templates/search.html @@ -0,0 +1,11 @@ + diff --git a/static/app/services/api.ts b/static/app/services/api.ts index aa8a353..d08d662 100644 --- a/static/app/services/api.ts +++ b/static/app/services/api.ts @@ -125,8 +125,8 @@ export class Api { delete: (trigger_id: string) => { return this._query("trigger/" + trigger_id, "DELETE"); }, - page: (num: number, size: number): ng.IPromise => { - return this._query(`trigger/page?p=${num}&size=${size}`, "GET"); + page: (num: number, size: number, q: string): ng.IPromise => { + return this._query(`trigger/page?p=${num}&size=${size}&q=${encodeURIComponent(q || '')}`, "GET"); }, get: (trigger_id: string): ng.IPromise => { return this._query("trigger/" + trigger_id, "GET") @@ -229,4 +229,4 @@ export class Api { }), "GET"); } }; -} \ No newline at end of file +} diff --git a/static/tests/controllers/triggers.ts b/static/tests/controllers/triggers.ts index 422e5b4..20056c9 100644 --- a/static/tests/controllers/triggers.ts +++ b/static/tests/controllers/triggers.ts @@ -75,7 +75,7 @@ describe("TriggersController", () => { it("two trigger rows rendered", () => { expect(element.find(".trigger-row").length).toBe(1); }); - + }); describe("open trigger", () => { @@ -103,7 +103,7 @@ describe("TriggersController", () => { }); }); }); - + describe("show trigger metrics", () => { beforeEach(() => { controller.toggle_trigger_metrics('WARN', scope.triggers[0]); @@ -115,7 +115,7 @@ describe("TriggersController", () => { expect(scope.show_trigger_metrics[0].value.num).toBe(1); }); }); - + describe("add filter tag", () => { var event: IAltKeyEvent; beforeEach(() => { @@ -155,4 +155,4 @@ describe("TriggersController", () => { }); }); }); -}) \ No newline at end of file +}) diff --git a/static/triggers.html b/static/triggers.html index 65d57d4..ebbeaec 100644 --- a/static/triggers.html +++ b/static/triggers.html @@ -2,9 +2,8 @@
- - - + +
Subscribed: