Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotrajano committed Jun 28, 2020
1 parent 77d64b8 commit 5ce4113
Show file tree
Hide file tree
Showing 10 changed files with 466 additions and 27 deletions.
24 changes: 20 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const StatusProject = require(`./models/StatusProject`);
const Project = require(`./models/Project`);
const FeatureStatus = require(`./models/FeatureStatus`);
const StatusProgress = require(`./models/StatusProgress`);
const SERVER_PORT = 8787;
const SERVER_PORT = process.env.PORT || 8787;

app.use(
session({ secret: "keyboardCat", resave: false, saveUninitialized: true })
);
app.use(flash());
app.use(function (req, res, next) {
console.log("ACESSANDO MIDDLEWARE");
console.log("ACESSANDO MIDDLEWARE...");

res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
Expand Down Expand Up @@ -91,6 +91,22 @@ app.get(`/api/getStatusProgress`, (req, res) => {
});
});

app.listen(SERVER_PORT, function () {
console.log("SERVIDOR STARTED!");
app.get(`/api/getStatus`, (req, res) => {
StatusProgress.getStatus()
.then(function (results) {
res.send(results);
})
.catch(function (err) {
req.flash("error_msg", "ERROR" + err);
res.redirect(`/project`);
});
});

app.get(`/api/getStatus2`, async (req, res) => {
let result = await StatusProgress.getStatus();
res.send(result);
});

app.listen(SERVER_PORT, () => {
console.log("Server listening on port " + SERVER_PORT);
});
36 changes: 25 additions & 11 deletions db/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,31 @@ const HOST = "localhost";
const USER = "root";
const PASSWORD = "123456";
const DATABASE = "trackpath";
let cachedDbPool;

const connection = mysql.createConnection({
host: HOST,
user: USER,
password: PASSWORD,
database: DATABASE,
});
// const connection = mysql.createConnection({
// host: HOST,
// user: USER,
// password: PASSWORD,
// database: DATABASE,
// });

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

module.exports = connection;
function cachedPool() {
if (!cachedDbPool) {
cachedDbPool = mysql.createPool({
connectionLimit: 1,
host: HOST,
user: USER,
password: PASSWORD,
database: DATABASE,
});
}
return cachedDbPool;
}

module.exports = cachedPool();
36 changes: 36 additions & 0 deletions models/Bug.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ const create = async function (bug, callback) {
});
};

const updateSolveIssue = async function (bug, callback) {
let sql = `update bugs as b
SET b.Summary = "${bug.Summary}", b.StatusID = "${bug.featureStatus}" where b.ID=${bug.bugID}`;

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

const findByPK = async function (id, callback) {
let sql = `SELECT b.ID, b.Title, b.Summary, b.EstimatedHours,DATE_FORMAT(b.DeliveryDate,'%Y-%m-%d') as DeliveryDate, DATE_FORMAT(b.CreatedAt,'%Y-%m-%d') as CreatedAt,b.ProjectID,b.StatusID,b.SeverityID,b.PriorityID
FROM bugs as b
where b.ID =${id}`;

connection.query(sql, function (err, result) {
if (err) throw err;
console.log(sql);
return callback(result[0]);
});
};

const findAll = async function (callback) {
let sql = `select * from bugs`;

Expand All @@ -24,7 +47,20 @@ const findAll = async function (callback) {
});
};

const getBugsByProject = async function (id, callback) {
let sql = `select * from bugs where projectid=${id}`;

connection.query(sql, function (err, results) {
if (err) throw err;
console.log(sql);
return callback(results);
});
};

module.exports = {
create: create,
findAll: findAll,
getBugsByProject: getBugsByProject,
findByPK: findByPK,
updateSolveIssue: updateSolveIssue,
};
21 changes: 20 additions & 1 deletion models/StatusProgress.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const connection = require("../db/connection");

const StatusProgressValue = {
NOT_STARTED: 6,
DONE: 10,
Expand All @@ -14,4 +15,22 @@ const findAll = async function (callback) {
});
};

module.exports = { StatusProgressValue: StatusProgressValue, findAll: findAll };
async function getStatus() {
return new Promise((resolve, reject) => {
let sql = `SELECT * FROM StatusProgress`;
connection.cachedPool().query(sql, (err, results) => {
//if (err) throw err;
if (err) {
reject(err);
} else {
resolve(results);
}
});
});
}

module.exports = {
StatusProgressValue: StatusProgressValue,
findAll: findAll,
getStatus: getStatus,
};
28 changes: 28 additions & 0 deletions routes/bug.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ router.post(`/add`, (req, res) => {
});
});

router.get(`/`, (req, res) => {
res.render(`bug/bugs`);
});

router.get(`/solveIssue/:bugID`, (req, res) => {
Bug.findByPK(req.params.bugID, (bug) => {
Project.findByPK(bug.ProjectID, (project) => {
bug.project = project;
res.render(`bug/solveIssue`, { bug: bug });
});
});
});

router.post(`/solveIssue`, (req, res) => {
let bug = req.body;

Bug.updateSolveIssue(bug, (result) => {
req.flash("success_msg", "Bug successfully updated!");
res.redirect(`/bug`);
});
});

router.get(`/getSeverity`, (req, res) => {
Severity.findAll((results) => {
res.send(results);
Expand All @@ -43,4 +65,10 @@ router.get(`/getPriority`, (req, res) => {
});
});

router.get(`/getBugsByProject/:id`, (req, res) => {
Bug.getBugsByProject(req.params.id, (results) => {
res.send(results);
});
});

module.exports = router;
14 changes: 7 additions & 7 deletions routes/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ router.get(`/`, (req, res) => {

router.get(`/getFeaturesByProject/:id`, (req, res) => {
Feature.findFeaturesByProjects(req.params.id, function (results) {
let features = [];
results.forEach((feature) => {
if (feature.FeatureStatusID !== FeatureStatus.STATUS.CLOSED) {
features.push(feature);
}
});
res.send(features);
// let features = [];
// results.forEach((feature) => {
// if (feature.FeatureStatusID !== FeatureStatus.STATUS.CLOSED) {
// features.push(feature);
// }
// });
res.send(results);
});
});

Expand Down
143 changes: 143 additions & 0 deletions views/bug/bugs.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<h2>Bugs</h2>
<hr>

{{#each erros }}
<div class="alert-danger">{{texto}}</div>
{{else}}
{{/each}}


<div class="container">
<form action="" method="post">

<div class="row">
<div class="col-25">
<label for="ProjectCombo">Project</label>
</div>
<div class="col-75">
<select id="ProjectCombo" name="ProjectCombo"></select>
</div>
</div>

<div class="row w3-margin-top">
<input type="submit" class="w3-grey" value="Search">
</div>
</form>
</div>
<div id="containerList"></div>
<script>
$(document).ready(function () {
getActiveProjects();
});
async function getActiveProjects() {
const res = await fetch("http://localhost:8787/api/getActiveProjects");
const json = await res.json();
let ProjectCombo = document.getElementById("ProjectCombo");
let option = document.createElement("option");
option.value = 0;
option.innerText = "Select a project...";
ProjectCombo.appendChild(option);
for (let i = 0; i < json.length; i++) {
let option = document.createElement("option");
option.value = json[i].ID;
option.innerText = json[i].NameProject;
ProjectCombo.appendChild(option);
}
}
$(document).ready(function () {
$("#ProjectCombo").change(function () {
let id = $(this).children("option:selected").val();
getBugsByProject(id)
});
});
async function getBugsByProject(id) {
$("#containerList").empty()
const res = await fetch(`http://localhost:8787/bug/getBugsByProject/${id}`);
const json = await res.json();
let containerList = document.getElementById("containerList");
let i;
for (i = 0; i < json.length; i++) {
let divItem = document.createElement("div");
divItem.setAttribute("class", "solveItemDiv")
let p = document.createElement("p");
p.innerText = json[i].Title;
divItem.appendChild(p)
let span = document.createElement("span");
if (json[i].StatusID === 1) {
span.setAttribute("class", "label-issue danger")
span.innerText = "Open";
} else if (json[i].StatusID === 2) {
span.setAttribute("class", "label-issue warning")
span.innerText = "In progress";
} else if (json[i].FeatureStatusID === 3) {
span.setAttribute("class", "label-issue success")
span.innerText = "To be tested";
} else {
span.setAttribute("class", "label-issue info")
span.innerText = "Closed";
}
divItem.appendChild(span)
containerList.appendChild(divItem)
let p1 = document.createElement("p");
p1.innerText = "Notes: " + json[i].Summary;
let div = document.createElement("div");
div.setAttribute("class", "panel")
div.appendChild(p1)
containerList.appendChild(div)
let DivPanel = document.getElementsByClassName("panel")
let openFeatureLink = document.createElement("a");
openFeatureLink.setAttribute("href", `bug/solveIssue/${json[i].ID}`)
let openFeaturebutton = document.createElement("button");
openFeaturebutton.setAttribute("class", "w3-button w3-grey w3-round-medium w3-margin-bottom")
openFeaturebutton.innerText = "Solve Issue"
openFeatureLink.appendChild(openFeaturebutton)
DivPanel[i].appendChild(openFeatureLink)
}
var acc = document.getElementsByClassName("solveItemDiv");
var j;
for (j = 0; j < acc.length; j++) {
acc[j].addEventListener("click", function () {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
});
}
}
</script>
Loading

0 comments on commit 5ce4113

Please sign in to comment.