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

Start collapsible menu component creation

Benjamin Bädorf536e3e80682b
diff --git a/frontend/src/app/core/apiv3/types/hal-collection.type.ts b/frontend/src/app/core/apiv3/types/hal-collection.type.ts
index ac42d9488f9..d2c10246670 100644
--- a/frontend/src/app/core/apiv3/types/hal-collection.type.ts
+++ b/frontend/src/app/core/apiv3/types/hal-collection.type.ts
@@ -1,9 +1,20 @@
+export interface IHALGrouping {
+ value:string;
+ count:number;
+ _links:{
+ valueLink:{
+ href:string;
+ }[];
+ };
+}
+
export interface IHALCollection<T> {
_type:'Collection';
count:number;
total:number;
pageSize:number;
offset:number;
+ groups?:IHALGrouping[];
_embedded:{
elements:T[];
}
diff --git a/frontend/src/app/core/setup/global-dynamic-components.const.ts b/frontend/src/app/core/setup/global-dynamic-components.const.ts
index 9831a0cd50a..776a4ac1bcb 100644
--- a/frontend/src/app/core/setup/global-dynamic-components.const.ts
+++ b/frontend/src/app/core/setup/global-dynamic-components.const.ts
@@ -173,8 +173,8 @@ import {
opInAppNotificationBellSelector,
} from 'core-app/features/in-app-notifications/bell/in-app-notification-bell.component';
import {
- IANCenterMenuComponent,
- ianCenterMenuSelector,
+ IanMenuComponent,
+ ianMenuSelector,
} from 'core-app/features/in-app-notifications/center/menu/menu.component';
@@ -226,5 +226,5 @@ export const globalDynamicComponents:OptionalBootstrapDefinition[] = [
{ selector: slideToggleSelector, cls: SlideToggleComponent },
{ selector: backupSelector, cls: BackupComponent },
{ selector: opInAppNotificationBellSelector, cls: InAppNotificationBellComponent },
- { selector: ianCenterMenuSelector, cls: IANCenterMenuComponent },
+ { selector: ianMenuSelector, cls: IanMenuComponent },
];
diff --git a/frontend/src/app/features/in-app-notifications/center/menu/menu.component.html b/frontend/src/app/features/in-app-notifications/center/menu/menu.component.html
index 88a233c78f0..1c78522237b 100644
--- a/frontend/src/app/features/in-app-notifications/center/menu/menu.component.html
+++ b/frontend/src/app/features/in-app-notifications/center/menu/menu.component.html
@@ -1,4 +1,4 @@
-<ul class="main-menu--children">
+<ul>
<li class="main-item-wrapper">
<a
class="op-menu--item-action overview-menu-item"
@@ -24,26 +24,6 @@
</a>
</li>
<li>
- <div class="tree-menu--container">
- <ul class="pages-hierarchy -with-hierarchy collapsible-menu--container">
- <li class="-hierarchy-expanded">
- <div class="tree-menu--item">
- <span class="tree-menu--hierarchy-span">
- <button
- class="tree-menu--hierarchy-indicator collapsible-menu--category-toggle"
- type="button"
- >
- <span class="tree-menu--hierarchy-indicator-icon" aria-hidden="true"></span>
- </button>
- <span class="tree-menu--hierarchy-indicator-expanded hidden-for-sighted">Expanded. Click to collapse</span>
- <span class="tree-menu--hierarchy-indicator-collapsed hidden-for-sighted">Collapsed. Click to show</span>
- </span>
- <ul class="pages-hierarchy -with-hierarchy">
- <li class="collapsible-menu--placeholder">You have no </li>
- </ul>
- </div>
- </li>
- </ul>
- </div>
+ <op-collapsible-menu></op-collapsible-menu>
</li>
</ul>
diff --git a/frontend/src/app/features/in-app-notifications/center/menu/menu.component.ts b/frontend/src/app/features/in-app-notifications/center/menu/menu.component.ts
index 1468603d789..40d6ed74def 100644
--- a/frontend/src/app/features/in-app-notifications/center/menu/menu.component.ts
+++ b/frontend/src/app/features/in-app-notifications/center/menu/menu.component.ts
@@ -5,17 +5,18 @@ import {
OnInit,
} from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';
+import { IanMenuService } from './state/ian-menu.service';
-export const ianCenterMenuSelector = 'op-ian-menu';
+export const ianMenuSelector = 'op-ian-menu';
@Component({
- selector: ianCenterMenuSelector,
+ selector: ianMenuSelector,
templateUrl: './menu.component.html',
styleUrls: ['./menu.component.sass'],
+ providers: [ IanMenuService ],
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class IANCenterMenuComponent implements OnInit {
+export class IanMenuComponent implements OnInit {
text = {
title: this.I18n.t('js.notifications.title'),
button_close: this.I18n.t('js.button_close'),
@@ -28,16 +29,12 @@ export class IANCenterMenuComponent implements OnInit {
constructor(
readonly cdRef:ChangeDetectorRef,
readonly I18n:I18nService,
- readonly resourceService:InAppNotificationsResourceService,
+ readonly ianMenuService:IanMenuService,
) {
console.log('menu');
}
ngOnInit() {
- this.resourceService.fetchNotifications({
- pageSize: 0,
- groupBy: 'project',
- filters: [['unread', '=', true]],
- });
+ this.ianMenuService.reload();
}
}
diff --git a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.query.ts b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.query.ts
new file mode 100644
index 00000000000..921aabf0672
--- /dev/null
+++ b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.query.ts
@@ -0,0 +1,24 @@
+import { Query } from '@datorama/akita';
+import {
+ map,
+ switchMap,
+} from 'rxjs/operators';
+import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';
+import { InAppNotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';
+import { selectCollectionAsEntities$ } from 'core-app/core/state/collection-store';
+import {
+ IanMenuState,
+ IanMenuStore,
+} from './ian-menu.store';
+
+export class IanMenuQuery extends Query<IanMenuState> {
+ notificationsByProject$ = this.select('notificationsByProject');
+ notificationsByReason$ = this.select('notificationsByReason');
+
+ constructor(
+ protected store:IanMenuStore,
+ protected resourceService:InAppNotificationsResourceService,
+ ) {
+ super(store);
+ }
+}
diff --git a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.service.ts b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.service.ts
new file mode 100644
index 00000000000..4ff67c26574
--- /dev/null
+++ b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.service.ts
@@ -0,0 +1,63 @@
+import {
+ Injectable,
+ Injector,
+} from '@angular/core';
+import {
+ map,
+ take,
+} from 'rxjs/operators';
+import { from } from 'rxjs';
+import { ID } from '@datorama/akita';
+import {
+ markNotificationsAsRead,
+ notificationsMarkedRead,
+} from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';
+import { InAppNotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';
+import {
+ EffectCallback,
+ EffectHandler,
+} from 'core-app/core/state/effects/effect-handler.decorator';
+import { ActionsService } from 'core-app/core/state/actions/actions.service';
+import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';
+import { selectCollectionAsHrefs$ } from 'core-app/core/state/collection-store';
+import { IanMenuQuery } from './ian-menu.query';
+import {
+ IanMenuStore,
+ IAN_MENU_PROJECT_FILTERS,
+ IAN_MENU_REASON_FILTERS,
+} from './ian-menu.store';
+
+@Injectable()
+@EffectHandler
+export class IanMenuService {
+ readonly id = 'ian-center';
+
+ readonly store = new IanMenuStore();
+
+ readonly query = new IanMenuQuery(this.store, this.resourceService);
+
+ constructor(
+ readonly injector:Injector,
+ readonly resourceService:InAppNotificationsResourceService,
+ readonly actions$:ActionsService,
+ readonly apiV3Service:APIV3Service,
+ ) {
+ }
+
+ /**
+ * Reload after notifications were successfully marked as read
+ */
+ @EffectCallback(notificationsMarkedRead)
+ private reloadOnNotificationRead() {
+ return this.reload();
+ }
+
+ public reload() {
+ this.resourceService.fetchNotifications(IAN_MENU_PROJECT_FILTERS)
+ .subscribe((data) => this.store.update({ notificationsByProject: data.groups }));
+ this.resourceService.fetchNotifications(IAN_MENU_REASON_FILTERS)
+ .subscribe((data) => this.store.update({ notificationsByReason: data.groups }));
+ }
+}
diff --git a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.store.ts b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.store.ts
new file mode 100644
index 00000000000..044f172f553
--- /dev/null
+++ b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.store.ts
@@ -0,0 +1,44 @@
+import { Store, StoreConfig } from '@datorama/akita';
+import { Apiv3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
+import { NOTIFICATIONS_MAX_SIZE } from 'core-app/core/state/in-app-notifications/in-app-notification.model';
+
+export interface IanMenuGroupingData {
+ value:string;
+ count:number;
+ _links:{
+ valueLink:{
+ href:string;
+ }[];
+ };
+}
+
+export interface IanMenuState {
+ notificationsByProject:IanMenuGroupingData[],
+ notificationsByReason:IanMenuGroupingData[],
+}
+
+export const IAN_MENU_PROJECT_FILTERS:Apiv3ListParameters = {
+ pageSize: 100,
+ groupBy: 'project',
+ filters: [['read_ian', '=', false]],
+};
+
+export const IAN_MENU_REASON_FILTERS:Apiv3ListParameters = {
+ pageSize: 100,
+ groupBy: 'reason',
+ filters: [['read_ian', '=', false]],
+};
+
+export function createInitialState():IanMenuState {
+ return {
+ notificationsByProject: [],
+ notificationsByReason: [],
+ };
+}
+
+@StoreConfig({ name: 'ian-menu' })
+export class IanMenuStore extends Store<IanMenuState> {
+ constructor() {
+ super(createInitialState());
+ }
+}
diff --git a/frontend/src/app/shared/components/sidemenu/collapsible-menu.component.html b/frontend/src/app/shared/components/sidemenu/collapsible-menu.component.html
new file mode 100644
index 00000000000..be91dab2686
--- /dev/null
+++ b/frontend/src/app/shared/components/sidemenu/collapsible-menu.component.html
@@ -0,0 +1,19 @@
+<ul class="pages-hierarchy -with-hierarchy collapsible-menu--container">
+ <li class="-hierarchy-expanded">
+ <div class="tree-menu--item">
+ <span class="tree-menu--hierarchy-span">
+ <button
+ class="tree-menu--hierarchy-indicator collapsible-menu--category-toggle"
+ type="button"
+ >
+ <span class="tree-menu--hierarchy-indicator-icon" aria-hidden="true"></span>
+ </button>
+ <span class="tree-menu--hierarchy-indicator-expanded hidden-for-sighted">Expanded. Click to collapse</span>
+ <span class="tree-menu--hierarchy-indicator-collapsed hidden-for-sighted">Collapsed. Click to show</span>
+ </span>
+ <ul class="pages-hierarchy -with-hierarchy">
+ <li class="collapsible-menu--placeholder">You have no </li>
+ </ul>
+ </div>
+ </li>
+</ul>
diff --git a/frontend/src/app/shared/components/sidemenu/collapsible-menu.component.sass b/frontend/src/app/shared/components/sidemenu/collapsible-menu.component.sass
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/frontend/src/app/shared/components/sidemenu/collapsible-menu.component.ts b/frontend/src/app/shared/components/sidemenu/collapsible-menu.component.ts
new file mode 100644
index 00000000000..96f30c16ce9
--- /dev/null
+++ b/frontend/src/app/shared/components/sidemenu/collapsible-menu.component.ts
@@ -0,0 +1,37 @@
+import {
+ ChangeDetectionStrategy,
+ ChangeDetectorRef,
+ Component,
+ Input,
+ OnInit,
+} from '@angular/core';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+
+export interface IOpCollapsibleMenuItem {
+ title:string;
+ icon?:string;
+ counter?:number;
+ link:string;
+}
+
+@Component({
+ selector: 'op-collapsible-menu',
+ templateUrl: './menu.component.html',
+ styleUrls: ['./menu.component.sass'],
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class OpCollapsibleMenuComponent implements OnInit {
+ @Input() items:IOpCollapsibleMenuItem[];
+
+ @Input() title:string;
+
+ collapsed = false;
+
+ constructor(
+ readonly cdRef:ChangeDetectorRef,
+ readonly I18n:I18nService,
+ ) { }
+
+ ngOnInit() {
+ }
+}
diff --git a/frontend/src/app/shared/shared.module.ts b/frontend/src/app/shared/shared.module.ts
index 422137391f1..678b6ddda60 100644
--- a/frontend/src/app/shared/shared.module.ts
+++ b/frontend/src/app/shared/shared.module.ts
@@ -72,6 +72,7 @@ import { DynamicBootstrapModule } from './components/dynamic-bootstrap/dynamic-b
import { OpFormFieldComponent } from './components/forms/form-field/form-field.component';
import { OpFormBindingDirective } from './components/forms/form-field/form-binding.directive';
import { OpOptionListComponent } from './components/option-list/option-list.component';
+import { OpCollapsibleMenuComponent } from './components/sidemenu/collapsible-menu.component';
export function bootstrapModule(injector:Injector) {
// Ensure error reporter is run
@@ -174,6 +175,7 @@ export function bootstrapModule(injector:Injector) {
OpFormFieldComponent,
OpFormBindingDirective,
OpOptionListComponent,
+ OpCollapsibleMenuComponent,
],
declarations: [
OpDateTimeComponent,
@@ -225,6 +227,7 @@ export function bootstrapModule(injector:Injector) {
OpFormFieldComponent,
OpFormBindingDirective,
OpOptionListComponent,
+ OpCollapsibleMenuComponent,
],
})
export class OPSharedModule {