2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
2015-07-17 11:30:04 -04:00
|
|
|
App.controller "FileTreeController", ["$scope", "$modal", "ide", "$rootScope", ($scope, $modal, ide, $rootScope) ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.openNewDocModal = () ->
|
|
|
|
$modal.open(
|
|
|
|
templateUrl: "newDocModalTemplate"
|
|
|
|
controller: "NewDocModalController"
|
|
|
|
resolve: {
|
|
|
|
parent_folder: () -> ide.fileTreeManager.getCurrentFolder()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.openNewFolderModal = () ->
|
|
|
|
$modal.open(
|
|
|
|
templateUrl: "newFolderModalTemplate"
|
|
|
|
controller: "NewFolderModalController"
|
|
|
|
resolve: {
|
|
|
|
parent_folder: () -> ide.fileTreeManager.getCurrentFolder()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.openUploadFileModal = () ->
|
|
|
|
$modal.open(
|
|
|
|
templateUrl: "uploadFileModalTemplate"
|
|
|
|
controller: "UploadFileModalController"
|
|
|
|
scope: $scope
|
|
|
|
resolve: {
|
|
|
|
parent_folder: () -> ide.fileTreeManager.getCurrentFolder()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.orderByFoldersFirst = (entity) ->
|
2015-04-14 12:05:13 -04:00
|
|
|
return '0' if entity?.type == "folder"
|
2014-07-08 07:02:26 -04:00
|
|
|
return '1'
|
|
|
|
|
|
|
|
$scope.startRenamingSelected = () ->
|
|
|
|
$scope.$broadcast "rename:selected"
|
|
|
|
|
|
|
|
$scope.openDeleteModalForSelected = () ->
|
|
|
|
$scope.$broadcast "delete:selected"
|
|
|
|
]
|
|
|
|
|
|
|
|
App.controller "NewDocModalController", [
|
|
|
|
"$scope", "ide", "$modalInstance", "$timeout", "parent_folder",
|
|
|
|
($scope, ide, $modalInstance, $timeout, parent_folder) ->
|
2016-09-21 11:31:02 -04:00
|
|
|
$scope.validFileRegex = ide.validFileRegex
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.inputs =
|
|
|
|
name: "name.tex"
|
|
|
|
$scope.state =
|
|
|
|
inflight: false
|
|
|
|
|
|
|
|
$modalInstance.opened.then () ->
|
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "open"
|
|
|
|
, 200
|
|
|
|
|
|
|
|
$scope.create = () ->
|
2015-03-02 07:46:02 -05:00
|
|
|
name = $scope.inputs.name
|
|
|
|
if !name? or name.length == 0
|
|
|
|
return
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.state.inflight = true
|
|
|
|
ide.fileTreeManager
|
2015-03-02 07:46:02 -05:00
|
|
|
.createDoc(name, parent_folder)
|
2016-02-29 08:05:17 -05:00
|
|
|
.error (e)->
|
|
|
|
$scope.error = e
|
2014-07-08 07:02:26 -04:00
|
|
|
.success () ->
|
|
|
|
$scope.state.inflight = false
|
|
|
|
$modalInstance.close()
|
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss('cancel')
|
|
|
|
]
|
|
|
|
|
|
|
|
App.controller "NewFolderModalController", [
|
|
|
|
"$scope", "ide", "$modalInstance", "$timeout", "parent_folder",
|
|
|
|
($scope, ide, $modalInstance, $timeout, parent_folder) ->
|
2016-09-21 11:31:02 -04:00
|
|
|
$scope.validFileRegex = ide.validFileRegex
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.inputs =
|
|
|
|
name: "name"
|
|
|
|
$scope.state =
|
|
|
|
inflight: false
|
|
|
|
|
|
|
|
$modalInstance.opened.then () ->
|
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "open"
|
|
|
|
, 200
|
|
|
|
|
|
|
|
$scope.create = () ->
|
2015-03-02 07:46:02 -05:00
|
|
|
name = $scope.inputs.name
|
|
|
|
if !name? or name.length == 0
|
|
|
|
return
|
|
|
|
$scope.state.inflight = true
|
2014-07-08 07:02:26 -04:00
|
|
|
ide.fileTreeManager
|
2015-03-02 07:46:02 -05:00
|
|
|
.createFolder(name, parent_folder)
|
2016-02-29 08:05:17 -05:00
|
|
|
.error (e)->
|
|
|
|
$scope.error = e
|
2017-03-31 05:30:28 -04:00
|
|
|
$scope.state.inflight = false
|
2014-07-08 07:02:26 -04:00
|
|
|
.success () ->
|
|
|
|
$scope.state.inflight = false
|
|
|
|
$modalInstance.close()
|
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss('cancel')
|
|
|
|
]
|
|
|
|
|
|
|
|
App.controller "UploadFileModalController", [
|
2017-06-08 10:12:18 -04:00
|
|
|
"$scope", "$rootScope", "ide", "$modalInstance", "$timeout", "parent_folder", "$window"
|
|
|
|
($scope, $rootScope, ide, $modalInstance, $timeout, parent_folder, $window) ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.parent_folder_id = parent_folder?.id
|
2015-12-01 07:55:35 -05:00
|
|
|
$scope.tooManyFiles = false
|
2015-12-01 08:08:49 -05:00
|
|
|
$scope.rateLimitHit = false
|
2015-12-02 10:40:14 -05:00
|
|
|
$scope.secondsToRedirect = 10
|
|
|
|
$scope.notLoggedIn = false
|
2016-02-24 11:35:05 -05:00
|
|
|
$scope.conflicts = []
|
|
|
|
$scope.control = {}
|
2015-12-02 10:40:14 -05:00
|
|
|
|
|
|
|
needToLogBackIn = ->
|
|
|
|
$scope.notLoggedIn = true
|
|
|
|
decreseTimeout = ->
|
|
|
|
$timeout (() ->
|
|
|
|
if $scope.secondsToRedirect == 0
|
|
|
|
$window.location.href = "/login?redir=/project/#{ide.project_id}"
|
|
|
|
else
|
|
|
|
decreseTimeout()
|
|
|
|
$scope.secondsToRedirect = $scope.secondsToRedirect - 1
|
|
|
|
), 1000
|
|
|
|
|
|
|
|
decreseTimeout()
|
|
|
|
|
2015-12-07 11:50:09 -05:00
|
|
|
$scope.max_files = 40
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.onComplete = (error, name, response) ->
|
|
|
|
$timeout (() ->
|
|
|
|
uploadCount--
|
2017-06-08 10:12:18 -04:00
|
|
|
if response.success
|
2017-06-08 10:55:17 -04:00
|
|
|
$rootScope.$broadcast 'file:upload:complete', response
|
2014-07-08 07:02:26 -04:00
|
|
|
if uploadCount == 0 and response? and response.success
|
|
|
|
$modalInstance.close("done")
|
|
|
|
), 250
|
|
|
|
|
2015-12-01 07:55:35 -05:00
|
|
|
$scope.onValidateBatch = (files)->
|
|
|
|
if files.length > $scope.max_files
|
|
|
|
$timeout (() ->
|
|
|
|
$scope.tooManyFiles = true
|
|
|
|
), 1
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
return true
|
|
|
|
|
2015-12-01 08:08:49 -05:00
|
|
|
$scope.onError = (id, name, reason)->
|
2015-12-02 10:40:14 -05:00
|
|
|
console.log(id, name, reason)
|
2015-12-01 08:08:49 -05:00
|
|
|
if reason.indexOf("429") != -1
|
|
|
|
$scope.rateLimitHit = true
|
2015-12-02 10:40:14 -05:00
|
|
|
else if reason.indexOf("403") != -1
|
|
|
|
needToLogBackIn()
|
|
|
|
|
2016-02-24 11:35:05 -05:00
|
|
|
_uploadTimer = null
|
|
|
|
uploadIfNoConflicts = () ->
|
|
|
|
if $scope.conflicts.length == 0
|
|
|
|
$scope.doUpload()
|
|
|
|
|
|
|
|
uploadCount = 0
|
|
|
|
$scope.onSubmit = (id, name) ->
|
|
|
|
uploadCount++
|
|
|
|
if ide.fileTreeManager.existsInFolder($scope.parent_folder_id, name)
|
|
|
|
$scope.conflicts.push name
|
|
|
|
$scope.$apply()
|
|
|
|
if !_uploadTimer?
|
|
|
|
_uploadTimer = setTimeout () ->
|
|
|
|
_uploadTimer = null
|
|
|
|
uploadIfNoConflicts()
|
|
|
|
, 0
|
|
|
|
return true
|
|
|
|
|
|
|
|
$scope.onCancel = (id, name) ->
|
|
|
|
uploadCount--
|
|
|
|
index = $scope.conflicts.indexOf(name)
|
|
|
|
if index > -1
|
|
|
|
$scope.conflicts.splice(index, 1)
|
|
|
|
$scope.$apply()
|
|
|
|
uploadIfNoConflicts()
|
|
|
|
|
|
|
|
$scope.doUpload = () ->
|
|
|
|
$scope.control?.q?.uploadStoredFiles()
|
2015-12-01 07:55:35 -05:00
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss('cancel')
|
|
|
|
]
|