mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-06-16 17:54:45 +00:00
open create dialog after template selection
This commit is contained in:
parent
42cdbc2931
commit
9e93d462f7
@ -25,7 +25,15 @@
|
|||||||
|
|
||||||
import { Effect, Actions, ofType } from '@ngrx/effects';
|
import { Effect, Actions, ofType } from '@ngrx/effects';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { map, withLatestFrom, switchMap, catchError } from 'rxjs/operators';
|
import {
|
||||||
|
map,
|
||||||
|
withLatestFrom,
|
||||||
|
switchMap,
|
||||||
|
catchError,
|
||||||
|
debounceTime,
|
||||||
|
flatMap,
|
||||||
|
skipWhile
|
||||||
|
} from 'rxjs/operators';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import {
|
import {
|
||||||
CreateFileFromTemplate,
|
CreateFileFromTemplate,
|
||||||
@ -37,8 +45,8 @@ import {
|
|||||||
import { CreateFileFromTemplateService } from '../../services/create-file-from-template.service';
|
import { CreateFileFromTemplateService } from '../../services/create-file-from-template.service';
|
||||||
import { AlfrescoApiService } from '@alfresco/adf-core';
|
import { AlfrescoApiService } from '@alfresco/adf-core';
|
||||||
import { ContentManagementService } from '../../services/content-management.service';
|
import { ContentManagementService } from '../../services/content-management.service';
|
||||||
import { from, of } from 'rxjs';
|
import { from, of, Observable } from 'rxjs';
|
||||||
import { NodeEntry } from '@alfresco/js-api';
|
import { NodeEntry, NodeBodyUpdate, MinimalNode } from '@alfresco/js-api';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TemplateEffects {
|
export class TemplateEffects {
|
||||||
@ -57,31 +65,70 @@ export class TemplateEffects {
|
|||||||
this.createFileFromTemplateService
|
this.createFileFromTemplateService
|
||||||
.openTemplatesDialog()
|
.openTemplatesDialog()
|
||||||
.pipe(
|
.pipe(
|
||||||
|
debounceTime(300),
|
||||||
|
flatMap(([node]) =>
|
||||||
|
this.createFileFromTemplateService
|
||||||
|
.createTemplateDialog(node)
|
||||||
|
.afterClosed()
|
||||||
|
),
|
||||||
|
skipWhile(node => !node),
|
||||||
withLatestFrom(this.store.select(getCurrentFolder)),
|
withLatestFrom(this.store.select(getCurrentFolder)),
|
||||||
switchMap(([[template], parentNode]) => {
|
switchMap(([template, parentNode]) => {
|
||||||
return from(
|
return this.copyNode(template, parentNode.id);
|
||||||
this.apiService
|
|
||||||
.getInstance()
|
|
||||||
.nodes.copyNode(template.id, { targetParentId: parentNode.id })
|
|
||||||
);
|
|
||||||
}),
|
}),
|
||||||
catchError(error => {
|
catchError(error => {
|
||||||
const { statusCode } = JSON.parse(error.message).error;
|
return this.handleError(error);
|
||||||
|
|
||||||
if (statusCode !== 409) {
|
|
||||||
this.store.dispatch(
|
|
||||||
new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return of(null);
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.subscribe((node: NodeEntry | null) => {
|
.subscribe((node: NodeEntry | null) => {
|
||||||
if (node) {
|
if (node) {
|
||||||
this.content.reload.next();
|
this.content.reload.next(node);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private copyNode(
|
||||||
|
source: MinimalNode,
|
||||||
|
parentId: string
|
||||||
|
): Observable<NodeEntry> {
|
||||||
|
return from(
|
||||||
|
this.apiService.getInstance().nodes.copyNode(source.id, {
|
||||||
|
targetParentId: parentId,
|
||||||
|
name: source.name
|
||||||
|
})
|
||||||
|
).pipe(
|
||||||
|
switchMap(node =>
|
||||||
|
this.updateNode(node.entry.id, {
|
||||||
|
properties: {
|
||||||
|
'cm:title': source.properties['cm:title'],
|
||||||
|
'cm:description': source.properties['cm:description']
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateNode(
|
||||||
|
id: string,
|
||||||
|
update: NodeBodyUpdate
|
||||||
|
): Observable<NodeEntry> {
|
||||||
|
return from(this.apiService.getInstance().nodes.updateNode(id, update));
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleError(error: Error): Observable<null> {
|
||||||
|
const { statusCode } = JSON.parse(error.message).error;
|
||||||
|
|
||||||
|
if (statusCode !== 409) {
|
||||||
|
this.store.dispatch(
|
||||||
|
new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC')
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.store.dispatch(
|
||||||
|
new SnackbarErrorAction('APP.MESSAGES.ERRORS.CONFLICT')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return of(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user