Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/controllers/facilitators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ def set_form_variables
# @facilitator.build_user if @facilitator.user.blank? # Build a fresh one if missing

if @facilitator.user
@facilitator.user.project_users.first || @facilitator.user.project_users.build
@facilitator.user.organization_users.first || @facilitator.user.organization_users.build
end
projects = if current_user.super_user?
Project.active
organizations = if current_user.super_user?
Organization.active
else
current_user.projects
current_user.organizations
end
@projects_array = projects.order(:name).pluck(:name, :id)
@organizations_array = organizations.order(:name).pluck(:name, :id)
end


Expand Down Expand Up @@ -176,9 +176,9 @@ def facilitator_params
:state2,
:zip2,
:notes,
project_users_attributes: [
organization_users_attributes: [
:id,
:project_id,
:organization_id,
:position,
:title,
:inactive,
Expand Down
18 changes: 9 additions & 9 deletions app/controllers/monthly_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create
@form_builder = FormBuilder.find(@report.owner_id)
build_month_and_year
load_agencies
@agency_id = report_params["project_id"]
@agency_id = report_params["organization_id"]

flash[:alert] = "There was a problem submitting your form: " +
"#{@report.errors.full_messages.join(" ")}"
Expand All @@ -61,7 +61,7 @@ def edit
build_month_and_year
find_form_builder
@report = Report.find(params[:id])
@agencies = current_user.projects.
@agencies = current_user.organizations.
where(windows_type_id: @report.windows_type_id)
@month = @report.date.month
@year = @report.date.year
Expand All @@ -85,7 +85,7 @@ def update
flash[:notice] = "Thanks for reporting on a update report. "
redirect_to authenticated_root_path
else
@agencies = current_user.projects.
@agencies = current_user.organizations.
where(windows_type_id: @report.windows_type_id)

flash[:alert] = "ERROR!!!!!!!!!!!!!!"
Expand All @@ -102,7 +102,7 @@ def show
@answers = @monthly_report.report_form_field_answers

if @monthly_report
if current_user.super_user? || (@monthly_report.project && current_user.project_ids.include?(@monthly_report.project.id))
if current_user.super_user? || (@monthly_report.organization && current_user.organization_ids.include?(@monthly_report.organization.id))
render :show
else
redirect_to authenticated_root_path, error: "You do not have permission to view this page."
Expand All @@ -116,7 +116,7 @@ def show
private

def load_agencies
@agencies = current_user.projects.
@agencies = current_user.organizations.
where(windows_type_id: @form_builder.windows_type_id).uniq
end

Expand All @@ -143,7 +143,7 @@ def find_form_builder
.decorate
end

agency = params[:agency_id] ? Project.find(params[:agency_id]) : current_user.projects.where(windows_type_id: @form_builder.windows_type).first
agency = params[:agency_id] ? Organization.find(params[:agency_id]) : current_user.organizations.where(windows_type_id: @form_builder.windows_type).first
@agency_id = agency.id unless agency.nil?
end

Expand Down Expand Up @@ -196,7 +196,7 @@ def build_report_form_fields
end

def find_workshop_logs
@workshop_logs = current_user.project_monthly_workshop_logs(
@workshop_logs = current_user.organization_monthly_workshop_logs(
@report.date, @report.windows_type
)

Expand All @@ -207,7 +207,7 @@ def find_workshop_logs

def find_combined_workshop_logs(agency_id)
combined_windows_type = WindowsType.where(short_name: "COMBINED").first
@combined_workshop_logs = current_user.project_workshop_logs(
@combined_workshop_logs = current_user.organization_workshop_logs(
@report.date, combined_windows_type, agency_id)
end

Expand All @@ -225,7 +225,7 @@ def report_params
end

params.require(:report).permit(
:type, :project_id, :date, :owner_id, :workshop_id,
:type, :organization_id, :date, :owner_id, :workshop_id,
:owner_type, :windows_type_id, :other_description,
media_files_attributes: [ :file ],
report_form_field_answers_attributes:
Expand Down
68 changes: 68 additions & 0 deletions app/controllers/organization_statuses_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
class OrganizationStatusesController < Admin::BaseController
before_action :set_organization_status, only: [ :show, :edit, :update, :destroy ]

def index
per_page = params[:number_of_items_per_page].presence || 25
unfiltered = OrganizationStatus.all
@count_display = unfiltered.count
@organization_statuses = unfiltered.paginate(page: params[:page], per_page: per_page).decorate
end

def show
@organization_status = @organization_status.decorate
end

def new
@organization_status = OrganizationStatus.new.decorate
set_form_variables
end

def edit
@organization_status = @organization_status.decorate
set_form_variables
end

def create
@organization_status = OrganizationStatus.new(organization_status_params)

if @organization_status.save
redirect_to organization_statuses_path, notice: "Organization status was successfully created."
else
@organization_status = OrganizationStatus.new.decorate
set_form_variables
render :new, status: :unprocessable_content
end
end

def update
if @organization_status.update(organization_status_params)
redirect_to organization_statuses_path, notice: "Organization status was successfully updated.", status: :see_other
else
@organization_status = OrganizationStatus.new.decorate
set_form_variables
render :edit, status: :unprocessable_content
end
end

def destroy
@organization_status.destroy!
redirect_to organization_statuses_path, notice: "Organization status was successfully destroyed."
end

# Optional hooks for setting variables for forms or index
def set_form_variables
end

private

def set_organization_status
@organization_status = OrganizationStatus.find(params[:id])
end

# Strong parameters
def organization_status_params
params.require(:organization_status).permit(
:name
)
end
end
13 changes: 13 additions & 0 deletions app/controllers/organization_users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class OrganizationUsersController < ApplicationController
def destroy
organization_user = OrganizationUser.find(params[:id])
user = organization_user.user

if organization_user.destroy
flash[:notice] = "Organization user has been deleted."
else
flash[:alert] = "Unable to delete organization user. Please contact AWBW."
end
redirect_to generate_facilitator_user_path(user)
end
end
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
class ProjectsController < ApplicationController
before_action :set_project, only: [ :show, :edit, :update, :destroy ]
class OrganizationsController < ApplicationController
before_action :set_organization, only: [ :show, :edit, :update, :destroy ]

def index
per_page = params[:number_of_items_per_page].presence || 25
unpaginated = Project.search_by_params(params).order(:name)
@projects_count = unpaginated.count
@projects = unpaginated.paginate(page: params[:page], per_page: per_page)
unpaginated = Organization.search_by_params(params).order(:name)
@organizations_count = unpaginated.count
@organizations = unpaginated.paginate(page: params[:page], per_page: per_page)
set_index_variables
end

def show
@project.increment_view_count!(session: session, request: request)
@organization.increment_view_count!(session: session, request: request)

# Reuse WorkshopLogsController#index logic programmatically
workshop_logs_controller = WorkshopLogsController.new
workshop_logs_controller.request = request
workshop_logs_controller.response = response
params[:project_id] = @project.id # Inject context so the WorkshopLogsController#index scopes properly
params[:organization_id] = @organization.id # Inject context so the WorkshopLogsController#index scopes properly
workshop_logs_controller.params = params
workshop_logs_controller.index

workshop_logs = WorkshopLog.where(project_id: @project.id)
workshop_logs = WorkshopLog.where(organization_id: @organization.id)
@month_year_options = workshop_logs.group("DATE_FORMAT(COALESCE(date, created_at, NOW()), '%Y-%m')")
.select("DATE_FORMAT(COALESCE(date, created_at, NOW()), '%Y-%m') AS ym,
MAX(COALESCE(date, created_at)) AS max_dt")
Expand All @@ -30,7 +30,7 @@ def show
@year_options = workshop_logs.pluck(
Arel.sql("DISTINCT EXTRACT(YEAR FROM COALESCE(date, created_at, NOW()))")
).sort.reverse
@projects = Project.where(id: @project.id)
@organizations = Organization.where(id: @organization.id)
@per_page = params[:per_page] || 10
@workshop_logs_unpaginated = workshop_logs
@workshop_logs_count = @workshop_logs_unpaginated.size
Expand All @@ -42,7 +42,7 @@ def show
end

def new
@project = Project.new
@organization = Organization.new
set_form_variables
end

Expand All @@ -51,63 +51,63 @@ def edit
end

def create
@project = Project.new(project_params)
@organization = Organization.new(organization_params)

if @project.save
redirect_to projects_path, notice: "Organization was successfully created."
if @organization.save
redirect_to organizations_path, notice: "Organization was successfully created."
else
set_form_variables
render :new, status: :unprocessable_content
end
end

def update
if @project.update(project_params)
redirect_to projects_path, notice: "Organization was successfully updated.", status: :see_other
if @organization.update(organization_params)
redirect_to organizations_path, notice: "Organization was successfully updated.", status: :see_other
else
set_form_variables
render :edit, status: :unprocessable_content
end
end

def destroy
@project.destroy!
redirect_to projects_path, notice: "Organization was successfully destroyed."
@organization.destroy!
redirect_to organizations_path, notice: "Organization was successfully destroyed."
end

# Optional hooks for setting variables for forms or index
def set_form_variables
@project_statuses = ProjectStatus.all
@organization_statuses = OrganizationStatus.all
@facilitators_array = Facilitator.joins(:user)
.order(:first_name, :last_name)
.map { |f| [ f.name, f.user.id ] }
@project.project_users = @project.project_users
.includes(:project)
.sort_by { |pu| pu.user.facilitator&.name.to_s.downcase }
@organization.organization_users = @organization.organization_users
.includes(:organization)
.sort_by { |ou| ou.user.facilitator&.name.to_s.downcase }
end

def set_index_variables
@project_statuses = ProjectStatus.all
@organization_statuses = OrganizationStatus.all
end

private

def set_project
@project = Project.find(params[:id])
def set_organization
@organization = Organization.find(params[:id])
end

# Strong parameters
def project_params
params.require(:project).permit(
def organization_params
params.require(:organization).permit(
:name, :description, :start_date, :end_date, :mission_vision_values, :internal_id,
:inactive, :logo, :notes, :agency_type, :agency_type_other, :website_url,
:project_status_id, :location_id, :windows_type_id,
:organization_status_id, :location_id, :windows_type_id,
sectorable_items_attributes: [
:id,
:sector_id,
:_destroy
],
project_users_attributes: [
organization_users_attributes: [
:id,
:user_id,
:inactive,
Expand Down
68 changes: 0 additions & 68 deletions app/controllers/project_statuses_controller.rb

This file was deleted.

Loading