Skip to content

Commit

Permalink
Show asset viewer on favourite page
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-va committed Oct 29, 2024
1 parent 08b70e7 commit 591e232
Show file tree
Hide file tree
Showing 23 changed files with 34 additions and 220 deletions.
4 changes: 0 additions & 4 deletions apps/client-asset-sg/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ registerLocaleData(locale_deCH, 'de-CH');
path: ':lang/asset-admin',
loadChildren: () => import('@asset-sg/asset-editor').then((m) => m.AssetEditorModule),
},
{
path: ':lang/favorites',
loadChildren: () => import('@asset-sg/favorites').then((m) => m.FavoritesRoutingModule),
},
{
matcher: assetsPageMatcher,
loadChildren: () => import('@asset-sg/asset-viewer').then((m) => m.AssetViewerModule),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
asset-sg-menu-bar-item
icon="assets"
[link]="isActive ? null : [translateService.currentLang]"
[isActive]="isActive && ((isFiltersOpen$ | async) ?? false)"
[isActive]="isActive"
(click)="isActive ? toggleAssetDrawer() : null"
>
menuBar.filters
</li>
@if (userExists$ | async) {
<li
*ngIf="userExists$ | async"
*rxLet="activeItem === 'favorites'; let isActive"
asset-sg-menu-bar-item
icon="favorite"
[link]="[translateService.currentLang, 'favorites']"
[isActive]="activeItem === 'favorites'"
[link]="isActive ? null : [translateService.currentLang, 'favorites']"
[isActive]="isActive"
(click)="isActive ? toggleAssetDrawer() : null"
>
menuBar.favourites
</li>
}
<li
*canCreate="AssetEditPolicy"
asset-sg-menu-bar-item
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component, HostBinding, inject } from '@angular/core';
import { NavigationEnd, Router, UrlSerializer } from '@angular/router';
import { NavigationEnd, Router } from '@angular/router';
import { appSharedStateActions, fromAppShared } from '@asset-sg/client-shared';
import { AssetEditPolicy } from '@asset-sg/shared/v2';
import { UntilDestroy } from '@ngneat/until-destroy';
Expand All @@ -23,7 +23,6 @@ export class MenuBarComponent {
readonly role = 'navigation';

private readonly router = inject(Router);
private readonly urlSerializer = inject(UrlSerializer);
private readonly store = inject(Store<AppState>);

readonly translateService = inject(TranslateService);
Expand All @@ -35,7 +34,8 @@ export class MenuBarComponent {
filter((event) => event instanceof NavigationEnd),
startWith(() => undefined),
map((): MenuItem | null => {
const segments = this.router.getCurrentNavigation()?.finalUrl?.root.children['primary'].segments;
const segments = (this.router.getCurrentNavigation() ?? this.router.lastSuccessfulNavigation)?.finalUrl?.root
.children['primary'].segments;
if (segments == null || segments.length === 1) {
return 'home';
}
Expand Down
4 changes: 0 additions & 4 deletions apps/client-asset-sg/src/app/i18n/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export const deAppTranslations = {
nameTaken: "Der Name '{{name}}' wird bereits von einer anderen Arbeitsgruppe verwendet.",
},
},
categories: {
favorites: 'Favoriten',
},
favorites: {
title: 'Favoriten',
},
Expand All @@ -48,7 +45,6 @@ export const deAppTranslations = {
dragHandleLabel: 'Ziehgriff',
},
search: {
categories: 'Kategorien',
textSearchFieldPlaceholder: 'Suche nach...',
searchInstructionsHeading: 'Asset-Suche',
searchInstructions:
Expand Down
4 changes: 0 additions & 4 deletions apps/client-asset-sg/src/app/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export const enAppTranslations: AppTranslations = {
nameTaken: "The name '{{name}}' is already taken by another workgroup.",
},
},
categories: {
favorites: 'Favorites',
},
favorites: {
title: 'Favorites',
},
Expand All @@ -50,7 +47,6 @@ export const enAppTranslations: AppTranslations = {
dragHandleLabel: 'Drag handle',
},
search: {
categories: 'Categories',
textSearchFieldPlaceholder: 'Search by...',
searchInstructionsHeading: 'Asset-Search',
searchInstructions: 'Search for an asset using the search field or by drawing a ploygon on the map.',
Expand Down
4 changes: 0 additions & 4 deletions apps/client-asset-sg/src/app/i18n/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export const frAppTranslations: AppTranslations = {
nameTaken: "Le nom '{{name}}' est déjà utilisé par un autre groupe de travail.",
},
},
categories: {
favorites: 'Favorites',
},
favorites: {
title: 'Favorites',
},
Expand All @@ -50,7 +47,6 @@ export const frAppTranslations: AppTranslations = {
dragHandleLabel: 'Poignée de tirage',
},
search: {
categories: 'Catégories',
textSearchFieldPlaceholder: 'Recherche par...',
searchInstructionsHeading: "Recherche d'assets",
searchInstructions: "Recherche d'un asset via le champ de recherche ou en dessinant un polygone sur la carte.",
Expand Down
4 changes: 0 additions & 4 deletions apps/client-asset-sg/src/app/i18n/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export const itAppTranslations: AppTranslations = {
nameTaken: "IT Der Name '{{name}}' wird bereits von einer anderen Arbeitsgruppe verwendet.",
},
},
categories: {
favorites: 'IT Favoriten',
},
favorites: {
title: 'IT Favoriten',
},
Expand All @@ -50,7 +47,6 @@ export const itAppTranslations: AppTranslations = {
dragHandleLabel: 'IT Ziehgriff',
},
search: {
categories: 'IT Kategorien',
textSearchFieldPlaceholder: 'IT Suche nach...',
searchInstructionsHeading: 'IT Asset-Suche',
searchInstructions: 'IT Suche nach einem Asset über das Suchfeld oder durch Zeichnen eines Polygons auf der Karte.',
Expand Down
4 changes: 0 additions & 4 deletions apps/client-asset-sg/src/app/i18n/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export const rmAppTranslations: AppTranslations = {
nameTaken: "RM Name '{{name}}' wird bereits von einer anderen Arbeitsgruppe verwendet.",
},
},
categories: {
favorites: 'RM Favoriten',
},
favorites: {
title: 'RM Favoriten',
},
Expand All @@ -50,7 +47,6 @@ export const rmAppTranslations: AppTranslations = {
dragHandleLabel: 'RM Ziehgriff',
},
search: {
categories: 'RM Kategorien',
textSearchFieldPlaceholder: 'RM Suche nach...',
searchInstructionsHeading: 'RM Asset-Suche',
searchInstructions: 'RM Suche nach einem Asset über das Suchfeld oder durch Zeichnen eines Polygons auf der Karte.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ export class AssetSearchService {
usageCodes: {
buckets: AggregationBucket<UsageCode>[];
};
favorites?: {
buckets: [AggregationBucket];
};
workgroupIds: {
buckets: AggregationBucket<number>[];
};
Expand All @@ -261,13 +258,6 @@ export class AssetSearchService {
return { aggs: { a: { [operator]: field } }, filter: { bool: { filter } } };
};

const makeFavoritesAggregation = (): AggregationsAggregationContainer => {
const NUMBER_OF_BUCKETS = 10_000;
const { filter } = mapQueryToElasticDslParts({ ...query, categories: ['favorites'] }, user);
const field: { field: string; size?: number } = { field: 'favoredByUserIds', size: NUMBER_OF_BUCKETS };
return { aggs: { a: { terms: field } }, filter: { bool: { filter } } };
};

const { must, filter } = mapQueryToElasticDslParts(query, user);

const aggregateByQuery = async (aggs: Record<string, AggregationsAggregationContainer>) => {
Expand Down Expand Up @@ -299,7 +289,6 @@ export class AssetSearchService {
manCatLabelItemCodes: [],
usageCodes: [],
workgroupIds: [],
categories: [],
};
}

Expand All @@ -313,7 +302,6 @@ export class AssetSearchService {
workgroupIds: makeAggregation('terms', 'workgroupIds', 'workgroupId'),
minCreateDate: makeAggregation('min', 'minCreateDate', 'createDate'),
maxCreateDate: makeAggregation('max', 'maxCreateDate', 'createDate'),
favorites: makeFavoritesAggregation(),
});

const aggs = result.aggregations as unknown as NestedAggResult<Result>;
Expand All @@ -331,12 +319,6 @@ export class AssetSearchService {
manCatLabelItemCodes: aggs.manCatLabelItemCodes.a.buckets.map(mapBucket),
usageCodes: aggs.usageCodes.a.buckets.map(mapBucket),
workgroupIds: aggs.workgroupIds.a.buckets.map(mapBucket),
categories: [
{
value: 'favorites',
count: aggs.favorites?.a?.buckets[0]?.doc_count ?? 0,
},
],
createDate: {
min: dateFromDateId(aggs.minCreateDate.a.value),
max: dateFromDateId(aggs.maxCreateDate.a.value),
Expand Down Expand Up @@ -798,15 +780,12 @@ const mapQueryToElasticDslParts = (
},
});
}
if (query.categories) {
const categories = new Set(query.categories);
if (categories.delete('favorites')) {
filters.push({
terms: {
favoredByUserIds: [user.id],
},
});
}
if (query.favoritesOnly) {
filters.push({
terms: {
favoredByUserIds: [user.id],
},
});
}

if (query.polygon != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ <h2 translate>search.searchControl</h2>
</div>
<section class="filters">
<h3 translate>search.refineSearch</h3>
<section>
<h4 translate>search.categories</h4>
<asset-sg-asset-search-filter [filters]="categoriesFilters$ | push" />
</section>
<section>
<h4 translate>search.workgroup</h4>
<asset-sg-asset-search-filter [filters]="workgroupFilters$ | push" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
selectAssetKindFilters,
selectAssetSearchQuery,
selectAvailableAuthors,
selectCategoriesFilters,
selectCreateDate,
selectGeometryFilters,
selectIsFiltersOpen,
Expand Down Expand Up @@ -56,7 +55,6 @@ export class AssetSearchRefineComponent implements OnInit, OnDestroy, AfterViewI
readonly languageFilters$ = this.store.select(selectLanguageFilters);
readonly assetKindFilters$ = this.store.select(selectAssetKindFilters);
readonly workgroupFilters$ = this.store.select(selectWorkgroupFilters);
readonly categoriesFilters$ = this.store.select(selectCategoriesFilters);

readonly isDrawActive$ = this.store.select(selectMapControlIsDrawing);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AssetSearchQuery, AssetSearchResult, LV95, Polygon } from '@asset-sg/sh
import * as RD from '@devexperts/remote-data-ts';
import { UntilDestroy } from '@ngneat/until-destroy';
import { Actions, concatLatestFrom, createEffect, ofType } from '@ngrx/effects';
import { ROUTER_NAVIGATED } from '@ngrx/router-store';
import { ROUTER_NAVIGATED, RouterNavigatedPayload } from '@ngrx/router-store';
import { Store } from '@ngrx/store';
import * as D from 'io-ts/Decoder';
import { EMPTY, filter, identity, map, merge, of, share, switchMap, withLatestFrom } from 'rxjs';
Expand Down Expand Up @@ -141,8 +141,13 @@ export class AssetSearchEffects {
*/
public queryParams$ = this.actions$.pipe(
ofType(ROUTER_NAVIGATED),
filter((x) => assetsPageMatcher(x.payload.routerState.root.firstChild.url) !== null),
filter(
({ payload }: { payload: RouterNavigatedPayload }) =>
assetsPageMatcher(payload.routerState.root.firstChild?.url ?? []) !== null
),
map(({ payload }) => {
const routerState = payload.routerState;
const url = routerState.root.firstChild?.url ?? [];
const params = payload.routerState.root.queryParams;
const query: AssetSearchQuery = {};
const assetId: number | undefined = readNumberParam(params, QUERY_PARAM_MAPPING.assetId);
Expand All @@ -158,7 +163,9 @@ export class AssetSearchEffects {
query.geometryCodes = readArrayParam(params, QUERY_PARAM_MAPPING.geometryCodes);
query.languageItemCodes = readArrayParam(params, QUERY_PARAM_MAPPING.languageItemCodes);
query.workgroupIds = readArrayParam<number>(params, QUERY_PARAM_MAPPING.workgroupIds);
query.categories = readArrayParam<'favorites'>(params, QUERY_PARAM_MAPPING.categories) ?? ['favorites'];
if (url.length === 2 && url[1].path === 'favorites') {
query.favoritesOnly = true;
}
return { query, assetId };
}),
share()
Expand Down Expand Up @@ -224,13 +231,7 @@ export class AssetSearchEffects {
updateArrayParam(params, QUERY_PARAM_MAPPING.languageItemCodes, query.languageItemCodes);
updateArrayParam(params, QUERY_PARAM_MAPPING.workgroupIds, query.workgroupIds);

// Delete the categories parameter when it is in its default state,
// so we can display a "clean" url by default.
if (query.categories?.length === 1 && query.categories[0] === 'favorites') {
delete params[QUERY_PARAM_MAPPING.categories];
} else {
updateArrayParam(params, QUERY_PARAM_MAPPING.categories, query.categories ?? []);
}
console.log('todo nav');

return this.router.navigate([], { queryParams: params });
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,7 @@ export interface AppStateWithAssetSearch extends AppState {
}

const initialState: AssetSearchState = {
query: {
text: undefined,
polygon: undefined,
authorId: undefined,
createDate: undefined,
manCatLabelItemCodes: undefined,
assetKindItemCodes: undefined,
usageCodes: undefined,
geometryCodes: undefined,
languageItemCodes: undefined,
categories: ['favorites'],
},
query: {},
results: {
page: {
size: 0,
Expand All @@ -58,7 +47,6 @@ const initialState: AssetSearchState = {
manCatLabelItemCodes: [],
usageCodes: [],
workgroupIds: [],
categories: [],
createDate: null,
},
isFiltersOpen: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ export const selectCurrentAssetDetail = createSelector(assetSearchFeature, (stat
export const selectStudies = createSelector(assetSearchFeature, (state) => state.studies);

export const selectHasDefaultFilters = createSelector(assetSearchFeature, ({ query }) =>
(Object.entries(query) as Array<[keyof AssetSearchQuery, unknown]>).every(([key, value]) => {
if (key === 'categories') {
const categories = value as string[];
return categories?.length === 1 && categories[0] === 'favorites';
}
return value === undefined;
})
Object.values(query).every((value) => value === undefined)
);

export const selectCurrentAssetDetailVM = createSelector(
Expand Down Expand Up @@ -272,13 +266,6 @@ export const selectManCatLabelFilters = selectFilters<string>('manCatLabelItemCo
}))
);

export const selectCategoriesFilters = selectFilters<'favorites'>('categories', () => [
{
name: { key: `categories.favorites` },
value: 'favorites',
},
]);

export interface AvailableAuthor {
contactId: number;
count: number;
Expand Down
1 change: 0 additions & 1 deletion libs/favorites/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './lib/favorites.module';
export * from './lib/favorites-routing.module';

This file was deleted.

Loading

0 comments on commit 591e232

Please sign in to comment.