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

Commit

Permalink
fix: Impossible to detach an API while creating a view
Browse files Browse the repository at this point in the history
  • Loading branch information
aelamrani committed Sep 9, 2019
1 parent 9eb5b62 commit 6492d84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
29 changes: 12 additions & 17 deletions src/management/configuration/views/view/view.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ViewController {
private viewApis: any[];
private selectedAPIs: any[];
private addedAPIs: any[];
private deletedAPIs: any[];
public searchText: string = "";
public viewForm: any;
private formChanged: boolean = false;
Expand All @@ -47,7 +46,6 @@ class ViewController {
}

$onInit() {
this.deletedAPIs = [];
this.addedAPIs = [];
this.selectedAPIs = (this.viewApis) ? this.viewApis.slice(0) : [];
let self = this;
Expand All @@ -68,7 +66,7 @@ class ViewController {
let apiViews = api.views || [];
apiViews.push(view.id);
api.views = apiViews;
return that.ApiService.update(api)
return that.ApiService.update(api);
});
that.$q.all(apiFunctions).then(() => {
that.NotificationService.show('View ' + view.name + ' has been saved.');
Expand Down Expand Up @@ -109,30 +107,27 @@ class ViewController {
}

removeApi(api) {
let that = this;
this.$mdDialog.show({
controller: 'DeleteAPIViewDialogController',
template: require('./delete-api-view.dialog.html'),
locals: {
api: api
}
}).then(function (deleteApi) {
}).then((deleteApi) => {
if (deleteApi) {
that.deletedAPIs.push(api);
if (that.viewApis.some(a => a.id === api.id)) {
if (this.viewApis && this.viewApis.some(a => a.id === api.id)) {
// we need to retrieve the API to get the all information required for the update
that.ApiService.get(api.id).then(response => {
this.ApiService.get(api.id).then(response => {
let apiFound = response.data;
apiFound.views = _.remove(apiFound.views, that.view.id);
that.ApiService.update(apiFound).then(() => {
that.NotificationService.show("API '" + api.name + "' detached with success")
_.remove(that.selectedAPIs, api);
_.remove(that.viewApis, api);
})
apiFound.views = _.remove(apiFound.views, this.view.id);
this.ApiService.update(apiFound).then(() => {
this.NotificationService.show("API '" + api.name + "' detached with success")
_.remove(this.selectedAPIs, api);
_.remove(this.viewApis, api);
});
});
} else {
that.NotificationService.show("API '" + api.name + "' detached with success")
_.remove(that.selectedAPIs, api);
_.remove(this.selectedAPIs, api);
}
}
});
Expand All @@ -148,7 +143,7 @@ class ViewController {
}

isHighlightApi(api) {
return this.view.highlightApi === api.id;
return this.view && this.view.highlightApi === api.id;
}

getApis() {
Expand Down
16 changes: 8 additions & 8 deletions src/management/configuration/views/view/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ <h4 ng-if="api.version"><ng-md-icon icon="watch_later" style="fill:grey;" size="
</table>
</md-table-container>

<div layout="row">
<md-button ng-disabled="$ctrl.viewForm.$invalid || $ctrl.viewForm.$pristine && !$ctrl.formChanged"
ng-click="$ctrl.save()"
permission permission-only="['portal-view-c', 'portal-view-u']"
class="md-raised md-primary">
Save
</md-button>
</div>
<div layout="row">
<md-button ng-disabled="$ctrl.viewForm.$invalid || $ctrl.viewForm.$pristine && !$ctrl.formChanged"
ng-click="$ctrl.save()"
permission permission-only="['portal-view-c', 'portal-view-u']"
class="md-raised md-primary">
Save
</md-button>
</div>
</div>
</div>
</div>

0 comments on commit 6492d84

Please sign in to comment.