Merge pull request #1898 from overleaf/as-tags-archived-projects

Clean up decaffeinated project list code

GitOrigin-RevId: ae2408b8768eb8be02b4cf80be5400bb707fff66
This commit is contained in:
Simon Detheridge 2019-06-21 14:45:43 +01:00 committed by sharelatex
parent d1e587a51e
commit 6e238a8345
2 changed files with 134 additions and 184 deletions

View file

@ -1,25 +1,10 @@
/* eslint-disable
camelcase,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS205: Consider reworking code to avoid use of IIFEs
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
define(['base', 'main/project-list/services/project-list'], function(App) { define(['base', 'main/project-list/services/project-list'], function(App) {
App.controller('ProjectPageController', function( App.controller('ProjectPageController', function(
$scope, $scope,
$modal, $modal,
$q,
$window, $window,
queuedHttp, queuedHttp,
event_tracking, event_tracking, // eslint-disable-line camelcase
$timeout, $timeout,
localStorage, localStorage,
ProjectListService ProjectListService
@ -52,16 +37,16 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
newVal => ($scope.nUntagged = newVal) newVal => ($scope.nUntagged = newVal)
) )
const storedUIOpts = JSON.parse(localStorage('project_list'))
var recalculateProjectListHeight = function() { var recalculateProjectListHeight = function() {
const $projListCard = $('.project-list-card') const $projListCard = $('.project-list-card')
const topOffset = __guard__($projListCard.offset(), x => x.top) if (!$projListCard) return
const topOffset = $projListCard.offset().top
const cardPadding = $projListCard.outerHeight() - $projListCard.height() const cardPadding = $projListCard.outerHeight() - $projListCard.height()
const bottomOffset = $('footer').outerHeight() const bottomOffset = $('footer').outerHeight()
const height = const height =
$window.innerHeight - topOffset - bottomOffset - cardPadding $window.innerHeight - topOffset - bottomOffset - cardPadding
return ($scope.projectListHeight = height) $scope.projectListHeight = height
} }
function defaultComparator(v1, v2) { function defaultComparator(v1, v2) {
@ -127,7 +112,7 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
angular.element($window).bind('resize', function() { angular.element($window).bind('resize', function() {
recalculateProjectListHeight() recalculateProjectListHeight()
return $scope.$apply() $scope.$apply()
}) })
$scope.$on('project-list:notifications-received', () => $scope.$on('project-list:notifications-received', () =>
@ -136,14 +121,14 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
// Allow tags to be accessed on projects as well // Allow tags to be accessed on projects as well
const projectsById = {} const projectsById = {}
for (var project of Array.from($scope.projects)) { for (let project of $scope.projects) {
projectsById[project.id] = project projectsById[project.id] = project
} }
for (var tag of Array.from($scope.tags)) { for (var tag of $scope.tags) {
for (let project_id of Array.from(tag.project_ids || [])) { for (let projectId of tag.project_ids || []) {
project = projectsById[project_id] let project = projectsById[projectId]
if (project != null) { if (project) {
if (!project.tags) { if (!project.tags) {
project.tags = [] project.tags = []
} }
@ -152,24 +137,11 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
} }
} }
const markTagAsSelected = id =>
(() => {
const result = []
for (tag of Array.from($scope.tags)) {
if (tag._id === id) {
result.push((tag.selected = true))
} else {
result.push((tag.selected = false))
}
}
return result
})()
$scope.changePredicate = function(newPredicate) { $scope.changePredicate = function(newPredicate) {
if ($scope.predicate === newPredicate) { if ($scope.predicate === newPredicate) {
$scope.reverse = !$scope.reverse $scope.reverse = !$scope.reverse
} }
return ($scope.predicate = newPredicate) $scope.predicate = newPredicate
} }
$scope.getSortIconClass = function(column) { $scope.getSortIconClass = function(column) {
@ -188,19 +160,19 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
'project-search', 'project-search',
'keydown' 'keydown'
) )
return $scope.updateVisibleProjects() $scope.updateVisibleProjects()
} }
$scope.clearSearchText = function() { $scope.clearSearchText = function() {
$scope.searchText.value = '' $scope.searchText.value = ''
$scope.filter = 'all' $scope.filter = 'all'
$scope.$emit('search:clear') $scope.$emit('search:clear')
return $scope.updateVisibleProjects() $scope.updateVisibleProjects()
} }
$scope.setFilter = function(filter) { $scope.setFilter = function(filter) {
$scope.filter = filter $scope.filter = filter
return $scope.updateVisibleProjects() $scope.updateVisibleProjects()
} }
$scope.updateSelectedProjects = function() { $scope.updateSelectedProjects = function() {
@ -222,10 +194,10 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
$scope.updateVisibleProjects = function() { $scope.updateVisibleProjects = function() {
$scope.visibleProjects = [] $scope.visibleProjects = []
const selectedTag = $scope.getSelectedTag() const selectedTag = $scope.getSelectedTag()
for (project of Array.from($scope.projects)) { for (let project of $scope.projects) {
let visible = true let visible = true
// Only show if it matches any search text // Only show if it matches any search text
if ($scope.searchText.value != null && $scope.searchText.value !== '') { if ($scope.searchText.value !== '') {
if ( if (
project.name project.name
.toLowerCase() .toLowerCase()
@ -238,7 +210,7 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
if ( if (
$scope.filter === 'tag' && $scope.filter === 'tag' &&
selectedTag != null && selectedTag != null &&
!Array.from(selectedTag.project_ids).includes(project.id) !selectedTag.project_ids.includes(project.id)
) { ) {
visible = false visible = false
} }
@ -297,11 +269,11 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
selectedTagId: selectedTag != null ? selectedTag._id : undefined selectedTagId: selectedTag != null ? selectedTag._id : undefined
}) })
) )
return $scope.updateSelectedProjects() $scope.updateSelectedProjects()
} }
$scope.getSelectedTag = function() { $scope.getSelectedTag = function() {
for (tag of Array.from($scope.tags)) { for (tag of $scope.tags) {
if (tag.selected) { if (tag.selected) {
return tag return tag
} }
@ -309,41 +281,41 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
return null return null
} }
$scope._removeProjectIdsFromTagArray = function(tag, remove_project_ids) { $scope._removeProjectIdsFromTagArray = function(tag, removeProjectIds) {
// Remove project_id from tag.project_ids // Remove project_id from tag.project_ids
const remaining_project_ids = [] const remainingProjectIds = []
const removed_project_ids = [] const removedProjectIds = []
for (let project_id of Array.from(tag.project_ids)) { for (let projectId of tag.project_ids) {
if (!Array.from(remove_project_ids).includes(project_id)) { if (!removeProjectIds.includes(projectId)) {
remaining_project_ids.push(project_id) remainingProjectIds.push(projectId)
} else { } else {
removed_project_ids.push(project_id) removedProjectIds.push(projectId)
} }
} }
tag.project_ids = remaining_project_ids tag.project_ids = remainingProjectIds
return removed_project_ids return removedProjectIds
} }
$scope._removeProjectFromList = function(project) { $scope._removeProjectFromList = function(project) {
const index = $scope.projects.indexOf(project) const index = $scope.projects.indexOf(project)
if (index > -1) { if (index > -1) {
return $scope.projects.splice(index, 1) $scope.projects.splice(index, 1)
} }
} }
$scope.removeSelectedProjectsFromTag = function(tag) { $scope.removeSelectedProjectsFromTag = function(tag) {
tag.showWhenEmpty = true tag.showWhenEmpty = true
const selected_project_ids = $scope.getSelectedProjectIds() const selectedProjectIds = $scope.getSelectedProjectIds()
const selected_projects = $scope.getSelectedProjects() const selectedProjects = $scope.getSelectedProjects()
const removed_project_ids = $scope._removeProjectIdsFromTagArray( const removedProjectIds = $scope._removeProjectIdsFromTagArray(
tag, tag,
selected_project_ids selectedProjectIds
) )
// Remove tag from project.tags // Remove tag from project.tags
for (project of Array.from(selected_projects)) { for (let project of selectedProjects) {
if (!project.tags) { if (!project.tags) {
project.tags = [] project.tags = []
} }
@ -353,10 +325,10 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
} }
} }
for (let project_id of Array.from(removed_project_ids)) { for (let projectId of removedProjectIds) {
queuedHttp({ queuedHttp({
method: 'DELETE', method: 'DELETE',
url: `/tag/${tag._id}/project/${project_id}`, url: `/tag/${tag._id}/project/${projectId}`,
headers: { headers: {
'X-CSRF-Token': window.csrfToken 'X-CSRF-Token': window.csrfToken
} }
@ -365,7 +337,7 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
// If we're filtering by this tag then we need to remove // If we're filtering by this tag then we need to remove
// the projects from view // the projects from view
return $scope.updateVisibleProjects() $scope.updateVisibleProjects()
} }
$scope.removeProjectFromTag = function(project, tag) { $scope.removeProjectFromTag = function(project, tag) {
@ -386,12 +358,12 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
'X-CSRF-Token': window.csrfToken 'X-CSRF-Token': window.csrfToken
} }
}) })
return $scope.updateVisibleProjects() $scope.updateVisibleProjects()
} }
} }
$scope.addSelectedProjectsToTag = function(tag) { $scope.addSelectedProjectsToTag = function(tag) {
const selected_projects = $scope.getSelectedProjects() const selectedProjects = $scope.getSelectedProjects()
event_tracking.send( event_tracking.send(
'project-list-page-interaction', 'project-list-page-interaction',
'project action', 'project action',
@ -399,35 +371,29 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
) )
// Add project_ids into tag.project_ids // Add project_ids into tag.project_ids
const added_project_ids = [] const addedProjectIds = []
for (let project_id of Array.from($scope.getSelectedProjectIds())) { for (let projectId of $scope.getSelectedProjectIds()) {
if (!Array.from(tag.project_ids).includes(project_id)) { if (!tag.project_ids.includes(projectId)) {
tag.project_ids.push(project_id) tag.project_ids.push(projectId)
added_project_ids.push(project_id) addedProjectIds.push(projectId)
} }
} }
// Add tag into each project.tags // Add tag into each project.tags
for (project of Array.from(selected_projects)) { for (let project of selectedProjects) {
if (!project.tags) { if (!project.tags) {
project.tags = [] project.tags = []
} }
if (!Array.from(project.tags).includes(tag)) { if (!project.tags.includes(tag)) {
project.tags.push(tag) project.tags.push(tag)
} }
} }
return (() => { for (let projectId of addedProjectIds) {
const result = [] queuedHttp.post(`/tag/${tag._id}/project/${projectId}`, {
for (let project_id of Array.from(added_project_ids)) { _csrf: window.csrfToken
result.push( })
queuedHttp.post(`/tag/${tag._id}/project/${project_id}`, { }
_csrf: window.csrfToken
})
)
}
return result
})()
} }
$scope.createTag = name => tag $scope.createTag = name => tag
@ -438,14 +404,14 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
controller: 'NewTagModalController' controller: 'NewTagModalController'
}) })
return modalInstance.result.then(function(tag) { modalInstance.result.then(function(tag) {
const tagIsDuplicate = $scope.tags.find(function(existingTag) { const tagIsDuplicate = $scope.tags.find(function(existingTag) {
return tag.name === existingTag.name return tag.name === existingTag.name
}) })
if (!tagIsDuplicate) { if (!tagIsDuplicate) {
$scope.tags.push(tag) $scope.tags.push(tag)
return $scope.addSelectedProjectsToTag(tag) $scope.addSelectedProjectsToTag(tag)
} }
}) })
} }
@ -472,7 +438,7 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
// TODO: Check access level if correct after adding it in // TODO: Check access level if correct after adding it in
// to the rest of the app // to the rest of the app
}) })
return $scope.updateVisibleProjects() $scope.updateVisibleProjects()
}) })
} }
@ -496,8 +462,8 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
scope: $scope scope: $scope
}) })
return modalInstance.result.then( modalInstance.result.then(
project_id => (window.location = `/project/${project_id}`) projectId => (window.location = `/project/${projectId}`)
) )
} }
@ -510,8 +476,8 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
.then(() => (project.name = newName)) .then(() => (project.name = newName))
$scope.openRenameProjectModal = function() { $scope.openRenameProjectModal = function() {
project = $scope.getFirstSelectedProject() let project = $scope.getFirstSelectedProject()
if (project == null || project.accessLevel !== 'owner') { if (!project || project.accessLevel !== 'owner') {
return return
} }
event_tracking.send( event_tracking.send(
@ -554,13 +520,13 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
// TODO: Check access level if correct after adding it in // TODO: Check access level if correct after adding it in
// to the rest of the app // to the rest of the app
}) })
return $scope.updateVisibleProjects() $scope.updateVisibleProjects()
}) })
} }
$scope.openCloneProjectModal = function() { $scope.openCloneProjectModal = function() {
project = $scope.getFirstSelectedProject() let project = $scope.getFirstSelectedProject()
if (project == null) { if (!project) {
return return
} }
@ -597,9 +563,7 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
'project action', 'project action',
'Delete' 'Delete'
) )
return modalInstance.result.then(() => modalInstance.result.then(() => $scope.archiveOrLeaveSelectedProjects())
$scope.archiveOrLeaveSelectedProjects()
)
} }
$scope.archiveOrLeaveSelectedProjects = () => $scope.archiveOrLeaveSelectedProjects = () =>
@ -654,34 +618,34 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
} }
}) })
return modalInstance.result.then(() => $scope.deleteSelectedProjects()) modalInstance.result.then(() => $scope.deleteSelectedProjects())
} }
$scope.deleteSelectedProjects = function() { $scope.deleteSelectedProjects = function() {
const selected_projects = $scope.getSelectedProjects() const selectedProjects = $scope.getSelectedProjects()
const selected_project_ids = $scope.getSelectedProjectIds() const selectedProjectIds = $scope.getSelectedProjectIds()
// Remove projects from array // Remove projects from array
for (project of Array.from(selected_projects)) { for (let project of selectedProjects) {
$scope._removeProjectFromList(project) $scope._removeProjectFromList(project)
} }
// Remove project from any tags // Remove project from any tags
for (tag of Array.from($scope.tags)) { for (tag of $scope.tags) {
$scope._removeProjectIdsFromTagArray(tag, selected_project_ids) $scope._removeProjectIdsFromTagArray(tag, selectedProjectIds)
} }
for (let project_id of Array.from(selected_project_ids)) { for (let projectId of selectedProjectIds) {
queuedHttp({ queuedHttp({
method: 'DELETE', method: 'DELETE',
url: `/project/${project_id}?forever=true`, url: `/project/${projectId}?forever=true`,
headers: { headers: {
'X-CSRF-Token': window.csrfToken 'X-CSRF-Token': window.csrfToken
} }
}) })
} }
return $scope.updateVisibleProjects() $scope.updateVisibleProjects()
} }
$scope.restoreSelectedProjects = () => $scope.restoreSelectedProjects = () =>
@ -689,11 +653,11 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
$scope.restoreProjects = function(projects) { $scope.restoreProjects = function(projects) {
const projectIds = projects.map(p => p.id) const projectIds = projects.map(p => p.id)
for (project of Array.from(projects)) { for (let project of projects) {
project.archived = false project.archived = false
} }
for (let projectId of Array.from(projectIds)) { for (let projectId of projectIds) {
queuedHttp({ queuedHttp({
method: 'POST', method: 'POST',
url: `/project/${projectId}/restore`, url: `/project/${projectId}/restore`,
@ -703,7 +667,7 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
}) })
} }
return $scope.updateVisibleProjects() $scope.updateVisibleProjects()
} }
$scope.openUploadProjectModal = function() { $scope.openUploadProjectModal = function() {
@ -744,17 +708,29 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
} }
}) })
if ((storedUIOpts != null ? storedUIOpts.filter : undefined) != null) { const markTagAsSelected = id => {
if (storedUIOpts.filter === 'tag' && storedUIOpts.selectedTagId != null) { for (tag of $scope.tags) {
if (tag._id === id) {
tag.selected = true
} else {
tag.selected = false
}
}
}
const storedUIOpts = JSON.parse(localStorage('project_list'))
if (storedUIOpts && storedUIOpts.filter) {
if (storedUIOpts.filter === 'tag' && storedUIOpts.selectedTagId) {
markTagAsSelected(storedUIOpts.selectedTagId) markTagAsSelected(storedUIOpts.selectedTagId)
} }
return $scope.setFilter(storedUIOpts.filter) $scope.setFilter(storedUIOpts.filter)
} else { } else {
return $scope.updateVisibleProjects() $scope.updateVisibleProjects()
} }
}) })
return App.controller('ProjectListItemController', function( App.controller('ProjectListItemController', function(
$scope, $scope,
$modal, $modal,
queuedHttp, queuedHttp,
@ -782,8 +758,10 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
$scope.isLinkSharingProject = project => project.source === 'token' $scope.isLinkSharingProject = project => project.source === 'token'
$scope.hasGenericOwnerName = () => { $scope.hasGenericOwnerName = () => {
/* eslint-disable camelcase */
const { first_name, last_name, email } = $scope.project.owner const { first_name, last_name, email } = $scope.project.owner
return !first_name && !last_name && !email return !first_name && !last_name && !email
/* eslint-enable camelcase */
} }
$scope.getOwnerName = ProjectListService.getOwnerName $scope.getOwnerName = ProjectListService.getOwnerName
@ -794,7 +772,7 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
$scope.$watch('project.selected', function(value) { $scope.$watch('project.selected', function(value) {
if (value != null) { if (value != null) {
return $scope.updateSelectedProjects() $scope.updateSelectedProjects()
} }
}) })
@ -816,13 +794,13 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
} }
} }
}) })
return ($scope.project.isTableActionInflight = false) $scope.project.isTableActionInflight = false
}) })
} }
$scope.download = function(e) { $scope.download = function(e) {
e.stopPropagation() e.stopPropagation()
return $scope.downloadProjectsById([$scope.project.id]) $scope.downloadProjectsById([$scope.project.id])
} }
$scope.archiveOrLeave = function(e) { $scope.archiveOrLeave = function(e) {
@ -835,10 +813,10 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
$scope.restore = function(e) { $scope.restore = function(e) {
e.stopPropagation() e.stopPropagation()
return $scope.restoreProjects([$scope.project]) $scope.restoreProjects([$scope.project])
} }
return ($scope.deleteProject = function(e) { $scope.deleteProject = function(e) {
e.stopPropagation() e.stopPropagation()
const modalInstance = $modal.open({ const modalInstance = $modal.open({
templateUrl: 'deleteProjectsModalTemplate', templateUrl: 'deleteProjectsModalTemplate',
@ -850,7 +828,7 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
} }
}) })
return modalInstance.result.then(function() { modalInstance.result.then(function() {
$scope.project.isTableActionInflight = true $scope.project.isTableActionInflight = true
return queuedHttp({ return queuedHttp({
method: 'DELETE', method: 'DELETE',
@ -862,19 +840,13 @@ define(['base', 'main/project-list/services/project-list'], function(App) {
.then(function() { .then(function() {
$scope.project.isTableActionInflight = false $scope.project.isTableActionInflight = false
$scope._removeProjectFromList($scope.project) $scope._removeProjectFromList($scope.project)
for (let tag of Array.from($scope.tags)) { for (let tag of $scope.tags) {
$scope._removeProjectIdsFromTagArray(tag, [$scope.project.id]) $scope._removeProjectIdsFromTagArray(tag, [$scope.project.id])
} }
return $scope.updateVisibleProjects() $scope.updateVisibleProjects()
}) })
.catch(() => ($scope.project.isTableActionInflight = false)) .catch(() => ($scope.project.isTableActionInflight = false))
}) })
}) }
}) })
}) })
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}

View file

@ -1,45 +1,27 @@
/* eslint-disable
camelcase,
max-len,
no-return-assign,
no-undef,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
define(['base', 'ide/colors/ColorManager'], function(App, ColorManager) { define(['base', 'ide/colors/ColorManager'], function(App, ColorManager) {
App.controller('TagListController', function($scope, $modal) { App.controller('TagListController', function($scope, $modal) {
$scope.filterProjects = function(filter) { $scope.filterProjects = function(filter = 'all') {
if (filter == null) {
filter = 'all'
}
$scope._clearTags() $scope._clearTags()
return $scope.setFilter(filter) $scope.setFilter(filter)
} }
$scope._clearTags = () => $scope._clearTags = () =>
Array.from($scope.tags).map(tag => (tag.selected = false)) $scope.tags.forEach(tag => {
tag.selected = false
})
$scope.selectTag = function(tag) { $scope.selectTag = function(tag) {
$scope._clearTags() $scope._clearTags()
tag.selected = true tag.selected = true
return $scope.setFilter('tag') $scope.setFilter('tag')
} }
$scope.selectUntagged = function() { $scope.selectUntagged = function() {
$scope._clearTags() $scope._clearTags()
return $scope.setFilter('untagged') $scope.setFilter('untagged')
} }
$scope.getHueForTagId = tag_id => { $scope.getHueForTagId = tagId => ColorManager.getHueForTagId(tagId)
return ColorManager.getHueForTagId(tag_id)
}
$scope.deleteTag = function(tag) { $scope.deleteTag = function(tag) {
const modalInstance = $modal.open({ const modalInstance = $modal.open({
@ -51,9 +33,9 @@ define(['base', 'ide/colors/ColorManager'], function(App, ColorManager) {
} }
} }
}) })
return modalInstance.result.then(function() { modalInstance.result.then(function() {
// Remove tag from projects // Remove tag from projects
for (let project of Array.from($scope.projects)) { for (let project of $scope.projects) {
if (!project.tags) { if (!project.tags) {
project.tags = [] project.tags = []
} }
@ -63,33 +45,30 @@ define(['base', 'ide/colors/ColorManager'], function(App, ColorManager) {
} }
} }
// Remove tag // Remove tag
return ($scope.tags = $scope.tags.filter(t => t !== tag)) $scope.tags = $scope.tags.filter(t => t !== tag)
}) })
} }
return ($scope.renameTag = function(tag) { $scope.renameTag = function(tag) {
const modalInstance = $modal.open({ const modalInstance = $modal.open({
templateUrl: 'renameTagModalTemplate', templateUrl: 'renameTagModalTemplate',
controller: 'RenameTagModalController', controller: 'RenameTagModalController',
resolve: { resolve: {
tag() { tag() {
return tag return tag
},
existing_tags() {
return $scope.tags
} }
} }
}) })
return modalInstance.result.then(new_name => (tag.name = new_name)) modalInstance.result.then(newName => (tag.name = newName))
}) }
}) })
App.controller('TagDropdownItemController', function($scope) { App.controller('TagDropdownItemController', function($scope) {
$scope.recalculateProjectsInTag = function() { $scope.recalculateProjectsInTag = function() {
let partialSelection let partialSelection
$scope.areSelectedProjectsInTag = false $scope.areSelectedProjectsInTag = false
for (let project_id of Array.from($scope.getSelectedProjectIds())) { for (let projectId of $scope.getSelectedProjectIds()) {
if (Array.from($scope.tag.project_ids).includes(project_id)) { if ($scope.tag.project_ids.includes(projectId)) {
$scope.areSelectedProjectsInTag = true $scope.areSelectedProjectsInTag = true
} else { } else {
partialSelection = true partialSelection = true
@ -97,25 +76,25 @@ define(['base', 'ide/colors/ColorManager'], function(App, ColorManager) {
} }
if ($scope.areSelectedProjectsInTag && partialSelection) { if ($scope.areSelectedProjectsInTag && partialSelection) {
return ($scope.areSelectedProjectsInTag = 'partial') $scope.areSelectedProjectsInTag = 'partial'
} }
} }
$scope.addOrRemoveProjectsFromTag = function() { $scope.addOrRemoveProjectsFromTag = function() {
if ($scope.areSelectedProjectsInTag === true) { if ($scope.areSelectedProjectsInTag === true) {
$scope.removeSelectedProjectsFromTag($scope.tag) $scope.removeSelectedProjectsFromTag($scope.tag)
return ($scope.areSelectedProjectsInTag = false) $scope.areSelectedProjectsInTag = false
} else if ( } else if (
$scope.areSelectedProjectsInTag === false || $scope.areSelectedProjectsInTag === false ||
$scope.areSelectedProjectsInTag === 'partial' $scope.areSelectedProjectsInTag === 'partial'
) { ) {
$scope.addSelectedProjectsToTag($scope.tag) $scope.addSelectedProjectsToTag($scope.tag)
return ($scope.areSelectedProjectsInTag = true) $scope.areSelectedProjectsInTag = true
} }
} }
$scope.$watch('selectedProjects', () => $scope.recalculateProjectsInTag()) $scope.$watch('selectedProjects', () => $scope.recalculateProjectsInTag())
return $scope.recalculateProjectsInTag() $scope.recalculateProjectsInTag()
}) })
App.controller('NewTagModalController', function( App.controller('NewTagModalController', function(
@ -139,7 +118,7 @@ define(['base', 'ide/colors/ColorManager'], function(App, ColorManager) {
const name = $scope.inputs.newTagName const name = $scope.inputs.newTagName
$scope.state.inflight = true $scope.state.inflight = true
$scope.state.error = false $scope.state.error = false
return $http $http
.post('/tag', { .post('/tag', {
_csrf: window.csrfToken, _csrf: window.csrfToken,
name name
@ -147,15 +126,15 @@ define(['base', 'ide/colors/ColorManager'], function(App, ColorManager) {
.then(function(response) { .then(function(response) {
const { data } = response const { data } = response
$scope.state.inflight = false $scope.state.inflight = false
return $modalInstance.close(data) $modalInstance.close(data)
}) })
.catch(function() { .catch(function() {
$scope.state.inflight = false $scope.state.inflight = false
return ($scope.state.error = true) $scope.state.error = true
}) })
} }
return ($scope.cancel = () => $modalInstance.dismiss('cancel')) $scope.cancel = () => $modalInstance.dismiss('cancel')
}) })
App.controller('RenameTagModalController', function( App.controller('RenameTagModalController', function(
@ -163,8 +142,7 @@ define(['base', 'ide/colors/ColorManager'], function(App, ColorManager) {
$modalInstance, $modalInstance,
$timeout, $timeout,
$http, $http,
tag, tag
existing_tags
) { ) {
$scope.inputs = { tagName: tag.name } $scope.inputs = { tagName: tag.name }
@ -188,15 +166,15 @@ define(['base', 'ide/colors/ColorManager'], function(App, ColorManager) {
}) })
.then(function() { .then(function() {
$scope.state.inflight = false $scope.state.inflight = false
return $modalInstance.close(name) $modalInstance.close(name)
}) })
.catch(function() { .catch(function() {
$scope.state.inflight = false $scope.state.inflight = false
return ($scope.state.error = true) $scope.state.error = true
}) })
} }
return ($scope.cancel = () => $modalInstance.dismiss('cancel')) $scope.cancel = () => $modalInstance.dismiss('cancel')
}) })
return App.controller('DeleteTagModalController', function( return App.controller('DeleteTagModalController', function(
@ -223,14 +201,14 @@ define(['base', 'ide/colors/ColorManager'], function(App, ColorManager) {
}) })
.then(function() { .then(function() {
$scope.state.inflight = false $scope.state.inflight = false
return $modalInstance.close() $modalInstance.close()
}) })
.catch(function() { .catch(function() {
$scope.state.inflight = false $scope.state.inflight = false
return ($scope.state.error = true) $scope.state.error = true
}) })
} }
return ($scope.cancel = () => $modalInstance.dismiss('cancel')) $scope.cancel = () => $modalInstance.dismiss('cancel')
}) })
}) })