diff --git a/ClientApp/boot-client.ts b/ClientApp/boot-client.ts index be3ca22..6c97809 100644 --- a/ClientApp/boot-client.ts +++ b/ClientApp/boot-client.ts @@ -9,11 +9,13 @@ import { provideRouter } from '@angular/router'; import { HTTP_PROVIDERS } from '@angular/http'; import { App } from './components/app/app'; import { routes } from './routes'; +import { disableDeprecatedForms, provideForms } from '@angular/forms'; bootstrap(App, [ ...HTTP_PROVIDERS, FormBuilder, - provideRouter(routes) + provideRouter(routes), + provideForms() ]); // Basic hot reloading support. Automatically reloads and restarts the Angular 2 app each time diff --git a/ClientApp/components/home/home.ts b/ClientApp/components/home/home.ts index 64692b3..e004338 100644 --- a/ClientApp/components/home/home.ts +++ b/ClientApp/components/home/home.ts @@ -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() { } -} +} \ No newline at end of file diff --git a/ClientApp/components/quest/quest.html b/ClientApp/components/quest/quest.html index 0f21235..86689d1 100644 --- a/ClientApp/components/quest/quest.html +++ b/ClientApp/components/quest/quest.html @@ -1,7 +1,24 @@ -

Квест

+
+
+

+ {{task.title}} +

-

This is a simple example of an Angular 2 component.

- -

Current count: {{ currentCount }}

- - +

{{task.content}}

+
+
+ +
+
+
+ {{hints}} +
+
+
+
Просмотрено - {{task.watched}}
+
Пройдено - {{task.done}}
+
\ No newline at end of file diff --git a/ClientApp/components/quest/quest.ts b/ClientApp/components/quest/quest.ts index af1f3af..9c6b0b2 100644 --- a/ClientApp/components/quest/quest.ts +++ b/ClientApp/components/quest/quest.ts @@ -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 = ''; + }); } } diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 7a59c5d..7061228 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; +using System; using System.Linq; -using System.Threading.Tasks; using HabraQuest.Model; using Microsoft.AspNetCore.Mvc; @@ -26,17 +24,59 @@ public IActionResult Error() return View(); } - public string RegisterNewPlayer() + public Player InitializePlayer() { - Player player = new Player + Player player = null; + var token = Request.Cookies["playerToken"]; + if (token == null) { - Token = Guid.NewGuid() - }; + player = new Player + { + Token = Guid.NewGuid() + }; + + dataContext.Add(player); + dataContext.SaveChanges(); + } + + return player ?? dataContext.Players.Single(p => p.Token.ToString() == token); + } - dataContext.Add(player); - dataContext.SaveChanges(); + public dynamic GetCurrentState() + { + return new + { + Task = new QuestTask + { + Id = 2, + Title = "Шта?", + Content = "Превед, креведко" + }, + Player = InitializePlayer(), + }; + } - return player.Token.ToString(); + public dynamic SubmitAnswer() + { + return new + { + Task = new QuestTask + { + Id = 3, + Title = "Шта?2", + Content = "Превед, креведко. ololo" + }, + Player = InitializePlayer(), + }; } } + + public class QuestTask + { + public int Id { get; set; } + public string Title { get; set; } + public string Content { get; set; } + public int Watched { get; set; } + public int Done { get; set; } + } } diff --git a/Views/Home/Index.cshtml b/Views/Home/Index.cshtml index 6adad5c..f184985 100644 --- a/Views/Home/Index.cshtml +++ b/Views/Home/Index.cshtml @@ -1,7 +1,3 @@ -@{ - ViewData["Title"] = "Home Page"; -} - Loading... diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 12e8e3a..18e803a 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -1,9 +1,9 @@ - + - @ViewData["Title"] - HabraQuest + HabraQuest diff --git a/package.json b/package.json index 0058df8..9d800ff 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "HabraQuest", + "name": "habraquest", "version": "0.0.0", "devDependencies": { "bootstrap": "^3.3.6", @@ -18,13 +18,14 @@ "webpack-hot-middleware": "^2.10.0" }, "dependencies": { - "@angular/common": "2.0.0-rc.3", - "@angular/compiler": "2.0.0-rc.3", - "@angular/core": "2.0.0-rc.3", - "@angular/http": "2.0.0-rc.3", - "@angular/platform-browser": "2.0.0-rc.3", - "@angular/platform-browser-dynamic": "2.0.0-rc.3", - "@angular/platform-server": "2.0.0-rc.3", + "@angular/common": "2.0.0-rc.4", + "@angular/compiler": "2.0.0-rc.4", + "@angular/core": "2.0.0-rc.4", + "@angular/forms": "^0.2.0", + "@angular/http": "2.0.0-rc.4", + "@angular/platform-browser": "2.0.0-rc.4", + "@angular/platform-browser-dynamic": "2.0.0-rc.4", + "@angular/platform-server": "2.0.0-rc.4", "@angular/router": "3.0.0-alpha.8", "angular2-universal": "^0.104.1", "aspnet-prerendering": "^1.0.2",