additional cleanup of kanban utils.
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -1,106 +1,105 @@
|
|||||||
import _ from "lodash/";
|
import {groupBy} from "lodash";
|
||||||
|
|
||||||
const sortByParentId = (arr) => {
|
const sortByParentId = (arr) => {
|
||||||
// return arr.reduce((accumulator, currentValue) => {
|
// return arr.reduce((accumulator, currentValue) => {
|
||||||
// //Find the parent item.
|
// //Find the parent item.
|
||||||
// let item = accumulator.find((x) => x.id === currentValue.kanbanparent);
|
// let item = accumulator.find((x) => x.id === currentValue.kanbanparent);
|
||||||
// //Get index of praent item
|
// //Get index of parent item
|
||||||
// let index = accumulator.indexOf(item);
|
// let index = accumulator.indexOf(item);
|
||||||
|
|
||||||
// index = index !== -1 ? index + 1 : 0;
|
// index = index !== -1 ? index + 1 : 0;
|
||||||
// accumulator.splice(index, 0, currentValue);
|
// accumulator.splice(index, 0, currentValue);
|
||||||
// return accumulator;
|
// return accumulator;
|
||||||
// }, []);
|
// }, []);
|
||||||
|
|
||||||
var parentId = "-1";
|
let parentId = "-1";
|
||||||
var sortedList = [];
|
const sortedList = [];
|
||||||
var byParentsIdsList = _.groupBy(arr, "kanbanparent"); // Create a new array with objects indexed by parentId
|
const byParentsIdsList = groupBy(arr, "kanbanparent"); // Create a new array with objects indexed by parentId
|
||||||
//console.log("sortByParentId -> byParentsIdsList", byParentsIdsList);
|
//console.log("sortByParentId -> byParentsIdsList", byParentsIdsList);
|
||||||
|
|
||||||
while (byParentsIdsList[parentId]) {
|
while (byParentsIdsList[parentId]) {
|
||||||
sortedList.push(byParentsIdsList[parentId][0]);
|
sortedList.push(byParentsIdsList[parentId][0]);
|
||||||
parentId = byParentsIdsList[parentId][0].id;
|
parentId = byParentsIdsList[parentId][0].id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (byParentsIdsList["null"])
|
if (byParentsIdsList["null"])
|
||||||
byParentsIdsList["null"].map((i) => sortedList.push(i));
|
byParentsIdsList["null"].map((i) => sortedList.push(i));
|
||||||
|
|
||||||
//Validate that the 2 arrays are of the same length and no children are missing.
|
//Validate that the 2 arrays are of the same length and no children are missing.
|
||||||
if (arr.length !== sortedList.length) {
|
if (arr.length !== sortedList.length) {
|
||||||
arr.map((origItem) => {
|
arr.map((origItem) => {
|
||||||
if (!!!sortedList.find((s) => s.id === origItem.id)) {
|
if (!!!sortedList.find((s) => s.id === origItem.id)) {
|
||||||
sortedList.push(origItem);
|
sortedList.push(origItem);
|
||||||
console.log("DATA CONSISTENCY ERROR: ", origItem.ro_number);
|
console.log("DATA CONSISTENCY ERROR: ", origItem.ro_number);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return sortedList;
|
return sortedList;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createBoardData = (AllStatuses, Jobs, filter) => {
|
export const createBoardData = (AllStatuses, Jobs, filter) => {
|
||||||
const { search, employeeId } = filter;
|
const {search, employeeId} = filter;
|
||||||
console.log("==========GENERATING BOARD DATA=============");
|
const boardLanes = {
|
||||||
const boardLanes = {
|
columns: AllStatuses.map((s) => {
|
||||||
columns: AllStatuses.map((s) => {
|
return {
|
||||||
return {
|
id: s,
|
||||||
id: s,
|
title: s,
|
||||||
title: s,
|
cards: [],
|
||||||
cards: [],
|
};
|
||||||
};
|
}),
|
||||||
}),
|
};
|
||||||
};
|
|
||||||
|
|
||||||
const filteredJobs =
|
const filteredJobs =
|
||||||
(search === "" || !search) && !employeeId
|
(search === "" || !search) && !employeeId
|
||||||
? Jobs
|
? Jobs
|
||||||
: Jobs.filter((j) => {
|
: Jobs.filter((j) => {
|
||||||
let include = false;
|
let include = false;
|
||||||
if (search && search !== "") {
|
if (search && search !== "") {
|
||||||
include = CheckSearch(search, j);
|
include = CheckSearch(search, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!!employeeId) {
|
if (!!employeeId) {
|
||||||
include =
|
include =
|
||||||
include ||
|
include ||
|
||||||
j.employee_body === employeeId ||
|
j.employee_body === employeeId ||
|
||||||
j.employee_prep === employeeId ||
|
j.employee_prep === employeeId ||
|
||||||
j.employee_csr === employeeId ||
|
j.employee_csr === employeeId ||
|
||||||
j.employee_refinish === employeeId;
|
j.employee_refinish === employeeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return include;
|
return include;
|
||||||
});
|
});
|
||||||
|
|
||||||
const DataGroupedByStatus = _.groupBy(filteredJobs, (d) => d.status);
|
const DataGroupedByStatus = groupBy(filteredJobs, (d) => d.status);
|
||||||
|
|
||||||
Object.keys(DataGroupedByStatus).map((statusGroupKey) => {
|
Object.keys(DataGroupedByStatus).map((statusGroupKey) => {
|
||||||
try {
|
try {
|
||||||
const needle = boardLanes.columns.find((l) => l.id === statusGroupKey);
|
const needle = boardLanes.columns.find((l) => l.id === statusGroupKey);
|
||||||
if (!needle?.cards) return null;
|
if (!needle?.cards) return null;
|
||||||
needle.cards = sortByParentId(DataGroupedByStatus[statusGroupKey]);
|
needle.cards = sortByParentId(DataGroupedByStatus[statusGroupKey]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error while creating board card", error);
|
console.log("Error while creating board card", error);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
return boardLanes;
|
return boardLanes;
|
||||||
};
|
};
|
||||||
|
|
||||||
const CheckSearch = (search, job) => {
|
const CheckSearch = (search, job) => {
|
||||||
return (
|
return (
|
||||||
(job.ro_number || "").toLowerCase().includes(search.toLowerCase()) ||
|
(job.ro_number || "").toLowerCase().includes(search.toLowerCase()) ||
|
||||||
(job.ownr_fn || "").toLowerCase().includes(search.toLowerCase()) ||
|
(job.ownr_fn || "").toLowerCase().includes(search.toLowerCase()) ||
|
||||||
(job.ownr_co_nm || "").toLowerCase().includes(search.toLowerCase()) ||
|
(job.ownr_co_nm || "").toLowerCase().includes(search.toLowerCase()) ||
|
||||||
(job.ownr_ln || "").toLowerCase().includes(search.toLowerCase()) ||
|
(job.ownr_ln || "").toLowerCase().includes(search.toLowerCase()) ||
|
||||||
(job.status || "").toLowerCase().includes(search.toLowerCase()) ||
|
(job.status || "").toLowerCase().includes(search.toLowerCase()) ||
|
||||||
(job.v_make_desc || "").toLowerCase().includes(search.toLowerCase()) ||
|
(job.v_make_desc || "").toLowerCase().includes(search.toLowerCase()) ||
|
||||||
(job.v_model_desc || "").toLowerCase().includes(search.toLowerCase()) ||
|
(job.v_model_desc || "").toLowerCase().includes(search.toLowerCase()) ||
|
||||||
(job.clm_no || "").toLowerCase().includes(search.toLowerCase()) ||
|
(job.clm_no || "").toLowerCase().includes(search.toLowerCase()) ||
|
||||||
(job.plate_no || "").toLowerCase().includes(search.toLowerCase())
|
(job.plate_no || "").toLowerCase().includes(search.toLowerCase())
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// export const updateBoardOnMove = (board, card, source, destination) => {
|
// export const updateBoardOnMove = (board, card, source, destination) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user