2020-06-23 04:45:38 -04:00
|
|
|
import _ from 'lodash'
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../base'
|
|
|
|
import './services/project-list'
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller('ProjectPageController', function (
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope,
|
|
|
|
$modal,
|
|
|
|
$window,
|
|
|
|
queuedHttp,
|
|
|
|
eventTracking, // eslint-disable-line camelcase
|
|
|
|
$timeout,
|
|
|
|
localStorage,
|
|
|
|
ProjectListService
|
|
|
|
) {
|
|
|
|
$scope.projects = window.data.projects
|
|
|
|
$scope.tags = window.data.tags
|
|
|
|
$scope.notifications = window.data.notifications
|
|
|
|
$scope.notificationsInstitution = window.data.notificationsInstitution
|
|
|
|
$scope.allSelected = false
|
|
|
|
$scope.selectedProjects = []
|
|
|
|
$scope.filter = 'all'
|
|
|
|
$scope.predicate = 'lastUpdated'
|
|
|
|
$scope.nUntagged = 0
|
|
|
|
$scope.reverse = true
|
|
|
|
$scope.searchText = { value: '' }
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.$watch('predicate', function (newValue) {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.comparator =
|
|
|
|
newValue === 'ownerName' ? ownerNameComparator : defaultComparator
|
|
|
|
})
|
2019-04-17 06:11:32 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$timeout(() => recalculateProjectListHeight(), 10)
|
|
|
|
|
|
|
|
$scope.$watch(
|
|
|
|
() =>
|
|
|
|
$scope.projects.filter(
|
|
|
|
project =>
|
|
|
|
(project.tags == null || project.tags.length === 0) &&
|
|
|
|
!project.archived &&
|
|
|
|
!project.trashed
|
|
|
|
).length,
|
|
|
|
newVal => ($scope.nUntagged = newVal)
|
|
|
|
)
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
var recalculateProjectListHeight = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
const $projListCard = $('.project-list-card')
|
|
|
|
if (!$projListCard || !$projListCard.offset()) return
|
|
|
|
|
|
|
|
const topOffset = $projListCard.offset().top
|
|
|
|
const cardPadding = $projListCard.outerHeight() - $projListCard.height()
|
|
|
|
const bottomOffset = $('footer').outerHeight()
|
|
|
|
const height = $window.innerHeight - topOffset - bottomOffset - cardPadding
|
|
|
|
$scope.projectListHeight = height
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2019-04-17 06:11:32 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
} else {
|
|
|
|
result = type1 < type2 ? -1 : 1
|
|
|
|
}
|
2019-04-17 06:11:32 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
return result
|
|
|
|
}
|
2019-04-17 06:11:32 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
function ownerNameComparator(v1, v2) {
|
|
|
|
if ($scope.predicate !== 'ownerName') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (v1.value === 'You') {
|
|
|
|
if (v2.value === 'You') {
|
|
|
|
return v1.index < v2.index ? -1 : 1
|
2019-04-17 06:11:32 -04:00
|
|
|
} else {
|
2020-05-19 05:02:56 -04:00
|
|
|
return 1
|
2019-04-17 06:11:32 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
} 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
|
2019-04-17 06:11:32 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
} else {
|
|
|
|
if (v2.value === 'You') {
|
|
|
|
return -1
|
|
|
|
} else if (v2.value === 'An Overleaf v1 User' || v2.value === 'None') {
|
|
|
|
return 1
|
2019-04-17 06:11:32 -04:00
|
|
|
} else {
|
2020-05-19 05:02:56 -04:00
|
|
|
return v1.value > v2.value ? -1 : 1
|
2019-04-17 06:11:32 -04:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2019-04-17 06:11:32 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
angular.element($window).bind('resize', function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
recalculateProjectListHeight()
|
|
|
|
$scope.$apply()
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.$on('project-list:notifications-received', () =>
|
|
|
|
$scope.$applyAsync(() => recalculateProjectListHeight())
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// Allow tags to be accessed on projects as well
|
|
|
|
const projectsById = {}
|
|
|
|
for (let project of $scope.projects) {
|
|
|
|
projectsById[project.id] = project
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.getProjectById = id => projectsById[id]
|
2019-06-27 06:13:59 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
for (let tag of $scope.tags) {
|
|
|
|
for (let projectId of tag.project_ids || []) {
|
|
|
|
let project = projectsById[projectId]
|
|
|
|
if (project) {
|
|
|
|
if (!project.tags) {
|
|
|
|
project.tags = []
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
project.tags.push(tag)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.changePredicate = function (newPredicate) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if ($scope.predicate === newPredicate) {
|
|
|
|
$scope.reverse = !$scope.reverse
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.predicate = newPredicate
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.getSortIconClass = function (column) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (column === $scope.predicate && $scope.reverse) {
|
|
|
|
return 'fa-caret-down'
|
|
|
|
} else if (column === $scope.predicate && !$scope.reverse) {
|
|
|
|
return 'fa-caret-up'
|
|
|
|
} else {
|
|
|
|
return ''
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.searchProjects = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
eventTracking.send(
|
|
|
|
'project-list-page-interaction',
|
|
|
|
'project-search',
|
|
|
|
'keydown'
|
|
|
|
)
|
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.clearSearchText = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.searchText.value = ''
|
|
|
|
$scope.filter = 'all'
|
|
|
|
$scope.$emit('search:clear')
|
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.setFilter = function (filter) {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.filter = filter
|
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.updateSelectedProjects = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.selectedProjects = $scope.projects.filter(
|
|
|
|
project => project.selected
|
|
|
|
)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.getSelectedProjects = () => $scope.selectedProjects
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.getSelectedProjectIds = () =>
|
|
|
|
$scope.selectedProjects.map(project => project.id)
|
|
|
|
|
|
|
|
$scope.getFirstSelectedProject = () => $scope.selectedProjects[0]
|
|
|
|
|
|
|
|
$scope.hasLeavableProjectsSelected = () =>
|
|
|
|
_.some(
|
|
|
|
$scope.getSelectedProjects(),
|
|
|
|
project => project.accessLevel !== 'owner' && project.trashed
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.hasDeletableProjectsSelected = () =>
|
|
|
|
_.some(
|
|
|
|
$scope.getSelectedProjects(),
|
|
|
|
project => project.accessLevel === 'owner' && project.trashed
|
|
|
|
)
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.updateVisibleProjects = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.visibleProjects = []
|
|
|
|
const selectedTag = $scope.getSelectedTag()
|
|
|
|
for (let project of $scope.projects) {
|
|
|
|
let visible = true
|
|
|
|
// Only show if it matches any search text
|
|
|
|
if ($scope.searchText.value !== '') {
|
2018-11-05 05:06:39 -05:00
|
|
|
if (
|
2020-05-19 05:02:56 -04:00
|
|
|
project.name
|
|
|
|
.toLowerCase()
|
|
|
|
.indexOf($scope.searchText.value.toLowerCase()) === -1
|
2018-11-05 05:06:39 -05:00
|
|
|
) {
|
|
|
|
visible = false
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
// Only show if it matches the selected tag
|
|
|
|
if (
|
|
|
|
$scope.filter === 'tag' &&
|
|
|
|
selectedTag != null &&
|
|
|
|
!selectedTag.project_ids.includes(project.id)
|
|
|
|
) {
|
|
|
|
visible = false
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// 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
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// Hide projects we own if we only want to see shared projects
|
|
|
|
if ($scope.filter === 'shared' && project.accessLevel === 'owner') {
|
|
|
|
visible = false
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// Hide projects we don't own if we only want to see owned projects
|
|
|
|
if ($scope.filter === 'owned' && project.accessLevel !== 'owner') {
|
|
|
|
visible = false
|
|
|
|
}
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if ($scope.filter === 'archived') {
|
|
|
|
// Only show archived projects
|
|
|
|
if (!project.archived) {
|
2018-11-05 05:06:39 -05:00
|
|
|
visible = false
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
} else {
|
|
|
|
// Only show non-archived projects
|
|
|
|
if (project.archived) {
|
|
|
|
visible = false
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if ($scope.filter === 'trashed') {
|
|
|
|
// Only show trashed projects
|
|
|
|
if (!project.trashed) {
|
|
|
|
visible = false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Only show non-trashed projects
|
|
|
|
if (project.trashed) {
|
|
|
|
visible = false
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (visible) {
|
|
|
|
$scope.visibleProjects.push(project)
|
|
|
|
} else {
|
|
|
|
// We don't want hidden selections
|
|
|
|
project.selected = false
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
localStorage(
|
|
|
|
'project_list',
|
|
|
|
JSON.stringify({
|
|
|
|
filter: $scope.filter,
|
2021-04-27 03:52:58 -04:00
|
|
|
selectedTagId: selectedTag != null ? selectedTag._id : undefined,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
)
|
|
|
|
$scope.updateSelectedProjects()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.getSelectedTag = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
for (let tag of $scope.tags) {
|
|
|
|
if (tag.selected) {
|
|
|
|
return tag
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope._removeProjectIdsFromTagArray = function (tag, removeProjectIds) {
|
2020-05-19 05:02:56 -04:00
|
|
|
// Remove project_id from tag.project_ids
|
|
|
|
const remainingProjectIds = []
|
|
|
|
const removedProjectIds = []
|
|
|
|
for (let projectId of tag.project_ids) {
|
|
|
|
if (!removeProjectIds.includes(projectId)) {
|
|
|
|
remainingProjectIds.push(projectId)
|
|
|
|
} else {
|
|
|
|
removedProjectIds.push(projectId)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
tag.project_ids = remainingProjectIds
|
|
|
|
return removedProjectIds
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope._removeProjectFromList = function (project) {
|
2020-05-19 05:02:56 -04:00
|
|
|
const index = $scope.projects.indexOf(project)
|
|
|
|
if (index > -1) {
|
|
|
|
$scope.projects.splice(index, 1)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.removeSelectedProjectsFromTag = function (tag) {
|
2020-05-19 05:02:56 -04:00
|
|
|
tag.showWhenEmpty = true
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const selectedProjectIds = $scope.getSelectedProjectIds()
|
|
|
|
const selectedProjects = $scope.getSelectedProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const removedProjectIds = $scope._removeProjectIdsFromTagArray(
|
|
|
|
tag,
|
|
|
|
selectedProjectIds
|
|
|
|
)
|
|
|
|
|
|
|
|
// Remove tag from project.tags
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
for (let projectId of removedProjectIds) {
|
|
|
|
queuedHttp({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `/tag/${tag._id}/project/${projectId}`,
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-CSRF-Token': window.csrfToken,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// If we're filtering by this tag then we need to remove
|
|
|
|
// the projects from view
|
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.removeProjectFromTag = function (project, tag) {
|
2020-05-19 05:02:56 -04:00
|
|
|
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: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-CSRF-Token': window.csrfToken,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.addSelectedProjectsToTag = function (tag) {
|
2020-05-19 05:02:56 -04:00
|
|
|
const selectedProjects = $scope.getSelectedProjects()
|
|
|
|
eventTracking.send(
|
|
|
|
'project-list-page-interaction',
|
|
|
|
'project action',
|
|
|
|
'addSelectedProjectsToTag'
|
|
|
|
)
|
|
|
|
|
|
|
|
// Add project_ids into tag.project_ids
|
|
|
|
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
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// Add tag into each project.tags
|
|
|
|
for (let project of selectedProjects) {
|
|
|
|
if (!project.tags) {
|
|
|
|
project.tags = []
|
|
|
|
}
|
|
|
|
if (!project.tags.includes(tag)) {
|
|
|
|
project.tags.push(tag)
|
2019-06-21 09:45:43 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
for (let projectId of addedProjectIds) {
|
|
|
|
queuedHttp.post(`/tag/${tag._id}/project/${projectId}`, {
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: window.csrfToken,
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.openNewTagModal = function (e) {
|
2020-05-19 05:02:56 -04:00
|
|
|
const modalInstance = $modal.open({
|
|
|
|
templateUrl: 'newTagModalTemplate',
|
2021-04-27 03:52:58 -04:00
|
|
|
controller: 'NewTagModalController',
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
2019-04-08 06:19:20 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
modalInstance.result.then(function (tag) {
|
|
|
|
const tagIsDuplicate = $scope.tags.find(function (existingTag) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return tag.name === existingTag.name
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (!tagIsDuplicate) {
|
|
|
|
$scope.tags.push(tag)
|
|
|
|
$scope.addSelectedProjectsToTag(tag)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.createProject = function (name, template) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (template == null) {
|
|
|
|
template = 'none'
|
|
|
|
}
|
|
|
|
return queuedHttp
|
|
|
|
.post('/project/new', {
|
|
|
|
_csrf: window.csrfToken,
|
|
|
|
projectName: name,
|
2021-04-27 03:52:58 -04:00
|
|
|
template,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
.then(function (response) {
|
2020-05-19 05:02:56 -04:00
|
|
|
const { data } = response
|
|
|
|
$scope.projects.push({
|
|
|
|
name,
|
|
|
|
_id: data.project_id,
|
|
|
|
accessLevel: 'owner',
|
2021-04-27 03:52:58 -04:00
|
|
|
owner: data.owner,
|
2020-05-19 05:02:56 -04:00
|
|
|
// TODO: Check access level if correct after adding it in
|
|
|
|
// to the rest of the app
|
|
|
|
})
|
|
|
|
$scope.updateVisibleProjects()
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.openCreateProjectModal = function (template) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (template == null) {
|
|
|
|
template = 'none'
|
|
|
|
}
|
|
|
|
eventTracking.send('project-list-page-interaction', 'new-project', template)
|
|
|
|
const modalInstance = $modal.open({
|
|
|
|
templateUrl: 'newProjectModalTemplate',
|
|
|
|
controller: 'NewProjectModalController',
|
|
|
|
resolve: {
|
|
|
|
template() {
|
|
|
|
return template
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
2021-04-27 03:52:58 -04:00
|
|
|
scope: $scope,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
modalInstance.result.then(
|
|
|
|
projectId => (window.location = `/project/${projectId}`)
|
|
|
|
)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.renameProject = (project, newName) =>
|
|
|
|
queuedHttp
|
|
|
|
.post(`/project/${project.id}/rename`, {
|
|
|
|
newProjectName: newName,
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: window.csrfToken,
|
2018-11-13 05:34:27 -05:00
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
.then(() => (project.name = newName))
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.openRenameProjectModal = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
let project = $scope.getFirstSelectedProject()
|
|
|
|
if (!project || project.accessLevel !== 'owner') {
|
|
|
|
return
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
eventTracking.send(
|
|
|
|
'project-list-page-interaction',
|
|
|
|
'project action',
|
|
|
|
'Rename'
|
|
|
|
)
|
|
|
|
$modal.open({
|
|
|
|
templateUrl: 'renameProjectModalTemplate',
|
|
|
|
controller: 'RenameProjectModalController',
|
|
|
|
resolve: {
|
|
|
|
project() {
|
|
|
|
return project
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
2021-04-27 03:52:58 -04:00
|
|
|
scope: $scope,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.cloneProject = function (project, cloneName) {
|
2020-05-19 05:02:56 -04:00
|
|
|
eventTracking.send(
|
|
|
|
'project-list-page-interaction',
|
|
|
|
'project action',
|
|
|
|
'Clone'
|
|
|
|
)
|
|
|
|
return queuedHttp
|
|
|
|
.post(`/project/${project.id}/clone`, {
|
|
|
|
_csrf: window.csrfToken,
|
2021-04-27 03:52:58 -04:00
|
|
|
projectName: cloneName,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
.then(function (response) {
|
2020-05-19 05:02:56 -04:00
|
|
|
const { data } = response
|
|
|
|
$scope.projects.push({
|
|
|
|
name: data.name,
|
|
|
|
id: data.project_id,
|
|
|
|
accessLevel: 'owner',
|
2021-04-27 03:52:58 -04:00
|
|
|
owner: data.owner,
|
2020-05-19 05:02:56 -04:00
|
|
|
// TODO: Check access level if correct after adding it in
|
|
|
|
// to the rest of the app
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.openCloneProjectModal = function (project) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (!project) {
|
|
|
|
return
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$modal.open({
|
|
|
|
templateUrl: 'cloneProjectModalTemplate',
|
|
|
|
controller: 'CloneProjectModalController',
|
|
|
|
resolve: {
|
|
|
|
project() {
|
|
|
|
return project
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
2021-04-27 03:52:58 -04:00
|
|
|
scope: $scope,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// Methods to create modals for archiving, trashing, leaving and deleting projects
|
2021-04-14 09:17:21 -04:00
|
|
|
const _createArchiveTrashLeaveOrDeleteProjectsModal = function (
|
2020-05-19 05:02:56 -04:00
|
|
|
action,
|
|
|
|
projects
|
|
|
|
) {
|
|
|
|
eventTracking.send(
|
|
|
|
'project-list-page-interaction',
|
|
|
|
'project action',
|
|
|
|
action
|
|
|
|
)
|
|
|
|
return $modal.open({
|
|
|
|
templateUrl: 'archiveTrashLeaveOrDeleteProjectsModalTemplate',
|
|
|
|
controller: 'ArchiveTrashLeaveOrDeleteProjectsModalController',
|
|
|
|
resolve: {
|
|
|
|
projects() {
|
|
|
|
return projects
|
2018-11-05 05:06:39 -05:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
action() {
|
|
|
|
return action
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2019-02-15 08:16:21 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.createArchiveProjectsModal = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return _createArchiveTrashLeaveOrDeleteProjectsModal('archive', projects)
|
|
|
|
}
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.createTrashProjectsModal = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return _createArchiveTrashLeaveOrDeleteProjectsModal('trash', projects)
|
|
|
|
}
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.createLeaveProjectsModal = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return _createArchiveTrashLeaveOrDeleteProjectsModal('leave', projects)
|
|
|
|
}
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.createDeleteProjectsModal = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return _createArchiveTrashLeaveOrDeleteProjectsModal('delete', projects)
|
|
|
|
}
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.createLeaveOrDeleteProjectsModal = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return _createArchiveTrashLeaveOrDeleteProjectsModal(
|
|
|
|
'leaveOrDelete',
|
|
|
|
projects
|
|
|
|
)
|
|
|
|
}
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
//
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.openArchiveProjectsModal = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
const modalInstance = $scope.createArchiveProjectsModal(
|
|
|
|
$scope.getSelectedProjects()
|
|
|
|
)
|
|
|
|
modalInstance.result.then(() => $scope.archiveSelectedProjects())
|
|
|
|
}
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.openTrashProjectsModal = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
const modalInstance = $scope.createTrashProjectsModal(
|
|
|
|
$scope.getSelectedProjects()
|
|
|
|
)
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
modalInstance.result.then(() => $scope.trashSelectedProjects())
|
|
|
|
}
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.openLeaveProjectsModal = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
const modalInstance = $scope.createLeaveProjectsModal(
|
|
|
|
$scope.getSelectedProjects()
|
|
|
|
)
|
|
|
|
modalInstance.result.then(() => $scope.leaveSelectedProjects())
|
|
|
|
}
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.openDeleteProjectsModal = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
const modalInstance = $scope.createDeleteProjectsModal(
|
|
|
|
$scope.getSelectedProjects()
|
|
|
|
)
|
|
|
|
modalInstance.result.then(() => $scope.deleteSelectedProjects())
|
|
|
|
}
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.openLeaveOrDeleteProjectsModal = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
const modalInstance = $scope.createLeaveOrDeleteProjectsModal(
|
|
|
|
$scope.getSelectedProjects()
|
|
|
|
)
|
|
|
|
modalInstance.result.then(() => $scope.leaveOrDeleteSelectedProjects())
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
//
|
|
|
|
$scope.archiveSelectedProjects = () =>
|
|
|
|
$scope.archiveProjects($scope.getSelectedProjects())
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.unarchiveSelectedProjects = () =>
|
|
|
|
$scope.unarchiveProjects($scope.getSelectedProjects())
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.trashSelectedProjects = () =>
|
|
|
|
$scope.trashProjects($scope.getSelectedProjects())
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.untrashSelectedProjects = () =>
|
|
|
|
$scope.untrashProjects($scope.getSelectedProjects())
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.leaveSelectedProjects = () =>
|
|
|
|
$scope.leaveProjects($scope.getSelectedProjects())
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.deleteSelectedProjects = () =>
|
|
|
|
$scope.deleteProjects($scope.getSelectedProjects())
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.leaveOrDeleteSelectedProjects = () =>
|
|
|
|
$scope.leaveOrDeleteProjects($scope.getSelectedProjects())
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
//
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.archiveProjects = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
for (let project of projects) {
|
|
|
|
project.archived = true
|
|
|
|
project.trashed = false
|
|
|
|
_archiveProject(project)
|
2019-02-15 08:16:21 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.unarchiveProjects = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
for (let project of projects) {
|
|
|
|
project.archived = false
|
|
|
|
_unarchiveProject(project)
|
2019-11-25 10:41:12 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
2019-02-15 08:16:21 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.trashProjects = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
for (let project of projects) {
|
|
|
|
project.trashed = true
|
|
|
|
project.archived = false
|
|
|
|
_trashProject(project)
|
2019-11-25 10:41:12 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
2019-06-27 06:14:16 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.untrashProjects = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
for (let project of projects) {
|
|
|
|
project.trashed = false
|
|
|
|
_untrashProject(project)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.leaveProjects = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
_deleteOrLeaveProjectsLocally(projects)
|
|
|
|
for (let project of projects) {
|
|
|
|
_leaveProject(project)
|
2019-04-17 06:11:32 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
2019-04-17 06:11:32 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.deleteProjects = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
_deleteOrLeaveProjectsLocally(projects)
|
|
|
|
for (let project of projects) {
|
|
|
|
_deleteProject(project)
|
|
|
|
}
|
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.leaveOrDeleteProjects = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
_deleteOrLeaveProjectsLocally(projects)
|
|
|
|
for (let project of projects) {
|
|
|
|
if (project.accessLevel === 'owner') {
|
2019-11-25 10:41:12 -05:00
|
|
|
_deleteProject(project)
|
2020-05-19 05:02:56 -04:00
|
|
|
} else {
|
|
|
|
_leaveProject(project)
|
2019-11-25 10:41:12 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// Actual interaction with the backend---we could move this into a service
|
2021-04-14 09:17:21 -04:00
|
|
|
const _archiveProject = function (project) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return queuedHttp({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/project/${project.id}/archive`,
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-CSRF-Token': window.csrfToken,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const _unarchiveProject = function (project) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return queuedHttp({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `/project/${project.id}/archive`,
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-CSRF-Token': window.csrfToken,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const _trashProject = function (project) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return queuedHttp({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/project/${project.id}/trash`,
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-CSRF-Token': window.csrfToken,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const _untrashProject = function (project) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return queuedHttp({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `/project/${project.id}/trash`,
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-CSRF-Token': window.csrfToken,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const _leaveProject = function (project) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return queuedHttp({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/project/${project.id}/leave`,
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-CSRF-Token': window.csrfToken,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const _deleteProject = function (project) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return queuedHttp({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `/project/${project.id}`,
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-CSRF-Token': window.csrfToken,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const _deleteOrLeaveProjectsLocally = function (projects) {
|
2020-05-19 05:02:56 -04:00
|
|
|
const projectIds = projects.map(p => p.id)
|
|
|
|
for (let tag of $scope.tags || []) {
|
|
|
|
$scope._removeProjectIdsFromTagArray(tag, projectIds)
|
2019-11-25 10:41:12 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
for (let project of projects || []) {
|
|
|
|
$scope._removeProjectFromList(project)
|
2019-11-25 10:41:12 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.getValueForCurrentPredicate = function (project) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if ($scope.predicate === 'ownerName') {
|
|
|
|
return ProjectListService.getOwnerName(project)
|
|
|
|
} else {
|
|
|
|
return project[$scope.predicate]
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.openUploadProjectModal = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
$modal.open({
|
|
|
|
templateUrl: 'uploadProjectModalTemplate',
|
2021-04-27 03:52:58 -04:00
|
|
|
controller: 'UploadProjectModalController',
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.downloadSelectedProjects = () =>
|
|
|
|
$scope.downloadProjectsById($scope.getSelectedProjectIds())
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.downloadProjectsById = function (projectIds) {
|
2020-05-19 05:02:56 -04:00
|
|
|
let path
|
|
|
|
eventTracking.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`
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return (window.location = path)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const markTagAsSelected = id => {
|
|
|
|
for (let tag of $scope.tags) {
|
|
|
|
if (tag._id === id) {
|
|
|
|
tag.selected = true
|
|
|
|
} else {
|
|
|
|
tag.selected = false
|
2019-06-21 09:45:43 -04:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2019-06-21 09:45:43 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const storedUIOpts = JSON.parse(localStorage('project_list'))
|
2019-06-21 09:45:43 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (storedUIOpts && storedUIOpts.filter) {
|
|
|
|
if (storedUIOpts.filter === 'tag' && storedUIOpts.selectedTagId) {
|
|
|
|
markTagAsSelected(storedUIOpts.selectedTagId)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.setFilter(storedUIOpts.filter)
|
|
|
|
} else {
|
|
|
|
$scope.updateVisibleProjects()
|
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller(
|
|
|
|
'ProjectListItemController',
|
|
|
|
function ($scope, $modal, queuedHttp, ProjectListService) {
|
|
|
|
$scope.projectLink = function (project) {
|
|
|
|
return `/project/${project.id}`
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.isLinkSharingProject = project => project.source === 'token'
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.hasGenericOwnerName = () => {
|
|
|
|
/* eslint-disable camelcase */
|
|
|
|
const { first_name, last_name, email } = $scope.project.owner
|
|
|
|
return !first_name && !last_name && !email
|
|
|
|
/* eslint-enable camelcase */
|
|
|
|
}
|
2019-01-09 08:24:14 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.getOwnerName = ProjectListService.getOwnerName
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.getUserName = ProjectListService.getUserName
|
2019-05-21 09:28:13 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.isOwner = () =>
|
|
|
|
$scope.project.owner && window.user_id === $scope.project.owner._id
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.$watch('project.selected', function (value) {
|
|
|
|
if (value != null) {
|
|
|
|
$scope.updateSelectedProjects()
|
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.clone = function (e) {
|
|
|
|
e.stopPropagation()
|
|
|
|
$scope.openCloneProjectModal($scope.project)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.download = function (e) {
|
|
|
|
e.stopPropagation()
|
|
|
|
$scope.downloadProjectsById([$scope.project.id])
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.archive = function (e) {
|
|
|
|
e.stopPropagation()
|
|
|
|
$scope.createArchiveProjectsModal([$scope.project]).result.then(() => {
|
|
|
|
$scope.archiveProjects([$scope.project])
|
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.unarchive = function (e) {
|
|
|
|
e.stopPropagation()
|
|
|
|
$scope.unarchiveProjects([$scope.project])
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.trash = function (e) {
|
|
|
|
e.stopPropagation()
|
|
|
|
$scope.createTrashProjectsModal([$scope.project]).result.then(() => {
|
|
|
|
$scope.trashProjects([$scope.project])
|
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.untrash = function (e) {
|
|
|
|
e.stopPropagation()
|
|
|
|
$scope.untrashProjects([$scope.project])
|
|
|
|
}
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.leave = function (e) {
|
|
|
|
e.stopPropagation()
|
|
|
|
$scope.createLeaveProjectsModal([$scope.project]).result.then(() => {
|
|
|
|
$scope.leaveProjects([$scope.project])
|
|
|
|
})
|
|
|
|
}
|
2019-11-25 10:41:12 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.delete = function (e) {
|
|
|
|
e.stopPropagation()
|
|
|
|
$scope.createDeleteProjectsModal([$scope.project]).result.then(() => {
|
|
|
|
$scope.deleteProjects([$scope.project])
|
|
|
|
})
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
)
|