Skip to content

Commit

Permalink
[FS-12] Add agenda app panel
Browse files Browse the repository at this point in the history
  • Loading branch information
beetlegius-jt committed Jan 28, 2025
1 parent cd60827 commit 33ca337
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/components/app/agenda_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<nav class="nav nav-pills nav-fill" role="tablist">
<% @weekdays.each do |day| %>
<%= button_tag day.strftime("%A"), class: ["nav-link", ("active" if day.today?)], data: { bs_toggle: :tab, bs_target: "##{day}" } %>
<% end %>
</nav>

<hr>

<div class="tab-content">
<% @grouped_events.each_pair do |day, events| %>
<%= tag.div id: day, class: ["tab-pane", ("active" if day.today?)], role: :tabpanel do %>
<ul class="list-group">
<% events.each do |event| %>
<li class="list-group-item d-flex justify-content-between lh-lg align-items-center">
<%= event.activity_name %>

<small><%= event.start_time %> - <%= event.end_time %></small>
</li>
<% end %>
</ul>
<% end %>
<% end %>
</div>
8 changes: 8 additions & 0 deletions app/components/app/agenda_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module App
class AgendaComponent < ViewComponent::Base
def initialize(events:)
@grouped_events = events.group_by { |event| event.starts_at.to_date }
@weekdays = Time.zone.today.all_week
end
end
end
14 changes: 14 additions & 0 deletions app/controllers/app/agendas_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module App
class AgendasController < BaseController
def show
authorize :agenda, :show?

activities = policy_scope(Current.company.activities).includes(:schedule)
week = Time.zone.today.all_week

@events = EventDecorator.decorate_collection(
Event.from_activities(activities, from: week.begin, to: week.end)
)
end
end
end
7 changes: 7 additions & 0 deletions app/policies/app/agenda_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module App
class AgendaPolicy < ApplicationPolicy
def show?
customer?
end
end
end
16 changes: 16 additions & 0 deletions app/views/app/agendas/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%= turbo_frame_tag :remote_modal, target: :_top do %>
<div class="modal" data-controller="modal" data-bs-backdrop="static">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><%= t '.title' %></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>

<div class="modal-body">
<%= render App::AgendaComponent.new(events: @events) %>
</div>
</div>
</div>
</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/app/events/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

<div class="card mb-3">
<div class="card-header">
<%= link_to t(".agenda"), app_agenda_path, class: "text-sm float-end", data: { turbo_frame: :remote_modal } if policy([:app, :agenda]).show? %>

<%= Event.model_name.human.pluralize %>
</div>

Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ en:
schedule_fields:
add_rule: Add rule
app:
agendas:
show:
title: Agenda
events:
index:
today: Today
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

constraints CompanyConstraint.new do
namespace :app do
resource :agenda, only: :show
resources :activities, only: [] do
resources :reservations, only: [ :new, :create ]
end
Expand Down
21 changes: 21 additions & 0 deletions spec/components/app/agenda_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe App::AgendaComponent, type: :component do
let(:activity) { build(:activity) }
let(:event1) { build(:event, activity:, starts_at: Time.current.beginning_of_week).decorate }
let(:event2) { build(:event, activity:, starts_at: Time.current.end_of_week).decorate }

subject { render_inline(described_class.new(events: [ event1, event2 ])).to_html }

Time.zone.today.all_week.each do |date|
it { is_expected.to include(date.strftime("%A")) }
end

it { is_expected.to include(activity.name) }
it { is_expected.to include(event1.start_time) }
it { is_expected.to include(event1.end_time) }
it { is_expected.to include(event2.start_time) }
it { is_expected.to include(event2.end_time) }
end
15 changes: 15 additions & 0 deletions spec/policies/app/agenda_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

RSpec.describe App::AgendaPolicy, type: :policy do
let(:customer) { create(:customer) }

subject { described_class }

before { Current.customer = customer }

permissions :show? do
it_behaves_like "a customer resource" do
let(:resource) { :agenda }
end
end
end

0 comments on commit 33ca337

Please sign in to comment.