Video,
VideoService
} from '../shared/index';
-import { Search, SearchField } from '../../shared/index';
-import { AuthService, User } from '../../users/index';
+import { AuthService, Search, SearchField, User } from '../../shared/index';
import { VideoMiniatureComponent } from './video-miniature.component';
import { VideoSortComponent } from './video-sort.component';
selector: 'my-videos-list',
styleUrls: [ 'client/app/videos/video-list/video-list.component.css' ],
templateUrl: 'client/app/videos/video-list/video-list.component.html',
- directives: [ ROUTER_DIRECTIVES, PAGINATION_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent, LoaderComponent ]
+ directives: [ LoaderComponent, PAGINATION_DIRECTIVES, ROUTER_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent ]
})
export class VideoListComponent implements OnInit {
- user: User = null;
- videos: Video[] = [];
+ loading = false;
pagination: Pagination = {
currentPage: 1,
itemsPerPage: 9,
total: 0
};
sort: SortField;
- loading: boolean = false;
+ user: User = null;
+ videos: Video[] = [];
private search: Search;
constructor(
- private _authService: AuthService,
- private _videoService: VideoService,
- private _routeParams: RouteParams,
- private _router: Router
+ private authService: AuthService,
+ private router: Router,
+ private routeParams: RouteParams,
+ private videoService: VideoService
) {
this.search = {
- value: this._routeParams.get('search'),
- field: <SearchField>this._routeParams.get('field')
+ value: this.routeParams.get('search'),
+ field: <SearchField>this.routeParams.get('field')
};
- this.sort = <SortField>this._routeParams.get('sort') || '-createdDate';
+ this.sort = <SortField>this.routeParams.get('sort') || '-createdDate';
}
ngOnInit() {
- if (this._authService.isLoggedIn()) {
+ if (this.authService.isLoggedIn()) {
this.user = User.load();
}
let observable = null;
if (this.search.value !== null) {
- observable = this._videoService.searchVideos(this.search, this.pagination, this.sort);
+ observable = this.videoService.searchVideos(this.search, this.pagination, this.sort);
} else {
- observable = this._videoService.getVideos(this.pagination, this.sort);
+ observable = this.videoService.getVideos(this.pagination, this.sort);
}
observable.subscribe(
({ videos, totalVideos }) => {
this.videos = videos;
this.pagination.total = totalVideos;
+
this.loading = false;
},
error => alert(error)
);
}
- onRemoved(video: Video): void {
+ noVideo() {
+ return !this.loading && this.videos.length === 0;
+ }
+
+ onRemoved(video: Video) {
this.videos.splice(this.videos.indexOf(video), 1);
}
};
if (this.search.value) {
- params.search = this.search.value;
params.field = this.search.field;
+ params.search = this.search.value;
}
- this._router.navigate(['VideosList', params]);
+ this.router.navigate(['VideosList', params]);
this.getVideos();
}
}