Class: Kuroko2::JobDefinitionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Kuroko2::JobDefinitionsController
- Defined in:
- app/controllers/kuroko2/job_definitions_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/kuroko2/job_definitions_controller.rb', line 47 def create @definition = Kuroko2::JobDefinition.new(definition_params) @definition.admins = Kuroko2::User.active.with(admin_id_params) if @definition.save_and_record_revision(edited_user: current_user) current_user.stars.create(job_definition: @definition) redirect_to @definition, notice: 'Job Definition was successfully created.' else render :new end end |
#destroy ⇒ Object
78 79 80 81 82 |
# File 'app/controllers/kuroko2/job_definitions_controller.rb', line 78 def destroy @definition.destroy redirect_to job_definitions_path, notice: 'Job Definition was successfully destroyed.' end |
#edit ⇒ Object
60 61 |
# File 'app/controllers/kuroko2/job_definitions_controller.rb', line 60 def edit end |
#index ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/kuroko2/job_definitions_controller.rb', line 4 def index rel = Kuroko2::JobDefinition.joins(:admins).includes(:tags, :job_schedules, :admins) query = query_params[:q] if query.present? rel = rel.search_by(query) end @input_tags = query_params[:tag] || [] if @input_tags.present? rel = rel.tagged_by(@input_tags) end if query.present? || @input_tags.present? @related_tags = rel.includes(:tags).map(&:tags).flatten.uniq else @related_tags = Kuroko2::Tag.all end @definitions = rel.ordered.page(page_params[:page]) end |
#new ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/kuroko2/job_definitions_controller.rb', line 35 def new dup_from = Kuroko2::JobDefinition.find_by(id: params[:dup_from]) if dup_from.present? @definition = dup_from.dup @definition.admins = dup_from.admins @definition. = dup_from. else @definition = Kuroko2::JobDefinition.new end @definition.admins << current_user unless @definition.admins.include?(current_user) end |
#show ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/controllers/kuroko2/job_definitions_controller.rb', line 26 def show @instances = @definition.job_instances.page(0) @schedules = @definition.job_schedules @suspend_schedules = @definition.job_suspend_schedules @schedule = Kuroko2::JobSchedule.new(job_definition: @definitions) @suspend_schedule = Kuroko2::JobSuspendSchedule.new(job_definition: @definitions) end |
#update ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/kuroko2/job_definitions_controller.rb', line 63 def update success = ActiveRecord::Base.transaction do @definition.attributes = definition_params @definition.admins = Kuroko2::User.active.with(admin_id_params) @definition.save_and_record_revision(edited_user: current_user) end if success redirect_to @definition, notice: 'Job Definition was successfully updated.' else render :edit end end |