Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Full Stack harjoitustyö
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
AA2875
Full Stack harjoitustyö
Commits
4e35361e
Commit
4e35361e
authored
2 years ago
by
AA2875
Browse files
Options
Downloads
Patches
Plain Diff
Auto täyttö kokonais ajalle
parent
4e507b05
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
V2/page/code.js
+58
-9
58 additions, 9 deletions
V2/page/code.js
V2/page/index.html
+8
-4
8 additions, 4 deletions
V2/page/index.html
with
66 additions
and
13 deletions
V2/page/code.js
+
58
−
9
View file @
4e35361e
...
...
@@ -123,17 +123,16 @@ function jumpItemFullInfo(jump) {
return
ul
}
function
cumulativeFreeFallTime
(
id
)
{
let
jumpIndex
=
jumpsJSON
.
findIndex
(
jump
=>
jump
.
_id
===
id
)
let
totalTime
=
0
for
(
let
index
=
jumpsJSON
.
length
-
1
;
index
>=
jumpIndex
;
index
--
)
{
totalTime
+=
parseInt
(
jumpsJSON
[
index
].
falltime
)
}
return
totalTime
}
function
makeEditable
(
span
)
{
let
input
=
document
.
createElement
(
'
input
'
)
const
onlyNumbers
=
[
'
height
'
,
'
falltime
'
,
'
totalfalltime
'
]
if
(
onlyNumbers
.
includes
(
span
.
parentElement
.
className
))
{
let
preventLetters
=
document
.
createAttribute
(
'
onkeypress
'
)
preventLetters
.
value
=
'
return /[0-9]/i.test(event.key)
'
input
.
setAttributeNode
(
preventLetters
)
}
input
.
value
=
span
.
innerHTML
let
li
=
span
.
parentElement
let
id
=
li
.
parentElement
.
parentElement
.
id
...
...
@@ -313,6 +312,8 @@ async function addJump() {
let
infoText
=
document
.
getElementById
(
'
infoText
'
)
infoText
.
innerHTML
=
''
jumpsJSON
[
jumpsJSON
.
length
]
=
data
// loadJumps()
}
function
editJump
(
id
){
...
...
@@ -457,7 +458,7 @@ function addDataField(id, fieldName) {
fullJumpInfo
.
insertBefore
(
newField
,
jumpEditAndDeleteButtons
)
}
async
function
insertDefaults
()
{
async
function
nextJumpNumber
()
{
let
numberInput
=
document
.
getElementById
(
'
newJumpNumber
'
)
if
(
numberInput
.
value
!=
''
)
return
let
response
=
await
fetch
(
'
http://localhost:3000/jumps
'
)
...
...
@@ -477,6 +478,54 @@ async function insertDefaults() {
numberInput
.
value
=
newJumpNumber
}
function
totalFalltime
()
{
let
totalFalltimeInput
=
document
.
getElementById
(
'
newJumpTotalFalltime
'
)
let
falltimeInput
=
document
.
getElementById
(
'
newJumpFalltime
'
)
let
jumpNumber
=
document
.
getElementById
(
'
newJumpNumber
'
).
value
let
jumpIndexUntilJumpNumber
=
jumpsJSON
.
length
jumpsJSON
.
forEach
(
jump
=>
{
if
(
jumpNumber
>
jump
.
number
)
{
jumpIndexUntilJumpNumber
--
}
})
let
totalFalltime
=
0
if
(
parseInt
(
jumpNumber
)
<
2
)
{
totalFalltime
=
0
jumpIndexUntilJumpNumber
--
}
else
{
totalFalltime
=
parseInt
(
jumpsJSON
[
jumpIndexUntilJumpNumber
].
totalfalltime
)
}
if
(
falltimeInput
.
value
!=
''
)
{
totalFalltime
+=
parseInt
(
falltimeInput
.
value
)
}
else
{
totalFalltimeInput
.
value
=
''
}
totalFalltimeInput
.
value
=
`
${
secondsToMinutes
(
totalFalltime
)}
(
${
totalFalltime
}
s)`
}
function
secondsToMinutes
(
timeInSec
)
{
let
minutes
=
Math
.
floor
(
timeInSec
/
60
)
let
seconds
=
timeInSec
-
(
minutes
*
60
)
let
time
=
`
${
minutes
}
min
${
seconds
}
s`
return
time
}
function
ifValueInSeconds
(
value
)
{
let
input
=
document
.
getElementById
(
'
newJumpTotalFalltime
'
)
if
(
/^
\d
+$/
.
test
(
value
))
{
input
.
value
=
secondsToMinutes
(
value
)
}
}
function
cumulativeFreeFalltime
(
id
)
{
let
jumpIndex
=
jumpsJSON
.
findIndex
(
jump
=>
jump
.
_id
===
id
)
let
totalTime
=
0
for
(
let
index
=
jumpsJSON
.
length
-
1
;
index
>=
jumpIndex
;
index
--
)
{
totalTime
+=
parseInt
(
jumpsJSON
[
index
].
falltime
)
}
return
totalTime
}
function
getJumpInfo
(
id
)
{
let
jump
=
document
.
getElementById
(
id
)
let
number
=
jump
.
getElementsByClassName
(
'
jumpNumber
'
)[
0
].
innerHTML
...
...
This diff is collapsed.
Click to expand it.
V2/page/index.html
+
8
−
4
View file @
4e35361e
...
...
@@ -10,14 +10,18 @@
<div
id=
"container"
>
<h1>
Hypyt
</h1>
<input
type=
"text"
placeholder=
"Hyppy nro.*"
id=
"newJumpNumber"
onkeypress=
"return /[0-9]/i.test(event.key)"
onfocus=
"
insertDefaults
()"
/>
onkeypress=
"return /[0-9]/i.test(event.key)"
onfocus=
"
nextJumpNumber
()"
/>
<input
type=
"text"
placeholder=
"Päivä*"
id=
"newJumpDate"
/>
<input
type=
"text"
placeholder=
"Paikka*"
id=
"newJumpPlace"
/>
<input
type=
"text"
placeholder=
"Lentokone*"
id=
"newJumpPlane"
/>
<input
type=
"text"
placeholder=
"Päävarjo*"
id=
"newJumpCanopy"
/>
<input
type=
"text"
placeholder=
"Korkeus*"
id=
"newJumpHeight"
onkeypress=
"return /[0-9]/i.test(event.key)"
/>
<input
type=
"text"
placeholder=
"Vapaa*"
id=
"newJumpFalltime"
onkeypress=
"return /[0-9]/i.test(event.key)"
/>
<input
type=
"text"
placeholder=
"Vapaa yht.*"
id=
"newJumpTotalFalltime"
onkeypress=
"return /[0-9]/i.test(event.key)"
/>
<input
type=
"text"
placeholder=
"Korkeus, m*"
id=
"newJumpHeight"
onkeypress=
"return /[0-9]/i.test(event.key)"
/>
<input
type=
"text"
placeholder=
"Vapaa, s*"
id=
"newJumpFalltime"
onkeypress=
"return /[0-9]/i.test(event.key)"
oninput=
"totalFalltime()"
/>
<input
type=
"text"
placeholder=
"Vapaa yht., s*"
id=
"newJumpTotalFalltime"
onkeypress=
"return /[0-9]/i.test(event.key)"
onfocus=
"select()"
onblur=
"ifValueInSeconds(value)"
/>
<input
type=
"text"
placeholder=
"Kommentit"
id=
"newJumpComments"
/>
<input
type=
"text"
placeholder=
"Medialinkki"
id=
"newJumpLink"
/>
<button
onclick=
"addJump()"
id=
"addJumpBtn"
>
Lisää
</button>
...
...
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