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 stories and argstable for basic datepickers (#12376)
Yulefe7aaa30e5a3
diff --git a/frontend/package-lock.json b/frontend/package-lock.jsonindex 8dedd022f39..e5f1897b8b3 100644--- a/frontend/package-lock.json+++ b/frontend/package-lock.json@@ -70,6 +70,7 @@"json5": "^2.2.2","lodash": "^4.17.19","mark.js": "^8.11.0",+ "mdx-embed": "^1.1.2","mime": "^2.5.2","moment": "^2.29.4","moment-timezone": "^0.5.35",@@ -31317,6 +31318,17 @@"integrity": "sha512-/sKlQJCBYVY9Ers9hqzKou4H6V5UWc/M59TH2dvkt+84itfnq7uFOMLpOiOS4ujvHP4etln18fmIxA5R5fll0g==","dev": true},+ "node_modules/mdx-embed": {+ "version": "1.1.2",+ "resolved": "https://registry.npmjs.org/mdx-embed/-/mdx-embed-1.1.2.tgz",+ "integrity": "sha512-AAronHC/sh4py+RhJOuX8+9+lyUbJsmCLquXNPCEHZ0llPWjMuwls77hII/lWI2kwBSPZPahrqti8kGTv1pi1w==",+ "peerDependencies": {+ "@mdx-js/mdx": "^1.6.16",+ "@mdx-js/react": "^1.6.16",+ "react": "^16.x || ^17.x || ^18.x",+ "react-dom": "^16.x || ^17.x || ^18.x"+ }+ },"node_modules/media-typer": {"version": "0.3.0","resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",@@ -66584,6 +66596,11 @@"integrity": "sha512-/sKlQJCBYVY9Ers9hqzKou4H6V5UWc/M59TH2dvkt+84itfnq7uFOMLpOiOS4ujvHP4etln18fmIxA5R5fll0g==","dev": true},+ "mdx-embed": {+ "version": "1.1.2",+ "resolved": "https://registry.npmjs.org/mdx-embed/-/mdx-embed-1.1.2.tgz",+ "integrity": "sha512-AAronHC/sh4py+RhJOuX8+9+lyUbJsmCLquXNPCEHZ0llPWjMuwls77hII/lWI2kwBSPZPahrqti8kGTv1pi1w=="+ },"media-typer": {"version": "0.3.0","resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",diff --git a/frontend/package.json b/frontend/package.jsonindex 08dc5806bc0..ab6c90f2495 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -143,6 +143,7 @@"json5": "^2.2.2","lodash": "^4.17.19","mark.js": "^8.11.0",+ "mdx-embed": "^1.1.2","mime": "^2.5.2","moment": "^2.29.4","moment-timezone": "^0.5.35",diff --git a/frontend/src/app/core/apiv3/endpoints/time-entries/apiv3-time-entries-paths.ts b/frontend/src/app/core/apiv3/endpoints/time-entries/apiv3-time-entries-paths.tsindex 850d449edd5..56acd5d7db5 100644--- a/frontend/src/app/core/apiv3/endpoints/time-entries/apiv3-time-entries-paths.ts+++ b/frontend/src/app/core/apiv3/endpoints/time-entries/apiv3-time-entries-paths.ts@@ -46,8 +46,10 @@ import { ApiV3GettableResource } from 'core-app/core/apiv3/paths/apiv3-resource'export class ApiV3TimeEntriesPathsextends ApiV3Collection<TimeEntryResource, ApiV3TimeEntryPaths>implements ApiV3ListResourceInterface<TimeEntryResource> {- constructor(protected apiRoot:ApiV3Service,- protected basePath:string) {+ constructor(+ protected apiRoot:ApiV3Service,+ protected basePath:string,+ ) {super(apiRoot, basePath, 'time_entries', ApiV3TimeEntryPaths);}diff --git a/frontend/src/app/shared/components/datepicker/basic-datepicker.module.ts b/frontend/src/app/shared/components/datepicker/basic-datepicker.module.tsnew file mode 100644index 00000000000..984f9505167--- /dev/null+++ b/frontend/src/app/shared/components/datepicker/basic-datepicker.module.ts@@ -0,0 +1,33 @@+import { NgModule } from '@angular/core';+import {+ FormsModule,+ ReactiveFormsModule,+} from '@angular/forms';+import { CommonModule } from '@angular/common';++import { I18nService } from 'core-app/core/i18n/i18n.service';+import { OpBasicRangeDatePickerComponent } from './basic-range-date-picker/basic-range-date-picker.component';+import { OpBasicSingleDatePickerComponent } from './basic-single-date-picker/basic-single-date-picker.component';++@NgModule({+ imports: [+ FormsModule,+ ReactiveFormsModule,+ CommonModule,+ ],++ providers: [+ I18nService,+ ],++ declarations: [+ OpBasicRangeDatePickerComponent,+ OpBasicSingleDatePickerComponent,+ ],++ exports: [+ OpBasicRangeDatePickerComponent,+ OpBasicSingleDatePickerComponent,+ ],+})+export class OpBasicDatePickerModule { }diff --git a/frontend/src/app/shared/components/datepicker/datepicker.module.ts b/frontend/src/app/shared/components/datepicker/datepicker.module.tsnew file mode 100644index 00000000000..bcbba9e0334--- /dev/null+++ b/frontend/src/app/shared/components/datepicker/datepicker.module.ts@@ -0,0 +1,52 @@+import { NgModule } from '@angular/core';+import { A11yModule } from '@angular/cdk/a11y';+import {+ FormsModule,+ ReactiveFormsModule,+} from '@angular/forms';+import { CommonModule } from '@angular/common';++import { I18nService } from 'core-app/core/i18n/i18n.service';+import { OpModalSingleDatePickerComponent } from './modal-single-date-picker/modal-single-date-picker.component';+import { OpWpMultiDateFormComponent } from './wp-multi-date-form/wp-multi-date-form.component';+import { OpWpSingleDateFormComponent } from './wp-single-date-form/wp-single-date-form.component';+import { OpDatePickerBannerComponent } from './banner/datepicker-banner.component';+import { OpDatePickerSchedulingToggleComponent } from './scheduling-mode/datepicker-scheduling-toggle.component';+import { OpDatePickerWorkingDaysToggleComponent } from './toggle/datepicker-working-days-toggle.component';+import { OpBasicDatePickerModule } from './basic-datepicker.module';+import { OpSpotModule } from 'core-app/spot/spot.module';+import { OpenprojectModalModule } from '../modal/modal.module';++@NgModule({+ imports: [+ FormsModule,+ ReactiveFormsModule,+ CommonModule,+ A11yModule,+ OpSpotModule,+ OpBasicDatePickerModule,+ OpenprojectModalModule,+ ],++ providers: [+ I18nService,+ ],++ declarations: [+ OpDatePickerBannerComponent,+ OpDatePickerSchedulingToggleComponent,+ OpDatePickerWorkingDaysToggleComponent,++ OpModalSingleDatePickerComponent,+ OpWpMultiDateFormComponent,+ OpWpSingleDateFormComponent,+ ],++ exports: [+ OpModalSingleDatePickerComponent,+ OpWpMultiDateFormComponent,+ OpWpSingleDateFormComponent,+ OpBasicDatePickerModule,+ ],+})+export class OpDatePickerModule { }diff --git a/frontend/src/app/shared/shared.module.ts b/frontend/src/app/shared/shared.module.tsindex 2c1b554262f..feefbcc955b 100644--- a/frontend/src/app/shared/shared.module.ts+++ b/frontend/src/app/shared/shared.module.ts@@ -69,15 +69,6 @@ import { CopyToClipboardDirective } from './components/copy-to-clipboard/copy-toimport { OpDateTimeComponent } from './components/date/op-date-time.component';import { ToastComponent } from './components/toaster/toast.component';-import { OpWpSingleDateFormComponent } from 'core-app/shared/components/datepicker/wp-single-date-form/wp-single-date-form.component';-import { OpModalSingleDatePickerComponent } from 'core-app/shared/components/datepicker/modal-single-date-picker/modal-single-date-picker.component';-import { OpBasicSingleDatePickerComponent } from 'core-app/shared/components/datepicker/basic-single-date-picker/basic-single-date-picker.component';-import { OpBasicRangeDatePickerComponent } from 'core-app/shared/components/datepicker/basic-range-date-picker/basic-range-date-picker.component';-import { OpWpMultiDateFormComponent } from 'core-app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component';-import { OpDatePickerBannerComponent } from 'core-app/shared/components/datepicker/banner/datepicker-banner.component';-import { OpDatePickerWorkingDaysToggleComponent } from 'core-app/shared/components/datepicker/toggle/datepicker-working-days-toggle.component';-import { OpDatePickerSchedulingToggleComponent } from 'core-app/shared/components/datepicker/scheduling-mode/datepicker-scheduling-toggle.component';-// Old datepickersimport { OpMultiDatePickerComponent } from 'core-app/shared/components/datepicker/multi-date-picker/multi-date-picker.component';@@ -101,8 +92,9 @@ import { OpLoadingProjectListComponent } from './components/searchable-project-limport { 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 { OpenprojectModalModule } from 'core-app/shared/components/modal/modal.module';import { FullCalendarModule } from '@fullcalendar/angular';+import { OpDatePickerModule } from 'core-app/shared/components/datepicker/datepicker.module';export function bootstrapModule(injector:Injector):void {// Ensure error reporter is run@@ -151,6 +143,7 @@ export function bootstrapModule(injector:Injector):void {IconModule,AttributeHelpTextModule,FullCalendarModule,+ OpDatePickerModule,],exports: [// Re-export all commonly used@@ -172,6 +165,8 @@ export function bootstrapModule(injector:Injector):void {OpSpotModule,+ OpDatePickerModule,+FocusModule,OpDateTimeComponent,@@ -212,16 +207,6 @@ export function bootstrapModule(injector:Injector):void {ViewSelectComponent,- // Date pickers- OpWpSingleDateFormComponent,- OpModalSingleDatePickerComponent,- OpBasicSingleDatePickerComponent,- OpBasicRangeDatePickerComponent,- OpDatePickerBannerComponent,- OpWpMultiDateFormComponent,- OpDatePickerWorkingDaysToggleComponent,- OpDatePickerSchedulingToggleComponent,-// Old datepickersOpMultiDatePickerComponent,@@ -283,16 +268,6 @@ export function bootstrapModule(injector:Injector):void {OpNonWorkingDaysListComponent,- // Date pickers- OpWpSingleDateFormComponent,- OpModalSingleDatePickerComponent,- OpBasicSingleDatePickerComponent,- OpBasicRangeDatePickerComponent,- OpDatePickerBannerComponent,- OpWpMultiDateFormComponent,- OpDatePickerWorkingDaysToggleComponent,- OpDatePickerSchedulingToggleComponent,-// Old datepickersOpMultiDatePickerComponent,],diff --git a/frontend/src/stories/DatePickerBasic.example.html b/frontend/src/stories/DatePickerBasic.example.htmlnew file mode 100644index 00000000000..0b043547703--- /dev/null+++ b/frontend/src/stories/DatePickerBasic.example.html@@ -0,0 +1 @@+<op-basic-single-date-picker></op-basic-single-date-picker>diff --git a/frontend/src/stories/DatePickerBasic.example.ts b/frontend/src/stories/DatePickerBasic.example.tsnew file mode 100644index 00000000000..1180f7ea13a--- /dev/null+++ b/frontend/src/stories/DatePickerBasic.example.ts@@ -0,0 +1,7 @@+import { ChangeDetectionStrategy, Component } from '@angular/core';++@Component({+ templateUrl: './DatePickerBasic.example.html',+ changeDetection: ChangeDetectionStrategy.OnPush,+})+export class SbDatePickerBasicExample { }diff --git a/frontend/src/stories/DatePickerBasicPrefilled.example.html b/frontend/src/stories/DatePickerBasicPrefilled.example.htmlnew file mode 100644index 00000000000..1ccfb9fdbbe--- /dev/null+++ b/frontend/src/stories/DatePickerBasicPrefilled.example.html@@ -0,0 +1,3 @@+<op-basic-single-date-picker+ [value]="date"+></op-basic-single-date-picker>diff --git a/frontend/src/stories/DatePickerBasicPrefilled.example.ts b/frontend/src/stories/DatePickerBasicPrefilled.example.tsnew file mode 100644index 00000000000..d27bfef33c2--- /dev/null+++ b/frontend/src/stories/DatePickerBasicPrefilled.example.ts@@ -0,0 +1,10 @@+import * as moment from 'moment';+import { ChangeDetectionStrategy, Component } from '@angular/core';++@Component({+ templateUrl: './DatePickerBasicPrefilled.example.html',+ changeDetection: ChangeDetectionStrategy.OnPush,+})+export class SbDatePickerBasicPrefilledExample {+ date = moment(new Date()).format('YYYY-MM-DD');+}diff --git a/frontend/src/stories/DatePickerRangePrefilled.example.html b/frontend/src/stories/DatePickerRangePrefilled.example.htmlnew file mode 100644index 00000000000..5cfce760cdd--- /dev/null+++ b/frontend/src/stories/DatePickerRangePrefilled.example.html@@ -0,0 +1,3 @@+<op-basic-range-date-picker+ [value]="dates"+></op-basic-range-date-picker>diff --git a/frontend/src/stories/DatePickerRangePrefilled.example.ts b/frontend/src/stories/DatePickerRangePrefilled.example.tsnew file mode 100644index 00000000000..4102dc4d75a--- /dev/null+++ b/frontend/src/stories/DatePickerRangePrefilled.example.ts@@ -0,0 +1,13 @@+import * as moment from 'moment';+import { ChangeDetectionStrategy, Component } from '@angular/core';++@Component({+ templateUrl: './DatePickerRangePrefilled.example.html',+ changeDetection: ChangeDetectionStrategy.OnPush,+})+export class SbDatePickerRangePrefilledExample {+ dates = [+ moment(new Date()).format('YYYY-MM-DD'),+ moment(new Date()).add(4, 'days').format('YYYY-MM-DD'),+ ];+}diff --git a/frontend/src/stories/Datepicker-Basic.stories.mdx b/frontend/src/stories/Datepicker-Basic.stories.mdxindex 755bc54827a..3d195fe6186 100644--- a/frontend/src/stories/Datepicker-Basic.stories.mdx+++ b/frontend/src/stories/Datepicker-Basic.stories.mdx@@ -1,14 +1,80 @@-import { Meta, Story, Canvas } from '@storybook/addon-docs';--<Meta title="Patterns/Date Picker (2): Basic" />+import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs';+import { moduleMetadata } from '@storybook/angular';+import { Figma } from 'mdx-embed';++import { I18nService } from '../app/core/i18n/i18n.service';+import { I18nServiceStub } from './i18n.service.stub';++import { WeekdayService } from '../app/core/days/weekday.service';+import { WeekdayServiceStub } from './weekday.service.stub';++import { DayResourceService } from '../app/core/state/days/day.service';+import { DayResourceServiceStub } from './day.service.stub';++import { States } from '../app/core/states/states.service';+import { OpBasicDatePickerModule } from '../app/shared/components/datepicker/basic-datepicker.module';++import { OpBasicSingleDatePickerComponent } from '../app/shared/components/datepicker/basic-single-date-picker/basic-single-date-picker.component.ts'+import { OpBasicRangeDatePickerComponent } from '../app/shared/components/datepicker/basic-range-date-picker/basic-range-date-picker.component.ts'++import { SbDatePickerBasicExample } from './DatePickerBasic.example';+import { SbDatePickerBasicPrefilledExample } from './DatePickerBasicPrefilled.example';+import { SbDatePickerRangePrefilledExample } from './DatePickerRangePrefilled.example';++<Meta+ title="Patterns/Date Picker"+ decorators={[+ moduleMetadata({+ providers: [+ { provide: States, useValue: new States() },+ {+ provide: I18nService,+ useFactory: () => I18nServiceStub,+ },+ {+ provide: WeekdayService,+ useFactory: () => new WeekdayServiceStub(),+ },+ {+ provide: DayResourceService,+ useFactory: () => new DayResourceServiceStub(),+ },+ ],+ imports: [+ OpBasicDatePickerModule,+ ],+ }),+ ]}+/># Basic Date Picker+The basic date picker is a key element in OpenProject and is displayed any time the user has to input a date.+Basic date pickers are attached to existing date input fields and is displayed as a drop-down when that date input field is in focus. It consists of only the mini-calendar component.-Unlike the Work package and Modal variants, the basic date picker does not trap focus and as such does not allow for any keyboard navigation.+The basic date picker can also be placed inside modals like the work package date drop modal and the Baseline drop modal.++The most common places where users will interact with a date picker are:++- Work packages (start and finish dates, milestone date)+- Custom fields (of type date)+- Log time and costs+- Admin settings (specifying individual non-working days)+- Filters+- Baseline++<Canvas>+ <Story name="Single">+ {{ component: SbDatePickerBasicExample }}+ </Story>+</Canvas>-> **Example**: An example of a basic date picker (with input field)+## External dependencies++All date picker are built on the [Flatpickr javascript library](https://flatpickr.js.org/). The library gives us certain functionality out of the box with a fairly high degree of customisation, but also introduces limits (which will be mentioned below when relevant).++Please read the [Flatpickr documentation](https://flatpickr.js.org/instance-methods-properties-elements/) before using or contributing to date pickers.## Sub-variants@@ -18,34 +84,143 @@ The structure is very basic and consists only of one mini calendar. There are tw**Single** allows picking just one date (2023-02-09)-> **Example**: An example of a basic range date picker (with date pre-filled in the attached date input field)+<Canvas>+ <Story name="Single with prefilled value">+ {{ component: SbDatePickerBasicPrefilledExample }}+ </Story>+</Canvas>### Range**Range:** allows inputing a range (2023-02-09 - 2023-02-14), and shows the date picker with two months.-> **Example**: An example of a basic range date picker (with date pre-filled in the attached date input field).+<Canvas>+ <Story name="Range with prefilled value">+ {{ component: SbDatePickerRangePrefilledExample }}+ </Story>+</Canvas>-## Mobile+## Building Blocks-The basic date picker does not have a mobile version. On mobile devices, Flatpickr will automatically gracefully degrade to the device's native date picker.+All date pickers are built out of a common set of components. The basic building blocks specific to date pickers are:-## Margins and spacing+- Month-year selector+- Days of the week+- Mini day+- Mini calendar (made of Mini days)-1 rem between horizontal groupsets+Apart from the banner, all other building blocks are provided by Flatpickr and only styled in OpenProject. The following section will only describe how they are styled.+### Month-year selector-## Accessibility+**Month-year** selectors allow the user to move forward/backwards in one-month increments.++<Figma+ title="Month-year selector"+ url="file/XhCsrvs6rePifqbBpKYRWD/Components-Library?node-id=3655%3A17592&t=eNjGyvY1pXJeQFHr-1"+/>+++We use the basic structure provided by Flatpickr:++- previous button: *Grey 1* text, *Primary* on hover,+- month indicator: Body/Small Regular; *Grey 1* text+ - this becomes drop down selector when clicked+- year: Body/Small Regular; *Grey 1* text+ - this becomes a text box when clicked+- next button: *Grey 1* text, *Primary* on hover++There are two sub-variants:++1. arrows on both sides (for single date pickers)+2. without the right arrow: used on the left side of a two-month range calendar+3. without the left arrow: used on the right side of a two month range calendar++### Days of the week++Days of the week are headers for the mini calendar and list the days of the week in three-letter acronyms (Mon, Tue, Wed, Thu, Fri, Sat, Sun).++They are set in Caption/Bold; *Grey 1* text.++<Figma+ title="Days of the Week"+ url="file/XhCsrvs6rePifqbBpKYRWD/Components-Library?node-id=3655%3A17479&t=eNjGyvY1pXJeQFHr-1"+/>-The date picker itself never receives focus (and thus does not afford keyboard navigation or screen reader compatibility; see [Date Picker: Common elements](#) for accessibility shortcomings of of Flatpickr). However, the date input field that the date picker is attached to can receive focus, and all users can type in the desired date in the ISO format.+### Mini day-_To be completed_+The mini day displays individual dates on the mini-calendar, and has a number of different states. Each of these states can be *enabled* (it is active and clickable) or *disabled* (it is inactive and not clickable).++<Figma+ title="Days of the Week"+ url="file/XhCsrvs6rePifqbBpKYRWD/Components-Library?node-id=3655%3A17535&t=eNjGyvY1pXJeQFHr-1"+/>++Mini days are set in Caption/Regular.++- **Regular** days are the default state and cover the vast majority of cases.+ - Enabled: *Grey 1* text on *White* background.+ - On Hover: add stroke, 1px, Grey 3 (not-rounded)+ - Disabled: *Grey 3* text on *White* background.+ - Used when certain dates that are restricted by relations.+- **A non-working day** can be a weekend or one that's individually-defined in the admin settings:+ - Enabled: *Grey 1* text on *Grey 6* background+ - Used when the "Working days only" switch is OFF.+ - On Hover: add stroke, 1px, Grey 3 (not-rounded)+ - Disabled: *Grey 3* text on *Grey 6* background.+ - Default state, when the "Working days only" switch is ON.+- **Selected-start, select-end or selected-single** indicate the start and finish dates of a range, or the selected date for a single date.+ - They have 5-pixel rounding on the left for start, right for end and and on all corners for single dates.+ - Enabled: *White* text on *Main/Primary* background+ - Disabled: *Grey 3* text on *Grey 5* background+ - Used when the date is already set and not user-modifiable (eg. automatically scheduled).+- **Selected-mid** indicates working days that are included in a date range:+ - Enabled: *Main/Primary* text on *Main/Light* background+ - Disabled: *Grey 3* text on *Grey 5* background+ - used when the range is already set and not user-modifiable (eg. on a parent work package that is automatically scheduled and the dates are set by its children).+- **Selected-mid-non-spanned** indicates non-working days that are spanned (but not counted) in a date range:+ - Enabled state does not exist (since if a date is selected, it cannot be disabled).+ - Disabled: Main/Primary text on *Grey 6* background+ - Used when the selected range spans non-working days that are not included (Working days only switch is ON).+- **Today** indicates today's date.+ - Enabled: *Grey 1* text on *Indication*/*Current* background.+ - On Hover: add stroke, 1px, Grey 3 (not-rounded)+ - Disabled: *Grey 3* text on *Indication*/*Current* background.+ - Used when today falls on a non-working day and "Working days only" switch is ON.++### Mini calendar++The mini calendar consists of three elements:++- a month-year selector+- a days of the week line+- a 7×5 grid of mini days++<Figma+ title="Mini calendar"+ url="file/XhCsrvs6rePifqbBpKYRWD/Components-Library?node-id=3655%3A17552&t=eNjGyvY1pXJeQFHr-1"+/>++For certain months, there might be an additional (6) or one fewer (5) row, depending on the number of days in that month and the starting day.++For example, a February starting on a Monday will only have lines, and a November starting on a Saturday will have six.+++## Mobile++The basic date picker does not have a mobile version. On mobile devices, Flatpickr will automatically gracefully degrade to the device's native date picker.++For more complex implementations involving date pickers (the work package date field or the baseline modal), please refer to documentation concerning those specific features for notes on mobile-specific rendering.++## Accessibility++The basic date picker itself never receives focus (and thus does not afford keyboard navigation or screen reader compatibility). However, the date input field that the date picker is attached to can receive focus and all users can type in the desired date in the ISO format.## Usage-This date picker is used in:+The basic date picker is used in:-**Single:**+### Single date picker- Log time- Log unit costs@@ -60,6 +235,10 @@ This date picker is used in:- Budget forms- Dynamic forms-**Range:**+<ArgsTable of={OpBasicSingleDatePickerComponent} />++### Range date picker- Pause date reminders++<ArgsTable of={OpBasicRangeDatePickerComponent} />diff --git a/frontend/src/stories/Datepicker-Common.stories.mdx b/frontend/src/stories/Datepicker-Common.stories.mdxdeleted file mode 100644index c283e92f612..00000000000--- a/frontend/src/stories/Datepicker-Common.stories.mdx+++ /dev/null@@ -1,286 +0,0 @@-import { Meta, Story, Canvas } from '@storybook/addon-docs';--<Meta title="Patterns/Date Picker (1): Common elements" />--# Date picker: Common elements--The date picker is a key element in OpenProject and is displayed any time the user has to input a date.--> **Example**: a basic work package date picker (no banners)--The most common places where users will interact with a date picker are:--- Work packages (start and finish dates, milestone date)-- Custom fields (of type date)-- Log time and costs-- Admin settings (specifying individual non-working days)-- Filters--## Types--OpenProject offers three different types of date pickers, depending on where and how they are called.--**Work package date pickers** are drop modals only used for the main *date* field of work packages (but not for custom date fields):--> **Example**: a basic work package date picker (with banners, working days only ON)--**Modal date pickers** are also drop modals but are only used outside the main work package date field and where a basic date picker does not provide enough options.--> **Example**: a modal work package date picker (add non-working day)--**Basic date pickers** are barebones dropdown date pickers that only consist of a mini-calendar (and no additional options or fields) and are attached to date input fields on focus:--> **Example**: a basic date picker (filters)--## External dependencies--All date picker are built on the [Flatpickr javascript library](https://flatpickr.js.org/). The library gives us certain functionality out of the box with a fairly high degree of customisation, but also introduces limits (which will be mentioned below when relevant).--Please read the [Flatpickr documentation](https://flatpickr.js.org/instance-methods-properties-elements/) before using or contributing to date pickers.--## Building blocks--All date pickers are built out of a common set of components. The basic building blocks specific to date pickers are:--- Month-year selector-- Days of the week-- Mini day-- Mini calendar (made of Mini days)-- Banner--Apart from the banner, all other building blocks are provided by Flatpickr and only styled in OpenProject; the design system will only describe how they are styled.--Date pickers also use these other components from our design system: Selector field (switch), Form field, Action bar.--### Month-year selector--**Month-year** selectors allow the user to move forward/backwards in one-month increments.--> **Example**: Month-year selector--We use the basic structure provided by Flatpickr:--- previous button: *Grey 1* text, *Primary* on hover,-- month indicator: Body/Small Regular; *Grey 1* text- - this becomes drop down selector when clicked-- year: Body/Small Regular; *Grey 1* text- - this becomes a text box when clicked-- next button: *Grey 1* text, *Primary* on hover--There are two sub-variants:--1. arrows on both sides (for single date pickers)-2. without the right arrow: used on the left side of a two-month range calendar-3. without the left arrow: used on the right side of a two month range calendar--### Days of the week--Days of the week are headers for the mini calendar and list the days of the week in three-letter acronyms (Mon, Tue, Wed, Thu, Fri, Sat, Sun).--They are set in Caption/Bold; *Grey 1* text.--> **Example**: Days of the week--### Mini day--The mini day displays individual dates on the mini-calendar, and has a number of different states. Each of these states can be *enabled* (it is active and clickable) or *disabled* (it is inactive and not clickable).--> **Example**: The different states of the mini calendar, labeled.->-> Top row: enabled, bottom row: disabled.--Mini days are set in Caption/Regular.--- **Regular** days are the default state and cover the vast majority of cases.- - Enabled: *Grey 1* text on *White* background.- - On Hover: add stroke, 1px, Grey 3 (not-rounded)- - Disabled: *Grey 3* text on *White* background.- - Used when certain dates that are restricted by relations.-- **A non-working day** can be a weekend or one that's individually-defined in the admin settings:- - Enabled: *Grey 1* text on *Grey 6* background- - Used when the "Working days only" switch is OFF.- - On Hover: add stroke, 1px, Grey 3 (not-rounded)- - Disabled: *Grey 3* text on *Grey 6* background.- - Default state, when the "Working days only" switch is ON.-- **Selected-start, select-end or selected-single** indicate the start and finish dates of a range, or the selected date for a single date.- - They have 5-pixel rounding on the left for start, right for end and and on all corners for single dates.- - Enabled: *White* text on *Main/Primary* background- - Disabled: *Grey 3* text on *Grey 5* background- - Used when the date is already set and not user-modifiable (eg. automatically scheduled).-- **Selected-mid** indicates working days that are included in a date range:- - Enabled: *Main/Primary* text on *Main/Light* background- - Disabled: *Grey 3* text on *Grey 5* background- - used when the range is already set and not user-modifiable (eg. on a parent work package that is automatically scheduled and the dates are set by its children).-- **Selected-mid-non-spanned** indicates non-working days that are spanned (but not counted) in a date range:- - Enabled state does not exist (since if a date is selected, it cannot be disabled).- - Disabled: Main/Primary text on *Grey 6* background- - Used when the selected range spans non-working days that are not included (Working days only switch is ON).-- **Today** indicates today's date.- - Enabled: *Grey 1* text on *Indication*/*Current* background.- - On Hover: add stroke, 1px, Grey 3 (not-rounded)- - Disabled: *Grey 3* text on *Indication*/*Current* background.- - Used when today falls on a non-working day and "Working days only" switch is ON.--## Mini calendar--The mini calendar consists of three elements:--- a month-year selector-- a days of the week line-- a 7×5 grid of mini days--> **Example**: Mini calendar showing:->-> - Today-> - Weekends-> - Individual non-working days-> - Selected range (spanning non-working days)-> - Disabled date range (limited by relations)--For certain months, there might be an additional (6) or one fewer (5) row, depending on the number of days in that month and the starting day.--For example, a February starting on a Monday will only have lines, and a November starting on a Saturday will have six.--**Note:** Work package range date picker, two mini calendars display two mini calendars side by side; the month-year select of the left one has only a left arrow and the right one has only a right arrow.--## Banner--Work packages often have relations to other work package that can limit how the current work package can be scheduled. Banners in the date picker provide helpful contextual information that allows users to either make more informed decisions and understand limitations and potential consequences to changes they might make.--> **Example**: Desktop and mobile banners for the blue info "Available start date and finish dates are limited by relations" banner.--Banners can either be **information banners** that have a blue background (*Feedback/Info/Light*) and give user information about why certain options might not be available, or they can be **warning banners** that have an orange background (*Feedback/Warning/Light*) and warn users that their actions might have other consequences.--These colours are the same regardless of the theme.--Banners have 0.75 rem left/right padding, 0.5 rem top/bottom padding and 0.5 spacing between these three elements:--- an icon (*Info1*) on the left side, 24×24px-- text (set in *Basic/Grey 1*)- - The first line is set in *Caption/Bold*- - The second line is set in *Caption/Regular*-- a "Show relations" button that displays all directly related work packages in a custom GANTT view in a new tab--The mobile or single versions have these particularities:--- hides the icon-- retains only the first line of text, with a shorter text string (specified below)--There are four possible variants:--### Automatically scheduled (information)--This is an information banner that is displayed if the work package is that are automatically scheduled. As such, the user cannot input dates (unless they first switch "Manual scheduling" on). This is typically the case for parent work packages, whose dates are derived from those of the earliest and latest children.--> **Example**: Desktop and mobile banner: automatically scheduled.--Text:--> **Automatically scheduled. Dates are derived from relations.**-> Click on “Show relations” for GANTT overview.--Text (mobile or single versions):--> **Automatically scheduled. Dates derived.**--### Available dates limited by relations--This is an information banner that informs the user that certain dates may not be available for selection (visible on the Mini calendar below) due to existing relations. For example, a work package generally cannot start before the finish date of the preceding one.--> **Example**: Desktop and mobile banner: dates limited by relation.--Text:--> **Available start date and finish dates are limited by relations.**-> Click on “Show relations” for GANTT overview.--Text (mobile or single versions):--> **Available dates limited by relations.**--### Manual scheduling--This is a warning banner reminds the user that manual scheduling has been switched on for this work package, and that any existing relations will therefore for ignored for scheduling purposes. All constraints will be ignored, allowing the user to manually pick any date unconstrained by relations.--Note, however, that manual scheduling does not affect non-working days. If "Working days only" is switched on, non-working days remain unavailable.--> **Example**: Desktop and mobile banner: manual scheduling.--Text:--> **Manual scheduling enabled, all relations ignored.**-> Click on “Show relations” for GANTT overview.--Text (mobile or single versions):--> **Manual scheduling, relations ignored.**--### Dates will affect related work packages--This is a warning banner that informs users that changing the dates of the current work package will affect dates of other related work packages. It might for example push the following work package into the future.--> **Example**: Desktop and mobile banner: date will affect related WPs.--Text:--> **Changing these dates will affect dates of related work packages.**-> Click on “Show relations” for GANTT overview.--Text (mobile or single versions):--> **Changes will affect related work packages**.--## Options bar--The options bar consists of one or both of these selector fields:--- Manual scheduling (switch, default: off)-- Working days only (switch, default: on)--> **Example**: Just the top of the date picker with both these options in their default state.--## Input fields--The input field group set applies only to Work package date pickers and can contain these form fields:--> **Example**: The top part of the date picker with start date, end date and duration.--### Start date--Used to input the start date in ISO format (yyyy-mm-dd). Consists of:--1. Label ("Start date", on top)-2. Date input field-3. Today link (that input's today's date)--### Finish date--Used to input the finish date in ISO format (yyyy-mm-dd). Consists of:--- Label ("Finish date", on top)-- Date input field-- Today link (that input's today's date)--### Duration--- Label ("Duration", on top)-- Duration input field that, on focus, turns into an integer field- - On blur, the word " days" is added at the end, with proper pluralisation--Optionally, for milestones, there is only a single date field:--### Date--Used to input the date for single date pickers in ISO format (yyyy-mm-dd). Consists of:--- Label ("Date", on top)-- Date input field-- Today link (that input's today's date)--## Date picker variants: structure and options--See sub-sections (todo: add internal Storybook links):--- Work package date picker-- Modal date picker-- Basic date pickerdiff --git a/frontend/src/stories/Datepicker-Modal.stories.mdx b/frontend/src/stories/Datepicker-Modal.stories.mdxdeleted file mode 100644index b951248ea5d..00000000000--- a/frontend/src/stories/Datepicker-Modal.stories.mdx+++ /dev/null@@ -1,58 +0,0 @@-import { Meta, Story, Canvas } from '@storybook/addon-docs';--<Meta title="Patterns/Date Picker (3): Modal" />--# Modal Date Picker--They currently only exist in one variant:--- *Single:* Currently used only when adding individual non-working days in the admin settings. The picker has an additional text field for the name of the non-working day.--> **Example**: Modal work package single date picker (Add non-working day)--It consists of:--- Options (optional)- - This can be any selector field or form field required by the modal-- Input field (single date field)-- One mini calendar-- Action bar--The modal date picker does not have a range variant.--## Mobile--> **Example**: Mobile version of modal date picker--The **mobile** version is exactly the same except:--- The date picker, like all modals, is displayed full screen with a translucent grey background.-- The action bar has only action (*Save*); the cancel button is hidden, and is replaced with a close floating close button *outside* at the bottom (centred), as is common to all modals in mobile---## Margins and spacing--1 rem between horizontal groupsets--## Accessibility--The date picker receives focus when it is launched and traps focus until the user either closes the modal (via Enter or Escape). These fields can receive keyboard focus:--- Options-- Input fields-- Action bar--The mini-calendar itself does not afford keyboard navigation (see see [Date Picker: Common elements](#) for accessibility shortcomings of of Flatpickr).--_To be completed_--## Usage--This date picker is used in:--- **Range:**-- - Work package date field (all types except Milestone)-- **Single:**-- - Milestone date fielddiff --git a/frontend/src/stories/Datepicker-WorkPackage.stories.mdx b/frontend/src/stories/Datepicker-WorkPackage.stories.mdxdeleted file mode 100644index ee954d03a27..00000000000--- a/frontend/src/stories/Datepicker-WorkPackage.stories.mdx+++ /dev/null@@ -1,74 +0,0 @@-import { Meta, Story, Canvas } from '@storybook/addon-docs';--<Meta title="Patterns/Date Picker (4): Work Package" />--# Work Package Date Picker--There are two sub-variants:--- *Range:* This is the most complex variety, with info banners, start and end dates, duration, option switches, and two mini calendars visible.-- *Single:* Only a single date field, option switches, single mini calendar. Used only for milestones.--## Sub-variants-### Range--**Range** consists of:--- Banner-- Options bar-- Input fields (start, finish and duration)-- Two mini calendars-- Action bar--> **Example**: Work package range date picker with default settings--### Single--**Single** consists of:--- Banner (single version)-- Options bar-- Input fields (single date field)-- One mini calendar-- Action bar--> **Example**: Work package single date picker with default settings--## Mobile--- The date picker, like all modals, is displayed full screen with a translucent grey background-- The mobile version of the banner is displayed for both *range* and *single* variants-- For range input fields, *Start date* and *Finish date* are in one line and the Duration is a line by itself underneath.-- The action bar has only action (*Save*); the cancel button is hidden, and is replaced with a close floating close button *outside* at the bottom (centred), as is common to all modals in mobile--### Mobile Range--> **Example**: Mobile version of the work package range date picker--### Mobile Single--> **Example**: Mobile version of the work package single date picker--## Accessibility--The date picker receives focus when it is launched and traps focus until the user either closes the modal (via Enter or Escape). These fields can receive keyboard focus:--- Banner (with the 'Show relations' button)-- Options-- Input fields-- Action bar--The mini-calendar itself does not afford keyboard navigation (see see [Date Picker: Common elements](#) for accessibility shortcomings of of Flatpickr).--_To be completed_---## Margins and spacing--1 rem between horizontal groupsets--## Usage--This date picker is used in:--- Add non-working days *(Administration > Non-working days)*diff --git a/frontend/src/stories/day.service.stub.ts b/frontend/src/stories/day.service.stub.tsnew file mode 100644index 00000000000..e6b2c97ed10--- /dev/null+++ b/frontend/src/stories/day.service.stub.ts@@ -0,0 +1,49 @@+import { Injectable } from '@angular/core';+import { Observable, of } from 'rxjs';+import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';+import {+ ApiV3ListParameters,+} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';+import { DayStore } from 'core-app/core/state/days/day.store';+import { IDay } from 'core-app/core/state/days/day.model';+import {+ ResourceStore,+ ResourceStoreService,+} from 'core-app/core/state/resource-store.service';++@Injectable()+export class DayResourceServiceStub extends ResourceStoreService<IDay> {+ protected basePath():string {+ return '';+ }++ async isNonWorkingDay$(input:Date):Promise<boolean> {+ const day = input.getDay();+ return day > 5 || day === 0;+ }++ requireNonWorkingYear$(_date:Date|string):Observable<IDay[]> {+ return of([]);+ }++ requireNonWorkingYears$(_start:Date|string, _end:Date|string):Observable<IDay[]> {+ return of([]);+ }++ fetchCollection(_params:ApiV3ListParameters):Observable<IHALCollection<IDay>> {+ return of({+ _type: 'Collection',+ count: 0,+ pageSize: 10,+ offset: 0,+ total: 0,+ _embedded: {+ elements: [],+ },+ });+ }++ protected createStore():ResourceStore<IDay> {+ return new DayStore();+ }+}diff --git a/frontend/src/stories/i18n.service.stub.ts b/frontend/src/stories/i18n.service.stub.tsnew file mode 100644index 00000000000..febd8fcbe5f--- /dev/null+++ b/frontend/src/stories/i18n.service.stub.ts@@ -0,0 +1,52 @@+export const I18nServiceStub = {+ t<T=string>(name:string):any {+ return {+ 'date.abbr_day_names': [+ 'Mon',+ 'Tue',+ 'Wed',+ 'Thu',+ 'Fri',+ 'Sat',+ 'Sun',+ ],+ 'date.day_names': [+ 'Monday',+ 'Tuesday',+ 'Wednesday',+ 'Thursday',+ 'Friday',+ 'Saturday',+ 'Sunday',+ ],+ 'date.abbr_month_names': [+ 'Jan',+ 'Feb',+ 'Mar',+ 'Apr',+ 'May',+ 'Jun',+ 'Jul',+ 'Aug',+ 'Sep',+ 'Oct',+ 'Nov',+ 'Dec',+ ],+ 'date.month_names': [+ 'January',+ 'February',+ 'March',+ 'April',+ 'May',+ 'June',+ 'July',+ 'August',+ 'September',+ 'October',+ 'November',+ 'December',+ ],+ }[name] || name as T;+ },+};diff --git a/frontend/src/stories/weekday.service.stub.ts b/frontend/src/stories/weekday.service.stub.tsnew file mode 100644index 00000000000..f7662710391--- /dev/null+++ b/frontend/src/stories/weekday.service.stub.ts@@ -0,0 +1,59 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2023 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.+//++++import {+ Injectable,+} from '@angular/core';+import * as moment from 'moment';+import { IWeekday } from 'core-app/core/state/days/weekday.model';+import {+ Observable,+ of,+} from 'rxjs';++@Injectable({ providedIn: 'root' })+export class WeekdayServiceStub {+ private weekdays:IWeekday[] = [];++ /**+ * @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);+ }++ public get nonWorkingDays():IWeekday[] {+ return this.weekdays.filter((day) => !day.working);+ }++ loadWeekdays():Observable<IWeekday[]> {+ return of(this.weekdays);+ }+}