# frozen_string_literal: true

module GobiertoParticipation
  class ProcessesController < GobiertoParticipation::ApplicationController
    def index
      @processes = current_site.processes.process.open
      @groups = current_site.processes.group_process.open
    end

    def show
      @process = GobiertoParticipation::Process.find_by!(slug: params[:id])
      @process_news = find_process_news
      @process_events = find_process_events
      @activities = [] # TODO: implementation not yet defined
      @process_stages = @process.stages
    end

    private

    def find_person
      people_scope.find_by!(slug: params[:slug])
    end

    def find_process_news
      @process.news.active.sort_by(&:created_at).reverse.first(5)
      # TODO: rewrite using Rails chainable scopes. Maybe something like this:
      # @process.news.upcoming.order(created_at: :desc).limit(5)
    end

    def find_process_events
      @process.events.published.upcoming.order(starts_at: :asc).limit(5)
    end
  end
end

# frozen_string_literal: true

module GobiertoParticipation
  class ProcessesController < GobiertoParticipation::ApplicationController
    def index
      @processes = current_site.processes.process.open.active
      @groups = current_site.processes.group_process.open.active
    end

    def show
      @process = GobiertoParticipation::Process.find_by!(slug: params[:id])
      @process_news = find_process_news
      @process_events = find_process_events
      @activities = [] # TODO: implementation not yet defined
      @process_stages = @process.stages
    end

    private

    def find_person
      people_scope.find_by!(slug: params[:slug])
    end

    def find_process_news
      @process.news.active.sort_by(&:created_at).reverse.first(5)
      # TODO: rewrite using Rails chainable scopes. Maybe something like this:
      # @process.news.upcoming.order(created_at: :desc).limit(5)
    end

    def find_process_events
      @process.events.published.upcoming.order(starts_at: :asc).limit(5)
    end
  end
end

Fix active processes and groups in processes view
Fix active processes and groups in processes view
