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(
|
2018-06-10 10:44:00 -04:00
|
|
|
templateUrl: "newFileModalTemplate"
|
|
|
|
controller: "NewFileModalController"
|
|
|
|
size: 'lg'
|
2014-07-08 07:02:26 -04:00
|
|
|
resolve: {
|
|
|
|
parent_folder: () -> ide.fileTreeManager.getCurrentFolder()
|
2018-06-10 10:44:00 -04:00
|
|
|
type: () -> 'doc'
|
2014-07-08 07:02:26 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.openNewFolderModal = () ->
|
|
|
|
$modal.open(
|
|
|
|
templateUrl: "newFolderModalTemplate"
|
|
|
|
controller: "NewFolderModalController"
|
|
|
|
resolve: {
|
|
|
|
parent_folder: () -> ide.fileTreeManager.getCurrentFolder()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.openUploadFileModal = () ->
|
|
|
|
$modal.open(
|
2018-06-10 10:44:00 -04:00
|
|
|
templateUrl: "newFileModalTemplate"
|
|
|
|
controller: "NewFileModalController"
|
|
|
|
size: 'lg'
|
2014-07-08 07:02:26 -04:00
|
|
|
resolve: {
|
|
|
|
parent_folder: () -> ide.fileTreeManager.getCurrentFolder()
|
2018-06-10 10:44:00 -04:00
|
|
|
type: () -> 'upload'
|
2018-05-15 11:22:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
$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"
|
|
|
|
]
|
|
|
|
|
2018-06-10 10:44:00 -04:00
|
|
|
App.controller "NewFolderModalController", [
|
2014-07-08 07:02:26 -04:00
|
|
|
"$scope", "ide", "$modalInstance", "$timeout", "parent_folder",
|
|
|
|
($scope, ide, $modalInstance, $timeout, parent_folder) ->
|
2018-06-10 10:44:00 -04:00
|
|
|
$scope.inputs =
|
|
|
|
name: "name"
|
2014-07-08 07:02:26 -04:00
|
|
|
$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
|
2018-06-10 10:44:00 -04:00
|
|
|
.createFolder(name, $scope.parent_folder)
|
2017-06-20 06:49:55 -04:00
|
|
|
.then () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.state.inflight = false
|
2018-06-10 10:44:00 -04:00
|
|
|
$modalInstance.dismiss('done')
|
2017-06-20 11:27:05 -04:00
|
|
|
.catch (response)->
|
|
|
|
{ data } = response
|
|
|
|
$scope.error = data
|
2018-01-31 04:34:17 -05:00
|
|
|
$scope.state.inflight = false
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss('cancel')
|
|
|
|
]
|
|
|
|
|
2018-06-10 10:44:00 -04:00
|
|
|
App.controller "NewFileModalController", [
|
|
|
|
"$scope", "type", "parent_folder", "$modalInstance"
|
|
|
|
($scope, type, parent_folder, $modalInstance) ->
|
|
|
|
$scope.type = type
|
|
|
|
$scope.parent_folder = parent_folder
|
|
|
|
$scope.state = {
|
2014-07-08 07:02:26 -04:00
|
|
|
inflight: false
|
2018-06-10 10:44:00 -04:00
|
|
|
valid: true
|
|
|
|
}
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss('cancel')
|
|
|
|
$scope.create = () ->
|
|
|
|
$scope.$broadcast 'create'
|
|
|
|
$scope.$on 'done', () ->
|
|
|
|
$modalInstance.dismiss('done')
|
|
|
|
]
|
2014-07-08 07:02:26 -04:00
|
|
|
|
2018-06-10 10:44:00 -04:00
|
|
|
App.controller "NewDocModalController", [
|
|
|
|
"$scope", "ide", "$timeout"
|
|
|
|
($scope, ide, $timeout) ->
|
|
|
|
$scope.inputs =
|
|
|
|
name: "name.tex"
|
2014-07-08 07:02:26 -04:00
|
|
|
|
2018-06-10 10:44:00 -04:00
|
|
|
validate = () ->
|
|
|
|
name = $scope.inputs.name
|
|
|
|
$scope.state.valid = (name? and name.length > 0)
|
|
|
|
$scope.$watch 'inputs.name', validate
|
|
|
|
|
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "open"
|
|
|
|
, 200
|
|
|
|
|
|
|
|
$scope.$on '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
|
2018-06-10 10:44:00 -04:00
|
|
|
.createDoc(name, $scope.parent_folder)
|
2017-06-20 06:49:55 -04:00
|
|
|
.then () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.state.inflight = false
|
2018-06-10 10:44:00 -04:00
|
|
|
$scope.$emit 'done'
|
2017-06-20 11:27:05 -04:00
|
|
|
.catch (response)->
|
|
|
|
{ data } = response
|
|
|
|
$scope.error = data
|
2017-06-20 06:49:55 -04:00
|
|
|
$scope.state.inflight = false
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
App.controller "UploadFileModalController", [
|
2018-06-10 10:44:00 -04:00
|
|
|
"$scope", "$rootScope", "ide", "$timeout", "$window"
|
|
|
|
($scope, $rootScope, ide, $timeout, $window) ->
|
|
|
|
$scope.parent_folder_id = $scope.parent_folder?.id
|
|
|
|
$scope.project_id = ide.project_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
|
2018-06-10 10:44:00 -04:00
|
|
|
$scope.$emit 'done'
|
2014-07-08 07:02:26 -04:00
|
|
|
), 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
|
|
|
|
2018-02-16 11:35:51 -05:00
|
|
|
]
|
|
|
|
|
2018-05-15 11:22:47 -04:00
|
|
|
App.controller "ProjectLinkedFileModalController", [
|
2018-06-10 10:44:00 -04:00
|
|
|
"$scope", "ide", "$timeout",
|
|
|
|
($scope, ide, $timeout) ->
|
2018-06-08 04:35:52 -04:00
|
|
|
|
2018-05-15 11:22:47 -04:00
|
|
|
$scope.data =
|
|
|
|
projects: null # or []
|
2018-05-16 08:26:59 -04:00
|
|
|
selectedProjectId: null
|
2018-05-15 11:22:47 -04:00
|
|
|
projectEntities: null # or []
|
2018-06-08 04:35:52 -04:00
|
|
|
projectOutputFiles: null # or []
|
2018-05-15 11:22:47 -04:00
|
|
|
selectedProjectEntity: null
|
2018-06-08 07:32:22 -04:00
|
|
|
selectedProjectOutputFile: null
|
2018-05-16 05:29:51 -04:00
|
|
|
name: null
|
2018-06-10 10:44:00 -04:00
|
|
|
$scope.state.inFlight =
|
|
|
|
projects: false
|
|
|
|
entities: false
|
|
|
|
compile: false
|
2018-06-11 05:29:40 -04:00
|
|
|
$scope.state.isOutputFilesMode = false
|
2018-06-10 10:44:00 -04:00
|
|
|
$scope.state.error = false
|
2018-05-15 11:22:47 -04:00
|
|
|
|
2018-05-16 08:26:59 -04:00
|
|
|
$scope.$watch 'data.selectedProjectId', (newVal, oldVal) ->
|
2018-05-15 11:22:47 -04:00
|
|
|
return if !newVal
|
|
|
|
$scope.data.selectedProjectEntity = null
|
2018-06-11 05:29:40 -04:00
|
|
|
if $scope.state.isOutputFilesMode
|
2018-06-08 04:35:52 -04:00
|
|
|
$scope.compileProjectAndGetOutputFiles($scope.data.selectedProjectId)
|
|
|
|
else
|
|
|
|
$scope.getProjectEntities($scope.data.selectedProjectId)
|
2018-05-15 11:22:47 -04:00
|
|
|
|
2018-05-16 06:12:00 -04:00
|
|
|
# auto-set filename based on selected file
|
|
|
|
$scope.$watch 'data.selectedProjectEntity', (newVal, oldVal) ->
|
|
|
|
return if !newVal
|
|
|
|
fileName = newVal.split('/').reverse()[0]
|
|
|
|
if fileName
|
|
|
|
$scope.data.name = fileName
|
|
|
|
|
2018-06-08 07:32:22 -04:00
|
|
|
# auto-set filename based on selected file
|
|
|
|
$scope.$watch 'data.selectedProjectOutputFile', (newVal, oldVal) ->
|
|
|
|
return if !newVal
|
|
|
|
fileName = newVal.split('/').reverse()[0]
|
|
|
|
if fileName
|
|
|
|
$scope.data.name = fileName
|
|
|
|
|
2018-05-24 06:32:44 -04:00
|
|
|
_setInFlight = (type) ->
|
2018-05-16 08:26:59 -04:00
|
|
|
$scope.state.inFlight[type] = true
|
|
|
|
|
2018-05-24 06:32:44 -04:00
|
|
|
_reset = (opts) ->
|
2018-05-16 05:29:51 -04:00
|
|
|
isError = opts.err == true
|
2018-05-16 06:49:10 -04:00
|
|
|
inFlight = $scope.state.inFlight
|
2018-06-10 10:44:00 -04:00
|
|
|
inFlight.projects = inFlight.entities = inFlight.compile = false
|
|
|
|
$scope.state.inflight = false
|
2018-05-15 11:22:47 -04:00
|
|
|
$scope.state.error = isError
|
|
|
|
|
|
|
|
$scope.shouldEnableProjectSelect = () ->
|
2018-05-25 11:03:45 -04:00
|
|
|
{ state, data } = $scope
|
2018-05-16 06:49:10 -04:00
|
|
|
return !state.inFlight.projects && data.projects
|
2018-05-15 11:22:47 -04:00
|
|
|
|
|
|
|
$scope.shouldEnableProjectEntitySelect = () ->
|
2018-05-25 11:03:45 -04:00
|
|
|
{ state, data } = $scope
|
2018-05-16 08:26:59 -04:00
|
|
|
return !state.inFlight.projects && !state.inFlight.entities && data.projects && data.selectedProjectId
|
2018-05-15 11:22:47 -04:00
|
|
|
|
2018-06-08 04:35:52 -04:00
|
|
|
$scope.shouldEnableProjectOutputFileSelect = () ->
|
|
|
|
{ state, data } = $scope
|
|
|
|
return !state.inFlight.projects && !state.inFlight.compile && data.projects && data.selectedProjectId
|
|
|
|
|
2018-06-10 10:44:00 -04:00
|
|
|
|
|
|
|
validate = () ->
|
2018-05-15 11:22:47 -04:00
|
|
|
state = $scope.state
|
|
|
|
data = $scope.data
|
2018-06-10 10:44:00 -04:00
|
|
|
$scope.state.valid = !state.inFlight.projects &&
|
2018-05-16 06:49:10 -04:00
|
|
|
!state.inFlight.entities &&
|
2018-05-15 11:22:47 -04:00
|
|
|
data.projects &&
|
2018-05-16 08:26:59 -04:00
|
|
|
data.selectedProjectId &&
|
2018-06-08 04:35:52 -04:00
|
|
|
(
|
|
|
|
(
|
2018-06-11 05:29:40 -04:00
|
|
|
!$scope.state.isOutputFilesMode &&
|
2018-06-08 04:35:52 -04:00
|
|
|
data.projectEntities &&
|
|
|
|
data.selectedProjectEntity
|
|
|
|
) ||
|
|
|
|
(
|
2018-06-11 05:29:40 -04:00
|
|
|
$scope.state.isOutputFilesMode &&
|
2018-06-08 04:35:52 -04:00
|
|
|
data.projectOutputFiles &&
|
|
|
|
data.selectedProjectOutputFile
|
|
|
|
)
|
|
|
|
) &&
|
2018-05-16 05:29:51 -04:00
|
|
|
data.name
|
2018-06-10 10:44:00 -04:00
|
|
|
$scope.$watch 'state', validate, true
|
|
|
|
$scope.$watch 'data', validate, true
|
2018-05-15 11:22:47 -04:00
|
|
|
|
|
|
|
$scope.getUserProjects = () ->
|
2018-05-24 06:32:44 -04:00
|
|
|
_setInFlight('projects')
|
2018-05-15 11:22:47 -04:00
|
|
|
ide.$http.get("/user/projects", {
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
})
|
|
|
|
.then (resp) ->
|
|
|
|
$scope.data.projectEntities = null
|
2018-05-16 05:29:51 -04:00
|
|
|
$scope.data.projects = resp.data.projects.filter (p) ->
|
|
|
|
p._id != ide.project_id
|
2018-05-24 06:32:44 -04:00
|
|
|
_reset(err: false)
|
2018-05-15 11:22:47 -04:00
|
|
|
.catch (err) ->
|
2018-05-24 06:32:44 -04:00
|
|
|
_reset(err: true)
|
2018-05-15 11:22:47 -04:00
|
|
|
|
|
|
|
$scope.getProjectEntities = (project_id) =>
|
2018-05-24 06:32:44 -04:00
|
|
|
_setInFlight('entities')
|
2018-05-15 11:22:47 -04:00
|
|
|
ide.$http.get("/project/#{project_id}/entities", {
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
})
|
|
|
|
.then (resp) ->
|
2018-05-16 08:26:59 -04:00
|
|
|
if $scope.data.selectedProjectId == resp.data.project_id
|
2018-05-15 11:22:47 -04:00
|
|
|
$scope.data.projectEntities = resp.data.entities
|
2018-05-24 06:32:44 -04:00
|
|
|
_reset(err: false)
|
2018-05-15 11:22:47 -04:00
|
|
|
.catch (err) ->
|
2018-05-24 06:32:44 -04:00
|
|
|
_reset(err: true)
|
2018-05-15 11:22:47 -04:00
|
|
|
|
2018-06-08 07:32:22 -04:00
|
|
|
$scope.compileProjectAndGetOutputFiles = (project_id) =>
|
2018-06-08 04:35:52 -04:00
|
|
|
_setInFlight('compile')
|
2018-06-08 07:32:22 -04:00
|
|
|
ide.$http.post("/project/#{project_id}/compile", {
|
2018-06-08 04:35:52 -04:00
|
|
|
check: "silent",
|
|
|
|
draft: false,
|
|
|
|
incrementalCompilesEnabled: false
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
})
|
2018-06-08 07:32:22 -04:00
|
|
|
.then (resp) ->
|
|
|
|
if resp.data.status == 'success'
|
|
|
|
$scope.data.projectOutputFiles = resp.data.outputFiles
|
|
|
|
_reset(err: false)
|
|
|
|
else
|
|
|
|
$scope.data.projectOutputFiles = null
|
|
|
|
_reset(err: true)
|
2018-06-08 04:35:52 -04:00
|
|
|
.catch (err) ->
|
|
|
|
console.error(err)
|
|
|
|
_reset(err: true)
|
|
|
|
|
2018-05-15 11:22:47 -04:00
|
|
|
$scope.init = () ->
|
|
|
|
$scope.getUserProjects()
|
2018-05-24 06:32:44 -04:00
|
|
|
$timeout($scope.init, 0)
|
2018-05-15 11:22:47 -04:00
|
|
|
|
2018-06-10 10:44:00 -04:00
|
|
|
$scope.$on 'create', () ->
|
2018-05-16 08:44:21 -04:00
|
|
|
projectId = $scope.data.selectedProjectId
|
2018-05-16 05:29:51 -04:00
|
|
|
name = $scope.data.name
|
2018-06-11 05:29:40 -04:00
|
|
|
if $scope.state.isOutputFilesMode
|
2018-06-08 04:35:52 -04:00
|
|
|
provider = 'project_output_file'
|
|
|
|
payload = {
|
|
|
|
source_project_id: projectId,
|
|
|
|
source_output_file_path: $scope.data.selectedProjectOutputFile
|
|
|
|
}
|
|
|
|
else
|
|
|
|
provider = 'project_file'
|
|
|
|
payload = {
|
|
|
|
source_project_id: projectId,
|
|
|
|
source_entity_path: $scope.data.selectedProjectEntity
|
|
|
|
}
|
2018-05-24 06:32:44 -04:00
|
|
|
_setInFlight('create')
|
2018-05-16 05:29:51 -04:00
|
|
|
ide.fileTreeManager
|
2018-06-10 10:44:00 -04:00
|
|
|
.createLinkedFile(name, $scope.parent_folder, provider, payload)
|
2018-05-16 05:29:51 -04:00
|
|
|
.then () ->
|
2018-05-24 06:32:44 -04:00
|
|
|
_reset(err: false)
|
2018-06-10 10:44:00 -04:00
|
|
|
$scope.$emit 'done'
|
2018-05-16 05:29:51 -04:00
|
|
|
.catch (response)->
|
|
|
|
{ data } = response
|
2018-05-24 06:32:44 -04:00
|
|
|
_reset(err: true)
|
2018-05-15 11:22:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2018-06-10 10:44:00 -04:00
|
|
|
App.controller "UrlLinkedFileModalController", [
|
|
|
|
"$scope", "ide", "$timeout"
|
|
|
|
($scope, ide, $timeout) ->
|
2018-02-16 11:35:51 -05:00
|
|
|
$scope.inputs =
|
|
|
|
name: ""
|
|
|
|
url: ""
|
|
|
|
$scope.nameChangedByUser = false
|
|
|
|
|
2018-06-10 10:44:00 -04:00
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "open"
|
|
|
|
, 200
|
|
|
|
|
|
|
|
validate = () ->
|
|
|
|
{name, url} = $scope.inputs
|
|
|
|
if !name? or name.length == 0
|
|
|
|
$scope.state.valid = false
|
|
|
|
else if !url? or url.length == 0
|
|
|
|
$scope.state.valid = false
|
|
|
|
else
|
|
|
|
$scope.state.valid = true
|
|
|
|
$scope.$watch 'inputs.name', validate
|
|
|
|
$scope.$watch 'inputs.url', validate
|
2018-02-16 11:35:51 -05:00
|
|
|
|
|
|
|
$scope.$watch "inputs.url", (url) ->
|
|
|
|
if url? and url != "" and !$scope.nameChangedByUser
|
|
|
|
url = url.replace("://", "") # Ignore http:// etc
|
|
|
|
parts = url.split("/").reverse()
|
|
|
|
if parts.length > 1 # Wait for at one /
|
|
|
|
$scope.inputs.name = parts[0]
|
|
|
|
|
2018-06-10 10:44:00 -04:00
|
|
|
$scope.$on 'create', () ->
|
2018-02-16 11:35:51 -05:00
|
|
|
{name, url} = $scope.inputs
|
|
|
|
if !name? or name.length == 0
|
|
|
|
return
|
|
|
|
if !url? or url.length == 0
|
|
|
|
return
|
|
|
|
$scope.state.inflight = true
|
|
|
|
ide.fileTreeManager
|
2018-06-10 10:44:00 -04:00
|
|
|
.createLinkedFile(name, $scope.parent_folder, 'url', {url})
|
2018-02-16 11:35:51 -05:00
|
|
|
.then () ->
|
|
|
|
$scope.state.inflight = false
|
2018-06-10 10:44:00 -04:00
|
|
|
$scope.$emit 'done'
|
2018-02-16 11:35:51 -05:00
|
|
|
.catch (response)->
|
|
|
|
{ data } = response
|
|
|
|
$scope.error = data
|
|
|
|
$scope.state.inflight = false
|
|
|
|
|
|
|
|
]
|