Commit 6fea0680 authored by Ayush's avatar Ayush

Merge conflicts

parents 726f1423 6227a756
<?php
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header("Content-Type: application/json; charset=UTF-8");
include_once("database.php");
if($_SERVER['REQUEST_METHOD'] === 'GET')){
if($_SERVER['REQUEST_METHOD'] === 'GET'){
$sql1 = "SELECT Now()";
$currtime = $mysqli->query($sql1);
$sql2 = "SELECT * FROM questions WHERE stime <= $currtime and etime >= $currtime";
......
<?php
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header("Content-Type: application/json; charset=UTF-8");
include_once("database.php");
$postData = file_get_contents("php://input");
if(isset($postData) && !empty($postData)){
$request = json_decode($postData);
$title = trim($request->title);
$username = trim($request->username); //string
$statement = trim($request->statement); //string
......@@ -15,14 +22,14 @@ if(isset($postData) && !empty($postData)){
$stime = trim($request->start_time); //string
$etime = trim($request->end_time)
$sql = "INSERT INTO questions($title,$username,$statement,$tc1,$out1,$tc2,$out2,$stime,$etime)";
$sql = "INSERT INTO questions(title,username,statement,tc1,out1,tc2,out2,stime,etime) VALUES ('$title','$username','$statement','$tc1','$out1','$tc2','$out2','$stime','$etime')";
if($result = $mysqli->query($sql)){
$msg = "question uploaded";
echo json_encode($msg);
}
else{
$msg = "title already exists";
$msg = "question already exists";
echo json_encode($msg);
}
......
......@@ -2,6 +2,7 @@ import {Injectable} from '@angular/core';
import {File} from './file';
import {Observable, of} from 'rxjs';
import {HttpClient} from '@angular/common/http';
import { User } from './user';
@Injectable({
......
<div id="count">{{problems.length}} problems available!</div>
<div class="head">
<div id="count">{{problems.length}} problems available!</div>
<button (click) = "openForm()">Post a Problem</button>
</div>
<div class="loginPopup">
<div class="formPopup" id="popupForm">
<form class="formContainer" id="quesform" (ngSubmit) = "submitForm()">
<input type="text" id="title" placeholder="Problem Title" name="title" [(ngModel)]="questiontoPost.title" required>
<textarea id="statement" placeholder="Problem Statement" name="statement" rows="8" cols="80" [(ngModel)]="questiontoPost.statement" required></textarea>
<textarea id="tc1_i" cols="30" rows="8" name="tc1" placeholder="Testcase1 Input" style="margin-right: 20px;" [(ngModel)]="questiontoPost.tc1_inp"></textarea>
<textarea id="tc2_i" cols="30" rows="8" name="tc2" placeholder="Testcase2 Input" style="margin-left: 20px;" [(ngModel)]="questiontoPost.tc2_inp"></textarea>
<textarea id="tc1_o" cols="30" rows="4" name="out1" placeholder="Testcase1 Output" style="margin-right: 20px;" [(ngModel)]="questiontoPost.tc1_out"></textarea>
<textarea id="tc2_o" cols="30" rows="4" name="out2" placeholder="Testcase2 Output" style="margin-left: 20px;" [(ngModel)]="questiontoPost.tc2_out"></textarea>
<input type="datetime-local" name="stime" id="start_time" [(ngModel)]="questiontoPost.start_time">
<input type="datetime-local" name="etime" id="end_time" [(ngModel)]="questiontoPost.end_time">
<button type="submit" class="btn" (click) = "submitForm()">Submit</button>
<button type="button" class="btn cancel" (click) ="closeForm()">Close</button>
</form>
</div>
</div>
<div *ngFor="let problem of problems" class="card">
<div class="title">{{problem.title}}</div>
......
......@@ -23,3 +23,68 @@
margin: 20px;
font-size: 1.5em;
}
.head {
display: block;
text-align: center;
justify-content: space-around;
button {
font-size: 1.2rem;
}
}
.loginPopup {
position: relative;
text-align: center;
width: 100%;
}
.formPopup {
display: none;
position: fixed;
left: 50%;
top: 5%;
transform: translate(-50%, 5%);
z-index: 9;
background-color: var(--gc2);
}
.formContainer {
max-width: 800px;
padding: 20px;
text-align: center;
textarea {
display: inline-block;
border: none;
border-radius: 20px;
margin: 5px 0 20px 0;
padding: 5px 20px 5px 20px;
}
}
.formContainer input {
display: inline-block;
width: 80%;
height: 25px;
background-color: aliceblue;
border: none;
border-radius: 20px;
margin: 5px 0 20px 0;
padding: 5px 20px 5px 20px;
}
.formContainer .btn {
padding: 12px 20px;
border: none;
cursor: pointer;
width: 100%;
margin-bottom: 15px;
opacity: 0.8;
}
.formContainer .btn:hover,
.openButton:hover {
opacity: 1
}
......@@ -3,6 +3,8 @@ import {ProblemService} from '../problem.service';
import { ApiService } from '../api.service';
import {Problem} from '../problem';
import { User } from '../user';
import { Question } from '../question';
import { QuestionService } from '../question.service';
@Component({
selector: 'app-home',
......@@ -13,15 +15,32 @@ export class HomeComponent implements OnInit {
user: User;
problems: Problem[];
questiontoPost: Question = {
title: "",
username: "",
statement: "",
tc1_inp: "",
tc1_out: "",
tc2_inp: "",
tc2_out: "",
start_time: "",
end_time: ""
};
questions: any[];
constructor(private dataService: ApiService,
private problemService: ProblemService) {
private problemService: ProblemService,
private questionService: QuestionService) {
}
ngOnInit(): void {
this.user = JSON.parse(this.dataService.getToken());
console.log(this.user);
this.questiontoPost.username = this.user.username;
this.getProblems();
// this.questionService.getQues()
// .subscribe(questions => this.questions = questions);
// console.log(this.questions);
}
getProblems(): void {
......@@ -29,4 +48,38 @@ export class HomeComponent implements OnInit {
.subscribe(problems => this.problems = problems);
}
openForm(): void {
document.getElementById("popupForm").style.display = "block";
}
closeForm(): void {
document.getElementById("popupForm").style.display = "none";
}
resetForm(): void {
this.questiontoPost = {
title: "",
username: this.user.username,
statement: "",
tc1_inp: "",
tc1_out: "",
tc2_inp: "",
tc2_out: "",
start_time: "",
end_time: ""
};
}
submitForm() {
this.questionService.uploadQues(this.questiontoPost).subscribe(
(event: any) => {
if (typeof (event) === 'object') {
this.questiontoPost = null;
(document.getElementById('quesform') as HTMLInputElement).value = '';
}
}
);
this.resetForm();
this.closeForm();
}
}
import { TestBed } from '@angular/core/testing';
import { QuestionService } from './question.service';
describe('QuestionService', () => {
let service: QuestionService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(QuestionService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import {EventEmitter, Injectable, Output} from '@angular/core';
import {map} from 'rxjs/operators';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import { Question } from './question';
@Injectable({
providedIn: 'root'
})
export class QuestionService {
uploadUrl = "http://localhost/sfcode/backend/questions/question_save.php/";
getUrl = "http://localhost/sfcode/backend/questions/get_questions.php/";
constructor(private http: HttpClient) { }
uploadQues(ques: Question): Observable<any> {
return this.http.post(this.uploadUrl, ques);
}
getQues(): Observable<any[]> {
return this.http.get<any[]>(this.getUrl);
}
}
export interface Question {
title: string;
username: string;
statement: string;
tc1_inp: string;
tc1_out: string;
tc2_inp: string;
tc2_out: string;
start_time: string;
end_time: string;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment