Save and read filtering options from local storage.

This commit is contained in:
Paulo Reis 2017-04-27 16:07:03 +01:00
parent 3bdd5a4a2e
commit 884a89893d

View file

@ -2,7 +2,7 @@ define [
"base" "base"
], (App) -> ], (App) ->
App.controller "ProjectPageController", ($scope, $modal, $q, $window, queuedHttp, event_tracking, $timeout) -> App.controller "ProjectPageController", ($scope, $modal, $q, $window, queuedHttp, event_tracking, $timeout, localStorage) ->
$scope.projects = window.data.projects $scope.projects = window.data.projects
$scope.tags = window.data.tags $scope.tags = window.data.tags
$scope.notifications = window.data.notifications $scope.notifications = window.data.notifications
@ -18,6 +18,8 @@ define [
recalculateProjectListHeight() recalculateProjectListHeight()
, 10 , 10
storedUIOpts = JSON.parse(localStorage("project_list"))
recalculateProjectListHeight = () -> recalculateProjectListHeight = () ->
topOffset = $(".project-list-card")?.offset()?.top topOffset = $(".project-list-card")?.offset()?.top
bottomOffset = $("footer").outerHeight() + 25 bottomOffset = $("footer").outerHeight() + 25
@ -52,6 +54,13 @@ define [
project.tags ||= [] project.tags ||= []
project.tags.push tag project.tags.push tag
markTagAsSelected = (id) ->
for tag in $scope.tags
if tag._id == id
tag.selected = true
else
tag.selected = false
$scope.changePredicate = (newPredicate)-> $scope.changePredicate = (newPredicate)->
if $scope.predicate == newPredicate if $scope.predicate == newPredicate
$scope.reverse = !$scope.reverse $scope.reverse = !$scope.reverse
@ -126,6 +135,11 @@ define [
else else
# We don't want hidden selections # We don't want hidden selections
project.selected = false project.selected = false
localStorage("project_list", JSON.stringify({
filter: $scope.filter,
selectedTagId: selectedTag?._id
}))
$scope.updateSelectedProjects() $scope.updateSelectedProjects()
$scope.getSelectedTag = () -> $scope.getSelectedTag = () ->
@ -425,8 +439,6 @@ define [
window.location = path window.location = path
$scope.updateVisibleProjects()
App.controller "ProjectListItemController", ($scope) -> App.controller "ProjectListItemController", ($scope) ->
$scope.ownerName = () -> $scope.ownerName = () ->
if $scope.project.accessLevel == "owner" if $scope.project.accessLevel == "owner"