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
switch calendar view mode
Klaus Zanders7a94fe97f891
diff --git a/modules/costs/app/components/my/time_tracking/calendar_component.html.erb b/modules/costs/app/components/my/time_tracking/calendar_component.html.erbindex 55b8708b9f6..f5db518556a 100644--- a/modules/costs/app/components/my/time_tracking/calendar_component.html.erb+++ b/modules/costs/app/components/my/time_tracking/calendar_component.html.erb@@ -1,5 +1,5 @@<%= flex_layout(data: wrapper_data, classes: "time-entry-calendar") do |calendar_page| %>-<% calendar_page.with_row { render(My::TimeTracking::HeaderComponent.new(mode: mode, date: date)) } %>+<% calendar_page.with_row { render(My::TimeTracking::HeaderComponent.new(mode:, date:, view_mode: :calendar)) } %><% calendar_page.with_row do %><%= render(Primer::OpenProject::SubHeader.new) do |component|component.with_text { title }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.erbindex 22696b5ca1b..0201cb40011 100644--- a/modules/costs/app/components/my/time_tracking/header_component.html.erb+++ b/modules/costs/app/components/my/time_tracking/header_component.html.erb@@ -7,21 +7,24 @@])- 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)+ header.with_action_menu(+ menu_arguments: { anchor_align: :end },+ button_arguments: { button_block: calendar_mode_button_block }+ ) do |menu|+ %i[day week month].each do |action|+ menu.with_item(+ label: t("label_#{action}"),+ tag: :a,+ href: url_for(params.permit(:controller, :date, :view_mode).merge(action:))+ ) do |item|+ item.with_leading_visual_icon(icon: :calendar)+ end+ endendheader.with_action_menu(menu_arguments: { anchor_align: :end },- button_arguments: { button_block: params[:view_mode] == "list" ? list_button : cal_button }+ button_arguments: { button_block: view_mode_block }) do |menu|menu.with_item(label: t(:label_calendar),diff --git a/modules/costs/app/components/my/time_tracking/header_component.rb b/modules/costs/app/components/my/time_tracking/header_component.rbindex 34a79fdc6eb..4bd7f0b302d 100644--- a/modules/costs/app/components/my/time_tracking/header_component.rb+++ b/modules/costs/app/components/my/time_tracking/header_component.rb@@ -31,7 +31,7 @@module Mymodule TimeTrackingclass HeaderComponent < ApplicationComponent- options :date, :mode+ options :date, :mode, :view_modedef titlecase mode@@ -58,10 +58,49 @@ module Myenddef month_title- if Date.current == date- I18n.t(:label_today)+ if Date.current.all_month.include?(date)+ I18n.t(:label_this_month)else- I18n.t(:label_specific_day, day: I18n.l(date, format: :short))+ I18n.t(:label_specific_month, month: I18n.l(date, format: "%B %Y"))+ end+ end++ def view_mode_block+ if view_mode == :list+ lambda do |button|+ button.with_leading_visual_icon(icon: "list-unordered")+ button.with_trailing_action_icon(icon: "triangle-down")+ t(:label_list)+ end+ else+ lambda do |button|+ button.with_leading_visual_icon(icon: :calendar)+ button.with_trailing_action_icon(icon: "triangle-down")+ t(:label_calendar)+ end+ end+ end++ def calendar_mode_button_block+ case mode+ when :day+ lambda do |button|+ button.with_leading_visual_icon(icon: :calendar)+ button.with_trailing_action_icon(icon: "triangle-down")+ t(:label_day)+ end+ when :week+ lambda do |button|+ button.with_leading_visual_icon(icon: :calendar)+ button.with_trailing_action_icon(icon: "triangle-down")+ t(:label_week)+ end+ when :month+ lambda do |button|+ button.with_leading_visual_icon(icon: :calendar)+ button.with_trailing_action_icon(icon: "triangle-down")+ t(:label_month)+ endendendenddiff --git a/modules/costs/app/components/my/time_tracking/list_component.html.erb b/modules/costs/app/components/my/time_tracking/list_component.html.erbindex e30bd310c6c..cdc2790dd98 100644--- a/modules/costs/app/components/my/time_tracking/list_component.html.erb+++ b/modules/costs/app/components/my/time_tracking/list_component.html.erb@@ -1,5 +1,5 @@<%= component_wrapper(tag: "div", data: wrapper_data) do %>- <%= render(My::TimeTracking::HeaderComponent.new(mode: mode, date: date)) %>+ <%= render(My::TimeTracking::HeaderComponent.new(mode:, date:, view_mode: :list)) %><%= render(Primer::OpenProject::SubHeader.new) do |component|component.with_text { title }diff --git a/modules/costs/app/controllers/my/time_tracking_controller.rb b/modules/costs/app/controllers/my/time_tracking_controller.rbindex dfc83cc71f7..1f799f29d77 100644--- a/modules/costs/app/controllers/my/time_tracking_controller.rb+++ b/modules/costs/app/controllers/my/time_tracking_controller.rb@@ -34,21 +34,11 @@ module Myno_authorization_required!(:calendar, :day, :week, :month)- current_menu_item do |ctrl|- if ctrl.params[:action] == "day" && ctrl.today?- :my_time_tracking_today- elsif ctrl.params[:action] == "week" && ctrl.this_week?- :my_time_tracking_this_week- elsif ctrl.params[:action] == "month" && ctrl.this_month?- :my_time_tracking_this_month- else- :my_time_tracking- end- end+ menu_item :my_time_trackinglayout "global"- helper_method :current_day, :today?, :this_week?, :this_month?, :list_view_component+ helper_method :current_day, :today?, :this_week?, :this_month?, :list_view_component, :view_modedef calendarif mobile?@@ -107,7 +97,11 @@ module Myenddef view_mode- ActiveSupport::StringInquirer.new(params[:view_mode] || default_view_mode)+ if ["calendar", "list"].include?(params[:view_mode])+ params[:view_mode]+ else+ default_view_mode+ end.to_symenddef current_date@@ -126,10 +120,18 @@ module Myenddef list_view_component- if view_mode.list?- My::TimeTracking::ListComponent.new(time_entries: @time_entries, mode: params[:action].to_sym, date: current_day)+ if view_mode == :list+ My::TimeTracking::ListComponent.new(+ time_entries: @time_entries,+ mode: params[:action].to_sym,+ date: current_day+ )else- My::TimeTracking::CalendarComponent.new(time_entries: @time_entries, mode: params[:action].to_sym, date: current_day)+ My::TimeTracking::CalendarComponent.new(+ time_entries: @time_entries,+ mode: params[:action].to_sym,+ date: current_day+ )endenddiff --git a/modules/costs/config/locales/en.yml b/modules/costs/config/locales/en.ymlindex 8fa28fb6c10..7b688e0302a 100644--- a/modules/costs/config/locales/en.yml+++ b/modules/costs/config/locales/en.yml@@ -178,6 +178,8 @@ en:label_specific_week: "Week #%{week}"label_specific_month: "Month %{month}"label_list: "List"+ label_month: "Month"+ label_day: "Day"placeholder_activity_select_work_package_first: Work package selection is required firstdiff --git a/modules/costs/lib/costs/engine.rb b/modules/costs/lib/costs/engine.rbindex 5366b3c45bd..111ab738a03 100644--- a/modules/costs/lib/costs/engine.rb+++ b/modules/costs/lib/costs/engine.rb@@ -149,23 +149,23 @@ module Costscaption: :label_my_time_tracking,icon: :stopwatch- menu :global_menu,- :my_time_tracking_today,- { controller: "/my/time_tracking", action: "day" },- parent: :my_time_tracking,- caption: :label_today-- menu :global_menu,- :my_time_tracking_this_week,- { controller: "/my/time_tracking", action: "week" },- parent: :my_time_tracking,- caption: :label_this_week-- menu :global_menu,- :my_time_tracking_this_month,- { controller: "/my/time_tracking", action: "month" },- parent: :my_time_tracking,- caption: :label_this_month+ # menu :global_menu,+ # :my_time_tracking_today,+ # { controller: "/my/time_tracking", action: "day" },+ # parent: :my_time_tracking,+ # caption: :label_today+ #+ # menu :global_menu,+ # :my_time_tracking_this_week,+ # { controller: "/my/time_tracking", action: "week" },+ # parent: :my_time_tracking,+ # caption: :label_this_week+ #+ # menu :global_menu,+ # :my_time_tracking_this_month,+ # { controller: "/my/time_tracking", action: "month" },+ # parent: :my_time_tracking,+ # caption: :label_this_monthendinitializer "costs.settings" do