/* Парус 8 - Панели мониторинга - УДП - Доски задач Дополнительная разметка и вёрстка клиентских элементов */ //--------------------- //Подключение библиотек //--------------------- //--------- //Константы //--------- //Перечисление "Состояние события" export const EVENT_STATES = Object.freeze({ 0: "Все", 1: "Не аннулированные", 2: "Аннулированные" }); //Допустимые значение поля сортировки export const sortAttrs = [ { id: "code", descr: "Мнемокод" }, { id: "name", descr: "Наименование" }, { id: "pointDescr", descr: "Описание точки маршрута" } ]; //Допустимые значения направления сортировки export const sortDest = []; sortDest[-1] = "desc"; sortDest[1] = "asc"; //Цвета статусов export const COLORS = [ "mediumSlateBlue", "lightSalmon", "fireBrick", "orange", "gold", "limeGreen", "yellowGreen", "mediumAquaMarine", "paleTurquoise", "steelBlue", "skyBlue", "tan" ]; //Перечисление "Цвет индикации" export const EVENT_INDICATORS = Object.freeze({ EXPIRED: "#ff0000", EXPIRES_SOON: "#ffdf00", LINKED: "#1e90ff" }); //Перечисление Доп. свойства "Значение по умолчанию" export const DP_DEFAULT_VALUE = Object.freeze({ 0: "defaultStr", 1: "defaultNum", 2: "defaultDate", 3: "defaultNum" }); //Перечисление Доп. свойства "Префикс формата данных" export const DP_TYPE_PREFIX = Object.freeze({ 0: "S", 1: "N", 2: "D", 3: "N" }); //Перечисление Доп. свойства "Входящее значение дополнительного словаря" export const DP_IN_VALUE = Object.freeze({ 0: "pos_str_value", 1: "pos_num_value", 2: "pos_date_value", 3: "pos_num_value" }); //Перечисление Доп. свойства "Исходящее значение дополнительного словаря" export const DP_RETURN_VALUE = Object.freeze({ 0: "str_value", 1: "num_value", 2: "date_value", 3: "num_value" }); //Меню действий события export const menuItems = ( handleEdit, handleEditClient, handleDelete, handleTaskStateChange, handleTaskReturn, handleTaskSend, handleNotes, handleFileLinks ) => [ { method: "EDIT", name: "Исправить", icon: "edit", visible: false, delimiter: false, needReload: false, func: handleEdit }, { method: "EDIT_CLIENT", name: "Исправить в разделе", icon: "edit_note", visible: true, delimiter: false, needReload: false, func: handleEditClient }, { method: "DELETE", name: "Удалить", icon: "delete", visible: true, delimiter: true, needReload: true, func: handleDelete }, { method: "TASK_STATE_CHANGE", name: "Перейти", icon: "turn_right", visible: true, delimiter: false, needReload: true, func: handleTaskStateChange }, { method: "TASK_RETURN", name: "Выполнить возврат", icon: "turn_left", visible: true, delimiter: false, needReload: true, func: handleTaskReturn }, { method: "TASK_SEND", name: "Направить", icon: "send", visible: true, delimiter: true, needReload: true, func: handleTaskSend }, { method: "NOTES", name: "Примечания", icon: "event_note", visible: true, delimiter: true, needReload: false, func: handleNotes }, { method: "FILE_LINKS", name: "Присоединенные документы", icon: "attach_file", visible: true, delimiter: false, needReload: false, func: handleFileLinks } ]; //----------- //Тело модуля //----------- //Формирование массива из 0, 1 и 1< элементов export const arrayFormer = arr => { return arr ? (arr.length ? arr : [arr]) : []; }; //Конвертация формата HEX в формат RGB const hexToRGB = hex => { let r = parseInt(hex.slice(1, 3), 16); let g = parseInt(hex.slice(3, 5), 16); let b = parseInt(hex.slice(5, 7), 16); let a = 0.5; r = Math.round((a * (r / 255) + a * (255 / 255)) * 255); g = Math.round((a * (g / 255) + a * (255 / 255)) * 255); b = Math.round((a * (b / 255) + a * (255 / 255)) * 255); return "rgb(" + r + ", " + g + ", " + b + ")"; }; //Проверка выполнения условия заливки события export const bgColorRule = (task, colorRule) => { let ruleCode; let bgColor = null; if (colorRule.vType === "string") ruleCode = `S${colorRule.fieldCode}`; else if (colorRule.vType === "number") ruleCode = `N${colorRule.fieldCode}`; else if (colorRule.vType === "date") ruleCode = `D${colorRule.fieldCode}`; ruleCode ? (task.docProps[ruleCode] == colorRule.from ? (bgColor = hexToRGB(colorRule.color)) : null) : null; return bgColor; }; //Индикация истечения срока отработки события export const indicatorColorRule = task => { let sysDate = new Date(); let expireDate = task.dexpire_date ? new Date(task.dexpire_date) : null; let daysDiff = null; if (expireDate) { daysDiff = ((expireDate.getTime() - sysDate.getTime()) / (1000 * 60 * 60 * 24)).toFixed(2); if (daysDiff < 0) return EVENT_INDICATORS.EXPIRED; else if (daysDiff < 4) return EVENT_INDICATORS.EXPIRES_SOON; } return null; }; //Формирование случайного цвета export const randomColor = index => { const hue = index * 137.508; return hslToRgba(hue, 50, 70); }; //Цвет из hsl формата в rgba формат const hslToRgba = (h, s, l) => { s /= 100; l /= 100; const k = n => (n + h / 30) % 12; const a = s * Math.min(l, 1 - l); const f = n => l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1))); return `rgba(${Math.floor(255 * f(0))},${Math.floor(255 * f(8))},${Math.floor(255 * f(4))},0.3)`; }; //Формат дополнительного свойства типа число (длина, точность) const DPNumFormat = (l, p) => new RegExp("^(\\d{1," + (l - p) + "}" + (p > 0 ? "((\\.|,)\\d{1," + p + "})?" : "") + ")?$"); //Формат дополнительного свойства типа строка (длина) const DPStrFormat = l => new RegExp("^.{0," + l + "}$"); //Проверка валидности числа const isValidDPNum = (length, prec, value) => { return DPNumFormat(length, prec).test(value); }; //Проверка валидности строки const isValidDPStr = (length, value) => { return DPStrFormat(length).test(value); }; //Признак ошибки валидации export const validationError = (value = "", format, numW, numPrec, strW) => { if (format === 0) return isValidDPStr(strW, value); else if (format === 1) { return isValidDPNum(numW, numPrec, value); } else return true; }; //Конвертация времени в привычный формат export const timeFromSqlFormat = ts => { if (ts.indexOf(".") !== -1) { let s = 24 * 60 * 60 * ts; const h = Math.trunc(s / (60 * 60)); s = s % (60 * 60); const m = Math.trunc(s / 60); s = Math.round(s % 60); const formattedTime = ("0" + h).slice(-2) + ":" + ("0" + m).slice(-2) + ":" + ("0" + s).slice(-2); return formattedTime; } return ts; };