Skip to content

Commit 09b6af2

Browse files
Automatically update header and footer
1 parent d165b90 commit 09b6af2

File tree

6 files changed

+122
-43
lines changed

6 files changed

+122
-43
lines changed

modules/meeting/app/components/meetings/presentation_mode/footer_component.html.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="op-meeting-presentation--footer">
1+
<%= component_wrapper(class: "op-meeting-presentation--footer") do %>
22
<div class="op-meeting-presentation--footer-left">
33
<%= render(Primer::Beta::Button.new(
44
tag: :a,
@@ -49,5 +49,4 @@
4949
<% end %>
5050
</div>
5151
</div>
52-
</div>
53-
52+
<% end %>

modules/meeting/app/components/meetings/presentation_mode/footer_component.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def initialize(meeting:, sorted_agenda_item_ids:, current_item:, started_at:)
4040
@meeting = meeting
4141
@project = meeting.project
4242
@current_item = current_item
43-
@started_at = started_at
43+
@started_at = started_at.iso8601
4444
@agenda_item_ids = sorted_agenda_item_ids
4545
@current_index = sorted_agenda_item_ids.index(current_item.id)
4646
end
@@ -68,18 +68,22 @@ def has_next?
6868
def next_item
6969
return nil unless has_next?
7070

71-
@next_item ||= begin
71+
if defined?(@next_item)
72+
@next_item
73+
else
7274
next_id = @agenda_item_ids[@current_index + 1]
73-
@meeting.agenda_items.find_by(id: next_id)
75+
@next_item = @meeting.agenda_items.find_by(id: next_id)
7476
end
7577
end
7678

7779
def previous_item
7880
return nil unless has_previous?
7981

80-
@previous_item ||= begin
82+
if defined?(@previous_item)
83+
@previous_item
84+
else
8185
previous_id = @agenda_item_ids[@current_index - 1]
82-
@meeting.agenda_items.find_by(id: previous_id)
86+
@previous_item = @meeting.agenda_items.find_by(id: previous_id)
8387
end
8488
end
8589

modules/meeting/app/components/meetings/presentation_mode/header_component.html.erb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
<%=
2-
render Primer::OpenProject::PageHeader.new(classes: "op-meeting-presentation-header") do |header|
3-
header.with_breadcrumbs([])
4-
header.with_title_content(@meeting.title)
2+
component_wrapper do
3+
render Primer::OpenProject::PageHeader.new(classes: "op-meeting-presentation-header") do |header|
4+
header.with_breadcrumbs([])
5+
header.with_title_content(@meeting.title)
56

6-
header.with_action_button(
7-
tag: :a,
8-
scheme: :invisible,
9-
mobile_icon: :x,
10-
mobile_label: t(:"meeting.presentation_mode.exit"),
11-
href: meeting_path(@meeting),
12-
aria: { label: t(:"meeting.presentation_mode.exit") },
13-
title: t(:"meeting.presentation_mode.exit"),
14-
) do |button|
15-
button.with_leading_visual_icon(icon: :x)
16-
t(:"meeting.presentation_mode.exit")
7+
header.with_action_button(
8+
tag: :a,
9+
scheme: :invisible,
10+
mobile_icon: :x,
11+
mobile_label: t(:"meeting.presentation_mode.exit"),
12+
href: meeting_path(@meeting),
13+
aria: { label: t(:"meeting.presentation_mode.exit") },
14+
title: t(:"meeting.presentation_mode.exit"),
15+
) do |button|
16+
button.with_leading_visual_icon(icon: :x)
17+
t(:"meeting.presentation_mode.exit")
18+
end
1719
end
1820
end
1921
%>
20-

modules/meeting/app/components/meetings/presentation_mode/show_component.html.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
data: {
2121
controller: "meetings--submit",
2222
poll_for_changes_target: "reference",
23-
reference_value: current_item.updated_at.iso8601
23+
reference_value: @meeting.changed_hash
2424
} do %>
2525
<div class="op-meeting-presentation--header">
2626
<div class="op-meeting-presentation--header-title">
@@ -42,7 +42,6 @@
4242
meeting: @meeting,
4343
sorted_agenda_item_ids: @agenda_item_ids,
4444
current_item: current_item,
45-
started_at: started_at_param
45+
started_at: @started_at
4646
) %>
4747
<% end %>
48-
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
module Meetings
32+
module PresentationComponentStreams
33+
extend ActiveSupport::Concern
34+
35+
included do
36+
def update_content_via_turbo_stream
37+
update_header_via_turbo_stream
38+
update_footer_via_turbo_stream
39+
update_show_via_turbo_stream
40+
41+
respond_with_turbo_streams
42+
end
43+
44+
def update_reference_value(new_reference)
45+
turbo_streams << turbo_stream.set_dataset_attribute(
46+
"#op-meeting-presentation-content",
47+
"reference-value",
48+
new_reference
49+
)
50+
51+
end
52+
53+
def update_header_via_turbo_stream
54+
update_via_turbo_stream(
55+
component: Meetings::PresentationMode::HeaderComponent.new(
56+
meeting: @meeting
57+
)
58+
)
59+
end
60+
61+
def update_footer_via_turbo_stream
62+
update_via_turbo_stream(
63+
component: Meetings::PresentationMode::FooterComponent.new(
64+
meeting: @meeting,
65+
sorted_agenda_item_ids:,
66+
current_item: @meeting_agenda_item,
67+
started_at: @started_at
68+
)
69+
)
70+
end
71+
72+
def update_show_via_turbo_stream
73+
update_via_turbo_stream(
74+
component: MeetingAgendaItems::ItemComponent::ShowComponent.new(
75+
meeting_agenda_item: @meeting_agenda_item,
76+
current_occurrence: @meeting,
77+
presentation_mode: true
78+
)
79+
)
80+
end
81+
end
82+
end
83+
end

modules/meeting/app/controllers/meeting_presentation_controller.rb

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,32 @@
3131
class MeetingPresentationController < ApplicationController
3232
include OpTurbo::ComponentStream
3333
include Meetings::AgendaComponentStreams
34+
include Meetings::PresentationComponentStreams
3435

3536
before_action :check_feature_flag
3637

3738
before_action :find_meeting
3839
before_action :check_presentable
40+
before_action :set_started_at
3941
before_action :find_agenda_item, only: [:check_for_updates]
4042

4143
load_and_authorize_with_permission_in_optional_project :view_meetings
4244

4345
layout "meetings/presentation"
4446

4547
def show
46-
@started_at = params[:started_at].present? ? Time.zone.parse(params[:started_at]) : Time.current
4748
@current_id = determine_current_id
4849
end
4950

5051
def check_for_updates
51-
if params[:reference] == @meeting_agenda_item.updated_at.iso8601
52+
current_reference = @meeting.changed_hash
53+
if params[:reference] == current_reference
5254
head :no_content
5355
return
5456
end
5557

56-
turbo_streams << turbo_stream.set_dataset_attribute(
57-
"#op-meeting-presentation-content",
58-
"reference-value",
59-
@meeting_agenda_item.updated_at.iso8601
60-
)
61-
62-
update_via_turbo_stream(
63-
component: MeetingAgendaItems::ItemComponent::ShowComponent.new(
64-
meeting_agenda_item: @meeting_agenda_item,
65-
current_occurrence: @meeting,
66-
presentation_mode: true
67-
)
68-
)
69-
70-
respond_with_turbo_streams
58+
update_reference_value(current_reference)
59+
update_content_via_turbo_stream
7160
end
7261

7362
private
@@ -87,6 +76,10 @@ def check_feature_flag
8776
end
8877
end
8978

79+
def set_started_at
80+
@started_at = params[:started_at].present? ? Time.zone.parse(params[:started_at]) : Time.current
81+
end
82+
9083
def check_presentable
9184
if @meeting.agenda_items.empty?
9285
flash[:warning] = t("meeting.presentation_mode.no_items_flash")

0 commit comments

Comments
 (0)