Skip to content
Snippets Groups Projects
Commit 4adde34d authored by AA2875's avatar AA2875
Browse files

+totalfalltime sarake ja korjattu tuplikaatti save

parent 630ccfdd
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@ const jumpSchema = new mongoose.Schema({
canopy: { type: String, required: true },
height: { type: String, required: true },
falltime: { type: String, required: true },
totalfalltime: { type: String, required: true },
comments: { type: String, required: false },
link: { type: String, required: false }
})
......@@ -33,8 +34,8 @@ const Jump = mongoose.model('Jump', jumpSchema, 'jumps')
app.post('/jumps', async (request, response) => {
console.log(request.body)
const { number, date, place, plane, canopy, height, falltime, comments, link } = request.body
console.log(number, date, place, plane, canopy, height, falltime, comments, link )
const { number, date, place, plane, canopy, height, falltime, totalfalltime, comments, link } = request.body
console.log(number, date, place, plane, canopy, height, falltime, totalfalltime, comments, link )
const jump = new Jump({
number: number,
date: date,
......@@ -43,6 +44,7 @@ app.post('/jumps', async (request, response) => {
canopy: canopy,
height: height,
falltime: falltime,
totalfalltime: totalfalltime,
comments: comments,
link: link
})
......@@ -79,8 +81,8 @@ app.delete('/jumps/:id', async (request, response) => {
})
app.put('/jumps/:id', async (request, response) => {
const { number, date, place, plane, canopy, height, falltime, comments, link } = request.body
console.log(number, date, place, plane, canopy, height, falltime, comments, link)
const { number, date, place, plane, canopy, height, falltime, totalfalltime, comments, link } = request.body
console.log(number, date, place, plane, canopy, height, falltime, totalfalltime, comments, link)
const { id } = request.params
const jump = await Jump.findByIdAndUpdate(
id,
......@@ -91,6 +93,7 @@ app.put('/jumps/:id', async (request, response) => {
'canopy': canopy,
'height': height,
'falltime': falltime,
'totalfalltime': totalfalltime,
'comments': comments,
'link': link},
{'new': true}
......
......@@ -71,24 +71,9 @@ function createJumpListItem(jump) {
}
function jumpItemFullInfo(jump) {
const specs = [
'place',
'plane',
'canopy',
'height',
'falltime',
'comments',
'link'
]
const specNames = [
'Paikka',
'Lentokone',
'Päävarjo',
'Korkeus',
'Vapaapudotusaika',
'Kommentit',
'Medialinkki'
]
const specs = ['place', 'plane', 'canopy', 'height', 'falltime', 'totalfalltime', 'comments', 'link' ]
const specNames = [ 'Paikka', 'Lentokone', 'Päävarjo', 'Korkeus', 'Vapaapudotusaika', 'Yhteensä', 'Kommentit', 'Medialinkki' ]
let ul = document.createElement('ul')
let ulClass = document.createAttribute('class')
ulClass.value = 'fullJumpInfo'
......@@ -138,6 +123,15 @@ 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')
input.value = span.innerHTML
......@@ -290,12 +284,12 @@ function changeJumpOrder() {
async function addJump() {
const keys = ['Number','Date','Place','Plane','Canopy',
'Height','Falltime','Comments','Link']
'Height','Falltime','TotalFalltime','Comments','Link']
let data = {}
keys.forEach(key => {
let variableName = 'newJump' + key
let element = document.getElementById(variableName)
let inputID = 'newJump' + key
let element = document.getElementById(inputID)
let dataKey = key.toLowerCase()
data[`${dataKey}`] = element.value
element.value = ''
......@@ -319,7 +313,6 @@ async function addJump() {
let infoText = document.getElementById('infoText')
infoText.innerHTML = ''
loadJumps()
}
function editJump(id){
......@@ -400,7 +393,7 @@ function validateAndUpdate(id, headerColumns, addButtons) {
} else { valid.push(true) }
}
if (valid.every((valid) => valid == true)) {
const easyClasses = ['place', 'plane', 'canopy', 'height', 'falltime', 'comments', 'link']
const easyClasses = ['place', 'plane', 'canopy', 'height', 'falltime', 'totalfalltime', 'comments', 'link']
easyClasses.forEach(className => {
try {
let li = jump.getElementsByClassName(className)[0]
......@@ -476,7 +469,7 @@ function getJumpInfo(id) {
'number': number,
'date': date
}
let infoKeys = ['place','plane','canopy','height','falltime','comments']
let infoKeys = ['place','plane','canopy','height','falltime','totalfalltime','comments']
infoKeys.forEach(infoName => {
try {
......
......@@ -16,6 +16,7 @@
<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="Kommentit" id="newJumpComments"/>
<input type="text" placeholder="Medialinkki" id="newJumpLink"/>
<button onclick="addJump()" id="addJumpBtn">Lisää</button>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment