mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[ACS-8635] ADW: View button not working on create process (#10263)
This commit is contained in:
parent
8d895a9893
commit
51f74a54f3
@ -35,6 +35,8 @@ import { ProcessTestingModule } from '../../../testing/process.testing.module';
|
|||||||
import { AttachFileWidgetDialogService } from './attach-file-widget-dialog.service';
|
import { AttachFileWidgetDialogService } from './attach-file-widget-dialog.service';
|
||||||
import { ActivitiContentService } from '../../services/activiti-alfresco.service';
|
import { ActivitiContentService } from '../../services/activiti-alfresco.service';
|
||||||
import { ProcessContentService } from '../../services/process-content.service';
|
import { ProcessContentService } from '../../services/process-content.service';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
|
||||||
const fakeRepositoryListAnswer = [
|
const fakeRepositoryListAnswer = [
|
||||||
{
|
{
|
||||||
@ -145,6 +147,8 @@ describe('AttachFileWidgetComponent', () => {
|
|||||||
let fixture: ComponentFixture<AttachFileWidgetComponent>;
|
let fixture: ComponentFixture<AttachFileWidgetComponent>;
|
||||||
let element: HTMLInputElement;
|
let element: HTMLInputElement;
|
||||||
let activitiContentService: ActivitiContentService;
|
let activitiContentService: ActivitiContentService;
|
||||||
|
let router: Router;
|
||||||
|
let activatedRoute: ActivatedRoute;
|
||||||
let appConfigService: AppConfigService;
|
let appConfigService: AppConfigService;
|
||||||
let contentNodeDialogService: ContentNodeDialogService;
|
let contentNodeDialogService: ContentNodeDialogService;
|
||||||
let processContentService: ProcessContentService;
|
let processContentService: ProcessContentService;
|
||||||
@ -154,11 +158,24 @@ describe('AttachFileWidgetComponent', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [ProcessTestingModule, AttachFileWidgetComponent]
|
imports: [ProcessTestingModule, AttachFileWidgetComponent, RouterTestingModule],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: ActivatedRoute,
|
||||||
|
useValue: {
|
||||||
|
snapshot: {
|
||||||
|
queryParams: {}
|
||||||
|
},
|
||||||
|
queryParams: of({})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
fixture = TestBed.createComponent(AttachFileWidgetComponent);
|
fixture = TestBed.createComponent(AttachFileWidgetComponent);
|
||||||
widget = fixture.componentInstance;
|
widget = fixture.componentInstance;
|
||||||
element = fixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
|
router = TestBed.inject(Router);
|
||||||
|
activatedRoute = TestBed.inject(ActivatedRoute);
|
||||||
activitiContentService = TestBed.inject(ActivitiContentService);
|
activitiContentService = TestBed.inject(ActivitiContentService);
|
||||||
contentNodeDialogService = TestBed.inject(ContentNodeDialogService);
|
contentNodeDialogService = TestBed.inject(ContentNodeDialogService);
|
||||||
processContentService = TestBed.inject(ProcessContentService);
|
processContentService = TestBed.inject(ProcessContentService);
|
||||||
@ -381,6 +398,7 @@ describe('AttachFileWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
widget.field.id = 'attach-file-attach';
|
widget.field.id = 'attach-file-attach';
|
||||||
widget.field.params = definedSourceParams;
|
widget.field.params = definedSourceParams;
|
||||||
|
spyOn(router, 'navigate');
|
||||||
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer));
|
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer));
|
||||||
spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(of(fakePngAnswer));
|
spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(of(fakePngAnswer));
|
||||||
spyOn(contentNodeDialogService, 'openFileBrowseDialogByFolderId').and.returnValue(of([fakeNode]));
|
spyOn(contentNodeDialogService, 'openFileBrowseDialogByFolderId').and.returnValue(of([fakeNode]));
|
||||||
@ -401,6 +419,11 @@ describe('AttachFileWidgetComponent', () => {
|
|||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
|
|
||||||
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
|
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
|
||||||
|
expect(router.navigate).toHaveBeenCalledWith([], {
|
||||||
|
relativeTo: activatedRoute,
|
||||||
|
queryParams: { nodes: 'fake' },
|
||||||
|
queryParamsHandling: 'merge'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to upload files from local source', async () => {
|
it('should be able to upload files from local source', async () => {
|
||||||
@ -475,6 +498,7 @@ describe('AttachFileWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should remove file when remove is clicked', async () => {
|
it('should remove file when remove is clicked', async () => {
|
||||||
|
spyOn(router, 'navigate');
|
||||||
const menuButton = element.querySelector<HTMLButtonElement>('#file-1155-option-menu');
|
const menuButton = element.querySelector<HTMLButtonElement>('#file-1155-option-menu');
|
||||||
expect(menuButton).not.toBeNull();
|
expect(menuButton).not.toBeNull();
|
||||||
menuButton.click();
|
menuButton.click();
|
||||||
@ -489,6 +513,11 @@ describe('AttachFileWidgetComponent', () => {
|
|||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
|
|
||||||
expect(element.querySelector('#file-1155')).toBeNull();
|
expect(element.querySelector('#file-1155')).toBeNull();
|
||||||
|
expect(router.navigate).toHaveBeenCalledWith([], {
|
||||||
|
relativeTo: activatedRoute,
|
||||||
|
queryParams: { nodes: '' },
|
||||||
|
queryParamsHandling: 'merge'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should download file when download is clicked', async () => {
|
it('should download file when download is clicked', async () => {
|
||||||
|
@ -33,6 +33,7 @@ import { MatIconModule } from '@angular/material/icon';
|
|||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatMenuModule } from '@angular/material/menu';
|
import { MatMenuModule } from '@angular/material/menu';
|
||||||
import { MatListModule } from '@angular/material/list';
|
import { MatListModule } from '@angular/material/list';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'attach-widget',
|
selector: 'attach-widget',
|
||||||
@ -77,6 +78,8 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
|
|||||||
private contentDialog: ContentNodeDialogService,
|
private contentDialog: ContentNodeDialogService,
|
||||||
private appConfigService: AppConfigService,
|
private appConfigService: AppConfigService,
|
||||||
private downloadService: DownloadService,
|
private downloadService: DownloadService,
|
||||||
|
private router: Router,
|
||||||
|
private activatedRoute: ActivatedRoute,
|
||||||
private attachDialogService: AttachFileWidgetDialogService
|
private attachDialogService: AttachFileWidgetDialogService
|
||||||
) {
|
) {
|
||||||
super(formService, thumbnails, processContentService);
|
super(formService, thumbnails, processContentService);
|
||||||
@ -149,6 +152,7 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
|
|||||||
} else {
|
} else {
|
||||||
this.contentDialog.openFileBrowseDialogByFolderId(params.fileSource.selectedFolder.pathId).subscribe((selections: Node[]) => {
|
this.contentDialog.openFileBrowseDialogByFolderId(params.fileSource.selectedFolder.pathId).subscribe((selections: Node[]) => {
|
||||||
this.tempFilesList.push(...selections);
|
this.tempFilesList.push(...selections);
|
||||||
|
this.updateNodesParams();
|
||||||
this.uploadFileFromCS(
|
this.uploadFileFromCS(
|
||||||
selections,
|
selections,
|
||||||
this.field.params.fileSource.selectedFolder.accountId,
|
this.field.params.fileSource.selectedFolder.accountId,
|
||||||
@ -166,6 +170,7 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
|
|||||||
onRemoveAttachFile(file: File | RelatedContentRepresentation) {
|
onRemoveAttachFile(file: File | RelatedContentRepresentation) {
|
||||||
if (this.isTemporaryFile(file)) {
|
if (this.isTemporaryFile(file)) {
|
||||||
this.tempFilesList.splice(this.tempFilesList.indexOf((file as RelatedContentRepresentation).contentBlob), 1);
|
this.tempFilesList.splice(this.tempFilesList.indexOf((file as RelatedContentRepresentation).contentBlob), 1);
|
||||||
|
this.updateNodesParams();
|
||||||
}
|
}
|
||||||
this.removeFile(file);
|
this.removeFile(file);
|
||||||
}
|
}
|
||||||
@ -219,6 +224,7 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
|
|||||||
this.contentDialog.openFileBrowseDialogByDefaultLocation().subscribe((selections: Node[]) => {
|
this.contentDialog.openFileBrowseDialogByDefaultLocation().subscribe((selections: Node[]) => {
|
||||||
if (selections.length) {
|
if (selections.length) {
|
||||||
this.tempFilesList.push(...selections);
|
this.tempFilesList.push(...selections);
|
||||||
|
this.updateNodesParams();
|
||||||
this.uploadFileFromCS(selections, `alfresco-${repository.id}-${repository.name}Alfresco`);
|
this.uploadFileFromCS(selections, `alfresco-${repository.id}-${repository.name}Alfresco`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -277,6 +283,18 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private updateNodesParams(): void {
|
||||||
|
this.router.navigate(
|
||||||
|
[],
|
||||||
|
{
|
||||||
|
relativeTo: this.activatedRoute,
|
||||||
|
queryParams: { nodes: this.tempFilesList.map(file => file.id).join(',') },
|
||||||
|
queryParamsHandling: 'merge'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private getDomainHost(urlToCheck: string): string {
|
private getDomainHost(urlToCheck: string): string {
|
||||||
const result = urlToCheck.match('^(?:https?://)?(?:[^@/\n]+@)?(?:www\\.)?([^:/?\n]+)');
|
const result = urlToCheck.match('^(?:https?://)?(?:[^@/\n]+@)?(?:www\\.)?([^:/?\n]+)');
|
||||||
return result[1];
|
return result[1];
|
||||||
|
@ -77,7 +77,7 @@ export class UploadWidgetComponent extends WidgetComponent implements OnInit {
|
|||||||
const files = event.target.files;
|
const files = event.target.files;
|
||||||
let filesSaved = [];
|
let filesSaved = [];
|
||||||
|
|
||||||
if (this.field.json.value) {
|
if (this.field?.json.value) {
|
||||||
filesSaved = [...this.field.json.value];
|
filesSaved = [...this.field.json.value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user