Commit 695a4f07 authored by Yann Caumartin's avatar Yann Caumartin
Browse files

Merge branch 'feature/missionController' into develop

parents e32c94e6 fb28797b
......@@ -35,7 +35,7 @@ var listes = require('./models/checklists');
var source = require('./models/sources');
var datacenter = require('./models/datacenters');
var tache = require('./models/tasks');
var mission = require('./models/missions');
// Load templating and statics
app.use(express.static(path.join(__dirname, 'public')));
......
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);
}
});
}
});
};
......@@ -20,11 +20,12 @@ router.route('/location')
router.route('/dashboard')
.get(mid.requiresLogin, indexController.dashboard);
router.use('/users', mid.requiresLogin, require('./userRoute'));
router.use('/resources', mid.requiresLogin, require('./resourceRoute'));
router.use('/checklists', mid.requiresLogin, require('./checklistRoute'));
router.use('/sources', mid.requiresLogin, require('./sourceRoute'));
router.use('/guides', mid.requiresLogin, require('./guideRoute'));
router.use('/datacenters', mid.requiresLogin, require('./datacenterRoute'));
router.use('/users', require('./userRoute'));
router.use('/resources', require('./resourceRoute'));
router.use('/checklists', require('./checklistRoute'));
router.use('/sources', require('./sourceRoute'));
router.use('/guides', require('./guideRoute'));
router.use('/datacenters', require('./datacenterRoute'));
router.use('/missions', require('./missionRoute'));
module.exports = router
'use strict';
var express = require('express'),
router = express.Router();
var missionController = require('../controllers/missions');
router.route('/')
.get(missionController.list_missions)
.post(missionController.add_mission);
router.route('/:id')
.get(missionController.view_mission);
module.exports = router
......@@ -5,24 +5,24 @@
<div class="row">
<div class="col-12">
{% include "partials/modals/add-misssion.html" %}
{% include "partials/modals/add-mission.html" %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#add-misssion-modal">
Add new misssion
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#add-mission-modal">
Add new mission
</button>
<hr>
<div class="list-group">
{% for misssion in misssions %}
{% 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/{{ misssion._id }}" title="Look mission"><i class="fas fa-eye"></i></a>
<a href="misssions/{{ misssion._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="{{ misssion._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">
......@@ -36,8 +36,7 @@
</div>
<p class="mb-1">{{ mission.start_date }}</p>
<p class="mb-1">{{ mission.end_date }}</p>
<p class="mb-1">{{ misssion.email }}</p>
<small>group-one, group-two</small>
<p class="mb-1">{{ mission.email }}</p>
</div>
</div>
{% endfor %}
......
......@@ -5,12 +5,14 @@
<div class="row">
<div class="col-12">
<h2>View of mission #{{ mission._id }}</h2>
<h2>View of mission {{ mission._id }}</h2>
<hr>
{% include "partials/modals/add-participant-modal.html" %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#add-participant-modal">
Add new participant
</button>
{% include "partials/modals/add-checklist.html" %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#add-checklist-modal">
Add new checklist
</button>
......
<div class="modal fade" id="add-mission-modal" tabindex="-1" role="dialog" aria-labelledby="add-mission-modal-label" aria-hidden="true">
<div class="modal-dialog" role="document">
<form action="/missions/" method="POST">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add new mission</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="input-title">Title</label>
<input title="text" class="form-control" id="input-title" name="title" aria-describedby="quantityHelp" placeholder="Enter title">
</div>
<div class="form-group">
<label for="input-description">description</label>
<input type="description" class="form-control" id="input-description" name="description" aria-describedby="descriptionHelp" placeholder="Enter description">
</div>
<div class="form-group">
<label for="input-priority">priority</label>
<input type="priority" class="form-control" id="input-priority" name="priority" aria-describedby="priorityHelp" placeholder="Enter priority">
</div>
<div class="form-group">
<label for="input-start_date">start_date</label>
<input type="start_date" class="form-control" id="input-start_date" name="start_date" aria-describedby="start_dateHelp" placeholder="Enter start date">
</div>
<div class="form-group">
<label for="input-end_date">end_date</label>
<input type="end_date" class="form-control" id="input-end_date" name="end_date" aria-describedby="end_dateHelp" placeholder="Enter end date">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add mission</button>
</div>
</div>
</form>
</div>
</div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment