diff --git a/services/web/app/views/project/editor/file-tree-history.pug b/services/web/app/views/project/editor/file-tree-history.pug
index 98a9f17f33..3d45489b2e 100644
--- a/services/web/app/views/project/editor/file-tree-history.pug
+++ b/services/web/app/views/project/editor/file-tree-history.pug
@@ -6,13 +6,9 @@ aside.editor-sidebar.full-size(
.file-tree
.file-tree-inner(
ng-if="rootFolder",
- ng-controller="FileTreeRootFolderController",
ng-class="no-toolbar"
)
- ul.list-unstyled.file-tree-list(
- accept=".entity-name"
- on-drop-callback="onDrop"
- )
+ ul.list-unstyled.file-tree-list
file-entity(
entity="entity",
@@ -46,7 +42,6 @@ script(type='text/ng-template', id='entityListItemTemplate')
.entity(ng-if="entity.type != 'folder'")
.entity-name(
ng-click="select($event)"
- draggable-helper="draggableHelper"
context-menu
data-target="context-menu-{{ entity.id }}"
context-menu-container="body"
@@ -66,9 +61,6 @@ script(type='text/ng-template', id='entityListItemTemplate')
.entity(ng-if="entity.type == 'folder'", ng-controller="FileTreeFolderController")
.entity-name(
ng-click="select($event)"
- draggable-helper="draggableHelper"
- accept=".entity-name"
- on-drop-callback="onDrop"
)
div(
context-menu
@@ -98,8 +90,6 @@ script(type='text/ng-template', id='entityListItemTemplate')
ul.list-unstyled(
ng-if="entity.type == 'folder' && (depth == null || depth < MAX_DEPTH)"
ng-show="expanded"
- accept=".entity-name"
- on-drop-callback="onDrop"
)
file-entity(
entity="child",
@@ -122,77 +112,3 @@ script(type='text/ng-template', id='entityListItemTemplate')
)
span.sr-only
| Your project has hit Overleaf's maximum file depth limit. Files within this folder won't be visible.
-
-script(type='text/ng-template', id='newFolderModalTemplate')
- .modal-header
- h3 #{translate("new_folder")}
- .modal-body
- form(novalidate, name="newFolderForm")
- input.form-control(
- type="text",
- placeholder="Folder Name",
- required,
- ng-model="inputs.name",
- on-enter="create()",
- select-name-on="open",
- valid-file,
- name="name"
- )
- div.alert.alert-danger.row-spaced-small(ng-show="newFolderForm.name.$error.validFile")
- | #{translate('files_cannot_include_invalid_characters')}
- div.alert.alert-danger.row-spaced-small(ng-if="error")
- div(ng-switch="error")
- span(ng-switch-when="already exists") #{translate("file_already_exists")}
- span(ng-switch-default) {{error}}
- .modal-footer
- button.btn.btn-default(
- ng-disabled="state.inflight"
- ng-click="cancel()"
- ) #{translate("cancel")}
- button.btn.btn-primary(
- ng-disabled="newFolderForm.$invalid || state.inflight"
- ng-click="create()"
- )
- span(ng-hide="state.inflight") #{translate("create")}
- span(ng-show="state.inflight") #{translate("creating")}…
-
-script(type='text/ng-template', id='duplicateFileModalTemplate')
- .modal-header
- h3 #{translate("duplicate_file")}
- .modal-body
- p #{translate("file_already_exists_in_this_location", { fileName: "'{{ fileName }}'" })}
- .modal-footer
- button.btn.btn-default(
- ng-click="cancel()"
- ) #{translate("dismiss")}
-
-include ./new-file-modal
-
-script(type='text/ng-template', id='deleteEntityModalTemplate')
- .modal-header
- h3 #{translate("delete")} {{ entity.name }}
- .modal-body
- p !{translate("sure_you_want_to_delete")}
- ul
- li(ng-repeat="entity in entities") {{entity.name}}
- .modal-footer
- button.btn.btn-default(
- ng-disabled="state.inflight"
- ng-click="cancel()"
- ) #{translate("cancel")}
- button.btn.btn-danger(
- ng-disabled="state.inflight"
- ng-click="delete()"
- )
- span(ng-hide="state.inflight") #{translate("delete")}
- span(ng-show="state.inflight") #{translate("deleting")}…
-
-script(type='text/ng-template', id='invalidFileNameModalTemplate')
- .modal-header
- h3 #{translate('invalid_file_name')}
- .modal-body
- p #{translate('files_cannot_include_invalid_characters')}
- .modal-footer
- button.btn.btn-default(
- ng-click="$close()"
- ) #{translate('ok')}
diff --git a/services/web/app/views/project/editor/file-tree-react.pug b/services/web/app/views/project/editor/file-tree-react.pug
index 3e2b2d176d..21372664a2 100644
--- a/services/web/app/views/project/editor/file-tree-react.pug
+++ b/services/web/app/views/project/editor/file-tree-react.pug
@@ -26,9 +26,6 @@ aside.editor-sidebar.full-size(
set-started-free-trial="setStartedFreeTrial"
)
- div(ng-controller="FileTreeController")
- include ./new-file-modal
-
.outline-container(
vertical-resizable-bottom
ng-controller="OutlineController"
diff --git a/services/web/frontend/js/ide/file-tree/FileTreeManager.js b/services/web/frontend/js/ide/file-tree/FileTreeManager.js
index ddb16036bb..7e4d96b1c1 100644
--- a/services/web/frontend/js/ide/file-tree/FileTreeManager.js
+++ b/services/web/frontend/js/ide/file-tree/FileTreeManager.js
@@ -19,12 +19,9 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import './directives/fileEntity'
-import './directives/draggable'
-import './directives/droppable'
import './controllers/FileTreeController'
import './controllers/FileTreeEntityController'
import './controllers/FileTreeFolderController'
-import './controllers/FileTreeRootFolderController'
import '../../features/file-tree/controllers/file-tree-controller'
let FileTreeManager
@@ -482,24 +479,6 @@ export default FileTreeManager = class FileTreeManager {
})
}
- getEntityPath(entity) {
- return this._getEntityPathInFolder(this.$scope.rootFolder, entity)
- }
-
- _getEntityPathInFolder(folder, entity) {
- for (const child of Array.from(folder.children || [])) {
- if (child === entity) {
- return entity.name
- } else if (child.type === 'folder') {
- const path = this._getEntityPathInFolder(child, entity)
- if (path != null) {
- return child.name + '/' + path
- }
- }
- }
- return null
- }
-
getCurrentFolder() {
// Return the root folder if nothing is selected
return (
diff --git a/services/web/frontend/js/ide/file-tree/controllers/FileTreeController.js b/services/web/frontend/js/ide/file-tree/controllers/FileTreeController.js
index 361d7431d2..5bc46bca48 100644
--- a/services/web/frontend/js/ide/file-tree/controllers/FileTreeController.js
+++ b/services/web/frontend/js/ide/file-tree/controllers/FileTreeController.js
@@ -1,630 +1,15 @@
-import _ from 'lodash'
-/* eslint-disable
- camelcase,
- node/handle-callback-err,
- max-len,
- no-return-assign,
- no-unused-vars,
-*/
-// TODO: This file was created by bulk-decaffeinate.
-// Fix any style issues and re-enable lint.
-/*
- * decaffeinate suggestions:
- * DS102: Remove unnecessary code created because of implicit returns
- * DS103: Rewrite code to no longer use __guard__
- * DS207: Consider shorter variations of null checks
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
import App from '../../../base'
-App.controller(
- 'FileTreeController',
- function ($scope, $modal, ide, $rootScope) {
- $scope.openNewDocModal = () => {
- window.dispatchEvent(
- new CustomEvent('file-tree.start-creating', { detail: { mode: 'doc' } })
- )
- }
-
- $scope.openNewFolderModal = () =>
- $modal.open({
- templateUrl: 'newFolderModalTemplate',
- controller: 'NewFolderModalController',
- resolve: {
- parent_folder() {
- return ide.fileTreeManager.getCurrentFolder()
- },
- },
- })
-
- $scope.openUploadFileModal = reactBridgeParentFolderId =>
- $modal.open({
- templateUrl: 'newFileModalTemplate',
- controller: 'NewFileModalController',
- size: 'lg',
- resolve: {
- projectFeatures() {
- return ide.$scope.project.features
- },
- parent_folder() {
- if (reactBridgeParentFolderId) {
- return { id: reactBridgeParentFolderId }
- }
- return ide.fileTreeManager.getCurrentFolder()
- },
- type() {
- return 'upload'
- },
- userFeatures() {
- return ide.$scope.user.features
- },
- },
- })
-
- $scope.orderByFoldersFirst = function (entity) {
- if ((entity != null ? entity.type : undefined) === 'folder') {
- return '0'
- }
- return '1'
- }
-
- $scope.startRenamingSelected = () => $scope.$broadcast('rename:selected')
-
- return ($scope.openDeleteModalForSelected = () =>
- $scope.$broadcast('delete:selected'))
- }
-)
-
-App.controller(
- 'NewFolderModalController',
- function ($scope, ide, $modalInstance, $timeout, parent_folder) {
- $scope.inputs = { name: 'name' }
- $scope.state = { inflight: false }
-
- $modalInstance.opened.then(() =>
- $timeout(() => $scope.$broadcast('open'), 200)
+App.controller('FileTreeController', function ($scope) {
+ $scope.openNewDocModal = () => {
+ window.dispatchEvent(
+ new CustomEvent('file-tree.start-creating', { detail: { mode: 'doc' } })
)
-
- $scope.create = function () {
- const { name } = $scope.inputs
- if (name == null || name.length === 0) {
- return
- }
- $scope.state.inflight = true
- return ide.fileTreeManager
- .createFolder(name, $scope.parent_folder)
- .then(function () {
- $scope.state.inflight = false
- return $modalInstance.dismiss('done')
- })
- .catch(function (response) {
- const { data } = response
- $scope.error = data
- return ($scope.state.inflight = false)
- })
- }
-
- return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
}
-)
-App.controller(
- 'DuplicateFileModalController',
- function ($scope, $modalInstance, fileName) {
- $scope.fileName = fileName
- $scope.cancel = () => $modalInstance.dismiss('cancel')
- }
-)
-
-App.controller(
- 'NewFileModalController',
- function (
- $scope,
- ide,
- type,
- parent_folder,
- $modalInstance,
- eventTracking,
- projectFeatures,
- userFeatures
- ) {
- $scope.file_count = ide.fileTreeManager.getFullCount()
- $scope.type = type
- $scope.parent_folder = parent_folder
- $scope.state = {
- inflight: false,
- valid: true,
+ $scope.orderByFoldersFirst = function (entity) {
+ if ((entity != null ? entity.type : undefined) === 'folder') {
+ return '0'
}
- $scope.cancel = () => $modalInstance.dismiss('cancel')
- $scope.create = () => $scope.$broadcast('create')
-
- const hasMendeleyFeature =
- (projectFeatures && projectFeatures.references) ||
- (projectFeatures && projectFeatures.mendeley) ||
- (userFeatures && userFeatures.references) ||
- (userFeatures && userFeatures.mendeley)
-
- const hasZoteroFeature =
- (projectFeatures && projectFeatures.references) ||
- (projectFeatures && projectFeatures.zotero) ||
- (userFeatures && userFeatures.references) ||
- (userFeatures && userFeatures.zotero)
-
- $scope.$watch('type', function () {
- if ($scope.type === 'mendeley' && !hasMendeleyFeature) {
- eventTracking.send(
- 'subscription-funnel',
- 'editor-click-feature',
- $scope.type
- )
- }
- if ($scope.type === 'zotero' && !hasZoteroFeature) {
- eventTracking.send(
- 'subscription-funnel',
- 'editor-click-feature',
- $scope.type
- )
- }
- })
- $scope.$on('done', (e, opts = {}) => {
- const isBibFile = opts.name && /^.*\.bib$/.test(opts.name)
- if (opts.shouldReindexReferences || isBibFile) {
- ide.$scope.$emit('references:should-reindex', {})
- }
- $modalInstance.dismiss('done')
- })
+ return '1'
}
-)
-
-App.controller('NewDocModalController', function ($scope, ide, $timeout) {
- $scope.inputs = { name: 'name.tex' }
-
- $timeout(() => $scope.$broadcast('open'), 200)
-
- return $scope.$on('create', function () {
- const { name } = $scope.inputs
- if (name == null || name.length === 0) {
- return
- }
- $scope.state.inflight = true
- return ide.fileTreeManager
- .createDoc(name, $scope.parent_folder)
- .then(function () {
- $scope.state.inflight = false
- return $scope.$emit('done')
- })
- .catch(function (response) {
- const { data } = response
- $scope.error = data
- $scope.state.inflight = false
- })
- .finally(function () {
- if (!$scope.$$phase) {
- $scope.$apply()
- }
- })
- })
})
-
-App.controller(
- 'UploadFileModalController',
- function ($scope, $rootScope, ide, $timeout, $window) {
- $scope.parent_folder_id =
- $scope.parent_folder != null ? $scope.parent_folder.id : undefined
- $scope.project_id = ide.project_id
- $scope.tooManyFiles = false
- $scope.rateLimitHit = false
- $scope.secondsToRedirect = 10
- $scope.notLoggedIn = false
- $scope.conflicts = []
- $scope.control = {}
-
- const needToLogBackIn = function () {
- $scope.notLoggedIn = true
- var decreseTimeout = () =>
- $timeout(function () {
- if ($scope.secondsToRedirect === 0) {
- return ($window.location.href = `/login?redir=/project/${ide.project_id}`)
- } else {
- decreseTimeout()
- return ($scope.secondsToRedirect = $scope.secondsToRedirect - 1)
- }
- }, 1000)
-
- return decreseTimeout()
- }
-
- $scope.max_files = 40
- $scope.onComplete = (error, name, response) =>
- $timeout(function () {
- uploadCount--
- if (response.success) {
- $rootScope.$broadcast('file:upload:complete', response)
- }
- if (uploadCount === 0 && response != null && response.success) {
- return $scope.$emit('done', { name: name })
- }
- }, 250)
-
- $scope.onValidateBatch = function (files) {
- if (files.length > $scope.max_files) {
- $timeout(() => ($scope.tooManyFiles = true), 1)
- return false
- } else {
- return true
- }
- }
-
- $scope.onError = function (id, name, reason) {
- console.log(id, name, reason)
- if (reason.indexOf('429') !== -1) {
- return ($scope.rateLimitHit = true)
- } else if (reason.indexOf('403') !== -1) {
- return needToLogBackIn()
- }
- }
-
- let _uploadTimer = null
- const uploadIfNoConflicts = function () {
- if ($scope.conflicts.length === 0) {
- return $scope.doUpload()
- }
- }
-
- var uploadCount = 0
- $scope.onSubmit = function (id, name) {
- uploadCount++
- if (ide.fileTreeManager.existsInFolder($scope.parent_folder_id, name)) {
- $scope.conflicts.push(name)
- $scope.$apply()
- }
- if (_uploadTimer == null) {
- _uploadTimer = setTimeout(function () {
- _uploadTimer = null
- return uploadIfNoConflicts()
- }, 0)
- }
- return true
- }
-
- $scope.onCancel = function (id, name) {
- uploadCount--
- const index = $scope.conflicts.indexOf(name)
- if (index > -1) {
- $scope.conflicts.splice(index, 1)
- }
- $scope.$apply()
- return uploadIfNoConflicts()
- }
-
- return ($scope.doUpload = () =>
- __guard__($scope.control != null ? $scope.control.q : undefined, x =>
- x.uploadStoredFiles()
- ))
- }
-)
-
-App.controller(
- 'ProjectLinkedFileModalController',
- function ($scope, ide, $timeout) {
- $scope.data = {
- projects: null, // or []
- selectedProjectId: null,
- projectEntities: null, // or []
- projectOutputFiles: null, // or []
- selectedProjectEntity: null,
- selectedProjectOutputFile: null,
- buildId: null,
- name: null,
- }
- $scope.state.inFlight = {
- projects: false,
- entities: false,
- compile: false,
- }
- $scope.state.isOutputFilesMode = false
- $scope.state.error = false
-
- $scope.$watch('data.selectedProjectId', function (newVal, oldVal) {
- if (!newVal) {
- return
- }
- $scope.data.selectedProjectEntity = null
- $scope.data.selectedProjectOutputFile = null
- if ($scope.state.isOutputFilesMode) {
- return $scope.compileProjectAndGetOutputFiles(
- $scope.data.selectedProjectId
- )
- } else {
- return $scope.getProjectEntities($scope.data.selectedProjectId)
- }
- })
-
- $scope.$watch('state.isOutputFilesMode', function (newVal, oldVal) {
- if (!newVal && !oldVal) {
- return
- }
- $scope.data.selectedProjectOutputFile = null
- if (newVal === true) {
- return $scope.compileProjectAndGetOutputFiles(
- $scope.data.selectedProjectId
- )
- } else {
- return $scope.getProjectEntities($scope.data.selectedProjectId)
- }
- })
-
- // auto-set filename based on selected file
- $scope.$watch('data.selectedProjectEntity', function (newVal, oldVal) {
- if (!newVal) {
- return
- }
- const fileName = newVal.split('/').reverse()[0]
- if (fileName) {
- $scope.data.name = fileName
- }
- })
-
- // auto-set filename based on selected file
- $scope.$watch('data.selectedProjectOutputFile', function (newVal, oldVal) {
- if (!newVal) {
- return
- }
- if (newVal === 'output.pdf') {
- const project = _.find(
- $scope.data.projects,
- p => p._id === $scope.data.selectedProjectId
- )
- $scope.data.name =
- (project != null ? project.name : undefined) != null
- ? `${project.name}.pdf`
- : 'output.pdf'
- } else {
- const fileName = newVal.split('/').reverse()[0]
- if (fileName) {
- $scope.data.name = fileName
- }
- }
- })
-
- const _setInFlight = type => ($scope.state.inFlight[type] = true)
-
- const _reset = function (opts) {
- const isError = opts.err === true
- const { inFlight } = $scope.state
- inFlight.projects = inFlight.entities = inFlight.compile = false
- $scope.state.inflight = false
- return ($scope.state.error = isError)
- }
-
- $scope.toggleOutputFilesMode = function () {
- if (!$scope.data.selectedProjectId) {
- return
- }
- return ($scope.state.isOutputFilesMode = !$scope.state.isOutputFilesMode)
- }
-
- $scope.shouldEnableProjectSelect = function () {
- const { state, data } = $scope
- return !state.inFlight.projects && data.projects
- }
-
- $scope.hasNoProjects = function () {
- const { state, data } = $scope
- return (
- !state.inFlight.projects &&
- (data.projects == null || data.projects.length === 0)
- )
- }
-
- $scope.shouldEnableProjectEntitySelect = function () {
- const { state, data } = $scope
- return (
- !state.inFlight.projects &&
- !state.inFlight.entities &&
- data.projects &&
- data.selectedProjectId
- )
- }
-
- $scope.shouldEnableProjectOutputFileSelect = function () {
- const { state, data } = $scope
- return (
- !state.inFlight.projects &&
- !state.inFlight.compile &&
- data.projects &&
- data.selectedProjectId
- )
- }
-
- const validate = function () {
- const { state } = $scope
- const { data } = $scope
- $scope.state.valid =
- !state.inFlight.projects &&
- !state.inFlight.entities &&
- data.projects &&
- data.selectedProjectId &&
- ((!$scope.state.isOutputFilesMode &&
- data.projectEntities &&
- data.selectedProjectEntity) ||
- ($scope.state.isOutputFilesMode &&
- data.projectOutputFiles &&
- data.selectedProjectOutputFile)) &&
- data.name
- }
- $scope.$watch('state', validate, true)
- $scope.$watch('data', validate, true)
-
- $scope.getUserProjects = function () {
- _setInFlight('projects')
- return ide.$http
- .get('/user/projects', {
- _csrf: window.csrfToken,
- })
- .then(function (resp) {
- $scope.data.projectEntities = null
- $scope.data.projects = resp.data.projects.filter(
- p => p._id !== ide.project_id
- )
- return _reset({ err: false })
- })
- .catch(err => _reset({ err: true }))
- }
-
- $scope.getProjectEntities = project_id => {
- _setInFlight('entities')
- return ide.$http
- .get(`/project/${project_id}/entities`, {
- _csrf: window.csrfToken,
- })
- .then(function (resp) {
- if ($scope.data.selectedProjectId === resp.data.project_id) {
- $scope.data.projectEntities = resp.data.entities
- return _reset({ err: false })
- }
- })
- .catch(err => _reset({ err: true }))
- }
-
- $scope.compileProjectAndGetOutputFiles = project_id => {
- _setInFlight('compile')
- return ide.$http
- .post(`/project/${project_id}/compile`, {
- check: 'silent',
- draft: false,
- incrementalCompilesEnabled: false,
- _csrf: window.csrfToken,
- })
- .then(function (resp) {
- if (resp.data.status === 'success') {
- const filteredFiles = resp.data.outputFiles.filter(f =>
- f.path.match(/.*\.(pdf|png|jpeg|jpg|gif)/)
- )
- $scope.data.projectOutputFiles = filteredFiles
- $scope.data.buildId = __guard__(
- filteredFiles != null ? filteredFiles[0] : undefined,
- x => x.build
- )
- console.log('>> build_id', $scope.data.buildId)
- return _reset({ err: false })
- } else {
- $scope.data.projectOutputFiles = null
- return _reset({ err: true })
- }
- })
- .catch(function (err) {
- console.error(err)
- return _reset({ err: true })
- })
- }
-
- $scope.init = () => $scope.getUserProjects()
- $timeout($scope.init, 0)
-
- return $scope.$on('create', function () {
- let payload, provider
- const projectId = $scope.data.selectedProjectId
- const { name } = $scope.data
- if ($scope.state.isOutputFilesMode) {
- provider = 'project_output_file'
- payload = {
- source_project_id: projectId,
- source_output_file_path: $scope.data.selectedProjectOutputFile,
- build_id: $scope.data.buildId,
- }
- } else {
- provider = 'project_file'
- payload = {
- source_project_id: projectId,
- source_entity_path: $scope.data.selectedProjectEntity,
- }
- }
- _setInFlight('create')
- ide.fileTreeManager
- .createLinkedFile(name, $scope.parent_folder, provider, payload)
- .then(function () {
- _reset({ err: false })
- return $scope.$emit('done', { name: name })
- })
- .catch(function (response) {
- const { data } = response
- $scope.error = data
- })
- .finally(function () {
- if (!$scope.$$phase) {
- $scope.$apply()
- }
- })
- })
- }
-)
-
-export default App.controller(
- 'UrlLinkedFileModalController',
- function ($scope, ide, $timeout) {
- $scope.inputs = {
- name: '',
- url: '',
- }
- $scope.nameChangedByUser = false
-
- $timeout(() => $scope.$broadcast('open'), 200)
-
- const validate = function () {
- const { name, url } = $scope.inputs
- if (name == null || name.length === 0) {
- return ($scope.state.valid = false)
- } else if (url == null || url.length === 0) {
- return ($scope.state.valid = false)
- } else {
- return ($scope.state.valid = true)
- }
- }
- $scope.$watch('inputs.name', validate)
- $scope.$watch('inputs.url', validate)
-
- $scope.$watch('inputs.url', function (url) {
- if (url != null && url !== '' && !$scope.nameChangedByUser) {
- url = url.replace('://', '') // Ignore http:// etc
- const parts = url.split('/').reverse()
- if (parts.length > 1) {
- // Wait for at one /
- return ($scope.inputs.name = parts[0])
- }
- }
- })
-
- return $scope.$on('create', function () {
- const { name, url } = $scope.inputs
- if (name == null || name.length === 0) {
- return
- }
- if (url == null || url.length === 0) {
- return
- }
- $scope.state.inflight = true
- return ide.fileTreeManager
- .createLinkedFile(name, $scope.parent_folder, 'url', { url })
- .then(function () {
- $scope.state.inflight = false
- return $scope.$emit('done', { name: name })
- })
- .catch(function (response) {
- const { data } = response
- $scope.error = data
- return ($scope.state.inflight = false)
- })
- .finally(function () {
- if (!$scope.$$phase) {
- $scope.$apply()
- }
- })
- })
- }
-)
-
-function __guard__(value, transform) {
- return typeof value !== 'undefined' && value !== null
- ? transform(value)
- : undefined
-}
diff --git a/services/web/frontend/js/ide/file-tree/controllers/FileTreeEntityController.js b/services/web/frontend/js/ide/file-tree/controllers/FileTreeEntityController.js
index 5806939e20..9f39767db8 100644
--- a/services/web/frontend/js/ide/file-tree/controllers/FileTreeEntityController.js
+++ b/services/web/frontend/js/ide/file-tree/controllers/FileTreeEntityController.js
@@ -1,17 +1,3 @@
-/* eslint-disable
- chai-friendly/no-unused-expressions,
- max-len,
- no-return-assign,
-*/
-// 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
- */
import App from '../../../base'
import iconTypeFromName from '../util/iconTypeFromName'
App.controller(
@@ -23,7 +9,7 @@ App.controller(
if (e.ctrlKey || e.metaKey) {
e.stopPropagation()
const initialMultiSelectCount = ide.fileTreeManager.multiSelectedCount()
- ide.fileTreeManager.toggleMultiSelectEntity($scope.entity) === 0
+ ide.fileTreeManager.toggleMultiSelectEntity($scope.entity)
if (initialMultiSelectCount === 0) {
// On first multi selection, also include the current active/open file.
return ide.fileTreeManager.multiSelectSelectedEntity()
@@ -61,101 +47,6 @@ App.controller(
)
}
- $scope.draggableHelper = function () {
- if (ide.fileTreeManager.multiSelectedCount() > 0) {
- return $(
- `${ide.fileTreeManager.multiSelectedCount()} Files`
- )
- } else {
- return $(`${$scope.entity.name}`)
- }
- }
-
- $scope.inputs = { name: $scope.entity.name }
-
- $scope.startRenaming = () => ($scope.entity.renaming = true)
-
- let invalidModalShowing = false
- $scope.finishRenaming = function () {
- // avoid double events when blur and on-enter fire together
- if (!$scope.entity.renaming) {
- return
- }
-
- const { name } = $scope.inputs
-
- // validator will set name to undefined for invalid filenames
- if (name == null) {
- // Showing the modal blurs the rename box which calls us again
- // so track this with the invalidModalShowing flag
- if (invalidModalShowing) {
- return
- }
- invalidModalShowing = true
- const modal = $modal.open({
- templateUrl: 'invalidFileNameModalTemplate',
- })
- modal.result.then(() => (invalidModalShowing = false))
- return
- }
-
- delete $scope.entity.renaming
- if (name == null || name.length === 0) {
- $scope.inputs.name = $scope.entity.name
- return
- }
- return ide.fileTreeManager.renameEntity($scope.entity, name)
- }
-
- $scope.$on('rename:selected', function () {
- if ($scope.entity.selected) {
- return $scope.startRenaming()
- }
- })
-
- $scope.openDeleteModal = function () {
- let entities
- if (ide.fileTreeManager.multiSelectedCount() > 0) {
- entities = ide.fileTreeManager.getMultiSelectedEntityChildNodes()
- } else {
- entities = [$scope.entity]
- }
- return $modal.open({
- templateUrl: 'deleteEntityModalTemplate',
- controller: 'DeleteEntityModalController',
- resolve: {
- entities() {
- return entities
- },
- },
- })
- }
-
- $scope.$on('delete:selected', function () {
- if ($scope.entity.selected) {
- return $scope.openDeleteModal()
- }
- })
-
- return ($scope.iconTypeFromName = iconTypeFromName)
- }
-)
-
-export default App.controller(
- 'DeleteEntityModalController',
- function ($scope, ide, $modalInstance, entities) {
- $scope.state = { inflight: false }
-
- $scope.entities = entities
-
- $scope.delete = function () {
- $scope.state.inflight = true
- for (const entity of Array.from($scope.entities)) {
- ide.fileTreeManager.deleteEntity(entity)
- }
- return $modalInstance.close()
- }
-
- return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
+ $scope.iconTypeFromName = iconTypeFromName
}
)
diff --git a/services/web/frontend/js/ide/file-tree/controllers/FileTreeFolderController.js b/services/web/frontend/js/ide/file-tree/controllers/FileTreeFolderController.js
index 8f1e13961f..838205bcd3 100644
--- a/services/web/frontend/js/ide/file-tree/controllers/FileTreeFolderController.js
+++ b/services/web/frontend/js/ide/file-tree/controllers/FileTreeFolderController.js
@@ -1,17 +1,3 @@
-/* eslint-disable
- camelcase,
- max-len,
- no-return-assign,
-*/
-// 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
- */
import App from '../../../base'
export default App.controller(
@@ -33,102 +19,5 @@ export default App.controller(
$scope._storeCurrentStateInLocalStorage = function () {
localStorage(`folder.${$scope.entity.id}.expanded`, $scope.expanded)
}
-
- $scope.onDrop = function (events, ui) {
- let entities
- if (ide.fileTreeManager.multiSelectedCount()) {
- entities = ide.fileTreeManager.getMultiSelectedEntityChildNodes()
- } else {
- entities = [$(ui.draggable).scope().entity]
- }
-
- const ids = $scope.entity.children.map(entity => entity.id)
-
- for (const dropped_entity of Array.from(entities)) {
- if (!ids.includes(dropped_entity.id)) {
- try {
- ide.fileTreeManager.moveEntity(dropped_entity, $scope.entity)
- } catch (err) {
- $modal.open({
- templateUrl: 'duplicateFileModalTemplate',
- controller: 'DuplicateFileModalController',
- resolve: {
- fileName() {
- return dropped_entity.name
- },
- },
- })
- }
- }
- }
- $scope.$digest()
- // clear highlight explicitly
- return $('.file-tree-inner .droppable-hover').removeClass(
- 'droppable-hover'
- )
- }
-
- $scope.orderByFoldersFirst = function (entity) {
- // We need this here as well as in FileTreeController
- // since the file-entity diretive creates a new scope
- // that doesn't inherit from previous scopes.
- if ((entity != null ? entity.type : undefined) === 'folder') {
- return '0'
- }
- return '1'
- }
-
- $scope.openNewDocModal = () =>
- $modal.open({
- templateUrl: 'newFileModalTemplate',
- controller: 'NewFileModalController',
- size: 'lg',
- resolve: {
- parent_folder() {
- return $scope.entity
- },
- projectFeatures() {
- return ide.$scope.project.features
- },
- type() {
- return 'doc'
- },
- userFeatures() {
- return ide.$scope.user.features
- },
- },
- })
-
- $scope.openNewFolderModal = () =>
- $modal.open({
- templateUrl: 'newFolderModalTemplate',
- controller: 'NewFolderModalController',
- resolve: {
- parent_folder() {
- return $scope.entity
- },
- },
- })
-
- return ($scope.openUploadFileModal = () =>
- $modal.open({
- templateUrl: 'newFileModalTemplate',
- controller: 'NewFileModalController',
- size: 'lg',
- resolve: {
- parent_folder() {
- return $scope.entity
- },
- projectFeatures() {
- return ide.$scope.project.features
- },
- type() {
- return 'upload'
- },
- userFeatures() {
- return ide.$scope.user.features
- },
- },
- }))
}
)
diff --git a/services/web/frontend/js/ide/file-tree/controllers/FileTreeRootFolderController.js b/services/web/frontend/js/ide/file-tree/controllers/FileTreeRootFolderController.js
deleted file mode 100644
index 2f49b6513f..0000000000
--- a/services/web/frontend/js/ide/file-tree/controllers/FileTreeRootFolderController.js
+++ /dev/null
@@ -1,54 +0,0 @@
-/* eslint-disable
- camelcase,
- max-len,
- no-return-assign,
-*/
-// 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
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
-import App from '../../../base'
-
-export default App.controller(
- 'FileTreeRootFolderController',
- function ($scope, $modal, ide) {
- const { rootFolder } = $scope
- return ($scope.onDrop = function (events, ui) {
- let entities
- if (ide.fileTreeManager.multiSelectedCount()) {
- entities = ide.fileTreeManager.getMultiSelectedEntityChildNodes()
- } else {
- entities = [$(ui.draggable).scope().entity]
- }
-
- const ids = rootFolder.children.map(entity => entity.id)
-
- for (const dropped_entity of Array.from(entities)) {
- if (!ids.includes(dropped_entity.id)) {
- try {
- ide.fileTreeManager.moveEntity(dropped_entity, rootFolder)
- } catch (err) {
- $modal.open({
- templateUrl: 'duplicateFileModalTemplate',
- controller: 'DuplicateFileModalController',
- resolve: {
- fileName() {
- return dropped_entity.name
- },
- },
- })
- }
- }
- }
- $scope.$digest()
- // clear highlight explicitly
- return $('.file-tree-inner .droppable-hover').removeClass(
- 'droppable-hover'
- )
- })
- }
-)
diff --git a/services/web/frontend/js/ide/file-tree/directives/draggable.js b/services/web/frontend/js/ide/file-tree/directives/draggable.js
deleted file mode 100644
index 2bcf71b535..0000000000
--- a/services/web/frontend/js/ide/file-tree/directives/draggable.js
+++ /dev/null
@@ -1,23 +0,0 @@
-// TODO: This file was created by bulk-decaffeinate.
-// Fix any style issues and re-enable lint.
-/*
- * decaffeinate suggestions:
- * DS102: Remove unnecessary code created because of implicit returns
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
-import App from '../../../base'
-
-export default App.directive('draggable', () => ({
- link(scope, element, attrs) {
- return scope.$watch(attrs.draggable, function (draggable) {
- if (draggable) {
- return element.draggable({
- delay: 250,
- opacity: 0.95,
- scroll: true,
- helper: scope.$eval(attrs.draggableHelper),
- })
- }
- })
- },
-}))
diff --git a/services/web/frontend/js/ide/file-tree/directives/droppable.js b/services/web/frontend/js/ide/file-tree/directives/droppable.js
deleted file mode 100644
index cc1c4b96b6..0000000000
--- a/services/web/frontend/js/ide/file-tree/directives/droppable.js
+++ /dev/null
@@ -1,24 +0,0 @@
-// TODO: This file was created by bulk-decaffeinate.
-// Fix any style issues and re-enable lint.
-/*
- * decaffeinate suggestions:
- * DS102: Remove unnecessary code created because of implicit returns
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
-import App from '../../../base'
-
-export default App.directive('droppable', () => ({
- link(scope, element, attrs) {
- return scope.$watch(attrs.droppable, function (droppable) {
- if (droppable) {
- return element.droppable({
- greedy: true,
- hoverClass: 'droppable-hover',
- tolerance: 'pointer',
- accept: attrs.accept,
- drop: scope.$eval(attrs.onDropCallback),
- })
- }
- })
- },
-}))