Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TP: adds the ability to crud api endpoints for roles/capabilities management #2481

Merged
merged 3 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions traffic_portal/app/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ var trafficPortal = angular.module('trafficPortal', [
require('./modules/private/divisions/list').name,
require('./modules/private/divisions/new').name,
require('./modules/private/divisions/regions').name,
require('./modules/private/endpoints').name,
require('./modules/private/endpoints/edit').name,
require('./modules/private/endpoints/list').name,
require('./modules/private/endpoints/new').name,
require('./modules/private/iso').name,
require('./modules/private/jobs').name,
require('./modules/private/jobs/list').name,
Expand Down Expand Up @@ -232,12 +236,12 @@ var trafficPortal = angular.module('trafficPortal', [
require('./common/modules/release').name,

// forms
require('./common/modules/form/cacheGroup').name,
require('./common/modules/form/cacheGroup/edit').name,
require('./common/modules/form/cacheGroup/new').name,
require('./common/modules/form/asn').name,
require('./common/modules/form/asn/edit').name,
require('./common/modules/form/asn/new').name,
require('./common/modules/form/cacheGroup').name,
require('./common/modules/form/cacheGroup/edit').name,
require('./common/modules/form/cacheGroup/new').name,
require('./common/modules/form/capability').name,
require('./common/modules/form/capability/edit').name,
require('./common/modules/form/capability/new').name,
Expand Down Expand Up @@ -269,6 +273,9 @@ var trafficPortal = angular.module('trafficPortal', [
require('./common/modules/form/division').name,
require('./common/modules/form/division/edit').name,
require('./common/modules/form/division/new').name,
require('./common/modules/form/endpoint').name,
require('./common/modules/form/endpoint/edit').name,
require('./common/modules/form/endpoint/new').name,
require('./common/modules/form/federation').name,
require('./common/modules/form/federation/edit').name,
require('./common/modules/form/federation/new').name,
Expand Down Expand Up @@ -311,6 +318,7 @@ var trafficPortal = angular.module('trafficPortal', [
require('./common/modules/form/user/register').name,

// tables
require('./common/modules/table/asns').name,
require('./common/modules/table/cacheGroups').name,
require('./common/modules/table/cacheGroupAsns').name,
require('./common/modules/table/cacheGroupParameters').name,
Expand All @@ -320,7 +328,6 @@ var trafficPortal = angular.module('trafficPortal', [
require('./common/modules/table/capabilityEndpoints').name,
require('./common/modules/table/capabilityUsers').name,
require('./common/modules/table/changeLogs').name,
require('./common/modules/table/asns').name,
require('./common/modules/table/cdns').name,
require('./common/modules/table/cdnDeliveryServices').name,
require('./common/modules/table/cdnFederations').name,
Expand All @@ -341,6 +348,7 @@ var trafficPortal = angular.module('trafficPortal', [
require('./common/modules/table/deliveryServiceUsers').name,
require('./common/modules/table/divisions').name,
require('./common/modules/table/divisionRegions').name,
require('./common/modules/table/endpoints').name,
require('./common/modules/table/jobs').name,
require('./common/modules/table/origins').name,
require('./common/modules/table/physLocations').name,
Expand Down
46 changes: 44 additions & 2 deletions traffic_portal/app/src/common/api/EndpointService.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,55 @@
* under the License.
*/

var EndpointService = function(Restangular) {
var EndpointService = function(Restangular, locationUtils, messageModel) {

this.getEndpoints = function(queryParams) {
return Restangular.all('api_capabilities').getList(queryParams);
};

this.getEndpoint = function(id) {
return Restangular.one("api_capabilities", id).get();
};

this.createEndpoint = function(endpoint) {
return Restangular.service('api_capabilities').post(endpoint)
.then(
function() {
messageModel.setMessages([ { level: 'success', text: 'Endpoint created' } ], true);
locationUtils.navigateToPath('/endpoints');
},
function(fault) {
messageModel.setMessages(fault.data.alerts, false);
}
);
};

this.updateEndpoint = function(endpoint) {
return endpoint.put()
.then(
function() {
messageModel.setMessages([ { level: 'success', text: 'Endpoint updated' } ], false);
},
function(fault) {
messageModel.setMessages(fault.data.alerts, false);
}
);
};

this.deleteEndpoint = function(id) {
return Restangular.one("api_capabilities", id).remove()
.then(
function() {
messageModel.setMessages([ { level: 'success', text: 'Endpoint deleted' } ], true);
},
function(fault) {
messageModel.setMessages(fault.data.alerts, true);
}
);
};


};

EndpointService.$inject = ['Restangular'];
EndpointService.$inject = ['Restangular', 'locationUtils', 'messageModel'];
module.exports = EndpointService;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

var FormEndpointController = function(endpoint, $scope, formUtils, locationUtils, capabilityService) {

var getCapabilities = function() {
capabilityService.getCapabilities({ orderby: 'name' })
.then(function(result) {
$scope.capabilities = result;
});
};

$scope.endpoint = endpoint;

$scope.methods = [
{ value: 'GET', label: 'GET' },
{ value: 'POST', label: 'POST' },
{ value: 'PUT', label: 'PUT' },
{ value: 'PATCH', label: 'PATCH' },
{ value: 'DELETE', label: 'DELETE' }
];

$scope.navigateToPath = locationUtils.navigateToPath;

$scope.hasError = formUtils.hasError;

$scope.hasPropertyError = formUtils.hasPropertyError;

var init = function () {
getCapabilities();
};
init();

};

FormEndpointController.$inject = ['endpoint', '$scope', 'formUtils', 'locationUtils', 'capabilityService'];
module.exports = FormEndpointController;
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

var FormEditEndpointController = function(endpoint, $scope, $controller, $uibModal, $anchorScroll, locationUtils, endpointService) {

// extends the FormEndpointController to inherit common methods
angular.extend(this, $controller('FormEndpointController', { endpoint: endpoint, $scope: $scope }));

var deleteEndpoint = function(endpoint) {
endpointService.deleteEndpoint(endpoint.id)
.then(function() {
locationUtils.navigateToPath('/endpoints');
});
};

$scope.endpointName = angular.copy(endpoint.httpMethod) + ' ' + angular.copy(endpoint.httpRoute);

$scope.settings = {
isNew: false,
saveLabel: 'Update'
};

$scope.save = function(endpoint) {
endpointService.updateEndpoint(endpoint).
then(function() {
$scope.endpointName = angular.copy(endpoint.httpMethod) + ' ' + angular.copy(endpoint.httpRoute);
$anchorScroll(); // scrolls window to top
});
};

$scope.confirmDelete = function(endpoint) {
var params = {
title: 'Delete Endpoint: ' + endpoint.httpMethod + ' ' + endpoint.httpRoute,
key: endpoint.httpMethod + ' ' + endpoint.httpRoute
};
var modalInstance = $uibModal.open({
templateUrl: 'common/modules/dialog/delete/dialog.delete.tpl.html',
controller: 'DialogDeleteController',
size: 'md',
resolve: {
params: function () {
return params;
}
}
});
modalInstance.result.then(function() {
deleteEndpoint(endpoint);
}, function () {
// do nothing
});
};

};

FormEditEndpointController.$inject = ['endpoint', '$scope', '$controller', '$uibModal', '$anchorScroll', 'locationUtils', 'endpointService'];
module.exports = FormEditEndpointController;
21 changes: 21 additions & 0 deletions traffic_portal/app/src/common/modules/form/endpoint/edit/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

module.exports = angular.module('trafficPortal.form.endpoint.edit', [])
.controller('FormEditEndpointController', require('./FormEditEndpointController'));
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->

<div class="x_panel">
<div class="x_title">
<ol class="breadcrumb">
<li><a ng-click="navigateToPath('/endpoints')">API Endpoints</a></li>
<li class="active">{{endpointName}}</li>
</ol>
<div class="clearfix"></div>
</div>
<div class="x_content">
<br>
<form name="endpointForm" class="form-horizontal form-label-left" novalidate>
<div class="form-group" ng-class="{'has-error': hasError(endpointForm.httpMethod), 'has-feedback': hasError(endpointForm.httpMethod)}">
<label class="control-label col-md-2 col-sm-2 col-xs-12">HTTP Method *</label>
<div class="col-md-10 col-sm-10 col-xs-12">
<select name="httpMethod" class="form-control" ng-model="endpoint.httpMethod" ng-options="m.value as m.label for m in methods" required>
<option value="">Select...</option>
</select>
<small class="input-error" ng-show="hasPropertyError(endpointForm.httpMethod, 'required')">Required</small>
</div>
</div>
<div class="form-group" ng-class="{'has-error': hasError(endpointForm.httpRoute), 'has-feedback': hasError(endpointForm.httpRoute)}">
<label class="control-label col-md-2 col-sm-2 col-xs-12">HTTP Route *</label>
<div class="col-md-10 col-sm-10 col-xs-12">
<input name="httpRoute" type="text" class="form-control" placeholder="foos/*" ng-model="endpoint.httpRoute" ng-pattern="/^\S*$/" required autofocus>
<small class="input-error" ng-show="hasPropertyError(endpointForm.httpRoute, 'required')">Required</small>
<small class="input-error" ng-show="hasPropertyError(endpointForm.httpRoute, 'pattern')">No spaces</small>
<span ng-show="hasError(endpointForm.httpRoute)" class="form-control-feedback"><i class="fa fa-times"></i></span>
</div>
</div>
<div class="form-group" ng-class="{'has-error': hasError(endpointForm.capability), 'has-feedback': hasError(endpointForm.capability)}">
<label class="control-label col-md-2 col-sm-2 col-xs-12">Required Capability *</label>
<div class="col-md-10 col-sm-10 col-xs-12">
<select name="capability" class="form-control" ng-model="endpoint.capability" ng-options="c.name as c.name for c in capabilities" required>
<option value="">Select...</option>
</select>
<small class="input-error" ng-show="hasPropertyError(endpointForm.capability, 'required')">Required</small>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" ng-show="!settings.isNew" ng-click="confirmDelete(endpoint)">Delete</button>
<button type="button" class="btn btn-success" ng-disabled="endpointForm.$pristine || endpointForm.$invalid" ng-click="save(endpoint)">{{settings.saveLabel}}</button>
</div>
</form>
</div>
</div>
21 changes: 21 additions & 0 deletions traffic_portal/app/src/common/modules/form/endpoint/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

module.exports = angular.module('trafficPortal.form.endpoint', [])
.controller('FormEndpointController', require('./FormEndpointController'));
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

var FormNewEndpointController = function(endpoint, $scope, $controller, endpointService) {

// extends the FormEndpointController to inherit common methods
angular.extend(this, $controller('FormEndpointController', { endpoint: endpoint, $scope: $scope }));

$scope.endpointName = 'New';

$scope.settings = {
isNew: true,
saveLabel: 'Create'
};

$scope.save = function(endpoint) {
endpointService.createEndpoint(endpoint);
};

};

FormNewEndpointController.$inject = ['endpoint', '$scope', '$controller', 'endpointService'];
module.exports = FormNewEndpointController;