Skip to content

Commit

Permalink
Add orga
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedHamouGisaia committed Jan 26, 2024
1 parent ed7bbd8 commit c57194a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2 mat-dialog-title>{{'Duplicate' | translate}} {{action.config.name}}?</h2>
<span style="color: red; display: block;">{{errorMessage | translate}}</span>
</div>
<div mat-dialog-actions>
<button mat-raised-button class="modal_button" color="primary" (click)="duplicate(value, action.config.id)">{{ 'Duplicate' | translate}}</button>
<button mat-raised-button class="modal_button" color="primary" (click)="duplicate(value, action.config)">{{ 'Duplicate' | translate}}</button>
<button mat-raised-button class="modal_button" [mat-dialog-close]="false">{{ 'Cancel' | translate}}</button>
</div>
</div>
Expand All @@ -39,7 +39,7 @@ <h2 mat-dialog-title>{{'Rename' | translate}} {{action.config.name}}?</h2>
<span style="color: red; display: block;">{{errorMessage | translate}}</span>
</div>
<div mat-dialog-actions>
<button mat-raised-button class="modal_button" color="primary" (click)="rename(value, action.config.id)">{{ 'Rename' | translate}}</button>
<button mat-raised-button class="modal_button" color="primary" (click)="rename(value, action.config)">{{ 'Rename' | translate}}</button>
<button mat-raised-button class="modal_button" [mat-dialog-close]="false">{{ 'Cancel' | translate}}</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,54 +52,54 @@ export class ActionModalComponent {
if (!!arlasConfig) {
const previewId = this.configurationService.getPreview(arlasConfig);
if (previewId) {
this.duplicatePreviewThenConfig$(previewId, arlasConfig, config.name, newName).subscribe();
this.duplicatePreviewThenConfig$(previewId, arlasConfig, config.name, newName, config.org).subscribe();
} else {
this.duplicateConfig$(config.id, newName).subscribe();
this.duplicateConfig$(config.id, newName, config.org).subscribe();
}
} else {
/** */ console.error('Error duplicating the config: the config is not valid');
}
}


private duplicateConfig$(configId: string, newConfigName: string) {
return this.persistenceService.duplicate('config.json', configId, newConfigName)
private duplicateConfig$(configId: string, newConfigName: string, org?: string) {
return this.persistenceService.duplicate('config.json', configId, newConfigName, this.getOptionsSetOrg(org))
.pipe(
catchError(() => /** todo */ of()));

}

private duplicatePreviewThenConfig$(previewId: string, arlasConfig: any, oldConfigName: string, newConfigName: string) {
return this.duplicatePreview$(previewId, newConfigName)
private duplicatePreviewThenConfig$(previewId: string, arlasConfig: any, oldConfigName: string, newConfigName: string, org: string) {
return this.duplicatePreview$(previewId, newConfigName, org)
.pipe(
map((p: DataWithLinks) => {
const newArlasConfig = this.configurationService.updatePreview(arlasConfig, p.id);
const stringifiedNewArlasConfig = JSON.stringify(newArlasConfig);
this.persistenceService.duplicateValue('config.json', stringifiedNewArlasConfig, oldConfigName, newArlasConfig,
this.getOptionsSetOrg(p.doc_organization, this.persistenceService.options));
this.getOptionsSetOrg(p.doc_organization));
})
).pipe(
catchError(() => /** todo */ of()));

}

private duplicatePreview$(previewId: string, newConfigName: string): Observable<any> {
private duplicatePreview$(previewId: string, newConfigName: string, org?: string): Observable<any> {
const newPreviewName = newConfigName.concat('_preview');
return this.persistenceService.get(previewId, this.getOptionsWithoutOrg())
return this.persistenceService.get(previewId, this.getOptionsSetOrg(org))
.pipe(map((p: DataWithLinks) => {
this.persistenceService.create('preview', newPreviewName, p.doc_value, [], [],
this.getOptionsSetOrg(p.doc_organization, this.persistenceService.options));
this.getOptionsSetOrg(p.doc_organization));
}))
.pipe(catchError(() => /** todo*/ of()));
}

public rename(newName: string, configId: string) {
this.persistenceService.get(configId, this.getOptionsWithoutOrg()).subscribe(
public rename(newName: string, config: Config) {
this.persistenceService.get(config.id, this.getOptionsSetOrg(config.org)).subscribe(
currentConfig => {
const key = currentConfig.doc_key;
// NO NEED TO RENAME IT
// ['i18n', 'tour'].forEach(zone => ['fr', 'en'].forEach(lg => this.renameLinkedData(zone, key, newName, lg)));
this.persistenceService.rename(configId, newName, this.getOptionsWithoutOrg()).subscribe({
this.persistenceService.rename(config.id, newName, this.getOptionsSetOrg(config.org)).subscribe({
error: error => this.raiseError(error)
});
});
Expand Down Expand Up @@ -144,18 +144,8 @@ export class ActionModalComponent {
}
}

private getOptionsWithoutOrg(): any {
private getOptionsSetOrg(org: string) {
const options = Object.assign({}, this.persistenceService.options);
// No need to have arlas-org-filer headers to delete or get by id
if (!!options && !!options['headers']) {
if (!!options['headers']['arlas-org-filter']) {
delete options['headers']['arlas-org-filter'];
}
}
return options;
}

private getOptionsSetOrg(options: any, org: string) {
const newOptions = Object.assign({}, options);
// No need to have arlas-org-filer headers to delete or get by id
if (!!newOptions && !!newOptions['headers']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class ConfigMenuComponent implements OnInit {
// No need to have arlas-org-filer headers to delete or get by id
if(!!options && !!options['headers']){
if(!!options['headers']['arlas-org-filter']){
delete options['headers']['arlas-org-filter'];
options['headers']['arlas-org-filter'] = action.config.org;
}
}
this.getDialogRef(action).subscribe(id => {
Expand Down

0 comments on commit c57194a

Please sign in to comment.