Skip to content

Commit

Permalink
WIP fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigogs committed Nov 9, 2017
1 parent 6616d94 commit 2784073
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/public/javascript/services/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,22 @@ const ReportService = (($, _, moment, App, Util) => ({
const columnColorCache = {};
const columnOrderCache = {};
const dailyMovesCache = {};
const columnsMoveCache = {};

const getDailyColumnCache = day => (column, create = true) => {
let columnMoves = columnsMoveCache[column.id];
if (!columnMoves) columnMoves = (columnsMoveCache[column.id] = 0);

const getDailyColumnCache = day => (column) => {
let dailyCache = dailyMovesCache[day];
if (!dailyCache) dailyCache = (dailyMovesCache[day] = {});

let columnCache = dailyCache[column.id];
if (!columnCache) {
const total = _(dailyMovesCache).map().map(val => _.map(val)).flatten().filter({ id: column.id }).sumBy('count');
columnCache = (dailyCache[column.id] = Object.assign({}, column, { count: 0, total }));
}
if (!columnCache && create) columnCache = (dailyCache[column.id] = Object.assign({}, column, { count: columnMoves }));

return columnCache;
return columnCache || { count: 0 };
}

labels.forEach((day, index) => moves.forEach((move) => {
if (day !== move.formatedDate) return;

const from = move.from_column;
const to = move.to_column;

Expand All @@ -286,8 +285,10 @@ const ReportService = (($, _, moment, App, Util) => ({
from.order = from.order || columnOrderCache[from.id] || (columnOrderCache[from.id] = 0);

const cache = getDailyColumnCache(day)(from);
if (cache.count > 0) cache.count -= 1;
if (cache.total > 0) cache.total -= 1;
if (day === move.formatedDate && cache.count > 0) {
cache.count -= 1;
columnsMoveCache[from.id] -= 1;
}
}

if (to) {
Expand All @@ -297,13 +298,15 @@ const ReportService = (($, _, moment, App, Util) => ({
to.order = to.order || columnOrderCache[to.id] || (columnOrderCache[to.id] = 0);

const cache = getDailyColumnCache(day)(to);
cache.count += 1;
cache.total += 1;
if (day === move.formatedDate) {
cache.count += 1;
columnsMoveCache[to.id] += 1;
}
}
}));

const datasets = _(columns).orderBy('order').filter('visible').map((column) => {
const data = labels.map(day => getDailyColumnCache(day)(column).total);
const datasets = _(columnsCache).orderBy('order').filter('visible').map((column) => {
const data = labels.map(day => getDailyColumnCache(day)(column, false).count);

return {
data,
Expand All @@ -313,8 +316,6 @@ const ReportService = (($, _, moment, App, Util) => ({
};
}).value();

console.log(datasets)

return {
labels,
datasets,
Expand Down

0 comments on commit 2784073

Please sign in to comment.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy