2019-04-17 06:11:32 -04:00
|
|
|
define(['base', 'main/project-list/services/project-list'], function(App) {
|
2018-11-05 05:06:39 -05:00
|
|
|
App.controller('ProjectPageController', function(
|
|
|
|
$scope,
|
|
|
|
$modal,
|
|
|
|
$window,
|
|
|
|
queuedHttp,
|
2019-06-21 09:45:43 -04:00
|
|
|
event_tracking, // eslint-disable-line camelcase
|
2018-11-05 05:06:39 -05:00
|
|
|
$timeout,
|
2019-04-17 06:11:32 -04:00
|
|
|
localStorage,
|
|
|
|
ProjectListService
|
2018-11-05 05:06:39 -05:00
|
|
|
) {
|
|
|
|
$scope.projects = window.data.projects
|
|
|
|
$scope.tags = window.data.tags
|
|
|
|
$scope.notifications = window.data.notifications
|
|
|
|
$scope.allSelected = false
|
|
|
|
$scope.selectedProjects = []
|
|
|
|
$scope.isArchiveableProjectSelected = false
|
|
|
|
$scope.filter = 'all'
|
|
|
|
$scope.predicate = 'lastUpdated'
|
|
|
|
$scope.nUntagged = 0
|
|
|
|
$scope.reverse = true
|
|
|
|
$scope.searchText = { value: '' }
|
2019-04-17 06:11:32 -04:00
|
|
|
$scope.$watch('predicate', function(newValue) {
|
|
|
|
$scope.comparator =
|
|
|
|
newValue === 'ownerName' ? ownerNameComparator : defaultComparator
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
|
|
|
$timeout(() => recalculateProjectListHeight(), 10)
|
|
|
|
|
|
|
|
$scope.$watch(
|
|
|
|
() =>
|
|
|
|
$scope.projects.filter(
|
|
|
|
project =>
|
|
|
|
(project.tags == null || project.tags.length === 0) &&
|
|
|
|
!project.archived
|
|
|
|
).length,
|
|
|
|
newVal => ($scope.nUntagged = newVal)
|
|
|
|
)
|
|
|
|
|
|
|
|
var recalculateProjectListHeight = function() {
|
|
|
|
const $projListCard = $('.project-list-card')
|
2019-06-21 09:45:43 -04:00
|
|
|
if (!$projListCard) return
|
|
|
|
|
|
|
|
const topOffset = $projListCard.offset().top
|
2018-11-05 05:06:39 -05:00
|
|
|
const cardPadding = $projListCard.outerHeight() - $projListCard.height()
|
|
|
|
const bottomOffset = $('footer').outerHeight()
|
|
|
|
const height =
|
|
|
|
$window.innerHeight - topOffset - bottomOffset - cardPadding
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.projectListHeight = height
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:11:32 -04:00
|
|
|
function defaultComparator(v1, v2) {
|
|
|
|
var result = 0
|
|
|
|
var type1 = v1.type
|
|
|
|
var type2 = v2.type
|
|
|
|
|
|
|
|
if ($scope.predicate === 'ownerName') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type1 === type2) {
|
|
|
|
var value1 = v1.value
|
|
|
|
var value2 = v2.value
|
|
|
|
|
|
|
|
if (type1 === 'string') {
|
|
|
|
// Compare strings case-insensitively
|
|
|
|
value1 = value1.toLowerCase()
|
|
|
|
value2 = value2.toLowerCase()
|
|
|
|
} else if (type1 === 'object') {
|
|
|
|
// For basic objects, use the position of the object
|
|
|
|
// in the collection instead of the value
|
|
|
|
if (angular.isObject(value1)) value1 = v1.index
|
|
|
|
if (angular.isObject(value2)) value2 = v2.index
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value1 !== value2) {
|
|
|
|
result = value1 < value2 ? -1 : 1
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = type1 < type2 ? -1 : 1
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
function ownerNameComparator(v1, v2) {
|
|
|
|
if ($scope.predicate !== 'ownerName') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (v1.value === 'You') {
|
|
|
|
if (v2.value === 'You') {
|
|
|
|
return v1.index < v2.index ? -1 : 1
|
|
|
|
} else {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
} else if (v1.value === 'An Overleaf v1 User' || v1.value === 'None') {
|
|
|
|
if (v2.value === 'An Overleaf v1 User' || v2.value === 'None') {
|
|
|
|
return v1.index < v2.index ? -1 : 1
|
|
|
|
} else {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (v2.value === 'You') {
|
|
|
|
return -1
|
|
|
|
} else if (v2.value === 'An Overleaf v1 User' || v2.value === 'None') {
|
|
|
|
return 1
|
|
|
|
} else {
|
|
|
|
return v1.value > v2.value ? -1 : 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
angular.element($window).bind('resize', function() {
|
|
|
|
recalculateProjectListHeight()
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.$apply()
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
$scope.$on('project-list:notifications-received', () =>
|
|
|
|
$scope.$applyAsync(() => recalculateProjectListHeight())
|
|
|
|
)
|
|
|
|
|
|
|
|
// Allow tags to be accessed on projects as well
|
|
|
|
const projectsById = {}
|
2019-06-21 09:45:43 -04:00
|
|
|
for (let project of $scope.projects) {
|
2018-11-05 05:06:39 -05:00
|
|
|
projectsById[project.id] = project
|
|
|
|
}
|
|
|
|
|
2019-06-27 06:13:59 -04:00
|
|
|
$scope.getProjectById = id => projectsById[id]
|
|
|
|
|
|
|
|
for (let tag of $scope.tags) {
|
2019-06-21 09:45:43 -04:00
|
|
|
for (let projectId of tag.project_ids || []) {
|
|
|
|
let project = projectsById[projectId]
|
|
|
|
if (project) {
|
2018-11-05 05:06:39 -05:00
|
|
|
if (!project.tags) {
|
|
|
|
project.tags = []
|
|
|
|
}
|
|
|
|
project.tags.push(tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.changePredicate = function(newPredicate) {
|
|
|
|
if ($scope.predicate === newPredicate) {
|
|
|
|
$scope.reverse = !$scope.reverse
|
|
|
|
}
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.predicate = newPredicate
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.getSortIconClass = function(column) {
|
|
|
|
if (column === $scope.predicate && $scope.reverse) {
|
|
|
|
return 'fa-caret-down'
|
|
|
|
} else if (column === $scope.predicate && !$scope.reverse) {
|
|
|
|
return 'fa-caret-up'
|
|
|
|
} else {
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.searchProjects = function() {
|
|
|
|
event_tracking.send(
|
|
|
|
'project-list-page-interaction',
|
|
|
|
'project-search',
|
|
|
|
'keydown'
|
|
|
|
)
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateVisibleProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.clearSearchText = function() {
|
|
|
|
$scope.searchText.value = ''
|
|
|
|
$scope.filter = 'all'
|
|
|
|
$scope.$emit('search:clear')
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateVisibleProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.setFilter = function(filter) {
|
|
|
|
$scope.filter = filter
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateVisibleProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.updateSelectedProjects = function() {
|
|
|
|
$scope.selectedProjects = $scope.projects.filter(
|
|
|
|
project => project.selected
|
|
|
|
)
|
2018-11-13 05:34:27 -05:00
|
|
|
$scope.isArchiveableProjectSelected = $scope.selectedProjects.some(
|
2018-11-05 05:06:39 -05:00
|
|
|
project => window.user_id === project.owner._id
|
2018-11-13 05:34:27 -05:00
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.getSelectedProjects = () => $scope.selectedProjects
|
|
|
|
|
|
|
|
$scope.getSelectedProjectIds = () =>
|
|
|
|
$scope.selectedProjects.map(project => project.id)
|
|
|
|
|
|
|
|
$scope.getFirstSelectedProject = () => $scope.selectedProjects[0]
|
|
|
|
|
|
|
|
$scope.updateVisibleProjects = function() {
|
|
|
|
$scope.visibleProjects = []
|
|
|
|
const selectedTag = $scope.getSelectedTag()
|
2019-06-21 09:45:43 -04:00
|
|
|
for (let project of $scope.projects) {
|
2018-11-05 05:06:39 -05:00
|
|
|
let visible = true
|
|
|
|
// Only show if it matches any search text
|
2019-06-21 09:45:43 -04:00
|
|
|
if ($scope.searchText.value !== '') {
|
2018-11-05 05:06:39 -05:00
|
|
|
if (
|
|
|
|
project.name
|
|
|
|
.toLowerCase()
|
|
|
|
.indexOf($scope.searchText.value.toLowerCase()) === -1
|
|
|
|
) {
|
|
|
|
visible = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Only show if it matches the selected tag
|
|
|
|
if (
|
|
|
|
$scope.filter === 'tag' &&
|
|
|
|
selectedTag != null &&
|
2019-06-21 09:45:43 -04:00
|
|
|
!selectedTag.project_ids.includes(project.id)
|
2018-11-05 05:06:39 -05:00
|
|
|
) {
|
|
|
|
visible = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide tagged projects if we only want to see the uncategorized ones
|
|
|
|
if (
|
|
|
|
$scope.filter === 'untagged' &&
|
|
|
|
(project.tags != null ? project.tags.length : undefined) > 0
|
|
|
|
) {
|
|
|
|
visible = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide projects we own if we only want to see shared projects
|
|
|
|
if ($scope.filter === 'shared' && project.accessLevel === 'owner') {
|
|
|
|
visible = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide projects from V1 if we only want to see shared projects
|
|
|
|
if ($scope.filter === 'shared' && project.isV1Project) {
|
|
|
|
visible = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide projects we don't own if we only want to see owned projects
|
|
|
|
if ($scope.filter === 'owned' && project.accessLevel !== 'owner') {
|
|
|
|
visible = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($scope.filter === 'archived') {
|
|
|
|
// Only show archived projects
|
|
|
|
if (!project.archived) {
|
|
|
|
visible = false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Only show non-archived projects
|
|
|
|
if (project.archived) {
|
|
|
|
visible = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($scope.filter === 'v1' && !project.isV1Project) {
|
|
|
|
visible = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visible) {
|
|
|
|
$scope.visibleProjects.push(project)
|
|
|
|
} else {
|
|
|
|
// We don't want hidden selections
|
|
|
|
project.selected = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
localStorage(
|
|
|
|
'project_list',
|
|
|
|
JSON.stringify({
|
|
|
|
filter: $scope.filter,
|
|
|
|
selectedTagId: selectedTag != null ? selectedTag._id : undefined
|
|
|
|
})
|
|
|
|
)
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateSelectedProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.getSelectedTag = function() {
|
2019-06-27 06:13:59 -04:00
|
|
|
for (let tag of $scope.tags) {
|
2018-11-05 05:06:39 -05:00
|
|
|
if (tag.selected) {
|
|
|
|
return tag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope._removeProjectIdsFromTagArray = function(tag, removeProjectIds) {
|
2018-11-05 05:06:39 -05:00
|
|
|
// Remove project_id from tag.project_ids
|
2019-06-21 09:45:43 -04:00
|
|
|
const remainingProjectIds = []
|
|
|
|
const removedProjectIds = []
|
|
|
|
for (let projectId of tag.project_ids) {
|
|
|
|
if (!removeProjectIds.includes(projectId)) {
|
|
|
|
remainingProjectIds.push(projectId)
|
2018-11-05 05:06:39 -05:00
|
|
|
} else {
|
2019-06-21 09:45:43 -04:00
|
|
|
removedProjectIds.push(projectId)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
2019-06-21 09:45:43 -04:00
|
|
|
tag.project_ids = remainingProjectIds
|
|
|
|
return removedProjectIds
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope._removeProjectFromList = function(project) {
|
|
|
|
const index = $scope.projects.indexOf(project)
|
|
|
|
if (index > -1) {
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.projects.splice(index, 1)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.removeSelectedProjectsFromTag = function(tag) {
|
|
|
|
tag.showWhenEmpty = true
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
const selectedProjectIds = $scope.getSelectedProjectIds()
|
|
|
|
const selectedProjects = $scope.getSelectedProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
const removedProjectIds = $scope._removeProjectIdsFromTagArray(
|
2018-11-05 05:06:39 -05:00
|
|
|
tag,
|
2019-06-21 09:45:43 -04:00
|
|
|
selectedProjectIds
|
2018-11-05 05:06:39 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Remove tag from project.tags
|
2019-06-21 09:45:43 -04:00
|
|
|
for (let project of selectedProjects) {
|
2018-11-05 05:06:39 -05:00
|
|
|
if (!project.tags) {
|
|
|
|
project.tags = []
|
|
|
|
}
|
|
|
|
const index = project.tags.indexOf(tag)
|
|
|
|
if (index > -1) {
|
|
|
|
project.tags.splice(index, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
for (let projectId of removedProjectIds) {
|
2018-11-05 05:06:39 -05:00
|
|
|
queuedHttp({
|
|
|
|
method: 'DELETE',
|
2019-06-21 09:45:43 -04:00
|
|
|
url: `/tag/${tag._id}/project/${projectId}`,
|
2018-11-05 05:06:39 -05:00
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': window.csrfToken
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're filtering by this tag then we need to remove
|
|
|
|
// the projects from view
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateVisibleProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.removeProjectFromTag = function(project, tag) {
|
|
|
|
tag.showWhenEmpty = true
|
|
|
|
|
|
|
|
if (!project.tags) {
|
|
|
|
project.tags = []
|
|
|
|
}
|
|
|
|
const index = project.tags.indexOf(tag)
|
|
|
|
|
|
|
|
if (index > -1) {
|
|
|
|
$scope._removeProjectIdsFromTagArray(tag, [project.id])
|
|
|
|
project.tags.splice(index, 1)
|
|
|
|
queuedHttp({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `/tag/${tag._id}/project/${project.id}`,
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': window.csrfToken
|
|
|
|
}
|
|
|
|
})
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateVisibleProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.addSelectedProjectsToTag = function(tag) {
|
2019-06-21 09:45:43 -04:00
|
|
|
const selectedProjects = $scope.getSelectedProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
event_tracking.send(
|
|
|
|
'project-list-page-interaction',
|
|
|
|
'project action',
|
|
|
|
'addSelectedProjectsToTag'
|
|
|
|
)
|
|
|
|
|
|
|
|
// Add project_ids into tag.project_ids
|
2019-06-21 09:45:43 -04:00
|
|
|
const addedProjectIds = []
|
|
|
|
for (let projectId of $scope.getSelectedProjectIds()) {
|
|
|
|
if (!tag.project_ids.includes(projectId)) {
|
|
|
|
tag.project_ids.push(projectId)
|
|
|
|
addedProjectIds.push(projectId)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add tag into each project.tags
|
2019-06-21 09:45:43 -04:00
|
|
|
for (let project of selectedProjects) {
|
2018-11-05 05:06:39 -05:00
|
|
|
if (!project.tags) {
|
|
|
|
project.tags = []
|
|
|
|
}
|
2019-06-21 09:45:43 -04:00
|
|
|
if (!project.tags.includes(tag)) {
|
2018-11-05 05:06:39 -05:00
|
|
|
project.tags.push(tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
for (let projectId of addedProjectIds) {
|
|
|
|
queuedHttp.post(`/tag/${tag._id}/project/${projectId}`, {
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.openNewTagModal = function(e) {
|
|
|
|
const modalInstance = $modal.open({
|
|
|
|
templateUrl: 'newTagModalTemplate',
|
|
|
|
controller: 'NewTagModalController'
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
modalInstance.result.then(function(tag) {
|
2019-04-08 06:19:20 -04:00
|
|
|
const tagIsDuplicate = $scope.tags.find(function(existingTag) {
|
|
|
|
return tag.name === existingTag.name
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!tagIsDuplicate) {
|
|
|
|
$scope.tags.push(tag)
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.addSelectedProjectsToTag(tag)
|
2019-04-08 06:19:20 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.createProject = function(name, template) {
|
|
|
|
if (template == null) {
|
|
|
|
template = 'none'
|
|
|
|
}
|
|
|
|
return queuedHttp
|
|
|
|
.post('/project/new', {
|
|
|
|
_csrf: window.csrfToken,
|
|
|
|
projectName: name,
|
|
|
|
template
|
|
|
|
})
|
|
|
|
.then(function(response) {
|
|
|
|
const { data } = response
|
|
|
|
$scope.projects.push({
|
|
|
|
name,
|
|
|
|
_id: data.project_id,
|
2018-11-19 10:45:00 -05:00
|
|
|
accessLevel: 'owner',
|
|
|
|
owner: {
|
|
|
|
_id: window.user_id
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
// TODO: Check access level if correct after adding it in
|
|
|
|
// to the rest of the app
|
|
|
|
})
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateVisibleProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.openCreateProjectModal = function(template) {
|
|
|
|
if (template == null) {
|
|
|
|
template = 'none'
|
|
|
|
}
|
|
|
|
event_tracking.send(
|
|
|
|
'project-list-page-interaction',
|
|
|
|
'new-project',
|
|
|
|
template
|
|
|
|
)
|
|
|
|
const modalInstance = $modal.open({
|
|
|
|
templateUrl: 'newProjectModalTemplate',
|
|
|
|
controller: 'NewProjectModalController',
|
|
|
|
resolve: {
|
|
|
|
template() {
|
|
|
|
return template
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scope: $scope
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
modalInstance.result.then(
|
|
|
|
projectId => (window.location = `/project/${projectId}`)
|
2018-11-05 05:06:39 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.renameProject = (project, newName) =>
|
|
|
|
queuedHttp
|
|
|
|
.post(`/project/${project.id}/rename`, {
|
|
|
|
newProjectName: newName,
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
})
|
|
|
|
.then(() => (project.name = newName))
|
|
|
|
|
|
|
|
$scope.openRenameProjectModal = function() {
|
2019-06-21 09:45:43 -04:00
|
|
|
let project = $scope.getFirstSelectedProject()
|
|
|
|
if (!project || project.accessLevel !== 'owner') {
|
2018-11-05 05:06:39 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
event_tracking.send(
|
|
|
|
'project-list-page-interaction',
|
|
|
|
'project action',
|
|
|
|
'Rename'
|
|
|
|
)
|
2018-11-13 05:34:27 -05:00
|
|
|
$modal.open({
|
2018-11-05 05:06:39 -05:00
|
|
|
templateUrl: 'renameProjectModalTemplate',
|
|
|
|
controller: 'RenameProjectModalController',
|
|
|
|
resolve: {
|
|
|
|
project() {
|
|
|
|
return project
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scope: $scope
|
2018-11-13 05:34:27 -05:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.cloneProject = function(project, cloneName) {
|
|
|
|
event_tracking.send(
|
|
|
|
'project-list-page-interaction',
|
|
|
|
'project action',
|
|
|
|
'Clone'
|
|
|
|
)
|
|
|
|
return queuedHttp
|
|
|
|
.post(`/project/${project.id}/clone`, {
|
|
|
|
_csrf: window.csrfToken,
|
|
|
|
projectName: cloneName
|
|
|
|
})
|
|
|
|
.then(function(response) {
|
|
|
|
const { data } = response
|
|
|
|
$scope.projects.push({
|
2019-04-17 06:11:44 -04:00
|
|
|
name: data.name,
|
2018-11-05 05:06:39 -05:00
|
|
|
id: data.project_id,
|
|
|
|
accessLevel: 'owner',
|
|
|
|
owner: {
|
2019-04-17 06:11:44 -04:00
|
|
|
_id: data.owner_ref
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
// TODO: Check access level if correct after adding it in
|
|
|
|
// to the rest of the app
|
|
|
|
})
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateVisibleProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.openCloneProjectModal = function() {
|
2019-06-21 09:45:43 -04:00
|
|
|
let project = $scope.getFirstSelectedProject()
|
|
|
|
if (!project) {
|
2018-11-05 05:06:39 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-13 05:34:27 -05:00
|
|
|
$modal.open({
|
2018-11-05 05:06:39 -05:00
|
|
|
templateUrl: 'cloneProjectModalTemplate',
|
|
|
|
controller: 'CloneProjectModalController',
|
|
|
|
resolve: {
|
|
|
|
project() {
|
|
|
|
return project
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scope: $scope
|
2018-11-13 05:34:27 -05:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2019-02-15 08:16:21 -05:00
|
|
|
$scope.createArchiveProjectsModal = function(projects) {
|
|
|
|
return $modal.open({
|
2018-11-05 05:06:39 -05:00
|
|
|
templateUrl: 'deleteProjectsModalTemplate',
|
|
|
|
controller: 'DeleteProjectsModalController',
|
|
|
|
resolve: {
|
|
|
|
projects() {
|
2019-02-15 08:16:21 -05:00
|
|
|
return projects
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-02-15 08:16:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.openArchiveProjectsModal = function() {
|
|
|
|
const modalInstance = $scope.createArchiveProjectsModal(
|
|
|
|
$scope.getSelectedProjects()
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
event_tracking.send(
|
|
|
|
'project-list-page-interaction',
|
|
|
|
'project action',
|
|
|
|
'Delete'
|
|
|
|
)
|
2019-06-21 09:45:43 -04:00
|
|
|
modalInstance.result.then(() => $scope.archiveOrLeaveSelectedProjects())
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.archiveOrLeaveSelectedProjects = () =>
|
|
|
|
$scope.archiveOrLeaveProjects($scope.getSelectedProjects())
|
|
|
|
|
|
|
|
$scope.archiveOrLeaveProjects = function(projects) {
|
2018-11-13 05:34:27 -05:00
|
|
|
for (let project of projects) {
|
2019-02-15 08:16:21 -05:00
|
|
|
$scope.archiveOrLeaveProject(project)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-02-15 08:16:21 -05:00
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-02-15 08:16:21 -05:00
|
|
|
$scope.archiveOrLeaveProject = function(project) {
|
|
|
|
if (project.accessLevel === 'owner') {
|
|
|
|
project.archived = true
|
|
|
|
queuedHttp({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `/project/${project.id}`,
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': window.csrfToken
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
$scope._removeProjectFromList(project)
|
|
|
|
|
|
|
|
queuedHttp({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/project/${project.id}/leave`,
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': window.csrfToken
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:11:32 -04:00
|
|
|
$scope.getValueForCurrentPredicate = function(project) {
|
|
|
|
if ($scope.predicate === 'ownerName') {
|
|
|
|
return ProjectListService.getOwnerName(project)
|
|
|
|
} else {
|
|
|
|
return project[$scope.predicate]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
$scope.openDeleteProjectsModal = function() {
|
|
|
|
const modalInstance = $modal.open({
|
|
|
|
templateUrl: 'deleteProjectsModalTemplate',
|
|
|
|
controller: 'DeleteProjectsModalController',
|
|
|
|
resolve: {
|
|
|
|
projects() {
|
|
|
|
return $scope.getSelectedProjects()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
modalInstance.result.then(() => $scope.deleteSelectedProjects())
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.deleteSelectedProjects = function() {
|
2019-06-21 09:45:43 -04:00
|
|
|
const selectedProjects = $scope.getSelectedProjects()
|
|
|
|
const selectedProjectIds = $scope.getSelectedProjectIds()
|
2018-11-05 05:06:39 -05:00
|
|
|
|
|
|
|
// Remove projects from array
|
2019-06-21 09:45:43 -04:00
|
|
|
for (let project of selectedProjects) {
|
2018-11-05 05:06:39 -05:00
|
|
|
$scope._removeProjectFromList(project)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove project from any tags
|
2019-06-27 06:13:59 -04:00
|
|
|
for (let tag of $scope.tags) {
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope._removeProjectIdsFromTagArray(tag, selectedProjectIds)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
for (let projectId of selectedProjectIds) {
|
2018-11-05 05:06:39 -05:00
|
|
|
queuedHttp({
|
|
|
|
method: 'DELETE',
|
2019-06-21 09:45:43 -04:00
|
|
|
url: `/project/${projectId}?forever=true`,
|
2018-11-05 05:06:39 -05:00
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': window.csrfToken
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateVisibleProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.restoreSelectedProjects = () =>
|
|
|
|
$scope.restoreProjects($scope.getSelectedProjects())
|
|
|
|
|
|
|
|
$scope.restoreProjects = function(projects) {
|
|
|
|
const projectIds = projects.map(p => p.id)
|
2019-06-21 09:45:43 -04:00
|
|
|
for (let project of projects) {
|
2018-11-05 05:06:39 -05:00
|
|
|
project.archived = false
|
|
|
|
}
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
for (let projectId of projectIds) {
|
2018-11-05 05:06:39 -05:00
|
|
|
queuedHttp({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/project/${projectId}/restore`,
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': window.csrfToken
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateVisibleProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.openUploadProjectModal = function() {
|
2018-11-13 05:34:27 -05:00
|
|
|
$modal.open({
|
2018-11-05 05:06:39 -05:00
|
|
|
templateUrl: 'uploadProjectModalTemplate',
|
|
|
|
controller: 'UploadProjectModalController'
|
2018-11-13 05:34:27 -05:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.downloadSelectedProjects = () =>
|
|
|
|
$scope.downloadProjectsById($scope.getSelectedProjectIds())
|
|
|
|
|
|
|
|
$scope.downloadProjectsById = function(projectIds) {
|
|
|
|
let path
|
|
|
|
event_tracking.send(
|
|
|
|
'project-list-page-interaction',
|
|
|
|
'project action',
|
|
|
|
'Download Zip'
|
|
|
|
)
|
|
|
|
if (projectIds.length > 1) {
|
|
|
|
path = `/project/download/zip?project_ids=${projectIds.join(',')}`
|
|
|
|
} else {
|
|
|
|
path = `/project/${projectIds[0]}/download/zip`
|
|
|
|
}
|
|
|
|
return (window.location = path)
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.openV1ImportModal = project =>
|
|
|
|
$modal.open({
|
|
|
|
templateUrl: 'v1ImportModalTemplate',
|
|
|
|
controller: 'V1ImportModalController',
|
|
|
|
size: 'lg',
|
|
|
|
windowClass: 'v1-import-modal',
|
|
|
|
resolve: {
|
|
|
|
project() {
|
|
|
|
return project
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
const markTagAsSelected = id => {
|
2019-06-27 06:13:59 -04:00
|
|
|
for (let tag of $scope.tags) {
|
2019-06-21 09:45:43 -04:00
|
|
|
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) {
|
2018-11-05 05:06:39 -05:00
|
|
|
markTagAsSelected(storedUIOpts.selectedTagId)
|
|
|
|
}
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.setFilter(storedUIOpts.filter)
|
2018-11-05 05:06:39 -05:00
|
|
|
} else {
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateVisibleProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
App.controller('ProjectListItemController', function(
|
2018-11-05 05:06:39 -05:00
|
|
|
$scope,
|
|
|
|
$modal,
|
2019-04-17 06:11:32 -04:00
|
|
|
queuedHttp,
|
|
|
|
ProjectListService
|
2018-11-05 05:06:39 -05:00
|
|
|
) {
|
|
|
|
$scope.shouldDisableCheckbox = project =>
|
|
|
|
$scope.filter === 'archived' && project.accessLevel !== 'owner'
|
|
|
|
|
|
|
|
$scope.projectLink = function(project) {
|
|
|
|
if (
|
|
|
|
project.accessLevel === 'readAndWrite' &&
|
|
|
|
project.source === 'token'
|
|
|
|
) {
|
|
|
|
return `/${project.tokens.readAndWrite}`
|
|
|
|
} else if (
|
|
|
|
project.accessLevel === 'readOnly' &&
|
|
|
|
project.source === 'token'
|
|
|
|
) {
|
|
|
|
return `/read/${project.tokens.readOnly}`
|
|
|
|
} else {
|
|
|
|
return `/project/${project.id}`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.isLinkSharingProject = project => project.source === 'token'
|
|
|
|
|
2019-01-09 08:24:14 -05:00
|
|
|
$scope.hasGenericOwnerName = () => {
|
2019-06-21 09:45:43 -04:00
|
|
|
/* eslint-disable camelcase */
|
2019-01-09 08:24:14 -05:00
|
|
|
const { first_name, last_name, email } = $scope.project.owner
|
|
|
|
return !first_name && !last_name && !email
|
2019-06-21 09:45:43 -04:00
|
|
|
/* eslint-enable camelcase */
|
2019-01-09 08:24:14 -05:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:11:32 -04:00
|
|
|
$scope.getOwnerName = ProjectListService.getOwnerName
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-05-21 09:28:13 -04:00
|
|
|
$scope.getUserName = ProjectListService.getUserName
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
$scope.isOwner = () => window.user_id === $scope.project.owner._id
|
|
|
|
|
|
|
|
$scope.$watch('project.selected', function(value) {
|
|
|
|
if (value != null) {
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateSelectedProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
$scope.clone = function(e) {
|
|
|
|
e.stopPropagation()
|
|
|
|
$scope.project.isTableActionInflight = true
|
|
|
|
return $scope
|
|
|
|
.cloneProject($scope.project, `${$scope.project.name} (Copy)`)
|
|
|
|
.then(() => ($scope.project.isTableActionInflight = false))
|
|
|
|
.catch(function(response) {
|
|
|
|
const { data, status } = response
|
|
|
|
const error = status === 400 ? { message: data } : true
|
2018-11-13 05:34:27 -05:00
|
|
|
$modal.open({
|
2018-11-05 05:06:39 -05:00
|
|
|
templateUrl: 'showErrorModalTemplate',
|
|
|
|
controller: 'ShowErrorModalController',
|
|
|
|
resolve: {
|
|
|
|
error() {
|
|
|
|
return error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.project.isTableActionInflight = false
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.download = function(e) {
|
|
|
|
e.stopPropagation()
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.downloadProjectsById([$scope.project.id])
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.archiveOrLeave = function(e) {
|
|
|
|
e.stopPropagation()
|
2019-02-15 08:16:21 -05:00
|
|
|
$scope.createArchiveProjectsModal([$scope.project]).result.then(() => {
|
|
|
|
$scope.archiveOrLeaveProject($scope.project)
|
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.restore = function(e) {
|
|
|
|
e.stopPropagation()
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.restoreProjects([$scope.project])
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.deleteProject = function(e) {
|
2018-11-05 05:06:39 -05:00
|
|
|
e.stopPropagation()
|
|
|
|
const modalInstance = $modal.open({
|
|
|
|
templateUrl: 'deleteProjectsModalTemplate',
|
|
|
|
controller: 'DeleteProjectsModalController',
|
|
|
|
resolve: {
|
|
|
|
projects() {
|
|
|
|
return [$scope.project]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:45:43 -04:00
|
|
|
modalInstance.result.then(function() {
|
2018-11-05 05:06:39 -05:00
|
|
|
$scope.project.isTableActionInflight = true
|
|
|
|
return queuedHttp({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `/project/${$scope.project.id}?forever=true`,
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': window.csrfToken
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
$scope.project.isTableActionInflight = false
|
|
|
|
$scope._removeProjectFromList($scope.project)
|
2019-06-21 09:45:43 -04:00
|
|
|
for (let tag of $scope.tags) {
|
2018-11-05 05:06:39 -05:00
|
|
|
$scope._removeProjectIdsFromTagArray(tag, [$scope.project.id])
|
|
|
|
}
|
2019-06-21 09:45:43 -04:00
|
|
|
$scope.updateVisibleProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
.catch(() => ($scope.project.isTableActionInflight = false))
|
|
|
|
})
|
2019-06-21 09:45:43 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
})
|