2014-06-12 10:22:49 -04:00
|
|
|
window.ProjectPageApp = angular.module("ProjectPageApp", [])
|
2014-06-11 09:52:23 -04:00
|
|
|
|
2014-06-12 10:22:49 -04:00
|
|
|
ProjectPageApp.filter "formatDate", () ->
|
|
|
|
(date, format = "Do MMM YYYY, h:mm a") ->
|
|
|
|
moment(date).format(format)
|
|
|
|
|
|
|
|
ProjectPageApp.controller "ProjectPageController", ($scope) ->
|
|
|
|
$scope.projects = window.data.projects
|
2014-06-12 11:21:12 -04:00
|
|
|
$scope.visibleProjects = $scope.projects
|
2014-06-12 10:22:49 -04:00
|
|
|
$scope.tags = window.data.tags
|
|
|
|
$scope.allSelected = false
|
|
|
|
|
|
|
|
# Any individual changes to the selection buttons invalidates
|
|
|
|
# our 'select all'
|
|
|
|
$scope.$on "selected:on-change", (e) ->
|
|
|
|
$scope.allSelected = false
|
|
|
|
$scope.$broadcast "selection:change"
|
|
|
|
|
|
|
|
# Selecting or deselecting all should apply to all projects
|
|
|
|
$scope.onSelectAllChange = () ->
|
|
|
|
for project in $scope.visibleProjects
|
|
|
|
project.selected = $scope.allSelected
|
|
|
|
$scope.$broadcast "selection:change"
|
|
|
|
|
2014-06-12 11:21:12 -04:00
|
|
|
$scope.$watch "searchText", (value) ->
|
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
|
|
|
|
$scope.clearProjectSelections = () ->
|
2014-06-12 10:22:49 -04:00
|
|
|
for project in $scope.projects
|
|
|
|
project.selected = false
|
|
|
|
$scope.allSelected = false
|
|
|
|
$scope.$broadcast "selection:change"
|
|
|
|
|
|
|
|
$scope.updateVisibleProjects = () ->
|
|
|
|
$scope.visibleProjects = []
|
2014-06-12 11:21:12 -04:00
|
|
|
selectedTag = $scope.getSelectedTag()
|
2014-06-12 10:22:49 -04:00
|
|
|
for project in $scope.projects
|
|
|
|
visible = true
|
2014-06-12 11:21:12 -04:00
|
|
|
# Only show if it matches any search text
|
2014-06-12 10:22:49 -04:00
|
|
|
if $scope.searchText? and $scope.searchText != ""
|
|
|
|
if !project.name.toLowerCase().match($scope.searchText.toLowerCase())
|
|
|
|
visible = false
|
2014-06-12 11:21:12 -04:00
|
|
|
# Only show if it matches the selected tag
|
|
|
|
if selectedTag? and project._id not in selectedTag.project_ids
|
|
|
|
visible = false
|
2014-06-12 10:22:49 -04:00
|
|
|
if visible
|
|
|
|
$scope.visibleProjects.push project
|
2014-06-12 11:21:12 -04:00
|
|
|
console.log "visible", $scope.visibleProjects
|
|
|
|
$scope.clearProjectSelections()
|
|
|
|
|
|
|
|
$scope.getSelectedProjects = () ->
|
|
|
|
$scope.projects.filter (project) -> project.selected
|
|
|
|
|
|
|
|
$scope.getSelectedProjectIds = () ->
|
|
|
|
$scope.getSelectedProjects().map (project) -> project._id
|
2014-06-12 10:22:49 -04:00
|
|
|
|
2014-06-12 11:21:12 -04:00
|
|
|
$scope.getSelectedTag = () ->
|
|
|
|
for tag in $scope.tags
|
|
|
|
return tag if tag.selected
|
|
|
|
return null
|
|
|
|
|
|
|
|
ProjectPageApp.controller "ProjectListItemController", ($scope) ->
|
2014-06-12 10:22:49 -04:00
|
|
|
$scope.onSelectedChange = () ->
|
|
|
|
$scope.$emit "selected:on-change"
|
|
|
|
|
2014-06-12 11:21:12 -04:00
|
|
|
ProjectPageApp.controller "TagListController", ($scope) ->
|
|
|
|
$scope.view = "all"
|
|
|
|
|
|
|
|
$scope.selectAllProjects = () ->
|
|
|
|
$scope._clearTags()
|
|
|
|
$scope.setActiveItem("all")
|
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
|
|
|
|
$scope._clearTags = () ->
|
|
|
|
for tag in $scope.tags
|
|
|
|
tag.selected = false
|
|
|
|
|
|
|
|
$scope.setActiveItem = (view) ->
|
|
|
|
$scope.view = view
|
|
|
|
|
|
|
|
ProjectPageApp.controller "TagListItemController", ($scope) ->
|
|
|
|
$scope.selectTag = () ->
|
|
|
|
$scope._clearTags()
|
|
|
|
$scope.tag.selected = true
|
|
|
|
$scope.setActiveItem("tag")
|
|
|
|
$scope.updateVisibleProjects()
|
2014-06-12 10:22:49 -04:00
|
|
|
|
2014-06-12 11:21:12 -04:00
|
|
|
ProjectPageApp.controller "TagDropdownItemController", ($scope) ->
|
2014-06-12 10:22:49 -04:00
|
|
|
$scope.$on "selection:change", (e, newValue, oldValue) ->
|
|
|
|
console.log "selected watch listen"
|
|
|
|
$scope.recalculateProjectsInTag()
|
|
|
|
|
|
|
|
$scope.recalculateProjectsInTag = () ->
|
|
|
|
$scope.areSelectedProjectsInTag = false
|
|
|
|
for project_id in $scope.getSelectedProjectIds()
|
|
|
|
if project_id in $scope.tag.project_ids
|
|
|
|
$scope.areSelectedProjectsInTag = true
|
|
|
|
|
|
|
|
$scope.addOrRemoveProjectsFromTag = () ->
|
|
|
|
if $scope.areSelectedProjectsInTag
|
|
|
|
$scope.removeSelectedProjectsFromTag()
|
|
|
|
else
|
|
|
|
$scope.addSelectedProjectsToTag()
|
|
|
|
|
|
|
|
$scope.removeSelectedProjectsFromTag = () ->
|
|
|
|
selected_project_ids = $scope.getSelectedProjectIds()
|
|
|
|
remaining_project_ids = []
|
|
|
|
for project_id in $scope.tag.project_ids
|
|
|
|
if project_id not in selected_project_ids
|
|
|
|
remaining_project_ids.push project_id
|
|
|
|
$scope.tag.project_ids = remaining_project_ids
|
|
|
|
$scope.areSelectedProjectsInTag = false
|
|
|
|
|
|
|
|
$scope.addSelectedProjectsToTag = () ->
|
|
|
|
for project_id in $scope.getSelectedProjectIds()
|
|
|
|
unless project_id in $scope.tag.project_ids
|
|
|
|
$scope.tag.project_ids.push project_id
|
|
|
|
$scope.areSelectedProjectsInTag = true
|