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
Render non working days in the team planner and calendar
Oliver Günther5c45617bdbcd
diff --git a/frontend/src/app/core/days/weekday.service.ts b/frontend/src/app/core/days/weekday.service.tsindex b4e75d66570..5b4a63e0bc5 100644--- a/frontend/src/app/core/days/weekday.service.ts+++ b/frontend/src/app/core/days/weekday.service.ts@@ -50,9 +50,13 @@ export class WeekdayService {readonly injector:Injector,) {}- public isDateDisabled(date:Date):boolean {- const dayOfWeek = moment(date).isoWeekday();- return !!this.weekdays.find((wd) => wd.day === dayOfWeek && !wd.working);+ /**+ * @param date The iso day number (1-7) or a date instance+ * @return {boolean} whether the given iso day is working or not+ */+ public isNonWorkingDay(date:Date|number):boolean {+ const isoDayOfWeek = (typeof date === 'number') ? date : moment(date).isoWeekday();+ return !!this.weekdays.find((wd) => wd.day === isoDayOfWeek && !wd.working);}loadWeekdays():Observable<IWeekday[]> {diff --git a/frontend/src/app/features/calendar/op-calendar.service.ts b/frontend/src/app/features/calendar/op-calendar.service.tsindex 5b9a653e70b..4711bd6a553 100644--- a/frontend/src/app/features/calendar/op-calendar.service.ts+++ b/frontend/src/app/features/calendar/op-calendar.service.ts@@ -6,8 +6,12 @@ import {import {CalendarOptions,DatesSetArg,+ DayCellMountArg,+ DayHeaderMountArg,EventApi,EventDropArg,+ SlotLabelMountArg,+ SlotLaneMountArg,} from '@fullcalendar/core';import { I18nService } from 'core-app/core/i18n/i18n.service';import { ConfigurationService } from 'core-app/core/config/configuration.service';@@ -50,13 +54,18 @@ import { uiStateLinkClass } from 'core-app/features/work-packages/components/wp-import { debugLog } from 'core-app/shared/helpers/debug_output';import { WorkPackageViewContextMenu } from 'core-app/shared/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive';import { OPContextMenuService } from 'core-app/shared/components/op-context-menu/op-context-menu.service';-import { initial } from 'lodash';+import { WeekdayService } from 'core-app/core/days/weekday.service';export interface CalendarViewEvent {el:HTMLElement;event:EventApi;}+// The CalenderOptions typings are missing daygrid hooks+interface CalendarOptionsWithDayGrid extends CalendarOptions {+ dayGridDidMount:(data:DayCellMountArg) => void;+}+@Injectable()export class OpCalendarService extends UntilDestroyedMixin {static MAX_DISPLAYED = 100;@@ -75,6 +84,8 @@ export class OpCalendarService extends UntilDestroyedMixin {take(1),);+ weekdaysPromise = this.weekdayService.loadWeekdays().toPromise();+constructor(private I18n:I18nService,private configuration:ConfigurationService,@@ -95,6 +106,7 @@ export class OpCalendarService extends UntilDestroyedMixin {readonly halEditing:HalResourceEditingService,readonly wpTableSelection:WorkPackageViewSelectionService,readonly contextMenuService:OPContextMenuService,+ readonly weekdayService:WeekdayService,) {super();}@@ -235,7 +247,7 @@ export class OpCalendarService extends UntilDestroyedMixin {}public generateQueryProps(- query: QueryResource,+ query:QueryResource,startDate:string,endDate:string,):string {@@ -319,7 +331,7 @@ export class OpCalendarService extends UntilDestroyedMixin {this.contextMenuService.show(handler, event);}- private defaultOptions():CalendarOptions {+ private defaultOptions():CalendarOptionsWithDayGrid {return {editable: false,locale: this.I18n.locale,@@ -335,6 +347,11 @@ export class OpCalendarService extends UntilDestroyedMixin {initialDate: this.initialDate,initialView: this.initialView,datesSet: (dates) => this.updateDateParam(dates),+ dayHeaderDidMount: (data:DayHeaderMountArg) => this.applyNonWorkingDay(data),+ dayCellDidMount: (data:DayCellMountArg) => this.applyNonWorkingDay(data),+ dayGridDidMount: (data:DayCellMountArg) => this.applyNonWorkingDay(data),+ slotLaneDidMount: (data:SlotLaneMountArg) => this.applyNonWorkingDay(data),+ slotLabelDidMount: (data:SlotLabelMountArg) => this.applyNonWorkingDay(data),};}@@ -414,4 +431,12 @@ export class OpCalendarService extends UntilDestroyedMixin {return changeset;}++ private async applyNonWorkingDay(data:{ date?:Date, el:HTMLElement }) {+ await this.weekdaysPromise;++ if (data.date && this.weekdayService.isNonWorkingDay(data.date)) {+ data.el.classList.add('fc-non-working-day');+ }+ }}diff --git a/frontend/src/app/features/work-packages/components/wp-table/timeline/grid/wp-timeline-grid.directive.ts b/frontend/src/app/features/work-packages/components/wp-table/timeline/grid/wp-timeline-grid.directive.tsindex d6c707cabf4..9e284d0689a 100644--- a/frontend/src/app/features/work-packages/components/wp-table/timeline/grid/wp-timeline-grid.directive.ts+++ b/frontend/src/app/features/work-packages/components/wp-table/timeline/grid/wp-timeline-grid.directive.ts@@ -192,7 +192,7 @@ export class WorkPackageTableTimelineGrid implements AfterViewInit {private checkForNonWorkingDayHighlight(date:Moment, cell:HTMLElement) {const day = date.toDate();- if (this.weekdaysService.isDateDisabled(day)) {+ if (this.weekdaysService.isNonWorkingDay(day)) {cell.classList.add('wp-timeline--non-working-day');cell.dataset.qaSelector = `wp-timeline--non-working-day_${day.getDate()}-${day.getMonth() + 1}-${day.getFullYear()}`;}diff --git a/frontend/src/app/shared/components/datepicker/datepicker.modal.ts b/frontend/src/app/shared/components/datepicker/datepicker.modal.tsindex dfe2492dccc..e65d7bd766e 100644--- a/frontend/src/app/shared/components/datepicker/datepicker.modal.ts+++ b/frontend/src/app/shared/components/datepicker/datepicker.modal.ts@@ -244,7 +244,7 @@ export class DatePickerModalComponent extends OpModalComponent implements AfterVthis.onDataChange();},onDayCreate: (dObj:Date[], dStr:string, fp:flatpickr.Instance, dayElem:DayElement) => {- if (this.datePickerInstance?.weekdaysService.isDateDisabled(dayElem.dateObj)) {+ if (this.datePickerInstance?.weekdaysService.isNonWorkingDay(dayElem.dateObj)) {dayElem.classList.add('flatpickr-non-working-day');}diff --git a/frontend/src/app/shared/components/op-date-picker/datepicker.ts b/frontend/src/app/shared/components/op-date-picker/datepicker.tsindex 1ad5e90b746..c1c1e8704b2 100644--- a/frontend/src/app/shared/components/op-date-picker/datepicker.ts+++ b/frontend/src/app/shared/components/op-date-picker/datepicker.ts@@ -171,7 +171,7 @@ export class DatePicker {return moment(dateObj).format('W');},onDayCreate: (dObj:Date[], dStr:string, fp:flatpickr.Instance, dayElem:DayElement) => {- if (this.weekdaysService.isDateDisabled(dayElem.dateObj)) {+ if (this.weekdaysService.isNonWorkingDay(dayElem.dateObj)) {dayElem.classList.add('flatpickr-non-working-day');}},diff --git a/frontend/src/global_styles/vendor/_full_calendar.sass b/frontend/src/global_styles/vendor/_full_calendar.sassindex 2cfd7b5b384..a9d6c6d098b 100644--- a/frontend/src/global_styles/vendor/_full_calendar.sass+++ b/frontend/src/global_styles/vendor/_full_calendar.sass@@ -20,17 +20,12 @@table .fc-day-todaybackground: rgb(255 255 120 / 20%)- .fc-day-sat,- .fc-day-sun- background: rgb(109 109 109 / 20%)-- .fc-day-mon,- .fc-day-tue,- .fc-day-wed,- .fc-day-thu,- .fc-day-fri+ .fc-daybackground: rgb(205 205 205 / 20%)+ .fc-non-working-day+ background: rgb(109 109 109 / 20%)+// The days in full calendar are anchor elements which we do not// want to like like actual links.fc-col-header-cell a,diff --git a/modules/calendar/spec/features/calendar_dates_spec.rb b/modules/calendar/spec/features/calendar_dates_spec.rbnew file mode 100644index 00000000000..2a592131620--- /dev/null+++ b/modules/calendar/spec/features/calendar_dates_spec.rb@@ -0,0 +1,107 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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.+#++++require 'spec_helper'+require_relative './shared_context'++describe 'Calendar non working days', type: :feature, js: true do+ include_context 'with calendar full access'++ let!(:other_user) do+ create :user,+ firstname: 'Bernd',+ member_in_project: project,+ member_with_permissions: %w[+ view_work_packages view_calendar+ ]+ end++ before do+ login_as current_user++ week_days++ calendar.visit!+ end++ context 'with week days defined' do+ let!(:week_days) { create :week_days }++ it 'renders sat and sun as non working' do+ expect(page).to have_selector('.fc-day-sat.fc-non-working-day', minimum: 1, wait: 10)+ expect(page).to have_selector('.fc-day-sun.fc-non-working-day', minimum: 1)++ expect(page).to have_no_selector('.fc-day-mon.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-tue.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-wed.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-thu.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-fri.fc-non-working-day')++ find('.fc-next-button').click++ expect(page).to have_selector('.fc-day-sat.fc-non-working-day', minimum: 1, wait: 10)+ expect(page).to have_selector('.fc-day-sun.fc-non-working-day', minimum: 1)++ expect(page).to have_no_selector('.fc-day-mon.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-tue.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-wed.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-thu.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-fri.fc-non-working-day')+ end+ end++ context 'with all days marked as weekend' do+ let!(:week_days) do+ days = create(:week_days)++ WeekDay.update_all(working: false)++ days+ end++ it 'renders all as non working' do+ expect(page).to have_selector('.fc-day-sat.fc-non-working-day', minimum: 1, wait: 10)+ expect(page).to have_selector('.fc-day-sun.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-mon.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-tue.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-wed.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-thu.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-fri.fc-non-working-day', minimum: 1)++ find('.fc-next-button').click++ expect(page).to have_selector('.fc-day-sat.fc-non-working-day', minimum: 1, wait: 10)+ expect(page).to have_selector('.fc-day-sun.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-mon.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-tue.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-wed.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-thu.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-fri.fc-non-working-day', minimum: 1)+ end+ end+enddiff --git a/modules/team_planner/spec/features/team_planner_dates_spec.rb b/modules/team_planner/spec/features/team_planner_dates_spec.rbnew file mode 100644index 00000000000..7323349edb2--- /dev/null+++ b/modules/team_planner/spec/features/team_planner_dates_spec.rb@@ -0,0 +1,112 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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.+#++++require 'spec_helper'+require_relative './shared_context'++describe 'Team planner working days', type: :feature, js: true do+ before do+ with_enterprise_token(:team_planner_view)+ end++ include_context 'with team planner full access'++ context 'with week days defined' do+ let!(:week_days) { create :week_days }++ it 'renders sat and sun as non working' do+ team_planner.visit!++ team_planner.expect_empty_state+ retry_block do+ team_planner.click_add_user+ page.find('[data-qa-selector="tp-add-assignee"] input')+ team_planner.select_user_to_add user.name+ end++ expect(page).to have_selector('.fc-day-sat.fc-non-working-day', minimum: 1, wait: 10)+ expect(page).to have_selector('.fc-day-sun.fc-non-working-day', minimum: 1)++ expect(page).to have_no_selector('.fc-day-mon.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-tue.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-wed.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-thu.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-fri.fc-non-working-day')++ find('.fc-next-button').click++ expect(page).to have_selector('.fc-day-sat.fc-non-working-day', minimum: 1, wait: 10)+ expect(page).to have_selector('.fc-day-sun.fc-non-working-day', minimum: 1)++ expect(page).to have_no_selector('.fc-day-mon.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-tue.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-wed.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-thu.fc-non-working-day')+ expect(page).to have_no_selector('.fc-day-fri.fc-non-working-day')+ end+ end++ context 'with all days marked as weekend' do+ let!(:week_days) do+ days = create(:week_days)++ WeekDay.update_all(working: false)++ days+ end++ it 'renders all as non working' do+ team_planner.visit!++ team_planner.expect_empty_state+ retry_block do+ team_planner.click_add_user+ page.find('[data-qa-selector="tp-add-assignee"] input')+ team_planner.select_user_to_add user.name+ end++ expect(page).to have_selector('.fc-day-sat.fc-non-working-day', minimum: 1, wait: 10)+ expect(page).to have_selector('.fc-day-sun.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-mon.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-tue.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-wed.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-thu.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-fri.fc-non-working-day', minimum: 1)++ find('.fc-next-button').click++ expect(page).to have_selector('.fc-day-sat.fc-non-working-day', minimum: 1, wait: 10)+ expect(page).to have_selector('.fc-day-sun.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-mon.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-tue.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-wed.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-thu.fc-non-working-day', minimum: 1)+ expect(page).to have_selector('.fc-day-fri.fc-non-working-day', minimum: 1)+ end+ end+end