Commit 5f0b478d authored by Ayush's avatar Ayush

Reconfigure routing

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