Sha256: e11086d921308b987256fe2a3108b134ceafd60d5c072d1791c3665731e28405

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

require_dependency "yawl_rails/application_controller"

module YawlRails
  class ProcessesController < ApplicationController
    before_filter :load_process, only: [:show, :restart, :steps]

    def index
      page = (params[:page] || 1).to_i
      @processes = ::Yawl::Process.pagination_dataset.order(:id).reverse.paginate(page, Yawl::Config.pagination_per_page)

      respond_to do |format|
        format.html
        format.json { render :json => @processes }
      end
    end

    def show
      respond_to do |format|
        format.html
        format.json { render :json => @process.to_hash.merge(:steps => @process.steps.map(&:to_hash)) }
      end
    end

    def restart
      @process.start_first_unfinished_step

      respond_to do |format|
        format.html { redirect_to yawl_process_path(@process.name), :status => 303 }
        format.json { render :json => @process.to_hash, :location => yawl_process_url(@process.name) }
      end
    end

    def steps
      respond_to do |format|
        format.html { render :partial => "step_rows" }
        format.json { render :json => @process.to_hash.merge(:steps => @process.steps.map(&:to_hash)) }
      end
    end

    protected

    def load_process
      @process = ::Yawl::Process.first(:name => params[:id])
      if @process.nil?
        respond_to do |format|
          format.html { render :text => "Process not found", :status => 404 }
          format.json { render :json => { "error" => "Process not found" }, :status => 404 }
        end
        false
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yawl_rails-0.3.0 app/controllers/yawl_rails/processes_controller.rb
yawl_rails-0.2.2 app/controllers/yawl_rails/processes_controller.rb