Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ehasa-frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WIMMA Lab 2019
Overflow
ehasa-frontend
Commits
5cc29937
Commit
5cc29937
authored
5 years ago
by
Joni Laukka
Browse files
Options
Downloads
Patches
Plain Diff
edit game form update
parent
aec22e47
No related branches found
Branches containing commit
No related tags found
2 merge requests
!26
Development
,
!22
Join, edit game form
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/EditGameForm.js
+71
-26
71 additions, 26 deletions
src/components/EditGameForm.js
src/components/RegisterForm.js
+1
-1
1 addition, 1 deletion
src/components/RegisterForm.js
with
72 additions
and
27 deletions
src/components/EditGameForm.js
+
71
−
26
View file @
5cc29937
...
...
@@ -13,17 +13,19 @@ export class EditGameForm extends React.Component {
startTime
:
""
,
endDate
:
""
,
endTime
:
""
,
zoom
:
13
,
map
:
""
,
mapCenter
:
{
lat
:
62.2416479
,
lng
:
25.7597186
},
factionNameInput
:
""
,
factionPasswordInput
:
""
,
factions
:
[{
name
:
"
Overflow
"
,
password
:
"
Wimma
"
}]
factions
:
[],
objectivePoints
:
[]
// {
// objectivePointDescription: "",
// objectivePointMultiplier: ""
// }
};
this
.
handleMapDrag
=
this
.
handleMapDrag
.
bind
(
this
);
...
...
@@ -45,11 +47,16 @@ export class EditGameForm extends React.Component {
return
alert
(
"
Faction needs a name and password
"
);
}
if
(
this
.
state
.
factions
.
findIndex
(
faction
=>
faction
.
factionName
===
this
.
state
.
factionNameInput
)
!==
-
1
){
return
alert
(
"
Faction
"
+
this
.
state
.
factionNameInput
+
"
already exists
"
);
}
this
.
setState
(
state
=>
{
let
factions
=
state
.
factions
;
factions
.
push
({
name
:
this
.
state
.
factionNameInput
,
password
:
this
.
state
.
factionPasswordInput
factionName
:
this
.
state
.
factionNameInput
,
factionPassword
:
this
.
state
.
factionPasswordInput
,
multiplier
:
1
});
return
{
factions
:
factions
,
...
...
@@ -59,6 +66,31 @@ export class EditGameForm extends React.Component {
})
}
handleGameDeletion
=
e
=>
{
e
.
preventDefault
();
let
token
=
sessionStorage
.
getItem
(
"
token
"
);
if
(
window
.
confirm
(
"
Are you sure you want to delete this game
"
)){
alert
(
"
Game deleted
"
);
fetch
(
`
${
process
.
env
.
REACT_APP_URL
}
/game/
${
this
.
props
.
gameId
}
`
,{
method
:
"
DELETE
"
,
headers
:
{
Authorization
:
"
Bearer
"
+
token
,
Accept
:
"
application/json
"
,
"
Content-Type
"
:
"
application/json
"
},
})
.
then
(
result
=>
result
.
json
())
.
then
(
result
=>
{
console
.
log
(
result
);
this
.
handleView
();
})
.
catch
(
error
=>
console
.
log
(
error
));
}
}
// show/hide this form
handleView
=
e
=>
{
this
.
props
.
toggleView
(
this
.
props
.
view
);
...
...
@@ -84,8 +116,7 @@ export class EditGameForm extends React.Component {
};
handleGameSave
=
e
=>
{
let
startDate
=
this
.
state
.
startDate
+
"
T
"
+
this
.
state
.
startTime
+
"
:00.000Z
"
;
let
startDate
=
this
.
state
.
startDate
+
"
T
"
+
this
.
state
.
startTime
+
"
:00.000Z
"
;
let
endDate
=
this
.
state
.
endDate
+
"
T
"
+
this
.
state
.
endTime
+
"
:00.000Z
"
;
const
gameObject
=
{
...
...
@@ -94,7 +125,9 @@ export class EditGameForm extends React.Component {
map
:
""
,
startdate
:
startDate
,
enddate
:
endDate
,
center
:
this
.
state
.
mapCenter
center
:
this
.
state
.
mapCenter
,
factions
:
this
.
state
.
factions
,
objective_points
:
this
.
state
.
objectivePoints
};
e
.
preventDefault
();
...
...
@@ -143,18 +176,26 @@ export class EditGameForm extends React.Component {
startTime
:
json
.
startdate
.
substring
(
11
,
16
),
endDate
:
json
.
enddate
.
substring
(
0
,
10
),
endTime
:
json
.
enddate
.
substring
(
11
,
16
),
zoom
:
13
,
mapCenter
:
{
lat
:
json
.
center
.
lat
,
lng
:
json
.
center
.
lng
}
},
factions
:
json
.
factions
,
objectivePoints
:
json
.
objective_points
});
}
removeFaction
(
index
){
removeFaction
(
factionName
){
this
.
setState
(
state
=>
{
let
factions
=
state
.
factions
;
factions
.
splice
(
index
,
1
);
const
index
=
factions
.
findIndex
(
faction
=>
faction
.
factionName
===
factionName
);
if
(
index
!==
-
1
){
factions
.
splice
(
index
,
1
);
}
else
{
console
.
log
(
"
Faction is not in the faction list
"
);
}
return
factions
;
});
...
...
@@ -167,8 +208,8 @@ export class EditGameForm extends React.Component {
const
faction
=
this
.
state
.
factions
[
i
];
factions
.
push
(
<
Fragment
>
<
li
key
=
{
i
}
>
{
faction
.
n
ame
}
:
{
faction
.
p
assword
}
<
/li
>
<
button
onClick
=
{()
=>
this
.
removeFaction
(
i
)}
>
Remove
<
/button
>
<
li
key
=
{
faction
.
factionName
}
>
{
faction
.
factionN
ame
}
:
{
faction
.
factionP
assword
}
<
/li
>
<
button
type
=
"
button
"
onClick
=
{()
=>
this
.
removeFaction
(
faction
.
factionName
)}
>
Remove
<
/button
>
<
/Fragment
>
);
}
...
...
@@ -186,8 +227,9 @@ export class EditGameForm extends React.Component {
<
/div
>
<
div
className
=
""
>
<
form
id
=
"
game
Creation
Form
"
onSubmit
=
{
this
.
handleGame
Creation
}
><
/form
>
<
form
id
=
"
game
Edit
Form
"
onSubmit
=
{
this
.
handleGame
Save
}
><
/form
>
<
form
id
=
"
factionAddFrom
"
onSubmit
=
{
this
.
handleFactionAdd
}
><
/form
>
<
form
id
=
"
gameDeletionForm
"
onSubmit
=
{
this
.
handleGameDeletion
}
><
/form
>
<
form
onSubmit
=
{
this
.
handleGameSave
}
>
<
h1
>
Demo
Game
Editor
<
/h1
>
...
...
@@ -198,7 +240,7 @@ export class EditGameForm extends React.Component {
value
=
{
this
.
state
.
gamename
}
onChange
=
{
this
.
handleChange
}
id
=
"
editGameNameInput
"
form
=
"
game
Creation
Form
"
form
=
"
game
Edit
Form
"
required
/>
<
br
/>
...
...
@@ -209,7 +251,7 @@ export class EditGameForm extends React.Component {
value
=
{
this
.
state
.
description
}
onChange
=
{
this
.
handleChange
}
id
=
"
editGameDescriptionInput
"
form
=
"
game
Creation
Form
"
form
=
"
game
Edit
Form
"
required
/>
<
br
/>
...
...
@@ -221,7 +263,7 @@ export class EditGameForm extends React.Component {
value
=
{
this
.
state
.
startDate
}
onChange
=
{
this
.
handleChange
}
id
=
"
editGameDateStartInput
"
form
=
"
game
Creation
Form
"
form
=
"
game
Edit
Form
"
required
/>
<
input
...
...
@@ -231,7 +273,7 @@ export class EditGameForm extends React.Component {
value
=
{
this
.
state
.
startTime
}
onChange
=
{
this
.
handleChange
}
sid
=
"
editGameTimeStartInput
"
form
=
"
game
Creation
Form
"
form
=
"
game
Edit
Form
"
required
/>
<
br
/>
...
...
@@ -244,7 +286,7 @@ export class EditGameForm extends React.Component {
onChange
=
{
this
.
handleChange
}
min
=
{
this
.
state
.
startDate
}
id
=
"
editGameDateEndInput
"
form
=
"
game
Creation
Form
"
form
=
"
game
Edit
Form
"
required
/>
<
input
...
...
@@ -254,7 +296,7 @@ export class EditGameForm extends React.Component {
value
=
{
this
.
state
.
endTime
}
onChange
=
{
this
.
handleChange
}
id
=
"
editGameTimeEndInput
"
form
=
"
game
Creation
Form
"
form
=
"
game
Edit
Form
"
required
/>
<
br
/>
...
...
@@ -275,10 +317,10 @@ export class EditGameForm extends React.Component {
id
=
"
editGameCenterMap
"
className
=
""
center
=
{[
this
.
state
.
mapCenter
.
lat
,
this
.
state
.
mapCenter
.
lng
]}
zoom
=
{
this
.
state
.
zoom
}
zoom
=
"
13
"
style
=
{{
height
:
"
400px
"
,
width
:
"
400px
"
}}
onmoveend
=
{
this
.
handleMapDrag
}
onzoomend
=
{
this
.
handleMapScroll
}
//
onzoomend={this.handleMapScroll}
>
<
TileLayer
attribution
=
"
Maanmittauslaitoksen kartta
"
...
...
@@ -286,7 +328,10 @@ export class EditGameForm extends React.Component {
/>
<
/Map
>
<
br
/>
<
button
id
=
"
editGameSubmitButton
"
type
=
"
submit
"
form
=
"
gameCreationForm
"
>
<
button
style
=
{{
backgroundColor
:
"
red
"
}}
type
=
"
submit
"
form
=
"
gameDeletionForm
"
>
Delete
<
/button
>
<
button
id
=
"
editGameSubmitButton
"
type
=
"
submit
"
form
=
"
gameEditForm
"
>
Save
changes
<
/button
>
<
h2
>
{
this
.
state
.
errorMsg
}
<
/h2
>
...
...
This diff is collapsed.
Click to expand it.
src/components/RegisterForm.js
+
1
−
1
View file @
5cc29937
...
...
@@ -62,7 +62,7 @@ export class RegisterForm extends React.Component {
this
.
props
.
handleState
(
result
);
this
.
handleView
();
}
else
{
this
.
handleError
(
result
.
errorResponse
.
message
);
this
.
handleError
(
result
.
message
);
}
},
// Note: it's important to handle errors here
...
...
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