Skip to content

Commit 9d4746a

Browse files
committed
Timer and auth-gaurd works
1 parent 6b9a845 commit 9d4746a

11 files changed

Lines changed: 65 additions & 33 deletions

File tree

codecamp-front/src/app/components/navbar/navbar.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, trigger, transition, animate, style,state } from '@angular/core';
1+
import { Component, OnInit, trigger, transition, animate, style, state } from '@angular/core';
22
import { AuthService } from '../../services/auth.service';
33
import { Router } from '@angular/router';
44
import { ContestService } from '../../services/contest.service';
@@ -21,7 +21,7 @@ import { ContestService } from '../../services/contest.service';
2121
])
2222
]
2323
})
24-
export class NavbarComponent implements OnInit{
24+
export class NavbarComponent implements OnInit {
2525

2626
user: any;
2727
users;
@@ -36,9 +36,9 @@ export class NavbarComponent implements OnInit{
3636
});*/
3737
this.users = authService.getProfile().subscribe(profile => {
3838
this.user = profile.msg.username;
39-
//console.log(this.user);
39+
// console.log(this.user);
4040
});
41-
//console.log(this.user);
41+
// console.log(this.user);
4242
}
4343

4444
ngOnInit() {
@@ -52,8 +52,8 @@ export class NavbarComponent implements OnInit{
5252
undefined() {
5353

5454
}
55-
onToggle(){
56-
this.toggle = this.toggle? false:true;
55+
onToggle() {
56+
this.toggle = this.toggle ? false : true;
5757
this.contestService.ontoggle(this.toggle);
5858
}
5959

codecamp-front/src/app/components/problems/problems.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</div>
3939
<a
4040
class="nav-link problem"
41-
*ngFor="let i of problems"
41+
*ngFor="let i of (conditionToShowProblem ? problems : [])"
4242
(click)="onSelectProblem(i.code)">
4343
<div class="row">
4444
<div class="col-md-6">
@@ -52,7 +52,7 @@
5252
</div>
5353
<div class="col-md-3">
5454
<div class="timer">
55-
<p>Time to start</p>
55+
<p>{{typeOfNow}}</p>
5656
<div id="timer">
5757
<!--<span>{{days}}</span>days
5858
<span>{{hours}}</span>hours

codecamp-front/src/app/components/problems/problems.component.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,22 @@ export class ProblemsComponent implements OnInit {
2121
contestname;
2222
time;
2323

24-
//Called after the constructor, initializing input properties, and the first call to ngOnChanges.
25-
//Add 'implements OnInit' to the class.
24+
// Called after the constructor, initializing input properties, and the first call to ngOnChanges.
25+
// Add 'implements OnInit' to the class.
2626
countDownDate;
2727
now;
2828
end;
2929
distance;
30-
days= 0;
30+
days = 0;
3131
hours;
3232
minutes;
3333
seconds;
3434
times;
3535
start;
3636
x;
37-
ticks= 0;
37+
ticks = 0;
38+
typeOfNow = 'Contest Will Start In';
39+
conditionToShowProblem = false;
3840
constructor(
3941
private contestService: ContestService,
4042
private router: Router,
@@ -51,26 +53,33 @@ export class ProblemsComponent implements OnInit {
5153
this.start = new Date(contest.msg[0].startTime);
5254
this.end = new Date(contest.msg[0].endTime);
5355
var timer;
54-
if (this.start > new Date())
55-
var compareDate = this.start;
56-
else
57-
var compareDate = this.end;
58-
//compareDate.setDate(this.end.getDate()); //just for this demo today + 7 days
5956

60-
//console.log(compareDate);
57+
if (this.start > new Date()) {
58+
var compareDate = this.start;
59+
} else if (this.start <= new Date() && this.end >= new Date()) {
60+
this.typeOfNow = 'Contest Will End In';
61+
var compareDate = this.end;
62+
this.conditionToShowProblem = true;
63+
} else {
64+
this.typeOfNow = 'Contest Ended';
65+
this.conditionToShowProblem = true;
66+
}
67+
// compareDate.setDate(this.end.getDate()); //just for this demo today + 7 days
68+
69+
// console.log(compareDate);
6170
/* timer = setInterval(function() {
6271
timeBetweenDates(compareDate);
6372
}, 1000);*/
64-
setInterval((()=>{
65-
var dateEntered = compareDate;
73+
setInterval((() => {
74+
var dateEntered = compareDate;
6675
var now = new Date();
6776
var difference = dateEntered.getTime() - now.getTime();
6877

6978
if (difference <= 0) {
7079

7180
// Timer done
7281
clearInterval(timer);
73-
82+
this.times = '';
7483
} else {
7584

7685
var second = Math.floor(difference / 1000);
@@ -81,7 +90,7 @@ export class ProblemsComponent implements OnInit {
8190
hour %= 24;
8291
minute %= 60;
8392
second %= 60;
84-
//console.log(day,hour,minute,second);
93+
// console.log(day,hour,minute,second);
8594
// this.days = day;
8695
// this.hours = hour;
8796
// this.minutes = minute;
@@ -93,18 +102,17 @@ export class ProblemsComponent implements OnInit {
93102
var temp = String(day) + ' days ' + String(hour) + ' hr ' +String(minute) + ' min ' +String(second) + ' sec';
94103
////this.contestService.time.next(temp);
95104
//this.contestService.time.subscribe(value => this.times = value);*/
96-
this.times = String(day) + ' days ' + String(hour) + ' hr ' +String(minute) + ' min ' +String(second) + ' sec';
105+
this.times = String(day) + ' days ' + String(hour) + ' hr ' + String(minute) + ' min ' + String(second) + ' sec';
97106

98107
}
99-
}),1000);
100-
108+
}), 1000);
101109

102110
});
103111
this.contestService.currentContest.subscribe(contest => this.contestname = contest);
104112

105113

106114
}
107-
tickerFunc(tick){
115+
tickerFunc(tick) {
108116
this.ticks = tick;
109117
}
110118
onAddProblem() {

codecamp-front/src/app/components/profile/profile.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class ProfileComponent implements OnInit {
2222
}
2323

2424
ngOnInit() {
25-
console.log(this.user);
25+
// console.log(this.user);
2626
}
2727
onSubmitSel() {
2828
this.router.navigate([this.user.username, 'edit-profile']);

codecamp-front/src/app/services/auth.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class AuthService {
5454
}
5555

5656
public checkisAdmin() {
57-
let user = JSON.parse(localStorage.getItem('user'));
57+
const user = JSON.parse(localStorage.getItem('user'));
5858
if (user === undefined || user === null) {
5959
return false;
6060
} else if (user.isAdmin === true) {
@@ -63,7 +63,7 @@ export class AuthService {
6363
}
6464

6565
public getUsername() {
66-
let user = JSON.parse(localStorage.getItem('user'));
66+
const user = JSON.parse(localStorage.getItem('user'));
6767
return user;
6868
}
6969

contest/models/contest/contest.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ var contestSchema = new mongoose.Schema({
2828
}]
2929
})
3030

31-
module.exports = mongoose.model('Contest',contestSchema)
31+
module.exports = {
32+
Contest:mongoose.model('Contest',contestSchema),
33+
mongoose:mongoose
34+
};

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"express-messages": "*",
3131
"express-session": "*",
3232
"express-validator": "*",
33+
"gridfs-stream": "^1.1.1",
3334
"helmet": "^3.9.0",
3435
"iconv": "^2.3.0",
3536
"jsonwebtoken": "^8.1.0",

server/routes/contest.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const express = require('express');
22
const fs = require('fs');
33
const path = require('path');
4+
const multer = require('multer');
5+
46
const _ = require('lodash');
5-
const Contest = require('./../../contest/models/contest/contest');
7+
const {Contest,mongoose} = require('./../../contest/models/contest/contest');
68
const Problem = require('./../../contest/models/problem/problem');
79
const problemRoute = require('./problems')
810

server/routes/problems.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const express = require('express');
2-
const _ = require('lodash')
2+
const _ = require('lodash');
33
//const db = require('./../utils/db/db');
44
const Problem = require('./../../contest/models/problem/problem');
55
const Contest = require('./../../contest/models/contest/contest')
@@ -35,7 +35,8 @@ router.patch('/:code/edit',(req,res)=>{
3535
const code = req.params.code;
3636
// console.log(username);
3737
var body = _.pick(req.body,['code','name','successfulSubmission','image','level','contest','description','input_format','output_format','constraints','input_example','output_example','explanation_example','date_added','timelimit','sourcelimit','author','testCaseInput','testCaseOutput']);
38-
Problem.findOneAndUpdate({'code':code},{$set: body}).then((problem)=>{
38+
Problem.findOneAndUpdate({'code':code},{$set: body})
39+
.then((problem)=>{
3940
res.json({
4041
'success':true,
4142
'msg':'Problem updated Successfully!'

0 commit comments

Comments
 (0)