From 80bfd33c0bf910e2cfdd3270b14ba9eddd90e2e8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 18 Dec 2018 09:31:09 +0100 Subject: Add history page on client --- .../shared/menu/top-menu-dropdown.component.html | 5 ++- .../shared/menu/top-menu-dropdown.component.scss | 4 ++ .../app/shared/menu/top-menu-dropdown.component.ts | 14 +++++-- client/src/app/shared/shared.module.ts | 2 + .../src/app/shared/users/user-history.service.ts | 45 ++++++++++++++++++++++ 5 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 client/src/app/shared/users/user-history.service.ts (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/menu/top-menu-dropdown.component.html b/client/src/app/shared/menu/top-menu-dropdown.component.html index 2d6d1c4bf..d3c896019 100644 --- a/client/src/app/shared/menu/top-menu-dropdown.component.html +++ b/client/src/app/shared/menu/top-menu-dropdown.component.html @@ -4,7 +4,10 @@ {{ menuEntry.label }}
- + {{ menuEntry.label }} - {{ suffixLabels[menuEntry.label] }} diff --git a/client/src/app/shared/menu/top-menu-dropdown.component.scss b/client/src/app/shared/menu/top-menu-dropdown.component.scss index f3ef8f814..77159532f 100644 --- a/client/src/app/shared/menu/top-menu-dropdown.component.scss +++ b/client/src/app/shared/menu/top-menu-dropdown.component.scss @@ -12,3 +12,7 @@ position: relative; top: 2px; } + +/deep/ .dropdown-menu { + margin-top: 0 !important; +} diff --git a/client/src/app/shared/menu/top-menu-dropdown.component.ts b/client/src/app/shared/menu/top-menu-dropdown.component.ts index 272b721b2..e859c30dd 100644 --- a/client/src/app/shared/menu/top-menu-dropdown.component.ts +++ b/client/src/app/shared/menu/top-menu-dropdown.component.ts @@ -1,9 +1,8 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core' import { filter, take } from 'rxjs/operators' -import { NavigationStart, Router } from '@angular/router' +import { NavigationEnd, Router } from '@angular/router' import { Subscription } from 'rxjs' import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' -import { drop } from 'lodash-es' export type TopMenuDropdownParam = { label: string @@ -34,7 +33,7 @@ export class TopMenuDropdownComponent implements OnInit, OnDestroy { this.updateChildLabels(window.location.pathname) this.routeSub = this.router.events - .pipe(filter(event => event instanceof NavigationStart)) + .pipe(filter(event => event instanceof NavigationEnd)) .subscribe(() => this.updateChildLabels(window.location.pathname)) } @@ -52,6 +51,15 @@ export class TopMenuDropdownComponent implements OnInit, OnDestroy { .subscribe(e => this.openedOnHover = false) } + dropdownAnchorClicked (dropdown: NgbDropdown) { + if (this.openedOnHover) { + this.openedOnHover = false + return + } + + return dropdown.toggle() + } + closeDropdownIfHovered (dropdown: NgbDropdown) { if (this.openedOnHover === false) return diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts index 9810e9485..4a5d664db 100644 --- a/client/src/app/shared/shared.module.ts +++ b/client/src/app/shared/shared.module.ts @@ -62,6 +62,7 @@ import { UserBanModalComponent } from '@app/shared/moderation' import { UserModerationDropdownComponent } from '@app/shared/moderation/user-moderation-dropdown.component' import { BlocklistService } from '@app/shared/blocklist' import { TopMenuDropdownComponent } from '@app/shared/menu/top-menu-dropdown.component' +import { UserHistoryService } from '@app/shared/users/user-history.service' @NgModule({ imports: [ @@ -181,6 +182,7 @@ import { TopMenuDropdownComponent } from '@app/shared/menu/top-menu-dropdown.com VideoChangeOwnershipValidatorsService, VideoAcceptOwnershipValidatorsService, BlocklistService, + UserHistoryService, I18nPrimengCalendarService, ScreenService, diff --git a/client/src/app/shared/users/user-history.service.ts b/client/src/app/shared/users/user-history.service.ts new file mode 100644 index 000000000..9ed25bfc7 --- /dev/null +++ b/client/src/app/shared/users/user-history.service.ts @@ -0,0 +1,45 @@ +import { HttpClient, HttpParams } from '@angular/common/http' +import { Injectable } from '@angular/core' +import { environment } from '../../../environments/environment' +import { RestExtractor } from '../rest/rest-extractor.service' +import { RestService } from '../rest/rest.service' +import { Video } from '../video/video.model' +import { catchError, map, switchMap } from 'rxjs/operators' +import { ComponentPagination } from '@app/shared/rest/component-pagination.model' +import { VideoService } from '@app/shared/video/video.service' +import { ResultList } from '../../../../../shared' + +@Injectable() +export class UserHistoryService { + static BASE_USER_VIDEOS_HISTORY_URL = environment.apiUrl + '/api/v1/users/me/history/videos' + + constructor ( + private authHttp: HttpClient, + private restExtractor: RestExtractor, + private restService: RestService, + private videoService: VideoService + ) {} + + getUserVideosHistory (historyPagination: ComponentPagination) { + const pagination = this.restService.componentPaginationToRestPagination(historyPagination) + + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination) + + return this.authHttp + .get>(UserHistoryService.BASE_USER_VIDEOS_HISTORY_URL, { params }) + .pipe( + switchMap(res => this.videoService.extractVideos(res)), + catchError(err => this.restExtractor.handleError(err)) + ) + } + + deleteUserVideosHistory () { + return this.authHttp + .post(UserHistoryService.BASE_USER_VIDEOS_HISTORY_URL + '/remove', {}) + .pipe( + map(() => this.restExtractor.extractDataBool()), + catchError(err => this.restExtractor.handleError(err)) + ) + } +} -- cgit v1.2.3