Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
fix(page): create page without title
Browse files Browse the repository at this point in the history
also improve notifications on API response

fix gravitee-io/issues#171
  • Loading branch information
NicolasGeraud committed Jul 27, 2016
1 parent f46beda commit 24819a5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/app/api/admin/documentation/page/apiPage.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,22 @@ class PageController {
if(this.createMode) {
this.DocumentationService.createPage(this.$state.params.apiId, this.page)
.then(function (page) {
that.onPageUpdate();
that.$state.go(that.$state.current, that.$state.params, {reload: true});
})
.catch(function (error) {
that.$scope.error = error;
that.NotificationService.error(error);
});
} else {
this.DocumentationService.editPage(this.$state.params.apiId, this.page.id, this.page)
.then(function () {
that.onPageUpdate();
that.$state.go(that.$state.current, that.$state.params, {reload: true});
})
.catch(function (error) {
that.$scope.error = error;
that.NotificationService.error(error);
});
}
}
Expand Down Expand Up @@ -171,6 +175,14 @@ class PageController {
that.NotificationService.show('Page ' + editPage.name + ' has been ' + (editPage.published ? '':'un') + 'published with success');
});
}

hasNoTitle() {
return _.isNil(this.page) || _.isNil(this.page.name) || _.isEmpty(this.page.name);
}

onPageUpdate() {
this.NotificationService.show('Page \'' + this.page.name + '\' saved');
}
}

export default PageController;
6 changes: 3 additions & 3 deletions src/app/api/admin/documentation/page/apiPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ <h5>Or you could also import a file :</h5>
</div>
</md-card-content>
<div class="md-actions gravitee-api-save-button" layout="row" layout-align="end center">
<md-button class="md-raised" type="submit" ng-click="pageCtrl.upsert()" ng-disabled="formApi.$invalid || formApi.$pristine">
<md-button class="md-raised" type="submit" ng-click="pageCtrl.upsert()" ng-disabled="pageCtrl.hasNoTitle()">
Save
</md-button>
<md-button class="md-raised md-primary" type="button" ng-click="pageCtrl.reset()" ng-disabled="formApi.$invalid || formApi.$pristine">
<md-button class="md-raised md-primary" type="button" ng-click="pageCtrl.reset()">
Cancel
</md-button>
</div>
Expand Down Expand Up @@ -121,7 +121,7 @@ <h4>Fetch content from an external resource:</h4>
<div layout="column">
<form name="PageConfigFetcherForm" sf-schema="fetcherJsonSchema" sf-form="pageCtrl.fetcherJsonSchemaForm" sf-model="pageCtrl.page.source.configuration"></form>
</div>
<md-button class="md-raised" type="submit" ng-click="pageCtrl.upsert()">
<md-button ng-disabled="pageCtrl.hasNoTitle()" class="md-raised" type="submit" ng-click="pageCtrl.upsert()">
Save
</md-button>
</md-content>
Expand Down
8 changes: 7 additions & 1 deletion src/app/components/notification/notification.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ class NotificationService {
};

this.error = function (error, message) {
this.show(message || (error.data ? error.data.message : error), true);
this.show(message || (
error.data ?
Array.isArray(error.data) ?
error.data[0].message
: error.data.message
: error
), true);
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/index.interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ function interceptorConfig($httpProvider) {
}
} else {
if (error.status === 500) {
errorMessage = 'Unexpected error';
errorMessage = error.data ? error.data.message : 'Unexpected error';
} else if (error.status === 503) {
errorMessage = 'Server unavailable';
errorMessage = error.data ? error.data.message : 'Server unavailable';
}
}
if (!sessionExpired) {
Expand Down

0 comments on commit 24819a5

Please sign in to comment.