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
520ca40c
Commit
520ca40c
authored
5 years ago
by
Joni Laukka
Browse files
Options
Downloads
Patches
Plain Diff
Winner can be set to tasks
parent
792a6fea
No related branches found
No related tags found
2 merge requests
!26
Development
,
!19
Resolve "Tehtävälistan pohja"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/TaskItem.js
+66
-2
66 additions, 2 deletions
src/components/TaskItem.js
src/components/TaskList.js
+81
-10
81 additions, 10 deletions
src/components/TaskList.js
with
147 additions
and
12 deletions
src/components/TaskItem.js
+
66
−
2
View file @
520ca40c
import
React
from
'
react
'
;
class
TaskItem
extends
React
.
Component
{
constructor
(
props
){
super
(
props
);
this
.
state
=
{
edit
:
false
,
selectedFaction
:
""
,
factions
:
[]
}
}
componentDidMount
(){
this
.
getFactionlist
(
this
.
props
.
gameId
);
}
onEditClick
=
e
=>
{
this
.
setState
({
edit
:
!
this
.
state
.
edit
});
}
getFactionlist
(
gameId
){
fetch
(
`
${
process
.
env
.
REACT_APP_URL
}
/game/
${
gameId
}
`
,
{
method
:
'
GET
'
})
.
then
(
result
=>
result
.
json
())
.
then
(
result
=>
{
if
(
result
.
code
!==
undefined
){
console
.
log
(
result
);
}
else
{
this
.
setState
({
factions
:
result
.
factions
,
selectedFaction
:
result
.
factions
[
0
]
});
}
})
.
catch
(
error
=>
console
.
log
(
error
));
}
onSaveSubmit
=
e
=>
{
e
.
preventDefault
();
this
.
props
.
onSave
(
this
.
props
.
task
,
this
.
state
.
selectedFaction
);
this
.
setState
({
edit
:
false
})
}
handleFactionChange
=
e
=>
{
this
.
setState
({
selectedFaction
:
e
.
target
.
value
});
}
render
(){
return
(
<
div
className
=
'
tasklist-item
'
>
<
div
>
<
label
>
{
this
.
props
.
t
ext
}
<
/label
>
<
label
>
{
this
.
props
.
t
ask
.
taskName
}
<
/label
>
<
/div
>
<
div
>
<
label
>
{
this
.
props
.
description
}
<
/label
>
<
label
>
{
this
.
props
.
task
.
taskDescription
}
<
/label><br /
>
<
label
>
Faction
:
{
this
.
props
.
task
.
faction
!==
null
?
this
.
props
.
task
.
faction
.
factionName
:
"
Every faction
"
}
<
/label
>
<
/div
>
{
this
.
props
.
task
.
taskIsActive
&&
<
button
onClick
=
{
this
.
onEditClick
}
>
Edit
<
/button
>
}
{
this
.
state
.
edit
&&
<
form
onSubmit
=
{
this
.
onSaveSubmit
}
>
<
select
value
=
{
this
.
state
.
selectedFaction
}
onChange
=
{(
e
)
=>
this
.
setState
({
selectedFaction
:
e
.
target
.
value
})}
>
{
this
.
state
.
factions
.
map
((
item
)
=>
<
option
key
=
{
item
.
factionId
}
value
=
{
item
.
factionId
}
>
{
item
.
factionName
}
<
/option>
)
}
<
/select
>
<
button
type
=
"
submit
"
>
Save
<
/button
>
<
/form
>
}
<
/div
>
);
}
...
...
This diff is collapsed.
Click to expand it.
src/components/TaskList.js
+
81
−
10
View file @
520ca40c
...
...
@@ -8,12 +8,16 @@ class TaskList extends React.Component{
this
.
state
=
{
taskNameInput
:
""
,
// >= 3
taskDescriptionInput
:
""
,
// no limits
tasks
:
[]
tasks
:
[],
factionlist
:
[],
selectedFactionId
:
""
,
gameId
:
"
178cd342-9637-4481-ab81-d89585e9e006
"
// TODO: add this with props
}
}
componentDidMount
(){
this
.
getTasks
(
"
178cd342-9637-4481-ab81-d89585e9e006
"
);
this
.
getTasks
(
this
.
state
.
gameId
);
this
.
getFactionlist
(
this
.
state
.
gameId
)
// TODO: remove if the user is not admin?
}
getTasks
(
gameId
){
...
...
@@ -38,6 +42,24 @@ class TaskList extends React.Component{
.
catch
(
error
=>
console
.
log
(
error
));
}
getFactionlist
(
gameId
){
fetch
(
`
${
process
.
env
.
REACT_APP_URL
}
/game/
${
gameId
}
`
,
{
method
:
'
GET
'
})
.
then
(
result
=>
result
.
json
())
.
then
(
result
=>
{
if
(
result
.
code
!==
undefined
){
console
.
log
(
result
);
}
else
{
this
.
setState
({
factionlist
:
result
.
factions
});
}
})
.
catch
(
error
=>
console
.
log
(
error
));
}
handleTaskCreation
=
(
e
)
=>
{
e
.
preventDefault
();
if
(
this
.
state
.
taskNameInput
===
""
){
...
...
@@ -45,7 +67,7 @@ class TaskList extends React.Component{
}
let
token
=
sessionStorage
.
getItem
(
"
token
"
);
fetch
(
`
${
process
.
env
.
REACT_APP_URL
}
/task/new-task/
${
"
178cd342-9637-4481-ab81-d89585e9e006
"
}
`
,{
fetch
(
`
${
process
.
env
.
REACT_APP_URL
}
/task/new-task/
${
this
.
state
.
gameId
}
`
,{
method
:
"
POST
"
,
headers
:{
Authorization
:
"
Bearer
"
+
token
,
...
...
@@ -55,9 +77,9 @@ class TaskList extends React.Component{
taskName
:
this
.
state
.
taskNameInput
,
taskDescription
:
this
.
state
.
taskDescriptionInput
,
taskIsActive
:
true
,
faction
:
"
ad5195d6-820c-4a17-8549-65ac0945fd3e
"
,
faction
:
this
.
state
.
selectedFactionId
===
""
?
null
:
this
.
state
.
selectedFactionId
,
taskWinner
:
null
,
taskGame
:
"
178cd342-9637-4481-ab81-d89585e9e006
"
taskGame
:
this
.
state
.
gameId
})
})
.
then
(
result
=>
result
.
json
())
...
...
@@ -69,21 +91,67 @@ class TaskList extends React.Component{
else
{
// Success
alert
(
result
.
message
);
this
.
getTasks
(
"
178cd342-9637-4481-ab81-d89585e9e006
"
);
this
.
setState
({
taskDescriptionInput
:
""
,
taskNameInput
:
""
})
this
.
getTasks
(
this
.
state
.
gameId
);
}
})
.
catch
(
error
=>
console
.
log
(
error
));
}
handleFactionChange
=
e
=>
{
this
.
setState
({
selectedFactionId
:
e
.
target
.
value
});
}
onTaskSave
=
(
task
,
winnerFaction
)
=>
{
let
token
=
sessionStorage
.
getItem
(
"
token
"
);
fetch
(
`
${
process
.
env
.
REACT_APP_URL
}
/task/edit-task/
${
this
.
state
.
gameId
}
`
,
{
method
:
'
POST
'
,
headers
:
{
Authorization
:
"
Bearer
"
+
token
,
'
Content-Type
'
:
"
application/json
"
},
body
:
JSON
.
stringify
({
taskId
:
task
.
taskId
,
taskWinner
:
winnerFaction
.
factionId
,
taskGame
:
this
.
state
.
gameId
})
})
.
then
(
result
=>
result
.
json
())
.
then
(
result
=>
{
if
(
result
.
code
!==
201
){
alert
(
result
.
message
);
}
else
{
alert
(
result
.
message
);
this
.
getTasks
(
this
.
state
.
gameId
);
}
})
.
catch
(
error
=>
console
.
log
(
error
));
}
render
(){
let
tasks
=
[];
let
task
listItem
s
=
[];
for
(
let
i
=
0
;
i
<
this
.
state
.
tasks
.
length
;
i
++
)
{
const
task
=
this
.
state
.
tasks
[
i
];
tasks
.
push
(
<
TaskItem
key
=
{
task
.
taskId
}
t
ext
=
{
task
.
taskName
}
description
=
{
task
.
taskDescription
}
/
>
task
listItem
s
.
push
(
<
TaskItem
key
=
{
task
.
taskId
}
t
ask
=
{
task
}
gameId
=
{
this
.
state
.
gameId
}
onSave
=
{
this
.
onTaskSave
}
/
>
);
}
let
factionlistItems
=
this
.
state
.
factionlist
.
map
(
item
=>
{
return
<
option
key
=
{
item
.
factionId
}
value
=
{
item
.
factionId
}
>
{
item
.
factionName
}
<
/option
>
})
// add all factions option to the faction list
factionlistItems
.
unshift
(
<
option
key
=
"
all
"
value
=
""
>
Every
faction
<
/option
>
)
return
ReactDOM
.
createPortal
(
<
div
className
=
'
tasklist
'
>
<
h1
>
Tasklist
<
/h1
>
...
...
@@ -91,9 +159,12 @@ class TaskList extends React.Component{
<
label
>
New
task
<
/label
>
<
input
id
=
"
taskNameInput
"
type
=
'
text
'
placeholder
=
'
Task name
'
minLength
=
"
3
"
value
=
{
this
.
state
.
taskNameInput
}
onChange
=
{(
e
)
=>
this
.
setState
({
taskNameInput
:
e
.
target
.
value
})}
><
/input
>
<
textarea
id
=
"
taskDescriptionInput
"
placeholder
=
'
Task description
'
value
=
{
this
.
state
.
taskDescriptionInput
}
onChange
=
{(
e
)
=>
this
.
setState
({
taskDescriptionInput
:
e
.
target
.
value
})}
><
/textarea
>
<
select
id
=
"
taskFactionSelect
"
onChange
=
{
this
.
handleFactionChange
}
>
{
factionlistItems
}
<
/select
>
<
button
id
=
"
newTaskSubmitButton
"
type
=
"
submit
"
>
Add
new
task
<
/button
>
<
/form
>
{
tasks
}
{
task
listItem
s
}
<
/div>
,
document
.
getElementById
(
'
tasklist
'
)
);
...
...
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