Skip to content

Commit

Permalink
feat: CMS navigation category component
Browse files Browse the repository at this point in the history
  • Loading branch information
suschneider committed Oct 14, 2022
1 parent 1a6d0ce commit 19a7ab0
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app/core/facades/shopping.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class ShoppingFacade {
}

navigationCategory$(categoryRef: string, limit?: number) {
this.store.dispatch(loadCategoryTree({ categoryRef }));
this.store.dispatch(loadCategoryTree({ categoryRef, limit }));
return this.store.pipe(select(getNavigationCategory(categoryRef)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const loadTopLevelCategoriesSuccess = createAction(

export const loadCategoryTree = createAction(
'[Categories Internal] Load a specific category tree',
payload<{ categoryRef: string }>()
payload<{ categoryRef: string; limit: number }>()
);

export const loadCategoryTreeFail = createAction('[Categories API] Load a specific category tree fail', httpError());
Expand Down
10 changes: 7 additions & 3 deletions src/app/core/store/shopping/categories/categories.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { selectRouteParam } from 'ish-core/store/core/router';
import { setBreadcrumbData } from 'ish-core/store/core/viewconf';
import { personalizationStatusDetermined } from 'ish-core/store/customer/user';
import { loadMoreProducts } from 'ish-core/store/shopping/product-listing';
import { log } from 'ish-core/utils/dev/operators';
import { HttpStatusCodeService } from 'ish-core/utils/http-status-code/http-status-code.service';
import {
mapErrorToAction,
mapToPayload,
mapToPayloadProperty,
useCombinedObservableOnAction,
whenTruthy,
Expand Down Expand Up @@ -121,9 +123,11 @@ export class CategoriesEffects {
loadCategoryTree$ = createEffect(() =>
this.actions$.pipe(
useCombinedObservableOnAction(this.actions$.pipe(ofType(loadCategoryTree)), personalizationStatusDetermined),
mapToPayloadProperty('categoryRef'),
switchMap(categoryRef =>
this.categoryService.getCategoryTree(categoryRef).pipe(
log('nach der Action'),
mapToPayload(),
log('payload'),
switchMap(({ categoryRef, limit }) =>
this.categoryService.getCategoryTree(categoryRef, limit).pipe(
map(categories => loadCategoryTreeSuccess({ categories })),
mapErrorToAction(loadCategoryTreeFail)
)
Expand Down
9 changes: 9 additions & 0 deletions src/app/shared/cms/cms.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CMSDialogComponent } from './components/cms-dialog/cms-dialog.component
import { CMSFreestyleComponent } from './components/cms-freestyle/cms-freestyle.component';
import { CMSImageEnhancedComponent } from './components/cms-image-enhanced/cms-image-enhanced.component';
import { CMSImageComponent } from './components/cms-image/cms-image.component';
import { CMSNavigationCategoryComponent } from './components/cms-navigation-category/cms-navigation-category.component';
import { CMSNavigationLinkComponent } from './components/cms-navigation-link/cms-navigation-link.component';
import { CMSNavigationPageComponent } from './components/cms-navigation-page/cms-navigation-page.component';
import { CMSProductListCategoryComponent } from './components/cms-product-list-category/cms-product-list-category.component';
Expand Down Expand Up @@ -139,6 +140,14 @@ import { CMS_COMPONENT } from './configurations/injection-keys';
},
multi: true,
},
{
provide: CMS_COMPONENT,
useValue: {
definitionQualifiedName: 'app_sf_base_cm:component.navigation.category.pagelet2-Component',
class: CMSNavigationCategoryComponent,
},
multi: true,
},
],
})
export class CMSModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<ng-container *ngIf="pagelet?.hasParam('NavigationCategory')">
<li
*ngIf="category$ | async as category"
#subMenu
[class]="'dropdown not-first ' + pagelet.stringParam('CSSClass')"
(mouseover)="subMenuShow(subMenu)"
(mouseleave)="subMenuHide(subMenu)"
(click)="subMenuHide(subMenu)"
>
<ng-container *ngIf="pagelet.hasParam('DisplayName'); else noDisplayName">
<a [routerLink]="category.url" [ngStyle]="{ width: !(showSubMenu() && category.hasChildren) ? '100%' : '' }">
<div [ishServerHtml]="pagelet.stringParam('DisplayName')"></div>
</a>
</ng-container>
<ng-template #noDisplayName>
<a [routerLink]="category.url">{{ category.name }}</a>
</ng-template>
<ng-container *ngIf="showSubMenu() || pagelet.hasParam('SubNavigationHTML')">
<ish-sub-category-navigation
[categoryUniqueId]="category.uniqueId"
[subCategoriesDepth]="1"
[view]="'auto'"
></ish-sub-category-navigation>
</ng-container>
</li>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { instance, mock } from 'ts-mockito';

import { ShoppingFacade } from 'ish-core/facades/shopping.facade';

import { CMSNavigationCategoryComponent } from './cms-navigation-category.component';

describe('Cms Navigation Category Component', () => {
let component: CMSNavigationCategoryComponent;
let fixture: ComponentFixture<CMSNavigationCategoryComponent>;
let element: HTMLElement;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CMSNavigationCategoryComponent],
providers: [{ provide: ShoppingFacade, useFactory: () => instance(mock(ShoppingFacade)) }],
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(CMSNavigationCategoryComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
});

it('should be created', () => {
expect(component).toBeTruthy();
expect(element).toBeTruthy();
expect(() => fixture.detectChanges()).not.toThrow();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core';
import { Observable } from 'rxjs';

import { ShoppingFacade } from 'ish-core/facades/shopping.facade';
import { ContentPageletView } from 'ish-core/models/content-view/content-view.model';
import { NavigationCategory } from 'ish-core/models/navigation-category/navigation-category.model';
import { CMSComponent } from 'ish-shared/cms/models/cms-component/cms-component.model';

@Component({
selector: 'ish-cms-navigation-category',
templateUrl: './cms-navigation-category.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CMSNavigationCategoryComponent implements CMSComponent, OnChanges {
@Input() pagelet: ContentPageletView;

category$: Observable<NavigationCategory>;

constructor(private shoppingFacade: ShoppingFacade) {}

ngOnChanges(): void {
if (this.pagelet?.hasParam('NavigationCategory')) {
this.category$ = this.shoppingFacade.navigationCategory$(
this.pagelet.stringParam('NavigationCategory'),
this.pagelet.numberParam('SubNavigationDepth')
);
}
}

showSubMenu() {
return this.pagelet?.hasParam('SubNavigationDepth') && this.pagelet.numberParam('SubNavigationDepth') === 0
? false
: true;
}

subMenuShow(subMenu: HTMLElement) {
subMenu.classList.add('hover');
}
subMenuHide(subMenu: HTMLElement) {
subMenu.classList.remove('hover');
}
}
5 changes: 4 additions & 1 deletion src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { IconModule } from 'ish-core/icon.module';
import { PipesModule } from 'ish-core/pipes.module';
import { RoleToggleModule } from 'ish-core/role-toggle.module';
import { ModuleLoaderService } from 'ish-core/utils/module-loader/module-loader.service';
import { ShellModule } from 'ish-shell/shell.module';

import { CaptchaExportsModule } from '../extensions/captcha/exports/captcha-exports.module';
import { CompareExportsModule } from '../extensions/compare/exports/compare-exports.module';
Expand All @@ -42,6 +43,7 @@ import { CMSDialogComponent } from './cms/components/cms-dialog/cms-dialog.compo
import { CMSFreestyleComponent } from './cms/components/cms-freestyle/cms-freestyle.component';
import { CMSImageEnhancedComponent } from './cms/components/cms-image-enhanced/cms-image-enhanced.component';
import { CMSImageComponent } from './cms/components/cms-image/cms-image.component';
import { CMSNavigationCategoryComponent } from './cms/components/cms-navigation-category/cms-navigation-category.component';
import { CMSNavigationLinkComponent } from './cms/components/cms-navigation-link/cms-navigation-link.component';
import { CMSNavigationPageComponent } from './cms/components/cms-navigation-page/cms-navigation-page.component';
import { CMSProductListCategoryComponent } from './cms/components/cms-product-list-category/cms-product-list-category.component';
Expand Down Expand Up @@ -171,6 +173,7 @@ const importExportModules = [
RecentlyExportsModule,
RoleToggleModule,
RouterModule,
ShellModule,
StoreLocatorExportsModule,
SwiperModule,
TactonExportsModule,
Expand Down Expand Up @@ -290,7 +293,7 @@ const exportedComponents = [

@NgModule({
imports: [...importExportModules],
declarations: [...declaredComponents, ...exportedComponents],
declarations: [...declaredComponents, ...exportedComponents, CMSNavigationCategoryComponent],
exports: [...exportedComponents, ...importExportModules],
})
export class SharedModule {
Expand Down
3 changes: 1 addition & 2 deletions src/app/shell/shell.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { LazyContentIncludeComponent } from './shared/lazy-content-include/lazy-
import { LazyMiniBasketContentComponent } from './shared/lazy-mini-basket-content/lazy-mini-basket-content.component';
import { LazySearchBoxComponent } from './shared/lazy-search-box/lazy-search-box.component';

const exportedComponents = [CookiesBannerComponent, FooterComponent, HeaderComponent];
const exportedComponents = [CookiesBannerComponent, FooterComponent, HeaderComponent, SubCategoryNavigationComponent];

@NgModule({
imports: [
Expand Down Expand Up @@ -74,7 +74,6 @@ const exportedComponents = [CookiesBannerComponent, FooterComponent, HeaderCompo
LazySearchBoxComponent,
LoginStatusComponent,
MiniBasketComponent,
SubCategoryNavigationComponent,
UserInformationMobileComponent,
],
exports: [...exportedComponents],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,47 @@
}
},
"customAttributes": {}
},
{
"type": "PageletRO",
"definitionQualifiedName": "app_sf_base_cm:component.navigation.category.pagelet2-Component",
"link": {
"type": "Link",
"uri": "/inSPIRED-inTRONICS_Business-Site/rest/cms/pagelets/cmp_NAVIGATION_CATEGORY",
"title": "NAVIGATION CATEGORY",
"itemId": "cmp_NAVIGATION_CATEGORY"
},
"displayName": "NAVIGATION CATEGORY",
"id": "cmp_20220912_152120",
"domain": "inSPIRED-inTRONICS_Business-rest",
"configurationParameters": {
"NavigationCategory": {
"value": "Computers@inSPIRED-Computers",
"type": "bc_catalog:types.pagelet2-CategoryBO",
"definitionQualifiedName": "app_sf_base_cm:component.navigation.category.pagelet2-Component-NavigationCategory"
},
"DisplayName": {
"value": "Category",
"type": "bc_pmc:types.pagelet2-Text",
"definitionQualifiedName": "app_sf_base_cm:component.navigation.category.pagelet2-Component-AlternateNavigationTitle"
},
"SubNavigationDepth": {
"value": "3",
"type": "bc_pmc:types.pagelet2-Integer",
"definitionQualifiedName": "app_sf_base_cm:component.navigation.category.pagelet2-Component-SubNavigationDepth"
},
"CSSClass": {
"value": "testing",
"type": "bc_pmc:types.pagelet2-Text",
"definitionQualifiedName": "app_sf_base_cm:component.navigation.category.pagelet2-Component-CSSClass"
},
"SubNavigationHTML": {
"value": "<p><span style=\"background-color: #169179;\">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</span></p>",
"type": "bc_pmc:types.pagelet2-Html",
"definitionQualifiedName": "app_sf_base_cm:component.navigation.link.pagelet2-Component-SubNavigationHTML"
}
},
"customAttributes": {}
}
],
"displayName": "Header - Navigation",
Expand Down

0 comments on commit 19a7ab0

Please sign in to comment.