Skip to content

Commit ced9df7

Browse files
author
Piotrek
committed
Copied auth system from my previous application. Some components need to be deleted
1 parent 5c81cdf commit ced9df7

27 files changed

Lines changed: 759 additions & 40 deletions

‎templates/Angular2Spa/ClientApp/app/app.module.ts‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1+
import { ExploreDefinitionsComponent } from './components/exploreDefinitions/exploreDefinitions.component';
2+
import { DefinitionsService } from './shared/definitions.service';
3+
import { WordsService } from './shared/words.service';
4+
import { ExploreWordsComponent } from './components/exploreWords/exploreWords.component';
15
import { NgModule } from '@angular/core';
26
import { RouterModule } from '@angular/router';
3-
import { UniversalModule } from 'angular2-universal';
7+
import { UniversalModule, isBrowser, isNode } from 'angular2-universal';
48
import { AppComponent } from './components/app/app.component'
59
import { NavMenuComponent } from './components/navmenu/navmenu.component';
610
import { HomeComponent } from './components/home/home.component';
711
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
812
import { CounterComponent } from './components/counter/counter.component';
13+
import { DatabaseComponent } from './components/database/database.component';
14+
import { LoginComponent } from './components/login/login.component';
15+
import { RegisterComponent } from './components/register/register.component';
16+
import { AccountService } from './shared/account.service';
17+
import { LocalStorage } from './shared/localStorage';
18+
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
919

1020
@NgModule({
11-
bootstrap: [ AppComponent ],
21+
bootstrap: [AppComponent],
1222
declarations: [
1323
AppComponent,
1424
NavMenuComponent,
1525
CounterComponent,
1626
FetchDataComponent,
17-
HomeComponent
27+
HomeComponent,
28+
DatabaseComponent,
29+
LoginComponent,
30+
RegisterComponent,
31+
ExploreWordsComponent,
32+
ExploreDefinitionsComponent
1833
],
1934
imports: [
2035
UniversalModule, // Must be first import. This automatically imports BrowserModule, HttpModule, and JsonpModule too.
@@ -23,8 +38,21 @@ import { CounterComponent } from './components/counter/counter.component';
2338
{ path: 'home', component: HomeComponent },
2439
{ path: 'counter', component: CounterComponent },
2540
{ path: 'fetch-data', component: FetchDataComponent },
41+
{ path: 'database', component: DatabaseComponent },
42+
{ path: 'login', component: LoginComponent },
43+
{ path: 'register', component: RegisterComponent },
44+
{ path: 'exploreWords', component: ExploreWordsComponent },
45+
{ path: 'exploreDefinitions/:id', component: ExploreDefinitionsComponent },
2646
{ path: '**', redirectTo: 'home' }
27-
])
47+
]),
48+
FormsModule,
49+
ReactiveFormsModule
50+
],
51+
providers: [
52+
AccountService,
53+
WordsService,
54+
DefinitionsService,
55+
{ provide: LocalStorage, useValue: (isBrowser) ? window.localStorage : { getItem() { } } }
2856
]
2957
})
3058
export class AppModule {
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { Component } from '@angular/core';
2+
import '../../../rxjs-operators';
3+
import { AccountService } from '../../shared/account.service';
24

35
@Component({
46
selector: 'app',
5-
templateUrl: './app.component.html',
6-
styleUrls: ['./app.component.css']
7+
template: require('./app.component.html'),
8+
styles: [require('./app.component.css')]
79
})
810
export class AppComponent {
11+
constructor(private accountService: AccountService) { }
912
}

‎templates/Angular2Spa/ClientApp/app/components/counter/counter.component.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component } from '@angular/core';
22

33
@Component({
44
selector: 'counter',
5-
templateUrl: './counter.component.html'
5+
template: require('./counter.component.html')
66
})
77
export class CounterComponent {
88
public currentCount = 0;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<h1>Example Database data </h1>
2+
3+
<p>This component demonstrates downloading data from database.</p>
4+
5+
<p *ngIf="!stories"><em>Loading...</em></p>
6+
7+
<table class='table' *ngIf="stories">
8+
<thead>
9+
<tr>
10+
<th>Content</th>
11+
<th>Time of adding</th>
12+
<th>Views</th>
13+
</tr>
14+
</thead>
15+
<tbody>
16+
<tr *ngFor="let story of stories">
17+
<td>{{ story.content }}</td>
18+
<td>{{ story.timeOfAdding }}</td>
19+
<td>{{ story.numberOfViews }}</td>
20+
</tr>
21+
</tbody>
22+
</table>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { Http } from '@angular/http';
3+
4+
@Component({
5+
selector: 'database',
6+
template: require('./database.component.html')
7+
})
8+
export class DatabaseComponent implements OnInit {
9+
public stories: Story[];
10+
11+
constructor(http: Http) {
12+
http.get('api/storiesFromDb').subscribe(result => {
13+
this.stories = result.json();
14+
});
15+
}
16+
17+
ngOnInit() { }
18+
}
19+
20+
interface Story {
21+
content: string;
22+
timeOfAdding: Date;
23+
numberOfViews: number;
24+
}

‎templates/Angular2Spa/ClientApp/app/components/exploreDefinitions/exploreDefinitions.component.html‎

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Definition } from './../../shared/models/Definition';
2+
import { Router, ActivatedRoute } from '@angular/router';
3+
import { DefinitionsService } from './../../shared/definitions.service';
4+
import { Component, OnInit } from '@angular/core';
5+
import { Http } from '@angular/http';
6+
7+
@Component({
8+
selector: 'exploreDefinitions',
9+
template: require('./exploreDefinitions.component.html')
10+
})
11+
export class ExploreDefinitionsComponent implements OnInit {
12+
private definitionID: number;
13+
public definitions: Definition[];
14+
constructor(private http: Http, private definitionsService: DefinitionsService, private router: Router, private route: ActivatedRoute) { }
15+
16+
ngOnInit() {
17+
this.definitionID = this.route.snapshot.params['id'];
18+
console.log(this.definitionID);
19+
this.loadData();
20+
}
21+
22+
loadData(){
23+
this.definitionsService.getByID(this.definitionID).subscribe(result => {
24+
this.definitions = result;
25+
console.log(result);
26+
});
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Words from database:
2+
3+
<table class='table'>
4+
<thead>
5+
<tr>
6+
<th>ID</th>
7+
<th>Title</th>
8+
<th>WhenCreated</th>
9+
<th>Author</th>
10+
</tr>
11+
</thead>
12+
<tbody>
13+
<tr *ngFor="let word of words">
14+
<td>{{word.id}}</td>
15+
<td>{{word.title}}</td>
16+
<td>{{word.whenCreated}}</td>
17+
<td>{{word.author}}</td>
18+
<td>{{word.authorName}}</td>
19+
<td><button (click)="delete(word.id)">X</button></td>
20+
</tr>
21+
</tbody>
22+
</table>
23+
24+
<h4>New word:</h4>
25+
<input #newWordTitle />
26+
<button (click)="addNewData(newWordTitle.value); newWordTitle.value=''">
27+
Add word
28+
</button>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { WordsService } from './../../shared/words.service';
2+
import { Word } from './../../shared/models/Word';
3+
import { Http } from '@angular/http';
4+
import { Component, OnInit } from '@angular/core';
5+
6+
@Component({
7+
selector: 'exploreWords',
8+
template: require('./exploreWords.component.html')
9+
})
10+
export class ExploreWordsComponent implements OnInit {
11+
public words: Word[];
12+
13+
constructor(private http: Http, private wordsService: WordsService) {
14+
this.refreshData();
15+
}
16+
17+
ngOnInit() { }
18+
19+
refreshData() {
20+
this.wordsService.getAll().subscribe(result => {
21+
this.words = result;
22+
console.log(result);
23+
});
24+
}
25+
26+
addNewData(newTitle: string) {
27+
var newWord = <Word>{
28+
title: newTitle
29+
};
30+
this.wordsService.addNew(<Word>{ title: newTitle }).subscribe(result => {
31+
console.log(result);
32+
this.refreshData();
33+
});
34+
}
35+
36+
delete(id: number) {
37+
this.wordsService.delete(id).subscribe(result => {
38+
console.log(result);
39+
this.refreshData();
40+
});
41+
}
42+
}

‎templates/Angular2Spa/ClientApp/app/components/fetchdata/fetchdata.component.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { Http } from '@angular/http';
33

44
@Component({
55
selector: 'fetchdata',
6-
templateUrl: './fetchdata.component.html'
6+
template: require('./fetchdata.component.html')
77
})
88
export class FetchDataComponent {
99
public forecasts: WeatherForecast[];
1010

1111
constructor(http: Http) {
1212
http.get('/api/SampleData/WeatherForecasts').subscribe(result => {
13-
this.forecasts = result.json() as WeatherForecast[];
13+
this.forecasts = result.json();
1414
});
1515
}
1616
}

0 commit comments

Comments
 (0)