fix all present bug and remove console.log

This commit is contained in:
jslightham
2020-04-15 09:54:30 -04:00
parent 93956f9ab5
commit 3a03688e6a
8 changed files with 209 additions and 82 deletions

View File

@@ -17,7 +17,7 @@ let Att = require('./attendee.model');
attendanceRoute.route('/attendees').post(function (req, res) {
let username = req.body.user;
console.log(username)
//console.log(username)
Att.find({user: username}, function (err, posts){
if(err) {
res.json(err);
@@ -29,7 +29,7 @@ let Att = require('./attendee.model');
attendanceRoute.route('/getById').post(function (req, res) {
let username = req.body.user;
console.log(username)
//console.log(username)
Att.find({user: username}, function (err, posts){
if(err) {
res.json(err);

View File

@@ -4,15 +4,15 @@ const loginRoute = express.Router();
let LInfo = require('./user.model');
loginRoute.route('/add').post(function (req, res) {
console.log(req.body);
//console.log(req.body);
var username = req.body.user;
LInfo.findOne({user: username},
function(err, user){
console.log(user);
//console.log(user);
if(user == null){
let post = new LInfo(req.body);
post.dates = [];
console.log(post);
//console.log(post);
post.save()
.then(() => {
res.status(200).send("Account added successfully");
@@ -23,7 +23,7 @@ loginRoute.route('/add').post(function (req, res) {
}
else {
res.json(user);
console.log("user");
//console.log("user");
}
});
});
@@ -33,18 +33,18 @@ loginRoute.route('/post').post(function (req, res) {
//console.log(res);
var username = req.body.user;
var password = req.body.pass;
console.log(username);
console.log(password);
//console.log(username);
//console.log(password);
LInfo.findOne({user: username, pass: password},
function(err, user){
console.log(user);
//console.log(user);
if(!user){
res.json(null);
console.log("err");
//console.log("err");
}
else {
res.json(user);
console.log("user");
//console.log("user");
}
});
});
@@ -65,7 +65,7 @@ loginRoute.route('/post').post(function (req, res) {
var username = req.body.user;
var dates = req.body.dates;
Att.findOne({user: username}, function(err, post) {
LInfo.findOne({user: username}, function(err, post) {
if (!post)
res.status(404).send("data is not found");
else {
@@ -80,4 +80,7 @@ loginRoute.route('/post').post(function (req, res) {
}
});
});
module.exports = loginRoute;

View File

@@ -224,24 +224,16 @@
this.$router.push({name: 'login'});
}else{
this.post.user = this.user;
//alert(this.post.user);
let uri = 'http://65.92.152.100:4000/attendance/attendees';
let uri = 'http://localhost:4000/attendance/attendees';
this.axios.post(uri, this.post).then(res => {
this.attendees = res.data;
//console.log(this.attendees);
for(var element of this.attendees){
//console.log(element);
if(element.presences.indexOf(this.$route.params.id) > -1){
this.presentNames.push(element._id);
//document.getElementById(element + ":pcheckbox").style.backgroundColor = "green";
}else{
this.absentNames.push(element._id);
//document.getElementById(element + ":acheckbox").style.backgroundColor = "red";
}
}
//console.log(this.presentNames);
});
}
},
@@ -258,10 +250,7 @@
presentNames: [],
checked: true,
post: {},
user: null,
dismissSecs: 10,
dismissCountDown: 0,
showDismissibleAlert: false
user: null
}
},
methods: {
@@ -273,86 +262,131 @@
//iterate through all present, then all absent, and get array of that id user, then check for the current day, if it contains delete, and append the date to the correct array
for(var element of this.presentNames){
var test = {number: element};
let uri = 'http://65.92.152.100:4000/attendance/getarr';
let uri = 'http://localhost:4000/attendance/getarr';
this.axios.post(uri, test).then(res => {
var arr = res.data.presences;
arr = arr.filter(e => e !== this.$route.params.id);
//console.log(arr);
var arr2 = res.data.absenses;
arr2 = arr2.filter(e => e !== this.$route.params.id);
//console.log(arr2);
arr.push(this.$route.params.id);
this.post.presences = arr;
this.post.absenses = arr2;
//console.log(res.data._id);
var test2 = {id: res.data._id, presences: arr, absenses: arr2};
//console.log(test2);
let url = 'http://65.92.152.100:4000/attendance/post';
let url = 'http://localhost:4000/attendance/post';
this.axios.post(url, test2).then(res => {
console.log(res);
console.log("Arr: " + res);
// start of user updating
/*
var ldata = {user: this.user};
let url2 = 'http://65.92.152.100:4000/login/getdates';
let url2 = 'http://localhost:4000/login/getdates';
this.axios.post(url2, ldata).then(res => {
console.log(res.data);
//console.log(res.data);
var arrd = res.data.dates;
arrd = arrd.filter(e => e !== this.$route.params.id, this.date);
var ddata = {dates: arrd, user: this.user};
arrd.push(ddata);
console.log(arrd);
//arrd = arrd.filter(e => e !== this.$route.params.id, this.date);
for(var i = 0; i<arrd.length; i++){
if(arrd[i].date == this.$route.params.id){
arrd[i] = null;
}
}
let url3 = 'http://65.92.152.100:4000/login/update';
this.axios.post(url3, ddata).then(res => {
arrd = arrd.filter(function (el) {
return el != null;
});
var ddata = {date: this.$route.params.id, numPresent: this.presentNames.length};
arrd.push(ddata);
//console.log(arrd);
var userPostData = {dates: arrd, user: this.user}
let url3 = 'http://localhost:4000/login/update';
this.axios.post(url3, userPostData).then(res => {
//console.log("URL 3");
console.log(res);
this.$router.push({name: 'calendar'});
})
})
*/
})
})
}
//alert("hello");
for(var element1 of this.absentNames){
if(this.absentNames.length != 0){
//alert("absences")
for(var element1 of this.absentNames){
var test1 = {number: element1};
let uri1 = 'http://65.92.152.100:4000/attendance/getarr';
let uri1 = 'http://localhost:4000/attendance/getarr';
this.axios.post(uri1, test1).then(res => {
var arrr = res.data.absenses;
arrr = arrr.filter(e => e !== this.$route.params.id);
//console.log(arrr);
var arrr2 = res.data.presences;
arrr2 = arrr2.filter(e => e !== this.$route.params.id);
arrr.push(this.$route.params.id);
this.post.absenses = arrr;
//console.log(res.data._id);
var testt2 = {id: res.data._id, presences: arrr2, absenses: arrr};
//console.log(test2);
let url1 = 'http://65.92.152.100:4000/attendance/post';
let url1 = 'http://localhost:4000/attendance/post';
this.axios.post(url1, testt2).then(res => {
console.log(res);
this.$router.push({name: 'calendar'});
console.log("Arr2: " + res);
})
})
}
// start of user updating
var ldata = {user: this.user};
let url2 = 'http://localhost:4000/login/getdates';
this.axios.post(url2, ldata).then(res => {
//console.log(res.data);
var arrd = res.data.dates;
//arrd = arrd.filter(e => e !== this.$route.params.id, this.date);
for(var i = 0; i<arrd.length; i++){
if(arrd[i].date == this.$route.params.id){
arrd[i] = null;
}
}
arrd = arrd.filter(function (el) {
return el != null;
});
var ddata = {date: this.$route.params.id, numPresent: this.presentNames.length};
arrd.push(ddata);
console.log(arrd);
var userPostData = {dates: arrd, user: this.user}
let url3 = 'http://localhost:4000/login/update';
this.axios.post(url3, userPostData).then(res => {
console.log("URL 3");
console.log(res);
this.$router.push({name: 'calendar'});
})
})
}
},
test(input, type){
var letter;
if(type == "a"){
//alert(input);
//console.log(this.presentNames);
this.presentNames = this.presentNames.filter(e => e !== input);
//console.log(this.presentNames);
letter = "p";
document.getElementById(input + ":acheckbox").style.backgroundColor = "red";
document.getElementById(input + ":pcheckbox").style.backgroundColor = "#6CD182";

View File

@@ -123,7 +123,7 @@ export default {
this.checkAccount();
this.post.user = this.user;
//alert(this.post.user);
let uri = 'http://65.92.152.100:4000/attendance/attendees';
let uri = 'http://localhost:4000/attendance/attendees';
this.axios.post(uri, this.post).then(res => {
this.attendees = res.data;
console.log(this.attendees);
@@ -152,7 +152,7 @@ export default {
del(id){
this.post.id = id;
//alert(id);
let uri = 'http://65.92.152.100:4000/attendance/delete';
let uri = 'http://localhost:4000/attendance/delete';
this.axios.post(uri, this.post).then(() => {
location.reload();
});
@@ -161,7 +161,7 @@ export default {
//alert(this.attendee.name);
this.attendee.user = this.user;
let uri = 'http://65.92.152.100:4000/attendance/add';
let uri = 'http://localhost:4000/attendance/add';
this.axios.post(uri, this.attendee).then(() => {
location.reload();
});

View File

@@ -34,12 +34,27 @@
</b-collapse>
</b-navbar>
</div>
<center>
<div class="container">
<div id="" style="width: 35%; float:left; margin:10px;" class="box">
<h3>Attendance Calendar for {{user}}</h3>
<ul style="text-align: left;">
<li><b>-</b> Get started by creating some club members on the <a href="/attendees">"Manage Club Members"</a> page. </li>
<br>
<li><b>-</b> Use the calendar below to select a date to take attendance.</li>
<br>
<li><b>-</b> A day with attendance taken will be highlighted in blue. </li>
</ul>
<h1>Attendance Calendar for {{user}}:</h1>
</div>
<div id="" style="width: 60%; float:left; margin:10px;" class="box">
<form @submit.prevent="att">
<br><br><br>
<div id="cal">
<b-calendar v-model="value" locale="en-US" class="cal" selected-variant="primary" width="35vw" hide-header>
<div v-if="!dates"><center>Calendar loading please wait...</center></div>
<div v-else>
<b-calendar v-model="value" locale="en-US" class="cal" selected-variant="primary" width="30vw" :date-info-fn="dateClass">
<div class="d-flex" dir="ltr">
<b-button
size="sm"
@@ -59,13 +74,30 @@
</b-button>
</div>
</b-calendar>
</div>
</div>
</div>
<p id="incorrect">Please select a date in the calendar </p>
<br>
<div id="buttone">
<button class="btn btn-primary">Take/View Attendance</button>
</div>
</form>
</div>
<br>
<br>
</div>
<div id="calcontainer" style="border: 0.25px solid grey;">
<h3>Club Attendance</h3>
<div v-if="chartData.length == 1"><center>You haven't taken any attendance yet! Take some to view club performance.</center></div>
<div v-else>
<GChart type="LineChart" :data="chartData" :options="chartOptions" id="graph" style=""/>
</div>
</div>
</center>
</div>
</template>
@@ -90,7 +122,8 @@
}
#whole-page{
height: 100vh;
height: 100%;
text-align: center;
}
#incorrect {
@@ -98,14 +131,43 @@
display: none;
}
#calcontainer{
background-color: white;
width: 75%;
text-align: center;
padding: 20px;
border-radius: 10px;
display: inline-block;
}
.box{
border: 0.25px solid grey;
}
</style>
<script>
export default {
mounted() {
created() {
this.checkAccount()
var ldata = {user: this.user};
let url2 = 'http://localhost:4000/login/getdates';
this.axios.post(url2, ldata).then(res => {
var datearr = res.data.dates;
console.log(res.data.dates)
this.dates = [];
for(var i =0; i<datearr.length; i++){
this.dates[i] = datearr[i].date;
this.chartData[i+1] = [this.dates[i], datearr[i].numPresent];
}
})
},
updated(){
var body = document.body, html = document.documentElement;
var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
document.getElementById("whole-page").style.height = height + "px";
},
data() {
return {
@@ -115,7 +177,18 @@
attendee: {},
modal: null,
btn: null,
span: null
span: null,
dates: null,
chartData: [
["Dates", "Attendances"]
],
chartOptions: {
chart: {
title: "Club Performance",
width: 100,
height: 400
}
}
}
},
methods: {
@@ -142,6 +215,23 @@
},
clearDate() {
this.value = ''
},
dateClass(ymd, date) {
var year = 1900 + date.getYear();
var month = date.getMonth() + 1 + "";
if(month.length == 1){
month = "0" + month;
}
var day = date.getDate() + "";
if(day.length == 1){
day = "0" + day;
}
var str = year + "-" + month + "-" + day
return this.dates.includes(str) ? 'table-info' : ''
}
}
}

View File

@@ -40,7 +40,7 @@
<div v-if="chartData.length == 1"><center>You have no members yet! Add some to get insights. <br>Chart Loading, please wait...</center></div>
<div v-else>
<center>
<GChart type="ColumnChart" :data="chartData" :options="chartOptions" id="graph" /></center></div>
<GChart style="max-width: 70%;" type="ColumnChart" :data="chartData" :options="chartOptions" id="graph" /></center></div>
<br>
<center>
<table id="presences">
@@ -146,8 +146,7 @@ export default {
],
chartOptions: {
chart: {
title: "Company Performance",
subtitle: "Sales, Expenses, and Profit: 2014-2017",
title: "Club Performance",
width: 100,
height: 400
}
@@ -157,7 +156,7 @@ export default {
methods: {
getAttById(){
var data = {user: this.user};
let uri = 'http://65.92.152.100:4000/attendance/getById';
let uri = 'http://localhost:4000/attendance/getById';
this.axios.post(uri, data).then(res => {
console.log(res);
this.attendees = res.data;
@@ -165,11 +164,12 @@ export default {
for(var i = 0; i < this.attendees.length; i++){
this.chartData[i+1] = [this.attendees[i].name, parseInt(this.attendees[i].presences.length, 10)]
}
console.log(this.chartData);
});
},
getAttByPresences(){
var data = {user: this.user};
let uri = 'http://65.92.152.100:4000/attendance/getById';
let uri = 'http://localhost:4000/attendance/getById';
this.axios.post(uri, data).then(res => {
console.log(res);
this.attendees = res.data;
@@ -183,7 +183,7 @@ export default {
},
getAttByAbsenses(){
var data = {user: this.user};
let uri = 'http://65.92.152.100:4000/attendance/getById';
let uri = 'http://localhost:4000/attendance/getById';
this.axios.post(uri, data).then(res => {
console.log(res);
this.attendees = res.data;

View File

@@ -155,7 +155,7 @@ input:focus {
},
methods: {
add(){
let uri = 'http://65.92.152.100:4000/login/post';
let uri = 'http://localhost:4000/login/post';
this.axios.post(uri, this.post).then(res => {
if(!res.data){
document.getElementById("incorrect").style.display = "block";

View File

@@ -164,12 +164,12 @@ input:focus {
methods: {
add(){
if(this.post.user != "" || this.post.email != "" || this.post.pass != ""){
let uri = 'http://65.92.152.100:4000/login/add';
let uri = 'http://localhost:4000/login/add';
this.axios.post(uri, this.post).then(res => {
console.log(res);
if(!res.data.user){
alert("Success! Account Created!");
this.$router.push({name: '/'});
this.$router.push({name: 'login'});
}else{
alert("Error username already in use!")
}