Skip to content

Commit

Permalink
Implement /theirTasks page.
Browse files Browse the repository at this point in the history
  • Loading branch information
george-thomas-hill committed Jul 28, 2020
1 parent c94cc95 commit 1dc6ce0
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ app.use('/task', require('./task.js'));

app.use('/mytasks', require('./myTasks.js'));

app.use('/theirTasks', require('./theirTasks.js'));

app.get('/', function(req, res, next) {
var context = {};
res.render('signup', context);
Expand Down
66 changes: 66 additions & 0 deletions theirTasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const express = require('express');
const mysql = require('./dbcon.js');
const { requireAuth } = require('./middleware.js');
const Utils = require('./utils.js');
const router = express.Router();

router
.get('/', requireAuth, function(req, res) {
let callbackCount = 0;
const context = {};
context.userId = req.user.id;
context.name = req.user.name;
getMyTasks(res, context, complete);
function complete() {
res.render('theirTasks', context);
}
});

/* Get all tasks assigned to me */
function getMyTasks(res, context, complete){
const sql = `
SELECT t.*, p.Project_Name, u.name AS assignee_name, p.Project_Owner
FROM (
SELECT
*, id AS task_id, FALSE AS is_sub
FROM tasks t
WHERE assignee_id <> ?
UNION ALL
SELECT
st.id,
st.project_id,
CONCAT(t.name, " - ", st.name) AS name,
st.assignee_id,
st.due_date,
st.status,
st.description,
st.task_id,
TRUE AS is_sub
FROM subtasks st
INNER JOIN tasks t ON st.task_id = t.id
WHERE st.assignee_id <> ?
) t
INNER JOIN Projects p ON t.project_id = p.Project_ID
INNER JOIN users u ON t.assignee_id = u.id
WHERE p.Project_Owner = ?
ORDER BY t.due_date ASC
`;
const inserts = [context.userId, context.userId, context.userId];
mysql.pool.query(sql, inserts, function(error, results) {
if(error){
res.write(JSON.stringify(error));
res.end();
}
else {
results.forEach(t => {
t.isOverdue = Utils.isOverdue(t.due_date);
[t.due_date, t.format_date] = Utils.formatDueDate(t.due_date);
});
context.currenttasks = results.filter(t => t.status != 'Completed');
context.pasttasks = results.filter(t => t.status == 'Completed');
complete();
}
});
}

module.exports = router;
3 changes: 3 additions & 0 deletions views/partials/navbar_partial.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<li class="nav-item active">
<a class="nav-link" href='/mytasks'>My Tasks</a>
</li>
<li class="nav-item active">
<a class="nav-link" href='/theirTasks'>Tasks I've Assigned to Others</a>
</li>
</ul>
{{#if userId}}
<span class="danger mr-2"> Hi, {{name}}</span>
Expand Down
162 changes: 162 additions & 0 deletions views/theirTasks.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<!-- NAV BAR -->
{{> navbar_partial}}
<!-- NAV BAR -->

<br />
<!-- DISPLAY THEIR CURRENT TASKS/SUBTASKS -->
<p></p>
<div class="container">
<h2>Current Tasks I've Assigned to Others</h2>
<p></p>
<table class="table table-striped">

<thead class="thead-dark">
<tr>
<th scope="col">Project</th>
<th scope="col">Task</th>
<th scope="col">Description</th>
<th scope="col">Due Date</th>
<th scope="col">Status</th>
<th scope="col">Assignee</th>
<th scope="col">Manage</th>
</tr>
</thead>

<tbody>
{{#each currenttasks}}
<tr>
<th scope="row">{{Project_Name}}</th>
<td>{{name}}</td>
<td>{{description}}</td>
<td {{#if isOverdue}} class="danger"{{/if}}>{{due_date}}</td>
<td>{{status}}</td>
<td>{{assignee_name}}</td>
<td>
<a href="/task/{{task_id}}">
<button type="button" class="btn btn-success">
View Task
</button>
</a>
<button class="btn btn-primary" data-toggle="modal" data-target=".bs-modal-sm2-{{id}}">
<i class="fa fa-edit"></i>
</button>
<div class="modal fade bs-modal-sm2-{{id}}">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Edit Task {{name}}</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
</div>
<div class="modal-body">
{{#if is_sub}}<!-- if is subtask -->
<form method="post" action="/task/update-status">
{{else}}<!-- if is task -->
<form method="post" action="/project/update-status">
{{/if}}
<div class="form-row">
<div class="form-group col-sm-4">
<label for="status">Status</label>
<select required class="custom-select mr-sm-2" name="status">
<option {{#ifCond status '==' 'To Do'}}selected{{/ifCond}} value="To Do">To Do</option>
<option {{#ifCond status '==' 'In Progress'}}selected{{/ifCond}} value="In Progress">In Progress</option>
<option {{#ifCond status '==' 'On Hold'}}selected{{/ifCond}} value="On Hold">On Hold</option>
<option {{#ifCond status '==' 'Completed'}}selected{{/ifCond}} value="Completed">Completed</option>
</select>
</div>
<input name="id" type="hidden" value="{{id}}" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</td>
</tr>
{{/each}}
</tbody>

</table>
</div>


<!-- PAST TASKS I'VE ASSIGNED TO OTHERS -->
<div class="container">
<h2>Past Tasks I've Assigned to Others</h2>
<p></p>
<table class="table table-striped">

<thead class="thead-dark">
<tr>
<th scope="col">Project</th>
<th scope="col">Task</th>
<th scope="col">Description</th>
<th scope="col">Due Date</th>
<th scope="col">Status</th>
<th scope="col">Assignee</th>
<th scope="col">Manage</th>
</tr>
</thead>

<tbody>
{{#each pasttasks}}
<tr>
<th scope="row">{{Project_Name}}</th>
<td>{{name}}</td>
<td>{{description}}</td>
<td {{#if isOverdue}} class="danger"{{/if}}>{{due_date}}</td>
<td>{{status}}</td>
<td>{{assignee_name}}</td>
<td>
<a href="/task/{{task_id}}">
<button type="button" class="btn btn-success">
View Task
</button>
</a>
<button class="btn btn-primary" data-toggle="modal" data-target=".bs-modal-sm2-{{id}}">
<i class="fa fa-edit"></i>
</button>
<div class="modal fade bs-modal-sm2-{{id}}">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Edit Task {{name}}</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
</div>
<div class="modal-body">
{{#if is_sub}}<!-- if is subtask -->
<form method="post" action="/task/update-status">
{{else}}<!-- if is task -->
<form method="post" action="/project/update-status">
{{/if}}
<div class="form-row">
<div class="form-group col-sm-4">
<label for="status">Status</label>
<select required class="custom-select mr-sm-2" name="status">
<option {{#ifCond status '==' 'To Do'}}selected{{/ifCond}} value="To Do">To Do</option>
<option {{#ifCond status '==' 'In Progress'}}selected{{/ifCond}} value="In Progress">In Progress</option>
<option {{#ifCond status '==' 'On Hold'}}selected{{/ifCond}} value="On Hold">On Hold</option>
<option {{#ifCond status '==' 'Completed'}}selected{{/ifCond}} value="Completed">Completed</option>
</select>
</div>
<input name="id" type="hidden" value="{{id}}" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</td>
</tr>
{{/each}}
</tbody>

</table>
</div>

0 comments on commit 1dc6ce0

Please sign in to comment.