Commit 58d8b9ae authored by Shinya Maeda's avatar Shinya Maeda

Controller logic. Delete before modification. Halfway.

parent d278da48
...@@ -66,6 +66,7 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController ...@@ -66,6 +66,7 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
def schedule_params def schedule_params
params.require(:schedule) params.require(:schedule)
.permit(:description, :cron, :cron_timezone, :ref, :active) .permit(:description, :cron, :cron_timezone, :ref, :active,
variables_attributes: [:key, :value] )
end end
end end
...@@ -9,18 +9,30 @@ module Ci ...@@ -9,18 +9,30 @@ module Ci
belongs_to :owner, class_name: 'User' belongs_to :owner, class_name: 'User'
has_one :last_pipeline, -> { order(id: :desc) }, class_name: 'Ci::Pipeline' has_one :last_pipeline, -> { order(id: :desc) }, class_name: 'Ci::Pipeline'
has_many :pipelines has_many :pipelines
has_many :variables, class_name: 'Ci::PipelineScheduleVariable' has_many :variables, :dependent => :destroy, class_name: 'Ci::PipelineScheduleVariable'
validates :cron, unless: :importing?, cron: true, presence: { unless: :importing? } validates :cron, unless: :importing?, cron: true, presence: { unless: :importing? }
validates :cron_timezone, cron_timezone: true, presence: { unless: :importing? } validates :cron_timezone, cron_timezone: true, presence: { unless: :importing? }
validates :ref, presence: { unless: :importing? } validates :ref, presence: { unless: :importing? }
validates :description, presence: true validates :description, presence: true
validates_associated :variables
before_save :set_next_run_at before_save :set_next_run_at
scope :active, -> { where(active: true) } scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) } scope :inactive, -> { where(active: false) }
accepts_nested_attributes_for :variables, allow_destroy: true
before_validation(on: :update) do
# TODO: if validation failed, restore the deleted_obj
deleted_obj = Ci::PipelineScheduleVariable.where(pipeline_schedule_id: self).destroy_all
end
after_validation(on: :update) do
# TODO: if validation failed, restore the deleted_obj
end
def owned_by?(current_user) def owned_by?(current_user)
owner == current_user owner == current_user
end end
......
...@@ -4,6 +4,7 @@ module Ci ...@@ -4,6 +4,7 @@ module Ci
include HasVariable include HasVariable
belongs_to :pipeline_schedule belongs_to :pipeline_schedule
validates :key, uniqueness: { scope: :pipeline_schedule_id } validates :key, uniqueness: { scope: :pipeline_schedule_id }
end end
end end
...@@ -22,6 +22,38 @@ ...@@ -22,6 +22,38 @@
= f.label :ref, _('Target Branch'), class: 'label-light' = f.label :ref, _('Target Branch'), class: 'label-light'
= dropdown_tag(_("Select target branch"), options: { toggle_class: 'btn js-target-branch-dropdown', dropdown_class: 'git-revision-dropdown', title: _("Select target branch"), filter: true, placeholder: s_("OfSearchInADropdown|Filter"), data: { data: @project.repository.branch_names, default_branch: @project.default_branch } } ) = dropdown_tag(_("Select target branch"), options: { toggle_class: 'btn js-target-branch-dropdown', dropdown_class: 'git-revision-dropdown', title: _("Select target branch"), filter: true, placeholder: s_("OfSearchInADropdown|Filter"), data: { data: @project.repository.branch_names, default_branch: @project.default_branch } } )
= f.text_field :ref, value: @schedule.ref, id: 'schedule_ref', class: 'hidden', name: 'schedule[ref]', required: true = f.text_field :ref, value: @schedule.ref, id: 'schedule_ref', class: 'hidden', name: 'schedule[ref]', required: true
-# TODO: Test code
= @schedule.variables.inspect
- if @schedule.variables.present?
- @schedule.variables.each_with_index do |variable, i|
.form-group
.col-md-9
%label.label-light Key
%input.form-control{:name => "schedule[variables_attributes][#{i}][key]", :type => "text", :value => variable.key}/
%p.gl-field-error.hide This field is required.
%label.label-light Value
%input.form-control{:name => "schedule[variables_attributes][#{i}][value]", :type => "text", :value => variable.value}/
%p.gl-field-error.hide This field is required.
- if @schedule.variables.count == 1
- (1..1).each do |i|
.form-group
.col-md-9
%label.label-light Key
%input.form-control{:name => "schedule[variables_attributes][#{i}][key]", :type => "text"}/
%p.gl-field-error.hide This field is required.
%label.label-light Value
%input.form-control{:name => "schedule[variables_attributes][#{i}][value]", :type => "text"}/
%p.gl-field-error.hide This field is required.
- else
- (0..0).each do |i|
.form-group
.col-md-9
%label.label-light Key
%input.form-control{:name => "schedule[variables_attributes][#{i}][key]", :type => "text"}/
%p.gl-field-error.hide This field is required.
%label.label-light Value
%input.form-control{:name => "schedule[variables_attributes][#{i}][value]", :type => "text"}/
%p.gl-field-error.hide This field is required.
.form-group .form-group
.col-md-9 .col-md-9
= f.label :active, s_('PipelineSchedules|Activated'), class: 'label-light' = f.label :active, s_('PipelineSchedules|Activated'), class: 'label-light'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment