Skip to content

Commit

Permalink
Feat: remove useless call on collection list
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbet committed Nov 8, 2024
1 parent 338c36d commit 8cdc1c8
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dial
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { CollectionService } from '@services/collection-service/collection.service';
import { CollectionItem } from '@services/collection-service/models';
import { CollectionItem, GroupCollectionItem } from '@services/collection-service/models';
import { InitialChoice, LandingPageService } from '@services/landing-page/landing-page.service';
import { MainFormManagerService } from '@services/main-form-manager/main-form-manager.service';
import { Config } from '@services/main-form-manager/models-config';
Expand All @@ -47,7 +47,7 @@ export class LandingPageDialogComponent implements OnInit, OnDestroy {

public configChoice = InitialChoice.none;
public isServerReady = false;
public availablesCollections: { owner: CollectionItem[]; shared: CollectionItem[]; public: CollectionItem[]; };
public availablesCollections: GroupCollectionItem;
public InitialChoice = InitialChoice;

public displayedColumns: string[] = ['id', 'creation', 'detail'];
Expand Down Expand Up @@ -146,7 +146,8 @@ export class LandingPageDialogComponent implements OnInit, OnDestroy {
sharedWith: c.params.organisations.shared,
owner: c.params.organisations.owner
}));
this.availablesCollections = this.collectionService.groupCollectionItems(collectionsItems, this.data.currentOrga);
this.availablesCollections = this.collectionService.buildGroupCollectionItems(collectionsItems, this.data.currentOrga);
this.collectionService.setGroupCollectionItems(this.availablesCollections);
this.collectionService.setCollections(collectionsItems.map(c => c.name));
this.collectionService.setCollectionsRef(cdrs);
},
Expand Down
26 changes: 16 additions & 10 deletions src/app/components/landing-page/landing-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ import { StartupService, ZONE_WUI_BUILDER } from '@services/startup/startup.serv
import { UserOrgData } from 'arlas-iam-api';
import { DataWithLinks } from 'arlas-persistence-api';
import {
ArlasAuthentificationService, ArlasIamService, ArlasSettingsService, AuthentificationService, ConfigAction,
ArlasAuthentificationService, ArlasCollectionService, ArlasIamService, ArlasSettingsService, AuthentificationService, ConfigAction,
ConfigActionEnum, ErrorService, PermissionService, PersistenceService, UserInfosComponent
} from 'arlas-wui-toolkit';
import { Resource } from 'arlas-permissions-api';
import { NGXLogger } from 'ngx-logger';
import { Subscription } from 'rxjs';
import { Subscription, zip } from 'rxjs';
import { map } from 'rxjs/internal/operators/map';
import { LandingPageDialogComponent } from './landing-page-dialog.component';
import { InitialChoice, LandingPageService } from '@services/landing-page/landing-page.service';
import { ResourcesConfigFormBuilderService } from '@services/resources-form-builder/resources-config-form-builder.service';
import { CollectionService } from '@services/collection-service/collection.service';

export interface Configuration {
name: string;
Expand Down Expand Up @@ -97,6 +98,9 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
private translate: TranslateService,
private activatedRoute: ActivatedRoute,
private menu: MenuService,
private collectionService: CollectionService,
private arlasCollectionService: ArlasCollectionService,

private landingPageService: LandingPageService) {

this.authentMode = !!this.settingsService.getAuthentSettings() ? this.settingsService.getAuthentSettings().auth_mode : undefined;
Expand Down Expand Up @@ -211,7 +215,8 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
writers: data.doc_writers,
lastUpdate: +data.last_update_date,
zone: data.doc_zone,
org: this.arlasIamService.getOrganisation()
org: this.arlasIamService.getOrganisation(),
displayPublic: false
};
actions.push({
config,
Expand Down Expand Up @@ -260,13 +265,14 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {

public getConfigList() {
this.persistenceService.list(ZONE_WUI_BUILDER, this.configPageSize, this.configPageNumber + 1, 'desc')
.pipe(map(data => {
if (data.data !== undefined) {
return [data.total, data.data.map(d => this.computeData(d))];
} else {
return [data.total, []];
}
}))
.pipe(
map(data => {
if (data.data !== undefined) {
return [data.total, data.data.map(d => this.computeData(d))];
} else {
return [data.total, []];
}
}))
.subscribe({
next: (result) => {
this.configurationsLength = result[0] as number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class MapGlobalRequestGeometryFormGroup extends ConfigFormGroup {
resetDependantsOnChange: true,
isCollectionSelect: true
},
collectionService.getGroupCollectionItems()
collectionService.getGroupCollectionItemsWithCentroid()
),
geographicalOperator: new SelectFormControl(
geoOp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class MapLayerFormGroup extends ConfigFormGroup {
resetDependantsOnChange: true,
isCollectionSelect: true
},
collectionService.getGroupCollectionItems()
collectionService.getGroupCollectionItemsWithCentroid()
),

collectionDisplayName: new HiddenFormControl(
Expand Down
42 changes: 25 additions & 17 deletions src/app/services/collection-service/collection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ export class CollectionService {
public collectionMinIntervalMap = new Map<string, number>();
public collectionMaxIntervalMap = new Map<string, number>();
public collections: string[] = [];
public groupCollectionItems: GroupCollectionItem = {
collections: [],
owner: [],
shared: [],
public: []
};
public constructor(
private collabSearchService: ArlasCollaborativesearchService,
private spinner: NgxSpinnerService,
private defaultValueService: DefaultValuesService,
private translate: TranslateService,
private iamService: ArlasIamService
private translate: TranslateService
) { }

public getCollections(): string[] {
Expand All @@ -66,6 +71,23 @@ export class CollectionService {
this.collections = collections;
}

public setGroupCollectionItems(groupCollectionItems: GroupCollectionItem): void {
this.groupCollectionItems = groupCollectionItems;
}

public getGroupCollectionItems( ): GroupCollectionItem {
return this.groupCollectionItems;
}

public getGroupCollectionItemsWithCentroid( ): GroupCollectionItem {
const filterFuncion = (c) => !!this.collectionParamsMap.get(c.name) && !!this.collectionParamsMap.get(c.name).params.centroid_path;
const groupCollectionItem = {};
Object.keys(this.groupCollectionItems).forEach(k => {
groupCollectionItem[k] = this.groupCollectionItems[k].filter(filterFuncion);
});
return groupCollectionItem as GroupCollectionItem ;
}

public setCollectionsRef(crds: CollectionReferenceDescription[]): void {
crds.forEach(c => {
const collectionName = c.collection_name;
Expand Down Expand Up @@ -261,7 +283,7 @@ export class CollectionService {
}

// eslint-disable-next-line max-len
public groupCollectionItems(items: CollectionItem[], currentOrg: string): GroupCollectionItem {
public buildGroupCollectionItems(items: CollectionItem[], currentOrg: string): GroupCollectionItem {
const groupCollection = items.reduce((acc, item) => {
if (!!currentOrg && currentOrg.length > 0) {
if (item.isPublic && item.owner !== currentOrg) {
Expand All @@ -282,20 +304,6 @@ export class CollectionService {
}, { owner: [], shared: [], public: [], collections: [] });
return groupCollection;
}

public getGroupCollectionItems(): Observable<GroupCollectionItem> {
return this.getCollectionsReferenceDescription()
.pipe(map(cdrs => {
const collectionsItems = cdrs
.map(c => ({
name: c.collection_name,
isPublic: (c.params.organisations as any).public,
sharedWith: c.params.organisations.shared,
owner: c.params.organisations.owner
}));
return this.groupCollectionItems(collectionsItems, this.iamService.getOrganisation());
}));
}
}


15 changes: 13 additions & 2 deletions src/app/services/landing-page/landing-page.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Config } from '@services/main-form-manager/models-config';
import { MapConfig } from '@services/main-form-manager/models-map-config';
import { MainFormService } from '@services/main-form/main-form.service';
import { StartupService } from '@services/startup/startup.service';
import { ArlasConfigService, ArlasConfigurationDescriptor, ArlasSettingsService } from 'arlas-wui-toolkit';
import { ArlasConfigService, ArlasConfigurationDescriptor, ArlasIamService, ArlasSettingsService } from 'arlas-wui-toolkit';
import { NGXLogger } from 'ngx-logger';
import { NgxSpinnerService } from 'ngx-spinner';
import { Observable, Subject, Subscription, takeUntil } from 'rxjs';
Expand All @@ -53,7 +53,8 @@ export class LandingPageService implements OnDestroy {
private collectionService: CollectionService,
private arlasSettingsService: ArlasSettingsService,
private mainFormManager: MainFormManagerService,
public mainFormService: MainFormService) {
public mainFormService: MainFormService,
private arlasIamService: ArlasIamService) {
}

public ngOnDestroy() {
Expand All @@ -72,6 +73,16 @@ export class LandingPageService implements OnDestroy {
this.collectionService.getCollectionsReferenceDescription().pipe(takeUntil(this._onDestroy$)).subscribe({
next: cdrs => {
this.initCollections(cdrs, configJson, configMapJson, configId, configName);
const collectionsItems = cdrs
.map(c => ({
name: c.collection_name,
isPublic: (c.params.organisations as any).public,
sharedWith: c.params.organisations.shared,
owner: c.params.organisations.owner
}));
const groupCollectionItems = this.collectionService.buildGroupCollectionItems(collectionsItems, this.arlasIamService.getOrganisation());
this.collectionService.setGroupCollectionItems(groupCollectionItems);

},
error: () => {
this.spinner.hide('importconfig');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</ng-container>

<ng-container *ngIf="typedControl.optionalParams.isCollectionSelect">
<mat-optgroup *ngFor="let group of typedControl.groups | async |keyvalue :orderCollectionGroup" [label]="group.key | groupCollection:arlasIamService.getOrganisation()" [class.hideLabel]="group.value.length === 0">
<mat-optgroup *ngFor="let group of typedControl.groups | keyvalue :orderCollectionGroup" [label]="group.key | groupCollection:arlasIamService.getOrganisation()" [class.hideLabel]="group.value.length === 0">
<mat-option *ngFor="let collection of group.value" [value]="collection.name">
{{ collection.name | getCollectionDisplayName | translate }}
</mat-option>
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/models/config-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ export class SelectFormControl extends ConfigFormControl {
// used only for autocomplete: list of filtered options
public filteredOptions: Array<SelectOption>;
public syncOptions: Array<SelectOption> = [];
public groups;
public groups: GroupCollectionItem;

public constructor(
formState: any,
Expand All @@ -431,7 +431,7 @@ export class SelectFormControl extends ConfigFormControl {
public isAutocomplete: boolean,
options: Array<SelectOption> | Observable<Array<SelectOption>>,
optionalParams?: ControlOptionalParams,
groups?: Observable<GroupCollectionItem>) {
groups?: GroupCollectionItem) {

super(
formState,
Expand Down

0 comments on commit 8cdc1c8

Please sign in to comment.