Add error handling.

This commit is contained in:
Paulo Reis 2018-07-05 11:36:02 +01:00 committed by James Allen
parent c630c5d952
commit 4d1b6c6ba8
4 changed files with 53 additions and 7 deletions

View file

@ -11,7 +11,9 @@ form.row(
th.affiliations-table-email Email
th.affiliations-table-institution Institution and role
th.affiliations-table-inline-actions
tbody
tbody(
ng-if="!ui.hasError"
)
tr(
ng-repeat="userEmail in userEmails"
)
@ -73,7 +75,6 @@ form.row(
td.text-center(colspan="3")
i.fa.fa-fw.fa-spin.fa-refresh
|  Loading...
tr.affiliations-table-highlighted-row(
ng-if="!ui.showAddEmailUI && !ui.isLoadingEmails"
)
@ -139,6 +140,24 @@ form.row(
)
i.fa.fa-fw.fa-spin.fa-refresh
|  Adding...
tbody(
ng-if="ui.hasError"
)
tr.affiliations-table-error-row(
ng-if="true"
)
td.text-center(colspan="3")
div
i.fa.fa-fw.fa-exclamation-triangle
|  An error has occurred while performing your request.
div
| Click
a(
href
ng-click="acknowledgeError();"
) here
| to reload your emails and affiliations.
hr
script(type="text/ng-template", id="affiliationFormTpl")

View file

@ -52,12 +52,15 @@ define [
$scope.affiliationToChange.department = userEmail.affiliation.department
$scope.saveAffiliationChange = () ->
$scope.ui.isLoadingEmails = true
UserAffiliationsDataService
.addRoleAndDepartment(
$scope.affiliationToChange.email,
$scope.affiliationToChange.role,
$scope.affiliationToChange.department
)
.then () -> _getUserEmails()
.catch () -> $scope.ui.hasError = true
$scope.cancelAffiliationChange = (email) ->
$scope.affiliationToChange.email = ""
@ -93,15 +96,19 @@ define [
$scope.newAffiliation.role,
$scope.newAffiliation.department
)
addEmailPromise.then () ->
_reset()
_getUserEmails()
addEmailPromise
.then () ->
_reset()
_getUserEmails()
.catch () ->
$scope.ui.hasError = true
$scope.setDefaultUserEmail = (userEmail) ->
$scope.ui.isLoadingEmails = true
UserAffiliationsDataService
.setDefaultUserEmail userEmail.email
.then () -> _getUserEmails()
.catch () -> $scope.ui.hasError = true
$scope.removeUserEmail = (userEmail) ->
$scope.ui.isLoadingEmails = true
@ -111,6 +118,11 @@ define [
UserAffiliationsDataService
.removeUserEmail userEmail.email
.then () -> _getUserEmails()
.catch () -> $scope.ui.hasError = true
$scope.acknowledgeError = () ->
_reset()
_getUserEmails()
_reset = () ->
$scope.newAffiliation =
@ -120,6 +132,7 @@ define [
role: null
department: null
$scope.ui =
hasError: false
showChangeAffiliationUI: false
showManualUniversitySelectionUI: false
isLoadingEmails: false
@ -141,6 +154,9 @@ define [
.then (emails) ->
$scope.userEmails = emails
$scope.ui.isLoadingEmails = false
.catch () ->
$scope.ui.hasError = true
_getUserEmails()
]

View file

@ -27,7 +27,7 @@ define [
getDefaultDepartmentHints = () ->
$q.resolve defaultDepartmentHints
getUserEmails = () ->
getUserEmails = () ->
$http.get "/user/emails"
.then (response) -> response.data
@ -88,7 +88,6 @@ define [
_csrf: window.csrfToken
}
setDefaultUserEmail = (email) ->
$http.post "/user/emails/default", {
email,

View file

@ -29,6 +29,18 @@
.affiliations-table-highlighted-row {
background-color: tint(@content-alt-bg-color, 6%);
}
.affiliations-table-error-row {
background-color: @alert-danger-bg;
color: @alert-danger-text;
a {
color: #FFF;
font-weight: bold;
&:hover,
&:focus {
color: #FFF;
}
}
}
.affiliations-form-group {
margin-top: @table-cell-padding;