Skip to content

Commit 8531975

Browse files
committed
Problem page in progress
1 parent 6feda30 commit 8531975

25 files changed

Lines changed: 484 additions & 60 deletions

codecamp-front/src/app/app-routing.module.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { IdeComponent } from './components/ide/ide.component';
1616
import { ProblemsComponent } from './components/problems/problems.component';
1717
import { AddContestComponent } from './components/add-contest/add-contest.component';
1818
import { EditContestComponent } from './components/edit-contest/edit-contest.component';
19+
import { ProblemComponent } from './components/problem/problem.component';
20+
import { AddProblemComponent } from './components/add-problem/add-problem.component';
1921

2022

2123

@@ -24,14 +26,16 @@ const appRoutes: Routes = [
2426
{path: 'about', component: AboutComponent},
2527
{path: 'register' , component: RegisterComponent},
2628
{path: 'login' , component: LoginComponent},
27-
{path: 'problems' , component: PracticeComponent},
29+
{path: 'practice' , component: PracticeComponent},
2830
{path: 'contest' , component: ContestComponent},
2931
{path: 'discuss' , component: DiscussComponent},
3032
{path: 'profile' , component: ProfileComponent},
3133
{path: 'ide', component: IdeComponent},
32-
{path: 'problems/:problem', component: ProblemsComponent},
3334
{path: 'contest/add-contest', component: AddContestComponent},
34-
{path: 'contest/edit-contest', component: EditContestComponent}
35+
{path: 'contest/:contest', component: ProblemsComponent},
36+
{path: 'contest/:contest/addproblem', component: AddProblemComponent},
37+
{path: 'contest/:contest/:problem', component: ProblemComponent},
38+
{path: 'contest/edit/:edit-contest', component: EditContestComponent},
3539
];
3640

3741
@NgModule({

codecamp-front/src/app/app.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import { EditContestComponent } from './components/edit-contest/edit-contest.com
2727
import { SubmissionComponent } from './components/submission/submission.component';
2828
import { RanklistComponent } from './components/ranklist/ranklist.component';
2929
import { SolutionComponent } from './components/solution/solution.component';
30+
import { ProblemComponent } from './components/problem/problem.component';
31+
import { AddProblemComponent } from './components/add-problem/add-problem.component';
3032

3133

3234
@NgModule({
@@ -47,7 +49,9 @@ import { SolutionComponent } from './components/solution/solution.component';
4749
EditContestComponent,
4850
SubmissionComponent,
4951
RanklistComponent,
50-
SolutionComponent
52+
SolutionComponent,
53+
ProblemComponent,
54+
AddProblemComponent
5155
],
5256
imports: [
5357
BrowserModule,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.file-input, .file-output{
2+
padding: 10px;
3+
background: red;
4+
display: table;
5+
color: #fff;
6+
}
7+
8+
.file-output{
9+
background: green;
10+
}
11+
12+
input[type="file"] {
13+
display: none;
14+
}
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<div class="container">
2+
<div class="row">
3+
<div class="col-md-12">
4+
<div class="display-4">Add Problem</div>
5+
<form [formGroup]="form" (submit)="onAddProblemSubmit()">
6+
<div class="form-group">
7+
<label for="name">Problem Name</label>
8+
<input type="text"
9+
name="name"
10+
formControlName="name"
11+
class="form-control"
12+
placeholder="Enter Name"
13+
autocomplete="off"
14+
[ngClass]="{'is-invalid': (form.controls.name.errors && form.controls.name.dirty) , 'is-valid': !form.controls.name.errors}">
15+
</div>
16+
17+
<div class="form-group">
18+
<label for="id">Problem Code</label>
19+
<input type="text"
20+
name="code"
21+
formControlName="code"
22+
class="form-control"
23+
placeholder="Enter contest ID"
24+
autocomplete="off"
25+
[ngClass]="{'is-invalid': (form.controls.code.errors && form.controls.code.dirty) , 'is-valid': !form.controls.code.errors}">
26+
</div>
27+
<div class="row">
28+
<div class="col-md-6">
29+
<div class="form-group">
30+
<label for="level">Problem Level</label>
31+
<input type="text"
32+
name="level"
33+
formControlName="level"
34+
class="form-control"
35+
placeholder="Problem Level"
36+
autocomplete="off"
37+
[ngClass]="{'is-invalid': (form.controls.level.errors && form.controls.level.dirty) , 'is-valid': !form.controls.level.errors}">
38+
</div>
39+
</div>
40+
<div class="col-md-6">
41+
<div class="form-group">
42+
<label for="Author">Author</label>
43+
<input type="text"
44+
name="author"
45+
formControlName="author"
46+
class="form-control"
47+
placeholder="Author Name"
48+
autocomplete="off"
49+
[ngClass]="{'is-invalid': (form.controls.author.errors && form.controls.author.dirty) , 'is-valid': !form.controls.author.errors}">
50+
</div>
51+
</div>
52+
</div>
53+
<div class="row">
54+
<div class="col-md-6">
55+
<div class="form-group">
56+
<label for="Input Format">Input Format</label>
57+
<textarea
58+
name="input_format"
59+
formControlName="input_format"
60+
class="form-control"
61+
placeholder="Input Format"
62+
autocomplete="off"
63+
[ngClass]="{'is-invalid': (form.controls.input_format.errors && form.controls.input_format.dirty) , 'is-valid': !form.controls.input_format.errors}">
64+
</textarea>
65+
</div>
66+
</div>
67+
<div class="col-md-6">
68+
<div class="form-group">
69+
<label for="output_format">Output format</label>
70+
<textarea
71+
name="output_format"
72+
formControlName="output_format"
73+
class="form-control"
74+
placeholder="output_format"
75+
autocomplete="off"
76+
[ngClass]="{'is-invalid': (form.controls.output_format.errors && form.controls.output_format.dirty) , 'is-valid': !form.controls.output_format.errors}">
77+
</textarea>
78+
</div>
79+
</div>
80+
</div>
81+
<div class="form-group">
82+
<label for="Description">Description</label>
83+
<textarea
84+
name="description"
85+
formControlName="description"
86+
class="form-control" placeholder="Enter Description" autocomplete="off" rows="10">
87+
</textarea>
88+
</div>
89+
<div class="row">
90+
<div class="col-md-6">
91+
<div class="form-group">
92+
<label for="timelimit">Time Limit</label>
93+
<input type="text"
94+
name="timelimit"
95+
formControlName="timelimit"
96+
class="form-control"
97+
placeholder="Enter Time Limit"
98+
autocomplete="off"
99+
[ngClass]="{'is-invalid': (form.controls.timelimit.errors && form.controls.timelimit.dirty) , 'is-valid': !form.controls.timelimit.errors}">
100+
</div>
101+
</div>
102+
<div class="col-md-6">
103+
<div class="form-group">
104+
<label for="sourcelimit">Source Limit</label>
105+
<input type="text"
106+
name="sourcelimit"
107+
formControlName="sourcelimit"
108+
class="form-control"
109+
placeholder="Enter Source Limit"
110+
autocomplete="off"
111+
[ngClass]="{'is-invalid': (form.controls.sourcelimit.errors && form.controls.sourcelimit.dirty) , 'is-valid': !form.controls.sourcelimit.errors}">
112+
</div>
113+
</div>
114+
</div>
115+
<div class="row">
116+
<div class="col-md-6">
117+
<div class="form-group">
118+
<label for="Input TestCase">Input Testcase</label>
119+
<textarea
120+
name="input_example"
121+
formControlName="input_example"
122+
class="form-control"
123+
placeholder="Input TestCase"
124+
autocomplete="off"
125+
[ngClass]="{'is-invalid': (form.controls.input_example.errors && form.controls.input_example.dirty) , 'is-valid': !form.controls.input_example.errors}">
126+
</textarea>
127+
</div>
128+
</div>
129+
<div class="col-md-6">
130+
<div class="form-group">
131+
<label for="output_example">Output Testcase</label>
132+
<textarea
133+
name="output_example"
134+
formControlName="output_example"
135+
class="form-control"
136+
placeholder="Output Test case"
137+
autocomplete="off"
138+
[ngClass]="{'is-invalid': (form.controls.output_example.errors && form.controls.output_example.dirty) , 'is-valid': !form.controls.output_example.errors}">
139+
</textarea>
140+
</div>
141+
</div>
142+
</div>
143+
<div class="row">
144+
<div class="col-md-6">
145+
<div class="form-group">
146+
<label class="file-input">Input File
147+
<input type="file" class="form-control-file">
148+
</label>
149+
</div>
150+
</div>
151+
<div class="col-md-6">
152+
<div class="form-group">
153+
<label class="file-output">Output File
154+
<input type="file" class="form-control-file">
155+
</label>
156+
</div>
157+
158+
</div>
159+
</div>
160+
<div class="form-group">
161+
<label for="Explanation Example">Explanation Example</label>
162+
<textarea
163+
name="explanation_example"
164+
formControlName="explanation_example"
165+
class="form-control" placeholder="Explanation Example" autocomplete="off" rows="10">
166+
</textarea>
167+
</div>
168+
169+
<input
170+
[disabled]="!form.valid"
171+
type="submit" class="btn btn-primary" value="Add Problem">
172+
</form>
173+
</div>
174+
</div>
175+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { AddProblemComponent } from './add-problem.component';
4+
5+
describe('AddProblemComponent', () => {
6+
let component: AddProblemComponent;
7+
let fixture: ComponentFixture<AddProblemComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ AddProblemComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(AddProblemComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
3+
import { ContestService } from '../../services/contest.service';
4+
import { Router, ActivatedRoute } from '@angular/router';
5+
@Component({
6+
selector: 'app-add-problem',
7+
templateUrl: './add-problem.component.html',
8+
styleUrls: ['./add-problem.component.css']
9+
})
10+
export class AddProblemComponent implements OnInit {
11+
form: FormGroup;
12+
contest;
13+
constructor(
14+
private contestService: ContestService,
15+
private router: Router,
16+
private formBuilder: FormBuilder,
17+
private route: ActivatedRoute
18+
) { }
19+
20+
ngOnInit() {
21+
this.createForm();
22+
this.contest = this.route.snapshot.params['contest'];
23+
}
24+
25+
createForm() {
26+
this.form = this.formBuilder.group({
27+
code: ['', Validators.required],
28+
name: ['', Validators.required],
29+
level: [''],
30+
description: [''],
31+
input_format: [''],
32+
output_format: [''],
33+
constraints: [''],
34+
input_example: [''],
35+
output_example: [''],
36+
explanation_example: [''],
37+
timelimit: [''],
38+
sourcelimit: [''],
39+
author: [''],
40+
Input: [''],
41+
Output: ['']
42+
});
43+
}
44+
45+
onAddProblemSubmit() {
46+
const problem = {
47+
code: this.form.get('code').value,
48+
name: this.form.get('name').value,
49+
level: this.form.get('level').value,
50+
description: this.form.get('description').value,
51+
input_format: this.form.get('input_format').value,
52+
output_format: this.form.get('output_format').value,
53+
constraints: this.form.get('constraints').value,
54+
input_example: this.form.get('input_example').value,
55+
output_example: this.form.get('output_example').value,
56+
explanation_example: this.form.get('explanation_example').value,
57+
timelimit: this.form.get('timelimit').value,
58+
sourcelimit: this.form.get('sourcelimit').value,
59+
author: this.form.get('author').value,
60+
Input: this.form.get('Input').value,
61+
Output: this.form.get('Output').value,
62+
};
63+
64+
this.contestService.addProblem(problem, this.contest).subscribe(data => {
65+
if (!data.success) {
66+
console.log(data.msg);
67+
} else {
68+
this.router.navigate(['/contest', this.contest]);
69+
}
70+
});
71+
}
72+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.contest{
2+
background: white;
3+
border-bottom: 1px solid rgba(39,39,39,.1);
4+
padding: 1% 1%;
5+
box-shadow: 0 1px 15px 1px rgba(39,39,39,.1);
6+
cursor: pointer;
7+
}

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,34 @@
22
<div class="row">
33
<div class="col-md-12">
44
<button class="btn btn-warning" (click)="onAddContest()">Add Contest</button>
5-
<button class="btn btn-info" (click)="onEditContest()">Edit Contest</button>
65
</div>
76
</div>
87
</div>
8+
9+
<br>
10+
11+
<div class="container">
12+
<div class="col-md-12">
13+
<div class="row">
14+
<div class="col-md-8">
15+
Contest
16+
</div>
17+
<div class="col-md-4">
18+
Contest Code
19+
</div>
20+
</div>
21+
<a
22+
class="nav-link contest"
23+
*ngFor="let i of contest"
24+
(click)="onSelectContest(i.id)">
25+
<div class="row">
26+
<div class="col-md-8">
27+
{{i.name}}
28+
</div>
29+
<div class="col-md-4">
30+
{{i.id}}
31+
</div>
32+
</div>
33+
</a>
34+
</div>
35+
</div>

0 commit comments

Comments
 (0)