Commit 8e13b66b authored by Ermolaev Timur's avatar Ermolaev Timur

#111 Вывел сразу все задачи

parent 85ebd8db
...@@ -3,6 +3,7 @@ import { getHoursInDayNumbers, getAvailableTasks, getLinesInDay, getSortedTasks ...@@ -3,6 +3,7 @@ import { getHoursInDayNumbers, getAvailableTasks, getLinesInDay, getSortedTasks
import CalendarStandartCell from "../../../CalendarStandartCell/CalendarStandartCell"; import CalendarStandartCell from "../../../CalendarStandartCell/CalendarStandartCell";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { Grid } from "@mui/material"; import { Grid } from "@mui/material";
import CalendarWeekTask from "./CalendarWeekTask/CalendarWeekTask";
...@@ -39,21 +40,20 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat ...@@ -39,21 +40,20 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
return getSortedTasks(availableTasks) return getSortedTasks(availableTasks)
}, [availableTasks]) }, [availableTasks])
console.log(columnDayHeight)
const linesInDay = useMemo(() => { const linesInDay = useMemo(() => {
return getLinesInDay(availableTasks, sortedTasks, hoursInDay, hours, hourFormat) return getLinesInDay(availableTasks, sortedTasks, hoursInDay, hours, hourFormat)
}, [availableTasks, hourFormat, hours, hoursInDay, sortedTasks]) }, [availableTasks, hourFormat, hours, hoursInDay, sortedTasks])
const getBoxesInLine = (line, hoursInDay, sortedTasks) => { const getBoxesInLine = (line, hoursInDay, sortedTasks, linesInDay) => {
if (line) { if (line) {
let xs = 12/hoursInDay.length let xs = 12 / hoursInDay.length
const boxes = [] const boxes = []
for (let i = 0; i < line.length; i++) { for (let i = 0; i < line.length; i++) {
if (!isNaN(line[i])) { if (!isNaN(line[i])) {
} else { } else {
const task = sortedTasks[line[i].split('-')[1]] const task = sortedTasks[line[i].split('-')[1]]
const taskIsThere = boxes.find((taskFind)=>{ const taskIsThere = boxes.find((taskFind) => {
if (taskFind?.task?.id === task.id) return taskFind if (taskFind?.task?.id === task.id) return taskFind
return false return false
}) })
...@@ -62,37 +62,57 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat ...@@ -62,37 +62,57 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
taskIsThere.lastHour = i taskIsThere.lastHour = i
taskIsThere.height += step taskIsThere.height += step
} else { } else {
let tasksInHour = 0
for (let line of linesInDay) {
if (isNaN(line[i])) {
tasksInHour++
}
}
boxes.push({ boxes.push({
top: step * i, tasksInHour: tasksInHour,
top: step * i,
height: step, height: step,
firstHour: i, firstHour: i,
lastHour: i, lastHour: i,
task: sortedTasks[line[i].split('-')[1]]}) task: sortedTasks[line[i].split('-')[1]]
})
} }
} }
} }
return boxes return boxes
} }
} }
console.log(getBoxesInLine(linesInDay[0], hoursInDay, sortedTasks)) const arr = ['red', 'blue', 'yellow', 'purple', 'green']
return (<> return (<>
<Grid item xs={12 / 7} ref={dayColumnRef} sx={{ position: 'relative' }}> <Grid item xs={12 / 7} ref={dayColumnRef} sx={{ position: 'relative' }}>
{getBoxesInLine(linesInDay[0], hoursInDay, sortedTasks)?.map((task)=>{ {linesInDay?.map((line, i) => {
return ( const boxes = getBoxesInLine(line, hoursInDay, sortedTasks, linesInDay)
<div style={{ return (<>
backgroundColor: 'red', {boxes.map((task, index) => {
height: `${task.height}px`, const amount = task.tasksInHour
width: '96%', const oneTaskPrecentWidth = 100 / amount
margin: '0 auto', const left = oneTaskPrecentWidth * dayColumnRef.current.offsetWidth / 100 * i
position: 'absolute', const oneTaskWidth = dayColumnRef.current.offsetWidth - (oneTaskPrecentWidth * dayColumnRef.current.offsetWidth / 100) * i
top: task.top, const zIndex = 10 + i
marginLeft: 'auto', return (
marginRight: 'auto', <CalendarWeekTask
left: '0', key={index}
right: '0', width={oneTaskWidth}
}}> height={task.height}
left={left}
</div>) task={task.task}
top={task.top}
zIndex={zIndex}
>
</CalendarWeekTask>
)
})}
</>)
})} })}
{hoursInDay?.map((hour, i) => { {hoursInDay?.map((hour, i) => {
return ( return (
......
import { Box } from "@mui/material"
import { useEffect, useState } from "react"
function CalendarWeekTask({ height, width, left, top, task, zIndex }) {
const [color, setColor] = useState('')
useEffect(() => {
if (task.priority) {
if (task.priority === 'A') setColor('rgb(32, 138, 250)')
if (task.priority === 'B') setColor('lightgreen')
if (task.priority === 'C') setColor('yellow')
} else {
setColor('rgb(171, 157, 157);')
}
}, [task])
const styles = {
borderRadius: '5px',
border: '1px solid black',
backgroundColor: color,
height: `${height}px`,
width: `${width}px`,
position: 'absolute',
left: `${left}px`,
top: top,
zIndex: zIndex,
textAlign: 'left',
overflow: 'hidden',
textOverflow: 'ellipsis'
}
return (
<Box
sx={styles}>
<span style={{position: 'absolute', textOverflow: 'ellipsis', padding: '5px 0 0 10px'}}>
{task.title}
</span>
</Box>);
}
export default CalendarWeekTask;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment