PeerTube/client/src/app/app.component.ts

80 lines
1.8 KiB
TypeScript
Raw Normal View History

2016-05-13 12:18:37 +00:00
import { Component } from '@angular/core';
2016-07-18 13:39:10 +00:00
import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router';
2016-03-14 12:50:19 +00:00
import { FriendService } from './friends';
import {
AuthService,
AuthStatus,
2016-07-08 15:15:14 +00:00
SearchComponent,
SearchService
} from './shared';
2016-07-08 15:15:14 +00:00
import { VideoService } from './videos';
2016-03-14 12:50:19 +00:00
@Component({
selector: 'my-app',
template: require('./app.component.html'),
styles: [ require('./app.component.scss') ],
directives: [ ROUTER_DIRECTIVES, SearchComponent ],
providers: [ FriendService, VideoService, SearchService ]
2016-03-14 12:50:19 +00:00
})
export class AppComponent {
2016-05-27 15:25:52 +00:00
choices = [];
2016-05-27 15:49:18 +00:00
isLoggedIn: boolean;
2016-05-24 21:00:58 +00:00
2016-05-27 15:49:18 +00:00
constructor(
private authService: AuthService,
private friendService: FriendService,
2016-07-18 13:39:10 +00:00
private route: ActivatedRoute,
2016-05-27 15:49:18 +00:00
private router: Router
2016-03-22 14:51:54 +00:00
) {
2016-05-27 15:25:52 +00:00
this.isLoggedIn = this.authService.isLoggedIn();
2016-03-22 14:51:54 +00:00
2016-05-27 15:25:52 +00:00
this.authService.loginChangedSource.subscribe(
2016-03-22 14:51:54 +00:00
status => {
if (status === AuthStatus.LoggedIn) {
this.isLoggedIn = true;
console.log('Logged in.');
} else if (status === AuthStatus.LoggedOut) {
this.isLoggedIn = false;
console.log('Logged out.');
} else {
console.error('Unknown auth status: ' + status);
2016-03-22 14:51:54 +00:00
}
}
);
}
2016-03-14 21:16:43 +00:00
2016-08-09 19:45:21 +00:00
isUserAdmin() {
return this.authService.isAdmin();
}
2016-03-22 14:51:54 +00:00
logout() {
this.authService.logout();
// Redirect to home page
this.router.navigate(['/videos/list']);
2016-03-22 14:51:54 +00:00
}
2016-03-14 12:50:19 +00:00
makeFriends() {
2016-05-27 15:25:52 +00:00
this.friendService.makeFriends().subscribe(
2016-03-14 12:50:19 +00:00
status => {
if (status === 409) {
alert('Already made friends!');
2016-03-14 21:16:43 +00:00
} else {
2016-03-14 12:50:19 +00:00
alert('Made friends!');
}
},
error => alert(error)
2016-04-08 18:58:07 +00:00
);
2016-03-14 12:50:19 +00:00
}
quitFriends() {
2016-05-27 15:25:52 +00:00
this.friendService.quitFriends().subscribe(
2016-03-14 12:50:19 +00:00
status => {
2016-05-27 15:49:18 +00:00
alert('Quit friends!');
2016-03-14 12:50:19 +00:00
},
error => alert(error)
2016-04-08 18:58:07 +00:00
);
2016-03-14 12:50:19 +00:00
}
}