debugging...

This commit is contained in:
Maria Teresa Paratore 2024-03-21 17:26:30 +01:00
parent 172d53b28c
commit 82a8a19541
2 changed files with 43 additions and 49 deletions

View File

@ -19,9 +19,8 @@
<div formArrayName="facets">
<div [formGroupName] ="ind" *ngFor="let fct of facetArray.controls; let ind=index;" style="border: 3px solid rgb(72, 157, 202); padding: 10px; margin: 5px;">
<p><b>facet {{ind}}</b></p>
<mat-form-field appearance="outline" >
<input matInput formControlName="name" [style.width.px]="300" id="{{typeSpec.facetSpecs[ind].name}}" type="text" [readonly]="true" style="font-size: larger; font-weight: 700;" />
<input matInput formControlName="name" [style.width.px]="350" id="{{typeSpec.facetSpecs[ind].name}}" type="text" [readonly]="true" style="font-size: large; font-weight: 700;" />
</mat-form-field>
<mat-form-field>
<mat-label for="relation" >occurr. min</mat-label>
@ -56,31 +55,23 @@
</div>
</div>
<div style="padding-top: 20px; padding-bottom: 8px; margin: 5px;">
<button mat-icon-button color="primary" [disabled]="typeSpec.facetSpecs[ind].min==='1'"
<button mat-icon-button color="primary"
[disabled]="typeSpec.facetSpecs[ind].min==='1'"
(click)="removeFacet(ind)" matTooltip="remove" matTooltipClass="tableTooltip"
matTooltipPosition="above"><mat-icon>delete_outline</mat-icon></button>
</div>
</div>
</div>
<div style="padding-top: 20px; padding-bottom: 8px; margin: 5px;">
<!--
<button mat-icon-button color="primary"
(click)="addFacet(typeSpec.facetSpecs[0].name+'_'+typeSpec.facetSpecs[0].relation)" matTooltip="add new" matTooltipClass="tableTooltip"
matTooltipPosition="above"><mat-icon>add</mat-icon>add new facet</button>
-->
<!--
<button style="padding: 5px; margin-left:5px;" mat-raised-button color="primary" (click)="addFacet(typeSpec.facetSpecs[0].name+'_'+typeSpec.facetSpecs[0].relation)">
<mat-icon>add</mat-icon><span> Add Facet </span>
</button>
-->
<h3>Add new Facet:</h3>
<div style="padding-top: 24px; padding-bottom: 24px;">
<mat-form-field appearance="outline" [style.width.px]="250">
<mat-label for="selFacet" >Available Facet Types</mat-label>
<!--<select #teams (change)="onSelected(teams.value)">
(change)='onOptionsSelected(mySelect.value)'-->
<mat-select #selFacet (change)="onOptionsSelected(selFacet.value)">
<mat-select #selFacet (valueChange)="onOptionsSelected($event)">
<mat-option *ngFor="let item of addableFacets" [value]="item">
{{item}}
</mat-option>
@ -94,9 +85,6 @@
</div>
</div>
<!-- <button mat-button (click)="doAction()">Save Form</button> -->
<!--</form>-->
<!--fine form esterna-->
<b>Form's Value:</b>
{{ myForm.value | json }}

View File

@ -40,6 +40,7 @@ export class FacetComposerComponent implements OnInit {
// facetData: IFacetComposer[];
typeSpec: ITypeSpecification;
fieldsMap: Map<string, IFacetComposer>;
counterMap: Map<string, number>;
addableFacets: string[];
defaultProperty = {
@ -75,25 +76,19 @@ export class FacetComposerComponent implements OnInit {
this.titleType = data.type.name;
this.titlePath = data.context.path;
this.selectedOption = '';
// this.facetData = [];
this.typeSpec = {} as ITypeSpecification;
this.fieldsMap = new Map<string,IFacetComposer>();
this.counterMap = new Map<string,number>();
this.myForm = this.fb.group({
facets: new FormArray([
])
});
this.addableFacets = [];
/*
this.propertyGroup = new FormGroup({
properties: new FormArray([]),
});
*/
}
}
removeGroup(i: number) {
// remove address from the list
const control = <FormArray>this.myForm.controls['times'];
control.removeAt(i);
const control = <FormArray>this.myForm.controls['times'];
control.removeAt(i);
}
@ -102,6 +97,8 @@ export class FacetComposerComponent implements OnInit {
this.typeSpec = res;
//attenzione allo spazio prima della parentesi
this.fieldsMap = new Map(res.facetSpecs.map((obj) => [obj.name+' ('+obj.relation+')', obj]));
//parto con una facet per tipo
this.counterMap = new Map(res.facetSpecs.map((obj) => [obj.name+'_'+obj.relation, 1]));
/*
this.fieldsMap.forEach(function(value,key){
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
@ -135,7 +132,7 @@ export class FacetComposerComponent implements OnInit {
onOptionsSelected(value:string): void {
this.selectedOption = value;
console.debug('******onOptionsSelected?...'+value);
//console.debug('******onOptionsSelected?...'+value);
}
//TODO: NOTA BENE--> FormGroup->access by NAME, FormArray->access by INDEX!!
@ -200,14 +197,12 @@ export class FacetComposerComponent implements OnInit {
facetFg.addControl('relation', relationFc);
//1. creo formArray con le properties
//const propertiesFa = this.createPropertyArray(item.guiProps);
const propertiesFa = this.fb.array([]);
for(let j=0; j<item.guiProps.length; j++){
this.createPropertyArray(item.guiProps[j],propertiesFa);
}
//2. aggiungo formarray delle properties ai controls per la facet
facetFg.addControl('properties',propertiesFa);
//TODO
this.facetArray.push(facetFg);
}
@ -232,11 +227,6 @@ export class FacetComposerComponent implements OnInit {
this.myForm.reset();
}
/*To update form values programmatically, use the patchValue() or setValue() methods:*/
updateFormValues() {
this.myForm.patchValue({ name: 'John' });
}
///////////////////////////////
private addFacetGroup(): FormGroup {
@ -247,13 +237,10 @@ export class FacetComposerComponent implements OnInit {
}
//TODO: ADD DEFAULT FACET (usa json: defaultFacet)
addFacet(nameplus:string): void {
alert(nameplus)
// this.facetArray.push(this.addFacetGroup());
//this.createFacetGroup(this.facetData[ind]);
const icf: IFacetComposer = <IFacetComposer>this.fieldsMap.get(nameplus);
const icf: IFacetComposer = <IFacetComposer>this.fieldsMap.get(nameplus);
//TODO CHECK THIS
this.typeSpec.facetSpecs.push(icf);
const facetFg: FormGroup = this.fb.group({});
const nameFc = this.fb.control(icf.name);
@ -262,17 +249,22 @@ export class FacetComposerComponent implements OnInit {
const maxFc = this.fb.control(icf.max);
facetFg.addControl('max', maxFc);
const minFc = this.fb.control(icf.min);
//ogni facet aggiunta può essere rimossa
const minFc = this.fb.control('many');
facetFg.addControl('min', minFc);
const descriptionFc = this.fb.control(icf.description);
facetFg.addControl('description', descriptionFc);
//aggiorno il counter
/*
let oldCounter = this.counterMap.get(icf.name+'_'+icf.relation)!;
this.counterMap.set(icf.name+'_'+icf.relation,oldCounter++);
*/
const relationFc = this.fb.control(icf.relation,Validators.required);
facetFg.addControl('relation', relationFc);
//1. creo formArray con le properties
//const propertiesFa = this.createPropertyArray(item.guiProps);
const propertiesFa = this.fb.array([]);
for(let j=0; j<icf.guiProps.length; j++){
this.createPropertyArray(icf.guiProps[j],propertiesFa);
@ -280,13 +272,27 @@ export class FacetComposerComponent implements OnInit {
//2. aggiungo formarray delle properties ai controls per la facet
facetFg.addControl('properties',propertiesFa);
//Aggiunge in ultima posizione nel'array
this.facetArray.push(facetFg);
this.facetArray.push(facetFg);
}
/*
checkIfRemovable(facetSpec:IFacetComposer):boolean{
// TODO: AGGIUSTARE QUA
const check2 = (this.counterMap.get(facetSpec.name+'_'+facetSpec.relation)!)>1;
if (facetSpec.min==='1' && (this.counterMap.get(facetSpec.name+'_'+facetSpec.relation)!)===1){
return true;
} else {
return false;
}
}
*/
removeFacet(index: number): void {
const controls: FormArray = <FormArray>this.myForm.controls['facets'];
controls.removeAt(index);
this.facetArray.removeAt(index)
this.facetArray.removeAt(index);
this.typeSpec.facetSpecs.splice(index,1);
/*
for(let j=0; j<this.facetData[index].guiProps.length; j++){