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
cce9a6c8
Commit
cce9a6c8
authored
Nov 07, 2022
by
Ermolaev Timur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#28
реализовал создание таска через бекенд
parent
6a7323c0
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
74 additions
and
75 deletions
+74
-75
Task.ts
planner-api/src/models/Task.ts
+2
-2
MonthCalendarBody.js
...ont/src/components/MonthCalendarBody/MonthCalendarBody.js
+5
-19
MonthCalendar.js
planner-front/src/containers/MonthCalendar/MonthCalendar.js
+27
-18
tasksTypes.js
planner-front/src/store/actionTypes/tasksTypes.js
+3
-1
tasksActions.js
planner-front/src/store/actions/tasksActions.js
+32
-27
tasksReducer.js
planner-front/src/store/reducers/tasksReducer.js
+5
-8
No files found.
planner-api/src/models/Task.ts
View file @
cce9a6c8
...
@@ -36,9 +36,9 @@ import {
...
@@ -36,9 +36,9 @@ import {
description
!
:
string
description
!
:
string
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
createdAt
!
:
Date
;
createdAt
!
:
Date
;
@
Column
({
name
:
'dateTimeStart'
,
type
:
Date
,
nullable
:
true
})
@
Column
({
name
:
'dateTimeStart'
,
type
:
'varchar'
,
nullable
:
true
})
dateTimeStart
!
:
Date
|
null
;
dateTimeStart
!
:
Date
|
null
;
@
Column
({
name
:
'dateTimeDue'
,
type
:
Date
,
nullable
:
true
})
@
Column
({
name
:
'dateTimeDue'
,
type
:
'varchar'
,
nullable
:
true
})
dateTimeDue
!
:
Date
|
null
;
dateTimeDue
!
:
Date
|
null
;
@
Column
({
@
Column
({
type
:
"enum"
,
type
:
"enum"
,
...
...
planner-front/src/components/MonthCalendarBody/MonthCalendarBody.js
View file @
cce9a6c8
import
{
Grid
,
TextField
}
from
"@mui/material"
;
import
{
Grid
,
TextField
}
from
"@mui/material"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useDispatch
}
from
"react-redux"
;
import
{
setNewTasksForCells
}
from
"../../store/actions/tasksActions"
;
function
MonthCalendarBody
({
month
,
year
,
tasks
,
createTaskInCellHandler
})
{
function
MonthCalendarBody
({
month
,
year
,
tasks
,
createTaskInCellHandler
,
onChangeCellTaskTitle
,
setCurrentTask
})
{
const
[
hoursInDay
,
setHoursInDay
]
=
useState
([
'8:00'
,
'10:00'
,
'12:00'
,
'14:00'
,
'16:00'
,
'18:00'
,
'20:00'
,
'22:00'
,
'6:00'
])
const
[
hoursInDay
,
setHoursInDay
]
=
useState
([
'8:00'
,
'10:00'
,
'12:00'
,
'14:00'
,
'16:00'
,
'18:00'
,
'20:00'
,
'22:00'
,
'6:00'
])
const
[
daysInMonth
,
setDaysInMonth
]
=
useState
([])
const
[
daysInMonth
,
setDaysInMonth
]
=
useState
([])
...
@@ -38,7 +36,7 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler}) {
...
@@ -38,7 +36,7 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler}) {
if
(
year
===
task
.
infoForCell
.
startYear
)
{
if
(
year
===
task
.
infoForCell
.
startYear
)
{
if
(
month
+
1
===
task
.
infoForCell
.
startMonth
)
{
if
(
month
+
1
===
task
.
infoForCell
.
startMonth
)
{
if
(
day
.
dayNumber
===
task
.
infoForCell
.
startDay
&&
task
.
infoForCell
.
startDayOfWeek
===
day
.
dayOfWeek
)
{
if
(
day
.
dayNumber
===
task
.
infoForCell
.
startDay
&&
task
.
infoForCell
.
startDayOfWeek
===
day
.
dayOfWeek
)
{
if
((
task
.
infoForCell
.
endHour
<=
parseInt
(
hours
.
split
(
':'
)[
0
])
||
task
.
infoForCell
.
startHour
<=
parseInt
(
hours
.
split
(
':'
)[
0
]))
&&
(
task
.
infoForCell
.
endHour
>
=
parseInt
(
hours
.
split
(
':'
)[
0
])))
{
if
((
task
.
infoForCell
.
endHour
<=
parseInt
(
hours
.
split
(
':'
)[
0
])
||
task
.
infoForCell
.
startHour
<=
parseInt
(
hours
.
split
(
':'
)[
0
]))
&&
(
task
.
infoForCell
.
endHour
>
parseInt
(
hours
.
split
(
':'
)[
0
])))
{
return
task
return
task
}
}
}
}
...
@@ -48,19 +46,6 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler}) {
...
@@ -48,19 +46,6 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler}) {
return
task
return
task
}
}
const
onChangeCellTaskTitle
=
(
e
,
task
)
=>
{
const
value
=
e
.
target
.
value
;
const
name
=
e
.
target
.
name
;
const
{
id
}
=
task
;
const
newTasks
=
tasks
.
map
(
task
=>
{
if
(
task
.
id
===
id
)
{
return
{
...
task
,
[
name
]:
value
};
}
return
task
;
});
setNewTasksForCells
(
newTasks
)
}
return
(
return
(
<>
<>
<
Grid
<
Grid
...
@@ -103,7 +88,7 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler}) {
...
@@ -103,7 +88,7 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler}) {
key
=
{
i
}
key
=
{
i
}
item
xs
=
{
1.2222
}
item
xs
=
{
1.2222
}
sx
=
{{
borderRight
:
'1px solid black'
}}
sx
=
{{
borderRight
:
'1px solid black'
}}
onClick
=
{()
=>
{
createTaskInCellHandler
(
day
.
day
OfWeek
,
day
.
day
Number
,
hours
)}}
>
onClick
=
{()
=>
{
createTaskInCellHandler
(
day
.
dayNumber
,
hours
)}}
>
{
task
?
{
task
?
<
Grid
key
=
{
i
}
sx
=
{{
backgroundColor
:
'lightgreen'
}}
>
<
Grid
key
=
{
i
}
sx
=
{{
backgroundColor
:
'lightgreen'
}}
>
<
TextField
<
TextField
...
@@ -111,7 +96,8 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler}) {
...
@@ -111,7 +96,8 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler}) {
variant
=
"standard"
variant
=
"standard"
value
=
{
task
.
title
}
value
=
{
task
.
title
}
name
=
'title'
name
=
'title'
onChange
=
{(
e
)
=>
{
onChangeCellTaskTitle
(
e
,
task
)}}
><
/TextField
>
onClick
=
{(
e
)
=>
{
e
.
stopPropagation
();
setCurrentTask
(
task
)}}
onChange
=
{(
e
)
=>
{
onChangeCellTaskTitle
(
e
)}}
><
/TextField
>
<
/Grid> : null
}
<
/Grid> : null
}
<
/Grid
>
<
/Grid
>
)
)
...
...
planner-front/src/containers/MonthCalendar/MonthCalendar.js
View file @
cce9a6c8
import
{
Container
}
from
'@mui/material'
;
import
{
Container
}
from
'@mui/material'
;
import
moment
from
'moment'
;
import
{
useEffect
,
useState
}
from
'react'
;
import
{
useEffect
,
useState
}
from
'react'
;
import
{
useDispatch
,
useSelector
}
from
'react-redux'
;
import
{
useDispatch
,
useSelector
}
from
'react-redux'
;
import
MonthCalendarBody
from
'../../components/MonthCalendarBody/MonthCalendarBody'
;
import
MonthCalendarBody
from
'../../components/MonthCalendarBody/MonthCalendarBody'
;
import
MonthCalendarHeader
from
'../../components/MonthCalendarHeader/MonthCalendarHeader'
;
import
MonthCalendarHeader
from
'../../components/MonthCalendarHeader/MonthCalendarHeader'
;
import
{
fetchTasks
}
from
'../../store/actions/tasksActions'
;
import
{
addTask
,
fetchTasks
}
from
'../../store/actions/tasksActions'
;
function
MonthCalendar
()
{
function
MonthCalendar
()
{
const
dispatch
=
useDispatch
();
const
dispatch
=
useDispatch
();
...
@@ -13,13 +14,14 @@ function MonthCalendar() {
...
@@ -13,13 +14,14 @@ function MonthCalendar() {
const
[
year
,
setYear
]
=
useState
(
''
)
const
[
year
,
setYear
]
=
useState
(
''
)
const
[
worker
,
setWorker
]
=
useState
(
''
);
const
[
worker
,
setWorker
]
=
useState
(
''
);
const
[
calendarType
,
setCalendarType
]
=
useState
(
'Месяц'
);
const
[
calendarType
,
setCalendarType
]
=
useState
(
'Месяц'
);
const
[
currentTask
,
setCurrentTask
]
=
useState
({})
useEffect
(()
=>
{
useEffect
(()
=>
{
setMonth
(
new
Date
().
getMonth
())
setMonth
(
new
Date
().
getMonth
())
setYear
(
new
Date
().
getFullYear
())
setYear
(
new
Date
().
getFullYear
())
dispatch
(
fetchTasks
())
dispatch
(
fetchTasks
())
},
[
dispatch
])
},
[
dispatch
])
console
.
log
(
tasks
)
const
onChangeWorkerHandler
=
(
event
)
=>
{
const
onChangeWorkerHandler
=
(
event
)
=>
{
setWorker
(
event
.
target
.
value
);
setWorker
(
event
.
target
.
value
);
};
};
...
@@ -52,24 +54,29 @@ function MonthCalendar() {
...
@@ -52,24 +54,29 @@ function MonthCalendar() {
})
})
}
}
const
createTaskInCellHandler
=
(
dayOfWeek
,
dayNumber
,
dayHour
)
=>
{
function
dateToISOButLocal
(
date
)
{
// const newTasks = [...tasksForCell]
return
date
.
toLocaleString
(
'sv'
).
replace
(
' '
,
'T'
);
// const newTask = {
}
// id: Date.now(),
// user:"first",
const
createTaskInCellHandler
=
(
dayNumber
,
dayHour
)
=>
{
// title:"Новая",
const
hour
=
parseInt
(
dayHour
.
split
(
':'
)[
0
])
// description:"описание задачи11111",
const
newTask
=
{
// priority:"A",
title
:
"Задача"
,
// author:"Ivan",
description
:
"описание"
,
// executor:"Arman",
dateTimeStart
:
dateToISOButLocal
(
new
Date
(
year
,
month
,
dayNumber
,
hour
)),
// dateTimeStart:`${dayNumber}.${month+1}.${year} ${parseInt(dayHour.split(':')[0])}:00:00`,
dateTimeDue
:
dateToISOButLocal
(
new
Date
(
year
,
month
,
dayNumber
,
hour
+
2
)),
// dateTimeDue:`${dayNumber}.${month+1}.${year} ${parseInt(dayHour.split(':')[0]) + 1}:00:00`,
}
// }
dispatch
(
addTask
(
newTask
))
// newTasks.push(newTask)
setCurrentTask
((
newTask
))
// exampleTasks.push(newTask)
// setNewTasksWithInfoForCell(newTasks)
}
}
const
onChangeCellTaskTitle
=
(
e
)
=>
{
e
.
stopPropagation
()
const
value
=
e
.
target
.
value
;
const
name
=
e
.
target
.
name
;
setCurrentTask
({
...
currentTask
,
[
name
]:
value
})
}
console
.
log
(
tasks
)
return
(
return
(
<>
<>
<
Container
>
<
Container
>
...
@@ -89,6 +96,8 @@ function MonthCalendar() {
...
@@ -89,6 +96,8 @@ function MonthCalendar() {
year
=
{
year
}
year
=
{
year
}
tasks
=
{
tasks
}
tasks
=
{
tasks
}
createTaskInCellHandler
=
{
createTaskInCellHandler
}
createTaskInCellHandler
=
{
createTaskInCellHandler
}
onChangeCellTaskTitle
=
{
onChangeCellTaskTitle
}
setCurrentTask
=
{
setCurrentTask
}
/
>
/
>
<
/Container
>
<
/Container
>
<
/
>
<
/
>
...
...
planner-front/src/store/actionTypes/tasksTypes.js
View file @
cce9a6c8
...
@@ -2,4 +2,6 @@ export const FETCH_TASKS_REQUEST = "FETCH_TASKS_REQUEST";
...
@@ -2,4 +2,6 @@ export const FETCH_TASKS_REQUEST = "FETCH_TASKS_REQUEST";
export
const
FETCH_TASKS_SUCCESS
=
"FETCH_TASKS_SUCCESS"
;
export
const
FETCH_TASKS_SUCCESS
=
"FETCH_TASKS_SUCCESS"
;
export
const
FETCH_TASKS_FAILURE
=
"FETCH_TASKS_FAILURE"
;
export
const
FETCH_TASKS_FAILURE
=
"FETCH_TASKS_FAILURE"
;
export
const
SET_NEW_TASKS_FOR_CELLS
=
"SET_NEW_TASKS_FOR_CELLS"
;
export
const
ADD_NEW_TASK_REQUEST
=
"ADD_NEW_TASK_REQUEST"
;
\ No newline at end of file
export
const
ADD_NEW_TASK_SUCCESS
=
"ADD_NEW_TASK_SUCCESS"
;
export
const
ADD_NEW_TASK_FAILURE
=
"ADD_NEW_TASK_FAILURE"
;
\ No newline at end of file
planner-front/src/store/actions/tasksActions.js
View file @
cce9a6c8
import
{
FETCH_TASKS_FAILURE
,
FETCH_TASKS_REQUEST
,
FETCH_TASKS_SUCCESS
,
SET_NEW_TASKS_FOR_CELLS
}
from
"../actionTypes/tasksTypes"
;
import
{
ADD_NEW_TASK_FAILURE
,
ADD_NEW_TASK_REQUEST
,
ADD_NEW_TASK_SUCCESS
,
FETCH_TASKS_FAILURE
,
FETCH_TASKS_REQUEST
,
FETCH_TASKS_SUCCESS
}
from
"../actionTypes/tasksTypes"
;
import
axios
from
'../../axiosPlanner'
import
axios
from
'../../axiosPlanner'
const
fetchTasksRequest
=
()
=>
{
const
fetchTasksRequest
=
()
=>
{
...
@@ -12,40 +12,45 @@ const fetchTasksSuccess = (tasks) => {
...
@@ -12,40 +12,45 @@ const fetchTasksSuccess = (tasks) => {
const
fetchTasksFailure
=
(
error
)
=>
{
const
fetchTasksFailure
=
(
error
)
=>
{
return
{
type
:
FETCH_TASKS_FAILURE
,
error
}
return
{
type
:
FETCH_TASKS_FAILURE
,
error
}
};
};
export
const
setNewTasksForCells
=
(
tasks
)
=>
{
return
{
type
:
SET_NEW_TASKS_FOR_CELLS
,
tasks
}
}
export
const
fetchTasks
=
()
=>
{
export
const
fetchTasks
=
()
=>
{
return
async
(
dispatch
)
=>
{
return
async
(
dispatch
)
=>
{
dispatch
(
fetchTasksRequest
());
dispatch
(
fetchTasksRequest
());
try
{
try
{
const
response
=
await
axios
.
get
(
"/tasks"
);
const
response
=
await
axios
.
get
(
"/tasks"
);
const
arr
=
[
dispatch
(
fetchTasksSuccess
(
response
.
data
.
tasks
))
{
accomplish
:
"opened"
,
author
:
{
id
:
'f0e4a3bf-78fb-465b-9f28-620790750418'
,
name
:
'timur'
,
surname
:
'ermolaev'
,
displayName
:
'ermolaev t.'
,
email
:
'loool@mail.ru'
},
createdAt
:
"2022-11-07T11:35:30.937Z"
,
dateTimeDue
:
"2022-11-11T14:35:30.937Z"
,
dateTimeStart
:
"2022-11-11T11:35:30.937Z"
,
description
:
"lol"
,
id
:
"2fd828a2-3778-45fd-a11a-00d799db9142"
,
title
:
"task1"
,
},
{
accomplish
:
"opened"
,
author
:
{
id
:
'f0e4a3bf-78fb-465b-9f28-620790750418'
,
name
:
'timur'
,
surname
:
'ermolaev'
,
displayName
:
'ermolaev t.'
,
email
:
'loool@mail.ru'
},
createdAt
:
"2022-11-07T11:35:30.937Z"
,
dateTimeDue
:
"2022-11-25T16:00:00.937Z"
,
dateTimeStart
:
"2022-11-25T15:35:30.937Z"
,
description
:
"lol"
,
id
:
"2fd828a2-3778-45fd-a11a-00d799db9142"
,
title
:
"task2"
,
},
]
dispatch
(
fetchTasksSuccess
(
arr
))
setNewTasksForCells
()
}
catch
(
error
)
{
}
catch
(
error
)
{
dispatch
(
fetchTasksFailure
(
error
.
response
.
data
));
dispatch
(
fetchTasksFailure
(
error
.
response
.
data
));
}
}
}
}
}
}
const
addTaskRequest
=
()
=>
{
return
{
type
:
ADD_NEW_TASK_REQUEST
}
};
const
addTaskSuccess
=
()
=>
{
return
{
type
:
ADD_NEW_TASK_SUCCESS
}
};
const
addTaskFailure
=
(
error
)
=>
{
return
{
type
:
ADD_NEW_TASK_FAILURE
,
error
}
};
export
const
addTask
=
(
task
)
=>
{
return
async
(
dispatch
,
getState
)
=>
{
dispatch
(
addTaskRequest
());
const
token
=
getState
().
users
?.
user
?.
token
;
try
{
await
axios
.
post
(
"/tasks"
,
task
,
{
headers
:
{
'Authorization'
:
'aBhHYW8kXUUzjXlxOwGmg'
}
});
dispatch
(
addTaskSuccess
())
dispatch
(
fetchTasks
())
}
catch
(
error
)
{
dispatch
(
addTaskFailure
(
error
.
response
.
data
));
}
}
}
\ No newline at end of file
planner-front/src/store/reducers/tasksReducer.js
View file @
cce9a6c8
import
{
FETCH_TASKS_FAILURE
,
FETCH_TASKS_REQUEST
,
FETCH_TASKS_SUCCESS
,
SET_NEW_TASKS_FOR_CELLS
}
from
"../actionTypes/tasksTypes"
;
import
{
FETCH_TASKS_FAILURE
,
FETCH_TASKS_REQUEST
,
FETCH_TASKS_SUCCESS
}
from
"../actionTypes/tasksTypes"
;
const
initialState
=
{
const
initialState
=
{
tasks
:
[],
tasks
:
[],
...
@@ -11,7 +11,8 @@ const tasksReduсer = (state = initialState, action) => {
...
@@ -11,7 +11,8 @@ const tasksReduсer = (state = initialState, action) => {
case
FETCH_TASKS_REQUEST
:
case
FETCH_TASKS_REQUEST
:
return
{...
state
,
loading
:
true
};
return
{...
state
,
loading
:
true
};
case
FETCH_TASKS_SUCCESS
:
case
FETCH_TASKS_SUCCESS
:
const
newArr
=
action
.
tasks
.
map
((
task
)
=>
{
const
newArr
=
[]
action
.
tasks
.
forEach
((
task
)
=>
{
if
(
task
.
dateTimeStart
&&
task
.
dateTimeDue
)
{
if
(
task
.
dateTimeStart
&&
task
.
dateTimeDue
)
{
const
dateStart
=
task
.
dateTimeStart
.
split
(
'T'
)[
0
]
const
dateStart
=
task
.
dateTimeStart
.
split
(
'T'
)[
0
]
const
timeStart
=
task
.
dateTimeStart
.
split
(
'T'
)[
1
]
const
timeStart
=
task
.
dateTimeStart
.
split
(
'T'
)[
1
]
...
@@ -23,7 +24,7 @@ const tasksReduсer = (state = initialState, action) => {
...
@@ -23,7 +24,7 @@ const tasksReduсer = (state = initialState, action) => {
const
yearStartNumber
=
parseInt
(
dateStart
.
split
(
'-'
)[
0
])
const
yearStartNumber
=
parseInt
(
dateStart
.
split
(
'-'
)[
0
])
const
timeStartHour
=
parseInt
(
timeStart
.
split
(
':'
)[
0
])
const
timeStartHour
=
parseInt
(
timeStart
.
split
(
':'
)[
0
])
const
timeEndHour
=
parseInt
(
timeEnd
.
split
(
':'
)[
0
])
const
timeEndHour
=
parseInt
(
timeEnd
.
split
(
':'
)[
0
])
return
{...
task
,
infoForCell
:
{
newArr
.
push
(
{...
task
,
infoForCell
:
{
startDay
:
dayStart
,
startDay
:
dayStart
,
startDayOfWeek
:
dayOfWeekStartString
,
startDayOfWeek
:
dayOfWeekStartString
,
startHour
:
timeStartHour
,
startHour
:
timeStartHour
,
...
@@ -31,16 +32,12 @@ const tasksReduсer = (state = initialState, action) => {
...
@@ -31,16 +32,12 @@ const tasksReduсer = (state = initialState, action) => {
startYear
:
yearStartNumber
,
startYear
:
yearStartNumber
,
endHour
:
timeEndHour
,
endHour
:
timeEndHour
,
}
}
}
}
)
}
else
{
return
null
}
}
})
})
return
{...
state
,
loading
:
false
,
tasks
:
newArr
};
return
{...
state
,
loading
:
false
,
tasks
:
newArr
};
case
FETCH_TASKS_FAILURE
:
case
FETCH_TASKS_FAILURE
:
return
{...
state
,
loading
:
false
,
error
:
action
.
error
};
return
{...
state
,
loading
:
false
,
error
:
action
.
error
};
case
SET_NEW_TASKS_FOR_CELLS
:
return
{...
state
,
tasks
:
action
.
tasks
}
default
:
default
:
return
state
;
return
state
;
}
}
...
...
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