adapt filter component for work with include/exclude modes
parent
c155c9b104
commit
e4651a1c03
|
@ -63,8 +63,14 @@ taiga.PageMixin = PageMixin
|
||||||
# This mixin requires @location ($tgLocation), and @scope
|
# This mixin requires @location ($tgLocation), and @scope
|
||||||
|
|
||||||
class FiltersMixin
|
class FiltersMixin
|
||||||
selectFilter: (name, value, load=false) ->
|
excludePrefix: "exclude_"
|
||||||
|
|
||||||
|
selectFilter: (name, value, load=false, mode="include") ->
|
||||||
params = @location.search()
|
params = @location.search()
|
||||||
|
|
||||||
|
if mode == "exclude"
|
||||||
|
name = @.excludePrefix.concat(name)
|
||||||
|
|
||||||
if params[name] != undefined and name != "page"
|
if params[name] != undefined and name != "page"
|
||||||
existing = _.map(taiga.toString(params[name]).split(","), (x) -> trim(x))
|
existing = _.map(taiga.toString(params[name]).split(","), (x) -> trim(x))
|
||||||
existing.push(taiga.toString(value))
|
existing.push(taiga.toString(value))
|
||||||
|
@ -84,9 +90,12 @@ class FiltersMixin
|
||||||
location = if load then @location else @location.noreload(@scope)
|
location = if load then @location else @location.noreload(@scope)
|
||||||
location.search(filters)
|
location.search(filters)
|
||||||
|
|
||||||
unselectFilter: (name, value, load=false) ->
|
unselectFilter: (name, value, load=false, mode='include') ->
|
||||||
params = @location.search()
|
params = @location.search()
|
||||||
|
|
||||||
|
if mode == "exclude"
|
||||||
|
name = @.excludePrefix.concat(name)
|
||||||
|
|
||||||
if params[name] is undefined
|
if params[name] is undefined
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -127,7 +136,7 @@ class FiltersMixin
|
||||||
|
|
||||||
return @storage.get(hash) or {}
|
return @storage.get(hash) or {}
|
||||||
|
|
||||||
formatSelectedFilters: (type, list, urlIds) ->
|
formatSelectedFilters: (type, list, urlIds, mode="include") ->
|
||||||
selectedIds = urlIds.split(',')
|
selectedIds = urlIds.split(',')
|
||||||
selectedFilters = _.filter list, (it) ->
|
selectedFilters = _.filter list, (it) ->
|
||||||
selectedIds.indexOf(_.toString(it.id)) != -1
|
selectedIds.indexOf(_.toString(it.id)) != -1
|
||||||
|
@ -141,6 +150,7 @@ class FiltersMixin
|
||||||
key: type + ":" + it
|
key: type + ":" + it
|
||||||
dataType: type,
|
dataType: type,
|
||||||
name: it
|
name: it
|
||||||
|
mode: mode
|
||||||
}
|
}
|
||||||
|
|
||||||
validAppliedTags = _.map selectedFilters, (it) ->
|
validAppliedTags = _.map selectedFilters, (it) ->
|
||||||
|
@ -150,6 +160,7 @@ class FiltersMixin
|
||||||
dataType: type,
|
dataType: type,
|
||||||
name: it.name
|
name: it.name
|
||||||
color: it.color
|
color: it.color
|
||||||
|
mode: mode
|
||||||
}
|
}
|
||||||
|
|
||||||
return invalidAppliedTags.concat(validAppliedTags)
|
return invalidAppliedTags.concat(validAppliedTags)
|
||||||
|
|
|
@ -63,6 +63,7 @@ class FilterController
|
||||||
filter = {
|
filter = {
|
||||||
category: filterCategory
|
category: filterCategory
|
||||||
filter: filter
|
filter: filter
|
||||||
|
mode: @.filterMode
|
||||||
}
|
}
|
||||||
|
|
||||||
@.onAddFilter({filter: filter})
|
@.onAddFilter({filter: filter})
|
||||||
|
|
|
@ -17,7 +17,10 @@ form(name="vm.filtersForm")
|
||||||
|
|
||||||
.filters-step-cat
|
.filters-step-cat
|
||||||
.filters-applied
|
.filters-applied
|
||||||
.single-filter.ng-animate-disabled(ng-repeat="it in vm.selectedFilters track by it.key")
|
.single-filter.ng-animate-disabled(
|
||||||
|
ng-repeat="it in vm.selectedFilters track by it.key"
|
||||||
|
class="{{it.mode}}"
|
||||||
|
)
|
||||||
span.name(
|
span.name(
|
||||||
ng-attr-style="{{it.color ? 'border-color: ' + it.color: ''}}"
|
ng-attr-style="{{it.color ? 'border-color: ' + it.color: ''}}"
|
||||||
ng-if="it.dataType === 'tags'"
|
ng-if="it.dataType === 'tags'"
|
||||||
|
|
|
@ -13,6 +13,10 @@ tg-filter {
|
||||||
.filters-applied {
|
.filters-applied {
|
||||||
padding: 0 1rem 1rem;
|
padding: 0 1rem 1rem;
|
||||||
.single-filter {
|
.single-filter {
|
||||||
|
&.exclude {
|
||||||
|
background: $red-light;
|
||||||
|
text-decoration: line-through;
|
||||||
|
}
|
||||||
&:hover {
|
&:hover {
|
||||||
color: currentColor;
|
color: currentColor;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
|
|
Loading…
Reference in New Issue