Skip to content

Commit

Permalink
Add tag filter by click at trigger tag icon, #487
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Dec 16, 2017
1 parent 401ad69 commit b7dab30
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion dist/panel-triggers/partials/module.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
</span>

<span class="zbx-trigger-tags" ng-if="ctrl.panel.showTags && trigger.tags">
<span ng-repeat="tag in trigger.tags" tag-color-from-name="tag.tag+tag.value" class="label label-tag zbx-tag">
<span ng-repeat="tag in trigger.tags" ng-click="ctrl.addTagFilter(tag, trigger.datasource)"
tag-color-from-name="tag.tag+tag.value" class="label label-tag zbx-tag">
{{tag.tag}}: {{tag.value}}
</span>
</span>
Expand Down
16 changes: 16 additions & 0 deletions dist/panel-triggers/triggers_panel_ctrl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/panel-triggers/triggers_panel_ctrl.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/panel-triggers/partials/module.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
</span>

<span class="zbx-trigger-tags" ng-if="ctrl.panel.showTags && trigger.tags">
<span ng-repeat="tag in trigger.tags" tag-color-from-name="tag.tag+tag.value" class="label label-tag zbx-tag">
<span ng-repeat="tag in trigger.tags" ng-click="ctrl.addTagFilter(tag, trigger.datasource)"
tag-color-from-name="tag.tag+tag.value" class="label label-tag zbx-tag">
{{tag.tag}}: {{tag.value}}
</span>
</span>
Expand Down
15 changes: 15 additions & 0 deletions src/panel-triggers/triggers_panel_ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ export class TriggerPanelCtrl extends PanelCtrl {
}

parseTags(tagStr) {
if (!tagStr) {
return [];
}

let tags = _.map(tagStr.split(','), (tag) => tag.trim());
tags = _.map(tags, (tag) => {
const tagParts = tag.split(':');
Expand All @@ -420,6 +424,17 @@ export class TriggerPanelCtrl extends PanelCtrl {
return _.map(tags, (tag) => `${tag.tag}:${tag.value}`).join(', ');
}

addTagFilter(tag, ds) {
let tagFilter = this.panel.targets[ds].tags.filter;
let targetTags = this.parseTags(tagFilter);
let newTag = {tag: tag.tag, value: tag.value};
targetTags.push(newTag);
targetTags = _.uniqWith(targetTags, _.isEqual);
let newFilter = this.tagsToString(targetTags);
this.panel.targets[ds].tags.filter = newFilter;
this.refresh();
}

switchComment(trigger) {
trigger.showComment = !trigger.showComment;
}
Expand Down

0 comments on commit b7dab30

Please sign in to comment.