Skip to content

Commit

Permalink
Add repository_form template and its js controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ZitaNemeckova committed Feb 27, 2017
1 parent 1613524 commit 6e1f411
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
ManageIQ.angular.app.controller('repositoryFormController', ['$http', '$scope', 'repositoryId', 'miqService', function($http, $scope, repositoryId, miqService) {
var vm = this;

var init = function() {
vm.repositoryModel = {
name: '',
description: '',
scm_type: '',
url: '',
scm_credentials: '',
branch: '',
clean: false,
deleteOnUpdate: false,
updateOnLaunch: false,
};

vm.afterGet = false;

vm.model = 'repositoryModel';
vm.newRecord = false;

ManageIQ.angular.scope = vm;

miqService.sparkleOn();
// TODO change to API
if (repositoryId != 'new') {
$http.get('/ansible_repository/dummy_data')
.then(getRepositoryFormData)
.catch(miqService.handleFailure);
}
else {
vm.afterGet = true;
vm.modelCopy = angular.copy( vm.repositoryModel );
}
};

$scope.cancelClicked = function() {
// TODO go back
};

$scope.resetClicked = function() {
debugger;
vm.repositoryModel = angular.copy( vm.modelCopy );
$scope.angularForm.$setPristine(true);
miqService.miqFlash("warn", __("All changes have been reset"));
};

$scope.saveClicked = function() {
$scope.angularForm.$setPristine(true);
};

$scope.addClicked = function() {
// URL is different from save, maybe?
$scope.saveClicked();
};

function getRepositoryFormData(response) {
var data = response.data;

Object.assign(vm.repositoryModel, data);

$scope.afterGet = true;
vm.modelCopy = angular.copy(vm.repositoryModel);

miqService.sparkleOff();
}

init();
}]);

28 changes: 28 additions & 0 deletions app/controllers/ansible_repository_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,34 @@ def self.model
ConfigurationScriptSource
end

def get_session_data
@center_toolbar = 'ansible_repositories'
super
end

def edit
@in_a_form = true
@record = ConfigurationScriptSource.all[0]
binding.pry
end

def new
@in_a_form = true
end

def dummy_data
@record = ConfigurationScriptSource.all[0]
render :json => { :name => @record.name,
:description => @record.description,
scm_type: 'Troll',
url: 'localhost:3000',
scm_credentials: 'nope',
branch: 'none',
clean: true,
deleteOnUpdate: true,
updateOnLaunch: true,}
end

def display_playbooks
nested_list("ansible_playbook", ManageIQ::Providers::AnsibleTower::AutomationManager::Playbook)
end
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/application_helper/button/ansible_repository.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ApplicationHelper::Button::AnsibleRepository < ApplicationHelper::Button::Basic
def disabled?
@record.nil?
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class ApplicationHelper::Toolbar::AnsibleRepositoriesCenter < ApplicationHelper::Toolbar::Basic
button_group('ansible_repository', [
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 => "/new"),
button(
:embedded_configuration_script_source_edit,
'pficon pficon-edit fa-lg',
t = N_('Edit this Repository'),
t,
:klass => ApplicationHelper::Button::AnsibleRepository,
:onwhen => "1",
:url => "/edit"),
button(
:embedded_configuration_script_source_delete,
'pficon pficon-delete fa-lg',
t = N_('Remove selected Repositories'),
t,
:klass => ApplicationHelper::Button::AnsibleRepository,
:url_parms => "&refresh=y",
: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('auth_key_pair_cloud_vmdb', [
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
8 changes: 8 additions & 0 deletions app/helpers/application_helper/toolbar_chooser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,14 @@ def inventory_group_center_tb
end
end

def ansible_repository_center_tb
"ansible_repository_center_tb"
end

def ansible_repositories_center_tb
"ansible_repositories_center_tb"
end

def unassigned_configuration_profile_node(nodes)
configuration_profile_center_tb if nodes[2] == "unassigned"
end
Expand Down
98 changes: 98 additions & 0 deletions app/views/ansible_repository/_repository_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#main_div
%br
%br

.form-horizontal
%form#form_div{:name => "angularForm",
'ng-controller' => "repositoryFormController as vm",
'ng-show' => "afterGet",
: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,
"auto-focus" => ""}
%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",
"checkchange" => "",
:disabled => true,
"pf-select" => "")
.form-group
%label.col-md-2.control-label
= _('URL')
.col-md-8
%input.form-control{:type => "url",
:name => "url",
:id => "url",
'ng-model' => "vm.repositoryModel.url",
:required => "",
:checkchange => true}
%span.help-block{"ng-show" => "angularForm.description.$error.required"}
= _("Required")
.form-group
%label.col-md-2.control-label
= _('SCM credentials')
.col-md-8
= select_tag('scm_credentials',
options_for_select([["#{_('whatever')}", "wharever"]]),
"ng-model" => "vm.repositoryModel.scm_credentials",
"checkchange" => "",
"pf-select" => "")
.form-group
%label.col-md-2.control-label
= _('SCM Branch')
.col-md-8
%input.form-control{:type => "text",
:name => "branch",
"id" => "branch",
'ng-model' => "vm.repositoryModel.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.clean")
= _('Clean')
%span.fa.fa-info
%div
%label
= check_box_tag("clean", "1", false, 'ng-model' => 'vm.repositoryModel.deleteOnUpdate')
= _('Delete on Update')
%span.fa.fa-info
%div
%label
= check_box_tag("clean", "1", false, 'ng-model' => 'vm.repositoryModel.updateOnLaunch')
= _('Update on Launch')
%span.fa.fa-info
= render :partial => "layouts/angular/x_edit_buttons_angular"
:javascript
ManageIQ.angular.app.value('repositoryId', '#{@record.try(:id) || 'new'}');
miq_bootstrap('#form_div');
2 changes: 2 additions & 0 deletions app/views/ansible_repository/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#main_div
= render :partial => 'repository_form'
2 changes: 2 additions & 0 deletions app/views/ansible_repository/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#main_div
= render :partial => 'repository_form'
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,9 @@
:get => %w(
download_data
download_summary_pdf
dummy_data
edit
new
show
show_list
),
Expand Down

0 comments on commit 6e1f411

Please sign in to comment.