From 4d1b6c6ba843cb70bcbc23cf7b546353d8d542ae Mon Sep 17 00:00:00 2001 From: Paulo Reis Date: Thu, 5 Jul 2018 11:36:02 +0100 Subject: [PATCH] Add error handling. --- .../views/user/settings/user-affiliations.pug | 23 +++++++++++++++++-- .../UserAffiliationsController.coffee | 22 +++++++++++++++--- .../UserAffiliationsDataService.coffee | 3 +-- .../stylesheets/app/account-settings.less | 12 ++++++++++ 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/services/web/app/views/user/settings/user-affiliations.pug b/services/web/app/views/user/settings/user-affiliations.pug index 24424b495c..92f64dcdc3 100644 --- a/services/web/app/views/user/settings/user-affiliations.pug +++ b/services/web/app/views/user/settings/user-affiliations.pug @@ -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") diff --git a/services/web/public/coffee/main/affiliations/controllers/UserAffiliationsController.coffee b/services/web/public/coffee/main/affiliations/controllers/UserAffiliationsController.coffee index d88a15e161..8b7a5c926f 100644 --- a/services/web/public/coffee/main/affiliations/controllers/UserAffiliationsController.coffee +++ b/services/web/public/coffee/main/affiliations/controllers/UserAffiliationsController.coffee @@ -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() ] \ No newline at end of file diff --git a/services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee b/services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee index 6b689f5441..2886cf779d 100644 --- a/services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee +++ b/services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee @@ -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, diff --git a/services/web/public/stylesheets/app/account-settings.less b/services/web/public/stylesheets/app/account-settings.less index f8663f7b5f..17fecb4110 100644 --- a/services/web/public/stylesheets/app/account-settings.less +++ b/services/web/public/stylesheets/app/account-settings.less @@ -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;