Merge remote-tracking branch 'origin/ns-new-file-modal-error-handling'

GitOrigin-RevId: 4eadc159d779c10918e045e080e3b8be12e807a2
This commit is contained in:
Douglas Lovell 2019-01-24 08:49:42 -03:00 committed by sharelatex
parent 15061047a3
commit 59d4bd6182
3 changed files with 17 additions and 15 deletions

View file

@ -149,7 +149,10 @@ script(type='text/ng-template', id='newFileModalTemplate')
ng-model="data.name" ng-model="data.name"
name="name" name="name"
) )
div.alert.alert-danger.row-spaced-small(ng-if="state.error") Error, something went wrong! 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, something went wrong!
div(ng-if="type == 'url'", ng-controller="UrlLinkedFileModalController") div(ng-if="type == 'url'", ng-controller="UrlLinkedFileModalController")
form(novalidate, name="newLinkedFileForm") form(novalidate, name="newLinkedFileForm")
label(for="url") URL to fetch the file from label(for="url") URL to fetch the file from

View file

@ -80,9 +80,8 @@ define(['base'], function(App) {
} }
})) }))
return (selectName = function(element) { selectName = function(element) {
// Select up to last '.'. I.e. everything // Select up to last '.'. I.e. everything except the file extension
// except the file extension
element.focus() element.focus()
const name = element.val() const name = element.val()
if (element[0].setSelectionRange != null) { if (element[0].setSelectionRange != null) {
@ -92,5 +91,5 @@ define(['base'], function(App) {
} }
return element[0].setSelectionRange(0, selectionEnd) return element[0].setSelectionRange(0, selectionEnd)
} }
}) }
}) })

View file

@ -148,7 +148,7 @@ define(['base'], function(App) {
const validate = function() { const validate = function() {
const { name } = $scope.inputs const { name } = $scope.inputs
return ($scope.state.valid = name != null && name.length > 0) $scope.state.valid = name != null && name.length > 0
} }
$scope.$watch('inputs.name', validate) $scope.$watch('inputs.name', validate)
@ -169,7 +169,7 @@ define(['base'], function(App) {
.catch(function(response) { .catch(function(response) {
const { data } = response const { data } = response
$scope.error = data $scope.error = data
return ($scope.state.inflight = false) $scope.state.inflight = false
}) })
}) })
} }
@ -338,7 +338,7 @@ define(['base'], function(App) {
} }
const fileName = newVal.split('/').reverse()[0] const fileName = newVal.split('/').reverse()[0]
if (fileName) { if (fileName) {
return ($scope.data.name = fileName) $scope.data.name = fileName
} }
}) })
@ -352,14 +352,14 @@ define(['base'], function(App) {
$scope.data.projects, $scope.data.projects,
p => p._id === $scope.data.selectedProjectId p => p._id === $scope.data.selectedProjectId
) )
return ($scope.data.name = $scope.data.name =
(project != null ? project.name : undefined) != null (project != null ? project.name : undefined) != null
? `${project.name}.pdf` ? `${project.name}.pdf`
: 'output.pdf') : 'output.pdf'
} else { } else {
const fileName = newVal.split('/').reverse()[0] const fileName = newVal.split('/').reverse()[0]
if (fileName) { if (fileName) {
return ($scope.data.name = fileName) $scope.data.name = fileName
} }
} }
}) })
@ -418,7 +418,7 @@ define(['base'], function(App) {
const validate = function() { const validate = function() {
const { state } = $scope const { state } = $scope
const { data } = $scope const { data } = $scope
return ($scope.state.valid = $scope.state.valid =
!state.inFlight.projects && !state.inFlight.projects &&
!state.inFlight.entities && !state.inFlight.entities &&
data.projects && data.projects &&
@ -429,7 +429,7 @@ define(['base'], function(App) {
($scope.state.isOutputFilesMode && ($scope.state.isOutputFilesMode &&
data.projectOutputFiles && data.projectOutputFiles &&
data.selectedProjectOutputFile)) && data.selectedProjectOutputFile)) &&
data.name) data.name
} }
$scope.$watch('state', validate, true) $scope.$watch('state', validate, true)
$scope.$watch('data', validate, true) $scope.$watch('data', validate, true)
@ -519,7 +519,7 @@ define(['base'], function(App) {
} }
} }
_setInFlight('create') _setInFlight('create')
return ide.fileTreeManager ide.fileTreeManager
.createLinkedFile(name, $scope.parent_folder, provider, payload) .createLinkedFile(name, $scope.parent_folder, provider, payload)
.then(function() { .then(function() {
_reset({ err: false }) _reset({ err: false })
@ -527,7 +527,7 @@ define(['base'], function(App) {
}) })
.catch(function(response) { .catch(function(response) {
const { data } = response const { data } = response
return _reset({ err: true }) $scope.error = data
}) })
}) })
} }