-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c94cc95
commit 1dc6ce0
Showing
4 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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">×</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">×</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> |