Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
planner-team-one
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
21
Issues
21
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Евгений Положенцев
planner-team-one
Commits
c8d15d28
Commit
c8d15d28
authored
Nov 30, 2022
by
Ermolaev Timur
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'task-78-fix/fix_logic_calendar_tasks' into 'development'
Task 78 fix/fix logic calendar tasks See merge request
!55
parents
b25cde8e
40be6358
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
122 additions
and
81 deletions
+122
-81
copyTasks.ts
planner-api/src/routers/copyTasks.ts
+29
-29
CalendarStandartCell.js
...endarBody/CalendarStandartCell.js/CalendarStandartCell.js
+1
-1
MonthCalendar.js
planner-front/src/containers/MonthCalendar/MonthCalendar.js
+26
-12
tasksActions.js
planner-front/src/store/actions/tasksActions.js
+22
-9
tasksReducer.js
planner-front/src/store/reducers/tasksReducer.js
+44
-30
No files found.
planner-api/src/routers/copyTasks.ts
View file @
c8d15d28
...
...
@@ -28,38 +28,38 @@ const taskFinderById = async (taskId:string):Promise<null | Task>=>{
}
/** make copy of task in calendar view */
router
.
post
(
"/make-copy"
,
authAuthorOrExecutorOfTask
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
{
executorStatus
,
taskId
,
start
,
due
}
=
req
.
body
if
(
executorStatus
){
const
newDateTimeTask
=
new
DateTimeTask
();
newDateTimeTask
.
dateTimeStart
=
start
newDateTimeTask
.
dateTimeDue
=
due
newDateTimeTask
.
task
=
taskId
await
newDateTimeTask
.
save
()
const
task
=
taskFinderById
(
taskId
)
return
res
.
send
({
task
})
}
return
res
.
send
({
message
:
"Something wrong in make-copy router"
})
router
.
post
(
"/make-copy"
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
{
taskId
,
dateTimeDue
,
dateTimeStart
}
=
req
.
body
const
newDateTimeTask
=
new
DateTimeTask
();
newDateTimeTask
.
dateTimeStart
=
dateTimeStart
newDateTimeTask
.
dateTimeDue
=
dateTimeDue
newDateTimeTask
.
task
=
taskId
await
newDateTimeTask
.
save
()
const
task
=
taskFinderById
(
taskId
)
return
res
.
send
({
task
})
}
)
/** change date time of copy of task in calendar view */
router
.
put
(
"change-copy"
,
authAuthorOrExecutorOfTask
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
{
executorStatus
,
dateTimeTaskId
,
taskId
,
start
,
due
}
=
req
.
body
if
(
executorStatus
){
const
dateTimeTask
=
await
dataSource
.
createQueryBuilder
()
.
select
(
'dateTikeTask'
)
.
from
(
DateTimeTask
,
'dateTimeTask'
)
.
where
(
"dateTimeTask.id = :dateTimeTaskId"
,{
dateTimeTaskId
})
.
getOne
()
if
(
!
dateTimeTask
)
return
res
.
send
({
message
:
"such dateTimeTask does not exists"
})
dateTimeTask
.
dateTimeStart
=
start
dateTimeTask
.
dateTimeDue
=
due
await
dateTimeTask
.
save
()
const
task
=
taskFinderById
(
taskId
)
return
res
.
send
({
task
})
}
return
res
.
send
({
message
:
"Something wrong in make-copy router"
})
router
.
put
(
"/change-copy"
,
authAuthorOrExecutorOfTask
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
{
dateTimeTaskId
,
taskId
,
dateTimeStart
,
dateTimeDue
,
description
,
title
,
priority
}
=
req
.
body
const
dateTimeTask
=
await
dataSource
.
createQueryBuilder
()
.
select
(
'dateTimeTask'
)
.
from
(
DateTimeTask
,
'dateTimeTask'
)
.
where
(
"dateTimeTask.id = :dateTimeTaskId"
,{
dateTimeTaskId
})
.
getOne
()
if
(
!
dateTimeTask
)
return
res
.
send
({
message
:
"such dateTimeTask does not exists"
})
dateTimeTask
.
dateTimeStart
=
dateTimeStart
dateTimeTask
.
dateTimeDue
=
dateTimeDue
await
dateTimeTask
.
save
()
const
task
=
await
taskFinderById
(
taskId
)
if
(
!
task
)
return
res
.
status
(
404
).
send
({
Message
:
'task not found'
})
task
.
title
=
title
;
task
.
description
=
description
;
task
.
priority
=
priority
;
await
task
.
save
()
return
res
.
send
({
task
})
})
/**delete copyTask by dateTimeTaskId */
...
...
planner-front/src/components/MonthCalendarBody/CalendarStandartCell.js/CalendarStandartCell.js
View file @
c8d15d28
...
...
@@ -8,7 +8,7 @@ const CalendarStandartCell = ({children, xs, hours, dayNumber, createTaskInCell
const
[
isThisCell
,
setIsThisCell
]
=
useState
(
false
)
const
cellClass
=
{
position
:
'relative'
,
height
:
linesInDay
?.
length
?
`
${
40
*
linesInDay
.
length
+
35
}
px`
:
`
${
35
+
35
}
px`
,
height
:
linesInDay
?.
length
?
`
${
40
*
linesInDay
.
length
+
35
}
px`
:
`
${
35
}
px`
,
borderRight
:
'1px solid black'
,
}
useEffect
(()
=>
{
...
...
planner-front/src/containers/MonthCalendar/MonthCalendar.js
View file @
c8d15d28
...
...
@@ -3,11 +3,12 @@ import { useDispatch, useSelector } from 'react-redux';
import
MonthCalendarBody
from
'../../components/MonthCalendarBody/MonthCalendarBody'
;
import
MonthCalendarHeader
from
'../../components/MonthCalendarHeader/MonthCalendarHeader'
;
import
{
dateToISOLikeButLocal
,
getCurrentMonthString
,
getDaysInMonth
}
from
'../../helpers/CalendarHelpers'
;
import
{
addCalendarTask
,
deleteCalendarTask
,
editCalendarTask
,
fetchCalendarTasks
}
from
'../../store/actions/tasksActions'
;
import
{
addCalendarTask
,
addCopyCalendarTask
,
deleteCalendarTask
,
editCalendarTask
,
fetchCalendarTasks
}
from
'../../store/actions/tasksActions'
;
function
MonthCalendar
()
{
const
dispatch
=
useDispatch
();
const
{
calendarTasks
}
=
useSelector
(
state
=>
state
.
tasks
);
const
user
=
useSelector
(
state
=>
state
.
users
?.
user
);
const
[
hourFormat
,
setHourFormat
]
=
useState
(
false
);
const
[
dateNow
,
setDateNow
]
=
useState
({
month
:
''
,
year
:
''
})
...
...
@@ -65,7 +66,6 @@ function MonthCalendar() {
return
{...
prevState
,
month
:
prevState
.
month
+
1
}
})
},
[])
console
.
log
(
currentTask
)
const
decrementMonth
=
useCallback
(()
=>
{
setDateNow
((
prevState
)
=>
{
if
(
prevState
.
month
-
1
===
-
1
)
{
...
...
@@ -135,13 +135,15 @@ function MonthCalendar() {
due
=
dateToISOLikeButLocal
(
new
Date
(
dateNow
.
year
,
dateNow
.
month
,
dayNumber
,
hour
+
hourDiff
,
59
))
}
const
start
=
dateToISOLikeButLocal
(
new
Date
(
dateNow
.
year
,
dateNow
.
month
,
dayNumber
,
hour
,
0
))
const
new
Obj
=
{
const
new
Task
=
{
...
currentTask
,
dateTimeTaskId
:
currentTask
.
id
,
dateTimeStart
:
start
,
dateTimeDue
:
due
}
delete
newObj
.
infoForCell
await
dispatch
(
editCalendarTask
(
newObj
))
delete
newTask
.
id
delete
newTask
.
infoForCell
await
dispatch
(
editCalendarTask
(
newTask
))
setCurrentTask
({})
}
...
...
@@ -151,15 +153,26 @@ function MonthCalendar() {
const
day
=
currentTask
.
infoForCell
.
startDay
const
due
=
dateToISOLikeButLocal
(
new
Date
(
dateNow
.
year
,
dateNow
.
month
,
day
,
timeEndHour
-
1
,
59
))
const
start
=
dateToISOLikeButLocal
(
new
Date
(
dateNow
.
year
,
dateNow
.
month
,
day
,
timeStartHour
,
0
))
const
newTask
=
{
...
currentTask
,
dateTimeStart
:
start
,
dateTimeDue
:
due
}
delete
newTask
.
infoForCell
if
(
currentTask
.
id
)
{
const
newTask
=
{
...
currentTask
,
dateTimeStart
:
start
,
dateTimeDue
:
due
,
dateTimeTaskId
:
currentTask
.
id
,
taskId
:
currentTask
.
mainTaskId
}
delete
newTask
.
infoForCell
delete
newTask
.
id
await
dispatch
(
editCalendarTask
(
newTask
))
}
else
{
const
newTask
=
{
...
currentTask
,
dateTimeStart
:
start
,
dateTimeDue
:
due
,
executor
:
user
,
}
delete
newTask
.
infoForCell
delete
newTask
.
id
await
dispatch
(
addCalendarTask
(
newTask
))
}
}
...
...
@@ -178,10 +191,11 @@ function MonthCalendar() {
...
copyTask
,
dateTimeStart
:
start
,
dateTimeDue
:
due
,
taskId
:
copyTask
.
mainTaskId
}
delete
newTask
.
infoForCell
delete
newTask
.
id
await
dispatch
(
addCalendarTask
(
newTask
))
await
dispatch
(
addC
opyC
alendarTask
(
newTask
))
setCopyTask
(
null
)
}
...
...
planner-front/src/store/actions/tasksActions.js
View file @
c8d15d28
...
...
@@ -71,10 +71,23 @@ const addTaskFailure = (error) => {
};
export
const
addCalendarTask
=
(
task
)
=>
{
return
async
(
dispatch
,
getState
)
=>
{
return
async
(
dispatch
)
=>
{
dispatch
(
addTaskRequest
());
try
{
await
axios
.
post
(
"/tasks"
,
task
);
const
response
=
await
axios
.
post
(
"/tasks"
,
task
);
dispatch
(
addTaskSuccess
())
dispatch
(
fetchCalendarTasks
())
}
catch
(
error
)
{
dispatch
(
addTaskFailure
(
error
.
response
.
data
));
}
}
}
export
const
addCopyCalendarTask
=
(
task
)
=>
{
return
async
(
dispatch
)
=>
{
dispatch
(
addTaskRequest
());
try
{
const
response
=
await
axios
.
post
(
"/copy-tasks/make-copy"
,
task
);
dispatch
(
addTaskSuccess
())
dispatch
(
fetchCalendarTasks
())
}
catch
(
error
)
{
...
...
@@ -84,7 +97,7 @@ export const addCalendarTask = (task) => {
}
export
const
addTask
=
(
task
)
=>
{
return
async
(
dispatch
,
getState
)
=>
{
return
async
(
dispatch
)
=>
{
dispatch
(
addTaskRequest
());
try
{
await
axios
.
post
(
"/tasks"
,
task
);
...
...
@@ -109,7 +122,7 @@ const editTaskFailure = (error) => {
};
export
const
editTask
=
(
task
)
=>
{
return
async
(
dispatch
,
getState
)
=>
{
return
async
(
dispatch
)
=>
{
dispatch
(
editTaskRequest
());
try
{
await
axios
.
put
(
"/tasks"
,
task
);
...
...
@@ -122,10 +135,10 @@ export const editTask = (task) => {
}
export
const
editCalendarTask
=
(
task
)
=>
{
return
async
(
dispatch
,
getState
)
=>
{
return
async
(
dispatch
)
=>
{
dispatch
(
editTaskRequest
());
try
{
await
axios
.
put
(
"/
tasks
"
,
task
);
await
axios
.
put
(
"/
copy-tasks/change-copy
"
,
task
);
dispatch
(
editTaskSuccess
())
dispatch
(
fetchCalendarTasks
())
}
catch
(
error
)
{
...
...
@@ -147,7 +160,7 @@ const deleteTaskFailure = (error) => {
};
export
const
deleteTask
=
(
taskId
)
=>
{
return
async
(
dispatch
,
getState
)
=>
{
return
async
(
dispatch
)
=>
{
dispatch
(
deleteTaskRequest
());
try
{
await
axios
.
delete
(
`/tasks/
${
taskId
}
`
);
...
...
@@ -160,10 +173,10 @@ export const deleteTask = (taskId) => {
}
export
const
deleteCalendarTask
=
(
taskId
)
=>
{
return
async
(
dispatch
,
getState
)
=>
{
return
async
(
dispatch
)
=>
{
dispatch
(
deleteTaskRequest
());
try
{
await
axios
.
delete
(
`/tasks/
${
taskId
}
`
);
await
axios
.
delete
(
`/
copy-
tasks/
${
taskId
}
`
);
dispatch
(
deleteTaskSuccess
())
dispatch
(
fetchCalendarTasks
())
}
catch
(
error
)
{
...
...
planner-front/src/store/reducers/tasksReducer.js
View file @
c8d15d28
...
...
@@ -29,37 +29,51 @@ const tasksReduсer = (state = initialState, action) => {
case
FETCH_CALENDAR_TASKS_REQUEST
:
return
{...
state
,
loading
:
true
};
case
FETCH_CALENDAR_TASKS_SUCCESS
:
const
newArr
=
[]
action
.
tasks
.
forEach
((
task
)
=>
{
if
(
task
.
dateTimeStart
&&
task
.
dateTimeDue
)
{
if
(
new
Date
(
task
.
dateTimeDue
).
getTime
()
-
new
Date
(
task
.
dateTimeStart
).
getTime
()
<
(
24
*
3600000
)
&&
new
Date
(
task
.
dateTimeDue
).
getTime
()
-
new
Date
(
task
.
dateTimeStart
).
getTime
()
>
0
)
{
const
dateStart
=
task
.
dateTimeStart
.
split
(
'T'
)[
0
]
const
timeStart
=
task
.
dateTimeStart
.
split
(
'T'
)[
1
]
const
timeEnd
=
task
.
dateTimeDue
.
split
(
'T'
)[
1
]
const
dayStart
=
parseInt
(
dateStart
.
split
(
'-'
)[
2
])
const
monthStartNumber
=
parseInt
(
dateStart
.
split
(
'-'
)[
1
])
const
yearStartNumber
=
parseInt
(
dateStart
.
split
(
'-'
)[
0
])
const
timeStartHour
=
parseInt
(
timeStart
.
split
(
':'
)[
0
])
const
timeEndHour
=
parseInt
(
timeEnd
.
split
(
':'
)[
0
])
const
timeStartMinute
=
parseInt
(
timeStart
.
split
(
':'
)[
1
])
const
timeEndMinute
=
parseInt
(
timeEnd
.
split
(
':'
)[
1
])
const
newObj
=
{...
task
,
infoForCell
:
{
startDay
:
dayStart
,
startHour
:
timeStartHour
,
startMonth
:
monthStartNumber
,
startYear
:
yearStartNumber
,
startMinute
:
timeStartMinute
,
endHour
:
timeEndHour
,
endMinute
:
timeEndMinute
,
}
}
newArr
.
push
(
newObj
)
}
}
const
newTasksWithoutInfoForCell
=
[]
const
newTasksWithInfoForCell
=
[]
for
(
let
task
of
action
.
tasks
)
{
for
(
let
copy
of
task
.
dateTimeTasks
)
{
newTasksWithoutInfoForCell
.
push
({
...
copy
,
mainTaskId
:
task
.
id
,
executor
:
task
.
executor
,
author
:
task
.
author
,
priority
:
task
.
priority
,
title
:
task
.
title
,
description
:
task
.
description
})
return
{...
state
,
loading
:
false
,
calendarTasks
:
newArr
};
}
}
newTasksWithoutInfoForCell
.
forEach
((
task
)
=>
{
if
(
task
.
dateTimeStart
&&
task
.
dateTimeDue
)
{
if
(
new
Date
(
task
.
dateTimeDue
).
getTime
()
-
new
Date
(
task
.
dateTimeStart
).
getTime
()
<
(
24
*
3600000
)
&&
new
Date
(
task
.
dateTimeDue
).
getTime
()
-
new
Date
(
task
.
dateTimeStart
).
getTime
()
>
0
)
{
const
dateStart
=
task
.
dateTimeStart
.
split
(
'T'
)[
0
]
const
timeStart
=
task
.
dateTimeStart
.
split
(
'T'
)[
1
]
const
timeEnd
=
task
.
dateTimeDue
.
split
(
'T'
)[
1
]
const
dayStart
=
parseInt
(
dateStart
.
split
(
'-'
)[
2
])
const
monthStartNumber
=
parseInt
(
dateStart
.
split
(
'-'
)[
1
])
const
yearStartNumber
=
parseInt
(
dateStart
.
split
(
'-'
)[
0
])
const
timeStartHour
=
parseInt
(
timeStart
.
split
(
':'
)[
0
])
const
timeEndHour
=
parseInt
(
timeEnd
.
split
(
':'
)[
0
])
const
timeStartMinute
=
parseInt
(
timeStart
.
split
(
':'
)[
1
])
const
timeEndMinute
=
parseInt
(
timeEnd
.
split
(
':'
)[
1
])
const
newObj
=
{...
task
,
infoForCell
:
{
startDay
:
dayStart
,
startHour
:
timeStartHour
,
startMonth
:
monthStartNumber
,
startYear
:
yearStartNumber
,
startMinute
:
timeStartMinute
,
endHour
:
timeEndHour
,
endMinute
:
timeEndMinute
,
}
}
newTasksWithInfoForCell
.
push
(
newObj
)
}
}
})
return
{...
state
,
loading
:
false
,
calendarTasks
:
newTasksWithInfoForCell
};
case
FETCH_ALL_TASKS_SUCCESS
:
return
{...
state
,
loading
:
false
,
tasks
:
action
.
tasks
};
case
FETCH_CALENDAR_TASKS_FAILURE
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment