debugging new facets creation
This commit is contained in:
parent
82a8a19541
commit
c49a558f05
|
@ -30,6 +30,12 @@
|
|||
<mat-label for="relation" >occurr. max</mat-label>
|
||||
<input matInput formControlName="max" id="max" type="text" readonly="true"/>
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-label for="'counter_'+typeSpec.facetSpecs[ind].name+'_'+typeSpec.facetSpecs[ind].relation" >counter (hide)</mat-label>
|
||||
<input matInput formControlName="{{'counter_'+typeSpec.facetSpecs[ind].name+'_'+typeSpec.facetSpecs[ind].relation}}"
|
||||
id="{{'counter_'+typeSpec.facetSpecs[ind].name+'_'+typeSpec.facetSpecs[ind].relation}}" type="number"
|
||||
readonly="true"/>
|
||||
</mat-form-field>
|
||||
<div style="border: 1px solid rgb(202, 202, 202); padding: 10px; margin: 5px;">
|
||||
<textarea matInput formControlName="description" [readonly]="true">{{typeSpec.facetSpecs[ind].description}}</textarea>
|
||||
</div>
|
||||
|
@ -53,12 +59,11 @@
|
|||
type="{{typeSpec.facetSpecs[ind].guiProps[i].type}}"/>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!--(counterMap.get(typeSpec.facetSpecs[ind].name+'_'+typeSpec.facetSpecs[ind].relation)!)-->
|
||||
<div style="padding-top: 20px; padding-bottom: 8px; margin: 5px;">
|
||||
<button mat-icon-button color="primary"
|
||||
[disabled]="typeSpec.facetSpecs[ind].min==='1'"
|
||||
[disabled]="typeSpec.facetSpecs[ind].min==='1' && ((counterMap.get(typeSpec.facetSpecs[ind].name+'_'+typeSpec.facetSpecs[ind].relation)!)==1)"
|
||||
(click)="removeFacet(ind)" matTooltip="remove" matTooltipClass="tableTooltip"
|
||||
matTooltipPosition="above"><mat-icon>delete_outline</mat-icon></button>
|
||||
</div>
|
||||
|
@ -78,7 +83,8 @@
|
|||
</mat-select>
|
||||
</mat-form-field>
|
||||
<button mat-icon-button color="primary" matTooltip="add new facet"
|
||||
matTooltipClass="tableTooltip" [matTooltipPosition]="'right'" (click)="addFacet(selectedOption)">
|
||||
matTooltipClass="tableTooltip" [matTooltipPosition]="'right'"
|
||||
(click)="addFacet(selectedOption)">
|
||||
<mat-icon>add</mat-icon></button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/restrict-plus-operands */
|
||||
/* eslint-disable @typescript-eslint/member-ordering */
|
||||
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||
/* eslint-disable no-console */
|
||||
|
@ -99,15 +100,10 @@ export class FacetComposerComponent implements OnInit {
|
|||
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
|
||||
console.debug(`Map key is:${key} and value is:${value}`);
|
||||
console.debug('************************');
|
||||
});
|
||||
*/
|
||||
this.addableFacets = this.fillFacetSelect(this.fieldsMap);
|
||||
this.createForm(res);
|
||||
console.debug('**************CounterMap****************');
|
||||
console.debug(this.counterMap);
|
||||
});
|
||||
|
||||
|
||||
|
@ -189,13 +185,18 @@ export class FacetComposerComponent implements OnInit {
|
|||
|
||||
const minFc = this.fb.control(item.min);
|
||||
facetFg.addControl('min', minFc);
|
||||
|
||||
|
||||
const descriptionFc = this.fb.control(item.description);
|
||||
facetFg.addControl('description', descriptionFc);
|
||||
|
||||
const relationFc = this.fb.control(item.relation,Validators.required);
|
||||
facetFg.addControl('relation', relationFc);
|
||||
|
||||
const counterFc = this.fb.control(1);
|
||||
// alert(this.counterMap.get('counter_'+nameFc.value+'_'+relationFc.value));
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
||||
facetFg.addControl('counter_'+nameFc.value+'_'+relationFc.value, counterFc);
|
||||
|
||||
//1. creo formArray con le properties
|
||||
const propertiesFa = this.fb.array([]);
|
||||
for(let j=0; j<item.guiProps.length; j++){
|
||||
|
@ -227,7 +228,7 @@ export class FacetComposerComponent implements OnInit {
|
|||
this.myForm.reset();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
private addFacetGroup(): FormGroup {
|
||||
|
||||
return this.fb.group({
|
||||
|
@ -235,9 +236,13 @@ export class FacetComposerComponent implements OnInit {
|
|||
properties: this.fb.array([])
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
addFacet(nameplus:string): void {
|
||||
nameplus.replace(' (','_').replace(')','');
|
||||
alert('replaced...'+nameplus);
|
||||
//ATTENZIONE: nameplus contiene SPAZIO E PARENTESI
|
||||
const icf: IFacetComposer = <IFacetComposer>this.fieldsMap.get(nameplus);
|
||||
//TODO CHECK THIS
|
||||
this.typeSpec.facetSpecs.push(icf);
|
||||
|
@ -249,18 +254,23 @@ export class FacetComposerComponent implements OnInit {
|
|||
const maxFc = this.fb.control(icf.max);
|
||||
facetFg.addControl('max', maxFc);
|
||||
|
||||
//ogni facet aggiunta può essere rimossa
|
||||
const minFc = this.fb.control('many');
|
||||
const minFc = this.fb.control(icf.min);
|
||||
facetFg.addControl('min', minFc);
|
||||
|
||||
const newCounter = (this.counterMap.get(nameplus)!)+1;
|
||||
//alert('addFacet...nameplus...'+nameplus);
|
||||
// alert('addFacet...'+this.counterMap.get(nameplus));
|
||||
this.counterMap.set(icf.name+'_'+icf.relation,newCounter);
|
||||
const counterFc = this.fb.control(this.counterMap.get(nameplus));
|
||||
facetFg.addControl('counter_'+icf.name+'_'+icf.relation,counterFc);
|
||||
facetFg.patchValue;
|
||||
|
||||
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);
|
||||
|
@ -269,46 +279,40 @@ export class FacetComposerComponent implements OnInit {
|
|||
for(let j=0; j<icf.guiProps.length; j++){
|
||||
this.createPropertyArray(icf.guiProps[j],propertiesFa);
|
||||
}
|
||||
|
||||
//2. aggiungo formarray delle properties ai controls per la facet
|
||||
facetFg.addControl('properties',propertiesFa);
|
||||
//Aggiunge in ultima posizione nel'array
|
||||
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 {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
||||
const nameplus = this.facetArray.at(index).get('name')?.value+'_'+this.facetArray.at(index).get('relation')?.value;
|
||||
const newCounter = this.counterMap.get(nameplus)!-1;
|
||||
this.counterMap.set(nameplus,newCounter);
|
||||
//modifico il formcontrol
|
||||
console.log("*********WHEN REMOVING...")
|
||||
console.debug(nameplus);
|
||||
console.log("*********")
|
||||
|
||||
this.facetArray.get('counter_'+nameplus)?.setValue(newCounter);
|
||||
this.facetArray.at(index).get('counter_'+nameplus)?.patchValue;
|
||||
|
||||
const controls: FormArray = <FormArray>this.myForm.controls['facets'];
|
||||
|
||||
controls.removeAt(index);
|
||||
this.facetArray.removeAt(index);
|
||||
this.typeSpec.facetSpecs.splice(index,1);
|
||||
|
||||
/*
|
||||
for(let j=0; j<this.facetData[index].guiProps.length; j++){
|
||||
this.deleteProperty(index,j);
|
||||
}
|
||||
this.facetArray.removeAt(index);
|
||||
console.debug('*** rimosso indice: '+String(index));
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
deleteProperty(ind:number,i:number): void {
|
||||
this.getPropertiesArray(ind).removeAt(i);
|
||||
/*
|
||||
(<FormArray>(<FormGroup>this.facetArray.controls[index]).controls.propertyArray).push(this.propertyGroup);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue