-
Notifications
You must be signed in to change notification settings - Fork 357
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 repository CRUD #346
Add repository CRUD #346
Changes from 16 commits
a727871
64016db
4519dbc
c71fa2d
c07cadf
79dd29b
16431bf
c54492a
058f3bf
e6a363b
057fc00
e662af7
6f56970
6cfd269
d63cff8
3c4b3c4
1c965d1
d754205
42cee8f
0682857
a44b77a
b905166
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
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: '', | ||
scm_credentials: 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') | ||
.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() { | ||
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() { | ||
API.put('/api/configuration_script_sources/' + repositoryId, vm.repositoryModel) | ||
.then(getBack) | ||
.catch(miqService.handleFailure); | ||
}; | ||
|
||
$scope.addClicked = function() { | ||
API.post('/api/configuration_script_sources/', vm.repositoryModel) | ||
.then(getBack) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 spaces, not three please |
||
.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) { | ||
url += '&flash_warning=false&flash_error=true'; | ||
} | ||
window.location.href = url; | ||
}; | ||
|
||
var getCredentials = function(response) { | ||
response.resources.forEach( function(resource) { | ||
vm.scm_credentials.push({name: resource.name, value: resource.href}); | ||
}); | ||
}; | ||
|
||
var getManagerResource = function(response) { | ||
vm.repositoryModel.manager_resource = {'href': response.resources[0].href}; | ||
}; | ||
init(); | ||
}]); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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) { | ||
debugger; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ZitaNemeckova same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wink wink, nudge nudge |
||
return s.substring(0, 8) === 'https://' || s.substring(0, 7) === 'http://'; | ||
}; | ||
} | ||
} | ||
}); |
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 => "new_div"), | ||
button( | ||
:embedded_configuration_script_source_edit, | ||
'pficon pficon-edit fa-lg', | ||
t = N_('Edit this Repository'), | ||
t, | ||
:enabled => false, | ||
:onwhen => "1", | ||
:url_parms => "edit_div"), | ||
button( | ||
:embedded_configuration_script_source_delete, | ||
'pficon pficon-delete fa-lg', | ||
t = N_('Remove selected Repositories'), | ||
t, | ||
:url_parms => "delete_div", | ||
:enabled => false, | ||
:onwhen => "1+", | ||
:confirm => N_("Warning: The selected Repository will be permanently removed!")), | ||
] | ||
) | ||
]) | ||
end |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
%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) | ||
.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{'ng-model' => 'vm.repositoryModel.scm_credentials', | ||
'ng-options' => 'scm_credential.value as scm_credential.name for scm_credential in vm.scm_credentials'} | ||
.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'); | ||
$("#form-div").submit(function (e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is broken since you should never be submitting the form (old-style) .. Better to just put |
||
miqSparkleOn(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#main_div | ||
= render :partial => 'repository_form', :locals => {:newRecord => false} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#main_div | ||
= render :partial => 'repository_form', :locals => {:newRecord => true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Potentially a silly question as I am not familiar with UI code)
There can be 0 or 1
scm_credential
associated with arepo/project
. Here the pluralized form, does it mean multiple values expected? Or it is the list of values to be selected from?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jameswnl there are no stupid questions :) I must have missed some change because
scm_credentials
no longer exists and there'sauthentication_id
instead. Thanks :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, feel good to be useful in UI land 😄