Skip to content

Commit

Permalink
Story #13135 (pastis): add "comment" on regex
Browse files Browse the repository at this point in the history
  • Loading branch information
marob committed Jul 30, 2024
1 parent 1f7ae92 commit cca28e9
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public enum PuaAttributes {
REF("$ref"),
ENUM("enum"),
PATTERN("pattern"),
PATTERN_DESCRIPTION("patternDescription"),
MIN_LENGTH("minLength"),
MAX_LENGTH("maxLength"),
MINIMUM("minimum"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class PuaData implements Serializable {
Boolean additionalProperties;
List<String> Enum;
String pattern;
String patternDescription;
Integer minLength;
Integer maxLength;
Integer minimum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class PuaMetadataDetails {
List<String> enums;

String pattern;
String patternDescription;

public String serialiseString() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,6 @@ private ElementProperties getElementProperties(
addPuaDataToElementIfNotPresent(childProfile);
childProfile.getPuaData().setPattern(childPua.getString(k));
break;
case PATTERN_DESCRIPTION:
addPuaDataToElementIfNotPresent(childProfile);
childProfile.getPuaData().setPatternDescription(childPua.getString(k));
break;
case MIN_LENGTH:
addPuaDataToElementIfNotPresent(childProfile);
childProfile.getPuaData().setMinLength(childPua.getInt(k));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1050,9 +1050,6 @@ public void getMetaDataFromSeda(ElementProperties el, PuaMetadataDetails puaMeta
getMinAndMAxItems(el, puaMetadataDetails);
}
Optional.ofNullable(el.getPuaData()).map(PuaData::getPattern).ifPresent(puaMetadataDetails::setPattern);
Optional.ofNullable(el.getPuaData())
.map(PuaData::getPatternDescription)
.ifPresent(puaMetadataDetails::setPatternDescription);
if (el.getPuaData() != null && el.getPuaData().getEnum() != null) {
puaMetadataDetails.setEnums(el.getPuaData().getEnum());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
{
"additionalProperties": false,
"pattern": null,
"patternDescription": null,
"minLength": null,
"maxLength": null,
"minimum": null,
Expand Down Expand Up @@ -146,7 +145,6 @@
{
"additionalProperties": null,
"pattern": null,
"patternDescription": null,
"minLength": null,
"maxLength": null,
"minimum": null,
Expand Down Expand Up @@ -272,7 +270,6 @@
{
"additionalProperties": false,
"pattern": null,
"patternDescription": null,
"minLength": null,
"maxLength": null,
"minimum": null,
Expand Down Expand Up @@ -325,7 +322,6 @@
{
"additionalProperties": false,
"pattern": null,
"patternDescription": null,
"minLength": null,
"maxLength": null,
"minimum": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@
"puaData": {
"additionalProperties": false,
"pattern": null,
"patternDescription": null,
"minLength": null,
"maxLength": null,
"minimum": null,
Expand Down Expand Up @@ -204,7 +203,6 @@
"puaData": {
"additionalProperties": null,
"pattern": null,
"patternDescription": null,
"minLength": null,
"maxLength": null,
"minimum": null,
Expand Down Expand Up @@ -318,7 +316,6 @@
"puaData": {
"additionalProperties": false,
"pattern": null,
"patternDescription": null,
"minLength": null,
"maxLength": null,
"minimum": null,
Expand Down Expand Up @@ -366,7 +363,6 @@
"puaData": {
"additionalProperties": false,
"pattern": null,
"patternDescription": null,
"minLength": null,
"maxLength": null,
"minimum": null,
Expand Down
1 change: 0 additions & 1 deletion ui/ui-frontend/projects/pastis/src/app/models/pua-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export interface PuaData {
additionalProperties?: boolean;
enum?: string[];
pattern?: string;
patternDescription?: string;
minLength?: number;
maxLength?: number;
minimum?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ <h5>
</td>
</ng-container>

<!-- Commnent Column -->
<!-- Comment Column -->
<ng-container matColumnDef="commentaire">
<th *matHeaderCellDef class="pastis-font-table-header pastis-col" mat-header-cell>
{{ 'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA.COMMENTAIRE' | translate }}
Expand All @@ -190,6 +190,7 @@ <h5>
[maxlength]="120"
[ngModel]="element.commentaire"
class="commentaire-pastis"
[required]="hasCustomRegex(element)"
>
</vitamui-common-editable-textarea>
</div>
Expand Down Expand Up @@ -291,7 +292,7 @@ <h5>
<span class="text normal">{{ 'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA.SUPPRIMER' | translate }}</span>
</button>

<!-- Contrôle de métadonées => PUA -->
<!-- Contrôle de métadonnées => PUA -->
<mat-divider
*ngIf="
this.profileService.profileMode === 'PUA' &&
Expand All @@ -316,7 +317,7 @@ <h5>
<span class="text normal">{{ 'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA.CONTROLE_METADONNEE' | translate }}</span>
</button>

<!-- Edition des contres de nétadonnées -->
<!-- Edition des contres de métadonnées -->
<mat-divider
*ngIf="
this.profileService.profileMode === 'PUA' &&
Expand Down Expand Up @@ -443,6 +444,7 @@ <h2 class="pastis-dialog-config-title" matDialogTitle>
disableRipple="true"
panelClass="vitamui-mat-select"
[(value)]="regex"
(selectionChange)="radioExpressionReguliere = 'select'"
>
<mat-option *ngFor="let predefiniElement of availableRegex" [value]="predefiniElement.value">
{{ predefiniElement.label }}
Expand Down Expand Up @@ -477,6 +479,7 @@ <h2 class="pastis-dialog-config-title" matDialogTitle>
[disabled]="isNotRegexCustomisable()"
[placeholder]="'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA.SAISIR_EXPRESSION' | translate"
[(ngModel)]="customRegex"
(ngModelChange)="radioExpressionReguliere = 'input'"
[required]="true"
>
</vitamui-common-textarea>
Expand All @@ -485,9 +488,9 @@ <h2 class="pastis-dialog-config-title" matDialogTitle>
<vitamui-common-textarea
[disabled]="isNotRegexCustomisable()"
[placeholder]="'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA.PATTERN_COMMENT' | translate"
[(ngModel)]="patternDescription"
[(ngModel)]="commentaire"
[required]="true"
[maxlength]="115"
[maxlength]="120"
>
</vitamui-common-textarea>
</div>
Expand All @@ -504,7 +507,7 @@ <h2 class="pastis-dialog-config-title" matDialogTitle>
*ngIf="(enumerationControl || expressionControl) && clickedControl.name === clickedNode.name"
[disabled]="
(this.enumsControlSelected.length <= 0 && regex === null && customRegex === null) ||
(radioExpressionReguliere === 'input' && (!customRegex || !patternDescription))
(radioExpressionReguliere === 'input' && (!customRegex || !commentaire))
"
class="btn primary ml-5"
style="text-transform: uppercase"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ button.delete {
}

.pastis-vitamui-container-editable-commentaire {
width: 203px;
height: 50px;
position: relative;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ export class FileTreeMetadataComponent implements OnInit, OnDestroy {
radioExpressionReguliere: 'select' | 'input';
regex: string;
customRegex: string;
patternDescription: string;
formatagePredefini: Array<{ label: string; value: 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}$' },
Expand Down Expand Up @@ -424,11 +423,11 @@ export class FileTreeMetadataComponent implements OnInit, OnDestroy {

setDocumentation(metadata: MetadataHeaders, comment: string) {
if (this.clickedNode.name === metadata.nomDuChamp && this.clickedNode.id === metadata.id) {
comment ? (this.clickedNode.documentation = comment) : (this.clickedNode.documentation = null);
this.clickedNode.documentation = comment || null;
} else {
for (const node of this.clickedNode.children) {
if (node.name === metadata.nomDuChamp && node.id === metadata.id) {
comment ? (node.documentation = comment) : (node.documentation = null);
node.documentation = comment || null;
}
}
}
Expand Down Expand Up @@ -553,7 +552,7 @@ export class FileTreeMetadataComponent implements OnInit, OnDestroy {
console.log('The answer for arrays control was ', popUpAnswer);
if (popUpAnswer) {
this.arrayControl = popUpAnswer;
this.setControlsVues(this.arrayControl, popData.fileNode.name);
this.setControlsVues(this.arrayControl, popData.fileNode);
this.openControls = true;
}
}
Expand All @@ -569,8 +568,6 @@ export class FileTreeMetadataComponent implements OnInit, OnDestroy {
this.editedEnumControl = [];
this.enumsControlSelected = [];
this.openControls = true;
const type: string = this.selectedSedaNode.Type;
this.setAvailableRegex(type);
fileNode.puaData.enum.forEach((e) => {
this.editedEnumControl.push(e);
this.enumsControlSelected.push(e);
Expand All @@ -580,19 +577,17 @@ export class FileTreeMetadataComponent implements OnInit, OnDestroy {
const actualPattern = fileNode.puaData.pattern;
this.openControls = true;
this.expressionControl = true;
if (this.formatagePredefini.map((e) => e.value).includes(actualPattern)) {
const type: string = this.selectedSedaNode.Type;
this.setAvailableRegex(type);
this.commentaire = fileNode.documentation;
this.setAvailableRegex(this.selectedSedaNode.Type);
if (this.availableRegex.map((e) => e.value).includes(actualPattern)) {
this.regex = this.availableRegex.filter((e) => e.value === actualPattern).map((e) => e.value)[0];
this.radioExpressionReguliere = 'select';
} else {
this.customRegex = actualPattern;
this.patternDescription = fileNode.puaData.patternDescription;
this.radioExpressionReguliere = 'input';
}
} else {
this.customRegex = '';
this.patternDescription = '';
}
}

Expand All @@ -604,6 +599,17 @@ export class FileTreeMetadataComponent implements OnInit, OnDestroy {
return !!(fileNode.puaData && fileNode.puaData.pattern);
}

hasCustomRegex(element: MetadataHeaders): boolean {
const fileNode = this.fileService.getFileNodeById(this.fileService.nodeChange.getValue(), element.id);
const actualPattern = fileNode?.puaData?.pattern;
return (
actualPattern &&
!this.getAvailableRegex(fileNode?.sedaData?.Type)
.map((e) => e.value)
.includes(actualPattern)
);
}

resetControls() {
this.arrayControl = [];
this.enumerationControl = false;
Expand All @@ -615,24 +621,23 @@ export class FileTreeMetadataComponent implements OnInit, OnDestroy {
this.openControls = false;
this.regex = undefined;
this.customRegex = undefined;
this.patternDescription = undefined;
this.enumerationsSedaControl = [];
}

private setAvailableRegex(type: string) {
this.availableRegex = this.getAvailableRegex(type);
}

private getAvailableRegex(type: string): Array<{ label: string; value: string }> {
switch (type) {
case DateFormatType.date:
this.availableRegex = this.formatagePredefini.filter((e) => e.label === 'AAAA-MM-JJ');
break;
return this.formatagePredefini.filter((e) => e.label === 'AAAA-MM-JJ');
case DateFormatType.dateTime:
this.availableRegex = this.formatagePredefini.filter((e) => e.label === 'AAAA-MM-JJTHH:MM:SS');
break;
return this.formatagePredefini.filter((e) => e.label === 'AAAA-MM-JJTHH:MM:SS');
case DateFormatType.dateType:
this.availableRegex = this.formatagePredefini;
break;
return this.formatagePredefini;
default:
this.availableRegex = this.formatagePredefini.filter((e) => e.label === 'AAAA-MM-JJ' || e.label === 'AAAA');
break;
return this.formatagePredefini.filter((e) => e.label === 'AAAA-MM-JJ' || e.label === 'AAAA');
}
}

Expand All @@ -641,7 +646,8 @@ export class FileTreeMetadataComponent implements OnInit, OnDestroy {
return type === DateFormatType.date || type === DateFormatType.dateTime || type === DateFormatType.dateType;
}

setControlsVues(elements: string[], sedaName: string) {
private setControlsVues(elements: string[], fileNode: FileNode) {
const sedaName = fileNode.name;
if (elements.includes('Enumération') || elements.includes(this.translated(ADD_PUA_CONTROL_TRANSLATE_PATH + '.ENUMERATIONS_LABEL'))) {
this.enumerationControl = true;

Expand All @@ -658,7 +664,7 @@ export class FileTreeMetadataComponent implements OnInit, OnDestroy {
this.radioExpressionReguliere = 'select';
this.expressionControl = true;
this.customRegex = '';
this.patternDescription = '';
this.commentaire = fileNode.documentation;
const type: string = this.sedaService.findSedaChildByName(sedaName, this.selectedSedaNode).Type;
this.setAvailableRegex(type);
this.regex = this.formatagePredefini[0].value;
Expand Down Expand Up @@ -868,7 +874,11 @@ export class FileTreeMetadataComponent implements OnInit, OnDestroy {
}

this.clickedControl.puaData.pattern = this.radioExpressionReguliere === 'select' ? this.regex : this.customRegex;
this.clickedControl.puaData.patternDescription = this.radioExpressionReguliere === 'select' ? '' : this.patternDescription;
if (this.radioExpressionReguliere === 'input') {
this.clickedControl.documentation = this.commentaire;
const item = this.matDataSource.data.find((d) => d.id === this.clickedControl.id);
if (item) item.commentaire = this.commentaire; // Force la mise à jour du commentaire dans le matTable
}
}

onDeleteControls() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<label>{{ label }}</label>
<span class="editable-field-text-content display-all">{{ control?.value }}</span>
<div class="editable-field-control">
<textarea [formControl]="control" [maxlength]="maxlength" rows="3" #input></textarea>
<textarea [formControl]="control" [maxlength]="maxlength" [required]="required" rows="3" #input></textarea>
</div>
</div>
<i *ngIf="!showSpinner && !editMode" class="material-icons edit-icon">edit</i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { Component, ElementRef, forwardRef, Input, ViewChild } from '@angular/co
import { NG_VALUE_ACCESSOR } from '@angular/forms';

import { EditableFieldComponent } from '../editable-field.component';
import { coerceBooleanProperty } from '@angular/cdk/coercion';

export const EDITABLE_TEXTAREA_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
Expand All @@ -53,6 +54,7 @@ export const EDITABLE_TEXTAREA_VALUE_ACCESSOR: any = {
})
export class EditableTextareaComponent extends EditableFieldComponent {
@Input() maxlength: number;
@Input({ transform: coerceBooleanProperty }) required = false;
@ViewChild('input') private input: ElementRef;

constructor(elementRef: ElementRef) {
Expand Down

0 comments on commit cca28e9

Please sign in to comment.