Skip to content

Commit

Permalink
Replace tag selection window with a search string moira-alert#48
Browse files Browse the repository at this point in the history
  • Loading branch information
bersegosx committed Sep 8, 2016
1 parent 568a019 commit 14958fe
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 17 deletions.
2 changes: 2 additions & 0 deletions static/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 11 additions & 7 deletions static/app/controllers/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ITriggersScope extends ng.IScope, IPagingScope {
show_trigger_metrics: Array<MetricCheck>;
show_trigger: Trigger;
show_maintenance_check: MetricCheck;
search_string: string;
}

export class TriggersController {
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
};
Expand Down
28 changes: 28 additions & 0 deletions static/app/directives/search.ts
Original file line number Diff line number Diff line change
@@ -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 = "";
};
}
};
}
11 changes: 11 additions & 0 deletions static/app/directives/templates/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<nav>
<div class="nav-wrapper">
<form>
<div class="input-field">
<input id="search" type="search" ng-model="model" required placeholder="{{placeholder}}">
<label for="search"><i class="material-icons">search</i></label>
<i class="material-icons" ng-click="clear()">close</i>
</div>
</form>
</div>
</nav>
6 changes: 3 additions & 3 deletions static/app/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ITriggersList> => {
return this._query(`trigger/page?p=${num}&size=${size}`, "GET");
page: (num: number, size: number, q: string): ng.IPromise<ITriggersList> => {
return this._query(`trigger/page?p=${num}&size=${size}&q=${encodeURIComponent(q || '')}`, "GET");
},
get: (trigger_id: string): ng.IPromise<ITriggerJson> => {
return this._query("trigger/" + trigger_id, "GET")
Expand Down Expand Up @@ -229,4 +229,4 @@ export class Api {
}), "GET");
}
};
}
}
8 changes: 4 additions & 4 deletions static/tests/controllers/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("TriggersController", () => {
it("two trigger rows rendered", () => {
expect(element.find(".trigger-row").length).toBe(1);
});

});

describe("open trigger", () => {
Expand Down Expand Up @@ -103,7 +103,7 @@ describe("TriggersController", () => {
});
});
});

describe("show trigger metrics", () => {
beforeEach(() => {
controller.toggle_trigger_metrics('WARN', scope.triggers[0]);
Expand All @@ -115,7 +115,7 @@ describe("TriggersController", () => {
expect(scope.show_trigger_metrics[0].value.num).toBe(1);
});
});

describe("add filter tag", () => {
var event: IAltKeyEvent;
beforeEach(() => {
Expand Down Expand Up @@ -155,4 +155,4 @@ describe("TriggersController", () => {
});
});
});
})
})
5 changes: 2 additions & 3 deletions static/triggers.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<div class="grey lighten-4">
<div class="container">
<div class="row fat-row">
<moira-selector model="tags_filter" placeholder="Type or select tags to filter" items="tags">
<moira-tag ng-repeat="tag in tags_filter.selection" item="tag" remove="ctrl.remove_filter_tag(tag)"></moira-tag>
</moira-selector>
<moira-search model="search_string" placeholder="Type #tag and/or trigger name/metric">
</moira-search>
<div class="hide-on-small-only col m14" style="height:100%; padding-top:2px">
<span class="small grey-text text-darken-1" ng-if="settings.sub_tags.length">Subscribed:</span>
<moira-tag item="tag" ng-repeat="tag in settings.sub_tags" ng-click="ctrl.tag_click(tag, $event)" class="clickable" disabled="{{tags_filter.selection.contains(tag)}}">
Expand Down

0 comments on commit 14958fe

Please sign in to comment.