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
7e8eb317
Commit
7e8eb317
authored
2 years ago
by
AA2875
Browse files
Options
Downloads
Patches
Plain Diff
Muokkausta sulavemmaks
parent
b7de531b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
V2/index.js
+3
-10
3 additions, 10 deletions
V2/index.js
V2/page/code.js
+40
-5
40 additions, 5 deletions
V2/page/code.js
with
43 additions
and
15 deletions
V2/index.js
+
3
−
10
View file @
7e8eb317
...
...
@@ -3,13 +3,10 @@ const cors = require('cors')
const
app
=
express
()
const
port
=
3000
// cors - allow connection from different domains and ports
app
.
use
(
cors
())
// convert json string to json object (from request)
app
.
use
(
express
.
json
())
// mongo
const
mongoose
=
require
(
'
mongoose
'
)
const
mongoDB
=
'
mongodb+srv://eemuli:N33k3r123@test.147x5qr.mongodb.net/hyppynet
'
mongoose
.
connect
(
mongoDB
,
{
useNewUrlParser
:
true
,
useUnifiedTopology
:
true
})
...
...
@@ -20,7 +17,6 @@ db.once('open', function() {
console
.
log
(
"
Database connected
"
)
})
// scheema
const
jumpSchema
=
new
mongoose
.
Schema
({
number
:
{
type
:
String
,
required
:
true
},
date
:
{
type
:
String
,
required
:
true
},
...
...
@@ -32,8 +28,7 @@ const jumpSchema = new mongoose.Schema({
comments
:
{
type
:
String
,
required
:
false
},
link
:
{
type
:
String
,
required
:
false
}
})
// model
const
Jump
=
mongoose
.
model
(
'
Jump
'
,
jumpSchema
,
'
jumps
'
)
app
.
post
(
'
/jumps
'
,
async
(
request
,
response
)
=>
{
...
...
@@ -83,12 +78,11 @@ app.delete('/jumps/:id', async (request, response) => {
else
response
.
status
(
404
).
end
()
})
// update user data
app
.
put
(
'
/jumps/:id
'
,
async
(
request
,
response
)
=>
{
const
{
number
,
date
,
place
,
plane
,
canopy
,
height
,
falltime
,
comments
,
link
}
=
request
.
body
const
{
number
,
date
,
place
,
plane
,
canopy
,
height
,
falltime
,
comments
,
link
}
=
request
.
body
const
{
id
}
=
request
.
params
const
jump
=
await
Jump
.
findByIdAndUpdate
(
id
,
id
,
{
'
number
'
:
number
,
'
date
'
:
date
,
'
place
'
:
place
,
...
...
@@ -99,7 +93,6 @@ app.put('/jumps/:id', async (request, response) => {
'
comments
'
:
comments
,
'
link
'
:
link
},
{
'
new
'
:
true
}
// Tähä kaikki slotit?
)
response
.
json
(
jump
)
})
...
...
This diff is collapsed.
Click to expand it.
V2/page/code.js
+
40
−
5
View file @
7e8eb317
...
...
@@ -139,12 +139,44 @@ function makeEditable(span) {
input
.
value
=
span
.
innerHTML
let
li
=
span
.
parentElement
let
id
=
li
.
parentElement
.
parentElement
.
id
let
specName
=
li
.
className
let
originalValue
=
span
.
innerHTML
span
.
remove
()
li
.
appendChild
(
input
)
input
.
focus
()
input
.
addEventListener
(
'
focusout
'
,
()
=>
saveJump
(
id
))
// input takas spaniks
let
validateForUpdate
=
function
()
{
if
(
input
.
value
!=
''
)
{
saveJump
(
id
)
savedEdit
(
li
)
}
else
{
input
.
value
=
originalValue
input
.
style
.
color
=
'
red
'
input
.
style
.
transitionDuration
=
'
0s
'
setTimeout
(()
=>
{
input
.
style
.
transitionDuration
=
'
1s
'
input
.
style
.
color
=
'
black
'
},
1000
);
}
}
input
.
addEventListener
(
'
focusout
'
,
validateForUpdate
)
input
.
addEventListener
(
'
keypress
'
,
(
event
)
=>
{
if
(
event
.
key
===
'
Enter
'
)
{
validateForUpdate
input
.
blur
()
}
}
)
}
function
savedEdit
(
li
)
{
let
input
=
li
.
firstChild
let
savedValue
=
input
.
value
input
.
remove
()
let
span
=
document
.
createElement
(
'
span
'
)
let
spanClass
=
document
.
createAttribute
(
'
class
'
)
spanClass
.
value
=
'
fullJumpInfoValue
'
span
.
setAttributeNode
(
spanClass
)
span
.
appendChild
(
document
.
createTextNode
(
savedValue
))
li
.
appendChild
(
span
)
return
li
}
function
createHyperlink
(
link
)
{
...
...
@@ -290,13 +322,14 @@ function editJump(id){
function
getJumpInfo
(
id
)
{
let
jump
=
document
.
getElementById
(
id
)
let
number
=
jump
.
getElementsByClassName
(
'
jumpNumber
'
)[
0
].
innerHTML
number
=
number
.
slice
(
1
,
number
.
length
)
let
date
=
jump
.
getElementsByClassName
(
'
headerJumpDate
'
)[
0
].
innerHTML
let
data
=
{
'
number
'
:
number
,
'
date
'
:
date
}
let
infoKeys
=
[
'
place
'
,
'
plane
'
,
'
canopy
'
,
'
height
'
,
'
falltime
'
,
'
comments
'
]
infoKeys
.
forEach
(
infoName
=>
{
try
{
let
li
=
jump
.
getElementsByClassName
(
infoName
)[
0
]
...
...
@@ -328,7 +361,9 @@ async function saveJump(id){ // Erheitä esim text newJump.value
},
body
:
JSON
.
stringify
(
data
)
})
console
.
log
(
response
)
let
jumpIndex
=
jumpsJSON
.
findIndex
(
jump
=>
jump
.
_id
===
id
)
data
[
'
_id
'
]
=
id
jumpsJSON
[
jumpIndex
]
=
data
}
async
function
removeJump
(
id
)
{
...
...
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