OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Extract the page header into its own component
Klaus Zandersb5b94399073e
diff --git a/modules/costs/app/components/my/time_tracking/header_component.html.erb b/modules/costs/app/components/my/time_tracking/header_component.html.erbnew file mode 100644index 00000000000..3fa0caefe7e--- /dev/null+++ b/modules/costs/app/components/my/time_tracking/header_component.html.erb@@ -0,0 +1,41 @@+<%= render(Primer::OpenProject::PageHeader.new) do |header|+ header.with_title(variant: :large) { title }+ header.with_breadcrumbs(+ [+ { text: I18n.t(:label_my_time_tracking), href: my_time_tracking_path },+ title+ ]+ )++ cal_button = lambda do |button|+ button.with_leading_visual_icon(icon: :calendar)+ button.with_trailing_action_icon(icon: :"triangle-down")+ t(:label_calendar)+ end++ list_button = lambda do |button|+ button.with_leading_visual_icon(icon: "list-unordered")+ button.with_trailing_action_icon(icon: :"triangle-down")+ t(:label_list)+ end++ header.with_action_menu(+ menu_arguments: { anchor_align: :end },+ button_arguments: { button_block: params[:view_mode] == "list" ? list_button : cal_button }+ ) do |menu|+ menu.with_item(+ label: "Calendar", tag: :a,+ href: url_for(params.permit(:controller, :action, :date).merge(view_mode: "calendar"))+ ) do |item|+ item.with_leading_visual_icon(icon: :calendar)+ end+ menu.with_item(+ label: "List", tag: :a,+ href: url_for(params.permit(:controller, :action, :date).merge(view_mode: "list"))+ ) do |item|+ item.with_leading_visual_icon(icon: "list-unordered")+ end+ end++ header.with_action_zen_mode_button+ end %>diff --git a/modules/costs/app/components/my/time_tracking/header_component.rb b/modules/costs/app/components/my/time_tracking/header_component.rbnew file mode 100644index 00000000000..34a79fdc6eb--- /dev/null+++ b/modules/costs/app/components/my/time_tracking/header_component.rb@@ -0,0 +1,69 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+# ++++module My+ module TimeTracking+ class HeaderComponent < ApplicationComponent+ options :date, :mode++ def title+ case mode+ when :week then week_title+ when :month then month_title+ when :day then day_title+ end+ end++ def day_title+ if Date.current == date+ I18n.t(:label_today)+ else+ I18n.t(:label_specific_day, day: I18n.l(date, format: :short))+ end+ end++ def week_title+ if Date.current.all_week.include?(date)+ I18n.t(:label_this_week)+ else+ I18n.t(:label_specific_week, week: I18n.l(date, format: "%W %Y"))+ end+ end++ def month_title+ if Date.current == date+ I18n.t(:label_today)+ else+ I18n.t(:label_specific_day, day: I18n.l(date, format: :short))+ end+ end+ end+ end+enddiff --git a/modules/costs/app/views/my/time_tracking/day.html.erb b/modules/costs/app/views/my/time_tracking/day.html.erbindex 141f7b39ece..c11e1bd347b 100644--- a/modules/costs/app/views/my/time_tracking/day.html.erb+++ b/modules/costs/app/views/my/time_tracking/day.html.erb@@ -1,13 +1,2 @@-<%=- render Primer::OpenProject::PageHeader.new do |header|- header.with_title { I18n.t(:label_today) }- header.with_breadcrumbs(- [- { text: I18n.t(:label_my_time_tracking), href: my_time_tracking_path },- I18n.t(:label_today)- ]- )- end-%>-+<%= render(My::TimeTracking::HeaderComponent.new(mode: params[:action].to_sym, date: current_day)) %><%= render(list_view_component) %>diff --git a/modules/costs/app/views/my/time_tracking/month.html.erb b/modules/costs/app/views/my/time_tracking/month.html.erbindex 6f55ca5bce5..c11e1bd347b 100644--- a/modules/costs/app/views/my/time_tracking/month.html.erb+++ b/modules/costs/app/views/my/time_tracking/month.html.erb@@ -1,13 +1,2 @@-<%=- render Primer::OpenProject::PageHeader.new do |header|- header.with_title { I18n.t(:label_this_month) }- header.with_breadcrumbs(- [- { text: I18n.t(:label_my_time_tracking), href: my_time_tracking_path },- I18n.t(:label_this_month)- ]- )- end-%>-+<%= render(My::TimeTracking::HeaderComponent.new(mode: params[:action].to_sym, date: current_day)) %><%= render(list_view_component) %>diff --git a/modules/costs/app/views/my/time_tracking/week.html.erb b/modules/costs/app/views/my/time_tracking/week.html.erbindex 4aea1d1b5fa..c11e1bd347b 100644--- a/modules/costs/app/views/my/time_tracking/week.html.erb+++ b/modules/costs/app/views/my/time_tracking/week.html.erb@@ -1,36 +1,2 @@-<%=- render Primer::OpenProject::PageHeader.new do |header|- header.with_title(variant: :large) { I18n.t(:label_this_week) }- header.with_breadcrumbs(- [- { text: I18n.t(:label_my_time_tracking), href: my_time_tracking_path },- I18n.t(:label_this_week)- ]- )-- cal_button = lambda do |button|- button.with_leading_visual_icon(icon: :calendar)- button.with_trailing_action_icon(icon: :"triangle-down")- "Calendar"- end-- list_button = lambda do |button|- button.with_leading_visual_icon(icon: "list-unordered")- button.with_trailing_action_icon(icon: :"triangle-down")- "List"- end-- header.with_action_menu(menu_arguments: { anchor_align: :end }, button_arguments: { button_block: params[:view_mode] == "list" ? list_button : cal_button }) do |menu|- menu.with_item(label: "Calendar", tag: :a, href: url_for(params.permit(:controller, :action, :date).merge(view_mode: "calendar"))) do |item|- item.with_leading_visual_icon(icon: :calendar)- end- menu.with_item(label: "List", tag: :a, href: url_for(params.permit(:controller, :action, :date).merge(view_mode: "list"))) do |item|- item.with_leading_visual_icon(icon: "list-unordered")- end- end-- header.with_action_zen_mode_button- end-%>-+<%= render(My::TimeTracking::HeaderComponent.new(mode: params[:action].to_sym, date: current_day)) %><%= render(list_view_component) %>diff --git a/modules/costs/config/locales/en.yml b/modules/costs/config/locales/en.ymlindex d86942f18b2..7b0ee4e9718 100644--- a/modules/costs/config/locales/en.yml+++ b/modules/costs/config/locales/en.yml@@ -172,6 +172,10 @@ en:label_previous_day: "Previous day"label_previous_week: "Previous week"label_previous_month: "Previous month"+ label_specific_day: "Day %{day}"+ label_specific_week: "Week #%{week}"+ label_specific_month: "Month %{month}"+ label_list: "List"placeholder_activity_select_work_package_first: Work package selection is required first