This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Duplicate an api to create a new version of the API
Closes gravitee-io/issues#433
- Loading branch information
Showing
6 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/management/api/portal/general/dialog/apiDuplicate.dialog.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<!-- | ||
Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<md-dialog> | ||
<form name="formApiDefinition" ng-submit="$ctrl.duplicate()" novalidate> | ||
<md-dialog-content layout-padding> | ||
<h4>What do you want to duplicate?</h4> | ||
<div layout="column"> | ||
<div layout="row"> | ||
<md-input-container layout="row" flex> | ||
<label>Context path</label> | ||
<input type="text" ng-model="$ctrl.contextPath" name="contextPath" ng-change="$ctrl.onContextPathChanged()" | ||
minlength="3" ng-pattern="/^\/[\/.a-zA-Z0-9-_]+$/" placeholder="{{$ctrl.contextPathPlaceholder}}" required> | ||
<div ng-messages="$ctrl.contextPath.$error"> | ||
<div ng-message="required">Context path is required.</div> | ||
<div ng-message="minlength">Context path has to be more than 3 characters long.</div> | ||
<div ng-message="pattern">Context path is not valid (must start with a '/' and must contain any letter, capitalize letter, number, dash or underscore)</div> | ||
</div> | ||
<ng-md-icon icon="close" style="fill: red" ng-if="$ctrl.contextPathInvalid === true"></ng-md-icon> | ||
<ng-md-icon icon="check" style="fill: green" ng-if="$ctrl.contextPathInvalid === false"></ng-md-icon> | ||
</md-input-container> | ||
|
||
<md-input-container flex="30"> | ||
<label>Version</label> | ||
<input ng-model="$ctrl.version" type="text" maxlength="32" name="version" placeholder="{{$ctrl.versionPlaceholder}}"> | ||
<div class="hint" ng-if="$ctrl.version.$valid || $ctrl.version.$pristine">API Version (ex: 1.0)</div> | ||
<div ng-messages="$ctrl.version.$error"> | ||
<div ng-message="required">API Version is required.</div> | ||
<div ng-message="md-maxlength">The version has to be less than 32 characters long.</div> | ||
</div> | ||
</md-input-container> | ||
</div> | ||
|
||
<md-checkbox ng-repeat="fl in $ctrl.filteredFields" aria-label="fl.id" ng-model="fl.checked"> | ||
{{ fl.description }} | ||
</md-checkbox> | ||
</div> | ||
</md-dialog-content> | ||
<md-dialog-actions layout="row"> | ||
<md-button md-no-ink ng-click="$ctrl.hide()"> | ||
Cancel | ||
</md-button> | ||
<md-button type="submit" class="md-raised md-primary" ng-disabled="formApiDefinition.$invalid || $ctrl.contextPathInvalid"> | ||
Duplicate | ||
</md-button> | ||
</md-dialog-actions> | ||
</form> | ||
</md-dialog> |
55 changes: 55 additions & 0 deletions
55
src/management/api/portal/general/dialog/apiDuplicateDialog.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import * as _ from 'lodash'; | ||
import ApiService from "../../../../../services/api.service"; | ||
|
||
function DialogApiDuplicateController($mdDialog, ApiService: ApiService, api) { | ||
'ngInject'; | ||
this.contextPathPlaceholder = api.proxy.virtual_hosts[0].path; | ||
this.versionPlaceholder = api.version; | ||
this.filteredFields = [ | ||
{id: "groups", description: "Groups", checked: true}, | ||
{id: "members", description: "Members", checked: true}, | ||
{id: "pages", description: "Pages", checked: true}, | ||
{id: "plans", description: "Plans", checked: true} | ||
]; | ||
|
||
this.hide = () => { | ||
$mdDialog.hide(); | ||
}; | ||
|
||
this.duplicate = () => { | ||
const config = { | ||
context_path: this.contextPath, | ||
version: this.version, | ||
filtered_fields: _.map(_.filter(this.filteredFields, (fl: any) => { return !fl.checked; }), "id") | ||
}; | ||
ApiService.duplicate(api.id, config).then( (response) => { | ||
$mdDialog.hide(response.data); | ||
}); | ||
}; | ||
|
||
this.onContextPathChanged = () => { | ||
this.contextPathInvalid = false; | ||
ApiService.verify({context_path: this.contextPath}, {ignoreLoadingBar: true, silentCall: true}).then(() => { | ||
this.contextPathInvalid = false; | ||
}, () => { | ||
this.contextPathInvalid = true; | ||
}); | ||
}; | ||
} | ||
|
||
export default DialogApiDuplicateController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters