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

Add ability to edit a service instance #1324

Merged
merged 5 commits into from
Oct 27, 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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
}
context.noCancel = !!config.noCancel;
context.noSubmit = !!config.noSubmit;
context.allowEnter = config.allowEnter;

if (angular.isFunction(invalidityCheck)) {
context.invalidityCheck = invalidityCheck;
Expand Down Expand Up @@ -143,7 +144,11 @@

// Ignore enter if event has been marked with preventDefault()
vm.canUseEnter = function (ev) {
return !ev.isDefaultPrevented();
if (vm.context.allowEnter) {
return vm.context.allowEnter(vm, ev);
} else {
return !ev.isDefaultPrevented();
}
};

/**
Expand Down
7 changes: 7 additions & 0 deletions components/cloud-foundry/frontend/i18n/en_US/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@
},
"json-error-invalid": "Must be valid JSON"
},
"edit": {
"title": "Edit Service Instance",
"button": {
"yes": "Update"
},
"success": "Service instance successfully updated"
},
"view-envs": {
"title": "{{instanceName}}: Variables"
},
Expand Down
1 change: 1 addition & 0 deletions components/cloud-foundry/frontend/i18n/en_US/space.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"unmap-route-action": "Unmap Route",
"detach-service-action": "Detach Service",
"delete-service-action": "Delete Service",
"edit-service-action": "Edit Service",
"tabs": {
"show-all-button": "Show All",
"column.action": "action",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
all: all,
createServiceInstance: createServiceInstance,
deleteServiceInstance: deleteServiceInstance,
updateServiceInstance: updateServiceInstance,
listAllServiceBindingsForServiceInstance: listAllServiceBindingsForServiceInstance,
onAll: onAll
};
Expand Down Expand Up @@ -101,6 +102,25 @@
});
}

/**
* @function updateServiceInstance
* @memberof cloud-foundry.model.service-instance.ServiceInstance
* @description Update a service instance.
* @param {string} cnsiGuid - the CNSI guid
* @param {object} serviceInstanceGuid - the service instance guid of the service instance to delete
* @param {object} bindingData - the service instance data
* @param {object} params - additional params to pass to request
* @returns {promise} A promise object
* @public
*/
function updateServiceInstance(cnsiGuid, serviceInstanceGuid, bindingData, params) {
return serviceInstanceApi.UpdateServiceInstance(serviceInstanceGuid, bindingData, params,
modelUtils.makeHttpConfig(cnsiGuid))
.then(function (response) {
return response.data;
});
}

/**
* @function listAllServiceBindingsForServiceInstance
* @memberof cloud-foundry.model.service-instance.ServiceInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* @param {app.view.appNotificationsService} appNotificationsService - the toast notification service
* @param {app.framework.widgets.frameworkDetailView} frameworkDetailView - the detail view service
* @param {app.framework.widgets.dialog.frameworkDialogConfirm} frameworkDialogConfirm - the confirm dialog
* @param {object} cfServiceCreateServiceInstanceWorkflow - the cfServiceCreateServiceInstanceWorkflow service
* @returns {object} A service instance factory
*/
function serviceInstanceFactory($log, $translate, $q, modelManager, appNotificationsService, frameworkDetailView,
frameworkDialogConfirm) {
frameworkDialogConfirm, cfServiceCreateServiceInstanceWorkflow) {
var appModel = modelManager.retrieve('cloud-foundry.model.application');
var bindingModel = modelManager.retrieve('cloud-foundry.model.service-binding');
var instanceModel = modelManager.retrieve('cloud-foundry.model.service-instance');
Expand Down Expand Up @@ -204,8 +205,33 @@
frameworkDetailView(config, context);
}
});
},

/**
* @function editService
* @memberof cfServiceInstanceService
* @description Edit a service instance.
* @param {string} cnsiGuid - the CNSI guid
* @param {string} serviceInstance - the service instance
* @param {function=} callbackFunc - an optional callback function
* @returns {promise} The confirm dialog promise object
* @public
*/
editService: function (cnsiGuid, serviceInstance, callbackFunc) {
return cfServiceCreateServiceInstanceWorkflow.edit(
cnsiGuid,
serviceInstance
).then(function () {
appNotificationsService.notify('success', $translate.instant('app.app-info.app-tabs.services.edit.success'));
if (angular.isDefined(callbackFunc)) {
callbackFunc();
}
}).catch(function (error) {
$log.error('Failed to update service instance: ', error);
// Swallow error in rejected promise (most likely a failed http response) to ensure default msg is used
return $q.reject();
});
}
};
}

})();
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,13 @@ form .form-group {
}

}
}

.edit-service-instance .async-dialog {
min-height: 400px;
width: 600px;
}

.modal.detail-view.detail-view-dialog.create-service-instance-dialog.edit-service-instance>.modal-dialog .async-dialog .detail-view-content>ng-include {
flex: 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
function cfServiceCreateServiceInstanceWorkflow($q, modelManager, frameworkAsyncTaskDialog) {
var instanceModel = modelManager.retrieve('cloud-foundry.model.service-instance');
var serviceModel = modelManager.retrieve('cloud-foundry.model.service');

/**
* @function addService
Expand Down Expand Up @@ -80,6 +81,83 @@
},
doCreate
).result;
},

// function asyncDialog(config, context, submitAction, invalidityCheck, initPromise) {

edit: function (cnsiGuid, serviceInstance) {
var path = 'plugins/cloud-foundry/view/applications/workflows/create-service-instance/create-service-instance.html';
var options = {
instanceNames: [],
servicePlans: [],
userInput: {
plan: null
}
};

var doEdit = function () {
var instanceData = {
name: options.userInput.name,
tags: _.map(options.userInput.tags, function (tag) { return tag.text; })
};

if (serviceInstance.entity.service_plan_guid !== options.userInput.plan.metadata.guid) {
instanceData.service_plan_guid = options.userInput.plan.metadata.guid;
}

if (options.userInput.params) {
instanceData.parameters = options.userInput.params;
}
return instanceModel.updateServiceInstance(cnsiGuid, serviceInstance.metadata.guid, instanceData);
};

var doInitEdit = function () {
options.userInput = {
name: serviceInstance.entity.name,
tags: _.map(serviceInstance.entity.tags, function (tag) {
return {
text: tag
};
})
};

return serviceModel.allServicePlans(cnsiGuid, serviceInstance.entity.service_guid).then(function (servicePlans) {
var plans = _.map(servicePlans, function (o) { return { label: o.entity.name, value: o }; });
[].push.apply(options.servicePlans, plans);

if (options.servicePlans.length) {
options.userInput.plan = options.servicePlans[0].value;
}

// Get all of the instances so that we can check for name uniqueness
var queryOptions = { q: 'space_guid:' + serviceInstance.entity.space_guid };
return instanceModel.all(cnsiGuid, queryOptions).then(function (spaceInstances) {
options.instanceNames = _.map(spaceInstances, function (instance) { return instance.entity.name; });
});
});
};

return frameworkAsyncTaskDialog(
{
title: 'app.app-info.app-tabs.services.edit.title',
templateUrl: path,
submitCommit: true,
buttonTitles: {
submit: 'app.app-info.app-tabs.services.edit.button.yes'
},
class: 'dialog-form-larger create-service-instance-dialog edit-service-instance',
dialog: true,
allowEnter: function () {
return false;
}
},
{
options: options
},
doEdit,
undefined,
doInitEdit
).result;
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@

function getInitialActions() {
return [
{
name: 'cf.space-info.edit-service-action',
disabled: false,
execute: function (serviceInstance) {
cfServiceInstanceService.editService(vm.clusterGuid, serviceInstance, _.bind(update, vm, serviceInstance));
}
},
{
name: 'cf.space-info.delete-service-action',
disabled: false,
Expand Down Expand Up @@ -127,8 +134,8 @@
_.forEach(serviceInstances, function (si) {
if (vm.canDeleteOrUnbind) {
vm.actionsPerSI[si.metadata.guid] = vm.actionsPerSI[si.metadata.guid] || getInitialActions();
vm.actionsPerSI[si.metadata.guid][0].disabled = _.get(si.entity.service_bindings, 'length', 0) > 0 || !canDelete;
vm.actionsPerSI[si.metadata.guid][1].disabled = _.get(si.entity.service_bindings, 'length', 0) < 1 || !canUnbind;
vm.actionsPerSI[si.metadata.guid][1].disabled = _.get(si.entity.service_bindings, 'length', 0) > 0 || !canDelete;
vm.actionsPerSI[si.metadata.guid][2].disabled = _.get(si.entity.service_bindings, 'length', 0) < 1 || !canUnbind;
} else {
delete vm.actionsPerSI[si.metadata.guid];
}
Expand Down