mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-15839] Fix file object input in viewers (#8804)
* [AAE-15839] Fix file object input in viewers * [AAE-15839] Attend review comments * [AAE-15839] Remove duplication * [AAE-15839] Fix package-lock.json * [AAE-15839] Fix package.json * [AAE-15839] Remove duplication * [AAE-15839] Remove duplication
This commit is contained in:
committed by
GitHub
parent
1f96c3452c
commit
04803c1815
@@ -60,26 +60,27 @@ describe('BaseViewerWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should set the file id corretly when the field value is an array', (done) => {
|
it('should set the file id corretly when the field value is an array', (done) => {
|
||||||
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: [fakePngAnswer] });
|
assertFileId([fakePngAnswer], '1933', fakeForm, widget, fixture, done);
|
||||||
widget.field = fakeField;
|
});
|
||||||
|
|
||||||
fixture.detectChanges();
|
it('should set the file id corretly when the field value is an object', (done) => {
|
||||||
|
assertFileId(fakePngAnswer, '1933', fakeForm, widget, fixture, done);
|
||||||
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) => {
|
it('should set the file id corretly when the field value is a string', (done) => {
|
||||||
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' });
|
assertFileId('fakeValue', 'fakeValue', fakeForm, widget, fixture, done);
|
||||||
widget.field = fakeField;
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(widget.field.value).toBe('fakeValue');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function assertFileId(value: any, expectedFileId: string, fakeForm: FormModel, widget: BaseViewerWidgetComponent, fixture: ComponentFixture<BaseViewerWidgetComponent>, done: DoneFn) {
|
||||||
|
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value });
|
||||||
|
widget.field = fakeField;
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
expect(widget.field.value).toBe(expectedFileId);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
|||||||
import { FormService } from '../../../services/form.service';
|
import { FormService } from '../../../services/form.service';
|
||||||
import { WidgetComponent } from '../widget.component';
|
import { WidgetComponent } from '../widget.component';
|
||||||
|
|
||||||
/* eslint-disable @angular-eslint/component-selector */
|
/* eslint-disable @angular-eslint/component-selector */
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'base-viewer-widget',
|
selector: 'base-viewer-widget',
|
||||||
@@ -44,12 +44,13 @@ export class BaseViewerWidgetComponent extends WidgetComponent implements OnInit
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
if (this.field &&
|
if (this.field?.value) {
|
||||||
this.field.value &&
|
if (Array.isArray(this.field.value) && this.field.value.length > 0) {
|
||||||
Array.isArray(this.field.value) &&
|
const file = this.field.value[0];
|
||||||
this.field.value.length) {
|
this.field.value = file.id;
|
||||||
const file = this.field.value[0];
|
} else if (typeof this.field.value === 'object' && this.field.value.id) {
|
||||||
this.field.value = file.id;
|
this.field.value = this.field.value.id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,10 +15,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
import { Component, ViewEncapsulation } from '@angular/core';
|
||||||
import { WidgetComponent, FormService } from '@alfresco/adf-core';
|
import { FormService, BaseViewerWidgetComponent } from '@alfresco/adf-core';
|
||||||
|
|
||||||
/* eslint-disable @angular-eslint/component-selector */
|
/* eslint-disable @angular-eslint/component-selector */
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'file-viewer-widget',
|
selector: 'file-viewer-widget',
|
||||||
@@ -37,18 +37,8 @@ import { WidgetComponent, FormService } from '@alfresco/adf-core';
|
|||||||
},
|
},
|
||||||
encapsulation: ViewEncapsulation.None
|
encapsulation: ViewEncapsulation.None
|
||||||
})
|
})
|
||||||
export class FileViewerWidgetComponent extends WidgetComponent implements OnInit {
|
export class FileViewerWidgetComponent extends BaseViewerWidgetComponent {
|
||||||
constructor(formService: FormService) {
|
constructor(formService: FormService) {
|
||||||
super(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -15,8 +15,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, EventEmitter, OnInit, Output, ViewEncapsulation } from '@angular/core';
|
import { Component, EventEmitter, Output, ViewEncapsulation } from '@angular/core';
|
||||||
import { FormService, WidgetComponent } from '@alfresco/adf-core';
|
import { BaseViewerWidgetComponent, FormService } from '@alfresco/adf-core';
|
||||||
import { Node } from '@alfresco/js-api';
|
import { Node } from '@alfresco/js-api';
|
||||||
|
|
||||||
/* eslint-disable @angular-eslint/component-selector */
|
/* eslint-disable @angular-eslint/component-selector */
|
||||||
@@ -38,7 +38,7 @@ import { Node } from '@alfresco/js-api';
|
|||||||
},
|
},
|
||||||
encapsulation: ViewEncapsulation.None
|
encapsulation: ViewEncapsulation.None
|
||||||
})
|
})
|
||||||
export class PropertiesViewerWidgetComponent extends WidgetComponent implements OnInit {
|
export class PropertiesViewerWidgetComponent extends BaseViewerWidgetComponent {
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
nodeContentLoaded: EventEmitter<Node> = new EventEmitter();
|
nodeContentLoaded: EventEmitter<Node> = new EventEmitter();
|
||||||
@@ -47,16 +47,6 @@ export class PropertiesViewerWidgetComponent extends WidgetComponent implements
|
|||||||
super(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onNodeContentLoaded(node: Node) {
|
onNodeContentLoaded(node: Node) {
|
||||||
this.nodeContentLoaded.emit(node);
|
this.nodeContentLoaded.emit(node);
|
||||||
}
|
}
|
||||||
|
@@ -15,10 +15,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { FormService, WidgetComponent } from '@alfresco/adf-core';
|
import { BaseViewerWidgetComponent, FormService } from '@alfresco/adf-core';
|
||||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
import { Component, ViewEncapsulation } from '@angular/core';
|
||||||
|
|
||||||
/* eslint-disable @angular-eslint/component-selector */
|
/* eslint-disable @angular-eslint/component-selector */
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'file-viewer-widget',
|
selector: 'file-viewer-widget',
|
||||||
@@ -37,18 +37,8 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
|||||||
},
|
},
|
||||||
encapsulation: ViewEncapsulation.None
|
encapsulation: ViewEncapsulation.None
|
||||||
})
|
})
|
||||||
export class FileViewerWidgetComponent extends WidgetComponent implements OnInit {
|
export class FileViewerWidgetComponent extends BaseViewerWidgetComponent {
|
||||||
constructor(formService: FormService) {
|
constructor(formService: FormService) {
|
||||||
super(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -226,4 +226,3 @@
|
|||||||
"module": "./index.js",
|
"module": "./index.js",
|
||||||
"typings": "./index.d.ts"
|
"typings": "./index.d.ts"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user