Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotrajano committed Jul 8, 2020
1 parent b5be034 commit 2931ac3
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 53 deletions.
17 changes: 8 additions & 9 deletions models/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ const mysql = require("mysql");
const create = (project) => {
return new Promise((resolve, reject) => {
let sql = `INSERT INTO projects (NameProject,StartDate,EndDate,DescriptionProject,StatusID)
VALUES ('${project.NameProject}',STR_TO_DATE('${project.StartDate}',
'%Y-%m-%d'),STR_TO_DATE('${project.EndDate}', '%Y-%m-%d'),
'${project.DescriptionProject}',${project.StatusID})`;
VALUES ('${project.name}',STR_TO_DATE('${project.startDate}',
'%Y-%m-%d'),STR_TO_DATE('${project.endDate}', '%Y-%m-%d'),'${project.description}',${project.status})`;

connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result);
Expand All @@ -17,11 +16,11 @@ const create = (project) => {
const update = (project) => {
return new Promise((resolve, reject) => {
let sql = `update projects
set NameProject = '${project.NameProject}' ,
StartDate = STR_TO_DATE('${project.StartDate}', '%Y-%m-%d'),
EndDate = STR_TO_DATE('${project.EndDate}', '%Y-%m-%d') ,
DescriptionProject = '${project.DescriptionProject}', StatusID = ${project.StatusID}
where ID = ${project.ID}`;
set NameProject = '${project.name}' ,
StartDate = STR_TO_DATE('${project.startDate}', '%Y-%m-%d'),
EndDate = STR_TO_DATE('${project.endDate}', '%Y-%m-%d') ,
DescriptionProject = '${project.description}', StatusID = ${project.status}
where ID = ${project.id}`;

connection.query(sql, (err, result) => {
err ? reject(err) : resolve(result);
Expand All @@ -31,7 +30,7 @@ const update = (project) => {

const findAll = () => {
return new Promise((resolve, reject) => {
let sql = `select p.ID as ID, p.NameProject, DATE_FORMAT(p.StartDate,'%Y-%m-%d') as StartDate , DATE_FORMAT(p.EndDate,'%Y-%m-%d') as EndDate, p.DescriptionProject, sp.ID as StatusID, sp.StatusName
let sql = `select p.ID as id, p.NameProject, DATE_FORMAT(p.StartDate,'%Y-%m-%d') as StartDate , DATE_FORMAT(p.EndDate,'%Y-%m-%d') as EndDate, p.DescriptionProject, sp.ID as StatusID, sp.StatusName
from projects as p
inner join statusproject as sp
on p.StatusID = sp.ID
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon"
},
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ hr {
/* Float four columns side by side */
.column-db {
float: left;
width: 25%;
width: 20%;
padding: 0 5px;
}

Expand Down
14 changes: 12 additions & 2 deletions routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ router.get(`/`, async (req, res) => {
let totalFeatures = 0;
let totalIssuesSolved = 0;
let totalBugs = 0;
let totalClosedBugs = 0;

totalProjects = await Project.findAll();

Expand All @@ -23,13 +24,22 @@ router.get(`/`, async (req, res) => {
}
});

totalBugs = await Bug.findAll();
let bugs = await Bug.findAll();

bugs.forEach((bug) => {
if (bug.StatusID === FeatureStatus.STATUS.CLOSED) {
totalClosedBugs++;
} else {
totalBugs++;
}
});

res.render("admin/dashboard", {
totalProjects: totalProjects.length,
totalFeatures: totalFeatures,
totalIssuesSolved: totalIssuesSolved,
totalBugs: totalBugs.length,
totalBugs: totalBugs,
totalClosedBugs: totalClosedBugs,
});
});

Expand Down
31 changes: 14 additions & 17 deletions routes/project.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require(`express`);
const router = express.Router();
const Project = require(`../models/Project`);
const moment = require(`moment`);

router.get(`/`, (req, res) => {
Project.findAll()
Expand All @@ -18,6 +19,11 @@ router.get(`/new`, (req, res) => {

router.post(`/new`, (req, res) => {
let errors = [];
let project = req.body;

if (moment(req.body.startDate).isAfter(req.body.endDate)) {
errors.push({ texto: "Start Date must be less than End Date!" });
}

if (req.body.pName === "") {
errors.push({ texto: "Invalid input" });
Expand All @@ -28,16 +34,7 @@ router.post(`/new`, (req, res) => {
erros: errors,
});
} else {
const project = {
ID: req.body.ID,
NameProject: req.body.pName,
StartDate: req.body.startDate,
EndDate: req.body.endDate,
DescriptionProject: req.body.pDescription,
StatusID: req.body.pPriority,
};

if (!project.ID || project.ID === null || project.ID === undefined) {
if (!project.id || project.id === null || project.id === undefined) {
Project.create(project)
.then(() => {
req.flash("success_msg", "Project added successfully!");
Expand Down Expand Up @@ -65,12 +62,12 @@ router.get(`/edit/:id`, (req, res) => {
Project.findByPK(req.params.id)
.then((project) => {
res.render("project/newProject", {
ID: project.ID,
NameProject: project.NameProject,
StartDate: project.StartDate,
EndDate: project.EndDate,
StatusID: project.StatusID,
DescriptionProject: project.DescriptionProject,
id: project.ID,
name: project.NameProject,
startDate: project.StartDate,
endDate: project.EndDate,
statusId: project.StatusID,
description: project.DescriptionProject,
});
})
.catch((e) => {
Expand All @@ -80,7 +77,7 @@ router.get(`/edit/:id`, (req, res) => {
});

router.post(`/delete`, (req, res) => {
Project.remove(req.body.ID)
Project.remove(req.body.id)
.then(() => {
req.flash("error_msg", "Project has been deleted!");
res.redirect(`/project`);
Expand Down
8 changes: 8 additions & 0 deletions views/admin/dashboard.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
</div>
</div>

<div class="column-db">
<div class="card-db">
<p><i class="fa fa-bug i-size" aria-hidden="true"></i></p>
<h3>{{totalClosedBugs}}</h3>
<p>Bugs Done</p>
</div>
</div>



</div>
2 changes: 1 addition & 1 deletion views/bug/bugs.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
for (let i = 0; i < json.length; i++) {
let option = document.createElement("option");
option.value = json[i].ID;
option.value = json[i].id;
option.innerText = json[i].NameProject;
ProjectCombo.appendChild(option);
}
Expand Down
2 changes: 1 addition & 1 deletion views/feature/feature.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
for (let i = 0; i < json.length; i++) {
let option = document.createElement("option");
option.value = json[i].ID;
option.value = json[i].id;
option.innerText = json[i].NameProject;
ProjectCombo.appendChild(option);
}
Expand Down
26 changes: 13 additions & 13 deletions views/project/newProject.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,42 @@
<label for="pName">Project Name</label>
</div>
<div class="col-75">
<input type="hidden" id="ID" name="ID" value="{{ID}}">
<input type="text" id="pName" name="pName" value="{{NameProject}}">
<input type="hidden" id="id" name="id" value="{{id}}">
<input type="text" id="name" name="name" value="{{name}}">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="startDate">Start Date</label>
</div>
<div class="col-75">
<input type="date" id="startDate" name="startDate" value="{{StartDate}}">
<input type="date" id="startDate" name="startDate" value="{{startDate}}">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="endDate">End Date</label>
</div>
<div class="col-75">
<input type="date" id="endDate" name="endDate" value="{{EndDate}}">
<input type="date" id="endDate" name="endDate" value="{{endDate}}">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="pPriority">Status</label>
<label for="status">Status</label>
</div>
<div class="col-75">
<input type="hidden" value="{{StatusID}}" id="status">
<select id="pPriority" name="pPriority"></select>
<input type="hidden" value="{{statusId}}" id="statusId">
<select id="status" name="status"></select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="pDescription">Description</label>
<label for="description">Description</label>
</div>
<div class="col-75">
<textarea id="pDescription" name="pDescription" placeholder="Write something..."
style="height:200px">{{DescriptionProject}}</textarea>
<textarea id="description" name="description" placeholder="Write project description..."
style="height:200px">{{description}}</textarea>
</div>
</div>
<div class="row">
Expand All @@ -70,8 +70,8 @@
const res = await fetch("http://localhost:8787/api/getStatusProject");
const json = await res.json();
let pPriority = document.getElementById("pPriority");
let status = document.getElementById("status").value;
let statusSelect = document.getElementById("status");
let status = document.getElementById("statusId").value;
for (let i = 0; i < json.length; i++) {
let option = document.createElement("option");
Expand All @@ -80,7 +80,7 @@
if (status == json[i].ID) {
option.setAttribute("selected", "");
}
pPriority.appendChild(option);
statusSelect.appendChild(option);
}
}
Expand Down
16 changes: 8 additions & 8 deletions views/project/project.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@
<h5 class="w3-margin-bottom">Description: {{DescriptionProject}}</h5>
</div>
<div class="w3-bar w3-margin-bottom">
<a href="/feature/new/{{ID}}"> <button class="w3-button w3-grey w3-round-medium"><i class="fa fa-plus"
<a href="/feature/new/{{id}}"> <button class="w3-button w3-grey w3-round-medium"><i class="fa fa-plus"
aria-hidden="true"></i> New Feature</button></a>
<a href="/bug/add/{{ID}}"> <button class="w3-button w3-grey w3-round-medium"><i class="fa fa-plus"
<a href="/bug/add/{{id}}"> <button class="w3-button w3-grey w3-round-medium"><i class="fa fa-plus"
aria-hidden="true"></i>
Bugs</button></a>
<a href="/project/edit/{{ID}}"> <button class="w3-button w3-grey w3-round-medium">Edit</button></a>
<button onclick="document.getElementById('form_{{ID}}').style.display='block'"
<a href="/project/edit/{{id}}"> <button class="w3-button w3-grey w3-round-medium">Edit</button></a>
<button onclick="document.getElementById('form_{{id}}').style.display='block'"
class="w3-button w3-red w3-round-medium">Delete</button>
</div>
</div>
<div id="form_{{ID}}" class="modal">
<span onclick="document.getElementById('form_{{ID}}').style.display='none'" class="close"
<div id="form_{{id}}" class="modal">
<span onclick="document.getElementById('form_{{id}}').style.display='none'" class="close"
title="Close Modal">&times;</span>
<form class="modal-content" action="/project/delete" method="post">
<input type="hidden" id="ID" name="ID" value="{{ID}}">
<input type="hidden" id="id" name="id" value="{{id}}">
<div class="container1">
<h1>Delete Project</h1>
<p>Are you sure you want to delete this project?</p>
<div class="clearfix">
<button type="button" class="cancelbtn"
onclick="document.getElementById('form_{{ID}}').style.display='none'">Cancel</button>
onclick="document.getElementById('form_{{id}}').style.display='none'">Cancel</button>
<button type="submit" class="deletebtn">Delete</button>

</div>
Expand Down

0 comments on commit 2931ac3

Please sign in to comment.