Another iteration on issues filters.

stable
Andrey Antukh 2014-07-04 10:57:56 +02:00
parent 9ab62bdde7
commit 19828a5799
3 changed files with 58 additions and 31 deletions

View File

@ -57,6 +57,7 @@ class FiltersMixin
if params[name] != undefined and name != "page" if params[name] != undefined and name != "page"
existing = _.map(taiga.toString(params[name]).split(","), trim) existing = _.map(taiga.toString(params[name]).split(","), trim)
existing.push(taiga.toString(value)) existing.push(taiga.toString(value))
existing = _.compact(existing)
value = joinStr(",", _.uniq(existing)) value = joinStr(",", _.uniq(existing))
location = if load then @location else @location.noreload(@scope) location = if load then @location else @location.noreload(@scope)
@ -73,6 +74,7 @@ class FiltersMixin
parsedValues = _.map(taiga.toString(params[name]).split(","), trim) parsedValues = _.map(taiga.toString(params[name]).split(","), trim)
newValues = _.reject(parsedValues, (x) -> x == taiga.toString(value)) newValues = _.reject(parsedValues, (x) -> x == taiga.toString(value))
newValues = _.compact(newValues)
if _.isEmpty(newValues) if _.isEmpty(newValues)
value = null value = null

View File

@ -49,18 +49,35 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location) -> constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location) ->
@scope.sprintId = @params.id @scope.sprintId = @params.id
@scope.sectionName = "Issues" @scope.sectionName = "Issues"
@scope.filters = {}
promise = @.loadInitialData() promise = @.loadInitialData()
promise.then null, -> promise.then null, ->
console.log "FAIL" #TODO console.log "FAIL" #TODO
loadProject: ->
return @rs.projects.get(@scope.projectId).then (project) =>
@scope.project = project
@scope.issueStatusById = groupBy(project.issue_statuses, (x) -> x.id)
@scope.severityById = groupBy(project.severities, (x) -> x.id)
@scope.priorityById = groupBy(project.priorities, (x) -> x.id)
@scope.membersById = groupBy(project.memberships, (x) -> x.user)
return project
getUrlFilters: ->
filters = _.pick(@location.search(), "page", "tags", "statuses", "types", "subject",
"severities", "priorities", "assignedTo")
filters.page = 1 if not filters.page
return filters
loadFilters: -> loadFilters: ->
return @rs.issues.filtersData(@scope.projectId).then (data) => return @rs.issues.filtersData(@scope.projectId).then (data) =>
console.log data urlfilters = @.getUrlFilters()
# Build selected filters (from url) fast lookup data structure # Build selected filters (from url) fast lookup data structure
searchdata = {} searchdata = {}
for name, value of @.getFilters()
for name, value of urlfilters
if name == "page" if name == "page"
continue continue
@ -75,44 +92,43 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
return true return true
return false return false
console.log "2222", searchdata
# Build filters data structure # Build filters data structure
filters = {} @scope.filters.tags = _.map data.tags, (t) =>
filters.tags = _.map data.tags, (t) =>
obj = {id:t[0], name:t[0], count: t[1], type:"tags"} obj = {id:t[0], name:t[0], count: t[1], type:"tags"}
obj.selected = true if isSelected("tags", obj.id) obj.selected = true if isSelected("tags", obj.id)
return obj return obj
filters.priorities = _.map data.priorities, (t) => @scope.filters.priorities = _.map data.priorities, (t) =>
obj = {id:t[0], name:@scope.priorityById[t[0]].name, count:t[1], type:"priorities"} obj = {id:t[0], name:@scope.priorityById[t[0]].name, count:t[1], type:"priorities"}
obj.selected = true if isSelected("priorities", obj.id) obj.selected = true if isSelected("priorities", obj.id)
return obj return obj
filters.severities = _.map data.severities, (t) => @scope.filters.severities = _.map data.severities, (t) =>
obj = {id:t[0], name:@scope.severityById[t[0]].name, count:t[1], type:"severities"} obj = {id:t[0], name:@scope.severityById[t[0]].name, count:t[1], type:"severities"}
obj.selected = true if isSelected("severities", obj.id) obj.selected = true if isSelected("severities", obj.id)
return obj return obj
@scope.filters = filters @scope.filters.assignedTo = _.map data.assigned_to, (t) =>
@rootscope.$broadcast("filters:loaded", filters) obj = {id:t[0], count:t[1], type:"assignedTo"}
if t[0]
obj.name = @scope.usersById[t[0]].full_name_display
else
obj.name = "Unassigned"
obj.selected = true if isSelected("assignedTo", obj.id)
return obj
@scope.filters.statuses = _.map data.statuses, (t) =>
obj = {id:t[0], name:@scope.issueStatusById[t[0]].name, count:t[1], type:"statuses"}
obj.selected = true if isSelected("statuses", obj.id)
return obj
if urlfilters.subject
@scope.filters.subject = urlfilters.subject
@rootscope.$broadcast("filters:loaded", @scope.filters)
return data return data
loadProject: ->
return @rs.projects.get(@scope.projectId).then (project) =>
@scope.project = project
@scope.issueStatusById = groupBy(project.issue_statuses, (x) -> x.id)
@scope.severityById = groupBy(project.severities, (x) -> x.id)
@scope.priorityById = groupBy(project.priorities, (x) -> x.id)
@scope.membersById = groupBy(project.memberships, (x) -> x.user)
return project
getFilters: ->
filters = _.pick(@location.search(), "page", "tags", "status", "type",
"severities", "priorities")
filters.page = 1 if not filters.page
return filters
# Convert stored filters to http parameters # Convert stored filters to http parameters
# ready filters (the name difference exists # ready filters (the name difference exists
# because of some automatic lookups and is # because of some automatic lookups and is
@ -121,13 +137,19 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
prepareFilters: -> prepareFilters: ->
filters = {} filters = {}
for name, values of @.getFilters() for name, values of @.getUrlFilters()
if name == "severities" if name == "severities"
name = "severity" name = "severity"
else if name == "priorities" else if name == "priorities"
name = "priority" name = "priority"
else if name == "assignedTo"
name = "assigned_to"
else if name == "statuses"
name = "status"
filters[name] = values filters[name] = values
console.log "filter query params:", filters
return filters return filters
loadIssues: -> loadIssues: ->
@ -340,7 +362,6 @@ IssuesFiltersDirective = ($log, $location) ->
initializeSelectedFilters = ($el, filters) -> initializeSelectedFilters = ($el, filters) ->
for name, values of filters for name, values of filters
for val in values for val in values
console.log "klkk", val.selected
selectedFilters.push(val) if val.selected selectedFilters.push(val) if val.selected
renderSelectedFilters($el) renderSelectedFilters($el)

View File

@ -19,10 +19,10 @@ section.filters
// span.icon.icon-delete // span.icon.icon-delete
div.filters-cats div.filters-cats
ul ul
// li li
// a(href="", title="Status", data-type="status") a(href="", title="Status", data-type="statuses")
// span.title Status span.title Status
// span.icon.icon-arrow-right span.icon.icon-arrow-right
// li // li
// a(href="", title="Type", data-type="types") // a(href="", title="Type", data-type="types")
// span.title Type // span.title Type
@ -39,6 +39,10 @@ section.filters
a(href="", title="Tags", data-type="tags") a(href="", title="Tags", data-type="tags")
span.title Tags span.title Tags
span.icon.icon-arrow-right span.icon.icon-arrow-right
li
a(href="", title="Assigned to", data-type="assignedTo")
span.title Assigned to
span.icon.icon-arrow-right
//- Second step for selecting single filters to apply //- Second step for selecting single filters to apply
div.filter-list.hidden div.filter-list.hidden