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
Introduce RecentItemsService.
Pavel Balashou8e919e7f1fae
diff --git a/frontend/src/app/core/global_search/input/global-search-input.component.ts b/frontend/src/app/core/global_search/input/global-search-input.component.tsindex 4715cfd02f4..42a4e07da0d 100644--- a/frontend/src/app/core/global_search/input/global-search-input.component.ts+++ b/frontend/src/app/core/global_search/input/global-search-input.component.ts@@ -55,6 +55,7 @@ import { HalResourceService } from 'core-app/features/hal/services/hal-resource.import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { ApiV3Service } from '../../apiv3/api-v3.service';import { ApiV3WorkPackageCachedSubresource } from 'core-app/core/apiv3/endpoints/work_packages/api-v3-work-package-cached-subresource';+import { RecentItemsService } from 'core-app/core/recent-items.service';export const globalSearchSelector = 'global-search-input';@@ -143,6 +144,7 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {readonly cdRef:ChangeDetectorRef,readonly halNotification:HalResourceNotificationService,readonly ngZone:NgZone,+ readonly recentItemsService:RecentItemsService,) {}@@ -291,8 +293,7 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {private autocompleteWorkPackages(query:string):Observable<(WorkPackageResource|SearchOptionItem)[]> {if (!query) {- // replace with recent work packages read from local storage- const wpIds = ['9', '12'];+ const wpIds = this.recentItemsService.getAll();void this.apiV3Service.work_packages.requireAll(wpIds);diff --git a/frontend/src/app/core/global_search/openproject-global-search.module.ts b/frontend/src/app/core/global_search/openproject-global-search.module.tsindex e0e4de453ac..5f4d534c6e4 100644--- a/frontend/src/app/core/global_search/openproject-global-search.module.ts+++ b/frontend/src/app/core/global_search/openproject-global-search.module.ts@@ -36,6 +36,7 @@ import { GlobalSearchService } from 'core-app/core/global_search/services/globalimport { GlobalSearchWorkPackagesEntryComponent } from 'core-app/core/global_search/global-search-work-packages-entry.component';import { OpenprojectAutocompleterModule } from 'core-app/shared/components/autocompleter/openproject-autocompleter.module';import { OpSharedModule } from 'core-app/shared/shared.module';+import { RecentItemsService } from 'core-app/core/recent-items.service';@NgModule({imports: [@@ -45,6 +46,7 @@ import { OpSharedModule } from 'core-app/shared/shared.module';],providers: [GlobalSearchService,+ RecentItemsService,],declarations: [GlobalSearchInputComponent,diff --git a/frontend/src/app/core/recent-items.service.ts b/frontend/src/app/core/recent-items.service.tsnew file mode 100644index 00000000000..9eff6fc322b--- /dev/null+++ b/frontend/src/app/core/recent-items.service.ts@@ -0,0 +1,47 @@+// -- 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';++@Injectable()+export class RecentItemsService {+ add(id: string): void {+ let wps = JSON+ .parse(window.OpenProject.guardedLocalStorage('recent') || '[]')+ .filter((entry : string) => entry !== id);+ wps.unshift(id);+ if (wps.length > 5) {+ wps = wps.slice(0, 5);+ }+ window.localStorage.setItem('recent', JSON.stringify(wps));+ }++ getAll(): string[] {+ return JSON.parse(window.OpenProject.guardedLocalStorage('recent') || '[]')+ }+}diff --git a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts b/frontend/src/app/features/work-packages/openproject-work-packages.module.tsindex 755ace5a33b..aec83fff083 100644--- a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts+++ b/frontend/src/app/features/work-packages/openproject-work-packages.module.ts@@ -186,6 +186,7 @@ import { OpBaselineComponent } from 'core-app/features/work-packages/components/import { OpBaselineLoadingComponent } from 'core-app/features/work-packages/components/wp-baseline/baseline-loading/baseline-loading.component';import { OpBaselineLegendsComponent } from 'core-app/features/work-packages/components/wp-baseline/baseline-legends/baseline-legends.component';import { NgSelectModule } from '@ng-select/ng-select';+import { RecentItemsService } from 'core-app/core/recent-items.service';@NgModule({imports: [@@ -246,6 +247,8 @@ import { NgSelectModule } from '@ng-select/ng-select';StoragesResourceService,ProjectStoragesResourceService,++ RecentItemsService,],declarations: [// Routingdiff --git a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.tsindex bf35cf2b47f..12663df7908 100644--- a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts+++ b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts@@ -42,6 +42,7 @@ import {} from 'core-app/features/work-packages/services/notifications/work-package-notification.service';import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';import { CommentService } from 'core-app/features/work-packages/components/wp-activity/comment-service';+import { RecentItemsService } from 'core-app/core/recent-items.service';@Component({templateUrl: './wp-full-view.html',@@ -73,6 +74,7 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase impconstructor(public injector:Injector,public wpTableSelection:WorkPackageViewSelectionService,+ public recentItemsService:RecentItemsService,readonly $state:StateService,// private readonly i18n:I18nService,) {@@ -86,9 +88,10 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase impprotected init() {super.init();+ this.recentItemsService.add(this.workPackage.id!);+// Set Focused WPthis.wpTableFocus.updateFocus(this.workPackage.id!);-this.setWorkPackageScopeProperties(this.workPackage);}diff --git a/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.ts b/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.tsindex b892b7d461d..82527605695 100644--- a/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.ts+++ b/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.ts@@ -44,6 +44,7 @@ import { WorkPackageNotificationService } from 'core-app/features/work-packages/import { BackRoutingService } from 'core-app/features/work-packages/components/back-routing/back-routing.service';import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';import { CommentService } from 'core-app/features/work-packages/components/wp-activity/comment-service';+import { RecentItemsService } from 'core-app/core/recent-items.service';@Component({templateUrl: './wp-split-view.html',@@ -66,6 +67,7 @@ export class WorkPackageSplitViewComponent extends WorkPackageSingleViewBase imppublic keepTab:KeepTabService,public wpTableSelection:WorkPackageViewSelectionService,public wpTableFocus:WorkPackageViewFocusService,+ public recentItemsService:RecentItemsService,readonly $state:StateService,readonly backRouting:BackRoutingService,) {@@ -104,6 +106,7 @@ export class WorkPackageSplitViewComponent extends WorkPackageSingleViewBase imp);}});+ this.recentItemsService.add(wpId);}get shouldFocus():boolean {