Skip to content

Commit

Permalink
bug #13500 : wrong regex error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Hassane Diaby committed Oct 21, 2024
1 parent 07a882d commit 767e862
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { FileTreeService } from '../file-tree/file-tree.service';
import { AttributesPopupComponent } from './attributes/attributes.component';
import { FileTreeMetadataService } from './file-tree-metadata.service';
import { filter, map, tap } from 'rxjs/operators';
import { Logger } from 'vitamui-library';
import { DatePatternConstants, Logger } from 'vitamui-library';
import { BreadcrumbService } from '../../../core/services/breadcrumb.service';

const FILE_TREE_METADATA_TRANSLATE_PATH = 'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA';
Expand Down Expand Up @@ -125,10 +125,10 @@ export class FileTreeMetadataComponent implements OnInit, OnDestroy {
regex: string;
customRegex: string;
private formatagePredefini: Array<{ label: string; value: string }> = [
{ label: 'AAAA-MM-JJ', value: '^[0-9]{4}-[0-9]{2}-[0-9]{2}$' },
{ label: 'AAAA-MM-JJTHH:MM:SS', value: '^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$' },
{ label: 'AAAA', value: '^[0-9]{4}$' },
{ label: 'AAAA-MM', value: '^[0-9]{4}-[0-9]{2}$' },
{ label: 'AAAA-MM-JJ', value: DatePatternConstants.YEAR_MONTH_DAY },
{ label: 'AAAA-MM-JJTHH:MM:SS', value: DatePatternConstants.FULL_DATE },
{ label: 'AAAA', value: DatePatternConstants.YEAR },
{ label: 'AAAA-MM', value: DatePatternConstants.YEAR_MONTH },
];
availableRegex: Array<{ label: string; value: string }>;
public breadcrumbDataTop: Array<BreadcrumbDataTop>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ export const customTemplate: DisplayRule[] = [
Path: 'Version',
ui: {
Path: 'Generalities.Characteristics.Version',
component: 'textfield',
layout: {
columns: 1,
size: 'small',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@import '../../../../sass/variables/colors';

:host {
font-size: 12px;
font-weight: 400;
width: 100%;
color: $red;
display: flex;
align-items: center;
padding: 5px 0 0 0;

i {
font-size: 12px;
margin-right: 5px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum DatePatternConstants {
YEAR = '^[0-9]{4}$',
YEAR_MONTH = '^[0-9]{4}-[0-9]{2}$',
YEAR_MONTH_DAY = '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
FULL_DATE = '^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$',
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*ngSwitchCase="'datepicker'"
[formControl]="editObject.control"
[label]="editObject.displayRule.ui.label | translate | empty | appendStar: editObject.required"
pickerType="day"
[pickerType]="getPickerType(editObject)"
>
<vitamui-editor-hint [control]="editObject.control" [hint]="editObject.hint"></vitamui-editor-hint>
<vitamui-form-error-display [control]="editObject.control"></vitamui-form-error-display>
Expand All @@ -36,7 +36,7 @@
*ngSwitchCase="'datetime'"
[formControl]="editObject.control"
[label]="editObject.displayRule.ui.label | translate | empty | appendStar: editObject.required"
pickerType="day"
[pickerType]="getPickerType(editObject)"
>
<vitamui-editor-hint [control]="editObject.control" [hint]="editObject.hint"></vitamui-editor-hint>
<vitamui-form-error-display [control]="editObject.control"></vitamui-form-error-display>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DateDisplayService } from '../../../object-viewer/services/date-display
import { ComponentType } from '../../../object-viewer/types';
import { EditObject } from '../../models/edit-object.model';
import { FormControl } from '@angular/forms';
import { DatePatternConstants } from '../../../dates.constants';

@Component({
selector: 'vitamui-common-primitive-editor',
Expand All @@ -30,4 +31,17 @@ export class PrimitiveEditorComponent implements OnInit {
}

protected readonly FormControl = FormControl;

getPickerType(editObject: EditObject) {
if (editObject.pattern) {
if (editObject.pattern === DatePatternConstants.YEAR) {
return 'year';
} else if (editObject.pattern === DatePatternConstants.YEAR_MONTH_DAY) {
return 'day';
} else if (editObject.pattern === DatePatternConstants.YEAR_MONTH) {
return 'month';
}
}
return 'day';
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { DisplayRule, ProfiledSchemaElement, SchemaElement } from '../models';
import { LayoutSize } from '../types';
import { DatePatternConstants } from '../../dates.constants';

type ComponentName =
| 'balise-n1'
Expand Down Expand Up @@ -184,6 +185,24 @@ export class SchemaElementToDisplayRuleService {
const isSpecial = schemaElement.Path.includes('_.');
const isSelect = (schemaElement as ProfiledSchemaElement).Control?.Type === 'SELECT' || false;

const control = (schemaElement as ProfiledSchemaElement).Control;

if (control) {
if (
control.Type === 'REGEX' &&
[
DatePatternConstants.YEAR.toString(),
DatePatternConstants.YEAR_MONTH.toString(),
DatePatternConstants.YEAR_MONTH_DAY.toString(),
DatePatternConstants.FULL_DATE.toString(),
].includes(control.Value)
) {
return 'datepicker-date';
} else {
return defaultComponent;
}
}

if (isSelect && isUnique) return 'select-mono';
if (isSelect && isMultiple) return 'select-multi';

Expand Down
1 change: 1 addition & 0 deletions ui/ui-frontend/projects/vitamui-library/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,4 @@ export * from './app/modules/subrogation/subrogation-banner/subrogation-banner.c
export * from './app/modules/subrogation/subrogation.module';
export * from './app/modules/object-viewer/services/type.service';
export * from './app/modules/object-editor/pattern.validator';
export * from './app/modules/dates.constants';

0 comments on commit 767e862

Please sign in to comment.