mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-26215 standalone form (cloud) (#10535)
This commit is contained in:
@@ -34,10 +34,6 @@ describe('AvatarComponent', () => {
|
||||
|
||||
const getAvatarImageElement = (): HTMLImageElement => fixture.nativeElement.querySelector('.adf-avatar__image');
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should display initials when src is not provided', () => {
|
||||
component.src = '';
|
||||
fixture.detectChanges();
|
||||
|
@@ -24,6 +24,8 @@ import { FormFieldModel, FormFieldValidator, FormModel, FormOutcomeEvent, FormOu
|
||||
})
|
||||
// eslint-disable-next-line @angular-eslint/directive-class-suffix
|
||||
export abstract class FormBaseComponent {
|
||||
protected _form: FormModel;
|
||||
|
||||
static SAVE_OUTCOME_ID: string = '$save';
|
||||
static COMPLETE_OUTCOME_ID: string = '$complete';
|
||||
static START_PROCESS_OUTCOME_ID: string = '$startProcess';
|
||||
@@ -96,7 +98,27 @@ export abstract class FormBaseComponent {
|
||||
@Output()
|
||||
error = new EventEmitter<any>();
|
||||
|
||||
form: FormModel;
|
||||
/**
|
||||
* Custom style that is backed by the form.theme.
|
||||
*/
|
||||
formStyle: string = '';
|
||||
|
||||
get form(): FormModel {
|
||||
return this._form;
|
||||
}
|
||||
|
||||
/** Underlying form model instance. */
|
||||
@Input()
|
||||
set form(form: FormModel) {
|
||||
this._form = form;
|
||||
|
||||
if (form) {
|
||||
const theme = form.theme?.form;
|
||||
this.formStyle = theme ? this.flattenStyles(theme) : '';
|
||||
} else {
|
||||
this.formStyle = '';
|
||||
}
|
||||
}
|
||||
|
||||
getParsedFormDefinition(): FormBaseComponent {
|
||||
return this;
|
||||
@@ -226,4 +248,10 @@ export abstract class FormBaseComponent {
|
||||
protected abstract storeFormAsMetadata(): void;
|
||||
|
||||
protected abstract onExecuteOutcome(outcome: FormOutcomeModel): boolean;
|
||||
|
||||
private flattenStyles(styles: { [key: string]: string }): string {
|
||||
return Object.entries(styles)
|
||||
.map(([key, value]) => `${key}: ${value}`)
|
||||
.join(';');
|
||||
}
|
||||
}
|
||||
|
@@ -47,3 +47,4 @@ export * from './form-field-variable-options';
|
||||
export * from './widget-schema.model';
|
||||
export * from './theme.model';
|
||||
export * from './predefined-theme';
|
||||
export * from './displayable-cm-properties.model';
|
||||
|
@@ -57,7 +57,7 @@ export * from './text/text-mask.component';
|
||||
export * from './display-text';
|
||||
export * from './header';
|
||||
|
||||
export const WIDGET_DIRECTIVES: any[] = [
|
||||
export const WIDGET_DIRECTIVES = [
|
||||
UnknownWidgetComponent,
|
||||
TextWidgetComponent,
|
||||
NumberWidgetComponent,
|
||||
@@ -72,6 +72,6 @@ export const WIDGET_DIRECTIVES: any[] = [
|
||||
DateTimeWidgetComponent,
|
||||
JsonWidgetComponent,
|
||||
BaseViewerWidgetComponent
|
||||
];
|
||||
] as const;
|
||||
|
||||
export const MASK_DIRECTIVE: any[] = [InputMaskDirective];
|
||||
export const MASK_DIRECTIVE = [InputMaskDirective] as const;
|
||||
|
@@ -1,47 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* 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 { FormStylePipe } from './form-style.pipe';
|
||||
import { ThemeModel } from '../components/widgets/core/theme.model';
|
||||
|
||||
describe('FormStylePipe', () => {
|
||||
let pipe: FormStylePipe;
|
||||
|
||||
beforeEach(() => {
|
||||
pipe = new FormStylePipe();
|
||||
});
|
||||
|
||||
it('should transform form theme into styles', () => {
|
||||
const formTheme: ThemeModel = {
|
||||
form: {
|
||||
'--adf-form-label-font-size': '16px',
|
||||
'--adf-form-label-color': 'black',
|
||||
'--adf-form-label-font-weight': 'bold'
|
||||
}
|
||||
};
|
||||
|
||||
const result = pipe.transform(formTheme);
|
||||
|
||||
expect(result).toEqual('--adf-form-label-font-size: 16px;--adf-form-label-color: black;--adf-form-label-font-weight: bold');
|
||||
});
|
||||
|
||||
it('should return an empty string if form theme is undefined', () => {
|
||||
const result = pipe.transform(undefined);
|
||||
|
||||
expect(result).toEqual('');
|
||||
});
|
||||
});
|
@@ -1,36 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* 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 { Pipe, PipeTransform } from '@angular/core';
|
||||
import { ThemeModel } from '../components/widgets/core/theme.model';
|
||||
|
||||
@Pipe({
|
||||
name: 'adfFormStyle',
|
||||
standalone: true
|
||||
})
|
||||
export class FormStylePipe implements PipeTransform {
|
||||
transform(formTheme?: ThemeModel): string {
|
||||
const theme = formTheme?.form;
|
||||
return theme ? this.flattenStyles(theme) : '';
|
||||
}
|
||||
|
||||
private flattenStyles(styles: { [key: string]: string }): string {
|
||||
return Object.entries(styles)
|
||||
.map(([key, value]) => `${key}: ${value}`)
|
||||
.join(';');
|
||||
}
|
||||
}
|
@@ -16,4 +16,3 @@
|
||||
*/
|
||||
|
||||
export * from './field-style.pipe';
|
||||
export * from './form-style.pipe';
|
||||
|
@@ -38,10 +38,6 @@ describe('NavbarItemComponent', () => {
|
||||
button = fixture.nativeElement.querySelector('.adf-navbar-item-btn');
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should display label', () => {
|
||||
fixture.detectChanges();
|
||||
expect(button.textContent).toContain('Test Label');
|
||||
|
@@ -40,10 +40,6 @@ describe('ProgressComponent', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should default to bar variant and indeterminate mode', () => {
|
||||
expect(component.variant).toBe('bar');
|
||||
expect(component.mode).toBe('indeterminate');
|
||||
|
Reference in New Issue
Block a user