Skip to content

Commit

Permalink
modification
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotrajano committed Jun 24, 2020
1 parent c810d92 commit 6a38019
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 59 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
const path = require(`path`);
const project = require(`./routes/project`);
const feature = require(`./routes/feature`);
const admin = require(`./routes/admin`);
const session = require("express-session");
const flash = require("connect-flash");
const StatusProject = require(`./models/StatusProject`);
Expand Down Expand Up @@ -54,6 +55,7 @@ app.use(bodyparser.json());
app.use(express.static(path.join(__dirname, `public`)));
app.use(`/project`, project);
app.use(`/feature`, feature);
app.use(`/admin`, admin);

app.get("/", function (req, res) {
res.render(`index`);
Expand Down
26 changes: 25 additions & 1 deletion models/Feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,30 @@ const findFeaturesByProjects = async function (projectID, callback) {
console.log("Connected!");

let sql = `select * from features as f
where f.ProjectID = ${projectID}`;
where f.ProjectID = ${projectID} ORDER BY ID DESC`;

con.query(sql, async function (err, result) {
if (err) throw err;
console.log(sql);
con.destroy();
return callback(result);
});
});
};

const findAll = async function (callback) {
const con = await mysql.createConnection({
host: HOST,
user: USER,
password: PASSWORD,
database: DATABASE,
});

con.connect(async function (err) {
if (err) throw err;
console.log("Connected!");

let sql = `select * from features as f`;

con.query(sql, async function (err, result) {
if (err) throw err;
Expand Down Expand Up @@ -139,4 +162,5 @@ module.exports = {
findFeaturesByProjects: findFeaturesByProjects,
findByPK: findByPK,
updateSolveIssue: updateSolveIssue,
findAll: findAll,
};
42 changes: 42 additions & 0 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,45 @@ hr {
margin-top: 10px;
margin-bottom: 10px;
}

/* ############################# DASHBOARD ############################################################*/

/* Float four columns side by side */
.column-db {
float: left;
width: 25%;
padding: 0 5px;
}

.row-db {
margin-top: 70px;
}

/* Clear floats after the columns */
.row-db:after {
content: "";
display: table;
clear: both;
}

/* Responsive columns */
@media screen and (max-width: 600px) {
.column-db {
width: 100%;
display: block;
margin-bottom: 10px;
}
}

/* Style the counter cards */
.card-db {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 16px;
text-align: center;
background-color: #444;
color: white;
}

.i-size {
font-size: 50px;
}
42 changes: 42 additions & 0 deletions routes/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const express = require(`express`);
const router = express.Router();
const Project = require(`../models/Project`);
const Feature = require(`../models/Feature`);
const FeatureStatus = require(`../models/FeatureStatus`);
let totalProjects = 0;
let totalFeatures = 0;
let totalIssuesSolved = 0;

router.get(`/`, (req, res) => {
Project.findAll(async function (results) {
if (!results || results !== null) {
totalProjects = results.length;
}
});

Feature.findAll(async function (features) {
totalFeatures = 0;
features.forEach((feature) => {
if (feature.FeatureStatusID !== FeatureStatus.STATUS.CLOSED) {
totalFeatures++;
}
});
});

Feature.findAll(async function (features) {
totalIssuesSolved = 0;
features.forEach((feature) => {
if (feature.FeatureStatusID === FeatureStatus.STATUS.CLOSED) {
totalIssuesSolved++;
}
});
});

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

module.exports = router;
137 changes: 81 additions & 56 deletions routes/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,103 @@ const router = express.Router();
const Project = require(`../models/Project`);

router.get(`/`, (req, res) => {
Project.findAll(function(results) {
res.render("project/project", { Projects: results });
});
Project.findAll(function (results) {
res.render("project/project", { Projects: results });
});
});

router.get(`/new`, (req, res) => {
res.render("project/newProject");
res.render("project/newProject");
});

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

if (!req.body.pName ||
typeof req.body.pName === undefined ||
req.body.pName == null
) {
errors.push({ texto: "Project name required!" });
}
if (
!req.body.pName ||
typeof req.body.pName === undefined ||
req.body.pName == null
) {
errors.push({ texto: "Project name required!" });
}

if (errors.length > 0) {
res.render("project/newProject", {
erros: errors,
});
} else {
const newProject = {
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 (
!req.body.startDate ||
typeof req.body.startDate === undefined ||
req.body.startDate == null
) {
errors.push({ texto: "Start Date required!" });
}

if (
!req.body.endDate ||
typeof req.body.endDate === undefined ||
req.body.endDate == null
) {
errors.push({ texto: "End Date required!" });
}

if (
!req.body.pDescription ||
typeof req.body.pDescription === undefined ||
req.body.pDescription == null
) {
errors.push({ texto: "Description required!" });
}

if (!newProject.ID ||
newProject.ID === null ||
newProject.ID === undefined
) {
Project.create(newProject, function() {
req.flash("success_msg", "Project added successfully!");
res.redirect(`/project`);
});
} else {
Project.update(newProject, function() {
req.flash("success_msg", "Project modified successfully!");
res.redirect(`/project`);
});
}
if (errors.length > 0) {
res.render("project/newProject", {
erros: errors,
});
} else {
const newProject = {
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 (
!newProject.ID ||
newProject.ID === null ||
newProject.ID === undefined
) {
Project.create(newProject, function () {
req.flash("success_msg", "Project added successfully!");
res.redirect(`/project`);
});
} else {
Project.update(newProject, function () {
req.flash("success_msg", "Project modified successfully!");
res.redirect(`/project`);
});
}
}
});

router.get(`/edit/:id`, (req, res) => {
console.log(req.params.id);
Project.findByPK(req.params.id, function(result) {
console.log(result);
res.render("project/newProject", {
ID: result.ID,
NameProject: result.NameProject,
StartDate: result.StartDate,
EndDate: result.EndDate,
StatusID: result.StatusID,
DescriptionProject: result.DescriptionProject,
});
console.log(req.params.id);
Project.findByPK(req.params.id, function (result) {
console.log(result);
res.render("project/newProject", {
ID: result.ID,
NameProject: result.NameProject,
StartDate: result.StartDate,
EndDate: result.EndDate,
StatusID: result.StatusID,
DescriptionProject: result.DescriptionProject,
});
});
});

router.post(`/delete`, (req, res) => {
console.log(req.body.ID)
Project.remove(req.body.ID, function() {
req.flash("error_msg", "Project has been deleted!");
res.redirect(`/project`);
})
console.log(req.body.ID);
Project.remove(req.body.ID, function () {
req.flash("error_msg", "Project has been deleted!");
res.redirect(`/project`);
});
});


module.exports = router;
module.exports = router;
34 changes: 34 additions & 0 deletions views/admin/dashboard.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="row-db">
<div class="column-db">
<div class="card-db">
<p><i class="fa fa fa-lightbulb-o i-size" aria-hidden="true"></i></p>
<h3>{{totalProjects}}</h3>
<p>Projects</p>
</div>
</div>

<div class="column-db">
<div class="card-db">
<p><i class="fa fa-folder-open-o i-size" aria-hidden="true"></i></p>
<h3>{{totalFeatures}}</h3>
<p>New Features</p>
</div>
</div>

<div class="column-db">
<div class="card-db">
<p><i class="fa fa-bug i-size" aria-hidden="true"></i></p>
<h3>0</h3>
<p>Bugs Reported</p>
</div>
</div>

<div class="column-db">
<div class="card-db">
<p><i class="fa fa-check i-size"></i></p>
<h3>{{totalIssuesSolved}}</h3>
<p>Issues Solved</p>
</div>
</div>

</div>
5 changes: 3 additions & 2 deletions views/layouts/main.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

<div class="w3-sidebar w3-bar-block w3-card w3-animate-left" style="display:none" id="mySidebar">
<button class="w3-bar-item w3-button w3-large" onclick="w3_close()">Close &times;</button>
<a href="#" class="w3-bar-item w3-button"><i class="fa fa-tachometer" aria-hidden="true"></i> Dashboard</a>
<a href="/admin" class="w3-bar-item w3-button"><i class="fa fa-tachometer" aria-hidden="true"></i> Dashboard</a>
<a href="/project" class="w3-bar-item w3-button"><i class="fa fa-terminal" aria-hidden="true"></i> Projects</a>
<a href="/feature" class="w3-bar-item w3-button"><i class="fa fa-plus-square" aria-hidden="true"></i> New Features</a>
<a href="/feature" class="w3-bar-item w3-button"><i class="fa fa-plus-square" aria-hidden="true"></i> New
Features</a>
<a href="#" class="w3-bar-item w3-button"><i class="fa fa-bug" aria-hidden="true"></i> Bugs</a>
<a href="#" class="w3-bar-item w3-button"><i class="fa fa-calendar" aria-hidden="true"></i> Calendar</a>
<a href="#" class="w3-bar-item w3-button"><i class="fa fa-bar-chart" aria-hidden="true"></i> Reports</a>
Expand Down

0 comments on commit 6a38019

Please sign in to comment.