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

Commit

Permalink
feat(dictionary): Add global dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
brasseld authored and NicolasGeraud committed Sep 7, 2018
1 parent ceae57e commit 439219a
Show file tree
Hide file tree
Showing 17 changed files with 838 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/management-configuration-dictionaries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dictionaries

Dictionaries let you manage global properties to gateway runtime.

These properties are then available to API publisher who are able to use them from their API configuration.
16 changes: 16 additions & 0 deletions docs/management-configuration-dictionary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Dictionary

A dictionary can be MANUAL or DYNAMIC.

## MANUAL
In the case of a _manual_ dictionary, it is the responsibility of the administrator (or any user with update right) to
create / update or remove properties.

In the same, it is the responsibility of the administrator to deploy the dictionary into API Gateways.


## DYNAMIC
In the case of a _dynamic_ dictionary, properties are updated automatically according to an underlying provider.

Each time a change has been detected between previous properties and new properties, the dictionary is automatically
deployed into API Gateways and are then available during the HTTP request process.
3 changes: 2 additions & 1 deletion src/management/api/apiAdmin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import UserService from '../../services/user.service';
import NotificationService from "../../services/notification.service";
import ApiService from "../../services/api.service";
import {IScope} from "angular";
import { StateService } from '@uirouter/core';

import { StateService } from "@uirouter/core";

class ApiAdminController {
private api: any;
Expand Down
52 changes: 52 additions & 0 deletions src/management/configuration/configuration.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import NotificationSettingsService from "../../services/notificationSettings.ser
import TopApiService from "../../services/top-api.service";
import UserService from "../../services/user.service";
import ApiService from "../../services/api.service";
import DictionaryService from "../../services/dictionary.service";
import _ = require('lodash');

export default configurationRouterConfig;
Expand Down Expand Up @@ -431,5 +432,56 @@ function configurationRouterConfig($stateProvider) {
only: ['portal-settings-r']
}
}
})
.state('management.settings.dictionaries', {
abstract: true,
url: '/dictionaries'
})
.state('management.settings.dictionaries.list', {
url: '/',
component: 'dictionaries',
resolve: {
dictionaries: (DictionaryService: DictionaryService) =>
DictionaryService.list().then(response => response.data)
},
data: {
menu: null,
docs: {
page: 'management-configuration-dictionaries'
},
perms: {
only: ['management-dictionary-r']
}
}
})
.state('management.settings.dictionaries.new', {
url: '/new',
component: 'dictionary',
data: {
menu: null,
docs: {
page: 'management-configuration-dictionary'
},
perms: {
only: ['management-dictionary-c']
}
}
})
.state('management.settings.dictionaries.dictionary', {
url: '/:dictionaryId',
component: 'dictionary',
resolve: {
dictionary: (DictionaryService: DictionaryService, $stateParams) =>
DictionaryService.get($stateParams.dictionaryId).then(response => response.data)
},
data: {
menu: null,
docs: {
page: 'management-configuration-dictionary'
},
perms: {
only: ['management-dictionary-c', 'management-dictionary-r', 'management-dictionary-u', 'management-dictionary-d']
}
}
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 DialogDictionaryAddPropertyController($scope, $mdDialog) {
'ngInject';

this.hide = function () {
$mdDialog.hide();
};

this.save = function () {
let property = {
key: $scope.property.name,
value: $scope.property.value
};

$mdDialog.hide(property);
};
}

export default DialogDictionaryAddPropertyController;
41 changes: 41 additions & 0 deletions src/management/configuration/dictionaries/add-property.dialog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
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="New property">
<form name="formDictionaryProperty" ng-submit="dialogDictionaryAddPropertyCtrl.save()" novalidate>
<md-dialog-content layout-padding>
<h4>New property</h4>
<md-input-container>
<label>Name</label>
<input ng-model="property.name" id="key" required>
</md-input-container>
<md-input-container>
<label>Value</label>
<input ng-model="property.value" id="value" required>
</md-input-container>
</md-dialog-content>

<md-dialog-actions layout="row">
<md-button ng-click="dialogDictionaryAddPropertyCtrl.hide()" class="md-primary">
Cancel
</md-button>
<md-button type="submit" class="md-raised md-primary" ng-disabled="formDictionaryProperty.$invalid">
Add
</md-button>
</md-dialog-actions>
</form>
</md-dialog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/
const DictionariesComponent: ng.IComponentOptions = {
bindings: {
dictionaries: '<'
},
controller: 'DictionariesController',
template: require('./dictionaries.html')
};

export default DictionariesComponent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 { StateService } from "@uirouter/core";

class DictionariesController {

constructor(
private $state: StateService
) {
'ngInject';
}

select = (dictionary) => {
this.$state.go('management.settings.dictionaries.dictionary', {dictionaryId: dictionary.id});
}

}

export default DictionariesController;
69 changes: 69 additions & 0 deletions src/management/configuration/dictionaries/dictionaries.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!--
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-toolbar class="md-table-toolbar md-default">
<div class="md-toolbar-tools">
<span>Dictionaries</span>
<div flex></div>
</div>
</md-toolbar>

<md-table-container ng-if="$ctrl.dictionaries.length > 0">
<table md-table>
<thead md-head>
<tr md-row>
<th md-column>ID</th>
<th md-column>Name</th>
<th md-column>Description</th>
<th md-column>Type</th>
<th md-column>Number of properties</th>
<th md-column>Last updated at</th>
<th md-column>Last deployment at</th>
</tr>
</thead>
<tbody md-body>
<tr md-row ng-repeat="dictionary in $ctrl.dictionaries | orderBy: name" ng-click="$ctrl.select(dictionary)">
<td md-cell>{{dictionary.id}}</td>
<td md-cell>{{dictionary.name}}</td>
<td md-cell>{{dictionary.description}}</td>
<td md-cell>
{{dictionary.type}}
<span permission permission-only="['management-dictionary-u']" ng-if="dictionary.type === 'dynamic' && dictionary.state === 'started'" style="color: #429f46;"> - Started</span>
<span permission permission-only="['management-dictionary-u']" ng-if="dictionary.type === 'dynamic' && dictionary.state !== 'started'" style="color: red"> - Stopped</span>
</td>
<td md-cell>{{dictionary.properties}}</td>
<td md-cell>{{dictionary.updated_at | date:'MMM d, y h:mm:ss a'}}</td>
<td md-cell>{{(dictionary.deployed_at | date:'MMM d, y h:mm:ss a') || '-'}}</td>
</tr>
</tbody>
</table>
</md-table-container>

<gravitee-empty-state ng-if="$ctrl.dictionaries.length === 0"
icon="assignment"
model="Dictionary"
message="Dictionaries will appear here"
sub-message="Start creating a dictionary"
create-mode="true"></gravitee-empty-state>

<md-button permission permission-only="'management-dictionary-c'"
aria-label="Add dictionary"
class="md-fab md-fab-bottom-right gravitee-add-button"
ui-sref="management.settings.dictionaries.new">
<md-tooltip md-direction="top" md-visible="false">Add a new dictionary</md-tooltip>
<ng-md-icon icon="add"></ng-md-icon>
</md-button>
24 changes: 24 additions & 0 deletions src/management/configuration/dictionaries/dictionary.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/
const DictionaryComponent: ng.IComponentOptions = {
bindings: {
dictionary: '<'
},
controller: 'DictionaryController',
template: require('./dictionary.html')
};

export default DictionaryComponent;
Loading

0 comments on commit 439219a

Please sign in to comment.