Skip to content

Commit

Permalink
Merge pull request #1329 from SplitTime/oveson/service-form-for-produ…
Browse files Browse the repository at this point in the history
…ction

Set up service form in My Stuff
  • Loading branch information
moveson authored Dec 17, 2024
2 parents d759bf1 + 4667eed commit b6a18dc
Show file tree
Hide file tree
Showing 24 changed files with 361 additions and 222 deletions.
43 changes: 43 additions & 0 deletions app/controllers/my_stuff_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

class MyStuffController < ApplicationController
before_action :authenticate_user!
before_action :set_presenter

def index
end

def events
render partial: "events", locals: { presenter: @presenter }
end

def event_series
render partial: "event_series", locals: { presenter: @presenter }
end

def interests
render partial: "interests", locals: { presenter: @presenter }
end

def live_updates
render partial: "live_updates", locals: { presenter: @presenter }
end

def organizations
render partial: "organizations", locals: { presenter: @presenter }
end

def results
render partial: "results", locals: { presenter: @presenter }
end

def service_requirements
render partial: "service_requirements", locals: { presenter: @presenter }
end

private

def set_presenter
@presenter = MyStuffPresenter.new(current_user)
end
end
15 changes: 8 additions & 7 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# frozen_string_literal: true

class UsersController < ApplicationController
before_action :authenticate_user!
before_action :set_user, except: :index
before_action :set_user, only: [:update, :destroy]
before_action :authorize_user, only: [:update, :destroy]
after_action :verify_authorized

def index
authorize User

users = User.with_avatar_names.includes(:avatar)
.where(prepared_params[:filter])
.search(prepared_params[:search])
Expand All @@ -22,7 +26,6 @@ def index
end

def update
authorize @user
if @user.update(secure_params)
redirect_to users_path, notice: "User updated."
else
Expand All @@ -31,18 +34,16 @@ def update
end

def destroy
authorize @user
@user.destroy
redirect_to users_path, notice: "User deleted."
end

def my_stuff
private

def authorize_user
authorize @user
@presenter = MyStuffPresenter.new(@user)
end

private

def secure_params
params.require(:user).permit(:role)
end
Expand Down
9 changes: 9 additions & 0 deletions app/javascript/controllers/masonry_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import Masonry from "masonry-layout"
export default class extends Controller {
connect() {
this.masonry = new Masonry(this.element)

// Frames resize when they load, so Masonry needs to recalculate the layout
const frames = this.element.getElementsByTagName("turbo-frame")

Array.from(frames).forEach((frame) => {
frame.addEventListener("turbo:frame-load", () => {
this.masonry.layout();
});
});
}

disconnect() {
Expand Down
1 change: 1 addition & 0 deletions app/models/lottery_entrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class LotteryEntrant < ApplicationRecord
strip_attributes collapse_spaces: true
capitalize_attributes :first_name, :last_name, :city

scope :belonging_to_user, ->(user) { where(email: user.email).or(where.not(person: nil).where(person: user.avatar)) }
scope :accepted, -> { joins(:division_ranking).where(lotteries_division_rankings: { draw_status: :accepted }) }
scope :waitlisted, -> { joins(:division_ranking).where(lotteries_division_rankings: { draw_status: :waitlisted }) }
scope :drawn_beyond_waitlist, -> { joins(:division_ranking).where(lotteries_division_rankings: { draw_status: :drawn_beyond_waitlist }) }
Expand Down
6 changes: 1 addition & 5 deletions app/policies/user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def index?
end

def update?
current_user.admin?
index?
end

def destroy?
Expand All @@ -43,8 +43,4 @@ def destroy?
def current?
current_user.present?
end

def my_stuff?
current_user.admin? || (current_user == user_record)
end
end
9 changes: 7 additions & 2 deletions app/presenters/my_stuff_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def event_series
EventSeries.includes(:events).where(organization: organizations)
end

def lottery_entrants
LotteryEntrant.belonging_to_user(current_user)
.includes(:service_detail, division: { lottery: :organization })
end

def organizations
owned_organizations | steward_organizations
end
Expand All @@ -42,9 +47,9 @@ def recent_user_efforts(number)
end

def user_efforts
return nil unless avatar
return Effort.none unless avatar

@user_efforts ||= avatar.efforts.includes(:split_times).sort_by(&:calculated_start_time).reverse
@user_efforts ||= avatar.efforts.joins(:event).includes(event: :event_group).order("events.scheduled_start_time desc")
end

def interests
Expand Down
4 changes: 0 additions & 4 deletions app/presenters/visitor_index_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ def upcoming_courses(number)
Course.where("next_start_time > ?", Time.current).order(:next_start_time).limit(number)
end

def recent_user_efforts
@recent_user_efforts ||= avatar ? avatar.efforts.joins(:event).includes(event: :event_group).order("events.scheduled_start_time desc") : []
end

private

attr_reader :current_user
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_navigation_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%= link_to "Events", event_groups_path, class: "nav-link" %>
<%= link_to "Organizations", organizations_path, class: "nav-link" %>
<% if current_user %>
<%= link_to "My Stuff", my_stuff_user_path(current_user), class: "nav-link" %>
<%= link_to "My Stuff", my_stuff_path, class: "nav-link" %>
<%= link_to "Imports", import_jobs_path, class: "nav-link" %>
<%= link_to "Exports", export_jobs_path, class: "nav-link" %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,36 @@
</div>
</div>
</div>
<div class="card-body">
<table class="table table-responsive">
<tbody>
<tr>
<td class="text-center">
<% if presenter.completed_form.attached? %>
<%= fa_icon("circle-check", type: :solid, class: "text-success") %>
<% else %>
<%= fa_icon("circle-minus", type: :regular, class: "text-warning") %>
<% end %>
</td>
<td><%= presenter.completed_form.attached? ? "Uploaded" : "No file uploaded" %></td>
<td><%= l(presenter.completed_form.created_at) if presenter.completed_form.attached? %></td>
<td><%= presenter.completed_form.filename %></td>
</tr>
<tr>
<% if presenter.rejected? %>
<td class="text-center"><%= fa_icon("circle-xmark", type: :solid, class: "text-danger") %></td>
<td>Rejected</td>
<td><%= l(presenter.service_form_rejected_at) %></td>
<td><%= presenter.service_form_rejected_comments %></td>
<% elsif presenter.accepted? %>
<% if presenter.completed_form.attached? %>
<div class="card-body">
<table class="table table-responsive">
<tbody>
<tr>
<td class="text-center"><%= fa_icon("circle-check", type: :solid, class: "text-success") %></td>
<td>Accepted</td>
<td><%= l(presenter.service_form_accepted_at) %></td>
<td><%= presenter.service_form_accepted_comments %></td>
<% elsif presenter.completed_form.attached? %>
<td class="text-center"><%= fa_icon("file-magnifying-glass", type: :solid, class: "text-secondary") %></td>
<td>Under review</td>
<td></td>
<td></td>
<% end %>
</tr>
</tbody>
</table>
</div>
<td>Uploaded</td>
<td><%= l(presenter.completed_form.created_at) %></td>
<td><%= presenter.completed_form.filename %></td>
</tr>
<tr>
<% if presenter.rejected? %>
<td class="text-center"><%= fa_icon("circle-xmark", type: :solid, class: "text-danger") %></td>
<td>Rejected</td>
<td><%= l(presenter.service_form_rejected_at) %></td>
<td><%= presenter.service_form_rejected_comments %></td>
<% elsif presenter.accepted? %>
<td class="text-center"><%= fa_icon("circle-check", type: :solid, class: "text-success") %></td>
<td>Accepted</td>
<td><%= l(presenter.service_form_accepted_at) %></td>
<td><%= presenter.service_form_accepted_comments %></td>
<% elsif presenter.completed_form.attached? %>
<td class="text-center"><%= fa_icon("file-magnifying-glass", type: :solid, class: "text-secondary") %></td>
<td>Under review</td>
<td></td>
<td></td>
<% end %>
</tr>
</tbody>
</table>
</div>
<% end %>
</div>
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<%# locals: (record:, calculation:) %>

<% presenter = LotteryEntrantPresenter.new(record) %>
<%# locals: (presenter:) %>

<%= turbo_frame_tag dom_id(presenter) do %>
<div class="card bg-light mt-2">
<div class="card-body">
<div class="row">
<div class="col">
<%= render partial: "lottery_entrants/name_and_geolocation_with_icon", locals: { record: record } %>
<%= render partial: "lottery_entrants/name_and_geolocation_with_icon", locals: { record: presenter.__getobj__ } %>
</div>
<div class="col">
<h4 class="text-end"><span class="badge bg-secondary"><%= presenter.division_name %></span></h4>
Expand Down Expand Up @@ -37,10 +35,11 @@
<% end %>

<% if presenter.calculation.present? %>
<%= render partial: "ticket_calculations_table", locals: { presenter: presenter } %>
<hr/>
<%= render partial: "ticket_calculations_table", locals: { presenter: presenter } %>
<% end %>
<% if presenter.relevant_historical_facts.any? %>
<hr/>
<%= render partial: "historical_facts_table", locals: { presenter: presenter } %>
<% end %>
<% elsif current_user.nil? %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/lottery_entrants/show.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= render "lottery_entrant_with_tickets", record: @lottery_entrant %>
<%= render "lottery_entrant_with_tickets", presenter: LotteryEntrantPresenter.new(@lottery_entrant) %>
9 changes: 9 additions & 0 deletions app/views/my_stuff/_event_series.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%# locals: (presenter:) %>

<turbo-frame id="my_stuff_event_series_card">
<% presenter.recent_event_series(10).each do |series| %>
<h4 class="card-text">
<strong><%= link_to series.name, organization_event_series_path(series.organization, series) %></strong>
</h4>
<% end %>
</turbo-frame>
9 changes: 9 additions & 0 deletions app/views/my_stuff/_events.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%# locals: (presenter:) %>

<turbo-frame id="my_stuff_events_card">
<% presenter.recent_event_groups(20).each do |event_group| %>
<h4 class="card-text">
<strong><%= link_to event_group.name, event_group_path(event_group) %></strong>
</h4>
<% end %>
</turbo-frame>
9 changes: 9 additions & 0 deletions app/views/my_stuff/_interests.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%# locals: (presenter:) %>

<turbo-frame id="my_stuff_interests_card">
<% presenter.interests.each do |person| %>
<h4 class="card-text">
<strong><%= link_to person.full_name, person_path(person) %></strong>
</h4>
<% end %>
</turbo-frame>
9 changes: 9 additions & 0 deletions app/views/my_stuff/_live_updates.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%# locals: (presenter:) %>

<turbo-frame id="my_stuff_live_updates_card">
<% presenter.watch_efforts.each do |effort| %>
<h4 class="card-text">
<strong><%= link_to "#{effort.full_name} at #{effort.event_name}", effort_path(effort) %></strong>
</h4>
<% end %>
</turbo-frame>
16 changes: 16 additions & 0 deletions app/views/my_stuff/_organizations.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%# locals: (presenter:) %>

<turbo-frame id="my_stuff_organizations_card">
<% presenter.owned_organizations.each do |organization| %>
<h4 class="card-text">
<strong><%= link_to organization.name, organization_path(organization) %></strong>
<span class="badge bg-secondary">Owner</span>
</h4>
<% end %>
<% presenter.steward_organizations.each do |organization| %>
<h4 class="card-text">
<strong><%= link_to organization.name, organization_path(organization) %></strong>
<span class="badge bg-secondary">Steward</span>
</h4>
<% end %>
</turbo-frame>
9 changes: 9 additions & 0 deletions app/views/my_stuff/_results.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%# locals: (presenter:) %>

<turbo-frame id="my_stuff_results_card">
<% presenter.recent_user_efforts(20).each do |effort| %>
<h4 class="card-text">
<strong><%= link_to effort.event_name, effort_path(effort) %></strong>
</h4>
<% end %>
</turbo-frame>
9 changes: 9 additions & 0 deletions app/views/my_stuff/_service_requirements.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%# locals: (presenter:) %>

<turbo-frame id="my_stuff_service_requirements_card">
<% presenter.lottery_entrants.each do |lottery_entrant| %>
<h4 class="card-text fw-bold">
<%= link_to lottery_entrant.lottery.name, organization_lottery_entrant_service_detail_path(lottery_entrant.organization, lottery_entrant.lottery, lottery_entrant) %>
</h4>
<% end %>
</turbo-frame>
Loading

0 comments on commit b6a18dc

Please sign in to comment.