Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shakti1590 committed Apr 20, 2023
0 parents commit ba0d5b5
Show file tree
Hide file tree
Showing 22 changed files with 5,435 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node index.js
59 changes: 59 additions & 0 deletions assets/js/filterIssues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// get the form
let filterIssueForm = document.getElementById('filter-issue-form');
// get the details of the issues of the project in json
let issuesJson = document.getElementById('issue-data').getAttribute('data');
// parse the data
let issues = JSON.parse(issuesJson);
// get element where filtered issues will be shown
let issueList = document.getElementById('issues-list');

filterIssueForm.addEventListener('submit', function (e) {
e.preventDefault();

//create empty array where result will be stored
let filteredIssues = [];

//get all the form data
let labelsList = filterIssueForm.querySelectorAll('input[type=checkbox]');
let labelsElements = [...labelsList].filter((Element) => Element.checked);

let authorVal = filterIssueForm.querySelector(
'input[type=radio][name=author]:checked'
).value;

let [...labelsArr] = labelsElements.map((Element) => Element.value);

//add issue to filtered issues array
issues.map((el) => {
if (el.author == authorVal) {
if (!filteredIssues.includes(el)) {
filteredIssues.push(el);
}
}
labelsArr.map((label) => {
if (el.labels.includes(label)) {
if (!filteredIssues.includes(el)) {
filteredIssues.push(el);
}
}
});
});
//create a div and add details of the filtered issues
issueList.innerHTML = '';
for (let issue of filteredIssues) {
let Div = document.createElement('div');
Div.style = 'none';
Div.innerHTML = `
<div class="card w-100" >
<div class="card-body" >
<h4 class="card-title">Title : ${issue.title} </h4>
<h5 class="card-title">Author : ${issue.author}</h5>
<h6 class="card-subtitle mb-2 text-muted">
Description : ${issue.description}
</h6>
</div>
</div>
`;
issueList.appendChild(Div);
}
});
48 changes: 48 additions & 0 deletions assets/js/searchIssues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//get the form
let searchIssueForm = document.getElementById('search-issue-form');
// get the details of the issues of the project in json
let searchJson = document.getElementById('issue-data').getAttribute('data');
// parse the data
let searchIssues = JSON.parse(searchJson);
// get element where searched t will be shown
let searchList = document.getElementById('issues-list');

searchIssueForm.addEventListener('submit', function (e) {
e.preventDefault();

//create empty array where result will be stored
let searchedIssues = [];

//get all the form data

let titleValue = searchIssueForm.querySelector('input[name="tie"]').value;
let descriptionValue =
searchIssueForm.querySelector('input[name="des"]').value;

//add issue to searched issues array
searchIssues.map((el) => {
if (el.title == titleValue || el.description == descriptionValue) {
if (!searchedIssues.includes(el)) {
searchedIssues.push(el);
}
}
});
//create a div and add details of the searched issues
searchList.innerHTML = '';
for (let issue of searchedIssues) {
let Div = document.createElement('div');
Div.style = 'none';
Div.innerHTML = `
<div class="card w-100" >
<div class="card-body" >
<h4 class="card-title">Title : ${issue.title} </h4>
<h5 class="card-title">Author : ${issue.author}</h5>
<h6 class="card-subtitle mb-2 text-muted">
Description : ${issue.description}
</h6>
</div>
</div>
`;
searchList.appendChild(Div);
}
});
15 changes: 15 additions & 0 deletions config/mongoose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const mongoose = require('mongoose');
const url = 'mongodb+srv://shaktibtcs38:[email protected]/?retryWrites=true&w=majority';
// mongoose.connect('url')
mongoose.connect(url);
const db=mongoose.connection;

//If any Error then Getting this Line
db.on('error',console.error.bind(console,"Error connecting to MongoDB"));


db.once('open',()=>{
console.log("Connected to Database :: MongoDB ")
});

module.exports=db; //Exports db
13 changes: 13 additions & 0 deletions controllers/home_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Project = require('../models/project');
module.exports.home = async function (req, res) {
try {
let projects = await Project.find({}).sort('-createdAt');
return res.render('home', {
title: 'Issue Tracker | Home',
projects,
});
} catch {
console.log('Error', err);
return;
}
};
73 changes: 73 additions & 0 deletions controllers/project_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const Project = require('../models/project');
const Issue = require('../models/issue');
const { findById } = require('../models/project');

// create a project for the user
module.exports.create = async function (req, res) {
try {
Project.create({
name: req.body.name,
description: req.body.description,
author: req.body.author,
});
return res.redirect('back');
} catch (err) {
console.log(err);
return res.redirect('back');
}
};

// find project and display it in the project page
module.exports.project = async function (req, res) {
try {
let project = await Project.findById(req.params.id).populate({
path: 'issues',
});
if (project) {
return res.render('project_page', {
title: 'Project Page',
project,
});
}
return res.redirect('back');
} catch (err) {
console.log(err);
return res.redirect('back');
}
};

// create issue
module.exports.createIssue = async function (req, res) {
try {
let project = await Project.findById(req.params.id);
if (project) {
let issue = await Issue.create({
title: req.body.title,
description: req.body.description,
labels: req.body.labels,
author: req.body.author,
});
project.issues.push(issue);

if (!(typeof req.body.labels === 'string')) {
for (let label of req.body.labels) {
let isPresent = project.labels.find((obj) => obj == label);
if (!isPresent) {
project.labels.push(label);
}
}
} else {
let isPresent = project.labels.find((obj) => obj == req.body.labels);
if (!isPresent) {
project.labels.push(req.body.labels);
}
}
await project.save();
return res.redirect(`back`);
} else {
return res.redirect('back');
}
} catch (err) {
return res.redirect('back');
}
};
29 changes: 29 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require('dotenv').config(); //Load Env
const express = require('express');

const db = require('./config/mongoose');
const port = process.env.PORT || 8000;
const app = express();
const path = require('path');
const expressLayouts = require('express-ejs-layouts');

app.use(express.urlencoded());
app.use(express.static('assets'));
app.use(expressLayouts);

// extract style and scripts from sub pages into the layout
app.set('layout extractStyles', true);
app.set('layout extractScripts', true);

// set up the view engine
app.set('view engine', 'ejs');
app.set('views', './views');

// use express router
app.use('/', require('./routes'));
app.listen(port, function (err) {
if (err) {
console.log(`Error in running the server: ${err}`);
}
console.log(`Server is running on port: ${port}`);
});
35 changes: 35 additions & 0 deletions models/issue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const mongoose = require('mongoose');

const issueSchema = new mongoose.Schema(
{
title: {
type: String,
trim: true,
required: true,
},
description: {
type: String,
trim: true,
required: true,
},
author: {
type: String,
trim: true,
required: true,
},
labels: [
{
type: String,
trim: true,
required: true,
},
],
},
{
timestamps: true,
}
);

const Issue = mongoose.model('Issue', issueSchema);

module.exports = Issue;
37 changes: 37 additions & 0 deletions models/project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const mongoose = require('mongoose');

const projectSchema = new mongoose.Schema(
{
name: {
type: String,
trim: true,
required: true,
},
description: {
type: String,
required: true,
},
author: {
type: String,
required: true,
},
issues: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'Issue',
},
],
labels: [
{
type: String,
},
],
},
{
timestamps: true,
}
);

const Project = mongoose.model('Project', projectSchema);

module.exports = Project;
Loading

0 comments on commit ba0d5b5

Please sign in to comment.