-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #346 from ZitaNemeckova/repository_form
Add repository CRUD
- Loading branch information
Showing
9 changed files
with
360 additions
and
1 deletion.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
app/assets/javascripts/controllers/ansible_repository/repository_form_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
ManageIQ.angular.app.controller('repositoryFormController', ['$scope', 'repositoryId', 'miqService', 'API', function($scope, repositoryId, miqService, API) { | ||
var vm = this; | ||
|
||
var init = function() { | ||
vm.afterGet = false; | ||
|
||
vm.repositoryModel = { | ||
name: '', | ||
description: '', | ||
scm_type: 'git', | ||
manager_resource: {}, | ||
scm_url: '', | ||
authentication_id: null, | ||
scm_branch: '', | ||
scm_clean: false, | ||
scm_delete_on_update: false, | ||
scm_update_on_launch: false, | ||
}; | ||
|
||
API.get('/api/providers?collection_class=ManageIQ::Providers::EmbeddedAutomationManager') | ||
.then(getManagerResource) | ||
.catch(miqService.handleFailure); | ||
|
||
vm.model = 'repositoryModel'; | ||
|
||
ManageIQ.angular.scope = vm; | ||
|
||
$scope.newRecord = repositoryId === 'new'; | ||
|
||
vm.scm_credentials = [{name: __('Select credentials'), value: null}]; | ||
API.get('/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ScmCredential&expand=resources&sort_by=name&sort_order=ascending') | ||
.then(getCredentials) | ||
.catch(miqService.handleFailure); | ||
|
||
if (repositoryId !== 'new') { | ||
API.get('/api/configuration_script_sources/' + repositoryId) | ||
.then(getRepositoryFormData) | ||
.catch(miqService.handleFailure); | ||
} else { | ||
vm.afterGet = true; | ||
vm.modelCopy = angular.copy( vm.repositoryModel ); | ||
miqService.sparkleOff(); | ||
} | ||
}; | ||
|
||
$scope.cancelClicked = function() { | ||
miqService.sparkleOn(); | ||
var message = $scope.newRecord ? __('Add of Repository cancelled by user.') : sprintf(__('Edit of Repository \"%s\" cancelled by user.'), vm.repositoryModel.name); | ||
var url = '/ansible_repository/show_list' + '?flash_msg=' + message + '&escape=true&flash_warning=true&flash_error=false'; | ||
window.location.href = url; | ||
}; | ||
|
||
$scope.resetClicked = function() { | ||
vm.repositoryModel = angular.copy( vm.modelCopy ); | ||
$scope.angularForm.$setPristine(true); | ||
miqService.miqFlash('warn', __('All changes have been reset')); | ||
}; | ||
|
||
$scope.saveClicked = function() { | ||
miqService.sparkleOn(); | ||
API.put('/api/configuration_script_sources/' + repositoryId, vm.repositoryModel) | ||
.then(getBack) | ||
.catch(miqService.handleFailure); | ||
}; | ||
|
||
$scope.addClicked = function() { | ||
miqService.sparkleOn(); | ||
API.post('/api/configuration_script_sources/', vm.repositoryModel) | ||
.then(getBack) | ||
.catch(miqService.handleFailure); | ||
}; | ||
|
||
var getRepositoryFormData = function(response) { | ||
var data = response; | ||
Object.assign(vm.repositoryModel, data); | ||
vm.modelCopy = angular.copy( vm.repositoryModel ); | ||
vm.afterGet = true; | ||
miqService.sparkleOff(); | ||
}; | ||
|
||
var getBack = function(response) { | ||
var message = ''; | ||
var error = false; | ||
if (response.hasOwnProperty('results')) { | ||
error = ! response.results[0].success; | ||
if (error) { | ||
message = __('Unable to add Repository ') + vm.repositoryModel.name + ' .' + response.results[0].message; | ||
} else { | ||
message = sprintf(__('Add of Repository \"%s\" was successfully initialized.'), vm.repositoryModel.name); | ||
} | ||
} else { | ||
error = ! response.success; | ||
if (error) { | ||
message = __('Unable to edit Repository') + vm.repositoryModel.name + ' .' + response.message; | ||
} else { | ||
message = sprintf(__('Edit of Repository \"%s\" was successfully initialized.'), vm.repositoryModel.name); | ||
} | ||
} | ||
var url = '/ansible_repository/show_list' + '?flash_msg=' + message + '&escape=true'; | ||
if (error) { | ||
miqService.miqFlash('error', message); | ||
miqService.sparkleOff(); | ||
} else { | ||
window.location.href = url; | ||
} | ||
}; | ||
|
||
var getCredentials = function(response) { | ||
response.resources.forEach( function(resource) { | ||
vm.scm_credentials.push({name: resource.name, value: resource.id}); | ||
}); | ||
}; | ||
|
||
var getManagerResource = function(response) { | ||
if (!response.resources.length) { | ||
miqService.miqFlash('error', __('Embedded Ansible Provider not found.')); | ||
} else { | ||
vm.repositoryModel.manager_resource = {'href': response.resources[0].href}; | ||
} | ||
}; | ||
init(); | ||
}]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ManageIQ.angular.app.directive('urlValidation', function() { | ||
return { | ||
require: 'ngModel', | ||
link: function (_scope, _elem, _attrs, ctrl) { | ||
ctrl.$validators.urlValidation = function (modelValue, viewValue) { | ||
if (!viewValue) { | ||
return true; | ||
} | ||
return validUrl(viewValue); | ||
}; | ||
|
||
var validUrl = function(s) { | ||
return s.substring(0, 8) === 'https://' || s.substring(0, 7) === 'http://'; | ||
}; | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/helpers/application_helper/toolbar/ansible_repositories_center.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class ApplicationHelper::Toolbar::AnsibleRepositoriesCenter < ApplicationHelper::Toolbar::Basic | ||
button_group('ansible_repositories', [ | ||
select( | ||
:ansible_repositories_configuration, | ||
'fa fa-cog fa-lg', | ||
t = N_('Configuration'), | ||
t, | ||
:items => [ | ||
button( | ||
:embedded_configuration_script_source_add, | ||
'pficon pficon-edit fa-lg', | ||
t = N_('Add New Repository'), | ||
t, | ||
:url_parms => "unused_div"), | ||
button( | ||
:embedded_configuration_script_source_edit, | ||
'pficon pficon-edit fa-lg', | ||
t = N_('Edit this Repository'), | ||
t, | ||
:enabled => false, | ||
:onwhen => "1", | ||
:url_parms => "unused_div"), | ||
button( | ||
:embedded_configuration_script_source_delete, | ||
'pficon pficon-delete fa-lg', | ||
t = N_('Remove selected Repositories'), | ||
t, | ||
:url_parms => "unused_div", | ||
:enabled => false, | ||
:onwhen => "1+", | ||
:confirm => N_("Warning: The selected Repository will be permanently removed!")), | ||
] | ||
) | ||
]) | ||
end |
25 changes: 25 additions & 0 deletions
25
app/helpers/application_helper/toolbar/ansible_repository_center.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class ApplicationHelper::Toolbar::AnsibleRepositoryCenter < ApplicationHelper::Toolbar::Basic | ||
button_group('ansible_repository', [ | ||
select( | ||
:ansible_repository_configuration, | ||
'fa fa-cog fa-lg', | ||
t = N_('Configuration'), | ||
t, | ||
:items => [ | ||
button( | ||
:embedded_configuration_script_source_edit, | ||
'pficon pficon-edit fa-lg', | ||
t = N_('Edit this Repository'), | ||
t, | ||
:url => "/edit"), | ||
button( | ||
:embedded_configuration_script_source_delete, | ||
'pficon pficon-delete fa-lg', | ||
t = N_('Remove this Repository'), | ||
t, | ||
:url_parms => "&refresh=y", | ||
:confirm => N_("Warning: The selected Repository will be permanently removed!")), | ||
] | ||
), | ||
]) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
%br | ||
%br | ||
.form-horizontal | ||
%form#form_div{:name => "angularForm", | ||
'ng-controller' => "repositoryFormController as vm", | ||
'ng-show' => "vm.afterGet", | ||
'ng-cloak' => '', | ||
"miq-form" => true, | ||
"model" => "vm.repositoryModel", | ||
"model-copy" => 'vm.modelCopy', | ||
:novalidate => true} | ||
= render :partial => "layouts/flash_msg" | ||
.form-group{"ng-class" => "{'has-error': angularForm.name.$invalid}"} | ||
%label.col-md-2.control-label | ||
= _('Name') | ||
.col-md-8 | ||
%input.form-control{:type => "text", | ||
:name => "name", | ||
"id" => "name", | ||
'ng-model' => "vm.repositoryModel.name", | ||
:maxlength => MAX_NAME_LEN, | ||
:required => "", | ||
:checkchange => true} | ||
%span.help-block{"ng-show" => "angularForm.name.$error.required"} | ||
= _("Required") | ||
.form-group | ||
%label.col-md-2.control-label | ||
= _('Description') | ||
.col-md-8 | ||
%input.form-control{:type => "text", | ||
:name => "description", | ||
"id" => "description", | ||
'ng-model' => "vm.repositoryModel.description", | ||
:checkchange => true} | ||
.form-group | ||
%label.col-md-2.control-label | ||
= _('SCM type') | ||
.col-md-8 | ||
= select_tag('scm_type', | ||
options_for_select([[_("GIT"), "git"]], 'git'), | ||
"ng-model" => "vm.repositoryModel.scm_type", | ||
:disabled => true, | ||
:checkchange => true, | ||
'pf-select' => true) | ||
.form-group{"ng-class" => "{'has-error': angularForm.scm_url.$error.required || angularForm.scm_url.$error.urlValidation}"} | ||
%label.col-md-2.control-label | ||
= _('URL') | ||
.col-md-8 | ||
%input.form-control{:type => "text", | ||
:name => "scm_url", | ||
:id => "scm_url", | ||
'ng-model' => "vm.repositoryModel.scm_url", | ||
:required => "", | ||
:checkchange => true, | ||
'url-validation' => true} | ||
%span.help-block{"ng-show" => "angularForm.scm_url.$error.required"} | ||
= _("Required") | ||
%span.help-block{"ng-show" => "angularForm.scm_url.$error.urlValidation"} | ||
= _("URL must include a protocol (http:// or https://)") | ||
.form-group | ||
%label.col-md-2.control-label | ||
= _('SCM credentials') | ||
.col-md-8 | ||
%select{'name' => 'authentication_id', | ||
'ng-model' => 'vm.repositoryModel.authentication_id', | ||
'ng-options' => 'scm_credential.value as scm_credential.name for scm_credential in vm.scm_credentials', | ||
:checkchange => true, | ||
'pf-select' => true} | ||
.form-group | ||
%label.col-md-2.control-label | ||
= _('SCM Branch') | ||
.col-md-8 | ||
%input.form-control{:type => "text", | ||
:name => "scm_branch", | ||
"id" => "scm_branch", | ||
'ng-model' => "vm.repositoryModel.scm_branch", | ||
:checkchange => true} | ||
.form-group | ||
%label.col-md-2.control-label | ||
= _('SCM Update Options') | ||
.col-md-8 | ||
%div | ||
%label | ||
= check_box_tag("clean", "1", false, 'ng-model' => "vm.repositoryModel.scm_clean") | ||
= _('Clean') | ||
%div | ||
%label | ||
= check_box_tag("scm_delete_on_update", "1", false, 'ng-model' => 'vm.repositoryModel.scm_delete_on_update') | ||
= _('Delete on Update') | ||
%div | ||
%label | ||
= check_box_tag("scm_update_on_launch", "1", false, 'ng-model' => 'vm.repositoryModel.scm_update_on_launch') | ||
= _('Update on Launch') | ||
= render :partial => "layouts/angular/x_edit_buttons_angular" | ||
:javascript | ||
ManageIQ.angular.app.value('repositoryId', '#{@id}'); | ||
miq_bootstrap('#form_div'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#main_div | ||
= render :partial => 'repository_form' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#main_div | ||
= render :partial => 'repository_form' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters