+ class="adf-viewer-render-main"
+ fxFlexOrder="1"
+ fxFlex="1 1 auto">
@@ -17,7 +19,9 @@
+ class="adf-viewer-render-main"
+ fxFlexOrder="1"
+ fxFlex="1 1 auto">
@@ -37,6 +41,7 @@
[urlFile]="urlFile"
[fileName]="fileName"
[cacheType]="cacheTypeForContent"
+ (close)="onClose()"
(error)="onUnsupportedFile()">
@@ -44,6 +49,7 @@
();
@@ -107,6 +106,10 @@ export class ViewerRenderComponent implements OnChanges, OnInit, OnDestroy {
@Output()
submitFile = new EventEmitter();
+ /** Emitted when the img is submitted in the img viewer. */
+ @Output()
+ close = new EventEmitter();
+
extensionTemplates: { template: TemplateRef; isVisible: boolean }[] = [];
extension: string;
@@ -200,4 +203,8 @@ export class ViewerRenderComponent implements OnChanges, OnInit, OnDestroy {
this.viewerType = 'unknown';
}
+ onClose() {
+ this.close.next(true);
+ }
+
}
diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.html b/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.html
new file mode 100644
index 0000000000..00c6489b02
--- /dev/null
+++ b/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.html
@@ -0,0 +1,7 @@
+
diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.scss b/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.scss
new file mode 100644
index 0000000000..4af97c452d
--- /dev/null
+++ b/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.scss
@@ -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;
+ }
+ }
+ }
+ }
+}
diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.spec.ts
new file mode 100644
index 0000000000..01f77baa19
--- /dev/null
+++ b/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.spec.ts
@@ -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;
+ let fixture: ComponentFixture;
+
+ 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();
+ });
+ });
+});
diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.ts
new file mode 100644
index 0000000000..b0b1b672aa
--- /dev/null
+++ b/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.ts
@@ -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;
+ }
+ }
+}