-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ede3f19
commit 244f928
Showing
34 changed files
with
820 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class SubGroupEvaluationsController < ApplicationController | ||
include EvaluationsControllerHelper | ||
before_action :set_search, only: :table | ||
|
||
def table | ||
@point_details = PointDetail.joins(point_request: :evaluation) | ||
.where(evaluations: { id: current_evaluation.id }) | ||
.includes(:principle) | ||
@evaluation = current_evaluation | ||
@group = @evaluation.group | ||
|
||
@ordered_principles = @evaluation.principles | ||
.where(sub_group_id: params[:sub_group_id]) | ||
.order(:type, :id) | ||
|
||
point_eligible_user_ids = @evaluation.group.point_eligible_memberships.map(&:user_id) | ||
@users = User.with_full_name.where(id: point_eligible_user_ids) | ||
.includes(:entry_requests, | ||
point_requests: [point_details: [:point_detail_comments, :principle]]) | ||
search_users | ||
@users = @users.order(:full_name).page(params[:page]) | ||
@users_for_pagination = @users | ||
@users = EvaluationUserDecorator.decorate_collection(@users, context: { evaluation: @evaluation }) | ||
|
||
@evaluation_point_calculator = EvaluationPointCalculator.new(@users) | ||
evaluation_policy = policy(@evaluation) | ||
@update_point_request = evaluation_policy.update_point_request? | ||
@update_entry_request = evaluation_policy.update_entry_request? | ||
|
||
render 'evaluations/table' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
class SubGroupPrinciplesController < ApplicationController | ||
before_action :set_principle, only: %i[update destroy] | ||
before_action :validate_correct_evaluation, only: %i[update destroy] | ||
# before_action :authorize_evaluation, except: [:index] | ||
before_action :set_sub_group, only: [:index, :create, :update] | ||
|
||
def index | ||
@evaluation = current_evaluation | ||
authorize @evaluation, :show? | ||
|
||
@principles = @evaluation.principles.where(sub_group: @sub_group).order(:type, :id) | ||
@can_edit = true | ||
end | ||
|
||
def update | ||
@principle.update(principle_params) | ||
|
||
render 'principles/update' | ||
end | ||
|
||
def create | ||
@principle = Principle.new(principle_params) | ||
@evaluation = current_evaluation | ||
@principle.evaluation = @evaluation | ||
@principle.sub_group = @sub_group | ||
@principle.save | ||
|
||
render 'principles/create' | ||
end | ||
|
||
def destroy | ||
@principle.destroy | ||
|
||
render 'principles/destroy' | ||
end | ||
|
||
private | ||
|
||
def set_principle | ||
@principle = Principle.find(params[:id]) | ||
end | ||
|
||
def validate_correct_evaluation | ||
render forbidden_page unless current_evaluation == @principle.evaluation | ||
end | ||
|
||
def principle_params | ||
params.require(:principle).permit(:type, :name, :max_per_member, :description) | ||
end | ||
|
||
def current_evaluation | ||
current_group.current_evaluation | ||
end | ||
|
||
def set_sub_group | ||
@sub_group = SubGroup.find(params[:sub_group_id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
class SubGroupsController < ApplicationController | ||
before_action :set_sub_group, only: [:show, :edit, :update, :destroy, :join, :leave] | ||
|
||
# GET /sub_groups | ||
def index | ||
@sub_groups = SubGroup.where(group: current_group) | ||
sub_group_memberships = SubGroupMembership.where(membership: current_membership) | ||
@current_user_subgroup_ids = sub_group_memberships.map(&:sub_group_id) | ||
end | ||
|
||
# GET /sub_groups/1 | ||
def show | ||
@sub_group_memberships = @sub_group.sub_group_memberships.includes(membership: :user) | ||
end | ||
|
||
# GET /sub_groups/new | ||
def new | ||
@sub_group = SubGroup.new | ||
end | ||
|
||
# GET /sub_groups/1/edit | ||
def edit | ||
end | ||
|
||
# POST /sub_groups | ||
def create | ||
@sub_group = SubGroup.new(sub_group_params) | ||
@sub_group.group_id = params[:group_id] | ||
|
||
if @sub_group.save | ||
redirect_to group_sub_group_path(current_group, @sub_group), | ||
notice: 'Sub group was successfully created.' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
# PATCH/PUT /sub_groups/1 | ||
def update | ||
if @sub_group.update(sub_group_params) | ||
redirect_to group_sub_group_path(current_group, @sub_group), | ||
notice: 'Sub group was successfully updated.' | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
# DELETE /sub_groups/1 | ||
def destroy | ||
ActiveRecord::Base.transaction do | ||
@sub_group.sub_group_memberships.destroy_all | ||
@sub_group.principles.update_all(sub_group_id: nil) | ||
@sub_group.destroy | ||
end | ||
redirect_to group_sub_groups_path(current_group), notice: 'Sub group was successfully destroyed.' | ||
end | ||
|
||
def join | ||
SubGroupMembership.create!(membership: current_membership, sub_group: @sub_group) | ||
|
||
redirect_to group_sub_groups_path(current_group) | ||
end | ||
|
||
def leave | ||
sub_group_membership = SubGroupMembership.find_by( | ||
membership: current_membership, | ||
sub_group: @sub_group) | ||
sub_group_membership.destroy! | ||
|
||
redirect_to group_sub_groups_path(current_group) | ||
end | ||
|
||
def set_admin | ||
@sub_group_membership = SubGroupMembership.find(params[:sub_group_membership_id]) | ||
@sub_group_membership.update!(admin: params[:admin]) | ||
end | ||
|
||
private | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_sub_group | ||
@sub_group = SubGroup.find(params[:id]) | ||
end | ||
|
||
# Only allow a trusted parameter "white list" through. | ||
def sub_group_params | ||
params.require(:sub_group).permit(:name) | ||
end | ||
|
||
def current_membership | ||
@current_membership ||= current_user.membership_for(current_group) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module EvaluationsControllerHelper | ||
private | ||
|
||
def set_search | ||
@search = OpenStruct.new(term: params[:term]&.downcase, start_with?: !!params[:start_with]) | ||
end | ||
|
||
def search_users | ||
return if @search.term.blank? | ||
|
||
query = @search.start_with? ? "#{@search.term}%" : "%#{@search.term}%" | ||
@users = @users.where("full_name like ?", query) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# == Schema Information | ||
# | ||
# Table name: sub_groups | ||
# | ||
# id :bigint not null, primary key | ||
# name :string | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# group_id :bigint not null | ||
# | ||
# Indexes | ||
# | ||
# index_sub_groups_on_group_id (group_id) | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (group_id => groups.id) | ||
# | ||
|
||
class SubGroup < ApplicationRecord | ||
belongs_to :group | ||
has_many :sub_group_memberships | ||
has_many :memberships, through: :sub_group_memberships | ||
has_many :principles | ||
validates :name, presence: true | ||
validates :group_id, presence: true | ||
end |
Oops, something went wrong.