Commit 5f0b478d authored by Ayush's avatar Ayush

Reconfigure routing

parent 0c9724c7
<?php
include_once("database.php")
include_once("database.php");
$postData = file_get_contents("php://input");
if(isset($postData) && !empty($postData)) {
......@@ -38,8 +38,8 @@ if(isset($postData) && !empty($postData)) {
http_response_code(404);
}
}
}
}
?>
\ No newline at end of file
?>
......@@ -11,10 +11,11 @@ import { FileComponent } from './file/file.component';
const routes: Routes = [
{ path: 'home', component: HomeComponent, canActivate: [AuthGuard] },
{ path: 'arena/:id', component: ArenaComponent, canActivate: [AuthGuard] },
{ path: 'arena', component: IdeComponent, canActivate: [AuthGuard] },
{ path: 'arena/problem/:id', component: ArenaComponent, canActivate: [AuthGuard] },
{ path: 'arena/file/:id', component: IdeComponent, canActivate: [AuthGuard] },
{ path: 'arena/file/new', component: IdeComponent, canActivate: [AuthGuard] },
{ path: 'user', component: UserComponent, canActivate: [AuthGuard] },
{ path: 'files', component: FileComponent, canActivate: [AuthGuard] },
{ path: 'files', component: FileComponent, canActivate: [AuthGuard] },
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
{ path: '**', redirectTo: '/home' },
......
......@@ -19,7 +19,7 @@ export class ArenaComponent implements OnInit {
}
ngOnInit(): void {
this.id = parseInt(this.router.url.split('/')[2], 10);
this.id = parseInt(this.router.url.split('/')[3], 10);
this.getProblem();
const editorArea = document.getElementById('editor');
const editor = CodeMirror.fromTextArea(editorArea as HTMLTextAreaElement, {
......
......@@ -21,10 +21,11 @@ export class FileService {
for (const item of arr) {
ret.push({
username: '',
id: item,
filename: 'lambda',
language: '.cpp',
text: 'Random Shit',
text: 'Random Shit'
});
}
......
export interface File {
id: number;
username: string;
filename: string;
language: string;
text: string;
......
<div id="tray">
<button style="margin-right: 10px;" routerLink="/arena" routerLinkActive="active">Create A File</button>
<button style="margin-right: 10px;" routerLink="/arena/file/new" routerLinkActive="active">Create A File</button>
<button (click)="onClick()" id="myBtn" style="margin-left: 10px;">Upload A File</button>
</div>
......
......@@ -2,7 +2,7 @@
<a *ngIf="!loggedIn" routerLink="/register" routerLinkActive="active">Register</a>
<a *ngIf="!loggedIn" routerLink="/login" routerLinkActive="active">Login</a>
<a *ngIf="loggedIn" routerLink="/home" routerLinkActive="active">Home</a>
<a *ngIf="loggedIn" routerLink="/arena" routerLinkActive="active">Arena</a>
<a *ngIf="loggedIn" routerLink="/arena/file/new" routerLinkActive="active">Arena</a>
<a *ngIf="loggedIn" routerLink="/files" routerLinkActive="active">Files</a>
<a *ngIf="loggedIn" routerLink="/user" routerLinkActive="active">User</a>
</nav>
\ No newline at end of file
</nav>
......@@ -3,7 +3,7 @@
<div *ngFor="let problem of problems" class="card">
<div class="title">{{problem.title}}</div>
<div class="details">{{problem.details}}</div>
<button [routerLink]="['/arena', problem.id]" class="attempt">Attempt</button>
<button [routerLink]="['/arena/problem', problem.id]" class="attempt">Attempt</button>
<span class="stats"><span *ngIf="problem.n_attempts != 0">{{problem.n_correct}} accepted out of
{{problem.n_attempts}}
({{problem.n_correct / problem.n_attempts * 100}}%)</span><span *ngIf="problem.n_attempts === 0">No attempt
......
......@@ -6,6 +6,7 @@ import {RunCodeService} from '../run-code.service';
import {SaveFileComponent} from '../save-file/save-file.component';
import {File} from '../file';
import {FileService} from '../file.service';
import {ApiService} from '../api.service';
declare const CodeMirror: any;
......@@ -25,13 +26,15 @@ export class IdeComponent implements OnInit {
id: null,
filename: 'Untitled',
language: '.cpp',
text: ''
text: '',
username: JSON.parse(this.apiService.getToken()).username,
};
@ViewChild(InputComponent) inputField;
@ViewChild(IdeCompileComponent) runField;
@ViewChild(SaveFileComponent) saveField;
constructor(public router: Router, public runCodeService: RunCodeService, private fileService: FileService) {
constructor(public router: Router, public runCodeService: RunCodeService, private fileService: FileService,
private apiService: ApiService) {
}
ngOnInit(): void {
......
import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import {Component, OnInit, Output, EventEmitter, Input} from '@angular/core';
import {FileService} from '../file.service';
import {File} from '../file';
import {Location} from '@angular/common';
@Component({
selector: 'app-save-file',
......@@ -14,9 +15,11 @@ export class SaveFileComponent implements OnInit {
@Input() file: File;
isUploading = false;
constructor(public fileService: FileService) { }
constructor(public fileService: FileService, private location: Location) {
}
ngOnInit(): void { }
ngOnInit(): void {
}
setState(value: boolean): void {
const text = document.getElementById('filenameInput') as HTMLTextAreaElement;
......@@ -33,6 +36,8 @@ export class SaveFileComponent implements OnInit {
this.isUploading = false;
this.savedFile.emit(true);
this.isActive = false;
this.location.replaceState('/arena/file/' + response.key);
console.log(response);
}, (error) => {
console.log(error);
this.isUploading = false;
......
......@@ -22,7 +22,6 @@ export class UserComponent implements OnInit {
ngOnInit(): void {
this.dataService.getLoggedInState.subscribe(state => this.changeState(state));
this.loggedIn = this.dataService.isLoggedIn();
console.log(this.dataService.getToken());
this.user = JSON.parse(this.dataService.getToken());
(() => {
......
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