Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Post It
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Schreiter Marcus
Post It
Commits
ec29e020
Commit
ec29e020
authored
7 years ago
by
Schreiter Marcus
Browse files
Options
Downloads
Patches
Plain Diff
no message
parent
1cdad0de
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
helpers/helpers.js
+32
-0
32 additions, 0 deletions
helpers/helpers.js
server.js
+15
-93
15 additions, 93 deletions
server.js
views/feed.ejs
+38
-11
38 additions, 11 deletions
views/feed.ejs
with
85 additions
and
104 deletions
helpers/helpers.js
+
32
−
0
View file @
ec29e020
exports
.
syncLoop
=
function
(
iterations
,
process
,
exit
)
{
var
index
=
0
,
done
=
false
,
shouldExit
=
false
;
var
loop
=
{
next
:
function
()
{
if
(
done
)
{
if
(
shouldExit
&&
exit
)
{
return
exit
();
// Exit if we're done
}
}
// If we're not finished
if
(
index
<
iterations
)
{
index
++
;
// Increment our index
process
(
loop
);
// Run our process, pass in the loop
// Otherwise we're done
}
else
{
done
=
true
;
// Make sure we say we're done
if
(
exit
)
exit
();
// Call the callback on exit
}
},
iteration
:
function
()
{
return
index
-
1
;
// Return the loop number we're on
},
break
:
function
(
end
)
{
done
=
true
;
// End the loop
shouldExit
=
end
;
// Passing end as true means we still call the exit callback
}
};
loop
.
next
();
return
loop
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
server.js
+
15
−
93
View file @
ec29e020
...
...
@@ -11,12 +11,14 @@ var app = require('express')();
var
server
=
require
(
'
http
'
).
Server
(
app
);
var
io
=
require
(
'
socket.io
'
)(
server
);
var
database
=
require
(
'
./database/database
'
);
var
path
=
require
(
'
path
'
);
var
helpers
=
require
(
'
./helpers/helpers
'
);
//---------------------------Server Konfigurationen---------------------------
//Statische Seiten
app
.
use
(
express
.
static
(
__dirname
+
'
/
views
'
));
app
.
use
(
express
.
static
(
__dirname
+
'
/
static
'
));
//Body Parser
app
.
use
(
bodyParser
.
json
());
...
...
@@ -50,7 +52,7 @@ app.get('/', function (req, res) {
res
.
redirect
(
'
/feed
'
);
}
else
{
res
.
r
end
er
(
'
logIn.html
'
);
res
.
s
end
File
(
path
.
join
(
__dirname
+
'
/static/
logIn.html
'
)
)
;
}
...
...
@@ -95,7 +97,7 @@ app.get('/feed', function (req, res) {
database
.
read
(
'
users
'
,
query
,
userFields
,
function
(
usersResult
)
{
database
.
read
(
'
posts
'
,
null
,
fields
,
function
(
postsResult
)
{
syncLoop
(
postsResult
.
length
,
function
(
loop
)
{
helpers
.
syncLoop
(
postsResult
.
length
,
function
(
loop
)
{
var
i
=
loop
.
iteration
();
post
=
postsResult
[
i
];
database
.
read
(
'
users
'
,
{
'
userName
'
:
post
.
user
},
{
'
pictureId
'
:
1
},
function
(
pictureId
)
{
...
...
@@ -115,6 +117,14 @@ app.get('/feed', function (req, res) {
}
});
app
.
post
(
'
/comment
'
,
function
(
req
,
res
)
{
var
id
=
req
.
body
.
id
;
var
comment
=
req
.
body
.
content
;
console
.
log
(
req
.
body
);
//database.insert('')
});
//Logout - Löscht Session und leitet zurück zur Login-Seite
app
.
get
(
'
/logOut
'
,
function
(
req
,
res
)
{
req
.
session
.
destroy
(
function
(
err
)
{
...
...
@@ -162,65 +172,7 @@ app.post('/register', function (req, res) {
});
});
//DATENBANKVERBINDUNG
/*MongoClient.connect(urlDB, function(err, db) {
if (err) throw err;
console.log("Database created!");
//Registrierung neuer User
var newUser;
var newPassword;
var myobj = { name: newUser, password: newPassword };
//Userdaten in Datenbank einfügen
db.collection("users").insertOne(myobj, function(err, res) {
if (err) throw err;
console.log("1 document inserted");
});
//Loginverarbeitung
var username;
var password;
var query = { name: username };
db.collection("users").find(query).toArray(function(err, result) {
if (err) throw err;
console.log(result);
if (result.password == password) {
//Login erfolgreich
}
});
//Feed abrufen
db.collection("beitraege").find({}).toArray(function(err, result) {
if (err) throw err;
console.log(result);
//Feed ausgeben
});
//Feed filtern
//Neuer Beitrag
//Profilbild ändern
//Biografie ändern
db.close();
});*/
//SOCKET: BOT-POSTS
function
botPost
()
{
var
randomPost
=
Math
.
floor
(
Math
.
random
()
*
11
);
...
...
@@ -269,36 +221,6 @@ io.on('connection', function (socket) {
},
rand
);
});
function
syncLoop
(
iterations
,
process
,
exit
)
{
var
index
=
0
,
done
=
false
,
shouldExit
=
false
;
var
loop
=
{
next
:
function
()
{
if
(
done
)
{
if
(
shouldExit
&&
exit
)
{
return
exit
();
// Exit if we're done
}
}
// If we're not finished
if
(
index
<
iterations
)
{
index
++
;
// Increment our index
process
(
loop
);
// Run our process, pass in the loop
// Otherwise we're done
}
else
{
done
=
true
;
// Make sure we say we're done
if
(
exit
)
exit
();
// Call the callback on exit
}
},
iteration
:
function
()
{
return
index
-
1
;
// Return the loop number we're on
},
break
:
function
(
end
)
{
done
=
true
;
// End the loop
shouldExit
=
end
;
// Passing end as true means we still call the exit callback
}
};
loop
.
next
();
return
loop
;
}
This diff is collapsed.
Click to expand it.
views/feed.ejs
+
38
−
11
View file @
ec29e020
<
%
var
loggedInUser =
loggedInUser[0];
%
>
<!DOCTYPE html>
<html
lang=
"de"
>
...
...
@@ -6,12 +10,32 @@
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Feed
</title>
<link
type=
"text/css"
rel=
"stylesheet"
href=
"style.css"
/>
<script
src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"
></script>
<script
type=
"text/javascript"
src=
"/socket.io/socket.io.js"
></script>
<script>
var
socket
=
io
();
socket
.
on
(
'
newMessage
'
,
function
(
data
)
{
//reload feed somehow
});
$
(
document
).
ready
(
function
()
{
$
(
'
.commentButton
'
).
click
(
function
()
{
var
id
=
$
(
this
).
attr
(
'
id
'
);
var
commentContent
=
$
(
'
#commentContent_
'
+
id
).
val
();
var
user
=
'
<%= loggedInUser.userName %>
'
;
if
(
commentContent
)
{
$
.
post
(
'
/comment
'
,
{
'
postId
'
:
id
,
'
content
'
:
commentContent
,
'
user
'
:
user
},
function
()
{
});
}
});
});
</script>
</head>
...
...
@@ -38,13 +62,11 @@
</nav>
</div>
<!--
<img src="img/Icon<%= loggedInUser[0].pictureId %>.png" class="realtiveIcon" id="Logo"/>
-->
<div
class=
"userNavigation"
>
<table>
<tr>
<td><img
src=
"img/Icon<%= loggedInUser
[0]
.pictureId %>.png"
class=
"realtiveIcon"
id=
"Logo"
/></td>
<td><img
src=
"img/Icon<%= loggedInUser.pictureId %>.png"
class=
"realtiveIcon"
id=
"Logo"
/></td>
<td
id=
"namePost"
><a
href=
"/logOut"
class=
"logoutLink"
>
Logout
</a></td>
</tr>
</table>
...
...
@@ -68,9 +90,9 @@
<div
class=
"userData"
>
<table>
<tr>
<td><img
src=
"img/Icon<%= loggedInUser
[0]
.pictureId %>.png"
class=
"realtiveIcon"
<td><img
src=
"img/Icon<%= loggedInUser.pictureId %>.png"
class=
"realtiveIcon"
id=
"userIcon"
/></td>
<td
id=
"namePost"
><
%=
loggedInUser
[0]
.
userName
%
></td>
<td
id=
"namePost"
><
%=
loggedInUser.userName
%
></td>
</tr>
</table>
</div>
...
...
@@ -88,12 +110,14 @@
<form
class=
"feedform"
name=
"feed"
>
<h1
id=
"feedTitle"
>
Dein Feed
</h1>
<
%
for
(
var
i =
posts.length-1;
i
>
=0; i--){
var currentPost = posts[i];
%>
<div
class=
"feedcontainer"
>
<div
class=
"userData"
>
<table>
<tr>
...
...
@@ -110,16 +134,16 @@
<p>
Willst du diesen Post kommentieren?
</p>
<div
class=
"userData"
>
<table>
<tr>
<td><img
src=
"img/Icon<%= loggedInUser
[0]
.pictureId %>.png"
class=
"realtiveIcon"
<td><img
src=
"img/Icon<%= loggedInUser.pictureId %>.png"
class=
"realtiveIcon"
id=
"userIcon"
/></td>
<td
id=
"namePost"
><
%=
loggedInUser
[0]
.
userName
%
></td>
<td
id=
"namePost"
><
%=
loggedInUser.userName
%
></td>
</tr>
</table>
</div>
<div
class=
"commentContent"
>
<textarea
id=
"
subject
"
name=
"commentInput"
placeholder=
"Kommentiere diesen Post..."
></textarea>
<br>
<textarea
id=
"
commentContent_<%= currentPost.post._id%>
"
name=
"commentInput"
placeholder=
"Kommentiere diesen Post..."
></textarea>
<br>
</div>
<button
type=
"button"
onclick=
""
id=
"
submit
"
class=
"
b
utton
Box
"
>
Kommentieren
</button>
<br/>
<button
type=
"button"
onclick=
""
id=
"
<%= currentPost.post._id%>
"
class=
"
commentB
utton"
>
Kommentieren
</button>
<br/>
</div>
</div>
...
...
@@ -127,6 +151,9 @@
}
%
>
</form>
...
...
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