mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-10-08 14:51:32 +00:00
refactor part 2
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<div class="adf-file-viewer-widget {{field.className}}" [class.adf-invalid]="!field.isValid"
|
||||
[class.adf-readonly]="field.readOnly">
|
||||
<label class="adf-label" [attr.for]="field.id">{{field.name | translate }}<span class="adf-asterisk"
|
||||
*ngIf="isRequired()">*</span></label>
|
||||
<adf-viewer [overlayMode]="false" [nodeId]="field.value" [showViewer]="field.value" [allowGoBack]="false"></adf-viewer>
|
||||
<error-widget [error]="field.validationSummary"></error-widget>
|
||||
</div>
|
@@ -0,0 +1,19 @@
|
||||
file-viewer-widget {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
.adf-file-viewer-widget {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
adf-viewer.adf-viewer {
|
||||
position: relative;
|
||||
|
||||
.adf-viewer-container {
|
||||
.adf-viewer-content > div {
|
||||
height: 90vh;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,83 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { FormModel } from '../core/form.model';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { FormFieldModel } from '../core/form-field.model';
|
||||
import { FormService } from '../../../services/form.service';
|
||||
import { FileViewerWidgetComponent } from './file-viewer.widget';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
describe('FileViewerWidgetComponent', () => {
|
||||
const fakeForm = new FormModel();
|
||||
let widget: FileViewerWidgetComponent;
|
||||
let formServiceStub: Partial<FormService>;
|
||||
let fixture: ComponentFixture<FileViewerWidgetComponent>;
|
||||
|
||||
const fakePngAnswer: any = {
|
||||
id: '1933',
|
||||
link: false,
|
||||
isExternal: false,
|
||||
relatedContent: false,
|
||||
contentAvailable: true,
|
||||
name: 'a_png_file.png',
|
||||
simpleType: 'image',
|
||||
mimeType: 'image/png',
|
||||
previewStatus: 'queued',
|
||||
thumbnailStatus: 'queued',
|
||||
created: '2022-10-14T17:17:37.099Z',
|
||||
createdBy: { id: 1001, firstName: 'Admin', lastName: 'admin', email: 'admin@example.com' }
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [ FileViewerWidgetComponent ],
|
||||
providers: [ { provide: FormService, useValue: formServiceStub } ]
|
||||
});
|
||||
|
||||
formServiceStub = TestBed.inject(FormService);
|
||||
fixture = TestBed.createComponent(FileViewerWidgetComponent);
|
||||
widget = fixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should set the file id corretly when the field value is an array', (done) => {
|
||||
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: [fakePngAnswer] });
|
||||
widget.field = fakeField;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(widget.field.value).toBe('1933');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should set the file id corretly when the field value is a string', (done) => {
|
||||
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' });
|
||||
widget.field = fakeField;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(widget.field.value).toBe('fakeValue');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,55 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { FormService } from '../../../services/form.service';
|
||||
import { WidgetComponent } from '../widget.component';
|
||||
|
||||
/* eslint-disable @angular-eslint/component-selector */
|
||||
|
||||
@Component({
|
||||
selector: 'file-viewer-widget',
|
||||
templateUrl: './file-viewer.widget.html',
|
||||
styleUrls: ['./file-viewer.widget.scss'],
|
||||
host: {
|
||||
'(click)': 'event($event)',
|
||||
'(blur)': 'event($event)',
|
||||
'(change)': 'event($event)',
|
||||
'(focus)': 'event($event)',
|
||||
'(focusin)': 'event($event)',
|
||||
'(focusout)': 'event($event)',
|
||||
'(input)': 'event($event)',
|
||||
'(invalid)': 'event($event)',
|
||||
'(select)': 'event($event)'
|
||||
},
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class FileViewerWidgetComponent extends WidgetComponent implements OnInit {
|
||||
constructor(formService: FormService) {
|
||||
super(formService);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.field &&
|
||||
this.field.value &&
|
||||
Array.isArray(this.field.value) &&
|
||||
this.field.value.length) {
|
||||
const file = this.field.value[0];
|
||||
this.field.value = file.id;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user