[ADF-2726] fixed save content for external repository (#3341)

* [ADF-2726] start fixing the show of files loaded from CS

* [ADF-2726] start fixing the show of files loaded from CS

* [ADF-2726] fixed save content for external repository|

* [ADF-2726] fixed save content for external repository|

* [ADF-2726] reeanabled and fixed the tests

* [ADF-2726] reeanabled and fixed the tests

* [ADF-2726] added tests for attach file widget and activiti alfresco service

* [ADF-2726] added tests for attach file widget and activiti alfresco service

* [ADF-2726] fixed test
This commit is contained in:
Vito
2018-05-21 12:14:11 +01:00
committed by Eugenio Romano
parent b599e3a41a
commit 1c7f267c63
9 changed files with 344 additions and 29 deletions

View File

@@ -63,7 +63,7 @@
<mat-list-item class="adf-attach-files-row" *ngFor="let file of field.value">
<img mat-list-icon class="adf-attach-widget__icon"
[id]="'file-'+file.id+'-icon'"
[src]="getIcon(file.mimeType)"
[src]="file.content ? getIcon(file.content.mimeType) : getIcon(file.mimeType)"
[alt]="mimeTypeIcon"
(click)="onAttachFileClicked(file)"
(keyup.enter)="onAttachFileClicked(file)"

View File

@@ -32,6 +32,8 @@ import { ContentNodeDialogService } from '@alfresco/adf-content-services';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/from';
import { zip } from 'rxjs/observable/zip';
import { of } from 'rxjs/observable/of';
@Component({
selector: 'attach-widget',
@@ -121,7 +123,7 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
}
isTemporaryFile(file): boolean {
return this.tempFilesList.indexOf(file) !== -1 ? true : false;
return this.tempFilesList.findIndex((elem) => elem.name === file.name) >= 0;
}
openSelectDialogFromFileSource() {
@@ -129,6 +131,7 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
if (this.isDefinedSourceFolder()) {
this.contentDialog.openFileBrowseDialogByFolderId(params.fileSource.selectedFolder.pathId).subscribe(
(selections: MinimalNodeEntryEntity[]) => {
this.tempFilesList.push(...selections);
this.uploadFileFromCS(selections,
this.field.params.fileSource.selectedFolder.accountId,
this.field.params.fileSource.selectedFolder.siteId);
@@ -142,14 +145,14 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
}
onRemoveAttachFile(file: any) {
if (this.isTemporaryFile(file.contentBlob)) {
if (this.isTemporaryFile(file)) {
this.tempFilesList.splice(this.tempFilesList.indexOf(file.contentBlob), 1);
}
this.removeFile(file);
}
onAttachFileClicked(file: any) {
if (this.isTemporaryFile(file.contentBlob)) {
if (this.isTemporaryFile(file)) {
this.formService.formContentClicked.next(file);
} else {
this.fileClicked(file);
@@ -157,8 +160,8 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
}
downloadContent(file: any): void {
if (this.isTemporaryFile(file.contentBlob)) {
this.contentService.downloadBlob(file.contentBlob, file.name);
if (this.isTemporaryFile(file)) {
this.contentService.downloadBlob(file, file.name);
} else {
this.processContentService.getFileRawContent(file.id).subscribe(
(blob: Blob) => {
@@ -172,9 +175,10 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
}
openSelectDialog(repoId: string, repoName: string) {
const accountIdentifier = 'alfresco-' + repoId + repoName;
const accountIdentifier = 'alfresco-' + repoId + '-' + repoName;
this.contentDialog.openFileBrowseDialogBySite().subscribe(
(selections: MinimalNodeEntryEntity[]) => {
this.tempFilesList.push(...selections);
this.uploadFileFromCS(selections, accountIdentifier);
});
}
@@ -183,10 +187,11 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
let filesSaved = [];
Observable.from(fileNodeList)
.mergeMap(node =>
this.activitiContentService.applyAlfrescoNode(node,
zip(of(node.content.mimeType), this.activitiContentService.applyAlfrescoNode(node,
siteId,
accountId)
).subscribe((res) => {
accountId))
).subscribe(([mymeType, res]) => {
res.mimeType = mymeType;
filesSaved.push(res);
},
(error) => {
@@ -195,8 +200,8 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
() => {
this.field.value = filesSaved;
this.field.json.value = filesSaved;
this.hasFile = true;
});
this.hasFile = true;
}
}

View File

@@ -29,7 +29,7 @@ import {
ContentService,
setupTestBed
} from '@alfresco/adf-core';
import { ContentNodeDialogService } from '@alfresco/adf-content-services';
import { ContentNodeDialogService, ContentNodeSelectorModule } from '@alfresco/adf-content-services';
import { Observable } from 'rxjs/Observable';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { ProcessTestingModule } from '../testing/process.testing.module';
@@ -72,7 +72,10 @@ const definedSourceParams = {
const fakeMinimalNode: MinimalNodeEntryEntity = <MinimalNodeEntryEntity> {
id: 'fake',
name: 'fake-name'
name: 'fake-name',
content: {
mimeType: 'application/pdf'
}
};
const fakePngAnswer = {
@@ -89,9 +92,7 @@ const fakePngAnswer = {
'thumbnailStatus': 'queued'
};
/* tslint:disable */
// TODO: crashes because of LogService problem
xdescribe('AttachFileWidgetComponent', () => {
describe('AttachFileWidgetComponent', () => {
let widget: AttachFileWidgetComponent;
let fixture: ComponentFixture<AttachFileWidgetComponent>;
@@ -103,7 +104,7 @@ xdescribe('AttachFileWidgetComponent', () => {
let formService: FormService;
setupTestBed({
imports: [ProcessTestingModule]
imports: [ProcessTestingModule, ContentNodeSelectorModule]
});
beforeEach(async(() => {
@@ -165,15 +166,15 @@ xdescribe('AttachFileWidgetComponent', () => {
}));
it('should be able to upload files coming from content node selector', async(() => {
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(Observable.of(fakeRepositoryListAnswer));
spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(Observable.of(fakePngAnswer));
spyOn(contentNodeDialogService, 'openFileBrowseDialogBySite').and.returnValue(Observable.of([fakeMinimalNode]));
widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD,
value: []
});
widget.field.id = 'attach-file-attach';
widget.field.params = <FormFieldMetadata> allSourceParams;
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(Observable.of(fakeRepositoryListAnswer));
spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(Observable.of(fakePngAnswer));
spyOn(contentNodeDialogService, 'openFileBrowseDialogBySite').and.returnValue(Observable.of([fakeMinimalNode]));
fixture.detectChanges();
fixture.whenStable().then(() => {
let attachButton: HTMLButtonElement = element.querySelector('#attach-file-attach');
@@ -182,8 +183,9 @@ xdescribe('AttachFileWidgetComponent', () => {
fixture.detectChanges();
fixture.debugElement.query(By.css('#attach-SHAREME')).nativeElement.click();
fixture.detectChanges();
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
fixture.whenStable().then(() => {
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
});
}));