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

Commit

Permalink
feat: Allows to search subscriptions by api key
Browse files Browse the repository at this point in the history
  • Loading branch information
aelamrani committed Aug 30, 2019
1 parent eda9b01 commit 48197f4
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 29 deletions.
20 changes: 16 additions & 4 deletions src/management/api/portal/apis.portal.route.ts
Expand Up @@ -128,7 +128,7 @@ function apisPortalRouterConfig($stateProvider) {
}
})
.state('management.apis.detail.portal.subscriptions.list', {
url: '?page&size&:application&:status&:plan',
url: '?page&size&:application&:status&:plan&:api_key',
component: 'apiSubscriptions',
resolve: {
subscriptions: ($stateParams, ApiService: ApiService) => {
Expand All @@ -140,14 +140,18 @@ function apisPortalRouterConfig($stateProvider) {
}

if ($stateParams["application"]) {
query += "&application=" + $stateParams["application"]
query += "&application=" + $stateParams["application"];
}

if ($stateParams["plan"]) {
query += "&plan=" + $stateParams["plan"];
}

return ApiService.getSubscriptions($stateParams.apiId, query).then(response => response.data)
if ($stateParams["api_key"]) {
query += "&api_key=" + $stateParams["api_key"];
}

return ApiService.getSubscriptions($stateParams.apiId, query).then(response => response.data);
},

subscribers: ($stateParams, ApiService: ApiService) =>
Expand Down Expand Up @@ -186,11 +190,15 @@ function apisPortalRouterConfig($stateProvider) {
type: 'int',
value: 10,
dynamic: true
},
api_key: {
type: "string",
dynamic: true
}
}
})
.state('management.apis.detail.portal.subscriptions.subscription', {
url: '/:subscriptionId?:page&:size&:application&:status&:plan',
url: '/:subscriptionId?:page&:size&:application&:status&:plan&:api_key',
component: 'apiSubscription',
resolve: {
subscription: ($stateParams, ApiService: ApiService) =>
Expand Down Expand Up @@ -226,6 +234,10 @@ function apisPortalRouterConfig($stateProvider) {
type: 'int',
value: 10,
dynamic: true
},
api_key: {
type: "string",
dynamic: true
}
}
})
Expand Down
Expand Up @@ -47,9 +47,9 @@ const ApiSubscriptionComponent: ng.IComponentOptions = {
plan: $state.params['plan'],
status: $state.params['status'],
page: $state.params['page'],
size: $state.params['size']
size: $state.params['size'],
api_key: $state.params['api_key']
};
console.log(this.backStateParams)
}

$onInit() {
Expand Down
35 changes: 27 additions & 8 deletions src/management/api/portal/subscriptions/subscriptions.component.ts
Expand Up @@ -20,12 +20,15 @@ import { PagedResult } from "../../../../entities/pagedResult";
import { StateService } from '@uirouter/core';
import * as moment from 'moment';

let defaultStatus = ['ACCEPTED', 'PENDING', 'PAUSED'];

export class SubscriptionQuery {
status?: string[] = ['ACCEPTED', 'PENDING', 'PAUSED'];
status?: string[] = defaultStatus;
applications?: string[];
plans?: string[];
page?: number = 1;
size?: number = 10;
api_key?: string;
}

const ApiSubscriptionsComponent: ng.IComponentOptions = {
Expand Down Expand Up @@ -63,27 +66,30 @@ const ApiSubscriptionsComponent: ng.IComponentOptions = {
'ngInject';

this.onPaginate = this.onPaginate.bind(this);
if(this.$state.params["status"]) {
if (this.$state.params["status"]) {
if (Array.isArray(this.$state.params["status"])) {
this.query.status = this.$state.params["status"];
} else {
this.query.status = [this.$state.params["status"]];
this.query.status = this.$state.params["status"].split(',');
}
}
if(this.$state.params["application"]) {
if (this.$state.params["application"]) {
if (Array.isArray(this.$state.params["application"])) {
this.query.applications = this.$state.params["application"];
} else {
this.query.applications = [this.$state.params["application"]];
this.query.applications = this.$state.params["application"].split(',');
}
}
if(this.$state.params["plan"]) {
if (this.$state.params["plan"]) {
if (Array.isArray(this.$state.params["plan"])) {
this.query.plans = this.$state.params["plan"];
} else {
this.query.plans = [this.$state.params["plan"]];
this.query.plans = this.$state.params["plan"].split(',');
}
}
if (this.$state.params["api_key"]) {
this.query.api_key = this.$state.params["api_key"];
}
}

$onInit() {
Expand Down Expand Up @@ -123,6 +129,10 @@ const ApiSubscriptionsComponent: ng.IComponentOptions = {
parameters['plan'] = this.query.plans.join(',');
}

if (this.query.api_key !== undefined) {
parameters['api_key'] = this.query.api_key;
}

_.mapKeys(parameters, (value, key ) => {
return query += key + '=' + value + '&';
});
Expand All @@ -139,7 +149,8 @@ const ApiSubscriptionsComponent: ng.IComponentOptions = {
application: this.query.applications ? this.query.applications.join(",") : "",
plan: this.query.plans ? this.query.plans.join(",") : "",
page: this.query.page,
size: this.query.size
size: this.query.size,
api_key: this.query.api_key
}),
{notify: false});

Expand Down Expand Up @@ -223,6 +234,14 @@ const ApiSubscriptionsComponent: ng.IComponentOptions = {
document.getElementById('hidden-export-container').removeChild(hiddenElement);
});
}

hasFilter() {
return _.difference(defaultStatus, this.query.status).length > 0
|| _.difference(this.query.status, defaultStatus).length > 0
|| (this.query.applications && this.query.applications.length)
|| (this.query.plans && this.query.plans.length)
|| this.query.api_key;
}
}
};

Expand Down
13 changes: 9 additions & 4 deletions src/management/api/portal/subscriptions/subscriptions.html
Expand Up @@ -23,13 +23,13 @@ <h2></h2>
<div class="gv-filters" flex>
<form ng-submit="$ctrl.search()" name="$ctrl.subscriptionsFiltersForm">
<div layout-gt-sm="row">
<md-input-container class="md-block" flex-gt-sm flex="30">
<md-input-container class="md-block" flex-gt-sm flex="20">
<label>Plan</label>
<md-select ng-model="$ctrl.query.plans" placeholder="Plans" multiple>
<md-option ng-value="plan.id" ng-repeat="plan in $ctrl.plans track by plan.id">{{ plan.name }}</md-option>
</md-select>
</md-input-container>
<md-input-container class="md-block" flex-gt-sm flex="30">
<md-input-container class="md-block" flex-gt-sm flex="20">
<label>Application</label>
<md-select ng-model="$ctrl.query.applications" placeholder="Applications" multiple>
<md-option ng-value="subscriber.id" ng-repeat="subscriber in $ctrl.subscribers track by subscriber.id">{{ subscriber.name }}</md-option>
Expand All @@ -41,11 +41,15 @@ <h2></h2>
<md-option ng-value="key" ng-repeat="(key, value) in $ctrl.status">{{ value }}</md-option>
</md-select>
</md-input-container>
<md-input-container class="md-block" flex-gt-sm flex="20">
<label>API key</label>
<input ng-model="$ctrl.query.api_key">
</md-input-container>
<div>
<md-button type="submit" class="md-raised md-primary">
Search
</md-button>
<md-button type="button" class="md-raised" ng-click="$ctrl.clearFilters()" ng-disabled="$ctrl.subscriptionsFiltersForm.$pristine">
<md-button type="button" class="md-raised" ng-click="$ctrl.clearFilters()" ng-disabled="!$ctrl.hasFilter()">
Clear
</md-button>
<md-button type="button" class="md-raised" ng-click="$ctrl.exportAsCSV()" ng-disabled="!$ctrl.subscriptions.data || $ctrl.subscriptions.data.length === 0">
Expand Down Expand Up @@ -82,7 +86,8 @@ <h2></h2>
size: $ctrl.query.size,
status: $ctrl.query.status,
application: $ctrl.query.applications,
plan: $ctrl.query.plans
plan: $ctrl.query.plans,
api_key: $ctrl.query.api_key
})">
{{$ctrl.subscriptions.metadata[subscription.plan].name}}
</a>
Expand Down
16 changes: 14 additions & 2 deletions src/management/application/applications.route.ts
Expand Up @@ -116,7 +116,7 @@ function applicationsConfig($stateProvider) {
template: '<div ui-view></div>'
})
.state('management.applications.application.subscriptions.list', {
url: '?page&size&:api&:status',
url: '?page&size&:api&:status&:api_key',
component: 'applicationSubscriptions',
resolve: {
subscriptions: ($stateParams, ApplicationService: ApplicationService) => {
Expand All @@ -131,6 +131,10 @@ function applicationsConfig($stateProvider) {
query += "&api=" + $stateParams["api"]
}

if ($stateParams["api_key"]) {
query += "&api_key=" + $stateParams["api_key"];
}

return ApplicationService.listSubscriptions($stateParams.applicationId, query).then(response => response.data)
},

Expand Down Expand Up @@ -168,11 +172,15 @@ function applicationsConfig($stateProvider) {
type: 'int',
value: 10,
dynamic: true
},
api_key: {
type: 'string',
dynamic: true
}
}
})
.state('management.applications.application.subscriptions.subscription', {
url: '/:subscriptionId?page&size&:api&:status',
url: '/:subscriptionId?page&size&:api&:status&:api_key',
component: 'applicationSubscription',
resolve: {
subscription: ($stateParams, ApplicationService: ApplicationService) =>
Expand Down Expand Up @@ -204,6 +212,10 @@ function applicationsConfig($stateProvider) {
type: 'int',
value: 10,
dynamic: true
},
api_key: {
type: 'string',
dynamic: true
}
}
})
Expand Down
Expand Up @@ -42,7 +42,8 @@ const ApplicationSubscriptionComponent: ng.IComponentOptions = {
api: $state.params['api'],
status: $state.params['status'],
page: $state.params['page'],
size: $state.params['size']
size: $state.params['size'],
api_key: $state.params['api_key']
};
}

Expand Down
Expand Up @@ -22,8 +22,10 @@ import ApiService from '../../../../services/api.service';
import { PagedResult } from "../../../../entities/pagedResult";
import { StateService } from '@uirouter/core';

let defaultStatus = ['ACCEPTED', 'PENDING', 'PAUSED'];

export class SubscriptionQuery {
status?: string[] = ['ACCEPTED', 'PENDING','PAUSED'];
status?: string[] = defaultStatus;
apis?: string[];
page?: number = 1;
size?: number = 10;
Expand Down Expand Up @@ -57,20 +59,23 @@ class ApplicationSubscriptionsController {
'ngInject';

this.onPaginate = this.onPaginate.bind(this);
if(this.$state.params["status"]) {
if (this.$state.params["status"]) {
if (Array.isArray(this.$state.params["status"])) {
this.query.status = this.$state.params["status"];
} else {
this.query.status = [this.$state.params["status"]];
this.query.status = this.$state.params["status"].split(',');
}
}
if(this.$state.params["api"]) {
if (this.$state.params["api"]) {
if (Array.isArray(this.$state.params["api"])) {
this.query.apis = this.$state.params["api"];
} else {
this.query.apis = [this.$state.params["api"]];
this.query.apis = this.$state.params["api"].split(',');
}
}
if (this.$state.params["api_key"]) {
this.query.api_key = this.$state.params["api_key"];
}
}

onPaginate(page) {
Expand Down Expand Up @@ -102,6 +107,10 @@ class ApplicationSubscriptionsController {
parameters['api'] = this.query.apis.join(',');
}

if (this.query.api_key !== undefined) {
parameters['api_key'] = this.query.api_key;
}

_.mapKeys(parameters, (value, key ) => {
return query += key + '=' + value + '&';
});
Expand All @@ -117,7 +126,8 @@ class ApplicationSubscriptionsController {
status: this.query.status ? this.query.status.join(",") : "",
api: this.query.apis ? this.query.apis.join(",") : "",
page: this.query.page,
size: this.query.size
size: this.query.size,
api_key: this.query.api_key
}),
{notify: false});

Expand Down Expand Up @@ -226,6 +236,14 @@ class ApplicationSubscriptionsController {
});
});
}

hasFilter() {
return _.difference(defaultStatus, this.query.status).length > 0
|| _.difference(this.query.status, defaultStatus).length > 0
|| (this.query.applications && this.query.applications.length)
|| (this.query.plans && this.query.plans.length)
|| this.query.api_key;
}
}

export default ApplicationSubscriptionsController;
Expand Up @@ -35,11 +35,15 @@ <h2>Subscriptions</h2>
<md-option ng-value="key" ng-repeat="(key, value) in $ctrl.status">{{ value }}</md-option>
</md-select>
</md-input-container>
<md-input-container class="md-block" flex-gt-sm flex="20">
<label>API key</label>
<input ng-model="$ctrl.query.api_key">
</md-input-container>
<div>
<md-button type="submit" class="md-raised md-primary">
Search
</md-button>
<md-button type="button" class="md-raised" ng-click="$ctrl.clearFilters()" ng-disabled="$ctrl.subscriptionsFiltersForm.$pristine">
<md-button type="button" class="md-raised" ng-click="$ctrl.clearFilters()" ng-disabled="!$ctrl.hasFilter()">
Clear
</md-button>
</div>
Expand All @@ -66,7 +70,8 @@ <h2>Subscriptions</h2>
page: $ctrl.query.page,
size: $ctrl.query.size,
status: $ctrl.query.status,
api: $ctrl.query.apis})">
api: $ctrl.query.apis,
api_key: $ctrl.query.api_key})">
{{$ctrl.subscriptions.metadata[subscription.api].name}}
</a>
</td>
Expand Down

0 comments on commit 48197f4

Please sign in to comment.