Skip to content

Commit

Permalink
fixed bug - ocultar repetidos
Browse files Browse the repository at this point in the history
  • Loading branch information
asafJortilles committed Nov 17, 2023
1 parent 0812f7e commit da4bc5a
Showing 1 changed file with 55 additions and 37 deletions.
92 changes: 55 additions & 37 deletions eda/eda_app/src/app/module/components/eda-table/eda-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export class EdaTable {
public onSortColEvent: EventEmitter<any> = new EventEmitter();

public _value: any[] = [];
public _value_copy: any[] = [];

public cols: EdaColumn[] = [];
public rows: number = 10;
Expand Down Expand Up @@ -68,7 +67,7 @@ export class EdaTable {
public resultAsPecentage: boolean = false;
public onlyPercentages: boolean = false;
public percentageColumns: Array<any> = [];
public noRepetitions: boolean = false;
public noRepetitions: boolean;
public autolayout: boolean = true;
public sortedSerie: any = null;
public sortedColumn: any = { field: null, order: null };
Expand Down Expand Up @@ -221,12 +220,9 @@ export class EdaTable {
if (this.withColSubTotals) {
event ? this.colSubTotals(event.first / event.rows + 1) : this.colSubTotals(1);
}
if (this.noRepetitions) {
if (this.noRepetitions || !this.noRepetitions) {
this.noRepeatedRows();
}
if (!this.noRepetitions) {
this.withRepeatedRows();
}

}

Expand Down Expand Up @@ -509,49 +505,70 @@ export class EdaTable {
return row;
}

makeCopy(val) : void {
this._value_copy = val;
}

getCopy() {
return this._value_copy;
}

withRepeatedRows() {
const val = this.getCopy();

if (_.isEmpty(val) == true) {
return this._value;
} else {
this._value = val;
return this._value;
}
}

noRepeatedRows() {

this.makeCopy(this._value); //hacemos una copia del valor original que nos entra, por si tenemos que reutilizarlo en la vista opuesta
let val = this._value;
//usamos la extracción de valores para el noRepetitions
extractDataValues(val) {
//separamos valores de claves
let values = [];
for (let i=0; i<val.length;i++) {
values.push(Object.values(val[i]));
}

//tomamos claves que serán el cabecero
return values;
}
//usamos la extracción de labels para el noRepetitions
extractLabels(val) {
let labels = [];
labels.push(Object.keys(val[0])); //insertamos el primer objeto con el cabecero para iterar y extraer los datos
labels.forEach(e => {
e.forEach(function(key,val) {
labels.push(key);

})

})
labels.shift(); //borramos el primer objeto.
return labels;
}

noRepeatedRows() {

//separamos valores de claves
let values = this.extractDataValues(this.value);

//tomamos claves que serán el cabecero
let labels = this.extractLabels(this.value)

labels.shift(); //borramos el primer objeto.
let first = _.cloneDeep(values[0]);
let output = [];

//esta primera iteración con this.noRepetitions en false se hace para devolver las palabras repetidas al diálogo.
//Es una secuencia similar a la de quitar los valores, pero opuesta.
if (!this.noRepetitions) {

const output = [];
let values = this.extractDataValues(this.value);
values = values.filter(row => !row.every(element => element === null));
// Load the Table for a preview
for (let i = 0; i < values.length; i += 1) {
const obj = {};
if (i == 0) {
for (let e = 0; e < values[i].length; e += 1) {
obj[labels[e]] = values[i][e];
}
} else {
for (let e = 0; e < values[i].length; e += 1) {
if (values[i][e] == ""){
obj[labels[e]] = first[e];
} else {
obj[labels[e]] = values[i][e];
first[e] = values[i][e];
}
}
}

output.push(obj);
}
return this.value = output;

} else {
// ESTO SE HACE PARA EVITAR REPETIDOS EN LA TABLA. SI UN CAMPO TIENE UNA COLUMNA QUE SE REPITE
let first = _.cloneDeep(values[0]);
for (let i = 0; i < values.length; i += 1) {
Expand All @@ -572,13 +589,14 @@ export class EdaTable {
}
output.push(obj);
}

this._value = output;

return this._value;
this.value = output;

}
return this.value;

}


colsPercentages() {
if (this.percentageColumns.length !== 0) {
this.removePercentages();
Expand Down

0 comments on commit da4bc5a

Please sign in to comment.