Mejora al cargar las transacciones por tramos
This commit is contained in:
@ -8,23 +8,41 @@ const transacciones = {
|
||||
get: function() {
|
||||
return {
|
||||
transacciones: () => {
|
||||
return $.ajax({
|
||||
url: _urls.api + '/cuenta/' + this.cuenta_id + '/transacciones',
|
||||
let promises = []
|
||||
$.ajax({
|
||||
url: _urls.api + '/cuenta/' + this.cuenta_id + '/transacciones/amount',
|
||||
method: 'GET',
|
||||
dataType: 'json'
|
||||
}).then((data) => {
|
||||
if (data.cuenta === null) {
|
||||
return
|
||||
const amount = data.transacciones
|
||||
const step = 100
|
||||
for (let i = 0; i < amount; i += step) {
|
||||
promises.push($.ajax({
|
||||
url: _urls.api + '/cuenta/' + this.cuenta_id + '/transacciones/' + step + '/' + i,
|
||||
method: 'GET',
|
||||
dataType: 'json'
|
||||
}))
|
||||
}
|
||||
this.cuenta = data.cuenta
|
||||
this.saldo = this.cuenta.saldo
|
||||
$('#cuenta').html(this.cuenta.nombre + ' (' + this.cuenta.categoria.nombre + ')')
|
||||
if (data.transacciones === null || data.transacciones.length == 0) {
|
||||
return
|
||||
}
|
||||
this.transacciones = data.transacciones
|
||||
}).then(() => {
|
||||
this.draw()
|
||||
Promise.all(promises).then((data_arr) => {
|
||||
if (data_arr[0].cuenta === null) {
|
||||
return
|
||||
}
|
||||
this.cuenta = data_arr[0].cuenta
|
||||
this.saldo = this.cuenta.saldo
|
||||
$('#cuenta').html(this.cuenta.nombre + ' (' + this.cuenta.categoria.nombre + ')')
|
||||
this.transacciones = []
|
||||
data_arr.forEach(data => {
|
||||
if (data.transacciones === null || data.transacciones.length == 0) {
|
||||
return
|
||||
}
|
||||
this.transacciones.push(...data.transacciones)
|
||||
})
|
||||
this.transacciones.sort((a, b) => {
|
||||
return (new Date(b.fecha)) - (new Date(a.fecha))
|
||||
})
|
||||
}).then(() => {
|
||||
this.draw()
|
||||
})
|
||||
})
|
||||
},
|
||||
cuentas: () => {
|
||||
@ -53,7 +71,7 @@ const transacciones = {
|
||||
const parent = $(this.id)
|
||||
parent.html('')
|
||||
$.each(this.transacciones, (i, el) => {
|
||||
const fuente = (el.valor < 0) ? el.desde : el.hasta
|
||||
const fuente = (el.valor < 0) ? el.hasta : el.desde
|
||||
parent.append(
|
||||
$('<tr></tr>').append(
|
||||
$('<td></td>').html(el.fechaFormateada)
|
||||
@ -64,9 +82,9 @@ const transacciones = {
|
||||
).append(
|
||||
$('<td></td>').html(el.glosa + '<br />' + el.detalle)
|
||||
).append(
|
||||
$('<td></td>').attr('class', 'right aligned').html((el.valor < 0) ? el.valorFormateado.replace('-', '') : '')
|
||||
$('<td></td>').attr('class', 'right aligned').html((el.valor < 0) ? '' : el.valorFormateado.replace('-', ''))
|
||||
).append(
|
||||
$('<td></td>').attr('class', 'right aligned').html((el.valor < 0) ? '' : el.valorFormateado)
|
||||
$('<td></td>').attr('class', 'right aligned').html((el.valor < 0) ? el.valorFormateado.replace('-', '') : '')
|
||||
).append(
|
||||
$('<td></td>').attr('class', 'right aligned').html(format.format(this.saldo))
|
||||
)
|
||||
|
@ -6,7 +6,7 @@ const cuentas = {
|
||||
parent: () => {
|
||||
let parent = $(this.id)
|
||||
if (parent.length === 0) {
|
||||
const table = $('<table></table>').attr('class', 'ui table').append(
|
||||
const table = $('<table></table>').attr('class', 'ui striped table').append(
|
||||
$('<thead></thead>').append(
|
||||
$('<tr></tr>').append(
|
||||
$('<th></th>').html('Cuenta')
|
||||
|
@ -34,6 +34,15 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="transacciones">
|
||||
<tr>
|
||||
<td colspan="7">
|
||||
<div class="ui active dimmer">
|
||||
<div class="ui indeterminate elastic text loader">
|
||||
Buscando los datos
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
Reference in New Issue
Block a user