Skip to content

Commit

Permalink
improve tag filtering in builder page
Browse files Browse the repository at this point in the history
+tag means all tags with + must be present in the builder tags
-tag means no tags with - must be present in the builder tags
tag means at least one of the filtered tag might be present
  • Loading branch information
Pierre Tardy committed Nov 3, 2015
1 parent 6a662c1 commit 9795d4c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 7 deletions.
2 changes: 2 additions & 0 deletions master/docs/relnotes/index.rst
Expand Up @@ -20,6 +20,8 @@ Master
Features
~~~~~~~~

* Builders ui page has improved tag filtering capabilities

Fixes
~~~~~

Expand Down
50 changes: 43 additions & 7 deletions www/base/src/app/builders/builders.controller.coffee
Expand Up @@ -31,28 +31,64 @@ class Builders extends Controller

$scope.tags_filter = $location.search()["tags"]
$scope.tags_filter ?= []
$log.debug "params", $location.search()
if not angular.isArray($scope.tags_filter)
$scope.tags_filter = [$scope.tags_filter]

$scope.$watch "tags_filter", (tags, old) ->
if old?
$log.debug "go", tags
$location.search("tags", tags)
, true

$scope.isBuilderFiltered = (builder, index) ->

# filter out inactive builders
if not $scope.settings.show_old_builders.value and not $scope.hasActiveMaster(builder)
return false
if $scope.tags_filter.length == 0

pluses = _.filter($scope.tags_filter, (tag) -> tag.indexOf("+") == 0)
minuses = _.filter($scope.tags_filter, (tag) -> tag.indexOf("-") == 0)

# First enforce that we have no tag marked '-'
for tag in minuses
if builder.tags.indexOf(tag.slice(1)) >= 0
return false

# if only minuses or no filter
if $scope.tags_filter.length == minuses.length
return true
for tag in builder.tags
if $scope.tags_filter.indexOf(tag) >= 0

# Then enforce that we have all the tags marked '+'
for tag in pluses
if builder.tags.indexOf(tag.slice(1)) < 0
return false

# Then enforce that we have at least one of the tag (marked '+' or not)
for tag in $scope.tags_filter
if tag.indexOf("+") == 0
tag = tag.slice(1)
if builder.tags.indexOf(tag) >= 0
return true
return false

$scope.isTagFiltered = (tag) ->
return $scope.tags_filter.length == 0 or $scope.tags_filter.indexOf(tag) >= 0
return $scope.tags_filter.length == 0 or $scope.tags_filter.indexOf(tag) >= 0 or
$scope.tags_filter.indexOf('+' + tag) >= 0 or $scope.tags_filter.indexOf('-' + tag) >= 0

$scope.toggleTag = (tag) ->
if tag.indexOf('+') == 0
tag = tag.slice(1)
if tag.indexOf('-') == 0
tag = tag.slice(1)
i = $scope.tags_filter.indexOf(tag)
if i < 0
iplus = $scope.tags_filter.indexOf("+" + tag)
iminus = $scope.tags_filter.indexOf("-" + tag)
if i < 0 and iplus < 0 and iminus < 0
$scope.tags_filter.push("+" + tag)
else if iplus >= 0
$scope.tags_filter.splice(iplus, 1)
$scope.tags_filter.push('-' + tag)
else if iminus >= 0
$scope.tags_filter.splice(iminus, 1)
$scope.tags_filter.push(tag)
else
$scope.tags_filter.splice(i, 1)
Expand Down
21 changes: 21 additions & 0 deletions www/base/src/app/builders/builders.tpl.jade
Expand Up @@ -5,6 +5,27 @@
th Builder Name
th Builds
th
span(ng-init="help=false", ng-click="help=!help")
i.fa.fa-question-circle(style="position:relative")
.popover.bottom.anim-popover(ng-if="help",
style="display:block;min-width:600px;left:-300px;top:30px")
h5.popover-title
| Tags filtering
.popover-content
p
b
pre +{tag}
| all tags with '+' must be present in the builder tags
p
b
pre -{tag}
| no tags with '-' must be present in the builder tags
p
b
pre {tag}
| at least one of the filtered tag should be present
p url bar is updated with you filter configuration, so you can bookmark your filters!
.arrow
span(ng-show="tags_filter.length==0") Tags
span(ng-show="tags_filter.length < 5", ng-repeat="tag in tags_filter")
span.label.label-success(ng-click="toggleTag(tag)")
Expand Down

0 comments on commit 9795d4c

Please sign in to comment.