From 0626e7af82e02f8a5bd1e74a7d4d8c916d073ceb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 24 Apr 2018 15:10:54 +0200 Subject: Add account view --- client/src/app/shared/account/account.model.ts | 15 +++++++++++ client/src/app/shared/account/account.service.ts | 31 ++++++++++++++++++++++ client/src/app/shared/shared.module.ts | 2 ++ .../src/app/shared/video/abstract-video-list.html | 4 +-- client/src/app/shared/video/abstract-video-list.ts | 1 + client/src/app/shared/video/video.service.ts | 18 +++++++++++++ 6 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 client/src/app/shared/account/account.service.ts (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/account/account.model.ts b/client/src/app/shared/account/account.model.ts index 0bdc76478..3d5176bdd 100644 --- a/client/src/app/shared/account/account.model.ts +++ b/client/src/app/shared/account/account.model.ts @@ -16,6 +16,21 @@ export class Account implements ServerAccount { updatedAt: Date avatar: Avatar + constructor (hash: ServerAccount) { + this.id = hash.id + this.uuid = hash.uuid + this.url = hash.url + this.name = hash.name + this.displayName = hash.displayName + this.description = hash.description + this.host = hash.host + this.followingCount = hash.followingCount + this.followersCount = hash.followersCount + this.createdAt = new Date(hash.createdAt.toString()) + this.updatedAt = new Date(hash.updatedAt.toString()) + this.avatar = hash.avatar + } + static GET_ACCOUNT_AVATAR_URL (account: Account) { const absoluteAPIUrl = getAbsoluteAPIUrl() diff --git a/client/src/app/shared/account/account.service.ts b/client/src/app/shared/account/account.service.ts new file mode 100644 index 000000000..8c66ae04a --- /dev/null +++ b/client/src/app/shared/account/account.service.ts @@ -0,0 +1,31 @@ +import { Injectable } from '@angular/core' +import 'rxjs/add/operator/catch' +import 'rxjs/add/operator/map' +import { environment } from '../../../environments/environment' +import { Observable } from 'rxjs/Observable' +import { Account } from '@app/shared/account/account.model' +import { RestExtractor } from '@app/shared/rest/rest-extractor.service' +import { RestService } from '@app/shared/rest/rest.service' +import { HttpClient } from '@angular/common/http' +import { Account as ServerAccount } from '../../../../../shared/models/actors/account.model' +import { ReplaySubject } from 'rxjs/ReplaySubject' + +@Injectable() +export class AccountService { + static BASE_ACCOUNT_URL = environment.apiUrl + '/api/v1/accounts/' + + accountLoaded = new ReplaySubject(1) + + constructor ( + private authHttp: HttpClient, + private restExtractor: RestExtractor, + private restService: RestService + ) {} + + getAccount (id: number): Observable { + return this.authHttp.get(AccountService.BASE_ACCOUNT_URL + id) + .map(accountHash => new Account(accountHash)) + .do(account => this.accountLoaded.next(account)) + .catch((res) => this.restExtractor.handleError(res)) + } +} diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts index 74730e2aa..2178eebc8 100644 --- a/client/src/app/shared/shared.module.ts +++ b/client/src/app/shared/shared.module.ts @@ -31,6 +31,7 @@ import { VideoMiniatureComponent } from './video/video-miniature.component' import { VideoFeedComponent } from './video/video-feed.component' import { VideoThumbnailComponent } from './video/video-thumbnail.component' import { VideoService } from './video/video.service' +import { AccountService } from '@app/shared/account/account.service' @NgModule({ imports: [ @@ -104,6 +105,7 @@ import { VideoService } from './video/video.service' VideoBlacklistService, UserService, VideoService, + AccountService, MarkdownService ] }) diff --git a/client/src/app/shared/video/abstract-video-list.html b/client/src/app/shared/video/abstract-video-list.html index cb04e07b4..690529dcf 100644 --- a/client/src/app/shared/video/abstract-video-list.html +++ b/client/src/app/shared/video/abstract-video-list.html @@ -1,5 +1,5 @@ -
-
+
+
{{ titlePage }}
diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts index 728c864e9..642a85f65 100644 --- a/client/src/app/shared/video/abstract-video-list.ts +++ b/client/src/app/shared/video/abstract-video-list.ts @@ -29,6 +29,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { syndicationItems = [] loadOnInit = true + marginContent = true pageHeight: number videoWidth: number videoHeight: number diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index ef8babd55..f82aa7389 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts @@ -21,6 +21,8 @@ import { VideoDetails } from './video-details.model' import { VideoEdit } from './video-edit.model' import { Video } from './video.model' import { objectToFormData } from '@app/shared/misc/utils' +import { Account } from '@app/shared/account/account.model' +import { AccountService } from '@app/shared/account/account.service' @Injectable() export class VideoService { @@ -97,6 +99,22 @@ export class VideoService { .catch((res) => this.restExtractor.handleError(res)) } + getAccountVideos ( + account: Account, + videoPagination: ComponentPagination, + sort: VideoSortField + ): Observable<{ videos: Video[], totalVideos: number}> { + const pagination = this.restService.componentPaginationToRestPagination(videoPagination) + + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, sort) + + return this.authHttp + .get(AccountService.BASE_ACCOUNT_URL + account.id + '/videos', { params }) + .map(this.extractVideos) + .catch((res) => this.restExtractor.handleError(res)) + } + getVideos ( videoPagination: ComponentPagination, sort: VideoSortField, -- cgit v1.2.3