Skip to content

Commit

Permalink
Merge pull request #920 from gisaia/feat/store_preview_id
Browse files Browse the repository at this point in the history
fixes for preview update
  • Loading branch information
MohamedHamouGisaia authored Feb 15, 2024
2 parents f910983 + 8d61681 commit ebd020a
Show file tree
Hide file tree
Showing 12 changed files with 409 additions and 276 deletions.
240 changes: 140 additions & 100 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"ajv": "8.8.2",
"ajv-keywords": "5.1.0",
"ang-jsoneditor": "1.10.5",
"arlas-wui-toolkit": "~24.3.4",
"arlas-wui-toolkit": "25.0.0-beta.3",
"file-saver": "^2.0.2",
"jsoneditor": "9.5.6",
"moment": "^2.29.4",
Expand Down Expand Up @@ -91,6 +91,9 @@
"overrides": {
"portable-fetch": {
"node-fetch": "3.3.0"
},
"angular-oauth2-oidc-jwks": {
"jsrsasign": "^11.0.0"
}
}
}
1 change: 0 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import enComponents from 'arlas-web-components/assets/i18n/en.json';
import frComponents from 'arlas-web-components/assets/i18n/fr.json';
import enToolkit from 'arlas-wui-toolkit/assets/i18n/en.json';
import frToolkit from 'arlas-wui-toolkit/assets/i18n/fr.json';
import { ColorGeneratorLoader, ColorGeneratorModule } from 'arlas-web-components';


export function loadServiceFactory(defaultValuesService: DefaultValuesService) {
Expand Down
21 changes: 15 additions & 6 deletions src/app/components/landing-page/landing-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { Subscription } 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';

export interface Configuration {
name: string;
Expand Down Expand Up @@ -80,6 +81,7 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
public persistenceService: PersistenceService,
public mainFormService: MainFormService,
private startingConfigFormBuilder: StartingConfigFormBuilderService,
private resourcesConfigFormBuilder: ResourcesConfigFormBuilderService,
private arlasAuthentService: ArlasAuthentificationService,
private dialog: MatDialog,
private authService: AuthentificationService,
Expand Down Expand Up @@ -110,9 +112,12 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
this.mainFormService.configChange.next({ id: undefined, name: undefined });
}

this.mainFormService.startingConfig.init(
this.mainFormService.startingConfig?.init(
this.startingConfigFormBuilder.build()
);
this.mainFormService.resourcesConfig?.init(
this.resourcesConfigFormBuilder.build()
);
if (this.activatedRoute.snapshot.paramMap.has('id')) {
this.confId = this.activatedRoute.snapshot.paramMap.get('id');
this.loadConfig(this.confId);
Expand Down Expand Up @@ -206,7 +211,8 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
actions.push({
config,
configIdParam: 'config_id',
type: ConfigActionEnum.VIEW
type: ConfigActionEnum.VIEW,
enabled: data.updatable
});
actions.push({
config,
Expand All @@ -222,7 +228,9 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
actions.push({
config,
type: ConfigActionEnum.DUPLICATE,
name: data.doc_key
name: data.doc_key,
enabled: data.updatable

});
actions.push({
config,
Expand Down Expand Up @@ -290,7 +298,10 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
}

public loadConfig(id: string) {
this.persistenceService.get(id).subscribe(data => {
this.persistenceService.get(id).subscribe((data: DataWithLinks) => {
this.mainFormService.configurationName = data.doc_key;
this.mainFormService.configurationId = id;
this.mainFormService.dashboard = data;
const configJson = JSON.parse(data.doc_value) as Config;
if (configJson.arlas !== undefined) {
const configMapJson = configJson.arlas.web.components.mapgl.input.mapLayers as MapConfig;
Expand All @@ -299,8 +310,6 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
this.configChoice = InitialChoice.setup;
this.openChoice(this.configChoice);
}
this.mainFormService.configurationName = data.doc_key;
this.mainFormService.configurationId = id;
});
}
public getUserInfos() {
Expand Down
106 changes: 45 additions & 61 deletions src/app/modules/map-config/components/preview/preview.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ import { StartupService, ZONE_PREVIEW } from '@services/startup/startup.service'
import { ArlasColorService, MapglComponent } from 'arlas-web-components';
import { MapContributor } from 'arlas-web-contributors';
import { ArlasCollaborativesearchService, ArlasConfigService, ContributorBuilder, PersistenceService } from 'arlas-wui-toolkit';
import { merge, Subscription } from 'rxjs';
import { catchError, map, merge, Observable, of, Subscription, tap, throwError } from 'rxjs';
import { ArlasSettingsService } from 'arlas-wui-toolkit';
import { DataWithLinks } from 'arlas-persistence-api';

export interface MapglComponentInput {
mapglContributors: MapContributor[];
Expand Down Expand Up @@ -187,70 +188,53 @@ export class PreviewComponent implements AfterViewInit, OnDestroy {
img = rescaledCanvas.toDataURL('image/png');
}
this.mapglComponent.map.resize();
if (!!this.mainFormService.configurationName) {
const resourcesConfig = this.mainFormService.resourcesConfig.getFg();
const previewId = resourcesConfig.customControls.resources.previewId.value;
if (!!this.mainFormService.dashboard) {
const currentConfig = this.mainFormService.dashboard;
const name = this.mainFormService.configurationName.concat('_preview');
this.persistenceService.existByZoneKey('preview', name).subscribe(
exist => {
this.persistenceService.get(this.configId).subscribe({
next: (currentConfig) => {
let previewReaders = [];
let previewWriters = [];
if (currentConfig.doc_readers) {
previewReaders = currentConfig.doc_readers.map(reader => reader.replace('config.json', 'preview'));
}
if (currentConfig.doc_writers) {
previewWriters = currentConfig.doc_writers.map(writer => writer.replace('config.json', 'preview'));
}
if (exist.exists) {
this.persistenceService.getByZoneKey('preview', name).subscribe({
next: (data) => {
this.persistenceService.update(data.id, img, new Date(data.last_update_date).getTime(), name,
previewReaders, previewWriters);
this.snackbar.open(
this.translate.instant('Preview updated !')
);
},
error: (e) => {
this.snackbar.open(
this.translate.instant('Cannot update the preview')
);
}
});
} else {
this.persistenceService.create(
ZONE_PREVIEW,
name,
img,
previewReaders,
previewWriters
).subscribe({
next: () => {
this.snackbar.open(
this.translate.instant('Preview saved !')
);
},
error: (e) => {
this.snackbar.open(
this.translate.instant('Cannot create the preview')
);
}
});
}
},
error: (e) => {
this.snackbar.open(
this.translate.instant('Cannot fetch current config')
);
}
});


}
);
const pGroups = this.persistenceService.dashboardToResourcesGroups(currentConfig.doc_readers, currentConfig.doc_writers);
this.previewExists$(previewId)
.pipe(
map(exists => this.createOrUpdatePreview$(exists, previewId, img, name, pGroups.readers, pGroups.writers)))
.subscribe({
complete: () => this.snackbar.open(this.translate.instant('Preview saved !'))
});
} else {
resourcesConfig.customControls.resources.previewValue.setValue(img);
this.snackbar.open(
this.translate.instant('Cannot save Preview: You need to save the dashboard first')
this.translate.instant('Preview saved !')
);
}
}

private previewExists$(previewId): Observable<boolean> {
if (!previewId || previewId === '') {
return of(false);
} else {
return this.persistenceService.exists(previewId).pipe(map(r => r.exists));
}
}

private createOrUpdatePreview$(previewExists: boolean, previewId: string, img, name: string, previewReaders?, previewWriters?) {
const resourcesConfig = this.mainFormService.resourcesConfig.getFg();
resourcesConfig.customControls.resources.previewValue.setValue(img);
if (previewExists) {
this.persistenceService.updateResource(previewId, previewReaders, previewWriters, img);
this.persistenceService.create(ZONE_PREVIEW, name, img, previewReaders, previewWriters)
.pipe(map((p: DataWithLinks) => {
resourcesConfig.customControls.resources.previewId.setValue(p.id);
return p;
}))
.pipe(catchError((err) => this.catchPreviewError(err, 'Cannot update the preview'))).subscribe();
}
}

private catchPreviewError(err, msg) {
this.snackbar.open(
this.translate.instant(msg)
);
return throwError(() => new Error(err));
}

}
16 changes: 13 additions & 3 deletions src/app/services/main-form-manager/config-export-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { ARLAS_ID } from '@services/main-form/main-form.service';
import { hashCode, stringifyArlasFilter } from './tools';
import { ShortcutsService } from '@analytics-config/services/shortcuts/shortcuts.service';
import { DescribedUrl } from 'arlas-web-components/lib/components/results/utils/results.utils';
import { ResourcesConfigFormGroup } from '@services/resources-form-builder/resources-config-form-builder.service';

export enum EXPORT_TYPE {
json = 'json',
Expand Down Expand Up @@ -130,6 +131,7 @@ export class ConfigExportHelper {
}
public static process(
startingConfig: StartingConfigFormGroup,
resourcesConfig: ResourcesConfigFormGroup,
mapConfigGlobal: MapGlobalFormGroup,
mapConfigLayers: FormArray,
mapConfigVisualisations: FormArray,
Expand All @@ -144,7 +146,7 @@ export class ConfigExportHelper {
colorService: ArlasColorService,
collectionService: CollectionService,
shortcutsService: ShortcutsService
): any {
): Config {
const chipssearch: ChipSearchConfig = {
name: searchConfigGlobal.customControls.name.value,
icon: searchConfigGlobal.customControls.unmanagedFields.icon.value
Expand Down Expand Up @@ -203,7 +205,8 @@ export class ConfigExportHelper {
replacedAttribute: 'arlas.web.components.mapgl.input.mapLayers.externalEventLayers',
replacer: 'external-event-layers'
}
]
],
resources: {}
};
let mainCollection;
const collectionFormControl = startingConfig.customControls.collection;
Expand Down Expand Up @@ -271,10 +274,17 @@ export class ConfigExportHelper {
}

this.exportSideModulesConfig(config, sideModulesGlobal);

this.exportPreview(config, resourcesConfig);
return config;
}


private static exportPreview(config: Config, resourcesForm: ResourcesConfigFormGroup) {
if (resourcesForm.hasPreviewId()) {
config.resources.previewId = resourcesForm.customControls.resources.previewId.value;
}
}

public static getLayerSourceConfig(layerFg: FormGroup): LayerSourceConfig {
const layerValues = layerFg.value;
const modeValues = layerFg.value.mode === LAYER_MODE.features ? layerFg.value.featuresFg :
Expand Down
Loading

0 comments on commit ebd020a

Please sign in to comment.