Don't show tags which are empty when loaded

This commit is contained in:
James Allen 2014-06-18 11:30:56 +01:00
parent 70c51cb947
commit 9a03411d42
5 changed files with 34 additions and 28 deletions

View file

@ -68,7 +68,7 @@ block content
li
h2 Folders
li(
ng-repeat="tag in tags",
ng-repeat="tag in tags | filter:nonEmpty",
ng-controller="TagListItemController",
ng-class="{active: tag.selected}"
)
@ -189,13 +189,14 @@ block content
span.caret
ul.dropdown-menu.dropdown-menu-right.js-tags-dropdown-menu(
role="menu"
ng-controller="TagListController"
)
li.dropdown-header Add to folder
li(
ng-repeat="tag in tags | orderBy:'name'",
ng-repeat="tag in tags | filter:nonEmpty | orderBy:'name'",
ng-controller="TagDropdownItemController"
)
a(href="#", ng-click="addOrRemoveProjectsFromTag()")
a(href="#", ng-click="addOrRemoveProjectsFromTag()", stop-propagation="click")
i.fa(
ng-class="{\
'fa-check-square-o': areSelectedProjectsInTag == true,\
@ -206,7 +207,7 @@ block content
| {{tag.name}}
li.divider
li
a(href="#", ng-click="openNewTagModal()") Create New Folder
a(href="#", ng-click="openNewTagModal()", stop-propagation="click") Create New Folder
.btn-group(ng-hide="selectedProjects.length != 1").dropdown
a.btn.btn-default.dropdown-toggle(

View file

@ -1,19 +0,0 @@
.container
.page-header
h1 New File
.row
.span12.columns
form#newFile(enctype='multipart/form-data', method='post')
fieldset
.clearfix
label(for='xlInput') Name
.input
input.xlarge(type='text', name='name')
.clearfix
label(for='xlInput') Upload File
.input
input#file_upload.input-file(type='file', name='image')
.actions
Button.primary.btn(type='submit') Save

View file

@ -0,0 +1,13 @@
define [
"base"
], (App) ->
App.directive "stopPropagation", ($http) ->
console.log "Registering"
return {
restrict: "A",
link: (scope, element, attrs) ->
console.log "linking"
element.bind attrs.stopPropagation, (e) ->
console.log "click"
e.stopPropagation()
}

View file

@ -2,5 +2,6 @@ define [
"project-list"
"user-details"
"directives/asyncForm"
"directives/stopPropagation"
], () ->
angular.bootstrap(document.body, ["SharelatexApp"])

View file

@ -142,6 +142,8 @@ define [
$scope.projects.splice(index, 1)
$scope.removeSelectedProjectsFromTag = (tag) ->
tag.showWhenEmpty = true
selected_project_ids = $scope.getSelectedProjectIds()
selected_projects = $scope.getSelectedProjects()
@ -192,9 +194,10 @@ define [
$scope.tags.push {
name: name
project_ids: []
showWhenEmpty: true
}
$scope.openNewTagModal = () ->
$scope.openNewTagModal = (e) ->
modalInstance = $modal.open(
templateUrl: "newTagModalTemplate"
controller: "NewTagModalController"
@ -421,6 +424,12 @@ define [
for tag in $scope.tags
tag.selected = false
$scope.nonEmpty = (tag) ->
# The showWhenEmpty property will be set on any tag which we have
# modified during this session. Otherwise, tags which are empty
# when loading the page are not shown.
tag.project_ids.length > 0 or !!tag.showWhenEmpty
App.controller "TagListItemController", ($scope) ->
$scope.selectTag = () ->
$scope._clearTags()
@ -428,9 +437,6 @@ define [
$scope.setFilter("tag")
App.controller "TagDropdownItemController", ($scope) ->
$scope.$on "selection:change", (e, newValue, oldValue) ->
$scope.recalculateProjectsInTag()
$scope.recalculateProjectsInTag = () ->
$scope.areSelectedProjectsInTag = false
for project_id in $scope.getSelectedProjectIds()
@ -442,7 +448,7 @@ define [
if $scope.areSelectedProjectsInTag and partialSelection
$scope.areSelectedProjectsInTag = "partial"
$scope.addOrRemoveProjectsFromTag = () ->
$scope.addOrRemoveProjectsFromTag = (e) ->
if $scope.areSelectedProjectsInTag == true
$scope.removeSelectedProjectsFromTag($scope.tag)
$scope.areSelectedProjectsInTag = false
@ -450,6 +456,10 @@ define [
$scope.addSelectedProjectsToTag($scope.tag)
$scope.areSelectedProjectsInTag = true
$scope.$on "selection:change", (e, newValue, oldValue) ->
$scope.recalculateProjectsInTag()
$scope.recalculateProjectsInTag()
App.controller 'NewTagModalController', ($scope, $modalInstance, $timeout) ->
$scope.inputs =
newTagName: ""