From 6f55ac14da3d6f62aaf0a1bc8af08b468eb24249 Mon Sep 17 00:00:00 2001 From: Mikhail Chechnev Date: Wed, 3 Apr 2024 16:03:30 +0300 Subject: [PATCH] =?UTF-8?q?WEB=20APP:=20P8PGantt=20-=20=D0=BF=D0=BE=D0=B4?= =?UTF-8?q?=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B0=20=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D1=81=D0=BA?= =?UTF-8?q?=D0=B8=D1=85=20=D0=B4=D0=B8=D0=B0=D0=BB=D0=BE=D0=B3=D0=BE=D0=B2?= =?UTF-8?q?=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/p8p_gantt.js | 67 +++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/app/components/p8p_gantt.js b/app/components/p8p_gantt.js index 55ff58d..2f51fe8 100644 --- a/app/components/p8p_gantt.js +++ b/app/components/p8p_gantt.js @@ -90,6 +90,32 @@ const STYLES = { //Проверка существования значения const hasValue = value => typeof value !== "undefined" && value !== null && value !== ""; +//Формирование описания для легенды +const taskLegendDesc = ({ task, taskColors }) => { + if (Array.isArray(taskColors) && taskColors.length > 0) { + const colorDesc = taskColors.find( + color => task.bgColor === color.bgColor && task.textColor === color.textColor && task.bgProgressColor === color.bgProgressColor + ); + if (colorDesc) + return { + text: colorDesc.desc, + style: { + ...(colorDesc.bgProgressColor + ? { + background: `linear-gradient(to right, ${colorDesc.bgProgressColor} ,${ + colorDesc.bgColor ? colorDesc.bgColor : "transparent" + })` + } + : colorDesc.bgColor + ? { backgroundColor: colorDesc.bgColor } + : {}), + ...(colorDesc.textColor ? { color: colorDesc.textColor } : {}) + } + }; + else return null; + } else return null; +}; + //Редактор задачи const P8PGanttTaskEditor = ({ task, @@ -132,34 +158,17 @@ const P8PGanttTaskEditor = ({ const handleProgressChanged = (e, newValue) => setState(prev => ({ ...prev, progress: newValue })); //Описание легенды для задачи - let legend = null; - if (Array.isArray(taskColors)) { - const colorDesc = taskColors.find( - color => task.bgColor === color.bgColor && task.textColor === color.textColor && task.bgProgressColor === color.bgProgressColor - ); - if (colorDesc) - legend = ( - - ); - } + const legendDesc = taskLegendDesc({ task, taskColors }); + let legend = legendDesc ? ( + + ) : null; //Генерация содержимого return ( @@ -480,4 +489,4 @@ P8PGantt.propTypes = { //Интерфейс модуля //---------------- -export { P8P_GANTT_TASK_SHAPE, P8P_GANTT_TASK_ATTRIBUTE_SHAPE, P8P_GANTT_TASK_COLOR_SHAPE, P8PGantt }; +export { P8P_GANTT_TASK_SHAPE, P8P_GANTT_TASK_ATTRIBUTE_SHAPE, P8P_GANTT_TASK_COLOR_SHAPE, taskLegendDesc, P8PGantt };