Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
API Toucan
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Damien Armillon
API Toucan
Commits
948a089a
Commit
948a089a
authored
6 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
Change gestion des erreurs
parent
72cca50e
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
backend/routes/routesToucan.js
+1
-1
1 addition, 1 deletion
backend/routes/routesToucan.js
front/src/App.js
+11
-9
11 additions, 9 deletions
front/src/App.js
front/src/FormToucan.js
+43
-11
43 additions, 11 deletions
front/src/FormToucan.js
with
55 additions
and
21 deletions
backend/routes/routesToucan.js
+
1
−
1
View file @
948a089a
...
...
@@ -42,7 +42,7 @@ router.route("/toucans")
var
newPath
=
file
.
destination
+
"
/
"
+
id
+
extension
;
fs
.
rename
(
file
.
path
,
newPath
,
err
=>
{
if
(
err
)
{
res
.
err
(
err
);
res
.
status
(
400
).
send
(
err
);
}
});
}
...
...
This diff is collapsed.
Click to expand it.
front/src/App.js
+
11
−
9
View file @
948a089a
import
React
from
'
react
'
;
import
{
Segment
}
from
'
semantic-ui-react
'
;
import
{
Segment
,
SegmentGroup
}
from
'
semantic-ui-react
'
;
import
ToucanTable
from
'
./ToucanTable
'
;
import
FormToucan
from
'
./FormToucan
'
import
'
./App.css
'
;
function
App
()
{
return
(
<
div
>
<
Segment
.
Group
>
<
Segment
padded
style
=
{{
margin
:
"
3%
"
}}
>
<
h2
style
=
{{
textAlign
:
"
center
"
}}
>
Rajout
de
Toucan
<
/h2
>
<
FormToucan
/>
<
/Segment
>
<
Segment
textAlign
=
"
center
"
padded
style
=
{{
margin
:
"
3%
"
}}
>
<
ToucanTable
/>
<
h2
>
Les
Toucans
<
/h2
>
<
ToucanTable
style
=
{{
margin
:
"
50px
"
}}
/
>
<
/Segment
>
<
/
div
>
<
/
Segment.Group
>
);
}
...
...
This diff is collapsed.
Click to expand it.
front/src/FormToucan.js
+
43
−
11
View file @
948a089a
...
...
@@ -19,6 +19,8 @@ class FormToucan extends Component {
dateShown
:
""
,
date
:
undefined
,
responseMessage
:
""
,
}
}
...
...
@@ -54,6 +56,7 @@ class FormToucan extends Component {
}
onSubmit
=
()
=>
{
this
.
setState
({
responseMessage
:
""
});
const
{
date
,
title
,
toucan
,
cover
}
=
this
.
state
;
const
form
=
new
FormData
()
...
...
@@ -66,8 +69,24 @@ class FormToucan extends Component {
method
:
'
POST
'
,
body
:
form
})
.
then
(()
=>
window
.
location
.
reload
())
.
catch
((
err
)
=>
console
.
log
(
err
))
.
then
((
response
)
=>
{
if
(
response
.
ok
)
{
window
.
location
.
reload
()
}
else
{
try
{
response
.
json
().
then
((
json
)
=>
{
if
(
json
.
errmsg
.
split
(
"
"
)[
0
]
===
"
E11000
"
){
// L'erreur la plus probable
this
.
setState
({
responseMessage
:
"
La date sélectionnée existe déjà
"
})
}
else
{
this
.
setState
({
responseMessage
:
json
.
errmsg
})
}
});
}
catch
{
response
.
text
().
then
(
text
=>
this
.
setState
({
responseMessage
:
text
}))
}};
}
)
.
catch
((
err
)
=>
this
.
setState
({
responseMessage
:
err
}))
}
render
()
{
...
...
@@ -78,8 +97,11 @@ class FormToucan extends Component {
const
formError
=
errorMessage
.
length
!==
0
;
//Le formulaire a une erreur si errorMessage a au moins 1 erreure
return
(
<
div
>
<
Form
error
=
{
formError
}
onSubmit
=
{
this
.
onSubmit
}
>
<
Form
.
Group
style
=
{{
margin
:
"
auto
"
}}
>
<
Form
.
Input
style
=
{{
height
:
"
inherit
"
}}
type
=
"
text
"
label
=
"
Thème Toucan
"
placeholder
=
"
Thème
"
...
...
@@ -90,6 +112,19 @@ class FormToucan extends Component {
required
/>
<
DateInput
style
=
{{
width
:
"
10em
"
,}}
pickerStyle
=
{{
active
:{
backgroundColor
:
"
red
"
}}}
hideMobileKeyboard
label
=
"
Date
"
localization
=
"
fr
"
name
=
"
date
"
onChange
=
{
this
.
onDateChange
}
value
=
{
this
.
state
.
dateShown
}
required
/>
<
/Form.Group
>
<
Form
.
Group
>
<
Form
.
Input
label
=
"
PDF du Toucan
"
onChange
=
{
this
.
onFileChange
}
...
...
@@ -107,22 +142,19 @@ class FormToucan extends Component {
accept
=
"
image/png, image/jpeg
"
required
/>
<
DateInput
label
=
"
Date
"
localization
=
"
fr
"
name
=
"
date
"
onChange
=
{
this
.
onDateChange
}
value
=
{
this
.
state
.
dateShown
}
required
/>
<
Form
.
Button
disabled
=
{
formError
}
content
=
"
C'est parti !
"
/>
<
/Form.Group
>
<
Message
error
header
=
"
Formulaire incomplet
"
content
=
{
<
ul
>
{
errorMessage
.
map
((
err
)
=>
{
return
<
li
>
{
err
}
<
/li>}
)
}
<
/ul
>
}
/
>
<
Form
.
Button
disabled
=
{
formError
}
content
=
"
C'est parti !
"
/>
<
/Form
>
{
console
.
log
(
this
.
state
.
responseMessage
)}
{
this
.
state
.
responseMessage
?
<
Message
negative
header
=
"
Erreur Serveur
"
content
=
{
this
.
state
.
responseMessage
}
><
/Message>: null
}
<
/div
>
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment