-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple quest view, front-end code for it and fake back-end
- Loading branch information
Showing
8 changed files
with
113 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,13 @@ | ||
import * as ng from '@angular/core'; | ||
import { ROUTER_DIRECTIVES } from '@angular/router'; | ||
import { Cookie } from 'ng2-cookies/ng2-cookies'; | ||
import { Http } from '@angular/http'; | ||
|
||
@ng.Component({ | ||
selector: 'home', | ||
template: require('./home.html'), | ||
directives: [...ROUTER_DIRECTIVES], | ||
directives: [...ROUTER_DIRECTIVES] | ||
}) | ||
export class Home { | ||
constructor(private http: Http) { } | ||
|
||
ngOnInit() { | ||
let token = Cookie.get('playerToken'); | ||
if (!token) { | ||
this.http.get('/home/registernewplayer').subscribe(result => { | ||
token = result.text(); | ||
Cookie.set('playerToken', token); | ||
}); | ||
} | ||
constructor() { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
<h2>Квест</h2> | ||
<div style="margin-top: 50px"> | ||
<div> | ||
<p class="lead"> | ||
{{task.title}} | ||
</p> | ||
|
||
<p>This is a simple example of an Angular 2 component.</p> | ||
|
||
<p>Current count: <strong>{{ currentCount }}</strong></p> | ||
|
||
<button (click)="incrementCounter()">Increment</button> | ||
<h3 style="max-width: 400px">{{task.content}}</h3> | ||
<br /> | ||
<form (submit)="submit()"> | ||
<div class="form-group"> | ||
<input type="text" name="answer" class="form-control" autofocus="autofocus" placeholder="" [(ngModel)]="answer"> | ||
<br /> | ||
<a class="btn btn-success" (click)="submit()">Отправить</a> | ||
</div> | ||
</form> | ||
<br /> | ||
<div ng-style="{ 'color' : hintColor }"> | ||
<b>{{hints}}</b> | ||
</div> | ||
</div> | ||
<br /> | ||
<div>Просмотрено - {{task.watched}}</div> | ||
<div>Пройдено - {{task.done}}</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,33 @@ | ||
import * as ng from '@angular/core'; | ||
import {Inject} from '@angular/core'; | ||
import { Http } from '@angular/http'; | ||
import { Cookie } from 'ng2-cookies/ng2-cookies'; | ||
|
||
@ng.Component({ | ||
selector: 'quest', | ||
template: require('./quest.html') | ||
}) | ||
export class Quest { | ||
public currentTask = 0; | ||
private task: any = {}; | ||
private answer: string = ''; | ||
|
||
public nextTask() { | ||
// call API | ||
constructor( @Inject(Http) private http: Http) { | ||
this.http.get('/home/getcurrentstate', { withCredentials: true }) | ||
.subscribe(result => { | ||
this.task = result.json().task; | ||
let token = Cookie.get('playerToken'); | ||
if (!token) { | ||
token = result.json().player.token; | ||
Cookie.set('playerToken', token); | ||
} | ||
}); | ||
} | ||
|
||
submit() { | ||
this.http.get('/home/submitanswer', { withCredentials: true }) | ||
.subscribe(result => { | ||
this.task = result.json().task; | ||
this.answer = ''; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters