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

Added support for a vm to submit a custom button action #791

Merged
merged 1 commit into from
May 25, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client/app/services/custom-button/custom-button.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const CustomButtonComponent = {
bindings: {
customActions: '<',
serviceId: '<',
vmId: '<',
},
controller: CustomButtonController,
controllerAs: 'vm',
Expand All @@ -30,6 +31,11 @@ function CustomButtonController($state, EventNotifications, CollectionsApi, RBAC
button,
serviceId: vm.serviceId,
});
} else if (vm.vmId) {
const data = {action: button.name};
CollectionsApi.post('vms', vm.vmId, {}, data)
.then(postSuccess)
.catch(postFailure);
} else {
const data = {action: button.name};
CollectionsApi.post('services', vm.serviceId, {}, data)
Expand Down
44 changes: 44 additions & 0 deletions client/app/services/custom-button/custom-button.component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,47 @@ describe('CustomButton component', () => {
});
});
});

describe('Custom buttons for a VM', () => {
let parentScope, element, stateGoStub, apiPostStub;

beforeEach(module('app.services'));

beforeEach(inject(($compile, $rootScope, $state, CollectionsApi) => {
parentScope = $rootScope.$new();
parentScope.customActions = {
buttons: [
{
name: 'Bar',
visibility: {
roles: ['_ALL_'],
},
},
],
};
parentScope.serviceId = '_a service id_';
parentScope.vmId = '_a vm id_';

element = angular.element(`
<custom-button custom-actions="customActions" service-id="serviceId" vm-id="vmId">
</custom-button>
`);
$compile(element)(parentScope);
parentScope.$digest();

apiPostStub = sinon.stub(CollectionsApi, 'post').returns(Promise.resolve());
}));

it('should make a post to the vms endpoint', () => {
const button = element[0].querySelectorAll('.custom-button-action')[0];
const action = angular.element(button);

action.triggerHandler('click');
expect(apiPostStub).to.have.been.calledWith(
'vms',
'_a vm id_',
{},
{ action: 'Bar' },
);
});
});
1 change: 1 addition & 0 deletions client/app/services/vm-details/vm-details.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<div uib-dropdown class="ss-details-header__actions__inner dropdown-kebab-pf">
<custom-button ng-if="vm.hasCustomButtons()"
service-id="vm.vmDetails.service.id"
vm-id="vm.vmDetails.id"
custom-actions="vm.vmDetails.custom_actions">
</custom-button>
<custom-dropdown class="custom-dropdown pull-left"
Expand Down