diff --git a/package.json b/package.json index ad4df15..2a73c6c 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ }, "homepage": "https://github.com/Tomas025/PJTProcessoSoftware#readme", "dependencies": { + "chart.js": "^4.0.1", "dotenv": "^16.0.3", "ejs": "^3.1.8", "express": "^4.18.2", diff --git a/public/css/style.css b/public/css/style.css index 86e0dcf..5c0fb81 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -3,16 +3,16 @@ padding: 0; font-family: 'K2D', sans-serif; } - + body { background-color: #1E1E1E; font-family: Arial, Helvetica, sans-serif; } - + main { margin-left: 5vw; } - + #bgModal { visibility: hidden; position: fixed; @@ -23,7 +23,11 @@ main { z-index: 2; display: block; } - + +#mainModal { + width: 25vw; +} + #modalCriarAtividade { visibility: hidden; width: 70%; @@ -32,7 +36,48 @@ main { border-radius: 10px; margin: 17vh auto 0 auto; } + +#categoria { + background-color: #B3ADC0; + border-radius: 10px; + border: 0; + padding-left: 7px; + margin-bottom: 30px; +} + +#descrição, #data, #data2, #hora, #hora2 { + background-color: #B3ADC0; + border-radius: 10px; + border: 0; + padding-left: 7px; +} + +.data1, .datafim, .inicio, .fim { + margin-top: 25px; + font-size: 20px; +} +.inicio, .fim { + width: 10vw; + height: 30px; +} + +.finalizar, .cancelar{ + width: 7vw !important; + height: 40px !important; + margin: 20px 10px 0 0; + background-color: #9891A7; + border-radius: 10px; + border: none; +} +.lixeira { + width: 4vw !important; + height: 40px !important; + background-color: #9891A7; + border-radius: 10px; + border: none; +} + #modalVisualizarAtividade { visibility: hidden; width: 70%; @@ -41,7 +86,7 @@ main { border-radius: 10px; margin: 17vh auto 0 auto; } - + #headerModal { height: 20%; display: flex; @@ -52,34 +97,34 @@ main { font-size: 90%; color: #00000080; } - + #bodyModal { display: flex; align-items: center; justify-content: space-around; } - + #bodyModal input { width: 100%; - height: 50%; font-size: 130%; } - + #headerModal input { width: 50%; height: 50%; background-color: transparent; border: none; font-size: 130%; - cursor: pointer; + cursor: text; margin-left: 1vw; + margin-top: 3px; } - + #headerModal input:focus { box-shadow: 0 0 0 0; outline: 0; } - + #navBar { display: flex; align-items: center; @@ -87,12 +132,12 @@ main { background-color: #3C3845; margin-bottom: 5vh; } - + #logo { width: 250px; height: 65px; } - + #openModal { width: 250px; height: 40px; @@ -103,16 +148,16 @@ main { cursor: pointer; margin-left: 5vw; } - + #listaDeAtividades::-webkit-scrollbar{ width: 10px; } - + #listaDeAtividades::-webkit-scrollbar-thumb{ background-color: #706c7a71; border-radius: 10px; } - + #listaDeAtividades { display: flex; flex-direction: column; @@ -122,7 +167,7 @@ main { overflow-y: scroll; margin: 5vh 0 0 21vw; } - + #atividade { list-style: none; width: 40vw; @@ -136,7 +181,7 @@ main { display: flex; align-items: center; } - + .circle { width: 12px; height: 12px; diff --git a/public/imgs/Lixeira.png b/public/imgs/Lixeira.png new file mode 100644 index 0000000..85c2f2a Binary files /dev/null and b/public/imgs/Lixeira.png differ diff --git a/src/controllers/taskController.js b/src/controllers/taskController.js index 438dea0..dbed74b 100644 --- a/src/controllers/taskController.js +++ b/src/controllers/taskController.js @@ -1,5 +1,87 @@ +const taskModel = require('../models/task'); + module.exports = { async createTask(req, res){ - return res.render("main"); + const { name, category, dateTimeInitial, dateTimeFinal } = req.body; + + try { + const task = await taskModel.create({name, category, dateTimeInitial, dateTimeFinal}); + return res.status(200).json(task); + // return res.status(200).render("main"); + } catch (error) { + console.log(error); + return res.status(404).json({msg: "Error create task"}); + } + }, + + async index(req, res){ + try { + const tasks = await taskModel.find(); + return res.status(200).json(tasks); + // return res.status(200).render("main"); + } catch (error) { + console.log(error); + return res.status(404).json({msg: "Error show tasks"}); + } + }, + + async getTask(req, res){ + const taskId = req.params.taskId; + try { + const task = await taskModel.findById({_id: taskId}); + return res.status(200).json(task); + // return res.status(200).render("main"); + } catch (error) { + console.log(error); + return res.status(404).json({msg: "error show task"}); + } + }, + + async update(req, res){ + const taskId = req.params.taskId; + const { name, category, dateTimeInitial, dateTimeFinal, finished } = req.body; + + try { + const task = await taskModel.updateOne({ + name: name || undefined, + category: category || undefined, + dateTimeInitial: dateTimeInitial || undefined, + dateTimeFinal: dateTimeFinal || undefined, + finished: finished || undefined + }).where({_id: taskId}); + return res.status(200).json(task); + // return res.status(200).render("main"); + } catch (error) { + console.log(error); + return res.status(404).json({msg: "Update error"}); + } + + }, + + async destroy(req, res){ + const taskId = req.params.taskId; + + try { + const task = await taskModel.deleteOne({_id: taskId}); + return res.status(200).json(task); + // return res.status(200).render("main"); + } catch (error) { + console.log(error); + return res.status(404).json({msg: "Delete error"}); + } + }, + + async finishTask(req, res){ + const taskId = req.params.taskId; + const {finished} = req.body; + + try { + const task = await taskModel.updateOne({finished: !finished}).where({_id: taskId}); + return res.status(200).json(task); + // return res.status(200).render("main"); + } catch (error) { + console.log(error); + return res.status(404).json({msg: "error when finishing task"}); + } } } \ No newline at end of file diff --git a/src/db/connection.js b/src/db/connection.js new file mode 100644 index 0000000..7bac8e1 --- /dev/null +++ b/src/db/connection.js @@ -0,0 +1,7 @@ +const mongoose = require('mongoose'); + +async function connetiodb(){ + await mongoose.connect('mongodb+srv://gabriel:gbr81828182@cluster0.spv2phu.mongodb.net/test'); +} + +module.exports = connetiodb; \ No newline at end of file diff --git a/src/models/.gitkeep b/src/models/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/models/task.js b/src/models/task.js new file mode 100644 index 0000000..01ea9e9 --- /dev/null +++ b/src/models/task.js @@ -0,0 +1,17 @@ +const mongoose = require('mongoose'); + +const Schema = mongoose.Schema; +const ObjectId = Schema.ObjectId; + +const taskSchema = new Schema({ + id: ObjectId, + name: String, + category: String, + dateTimeInitial: String, + dateTimeFinal: String, + finished: {type: Boolean, default: false} +}); + +const taskModel = mongoose.model('tasks', taskSchema); + +module.exports = taskModel; \ No newline at end of file diff --git a/src/router.js b/src/router.js index 127f78e..7e3db5d 100644 --- a/src/router.js +++ b/src/router.js @@ -2,6 +2,11 @@ const router = require("express").Router(); const taskController = require('./controllers/taskController'); -router.get('/', taskController.createTask); +router.post('/createtask', taskController.createTask); +router.get('/alltask', taskController.index); +router.get('/gettask/:taskId', taskController.getTask); +router.post('/updatetask/:taskId', taskController.update); +router.get('/deletetask/:taskId', taskController.destroy); +router.post('/finishtask/:taskId', taskController.finishTask); module.exports = router; \ No newline at end of file diff --git a/src/server.js b/src/server.js index 5a8a596..948089a 100644 --- a/src/server.js +++ b/src/server.js @@ -1,8 +1,10 @@ const express = require("express"); const routes = require('./router'); const path = require('path'); +const connetiodb = require('./db/connection'); const app = express(); +connetiodb(); app.use(express.json()); app.use(express.urlencoded({extended: false})); diff --git a/views/home/home.ejs b/views/home/home.ejs index e472f48..798badf 100644 --- a/views/home/home.ejs +++ b/views/home/home.ejs @@ -1,62 +1,104 @@