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
[45001] Create a new component to show the list of non-working days of a year (#11718)
Behrokh Satarnejad30ce7a915d4d
diff --git a/app/controllers/admin/settings/working_days_settings_controller.rb b/app/controllers/admin/settings/working_days_settings_controller.rbindex c20146f0568..3cb0e20ff1d 100644--- a/app/controllers/admin/settings/working_days_settings_controller.rb+++ b/app/controllers/admin/settings/working_days_settings_controller.rb@@ -13,9 +13,9 @@ module Admin::Settingsenddef failure_callback(call)- @modified_non_working_days = call.result+ @modified_non_working_days = modified_non_working_days_for(call.result)flash[:error] = call.message || I18n.t(:notice_internal_server_error)- render action: 'show', tab: params[:tab]+ render action: 'show'endprotected@@ -38,8 +38,18 @@ module Admin::Settingsenddef non_working_days_params- non_working_days = params[:settings].to_unsafe_hash[:non_working_days] || {}+ non_working_days = params[:settings].to_unsafe_hash[:non_working_days_attributes] || {}non_working_days.to_h.valuesend++ def modified_non_working_days_for(result)+ return if result.nil?++ result.map do |record|+ json_attributes = record.as_json(only: %i[id name date])+ json_attributes["_destroy"] = true if record.marked_for_destruction?+ json_attributes+ end+ endendenddiff --git a/app/helpers/confirmation_dialog_helper.rb b/app/helpers/confirmation_dialog_helper.rbindex fb9d0c673b0..323faa355e6 100644--- a/app/helpers/confirmation_dialog_helper.rb+++ b/app/helpers/confirmation_dialog_helper.rb@@ -34,10 +34,14 @@ module ConfirmationDialogHelpertitle: nil,text: nil,danger_zone: false,+ show_list_data: false,+ list_title: nil,+ warning_text: nil,button_continue: nil,button_cancel: nil,icon_continue: nil,- divider: nil+ divider: nil,+ passed_data: nil){'augmented-confirm-dialog': {@@ -49,6 +53,10 @@ module ConfirmationDialogHelper}.compact,dangerHighlighting: danger_zone,divideContent: divider,+ listTitle: list_title,+ warningText: warning_text,+ passedData: passed_data,+ showListData: show_list_data,icon: {continue: icon_continue}.compactdiff --git a/app/services/settings/working_days_update_service.rb b/app/services/settings/working_days_update_service.rbindex ccf314964a5..82fae2ea6ff 100644--- a/app/services/settings/working_days_update_service.rb+++ b/app/services/settings/working_days_update_service.rb@@ -16,7 +16,7 @@## 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+# MERCHANTALITY 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@@ -93,7 +93,11 @@ class Settings::WorkingDaysUpdateService < Settings::UpdateServiceenddef destroy_records(ids)- wrap_result NonWorkingDay.where(id: ids).destroy_all+ records = NonWorkingDay.where(id: ids)+ # In case the transaction fails we also mark the records for destruction,+ # this way we can display them correctly on the frontend.+ records.each(&:mark_for_destruction)+ wrap_result records.destroy_allenddef wrap_result(result)diff --git a/app/views/admin/settings/working_days_settings/show.html.erb b/app/views/admin/settings/working_days_settings/show.html.erbindex 21c7ecf5adb..b0ec8e14169 100644--- a/app/views/admin/settings/working_days_settings/show.html.erb+++ b/app/views/admin/settings/working_days_settings/show.html.erb@@ -42,13 +42,6 @@ See COPYRIGHT and LICENSE files for more details.<%= styled_form_tag(admin_settings_working_days_path,method: :patch,- data: augmented_confirmation_dialog(- title: t('working_days.change_button'),- button_continue: t('working_days.change_button'),- text: "#{t('working_days.warning')}\n#{t(:text_are_you_sure_continue)}",- danger_zone: true,- divider: true- ),class: 'op-working-days-admin-settings') do %><section class="form--section">@@ -62,5 +55,9 @@ See COPYRIGHT and LICENSE files for more details.label: false %></div></section>++ <%= angular_component_tag 'op-non-working-days-list',+ data: { modified_non_working_days: @modified_non_working_days } %>+<%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark' %><% end %>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 246301bd4ea..ebe88dd6d58 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3164,7 +3164,7 @@ en:Non-working days are skipped when scheduling work packages and are excluded when calculating duration. This can be overridden at a work-package level.change_button: "Change working days"warning: >- Changing which days of the week are considered working days can affect the start and finish days of all work packages in all projects in this instance.+ Changing which days of the week are considered working days or non-working days can affect the start and finish days of all work packages in all projects in this instance. Please not that changes are only applied after you click on the save changes button.journal_note:changed: _**Working days** changed (%{changes})._days:diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 3ad71960bd7..ac61d0b7669 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -278,6 +278,21 @@ en:unlimited: "Unlimited"you_contribute: "Developers need to pay their bills, too. By upgrading to the Enterprise edition, you will be supporting this open source community effort and contributing to its development, maintenance and continuous improvement."+ working_days:+ calendar:+ empty_state_header: "Non-working days"+ empty_state_description: 'No specific non-working days are defined for this year. Click on "Add non-working day" below to add a date.'+ new_date: '(new)'+ add_non_working_day: "Add non-working day"+ already_added_error: "A non-working day for this date exists already. There can only be one non-working day created for each unique date."+ change_button: "Save and reschedule"+ change_title: "Change working days"+ removed_title: "You will remove the following days from the non-working days list:"+ change_description: "Changing which days of the week are considered working days or non-working days can affect the start and finish days of all work packages in all projects in this instance."+ warning: >+ The changes might take some time to take effect. You will be notified when all relevant work packages have been updated.++ Are you sure you want to to continue?custom_actions:date:specific: 'on'diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.jsindex dbbec2e87b8..7e2eefd7f71 100644--- a/frontend/.eslintrc.js+++ b/frontend/.eslintrc.js@@ -143,6 +143,7 @@ module.exports = {"_embedded","_meta","_type",+ "_destroy",],allowAfterThis: true,allowAfterSuper: false,diff --git a/frontend/package-lock.json b/frontend/package-lock.jsonindex 2280421a0b0..f23333ee67c 100644--- a/frontend/package-lock.json+++ b/frontend/package-lock.json@@ -29,6 +29,7 @@"@fullcalendar/core": "^6.0.2","@fullcalendar/daygrid": "^6.0.2","@fullcalendar/interaction": "^6.0.2",+ "@fullcalendar/list": "^6.0.2","@fullcalendar/resource": "^6.0.2","@fullcalendar/resource-common": "^6.0.0-beta.1","@fullcalendar/resource-timeline": "^6.0.2",@@ -5074,6 +5075,14 @@"@fullcalendar/core": "~6.0.2"}},+ "node_modules/@fullcalendar/list": {+ "version": "6.0.2",+ "resolved": "https://registry.npmjs.org/@fullcalendar/list/-/list-6.0.2.tgz",+ "integrity": "sha512-xeTNqGgQvW6u2isX8P3IV8w19Jzn/4Fs6nNc5tiEs0WJ6zd1bYEfruzDL0WPMMmcydgpkv0YHTLMwlnlFeq9+g==",+ "peerDependencies": {+ "@fullcalendar/core": "~6.0.2"+ }+ },"node_modules/@fullcalendar/premium-common": {"version": "6.0.0-beta.1","resolved": "https://registry.npmjs.org/@fullcalendar/premium-common/-/premium-common-6.0.0-beta.1.tgz",@@ -52218,6 +52227,11 @@"resolved": "https://registry.npmjs.org/@fullcalendar/interaction/-/interaction-6.0.2.tgz","integrity": "sha512-RPWWCp6wdzVCc3XdcBUZuduFGX/mB8OrV2xBF5wrGFbGAZE3OYuEPcVnLF1SsC+pJVntG6z1fL5aQ/OM8nul9Q=="},+ "@fullcalendar/list": {+ "version": "6.0.2",+ "resolved": "https://registry.npmjs.org/@fullcalendar/list/-/list-6.0.2.tgz",+ "integrity": "sha512-xeTNqGgQvW6u2isX8P3IV8w19Jzn/4Fs6nNc5tiEs0WJ6zd1bYEfruzDL0WPMMmcydgpkv0YHTLMwlnlFeq9+g=="+ },"@fullcalendar/premium-common": {"version": "6.0.0-beta.1","resolved": "https://registry.npmjs.org/@fullcalendar/premium-common/-/premium-common-6.0.0-beta.1.tgz",diff --git a/frontend/package.json b/frontend/package.jsonindex d8fc46eaa17..ec702d21c52 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -103,6 +103,7 @@"@fullcalendar/core": "^6.0.2","@fullcalendar/daygrid": "^6.0.2","@fullcalendar/interaction": "^6.0.2",+ "@fullcalendar/list": "^6.0.2","@fullcalendar/resource": "^6.0.2","@fullcalendar/resource-common": "^6.0.0-beta.1","@fullcalendar/resource-timeline": "^6.0.2",diff --git a/frontend/src/app/core/setup/global-dynamic-components.const.ts b/frontend/src/app/core/setup/global-dynamic-components.const.tsindex 246fac0c5e6..81b8ab701fe 100644--- a/frontend/src/app/core/setup/global-dynamic-components.const.ts+++ b/frontend/src/app/core/setup/global-dynamic-components.const.ts@@ -162,6 +162,10 @@ import {EnterprisePageComponent,enterprisePageSelector,} from 'core-app/shared/components/enterprise-page/enterprise-page.component';+import {+ OpNonWorkingDaysListComponent,+ nonWorkingDaysListSelector,+} from 'core-app/shared/components/op-non-working-days-list/op-non-working-days-list.component';import {EEActiveSavedTrialComponent,enterpriseActiveSavedTrialSelector,@@ -246,6 +250,7 @@ export const globalDynamicComponents:OptionalBootstrapDefinition[] = [{ selector: globalSearchSelector, cls: GlobalSearchInputComponent },{ selector: collapsibleSectionAugmentSelector, cls: CollapsibleSectionComponent },{ selector: enterpriseBannerSelector, cls: EnterpriseBannerComponent },+ { selector: nonWorkingDaysListSelector, cls: OpNonWorkingDaysListComponent },{ selector: enterprisePageSelector, cls: EnterprisePageComponent },{ selector: noResultsSelector, cls: NoResultsComponent },{ selector: enterpriseBaseSelector, cls: EnterpriseBaseComponent },diff --git a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.html b/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.htmlindex c70b96fabf2..5fdd82793e9 100644--- a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.html+++ b/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.html@@ -46,14 +46,16 @@<ng-content select="[slot=extra-fields]"></ng-content>- <spot-form-field- [label]="text.date"- >- <spot-text-field- slot="input"- name="date"- class="op-datepicker-modal--date-field"- [ngModel]="workingValue"+ <spot-form-field+ [label]="text.date"+ [required]="required"+ >+ <spot-text-field+ slot="input"+ name="date"+ class="op-datepicker-modal--date-field"+ [ngModel]="workingValue"+ [required]="required"(ngModelChange)="writeWorkingValue($event)"[showClearButton]="true"></spot-text-field>diff --git a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.ts b/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.tsindex 64a935b9593..61b4e459215 100644--- a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.ts+++ b/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.ts@@ -41,7 +41,10 @@ import {ViewEncapsulation,} from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';-import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';+import {+ ControlValueAccessor,+ NG_VALUE_ACCESSOR,+} from '@angular/forms';import {onDayCreate,parseDate,@@ -163,12 +166,16 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, AfterC}save($event:Event) {- $event.preventDefault();- this.valueChange.emit(this.workingValue);- this.onChange(this.workingValue);- this.writeValue(this.workingValue);- this.opened = false;- this.cdRef.detectChanges();+ const form = $event.target as HTMLFormElement;++ if (form.reportValidity()) {+ $event.preventDefault();+ this.valueChange.emit(this.workingValue);+ this.onChange(this.workingValue);+ this.writeValue(this.workingValue);+ this.opened = false;+ this.cdRef.detectChanges();+ }}setToday():void {diff --git a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.html b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.htmlindex 34257f6bbe9..eb4eb87f432 100644--- a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.html+++ b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.html@@ -14,13 +14,32 @@<span class="op-confirm-dialog--text spot-body-small"[textContent]="text.text"></span>- <span- *ngFor="let data of passedData"- class="spot-body-small"- >- <br/>- <strong>{{data}}</strong>- </span>++ <ng-container *ngIf="showListData; else showData">+ <span class="op-confirm-dialog--text spot-body-small"+ [textContent]="listTitle"+ ></span>+ <ul class="op-confirm-dialog--list">+ <li *ngFor="let data of passedData">+ <span>{{data}}</span>+ </li>+ </ul>+ </ng-container>++ <ng-template #showData>+ <span+ *ngFor="let data of passedData"+ class="spot-body-small"+ >+ <br/>+ <strong>{{data}}</strong>+ </span>+ </ng-template>++ <span class="op-confirm-dialog--text spot-body-small"+ [textContent]="warningText"+ ></span>+</div><div class="spot-action-bar">diff --git a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.sass b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.sassindex 4ebc798b1c8..238f785d30f 100644--- a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.sass+++ b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.sass@@ -1,3 +1,6 @@.op-confirm-dialog&--textwhite-space: pre-wrap++ &--list+ margin-left: var(--list-side-margin) !importantdiff --git a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.ts b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.tsindex 08406177935..9d5f57bf15c 100644--- a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.ts+++ b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.modal.ts@@ -53,6 +53,9 @@ export interface ConfirmDialogOptions {closeByEscape?:boolean;showClose?:boolean;closeByDocument?:boolean;+ showListData?:boolean;+ listTitle?:string;+ warningText?:string;passedData?:string[];dangerHighlighting?:boolean;divideContent?:boolean;@@ -66,6 +69,12 @@ export interface ConfirmDialogOptions {export class ConfirmDialogModalComponent extends OpModalComponent {public showClose:boolean;+ public showListData:boolean;++ public listTitle:string;++ public warningText:string;+public divideContent:boolean;public confirmed = false;@@ -97,6 +106,9 @@ export class ConfirmDialogModalComponent extends OpModalComponent {this.options = (locals.options || {}) as ConfirmDialogOptions;this.dangerHighlighting = _.defaultTo(this.options.dangerHighlighting, false);+ this.showListData = _.defaultTo(this.options.showListData, false);+ this.listTitle = _.defaultTo(this.options.listTitle, '');+ this.warningText = _.defaultTo(this.options.warningText, '');this.passedData = _.defaultTo(this.options.passedData, []);this.showClose = _.defaultTo(this.options.showClose, true);this.divideContent = _.defaultTo(this.options.divideContent, false);diff --git a/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.html b/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.htmlnew file mode 100644index 00000000000..672d6baf685--- /dev/null+++ b/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.html@@ -0,0 +1,58 @@+<full-calendar+ #ucCalendar+ *ngIf="calendarOptions"+ [options]="calendarOptions"+ class="op-non-working-days-list--calendar"+></full-calendar>++<ng-container *ngFor="let date of nonWorkingDays;">+ <ng-container *ngIf="!date.id">+ <input type="hidden" name="settings[non_working_days_attributes][{{ date.date }}][date]" [value]="date.date"/>+ <input type="hidden" name="settings[non_working_days_attributes][{{ date.date }}][name]" [value]="date.name"/>+ </ng-container>+ <ng-container *ngIf="date.id && date._destroy">+ <input type="hidden" name="settings[non_working_days_attributes][{{ date.id }}][id]" [value]="date.id"/>+ <input type="hidden" name="settings[non_working_days_attributes][{{ date.id }}][_destroy]" value="true" />+ </ng-container>+</ng-container>++<div+ class="op-non-working-days-list--add-button"+>+ <op-single-date-picker+ id="test"+ name="test"+ [showIgnoreNonWorkingDays]="false"+ [opened]="datepickerOpened"+ [required]="true"+ [showIgnoreNonWorkingDays]="false"+ [name]="text.add_non_working_day"+ (closed)="datepickerOpened = false"+ (valueChange)="addNonWorkingDay($event)"+ >+ <spot-form-field+ slot="extra-fields"+ [required]="true"+ [label]="text.non_working_day_name"+ >+ <spot-text-field+ name="name"+ slot="input"+ [required]="true"+ [(ngModel)]="selectedNonWorkingDayName"+ [showClearButton]="false"+ ></spot-text-field>+ </spot-form-field>++ <button+ slot="trigger"+ type="button"+ class="spot-link op-non-working-days-list--add-button"+ (click)="datepickerOpened = true"+ >+ <span class="spot-icon spot-icon_add"></span>+ <span [textContent]="text.add_non_working_day"></span>+ </button>+ </op-single-date-picker>+</div>+diff --git a/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.sass b/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.sassnew file mode 100644index 00000000000..cbdc7009016--- /dev/null+++ b/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.sass@@ -0,0 +1,23 @@+@import '../../app/spot/styles/sass/variables'++.op-non-working-days-list+ .fc-list-event-graphic+ display: none++ &--delete-icon+ opacity: 0++ &--add-button+ padding: $spot-spacing-0_5 0++ .fc-list-event+ &:hover+ .op-non-working-days-list--delete-icon+ opacity: 1++ .fc-list-empty+ display: unset !important+ background: inherit++ .fc-list-empty-cushion+ margin: auto !importantdiff --git a/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.ts b/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.tsnew file mode 100644index 00000000000..e297fc96e25--- /dev/null+++ b/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.ts@@ -0,0 +1,233 @@+import {+ ChangeDetectionStrategy,+ ChangeDetectorRef,+ Component,+ ElementRef,+ HostBinding,+ Injector,+ Input,+ OnInit,+ ViewChild,+ ViewEncapsulation,+} from '@angular/core';+import { BannersService } from 'core-app/core/enterprise/banners.service';+import { I18nService } from 'core-app/core/i18n/i18n.service';+import { OpModalService } from '../modal/modal.service';+import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';+import { populateInputsFromDataset } from 'core-app/shared/components/dataset-inputs';+import { FullCalendarComponent } from '@fullcalendar/angular';+import {+ EventInput,+ CalendarOptions,+} from '@fullcalendar/core';+import listPlugin from '@fullcalendar/list';+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';+import { DayResourceService } from 'core-app/core/state/days/day.service';+import { IDay } from 'core-app/core/state/days/day.model';+import { CalendarViewEvent } from 'core-app/features/calendar/op-work-packages-calendar.service';+import { opIconElement } from 'core-app/shared/helpers/op-icon-builder';+import { ConfirmDialogService } from 'core-app/shared/components/modals/confirm-dialog/confirm-dialog.service';+import { ConfirmDialogOptions } from '../modals/confirm-dialog/confirm-dialog.modal';+import { ToastService } from 'core-app/shared/components/toaster/toast.service';++export const nonWorkingDaysListSelector = 'op-non-working-days-list';++export interface INonWorkingDay {+ id:string|null;+ name:string;+ date:string;+ _destroy?:boolean;+}++@Component({+ selector: nonWorkingDaysListSelector,+ changeDetection: ChangeDetectionStrategy.OnPush,+ encapsulation: ViewEncapsulation.None,+ styleUrls: ['./op-non-working-days-list.component.sass'],+ templateUrl: './op-non-working-days-list.component.html',+})+export class OpNonWorkingDaysListComponent implements OnInit {+ @ViewChild(FullCalendarComponent) ucCalendar:FullCalendarComponent;++ @HostBinding('class.op-non-working-days-list') className = true;++ @Input() public modifiedNonWorkingDays:INonWorkingDay[] = [];++ text = {+ empty_state_header: this.I18n.t('js.admin.working_days.calendar.empty_state_header'),+ empty_state_description: this.I18n.t('js.admin.working_days.calendar.empty_state_description'),+ already_added_error: this.I18n.t('js.admin.working_days.already_added_error'),+ new_date: this.I18n.t('js.admin.working_days.calendar.new_date'),+ add_non_working_day: this.I18n.t('js.admin.working_days.add_non_working_day'),+ change_description: this.I18n.t('js.admin.working_days.change_description'),+ warning: this.I18n.t('js.admin.working_days.warning'),+ change_button: this.I18n.t('js.admin.working_days.change_button'),+ change_title: this.I18n.t('js.admin.working_days.change_title'),+ removed_title: this.I18n.t('js.admin.working_days.removed_title'),+ non_working_day_name: this.I18n.t('js.modals.label_name'),+ };++ form_submitted = false;++ nonWorkingDays:INonWorkingDay[] = [];++ datepickerOpened = false;++ selectedNonWorkingDayName:string = '';++ calendarOptions:CalendarOptions = {+ plugins: [listPlugin],+ initialView: 'listYear',+ contentHeight: 'auto',+ headerToolbar: {+ right: 'prev,next',+ center: '',+ left: 'title',+ },+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment+ events: this.calendarEventsFunction.bind(this),+ eventDidMount: (evt:CalendarViewEvent) => {+ const { el, event } = evt;+ const td = document.createElement('td');+ const anchor = document.createElement('a');+ anchor.title = 'Delete';+ anchor.href = '#';+ anchor.classList.add('fc-list-day-side-text', 'op-non-working-days-list--delete-icon');+ anchor.appendChild(opIconElement('icon', 'icon-delete'));++ anchor.addEventListener('click', () => {+ // Create 4 hidden inputs(id, name, date, _destroy) for the deleted NWD+ this.nonWorkingDays = this.nonWorkingDays.map((item) => {+ if (item.date === event.id) {+ return { ...item, _destroy: true };+ }++ return item;+ });+ event.remove();+ this.cdRef.detectChanges();+ });+ td.appendChild(anchor);+ el.appendChild(td);+ },+ noEventsContent: { html: `<table class="fc-list-table"><tbody><th><div class="fc-list-day-cushion"><a class="fc-list-day-text">${this.text.empty_state_header}</a></div></th><tr class="fc-event"><td>${this.text.empty_state_description}</td></tr></tbody></table>` },++ };++ constructor(+ readonly elementRef:ElementRef<HTMLElement>,+ protected I18n:I18nService,+ readonly bannersService:BannersService,+ readonly opModalService:OpModalService,+ readonly injector:Injector,+ readonly pathHelper:PathHelperService,+ readonly apiV3Service:ApiV3Service,+ readonly dayService:DayResourceService,+ readonly confirmDialogService:ConfirmDialogService,+ readonly toast:ToastService,+ readonly cdRef:ChangeDetectorRef,+ ) {+ populateInputsFromDataset(this);+ this.listenToFormSubmit();+ }++ private listenToFormSubmit() {+ const form = this.elementRef.nativeElement.closest('form') as HTMLFormElement;+ form.addEventListener('submit', (evt:Event) => {+ if (!this.form_submitted) {+ this.form_submitted = true;+ const target = evt.target as HTMLFormElement;+ const options:ConfirmDialogOptions = {+ text: {+ text: this.text.change_description,+ title: this.text.change_title,+ button_continue: this.text.change_button,+ },+ dangerHighlighting: true,+ divideContent: true,+ showListData: this.removedNonWorkingDays.length > 0,+ warningText: this.text.warning,+ passedData: this.removedNonWorkingDays,+ listTitle: this.text.removed_title,+ };+ evt.preventDefault();+ void this.confirmDialogService.confirm(options).then(() => {+ this.form_submitted = false;+ target.submit();+ });+ }+ });+ }++ ngOnInit():void {+ this+ .modifiedNonWorkingDays+ .forEach((el) => {+ this.nonWorkingDays.push({ ...el });+ });+ }++ public get removedNonWorkingDays():string[] {+ return this+ .nonWorkingDays+ .filter((el) => el._destroy)+ .map((el) => el.date);+ }++ public calendarEventsFunction(+ fetchInfo:{ start:Date },+ successCallback:(events:EventInput[]) => void,+ failureCallback:(error:unknown) => void,+ ):void|PromiseLike<EventInput[]> {+ this.dayService.requireNonWorkingYear$(fetchInfo.start)+ .subscribe(+ (days:IDay[]) => {+ this.nonWorkingDays = _+ .uniqBy([...this.nonWorkingDays, ...days], (el) => el.date)+ .filter((el:INonWorkingDay) => !this.nonWorkingDays.find((existing) => existing.id === el.id && existing._destroy));++ const events = this.mapToCalendarEvents(this.nonWorkingDays);+ successCallback(events);+ this.cdRef.detectChanges();+ },+ failureCallback,+ );+ }++ private mapToCalendarEvents(nonWorkingDays:INonWorkingDay[]) {+ return nonWorkingDays+ .filter((nwd) => nwd._destroy !== true)+ .map((nwd:IDay) => ({+ title: nwd.name,+ start: nwd.date,+ id: nwd.date,+ }));+ }++ public addNonWorkingDay(date:string):void {+ const name = this.selectedNonWorkingDayName;+ this.selectedNonWorkingDayName = '';++ if (!date || date === '' || !name || name === '') {+ return;+ }++ const day = {+ start: date,+ id: null,+ name,+ date,+ title: name,+ } as INonWorkingDay;++ const api = this.ucCalendar.getApi();++ if (api.getEventById(date)) {+ this.toast.addError(this.text.already_added_error);+ return;+ }++ this.nonWorkingDays = [...this.nonWorkingDays, day];+ api.addEvent({ ...day, id: date });+ }+}diff --git a/frontend/src/app/shared/shared.module.ts b/frontend/src/app/shared/shared.module.tsindex c8b25610908..2eae233bf2c 100644--- a/frontend/src/app/shared/shared.module.ts+++ b/frontend/src/app/shared/shared.module.ts@@ -94,9 +94,11 @@ import { OpSidemenuComponent } from './components/sidemenu/sidemenu.component';import { OpProjectIncludeComponent } from './components/project-include/project-include.component';import { OpProjectIncludeListComponent } from './components/project-include/list/project-include-list.component';import { OpLoadingProjectListComponent } from './components/searchable-project-list/loading-project-list.component';+import { OpNonWorkingDaysListComponent } from './components/op-non-working-days-list/op-non-working-days-list.component';import { ViewsResourceService } from 'core-app/core/state/views/views.service';import { OpenprojectContentLoaderModule } from 'core-app/shared/components/op-content-loader/openproject-content-loader.module';import { OpenprojectModalModule } from './components/modal/modal.module';+import { FullCalendarModule } from '@fullcalendar/angular';export function bootstrapModule(injector:Injector):void {// Ensure error reporter is run@@ -144,6 +146,7 @@ export function bootstrapModule(injector:Injector):void {FocusModule,IconModule,AttributeHelpTextModule,+ FullCalendarModule,],exports: [// Re-export all commonly used@@ -213,6 +216,8 @@ export function bootstrapModule(injector:Injector):void {OpWpMultiDateFormComponent,OpDatePickerWorkingDaysToggleComponent,OpDatePickerSchedulingToggleComponent,++ OpNonWorkingDaysListComponent,],providers: [StaticQueriesService,@@ -268,6 +273,8 @@ export function bootstrapModule(injector:Injector):void {OpProjectIncludeListComponent,OpLoadingProjectListComponent,+ OpNonWorkingDaysListComponent,+// Date pickersOpWpSingleDateFormComponent,OpSingleDatePickerComponent,diff --git a/frontend/src/app/spot/components/text-field/text-field.component.html b/frontend/src/app/spot/components/text-field/text-field.component.htmlindex 209ba77c5cd..c297b97af6c 100644--- a/frontend/src/app/spot/components/text-field/text-field.component.html+++ b/frontend/src/app/spot/components/text-field/text-field.component.html@@ -6,6 +6,7 @@[attr.inputmode]="inputmode"[disabled]="disabled"[placeholder]="placeholder"+ [required]="required"[ngModel]="value"(ngModelChange)="valueChanged($event)"(focus)="onInputFocus($event)"diff --git a/frontend/src/app/spot/components/text-field/text-field.component.ts b/frontend/src/app/spot/components/text-field/text-field.component.tsindex b4a68f7f3ad..161d97f8cdb 100644--- a/frontend/src/app/spot/components/text-field/text-field.component.ts+++ b/frontend/src/app/spot/components/text-field/text-field.component.ts@@ -67,6 +67,11 @@ export class SpotTextFieldComponent implements ControlValueAccessor {*/@Input() public value = '';+ /**+ * Whether the field should be receive a [required] property.+ */+ @Input() public required:boolean = false;+/*** The html input (Regexp) pattern to provide hints to keyboards what layout to use* and to aid in validation.diff --git a/package.json b/package.jsonindex 0a868a1f31c..a5684779c40 100644--- a/package.json+++ b/package.json@@ -16,5 +16,9 @@"devDependencies": {"@redocly/openapi-cli": "^1.0.0-beta.80","webfonts-generator": "^0.4.0"+ },+ "dependencies": {+ "@fullcalendar/core": "^6.0.2",+ "@fullcalendar/list": "^6.0.2"}}diff --git a/spec/controllers/admin/settings/working_days_settings_controller_spec.rb b/spec/controllers/admin/settings/working_days_settings_controller_spec.rbindex 6a2f6f46cfb..a9ff7e12730 100644--- a/spec/controllers/admin/settings/working_days_settings_controller_spec.rb+++ b/spec/controllers/admin/settings/working_days_settings_controller_spec.rb@@ -50,9 +50,9 @@ describe Admin::Settings::WorkingDaysSettingsController dodescribe 'update' dolet(:working_days) { [*'1'..'7'] }- let(:non_working_days) { {} }+ let(:non_working_days_attributes) { {} }let(:params) do- { settings: { working_days:, non_working_days: } }+ { settings: { working_days:, non_working_days_attributes: } }endsubject { patch 'update', params: }@@ -65,7 +65,7 @@ describe Admin::Settings::WorkingDaysSettingsController doendcontext 'with non_working_days' do- let(:non_working_days) do+ let(:non_working_days_attributes) do{ '0' => { 'name' => 'Christmas Eve', 'date' => '2022-12-24' } }end@@ -84,7 +84,7 @@ describe Admin::Settings::WorkingDaysSettingsController docontext 'when fails with a duplicate entry' dolet(:nwd_to_delete) { create(:non_working_day, name: 'NWD to delete') }- let(:non_working_days) do+ let(:non_working_days_attributes) do{'0' => { 'name' => 'Christmas Eve', 'date' => '2022-12-24' },'1' => { 'name' => 'Christmas Eve2', 'date' => '2022-12-24' },@@ -102,9 +102,9 @@ describe Admin::Settings::WorkingDaysSettingsController doit 'sets the @modified_non_working_days variable' dosubjectexpect(assigns(:modified_non_working_days)).to contain_exactly(- have_attributes(name: 'Christmas Eve', date: Date.parse('2022-12-24')),- have_attributes(name: 'Christmas Eve2', date: Date.parse('2022-12-24')),- have_attributes(nwd_to_delete.slice(:id, :name, :date))+ hash_including('name' => 'Christmas Eve', 'date' => '2022-12-24'),+ hash_including('name' => 'Christmas Eve2', 'date' => '2022-12-24'),+ hash_including(nwd_to_delete.as_json(only: %i[id name date]).merge('_destroy' => true)))enddiff --git a/spec/features/admin/working_days_spec.rb b/spec/features/admin/working_days_spec.rbindex 8b932f1c172..eddb8fbf898 100644--- a/spec/features/admin/working_days_spec.rb+++ b/spec/features/admin/working_days_spec.rb@@ -32,7 +32,15 @@ describe 'Working Days', js: true docreate_shared_association_defaults_for_work_package_factoryshared_let(:week_days) { week_with_saturday_and_sunday_as_weekend }- shared_let(:admin) { create :admin }+ shared_let(:admin) { create(:admin) }+ shared_let(:non_working_days) do+ [+ create(:non_working_day),+ create(:non_working_day),+ create(:non_working_day)+ ]+ end+let_schedule(<<~CHART)days | MTWTFSSmtwtfss |earliest_work_package | XXXXX |@@ -41,6 +49,7 @@ describe 'Working Days', js: true doCHARTlet(:dialog) { Components::ConfirmationDialog.new }+ let(:datepicker) { Components::Datepicker.new }current_user { admin }@@ -48,128 +57,242 @@ describe 'Working Days', js: true dovisit admin_settings_working_days_pathend- # Using this way instead of Setting.working_days as that is cached.- def working_days_setting- Setting.find_by(name: :working_days).value- end+ describe 'week days' do+ # Using this way instead of Setting.working_days as that is cached.+ def working_days_setting+ Setting.find_by(name: :working_days).value+ end- it 'contains all defined days from the settings' do- WeekDay.all.each do |day|- expect(page).to have_selector('label', text: day.name)- if day.working- expect(page).to have_checked_field day.name+ it 'contains all defined days from the settings' do+ WeekDay.all.each do |day|+ expect(page).to have_selector('label', text: day.name)+ if day.working+ expect(page).to have_checked_field day.name+ endendend- end- it 'rejects the updates when cancelling the dialog' do- expect(working_days_setting).to eq([1, 2, 3, 4, 5])+ it 'rejects the updates when cancelling the dialog' do+ expect(working_days_setting).to eq([1, 2, 3, 4, 5])++ uncheck 'Monday'+ uncheck 'Friday'- uncheck 'Monday'- uncheck 'Friday'+ click_on 'Save'++ perform_enqueued_jobs do+ dialog.cancel+ end- click_on 'Save'+ expect(page).not_to have_selector('.flash.notice')- perform_enqueued_jobs do- dialog.cancel+ expect(working_days_setting).to eq([1, 2, 3, 4, 5])++ expect_schedule(WorkPackage.all, <<~CHART)+ days | MTWTFSSmtwtfss |+ earliest_work_package | XXXXX |+ second_work_package | XX..XX |+ follower | XXX |+ CHARTend- expect(page).to have_no_selector('.flash.notice')+ it 'updates the values and saves the settings' do+ expect(working_days_setting).to eq([1, 2, 3, 4, 5])- expect(working_days_setting).to eq([1, 2, 3, 4, 5])+ uncheck 'Monday'+ uncheck 'Friday'- expect_schedule(WorkPackage.all, <<~CHART)- days | MTWTFSSmtwtfss |- earliest_work_package | XXXXX |- second_work_package | XX..XX |- follower | XXX |- CHART- end+ click_on 'Save'- it 'updates the values and saves the settings' do- expect(working_days_setting).to eq([1, 2, 3, 4, 5])+ perform_enqueued_jobs do+ dialog.confirm+ end- uncheck 'Monday'- uncheck 'Friday'+ expect(page).to have_selector('.flash.notice', text: 'Successful update.')+ expect(page).to have_unchecked_field 'Monday'+ expect(page).to have_unchecked_field 'Friday'+ expect(page).to have_unchecked_field 'Saturday'+ expect(page).to have_unchecked_field 'Sunday'+ expect(page).to have_checked_field 'Tuesday'+ expect(page).to have_checked_field 'Wednesday'+ expect(page).to have_checked_field 'Thursday'++ expect(working_days_setting).to eq([2, 3, 4])++ expect_schedule(WorkPackage.all, <<~CHART)+ days | MTWTFSSmtwtfssmtwt |+ earliest_work_package | XXX....XX |+ second_work_package | X....XXX |+ follower | XXX |+ CHART++ # The updated work packages will have a journal entry informing about the change+ wp_page = Pages::FullWorkPackage.new(earliest_work_package)+ wp_page.visit!++ wp_page.expect_comment(text: "Working days changed (Monday is now non-working, Friday is now non-working).")+ end- click_on 'Save'+ it 'shows error when non working days are all unset' do+ uncheck 'Monday'+ uncheck 'Tuesday'+ uncheck 'Wednesday'+ uncheck 'Thursday'+ uncheck 'Friday'- perform_enqueued_jobs do- dialog.confirm+ click_on 'Save'++ perform_enqueued_jobs do+ dialog.confirm+ end++ expect(page).to have_selector('.flash.error', text: 'At least one day of the week must be defined as a working day.')+ # Restore the checkboxes to their valid state+ expect(page).to have_checked_field 'Monday'+ expect(page).to have_checked_field 'Tuesday'+ expect(page).to have_checked_field 'Wednesday'+ expect(page).to have_checked_field 'Thursday'+ expect(page).to have_checked_field 'Friday'+ expect(page).to have_unchecked_field 'Saturday'+ expect(page).to have_unchecked_field 'Sunday'+ expect(working_days_setting).to eq([1, 2, 3, 4, 5])++ expect_schedule(WorkPackage.all, <<~CHART)+ days | MTWTFSSmtwtfss |+ earliest_work_package | XXXXX |+ second_work_package | XX..XX |+ follower | XXX |+ CHARTend- expect(page).to have_selector('.flash.notice', text: 'Successful update.')- expect(page).to have_unchecked_field 'Monday'- expect(page).to have_unchecked_field 'Friday'- expect(page).to have_unchecked_field 'Saturday'- expect(page).to have_unchecked_field 'Sunday'- expect(page).to have_checked_field 'Tuesday'- expect(page).to have_checked_field 'Wednesday'- expect(page).to have_checked_field 'Thursday'-- expect(working_days_setting).to eq([2, 3, 4])-- expect_schedule(WorkPackage.all, <<~CHART)- days | MTWTFSSmtwtfssmtwt |- earliest_work_package | XXX....XX |- second_work_package | X....XXX |- follower | XXX |- CHART-- # The updated work packages will have a journal entry informing about the change- wp_page = Pages::FullWorkPackage.new(earliest_work_package)- wp_page.visit!-- wp_page.expect_comment(text: "Working days changed (Monday is now non-working, Friday is now non-working).")+ it 'shows an error when a previous change to the working days configuration isn\'t processed yet' do+ # Have a job already scheduled+ # Attempting to set the job via simply using the UI would require to change the test setup of how+ # delayed jobs are handled.+ ActiveJob::QueueAdapters::DelayedJobAdapter+ .new+ .enqueue(WorkPackages::ApplyWorkingDaysChangeJob.new(user_id: 5))++ uncheck 'Tuesday'+ click_on 'Save'++ # Not executing the background jobs+ dialog.confirm++ expect(page).to have_selector('.flash.error',+ text: 'The previous changes to the working days configuration have not been applied yet.')+ endend- it 'shows error when non working days are all unset' do- uncheck 'Monday'- uncheck 'Tuesday'- uncheck 'Wednesday'- uncheck 'Thursday'- uncheck 'Friday'+ describe 'non-working days' do+ it 'can add non-working days' do+ click_on 'Add non-working day'++ # It can cancel and reopen+ page.within('[data-qa-selector="op-datepicker-modal"]') do+ click_on 'Cancel'+ end+ click_on 'Add non-working day'++ page.within('[data-qa-selector="op-datepicker-modal"]') do+ fill_in 'name', with: 'My holiday'+ end- click_on 'Save'+ date1 = Time.zone.today.next_week.next_occurring(:monday)+ datepicker.set_date date1- perform_enqueued_jobs do- dialog.confirm+ page.within('[data-qa-selector="op-datepicker-modal"]') do+ click_on 'Save'+ end++ expect(page).to have_selector('.fc-list-event-title', text: 'My holiday')++ # Add a second day+ click_on 'Add non-working day'++ page.within('[data-qa-selector="op-datepicker-modal"]') do+ fill_in 'name', with: 'Another important day'+ end++ date2 = Time.zone.today.next_week.next_occurring(:tuesday)+ datepicker.set_date date2++ page.within('[data-qa-selector="op-datepicker-modal"]') do+ click_on 'Save'+ end++ click_on 'Save'+ click_on 'Save and reschedule'++ expect(page).to have_selector('.flash.notice', text: 'Successful update.')++ nwd1 = NonWorkingDay.find_by(name: 'My holiday')+ expect(nwd1.date).to eq date1++ nwd2 = NonWorkingDay.find_by(name: 'Another important day')+ expect(nwd2.date).to eq date2++ # Check if date and name are entered then close the datepicker+ click_on 'Add non-working day'++ page.within('[data-qa-selector="op-datepicker-modal"]') do+ click_on 'Save'+ end+ expect(page).to have_selector('.flatpickr-calendar')+ datepicker.expect_visible++ page.within('[data-qa-selector="op-datepicker-modal"]') do+ fill_in 'name', with: 'Instance-wide NWD'+ end++ datepicker.set_date date2++ page.within('[data-qa-selector="op-datepicker-modal"]') do+ click_on 'Save'+ end+ expect(page).not_to have_selector('.flatpickr-calendar')++ expect(page).to have_selector('.op-toast', text: /A non-working day for this date exists already/)end- expect(page).to have_selector('.flash.error', text: 'At least one day of the week must be defined as a working day.')- # Restore the checkboxes to their valid state- expect(page).to have_checked_field 'Monday'- expect(page).to have_checked_field 'Tuesday'- expect(page).to have_checked_field 'Wednesday'- expect(page).to have_checked_field 'Thursday'- expect(page).to have_checked_field 'Friday'- expect(page).to have_unchecked_field 'Saturday'- expect(page).to have_unchecked_field 'Sunday'- expect(working_days_setting).to eq([1, 2, 3, 4, 5])-- expect_schedule(WorkPackage.all, <<~CHART)- days | MTWTFSSmtwtfss |- earliest_work_package | XXXXX |- second_work_package | XX..XX |- follower | XXX |- CHART- end+ it 'deletes a non-working day' do+ non_working_days.each do |nwd|+ expect(page).to have_selector('tr', text: nwd.date.strftime("%B %-d, %Y"))+ end++ delete_button = page.first('.op-non-working-days-list--delete-icon .icon-delete', visible: :all)+ delete_button.hover+ delete_button.click++ click_on 'Save'- it 'shows an error when a previous change to the working days configuration isn\'t processed yet' do- # Have a job already scheduled- # Attempting to set the job via simply using the UI would require to change the test setup of how- # delayed jobs are handled.- ActiveJob::QueueAdapters::DelayedJobAdapter- .new- .enqueue(WorkPackages::ApplyWorkingDaysChangeJob.new(user_id: 5))+ dialog.confirm++ # Remove the first date+ expect(page).not_to have_selector('tr', text: non_working_days.first.date.strftime("%B %-d, %Y"))+ expect(page).to have_selector('tr', text: non_working_days.last.date.strftime("%B %-d, %Y"))++ # Show an error when the changes cannot be saved and preserves the modifications upon submit+ errors = ActiveModel::Errors.new(NonWorkingDay.new)+ errors.add(:id, :invalid)++ # rubocop:disable RSpec/AnyInstance+ allow_any_instance_of(NonWorkingDay)+ .to receive(:errors)+ .and_return(errors)+ # rubocop:enable RSpec/AnyInstance- uncheck 'Tuesday'- click_on 'Save'+ delete_button = page.first('.op-non-working-days-list--delete-icon .icon-delete', visible: :all)+ delete_button.hover+ delete_button.click- # Not executing the background jobs- dialog.confirm+ click_on 'Save'- expect(page).to have_selector('.flash.error',- text: 'The previous changes to the working days configuration have not been applied yet.')+ dialog.confirm++ # Keep the second date hidden+ expect(page).not_to have_selector('tr', text: non_working_days.second.date.strftime("%B %-d, %Y"))+ expect(page).to have_selector('tr', text: non_working_days.last.date.strftime("%B %-d, %Y"))+ endendenddiff --git a/spec/services/settings/working_days_update_service_spec.rb b/spec/services/settings/working_days_update_service_spec.rbindex 3878e0ca666..51f14e0eea2 100644--- a/spec/services/settings/working_days_update_service_spec.rb+++ b/spec/services/settings/working_days_update_service_spec.rb@@ -174,6 +174,30 @@ describe Settings::WorkingDaysUpdateService do)endend++ context 'with duplicate params when deleting and re-creating non-working days' do+ let(:non_working_days_params) do+ [+ existing_nwd.slice(:id, :name, :date).merge('_destroy' => true),+ existing_nwd.slice(:name, :date),+ existing_nwd.slice(:name, :date)+ ]+ end++ include_examples 'unsuccessful working days settings call'++ it 'returns the unchanged results including the ones marked for destruction' do+ result = subject.result++ expect(result).to contain_exactly(+ have_attributes(existing_nwd.slice(:id, :name, :date)),+ have_attributes(existing_nwd.slice(:name, :date).merge(id: nil)),+ have_attributes(existing_nwd.slice(:name, :date).merge(id: nil))+ )++ expect(result.find { |r| r.id == existing_nwd.id }).to be_marked_for_destruction+ end+ endendendend