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
add view for workweek
Klaus Zandersb0b74984ca04
diff --git a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.tsindex e5241f1319a..37b641e8de1 100644--- a/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/my/time-tracking.controller.ts@@ -25,6 +25,8 @@ export default class MyTimeTrackingController extends Controller {canEdit: Boolean,allowTimes: Boolean,forceTimes: Boolean,+ workingDays: Array,+ startOfWeek: Number,};declare readonly calendarTarget:HTMLElement;@@ -38,6 +40,8 @@ export default class MyTimeTrackingController extends Controller {declare readonly forceTimesValue:boolean;declare readonly localeValue:string;declare readonly viewModeValue:string;+ declare readonly workingDaysValue:number[];+ declare readonly startOfWeekValue:number;private calendar:Calendar;private DEFAULT_TIMED_EVENT_DURATION = '01:00';@@ -85,7 +89,9 @@ export default class MyTimeTrackingController extends Controller {eventMaxStack: 2,eventShortHeight: 31,nowIndicator: true,- businessHours: { daysOfWeek: [1, 2, 3, 4, 5], startTime: '00:00', endTime: '24:00' },+ businessHours: { daysOfWeek: this.workingDaysValue, startTime: '00:00', endTime: '24:00' },+ hiddenDays: this.hiddenDays(),+ firstDay: this.startOfWeekValue,eventClassNames(arg) {return ['calendar-time-entry-event',@@ -373,6 +379,7 @@ export default class MyTimeTrackingController extends Controller {calendarView():string {switch (this.modeValue) {case 'week':+ case 'workweek':return 'timeGridWeek';case 'month':return 'dayGridMonth';@@ -383,6 +390,23 @@ export default class MyTimeTrackingController extends Controller {}}+ hiddenDays():number[] {+ // if we are not in workweek mode we do not hide any days+ if (this.modeValue !== 'workweek') {+ return [];+ }++ const hiddenDays = [0, 1, 2, 3, 4, 5, 6];+ this.workingDaysValue.forEach((day) => {+ const index = hiddenDays.indexOf(day);+ if (index > -1) {+ hiddenDays.splice(index, 1);+ }+ });++ return hiddenDays;+ }+newTimeEntry(event:ActionEvent) {const dialogParams = `onlyMe=true&date=${event.params.date}`;diff --git a/modules/costs/app/components/my/time_tracking/calendar_component.rb b/modules/costs/app/components/my/time_tracking/calendar_component.rbindex 8d229afcb62..c238905eccf 100644--- a/modules/costs/app/components/my/time_tracking/calendar_component.rb+++ b/modules/costs/app/components/my/time_tracking/calendar_component.rb@@ -52,7 +52,9 @@ module My"my--time-tracking-can-edit-value" => User.current.allowed_in_any_project?(:edit_own_time_entries),"my--time-tracking-allow-times-value" => TimeEntry.can_track_start_and_end_time?,"my--time-tracking-force-times-value" => TimeEntry.must_track_start_and_end_time?,- "my--time-tracking-locale-value" => I18n.locale+ "my--time-tracking-locale-value" => I18n.locale,+ "my--time-tracking-start-of-week-value" => Setting.start_of_week,+ "my--time-tracking-working-days-value" => working_days}end@@ -68,6 +70,13 @@ module MyI18n.t(mode, scope: "total_times", hours: total_str)end++ def working_days+ # Setting.working_days is mo=1, tu=2, we=3, th=4, fr=5, sa=6, su=7+ # hiddenDays in fullcalendar is su=0, mo=1, tu=2, we=3, th=4, fr=5, sa=6++ Setting.working_days.map { |day| day % 7 }.sort+ endendendenddiff --git a/modules/costs/app/components/my/time_tracking/list_component.rb b/modules/costs/app/components/my/time_tracking/list_component.rbindex d1b24a1039f..c8ac1260813 100644--- a/modules/costs/app/components/my/time_tracking/list_component.rb+++ b/modules/costs/app/components/my/time_tracking/list_component.rb@@ -53,7 +53,8 @@ module Mycase modewhen :day then [date]when :week then date.all_week- when :month then date.all_month.map(&:beginning_of_week).uniq+ when :workweek then workweek_days+ when :month then month_daysendend@@ -67,12 +68,29 @@ module Mydef date_title(date)if mode == :month- I18n.t(:label_specific_week, week: date.strftime("%W"))+ I18n.t(:label_specific_week, week: week_number(date))elseI18n.l(date, format: "%A %d")endend+ def workweek_days+ workdays_normalized = Setting.working_days.map { |day| day % 7 }.sort+ date.all_week.select { |d| workdays_normalized.include?(d.wday) }+ end++ def month_days+ date.all_month.map(&:beginning_of_week).uniq+ end++ def week_number(date)+ if Setting.start_of_week == 1 # monday+ I18n.l(date, format: "%W")+ else # 6 saturday, 7 sunday+ I18n.l(date, format: "%U")+ end+ end+def collapsed?(date)date.past?enddiff --git a/modules/costs/app/components/my/time_tracking/mode_switcher_component.rb b/modules/costs/app/components/my/time_tracking/mode_switcher_component.rbindex 7a9460c0a9c..6c08ba78a7b 100644--- a/modules/costs/app/components/my/time_tracking/mode_switcher_component.rb+++ b/modules/costs/app/components/my/time_tracking/mode_switcher_component.rb@@ -37,7 +37,7 @@ module Mydef callrender(Primer::Alpha::SegmentedControl.new("aria-label": I18n.t(:label_meeting_date_time))) do |control|- %i[day week month].each do |mode|+ %i[day week workweek month].each do |mode|control.with_item(tag: :a,href: my_time_tracking_path(date:, view_mode:, mode:),@@ -56,6 +56,8 @@ module My"op-calendar-day"when :week"op-calendar-week"+ when :workweek+ "briefcase"else"calendar"enddiff --git a/modules/costs/app/components/my/time_tracking/sub_header_component.rb b/modules/costs/app/components/my/time_tracking/sub_header_component.rbindex daa5dc72d69..914b94ee0de 100644--- a/modules/costs/app/components/my/time_tracking/sub_header_component.rb+++ b/modules/costs/app/components/my/time_tracking/sub_header_component.rb@@ -37,7 +37,7 @@ module Mycase modewhen :dayI18n.l(date, format: :long)- when :week+ when :week, :workweekbow = date.beginning_of_weekeow = date.end_of_week@@ -62,6 +62,9 @@ module Mywhen :day{ href: my_time_tracking_path(date: date - 1.day, view_mode:, mode:),aria: { label: I18n.t(:label_previous_day) } }+ when :workweek+ { href: my_time_tracking_path(date: date - 1.week, view_mode:, mode:),+ aria: { label: I18n.t(:label_previous_workweek) } }when :week{ href: my_time_tracking_path(date: date - 1.week, view_mode:, mode:),aria: { label: I18n.t(:label_previous_week) } }@@ -76,6 +79,9 @@ module Mywhen :day{ href: my_time_tracking_path(date: date + 1.day, view_mode:, mode:),aria: { label: I18n.t(:label_next_day) } }+ when :workweek+ { href: my_time_tracking_path(date: date + 1.week, view_mode:, mode:),+ aria: { label: I18n.t(:label_next_workweek) } }when :week{ href: my_time_tracking_path(date: date + 1.week, view_mode:, mode:),aria: { label: I18n.t(:label_next_week) } }diff --git a/modules/costs/app/controllers/my/time_tracking_controller.rb b/modules/costs/app/controllers/my/time_tracking_controller.rbindex 512c48ce3ce..50c90c9b023 100644--- a/modules/costs/app/controllers/my/time_tracking_controller.rb+++ b/modules/costs/app/controllers/my/time_tracking_controller.rb@@ -45,6 +45,7 @@ module Mydef indexcase modewhen :day then load_time_entries(date)+ when :workweek then load_time_entries(workweek)when :week then load_time_entries(date.all_week)when :month then load_time_entries(date.all_month)end@@ -73,6 +74,11 @@ module My@date ||= parsed_date || current_dateend+ def workweek+ workdays_normalized = Setting.working_days.map { |day| day % 7 }.sort+ date.all_week.select { |d| workdays_normalized.include?(d.wday) }+ end+def parsed_dateif params[:date].present?begin@@ -110,7 +116,7 @@ module Mydef current_datecase modewhen :day then Time.zone.today- when :week then Time.zone.today.beginning_of_week+ when :week, :workweek then Time.zone.today.beginning_of_weekwhen :month then Time.zone.today.beginning_of_monthendenddiff --git a/modules/costs/config/locales/en.yml b/modules/costs/config/locales/en.ymlindex 993c3485837..476b50a260a 100644--- a/modules/costs/config/locales/en.yml+++ b/modules/costs/config/locales/en.yml@@ -170,8 +170,10 @@ en:label_no_time: "No time tracked"label_next_day: "Next day"label_next_week: "Next week"+ label_next_workweek: "Next work week"label_next_month: "Next month"label_previous_day: "Previous day"+ label_previous_workweek: "Previous work week"label_previous_week: "Previous week"label_previous_month: "Previous month"label_specific_day: "Day %{day}"@@ -179,6 +181,7 @@ en:label_specific_month: "Month %{month}"label_list: "List"label_month: "Month"+ label_workweek: "Work week"label_day: "Day"label_today_capitalized: "Today"diff --git a/modules/costs/config/routes.rb b/modules/costs/config/routes.rbindex 856b91dc7e4..fef1b037ebb 100644--- a/modules/costs/config/routes.rb+++ b/modules/costs/config/routes.rb@@ -53,7 +53,7 @@ Rails.application.routes.draw doget "/time-tracking/(:mode-:view_mode)(/:date)" => "time_tracking#index",as: :time_tracking,constraints: {- mode: /day|week|month/,+ mode: /day|week|workweek|month/,view_mode: /list|calendar/,date: /\d{4}-\d{2}-\d{2}/}