WIP: Project Linked File modal

This commit is contained in:
Shane Kilkelly 2018-05-15 16:22:47 +01:00
parent 33b4a1768b
commit 9c33f3f8bc
3 changed files with 156 additions and 4 deletions

View file

@ -342,6 +342,60 @@ script(type='text/ng-template', id='newDocModalTemplate')
span(ng-show="state.inflight") #{translate("creating")}...
// Project Linked Files Modal
script(type='text/ng-template', id='projectLinkedFileModalTemplate')
.modal-header
h3 New file from Project
.modal-body
div
div.alert.alert-danger(ng-if="state.error") Error
div
form
.form-controls
label(for="project-select") Select a Project
select.form-control(
name="project-select"
ng-model="data.selectedProject"
ng-disabled="!shouldEnableProjectSelect()"
)
option(value="") --
option(
ng-repeat="project in data.projects"
value="{{ project._id }}"
) {{ project.name }}
br
.form-controls
label(for="project-entity-select") Select a File
select.form-control(
name="project-entity-select"
ng-model="data.selectedProjectEntity"
ng-disabled="!shouldEnableProjectEntitySelect()"
)
option(value="") --
option(
ng-repeat="projectEntity in data.projectEntities"
value="{{ projectEntity.path }}"
) {{ projectEntity.path }}
br
.modal-footer
span(ng-show="state.inFlight")
i.fa.fa-spinner.fa-spin
|  
button.btn.btn-default(
ng-disabled="state.inflight"
ng-click="cancel()"
) #{translate("cancel")}
button.btn.btn-primary(
ng-disabled="!shouldEnableCreateButton()"
ng-click="create()"
)
span(ng-hide="state.inflight") #{translate("create")}
span(ng-show="state.inflight") #{translate("creating")}...
script(type='text/ng-template', id='linkedFileModalTemplate')
.modal-header
h3 New file from URL

View file

@ -42,14 +42,14 @@ define [
# TODO: remove
window._getProjects = () =>
@ide.$http.get "/user/projects", {
@ide.$http.get("/user/projects", {
_csrf: window.csrfToken
}
}).then (resp) -> console.log(resp.status, resp.data)
window._getProjectEntities = (project_id) =>
@ide.$http.get "/project/#{project_id}/entities", {
@ide.$http.get("/project/#{project_id}/entities", {
_csrf: window.csrfToken
}
}).then (resp) -> console.log(resp.status, resp.data)
_bindToSocketEvents: () ->
@ide.socket.on "reciveNewDoc", (parent_folder_id, doc) =>

View file

@ -43,6 +43,19 @@ define [
}
)
$scope.openProjectLinkedFileModal = window.openProjectLinkedFileModal = () ->
unless 'url' in window.data.enabledLinkedFileTypes
console.warn("Project linked files are not enabled")
return
$modal.open(
templateUrl: "projectLinkedFileModalTemplate"
controller: "ProjectLinkedFileModalController"
scope: $scope
resolve: {
parent_folder: () -> ide.fileTreeManager.getCurrentFolder()
}
)
$scope.orderByFoldersFirst = (entity) ->
return '0' if entity?.type == "folder"
return '1'
@ -201,6 +214,91 @@ define [
$modalInstance.dismiss('cancel')
]
App.controller "ProjectLinkedFileModalController", [
"$scope", "ide", "$modalInstance", "$timeout", "parent_folder",
($scope, ide, $modalInstance, $timeout, parent_folder) ->
$scope.data =
projects: null # or []
selectedProject: null
projectEntities: null # or []
selectedProjectEntity: null
$scope.state =
inFlight: false
error: false
$scope.$watch 'data.selectedProject', (newVal, oldVal) ->
return if !newVal
$scope.data.selectedProjectEntity = null
$scope.getProjectEntities($scope.data.selectedProject)
$scope._reset = () ->
$scope.state.inFlight = false
$scope.state.error = false
$scope._resetAfterResponse = (opts) ->
isError = !!opts.err
$scope.state.inFlight = false
$scope.state.error = isError
$scope.shouldEnableProjectSelect = () ->
state = $scope.state
data = $scope.data
return !state.inFlight && data.projects
$scope.shouldEnableProjectEntitySelect = () ->
state = $scope.state
data = $scope.data
return !state.inFlight && data.projects && data.selectedProject
$scope.shouldEnableCreateButton = () ->
state = $scope.state
data = $scope.data
return !state.inFlight &&
data.projects &&
data.selectedProject &&
data.projectEntities &&
data.selectedProjectEntity
$scope.getUserProjects = () ->
$scope.state.inFlight = true
ide.$http.get("/user/projects", {
_csrf: window.csrfToken
})
.then (resp) ->
$scope.data.projectEntities = null
$scope.data.projects = resp.data.projects
$scope._resetAfterResponse(err: false)
.catch (err) ->
$scope._resetAfterResponse(err: true)
$scope.getProjectEntities = (project_id) =>
$scope.state.inFlight = true
ide.$http.get("/project/#{project_id}/entities", {
_csrf: window.csrfToken
})
.then (resp) ->
if $scope.data.selectedProject == resp.data.project_id
$scope.data.projectEntities = resp.data.entities
$scope._resetAfterResponse(err: false)
.catch (err) ->
$scope._resetAfterResponse(err: true)
# TODO: remove
window._S = $scope
$scope.init = () ->
$scope.getUserProjects()
$timeout($scope.init, 100)
$scope.create = () ->
console.log ">> create"
$scope.cancel = () ->
$modalInstance.dismiss('cancel')
]
# TODO: rename all this to UrlLinkedFilModalController
App.controller "LinkedFileModalController", [
"$scope", "ide", "$modalInstance", "$timeout", "parent_folder",
($scope, ide, $modalInstance, $timeout, parent_folder) ->