feat(config-details): add the ability to clone a config (#2189)
parent
6ab6cfafb7
commit
e8ab89ae79
|
@ -32,7 +32,7 @@ angular.module('portainer.docker', ['portainer.app'])
|
|||
|
||||
var configCreation = {
|
||||
name: 'docker.configs.new',
|
||||
url: '/new',
|
||||
url: '/new?id',
|
||||
views: {
|
||||
'content@': {
|
||||
templateUrl: 'app/docker/views/configs/create/createconfig.html',
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
ng-disabled="$ctrl.state.selectedItemCount === 0" ng-click="$ctrl.removeAction($ctrl.state.selectedItems)">
|
||||
<i class="fa fa-trash-alt space-right" aria-hidden="true"></i>Remove
|
||||
</button>
|
||||
<button type="button" class="btn btn-sm btn-primary" ui-sref="docker.configs.new">
|
||||
<button type="button" class="btn btn-sm btn-primary" ui-sref="docker.configs.new">
|
||||
<i class="fa fa-plus space-right" aria-hidden="true"></i>Add config
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
angular.module('portainer.docker')
|
||||
.controller('CreateConfigController', ['$scope', '$state', 'Notifications', 'ConfigService', 'Authentication', 'FormValidator', 'ResourceControlService',
|
||||
function ($scope, $state, Notifications, ConfigService, Authentication, FormValidator, ResourceControlService) {
|
||||
|
||||
.controller('CreateConfigController', ['$scope', '$state', '$transition$', 'Notifications', 'ConfigService', 'Authentication', 'FormValidator', 'ResourceControlService',
|
||||
function ($scope, $state, $transition$, Notifications, ConfigService, Authentication, FormValidator, ResourceControlService) {
|
||||
$scope.formValues = {
|
||||
Name: '',
|
||||
Labels: [],
|
||||
|
@ -90,4 +89,30 @@ function ($scope, $state, Notifications, ConfigService, Authentication, FormVali
|
|||
$scope.editorUpdate = function(cm) {
|
||||
$scope.formValues.ConfigContent = cm.getValue();
|
||||
};
|
||||
|
||||
function initView() {
|
||||
if (!$transition$.params().id) {
|
||||
$scope.formValues.displayCodeEditor = true;
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigService.config($transition$.params().id)
|
||||
.then(function success(data) {
|
||||
$scope.formValues.Name = data.Name + '_copy';
|
||||
$scope.formValues.Data = data.Data;
|
||||
var labels = _.keys(data.Labels);
|
||||
for (var i = 0; i < labels.length; i++) {
|
||||
var labelName = labels[i];
|
||||
var labelValue = data.Labels[labelName];
|
||||
$scope.formValues.Labels.push({ name: labelName, value: labelValue});
|
||||
}
|
||||
$scope.formValues.displayCodeEditor = true;
|
||||
})
|
||||
.catch(function error(err) {
|
||||
$scope.formValues.displayCodeEditor = true;
|
||||
Notifications.error('Failure', err, 'Unable to clone config');
|
||||
});
|
||||
}
|
||||
|
||||
initView();
|
||||
}]);
|
||||
|
|
|
@ -20,12 +20,13 @@
|
|||
<!-- !name-input -->
|
||||
<!-- config-data -->
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
<div class="col-sm-12" ng-if="formValues.displayCodeEditor">
|
||||
<code-editor
|
||||
identifier="config-creation-editor"
|
||||
placeholder="Define or paste the content of your config here"
|
||||
yml="false"
|
||||
on-change="editorUpdate"
|
||||
value="formValues.Data"
|
||||
></code-editor>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<td>
|
||||
{{ config.Id }}
|
||||
<button class="btn btn-xs btn-danger" ng-click="removeConfig(config.Id)"><i class="fa fa-trash-alt space-right" aria-hidden="true"></i>Delete this config</button>
|
||||
<button class="btn btn-xs btn-primary" ui-sref="docker.configs.new({id: config.Id})"><i class="fa fa-copy space-right" aria-hidden="true"></i>Clone config</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
Loading…
Reference in New Issue