Skip to content

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

Implement days and weekdays stores

Oliver Günther0c0c6d1c18a9
diff --git a/frontend/src/app/core/apiv3/api-v3.service.ts b/frontend/src/app/core/apiv3/api-v3.service.ts
index ac6c5ac04e7..d0fc48cb443 100644
--- a/frontend/src/app/core/apiv3/api-v3.service.ts
+++ b/frontend/src/app/core/apiv3/api-v3.service.ts
@@ -61,6 +61,7 @@ import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { ApiV3NotificationsPaths } from 'core-app/core/apiv3/endpoints/notifications/apiv3-notifications-paths';
import { ApiV3ViewsPaths } from 'core-app/core/apiv3/endpoints/views/apiv3-views-paths';
import { Apiv3BackupsPath } from 'core-app/core/apiv3/endpoints/backups/apiv3-backups-path';
+import { ApiV3DaysPaths } from 'core-app/core/apiv3/endpoints/days/api-v3-days-paths';
@Injectable({ providedIn: 'root' })
export class ApiV3Service {
@@ -73,6 +74,9 @@ export class ApiV3Service {
// /api/v3/configuration
public readonly configuration = this.apiV3CustomEndpoint(ApiV3ConfigurationPath);
+ // /api/v3/days
+ public readonly days = this.apiV3CustomEndpoint(ApiV3DaysPaths);
+
// /api/v3/documents
public readonly documents = this.apiV3CollectionEndpoint('documents');
diff --git a/frontend/src/app/core/apiv3/endpoints/days/api-v3-day-paths.ts b/frontend/src/app/core/apiv3/endpoints/days/api-v3-day-paths.ts
new file mode 100644
index 00000000000..d48683cccd1
--- /dev/null
+++ b/frontend/src/app/core/apiv3/endpoints/days/api-v3-day-paths.ts
@@ -0,0 +1,33 @@
+// -- 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.
+//++
+
+import { ApiV3GettableResource } from 'core-app/core/apiv3/paths/apiv3-resource';
+import { IDay } from 'core-app/core/state/days/day.model';
+
+export class ApiV3DayPaths extends ApiV3GettableResource<IDay> {
+}
diff --git a/frontend/src/app/core/apiv3/endpoints/days/api-v3-days-paths.ts b/frontend/src/app/core/apiv3/endpoints/days/api-v3-days-paths.ts
new file mode 100644
index 00000000000..a7a449ce297
--- /dev/null
+++ b/frontend/src/app/core/apiv3/endpoints/days/api-v3-days-paths.ts
@@ -0,0 +1,50 @@
+// -- 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.
+//++
+
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { ApiV3DayPaths } from 'core-app/core/apiv3/endpoints/days/api-v3-day-paths';
+import { IDay } from 'core-app/core/state/days/day.model';
+import {
+ ApiV3GettableResource,
+ ApiV3ResourceCollection,
+} from 'core-app/core/apiv3/paths/apiv3-resource';
+
+export class ApiV3DaysPaths extends ApiV3ResourceCollection<IDay, ApiV3DayPaths> {
+ // Base path
+ public readonly path:string;
+
+ constructor(readonly apiRoot:ApiV3Service,
+ protected basePath:string) {
+ super(apiRoot, basePath, 'days', ApiV3DayPaths);
+ }
+
+ // Static paths
+
+ // /api/v3/days/week
+ public readonly week = new ApiV3GettableResource(this.apiRoot, this.path, 'week', this);
+}
diff --git a/frontend/src/app/core/state/collection-store.ts b/frontend/src/app/core/state/collection-store.ts
index 5ef7242b5ed..928d686e814 100644
--- a/frontend/src/app/core/state/collection-store.ts
+++ b/frontend/src/app/core/state/collection-store.ts
@@ -9,6 +9,8 @@ import {
ApiV3ListParameters,
listParamsString,
} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
+import { IHalResourceLinks } from 'core-app/core/state/hal-resource';
+import idFromLink from 'core-app/features/hal/helpers/id-from-link';
export interface CollectionResponse {
ids:ID[];
@@ -97,3 +99,22 @@ export function collectionFrom<T>(elements:T[]):IHALCollection<T> {
},
};
}
+
+/**
+ * Takes a collection of elements that do not have an ID, and extract the ID from self link.
+ * @param collection a IHALCollection with elements that have a self link
+ * @returns the same collection with elements extended with an ID dervied from the self link.
+ */
+export function extendCollectionElementsWithId<T extends { _links:IHalResourceLinks }>(
+ collection:IHALCollection<T>,
+):IHALCollection<T&{ id:ID }> {
+ const elements = collection._embedded.elements.map((element) => ({ ...element, id: idFromLink(element._links.self.href) }));
+
+ return {
+ ...collection,
+ _embedded: {
+ ...collection._embedded,
+ elements,
+ },
+ };
+}
diff --git a/frontend/src/app/core/state/days/day.model.ts b/frontend/src/app/core/state/days/day.model.ts
new file mode 100644
index 00000000000..be6c6c6a8f7
--- /dev/null
+++ b/frontend/src/app/core/state/days/day.model.ts
@@ -0,0 +1,9 @@
+import { IHalResourceLinks } from 'core-app/core/state/hal-resource';
+
+export interface IDay {
+ id:string;
+ date:string;
+ name:string;
+ working:boolean;
+ _links:IHalResourceLinks;
+}
diff --git a/frontend/src/app/core/state/days/day.service.ts b/frontend/src/app/core/state/days/day.service.ts
new file mode 100644
index 00000000000..94ace0d01a6
--- /dev/null
+++ b/frontend/src/app/core/state/days/day.service.ts
@@ -0,0 +1,54 @@
+import { Injectable } from '@angular/core';
+import {
+ map,
+ tap,
+} from 'rxjs/operators';
+import { Observable } from 'rxjs';
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';
+import { HttpClient } from '@angular/common/http';
+import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
+import {
+ collectionKey,
+ extendCollectionElementsWithId,
+ insertCollectionIntoState,
+} from 'core-app/core/state/collection-store';
+import { DayStore } from 'core-app/core/state/days/day.store';
+import { IDay } from 'core-app/core/state/days/day.model';
+import {
+ CollectionStore,
+ ResourceCollectionService,
+} from 'core-app/core/state/resource-collection.service';
+
+@Injectable()
+export class DayResourceService extends ResourceCollectionService<IDay> {
+ private get daysPath():string {
+ return this
+ .apiV3Service
+ .days
+ .path;
+ }
+
+ constructor(
+ private http:HttpClient,
+ private apiV3Service:ApiV3Service,
+ ) {
+ super();
+ }
+
+ fetchDays(params:ApiV3ListParameters):Observable<IHALCollection<IDay>> {
+ const collectionURL = collectionKey(params);
+
+ return this
+ .http
+ .get<IHALCollection<IDay>>(this.daysPath + collectionURL)
+ .pipe(
+ map((collection) => extendCollectionElementsWithId(collection)),
+ tap((collection) => insertCollectionIntoState(this.store, collection, collectionURL)),
+ );
+ }
+
+ protected createStore():CollectionStore<IDay> {
+ return new DayStore();
+ }
+}
diff --git a/frontend/src/app/core/state/days/day.store.ts b/frontend/src/app/core/state/days/day.store.ts
new file mode 100644
index 00000000000..d4d8e25465e
--- /dev/null
+++ b/frontend/src/app/core/state/days/day.store.ts
@@ -0,0 +1,19 @@
+import {
+ EntityStore,
+ StoreConfig,
+} from '@datorama/akita';
+import {
+ CollectionState,
+ createInitialCollectionState,
+} from 'core-app/core/state/collection-store';
+import { IDay } from 'core-app/core/state/days/day.model';
+
+export interface DayState extends CollectionState<IDay> {
+}
+
+@StoreConfig({ name: 'days' })
+export class DayStore extends EntityStore<DayState> {
+ constructor() {
+ super(createInitialCollectionState());
+ }
+}
diff --git a/frontend/src/app/core/state/days/weekday.model.ts b/frontend/src/app/core/state/days/weekday.model.ts
new file mode 100644
index 00000000000..a4af121c1e3
--- /dev/null
+++ b/frontend/src/app/core/state/days/weekday.model.ts
@@ -0,0 +1,9 @@
+import { IHalResourceLinks } from 'core-app/core/state/hal-resource';
+
+export interface IWeekday {
+ id:string;
+ day:1|2|3|4|5|6|7;
+ name:string;
+ working:boolean;
+ _links:IHalResourceLinks;
+}
diff --git a/frontend/src/app/core/state/days/weekday.service.ts b/frontend/src/app/core/state/days/weekday.service.ts
new file mode 100644
index 00000000000..ad18dd29547
--- /dev/null
+++ b/frontend/src/app/core/state/days/weekday.service.ts
@@ -0,0 +1,77 @@
+import { Injectable } from '@angular/core';
+import {
+ map,
+ switchMap,
+ tap,
+} from 'rxjs/operators';
+import {
+ EMPTY,
+ Observable,
+} from 'rxjs';
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';
+import { HttpClient } from '@angular/common/http';
+import {
+ extendCollectionElementsWithId,
+ insertCollectionIntoState,
+} from 'core-app/core/state/collection-store';
+import { WeekdayStore } from 'core-app/core/state/days/weekday.store';
+import { IWeekday } from 'core-app/core/state/days/weekday.model';
+import {
+ CollectionStore,
+ ResourceCollectionService,
+} from 'core-app/core/state/resource-collection.service';
+
+@Injectable()
+export class WeekdayResourceService extends ResourceCollectionService<IWeekday> {
+ private get weekdaysPath():string {
+ return this
+ .apiV3Service
+ .days
+ .week
+ .path;
+ }
+
+ constructor(
+ private http:HttpClient,
+ private apiV3Service:ApiV3Service,
+ ) {
+ super();
+ }
+
+ require():Observable<IWeekday[]> {
+ return this
+ .query
+ .selectHasCache()
+ .pipe(
+ switchMap((hasCache) => (hasCache ? EMPTY : this.fetchWeekdays())),
+ switchMap(() => this.query.selectAll()),
+ );
+ }
+
+ require():Observable<IWeekday[]> {
+ return this
+ .query
+ .selectHasCache()
+ .pipe(
+ switchMap((hasCache) => (hasCache ? EMPTY : this.fetchWeekdays())),
+ switchMap(() => this.query.selectAll()),
+ );
+ }
+
+ private fetchWeekdays():Observable<IHALCollection<IWeekday>> {
+ const collectionURL = 'all'; // We load all weekdays
+
+ return this
+ .http
+ .get<IHALCollection<IWeekday>>(this.weekdaysPath)
+ .pipe(
+ map((collection) => extendCollectionElementsWithId(collection)),
+ tap((collection) => insertCollectionIntoState(this.store, collection, collectionURL)),
+ );
+ }
+
+ protected createStore():CollectionStore<IWeekday> {
+ return new WeekdayStore();
+ }
+}
diff --git a/frontend/src/app/core/state/days/weekday.store.ts b/frontend/src/app/core/state/days/weekday.store.ts
new file mode 100644
index 00000000000..5707af77b03
--- /dev/null
+++ b/frontend/src/app/core/state/days/weekday.store.ts
@@ -0,0 +1,19 @@
+import {
+ EntityStore,
+ StoreConfig,
+} from '@datorama/akita';
+import {
+ CollectionState,
+ createInitialCollectionState,
+} from 'core-app/core/state/collection-store';
+import { IWeekday } from 'core-app/core/state/days/weekday.model';
+
+export interface WeekdayState extends CollectionState<IWeekday> {
+}
+
+@StoreConfig({ name: 'weekdays' })
+export class WeekdayStore extends EntityStore<WeekdayState> {
+ constructor() {
+ super(createInitialCollectionState());
+ }
+}
diff --git a/frontend/src/app/core/state/openproject-state.module.ts b/frontend/src/app/core/state/openproject-state.module.ts
index 488f3259019..8ed43fa92de 100644
--- a/frontend/src/app/core/state/openproject-state.module.ts
+++ b/frontend/src/app/core/state/openproject-state.module.ts
@@ -32,6 +32,8 @@ import { InAppNotificationsResourceService } from './in-app-notifications/in-app
import { ProjectsResourceService } from './projects/projects.service';
import { PrincipalsResourceService } from './principals/principals.service';
import { CapabilitiesResourceService } from 'core-app/core/state/capabilities/capabilities.service';
+import { DayResourceService } from 'core-app/core/state/days/day.service';
+import { WeekdayResourceService } from 'core-app/core/state/days/weekday.service';
@NgModule({
providers: [
@@ -40,6 +42,8 @@ import { CapabilitiesResourceService } from 'core-app/core/state/capabilities/ca
ProjectsResourceService,
PrincipalsResourceService,
CapabilitiesResourceService,
+ DayResourceService,
+ WeekdayResourceService,
],
})
export class OpenProjectStateModule {}
diff --git a/frontend/src/app/shared/components/op-date-picker/datepicker.ts b/frontend/src/app/shared/components/op-date-picker/datepicker.ts
index ddd7e8e9b32..4442d22e614 100644
--- a/frontend/src/app/shared/components/op-date-picker/datepicker.ts
+++ b/frontend/src/app/shared/components/op-date-picker/datepicker.ts
@@ -32,6 +32,11 @@ import { Instance } from 'flatpickr/dist/types/instance';
import { ConfigurationService } from 'core-app/core/config/configuration.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { rangeSeparator } from 'core-app/shared/components/op-date-picker/op-range-date-picker/op-range-date-picker.component';
+import { WeekdayResourceService } from 'core-app/core/state/days/weekday.service';
+import { IWeekday } from 'core-app/core/state/days/weekday.model';
+import { Injector } from '@angular/core';
+import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
+import { take } from 'rxjs/operators';
import DateOption = flatpickr.Options.DateOption;
export class DatePicker {
@@ -41,7 +46,13 @@ export class DatePicker {
public datepickerInstance:Instance;
- private reshowTimeout:any;
+ private reshowTimeout:ReturnType<typeof setTimeout>;
+
+ private weekdays:IWeekday[] = [];
+
+ @InjectField() configurationService:ConfigurationService;
+
+ @InjectField() weekdaysService:WeekdayResourceService;
constructor(private datepickerElemIdentifier:string,
private date:Date|Date[]|string[]|string,