Skip to content

Commit

Permalink
new features
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotrajano committed Jun 20, 2020
1 parent e2c212b commit 368a541
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 50 deletions.
7 changes: 7 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const flash = require("connect-flash");
const StatusProject = require(`./models/StatusProject`);
const Project = require(`./models/Project`);
const FeatureStatus = require(`./models/FeatureStatus`);
const StatusProgress = require(`./models/StatusProgress`);
const SERVER_PORT = 8787;

app.use(
Expand Down Expand Up @@ -80,6 +81,12 @@ app.get(`/api/getFeatureStatus`, (req, res) => {
});
});

app.get(`/api/getStatusProgress`, (req, res) => {
StatusProgress.findAll(async function (results) {
res.send(results);
});
});

app.listen(SERVER_PORT, function () {
console.log("SERVIDOR STARTED!");
});
86 changes: 83 additions & 3 deletions models/Feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ const create = async function (feature, callback) {
if (err) throw err;
console.log("Connected!");

let sql = `insert into Features (TitleFeature, DescriptionFeature, EstimatedTime, DeliveryDate, CreatedAt, ProjectID, FeatureStatusID)
values
("${feature.TitleFeature}", "${feature.DescriptionFeature}", ${feature.EstimatedTime}, STR_TO_DATE('${feature.DeliveryDate}', '%Y-%m-%d'), STR_TO_DATE('${feature.CreatedAt}', '%Y-%m-%d'),${feature.ProjectID},${feature.FeatureStatusID})`;
let sql = `insert into Features (TitleFeature, DescriptionFeature, EstimatedTime, DeliveryDate,
CreatedAt, ProjectID, FeatureStatusID, StatusProgressID)
values
("${feature.TitleFeature}", "${feature.DescriptionFeature}", ${feature.EstimatedTime},
STR_TO_DATE('${feature.DeliveryDate}', '%Y-%m-%d'), STR_TO_DATE('${feature.CreatedAt}', '%Y-%m-%d'),
${feature.ProjectID},${feature.FeatureStatusID},${feature.StatusProgressID})`;

console.log(sql);

Expand Down Expand Up @@ -56,7 +59,84 @@ const findFeaturesByProjects = async function (projectID, callback) {
});
};

const findByPK = async function (ID, 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 f.ID, f.TitleFeature, f.DescriptionFeature, f.EstimatedTime, DATE_FORMAT(f.DeliveryDate,'%Y-%m-%d') as DeliveryDate,
DATE_FORMAT( f.CreatedAt,'%Y-%m-%d') as CreatedAt, f.ProjectID, f.FeatureStatusID,
f.StatusProgressID from features as f where f.ID =${ID}`;

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

const update = async function (ID, 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 = `UPDATE features as f
SET f.TitleFeature = '${obj.StartDate}', f.DescriptionFeature = '${obj.StartDate}', f.EstimatedTime = '${obj.StartDate}', f.DeliveryDate = STR_TO_DATE('${obj.StartDate}', '%Y-%m-%d'), f.CreatedAt = STR_TO_DATE('${obj.StartDate}', '%Y-%m-%d'), f.FeatureStatusID = ${obj.StartDate}, f.StatusProgressID = ${obj.StartDate}
WHERE f.ID =${obj.StartDate}`;

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

const updateSolveIssue = async function (feature, 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 = `UPDATE features as f
SET f.DescriptionFeature = '${feature.DescriptionFeature}', f.FeatureStatusID = ${feature.FeatureStatusID}, f.StatusProgressID = ${feature.StatusProgressID}
WHERE f.ID =${feature.ID}`;

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

module.exports = {
create: create,
findFeaturesByProjects: findFeaturesByProjects,
findByPK: findByPK,
updateSolveIssue: updateSolveIssue,
};
51 changes: 28 additions & 23 deletions models/FeatureStatus.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
const mysql = require("mysql");
const HOST = "localhost"
const USER = "root"
const PASSWORD = "123456"
const DATABASE = "trackpath"

const HOST = "localhost";
const USER = "root";
const PASSWORD = "123456";
const DATABASE = "trackpath";
const STATUS = {
OPEN: 1,
IN_PROGRESS: 2,
TO_BE_TESTED: 3,
CLOSED: 4,
};

const findAll = async function(callback) {
const con = await mysql.createConnection({
host: HOST,
user: USER,
password:PASSWORD ,
database: DATABASE,
});
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!");
con.connect(async function (err) {
if (err) throw err;
console.log("Connected!");

let sql = `SELECT * FROM FeatureStatus`;
let sql = `SELECT * FROM FeatureStatus`;

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

module.exports = {findAll:findAll}
module.exports = { STATUS: STATUS, findAll: findAll };
34 changes: 34 additions & 0 deletions models/StatusProgress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const mysql = require("mysql");
const HOST = "localhost";
const USER = "root";
const PASSWORD = "123456";
const DATABASE = "trackpath";
const StatusProgressValue = {
NOT_STARTED: 6,
DONE: 10,
};

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 StatusProgress`;

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

module.exports = { StatusProgressValue: StatusProgressValue, findAll: findAll };
34 changes: 33 additions & 1 deletion routes/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const express = require(`express`);
const router = express.Router();
const Project = require(`../models/Project`);
const Feature = require(`../models/Feature`);
const StatusProgress = require(`../models/StatusProgress`);
const FeatureStatus = require(`../models/FeatureStatus`);
const moment = require("moment");

router.get(`/`, (req, res) => {
Expand All @@ -10,7 +12,13 @@ router.get(`/`, (req, res) => {

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

Expand All @@ -30,6 +38,7 @@ router.post(`/new`, (req, res) => {
CreatedAt: moment().format("YYYY-MM-DD"),
ProjectID: req.body.projectID,
FeatureStatusID: req.body.featureStatus,
StatusProgressID: StatusProgress.StatusProgressValue.NOT_STARTED,
};

Feature.create(feature, function () {
Expand All @@ -38,4 +47,27 @@ router.post(`/new`, (req, res) => {
});
});

router.get(`/solveIssue/:id`, (req, res) => {
Feature.findByPK(req.params.id, function (feature) {
Project.findByPK(feature.ProjectID, function (project) {
feature.project = project;
res.render("feature/solveIssue", { feature: feature });
});
});
});

router.post(`/solveIssue`, (req, res) => {
const feature = {
ID: req.body.featureID,
DescriptionFeature: req.body.description,
FeatureStatusID: req.body.featureStatus,
StatusProgressID: req.body.Progress,
};

Feature.updateSolveIssue(feature, function (result) {
req.flash("success_msg", "Feature successfully updated!");
res.redirect(`/feature`);
});
});

module.exports = router;
26 changes: 25 additions & 1 deletion sql_db_scripts/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,28 @@ CREATE TABLE `projects` (
PRIMARY KEY (`ID`),
KEY `StatusID` (`StatusID`),
CONSTRAINT `projects_ibfk_1` FOREIGN KEY (`StatusID`) REFERENCES `statusproject` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;



CREATE TABLE `StatusProgress` (
`ID` int NOT NULL AUTO_INCREMENT,
`StatusProgressValue` int NOT NULL,
`StatusProgress` varchar(50) NOT NULL,
PRIMARY KEY (`ID`)
)

insert into StatusProgress (StatusProgressValue,StatusProgress) values (0, "Not Started");
insert into StatusProgress (StatusProgressValue,StatusProgress) values (25, "25%");
insert into StatusProgress (StatusProgressValue,StatusProgress) values (50, "50%");
insert into StatusProgress (StatusProgressValue,StatusProgress) values (75, "75%");
insert into StatusProgress (StatusProgressValue,StatusProgress) values (100, "Done") ;

ALTER TABLE features
ADD StatusProgressID int

ALTER TABLE features
ADD FOREIGN KEY (StatusProgressID) REFERENCES StatusProgress(ID);

ALTER TABLE features
MODIFY DescriptionFeature varchar(3000) NULL;
20 changes: 18 additions & 2 deletions views/feature/feature.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,28 @@
containerList.appendChild(button)
let p = document.createElement("p");
p.innerText = json[i].DescriptionFeature;
p.innerText = "Notes: " + json[i].DescriptionFeature;
let div = document.createElement("div");
div.appendChild(p)
div.setAttribute("class", "panel")
div.appendChild(p)
containerList.appendChild(div)
let DivPanel = document.getElementsByClassName("panel")
let openFeatureLink = document.createElement("a");
openFeatureLink.setAttribute("href", `feature/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)
}
Expand Down
2 changes: 1 addition & 1 deletion views/feature/newFeature.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

<div class="row">
<div class="col-25">
<label for="description">Description</label>
<label for="description">Notes</label>
</div>
<div class="col-75">
<textarea id="description" name="description" placeholder="Describe new feature..."
Expand Down
Loading

0 comments on commit 368a541

Please sign in to comment.