mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
fix readonly attach file scenarios (#5365)
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
"REMOVE_FILE": "Remove",
|
"REMOVE_FILE": "Remove",
|
||||||
"UPLOAD": "UPLOAD",
|
"UPLOAD": "UPLOAD",
|
||||||
"REQUIRED": "*Required",
|
"REQUIRED": "*Required",
|
||||||
|
"NO_FILE_ATTACHED" : "No file attached",
|
||||||
"VALIDATOR": {
|
"VALIDATOR": {
|
||||||
"INVALID_NUMBER": "Use a different number format",
|
"INVALID_NUMBER": "Use a different number format",
|
||||||
"INVALID_DATE": "Use a different date format",
|
"INVALID_DATE": "Use a different date format",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<div class="adf-attach-widget {{field.className}}"
|
<div class="adf-attach-widget {{field.className}}"
|
||||||
[class.adf-invalid]="!field.isValid"
|
[class.adf-invalid]="!field.isValid"
|
||||||
[class.adf-readonly]="field.readOnly">
|
[class.adf-readonly]="field.readOnly">
|
||||||
<label class="adf-label" [attr.for]="field.id">{{field.name}}
|
<label class="adf-label" [attr.for]="field.id">{{field.name}}
|
||||||
<span *ngIf="isRequired()">*</span>
|
<span *ngIf="isRequired()">*</span>
|
||||||
</label>
|
</label>
|
||||||
@@ -10,26 +10,27 @@
|
|||||||
{{ 'FORM.FIELD.UPLOAD' | translate }}
|
{{ 'FORM.FIELD.UPLOAD' | translate }}
|
||||||
<mat-icon>file_upload</mat-icon>
|
<mat-icon>file_upload</mat-icon>
|
||||||
<input #uploadFiles
|
<input #uploadFiles
|
||||||
[multiple]="multipleOption"
|
[multiple]="multipleOption"
|
||||||
type="file"
|
type="file"
|
||||||
[id]="field.id"
|
[id]="field.id"
|
||||||
(change)="onAttachFileChanged($event)"/>
|
(change)="onAttachFileChanged($event)"/>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="adf-attach-widget__menu-upload" *ngIf="isUploadButtonVisible() && isMultipleSourceUpload()">
|
<div class="adf-attach-widget__menu-upload" *ngIf="isUploadButtonVisible() && isMultipleSourceUpload()">
|
||||||
<button mat-raised-button color="primary" [matMenuTriggerFor]="menu" [id]="field.id">
|
<button mat-raised-button color="primary" [matMenuTriggerFor]="menu" [id]="field.id">
|
||||||
{{ 'FORM.FIELD.UPLOAD' | translate }}
|
{{ 'FORM.FIELD.UPLOAD' | translate }}
|
||||||
<mat-icon>attach_file</mat-icon>
|
<mat-icon>attach_file</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<mat-menu #menu="matMenu" class="adf-attach-widget__menu-content">
|
<mat-menu #menu="matMenu" class="adf-attach-widget__menu-content">
|
||||||
<div *ngIf="isContentSourceSelected()">
|
<div *ngIf="isContentSourceSelected()">
|
||||||
<button mat-menu-item
|
<button mat-menu-item
|
||||||
id="attach-{{field.params?.fileSource?.name}}"
|
id="attach-{{field.params?.fileSource?.name}}"
|
||||||
(click)="uploadFileFromCS()">
|
(click)="uploadFileFromCS()">
|
||||||
{{field.params?.fileSource?.name}}
|
{{field.params?.fileSource?.name}}
|
||||||
<mat-icon>
|
<mat-icon>
|
||||||
<img alt="alfresco" class="adf-attach-widget__image-logo" src="../assets/images/alfresco-flower.svg">
|
<img alt="alfresco" class="adf-attach-widget__image-logo"
|
||||||
</mat-icon>
|
src="../assets/images/alfresco-flower.svg">
|
||||||
|
</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</mat-menu>
|
</mat-menu>
|
||||||
@@ -53,12 +54,12 @@
|
|||||||
</button>
|
</button>
|
||||||
<mat-menu #fileActionMenu="matMenu" xPosition="before">
|
<mat-menu #fileActionMenu="matMenu" xPosition="before">
|
||||||
<button id="{{'file-'+file?.id+'-show-file'}}"
|
<button id="{{'file-'+file?.id+'-show-file'}}"
|
||||||
mat-menu-item (click)="onAttachFileClicked(file)">
|
mat-menu-item (click)="onAttachFileClicked(file)">
|
||||||
<mat-icon>image</mat-icon>
|
<mat-icon>image</mat-icon>
|
||||||
<span>{{ 'FORM.FIELD.SHOW_FILE' | translate }}</span>
|
<span>{{ 'FORM.FIELD.SHOW_FILE' | translate }}</span>
|
||||||
</button>
|
</button>
|
||||||
<button id="{{'file-'+file?.id+'-download-file'}}"
|
<button id="{{'file-'+file?.id+'-download-file'}}"
|
||||||
mat-menu-item (click)="downloadContent(file)">
|
mat-menu-item (click)="downloadContent(file)">
|
||||||
<mat-icon>file_download</mat-icon>
|
<mat-icon>file_download</mat-icon>
|
||||||
<span>{{ 'FORM.FIELD.DOWNLOAD_FILE' | translate }}</span>
|
<span>{{ 'FORM.FIELD.DOWNLOAD_FILE' | translate }}</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -71,6 +72,10 @@
|
|||||||
</mat-menu>
|
</mat-menu>
|
||||||
</mat-list-item>
|
</mat-list-item>
|
||||||
</mat-list>
|
</mat-list>
|
||||||
|
<div *ngIf="!hasFile && field.readOnly" id="{{'adf-attach-empty-list-'+field.id}}">
|
||||||
|
{{ 'FORM.FIELD.NO_FILE_ATTACHED' | translate }}
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<error-widget [error]="field.validationSummary"></error-widget>
|
<error-widget [error]="field.validationSummary"></error-widget>
|
||||||
|
@@ -234,6 +234,56 @@ describe('AttachFileCloudWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
describe('when is readonly', () => {
|
||||||
|
|
||||||
|
it('should show empty list message when there are no file', async(() => {
|
||||||
|
widget.field = new FormFieldModel(new FormModel(), {
|
||||||
|
type: FormFieldTypes.UPLOAD,
|
||||||
|
readOnly: true,
|
||||||
|
value: []
|
||||||
|
});
|
||||||
|
widget.field.id = 'empty-test';
|
||||||
|
widget.field.params = <FormFieldMetadata> onlyLocalParams;
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
expect(element.querySelector('#adf-attach-empty-list-empty-test')).not.toBeNull();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not show empty list message when there are files', async(() => {
|
||||||
|
widget.field = new FormFieldModel(new FormModel(), {
|
||||||
|
type: FormFieldTypes.UPLOAD,
|
||||||
|
readOnly: true,
|
||||||
|
value: [fakePngAnswer]
|
||||||
|
});
|
||||||
|
widget.field.id = 'fill-test';
|
||||||
|
widget.field.params = <FormFieldMetadata> onlyLocalParams;
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
expect(element.querySelector('#adf-attach-empty-list-fill-test')).toBeNull();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not show remove button when there are files attached', async(() => {
|
||||||
|
widget.field = new FormFieldModel(new FormModel(), {
|
||||||
|
type: FormFieldTypes.UPLOAD,
|
||||||
|
readOnly: true,
|
||||||
|
value: [fakePngAnswer]
|
||||||
|
});
|
||||||
|
widget.field.id = 'fill-test';
|
||||||
|
widget.field.params = <FormFieldMetadata> onlyLocalParams;
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
const menuButton: HTMLButtonElement = <HTMLButtonElement> (
|
||||||
|
fixture.debugElement.query(By.css('#file-1155-option-menu'))
|
||||||
|
.nativeElement
|
||||||
|
);
|
||||||
|
menuButton.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(fixture.debugElement.query(By.css('#file-1155-remove'))).toBeNull();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
describe('when a file is uploaded', () => {
|
describe('when a file is uploaded', () => {
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
widget.field = new FormFieldModel(new FormModel(), {
|
widget.field = new FormFieldModel(new FormModel(), {
|
||||||
|
@@ -34,6 +34,11 @@
|
|||||||
(change)="onFileChanged($event)"/>
|
(change)="onFileChanged($event)"/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="!hasFile && field.readOnly">
|
||||||
|
{{ 'FORM.FIELD.NO_FILE_ATTACHED' | translate }}
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<error-widget [error]="field.validationSummary"></error-widget>
|
<error-widget [error]="field.validationSummary"></error-widget>
|
||||||
<error-widget *ngIf="isInvalidFieldRequired()" required="{{ 'FORM.FIELD.REQUIRED' | translate }}"></error-widget>
|
<error-widget *ngIf="isInvalidFieldRequired()" required="{{ 'FORM.FIELD.REQUIRED' | translate }}"></error-widget>
|
||||||
|
Reference in New Issue
Block a user