Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Corentin Mors
avis-de-template-server
Commits
6bd3944e
Commit
6bd3944e
authored
Dec 07, 2018
by
Yann Caumartin
Browse files
Adds mission/view
parent
b224bb4a
Changes
3
Show whitespace changes
Inline
Side-by-side
controllers/missions.js
0 → 100644
View file @
6bd3944e
var
express
=
require
(
'
express
'
),
router
=
express
.
Router
(),
mongoose
=
require
(
'
mongoose
'
);
//GET all missions
exports
.
list_missions
=
function
(
req
,
res
,
next
)
{
//retrieve all users from Monogo
mongoose
.
model
(
'
Mission
'
).
find
({},
function
(
err
,
missions
)
{
if
(
err
)
{
return
console
.
error
(
err
);
}
else
{
//respond to both HTML and JSON. JSON responses require 'Accept: application/json;' in the Request Header
res
.
format
({
//HTML response will render the users/index.html
html
:
function
(){
res
.
render
(
'
./missions/list
'
,
{
title
:
'
Missions list
'
,
missions
:
missions
});
},
//JSON response will show all users in JSON format
json
:
function
(){
res
.
json
(
missions
);
}
});
}
});
}
//POST a new mission
exports
.
add_mission
=
function
(
req
,
res
)
{
// Get values from POST request. These can be done through forms or REST calls. These rely on the "name" attributes for forms
var
title
=
req
.
body
.
title
;
var
start_date
=
req
.
body
.
start_date
;
var
end_date
=
req
.
body
.
end_date
;
var
description
=
req
.
body
.
description
;
var
priority
=
req
.
body
.
priority
;
//call the create function for our database
mongoose
.
model
(
'
Mission
'
).
create
({
_id
:
new
mongoose
.
Types
.
ObjectId
(),
title
:
title
,
start_date
:
start_date
,
end_date
:
end_date
,
description
:
description
,
priority
:
priority
},
function
(
err
,
mission
)
{
if
(
err
)
{
res
.
send
(
"
There was a problem adding the information to the database.
"
);
}
else
{
//mission has been created
console
.
log
(
'
POST creating new mission:
'
+
mission
);
res
.
format
({
//HTML response will set the location and redirect back to the home page. You could also create a 'success' page if that's your thing
html
:
function
(){
// If it worked, set the header so the address bar doesn't still say /adduser
res
.
location
(
"
missions
"
);
// And forward to success page
res
.
redirect
(
"
/missions
"
);
},
//JSON response will show the newly created user
json
:
function
(){
res
.
json
(
mission
);
}
});
}
})
};
exports
.
view_mission
=
function
(
req
,
res
)
{
mongoose
.
model
(
'
Mission
'
).
findById
(
req
.
params
.
id
,
function
(
err
,
mission
)
{
if
(
err
)
{
console
.
log
(
'
GET Error: There was a problem retrieving:
'
+
err
);
}
else
{
console
.
log
(
'
GET Retrieving ID:
'
+
mission
.
_id
);
res
.
format
({
html
:
function
(){
res
.
render
(
'
missions/view
'
,
{
title
:
'
View of
'
+
mission
.
type
,
mission
:
mission
});
},
json
:
function
(){
res
.
json
(
mission
);
}
});
}
});
};
routes/missionRoute.js
View file @
6bd3944e
...
...
@@ -8,4 +8,7 @@ var express = require('express'),
.
get
(
missionController
.
list_missions
)
.
post
(
missionController
.
add_mission
);
router
.
route
(
'
/:id
'
)
.
get
(
missionController
.
view_mission
);
module
.
exports
=
router
views/missions/list.html
View file @
6bd3944e
...
...
@@ -8,7 +8,7 @@
{% include "partials/modals/add-mission.html" %}
<button
type=
"button"
class=
"btn btn-primary"
data-toggle=
"modal"
data-target=
"#add-mission-modal"
>
Add new miss
s
ion
Add new mission
</button>
<hr>
...
...
@@ -18,11 +18,11 @@
{% for mission in missions %}
<div
class=
"list-group-item list-group-item-action align-items-start list-group-item-flex"
>
<div
class=
"list-group-item-tools"
>
<a
href=
"
misssions/
{{ miss
s
ion._id }}"
title=
"Look mission"
><i
class=
"fas fa-eye"
></i></a>
<a
href=
"
misssions/
{{ miss
s
ion._id }}/edit"
title=
"Edit mission"
><i
class=
"fas fa-pencil-alt"
></i></a>
<a
href=
"{{ mission._id }}"
title=
"Look mission"
><i
class=
"fas fa-eye"
></i></a>
<a
href=
"{{ mission._id }}/edit"
title=
"Edit mission"
><i
class=
"fas fa-pencil-alt"
></i></a>
</div>
<div
class=
"list-group-item-image"
>
<svg
width=
"80"
height=
"80"
data-jdenticon-value=
"{{ miss
s
ion._id }}"
></svg>
<svg
width=
"80"
height=
"80"
data-jdenticon-value=
"{{ mission._id }}"
></svg>
</div>
<div
class=
"list-group-item-content"
>
<div
class=
"d-flex w-90 justify-content-between"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment