From db74e89f99cf8c34c3242e440bc3d0afdffc7baa Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 13 Jun 2014 14:14:56 +0100 Subject: [PATCH] Add folder labels next to the project name --- services/web/app/views/project/list.jade | 3 ++ .../web/public/coffee/project-list.coffee | 36 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/services/web/app/views/project/list.jade b/services/web/app/views/project/list.jade index 4cc1cbd598..c0d8151f03 100644 --- a/services/web/app/views/project/list.jade +++ b/services/web/app/views/project/list.jade @@ -169,6 +169,9 @@ block content input.select-item(type="checkbox", ng-model="project.selected", ng-change="onSelectedChange()") span.title a.projectName(href="/project/{{project.id}}") {{project.name}} + span + span.label.label-default(ng-repeat='tag in project.tags') + | {{tag.name}} .col-md-2 span.owner {{project.publicAccesLevel}} .col-md-4 diff --git a/services/web/public/coffee/project-list.coffee b/services/web/public/coffee/project-list.coffee index cab87097a1..9ec658dfa6 100644 --- a/services/web/public/coffee/project-list.coffee +++ b/services/web/public/coffee/project-list.coffee @@ -30,6 +30,18 @@ ProjectPageApp.controller "ProjectPageController", ($scope, $modal, $http) -> $scope.tags = window.data.tags $scope.allSelected = false + # Allow tags to be accessed on projects as well + projectsById = {} + for project in $scope.projects + projectsById[project._id] = project + + for tag in $scope.tags + for project_id in tag.project_ids or [] + project = projectsById[project_id] + if project? + project.tags ||= [] + project.tags.push tag + # Any individual changes to the selection buttons invalidates # our 'select all' $scope.$on "selected:on-change", (e) -> @@ -63,9 +75,12 @@ ProjectPageApp.controller "ProjectPageController", ($scope, $modal, $http) -> # Only show if it matches the selected tag if selectedTag? and project._id not in selectedTag.project_ids visible = false + if visible $scope.visibleProjects.push project - $scope.clearProjectSelections() + else + # We don't want hidden selections + project.selected = false $scope.getSelectedProjects = () -> $scope.projects.filter (project) -> project.selected @@ -80,6 +95,9 @@ ProjectPageApp.controller "ProjectPageController", ($scope, $modal, $http) -> $scope.removeSelectedProjectsFromTag = (tag) -> selected_project_ids = $scope.getSelectedProjectIds() + selected_projects = $scope.getSelectedProjects() + + # Remove project_id from tag.project_ids remaining_project_ids = [] removed_project_ids = [] for project_id in tag.project_ids @@ -89,6 +107,14 @@ ProjectPageApp.controller "ProjectPageController", ($scope, $modal, $http) -> removed_project_ids.push project_id tag.project_ids = remaining_project_ids + # Remove tag from project.tags + remaining_tags = [] + for project in selected_projects + project.tags ||= [] + index = project.tags.indexOf tag + if index > -1 + project.tags.splice(index, 1) + for project_id in removed_project_ids $http.post "/project/#{project_id}/tag", { deletedTag: tag.name @@ -100,12 +126,20 @@ ProjectPageApp.controller "ProjectPageController", ($scope, $modal, $http) -> $scope.updateVisibleProjects() $scope.addSelectedProjectsToTag = (tag) -> + selected_projects = $scope.getSelectedProjects() + + # Add project_ids into tag.project_ids added_project_ids = [] for project_id in $scope.getSelectedProjectIds() unless project_id in tag.project_ids tag.project_ids.push project_id added_project_ids.push project_id + # Add tag into each project.tags + for project in selected_projects + project.tags ||= [] + project.tags.push tag + for project_id in added_project_ids # TODO Factor this out into another provider? $http.post "/project/#{project_id}/tag", {