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(subscription): api publisher could add app subscription
- Loading branch information
1 parent
be9019d
commit 98ef087
Showing
8 changed files
with
218 additions
and
9 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
68 changes: 68 additions & 0 deletions
68
src/app/api/admin/subscriptions/subscription.create.dialog.controller.js
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,68 @@ | ||
/* | ||
* 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. | ||
*/ | ||
function DialogSubscriptionCreateController($scope, $mdDialog, plans, ApplicationService) { | ||
'ngInject'; | ||
this.plans = plans; | ||
this.selectedApp = null; | ||
this.selectedPlan = null; | ||
this.plansWithSubscriptions = []; | ||
|
||
|
||
this.hide = function () { | ||
$mdDialog.cancel(); | ||
}; | ||
|
||
this.save = function () { | ||
if (this.selectedApp && this.selectedPlan) { | ||
$mdDialog.hide({ | ||
applicationId: this.selectedApp.id, | ||
planId: this.selectedPlan | ||
}); | ||
} | ||
}; | ||
|
||
this.planAlreadyHaveSubscriptions = function(planId) { | ||
return _.indexOf(this.plansWithSubscriptions, planId) > -1; | ||
}; | ||
|
||
this.selectedItemChange = function () { | ||
this.plansWithSubscriptions = []; | ||
this.selectedPlan = null; | ||
if (this.selectedApp) { | ||
_.map(this.plans, (plan) => { | ||
ApplicationService.listSubscriptions(this.selectedApp.id, plan.id).then((response) => { | ||
var subs = _.filter(response.data, (sub) => { | ||
return sub.status === "pending" || sub.status === "accepted"; | ||
}); | ||
if (subs.length > 0) { | ||
this.plansWithSubscriptions.push(plan.id); | ||
} | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
this.searchApplication = function(searchedAppName) { | ||
if (searchedAppName) { | ||
return ApplicationService.search(searchedAppName).then((response) => { | ||
return response.data; | ||
}); | ||
} | ||
}; | ||
|
||
} | ||
|
||
export default DialogSubscriptionCreateController; |
79 changes: 79 additions & 0 deletions
79
src/app/api/admin/subscriptions/subscription.create.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,79 @@ | ||
<!-- | ||
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 aria-label="Create a subscription" style="width: 30%"> | ||
<md-toolbar> | ||
<div class="md-toolbar-tools"> | ||
<h2>Create a subscription</h2> | ||
<span flex></span> | ||
<md-button type="button" class="md-icon-button" ng-click="dialogSubscriptionCreateController.hide()"> | ||
X | ||
</md-button> | ||
</div> | ||
</md-toolbar> | ||
|
||
<md-dialog-content layout-padding > | ||
<div> | ||
<h5>Choose an application</h5> | ||
<form name="CreateSubscriptionForm" ng-submit="$event.preventDefault()" novalidate> | ||
<md-autocomplete | ||
md-selected-item="dialogSubscriptionCreateController.selectedApp" | ||
md-selected-item-change="dialogSubscriptionCreateController.selectedItemChange()" | ||
md-search-text="searchText" | ||
md-items="app in dialogSubscriptionCreateController.searchApplication(searchText)" | ||
md-item-text="app.name" | ||
md-min-length="3" | ||
placeholder="Search application ..." | ||
md-autofocus="true" | ||
required> | ||
<md-item-template id="searchedApp"> | ||
<span md-highlight-text="searchText" md-highlight-flags="i"> | ||
{{app.name}} ({{app.type}}) by {{app.owner.username}} | ||
</span> | ||
</md-item-template> | ||
<md-not-found> | ||
No application matching "{{searchText}}" were found. | ||
</md-not-found> | ||
</md-autocomplete> | ||
</form> | ||
</div> | ||
<h5>Select a plan</h5> | ||
<div layout="column" layout-align="start start" ng-cloak > | ||
<md-radio-group ng-model="dialogSubscriptionCreateController.selectedPlan"> | ||
<md-radio-button ng-repeat="plan in dialogSubscriptionCreateController.plans | orderBy: 'order'" | ||
value="{{plan.id}}" | ||
ng-disabled="dialogSubscriptionCreateController.planAlreadyHaveSubscriptions(plan.id)"> | ||
{{plan.name}} | ||
<md-tooltip md-direction="right"> {{plan.description}} </md-tooltip> | ||
<div ng-if="dialogSubscriptionCreateController.planAlreadyHaveSubscriptions(plan.id)" | ||
style="color:rgba(0, 0, 0, 0.54);font-size: smaller;"> | ||
There is already a <i>pending</i> or <i>accepted</i> subscription for this plan. | ||
</div> | ||
</md-radio-button> | ||
</md-radio-group> | ||
</div> | ||
</md-dialog-content> | ||
|
||
<md-dialog-actions layout="row"> | ||
<md-button type="button" ng-click="dialogSubscriptionCreateController.hide()" class="md-primary">Cancel</md-button> | ||
<md-button type="button" class="md-primary" | ||
ng-click="dialogSubscriptionCreateController.save()" | ||
ng-disabled="!dialogSubscriptionCreateController.selectedApp || !dialogSubscriptionCreateController.selectedPlan"> | ||
Create | ||
</md-button> | ||
</md-dialog-actions> | ||
</md-dialog> |
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
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
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