From c199c427d4ae586339822320f20f512a7a19dc3f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Oct 2018 14:35:31 +0200 Subject: Better typings --- .../app/shared/buttons/action-dropdown.component.ts | 6 +++--- client/src/app/shared/buttons/button.component.ts | 6 +++--- .../src/app/shared/buttons/edit-button.component.ts | 2 +- .../app/shared/guards/can-deactivate-guard.service.ts | 4 +++- client/src/app/shared/misc/help.component.ts | 2 +- client/src/app/shared/rest/rest-extractor.service.ts | 4 ++-- client/src/app/shared/rest/rest.service.ts | 2 +- client/src/app/shared/shared.module.ts | 6 +++--- client/src/app/shared/users/user.model.ts | 1 - client/src/app/shared/video/abstract-video-list.html | 2 +- client/src/app/shared/video/abstract-video-list.scss | 2 +- client/src/app/shared/video/abstract-video-list.ts | 11 +++++++---- client/src/app/shared/video/feed.component.html | 10 ++++++++++ client/src/app/shared/video/feed.component.scss | 19 +++++++++++++++++++ client/src/app/shared/video/feed.component.ts | 11 +++++++++++ client/src/app/shared/video/syndication.model.ts | 7 +++++++ client/src/app/shared/video/video-edit.model.ts | 5 ++--- client/src/app/shared/video/video-feed.component.html | 10 ---------- client/src/app/shared/video/video-feed.component.scss | 19 ------------------- client/src/app/shared/video/video-feed.component.ts | 10 ---------- client/src/app/shared/video/video.service.ts | 4 ++-- 21 files changed, 77 insertions(+), 66 deletions(-) create mode 100644 client/src/app/shared/video/feed.component.html create mode 100644 client/src/app/shared/video/feed.component.scss create mode 100644 client/src/app/shared/video/feed.component.ts create mode 100644 client/src/app/shared/video/syndication.model.ts delete mode 100644 client/src/app/shared/video/video-feed.component.html delete mode 100644 client/src/app/shared/video/video-feed.component.scss delete mode 100644 client/src/app/shared/video/video-feed.component.ts (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/buttons/action-dropdown.component.ts b/client/src/app/shared/buttons/action-dropdown.component.ts index 9877f639d..d8026ef41 100644 --- a/client/src/app/shared/buttons/action-dropdown.component.ts +++ b/client/src/app/shared/buttons/action-dropdown.component.ts @@ -2,9 +2,9 @@ import { Component, Input } from '@angular/core' export type DropdownAction = { label?: string - handler?: (T: any) => any - linkBuilder?: (T: any) => (string | number)[] - isDisplayed?: (T: any) => boolean + handler?: (a: T) => any + linkBuilder?: (a: T) => (string | number)[] + isDisplayed?: (a: T) => boolean } @Component({ diff --git a/client/src/app/shared/buttons/button.component.ts b/client/src/app/shared/buttons/button.component.ts index cccf98bc3..1a1162f09 100644 --- a/client/src/app/shared/buttons/button.component.ts +++ b/client/src/app/shared/buttons/button.component.ts @@ -8,9 +8,9 @@ import { Component, Input } from '@angular/core' export class ButtonComponent { @Input() label = '' - @Input() className: any = undefined - @Input() icon: any = undefined - @Input() title: any = undefined + @Input() className: string = undefined + @Input() icon: string = undefined + @Input() title: string = undefined getTitle () { return this.title || this.label diff --git a/client/src/app/shared/buttons/edit-button.component.ts b/client/src/app/shared/buttons/edit-button.component.ts index ea552663a..1fe4f7b30 100644 --- a/client/src/app/shared/buttons/edit-button.component.ts +++ b/client/src/app/shared/buttons/edit-button.component.ts @@ -8,5 +8,5 @@ import { Component, Input } from '@angular/core' export class EditButtonComponent { @Input() label: string - @Input() routerLink: any = [] + @Input() routerLink: string[] = [] } diff --git a/client/src/app/shared/guards/can-deactivate-guard.service.ts b/client/src/app/shared/guards/can-deactivate-guard.service.ts index e2a79e8c4..3a35fcfb3 100644 --- a/client/src/app/shared/guards/can-deactivate-guard.service.ts +++ b/client/src/app/shared/guards/can-deactivate-guard.service.ts @@ -4,8 +4,10 @@ import { Observable } from 'rxjs' import { ConfirmService } from '../../core/index' import { I18n } from '@ngx-translate/i18n-polyfill' +export type CanComponentDeactivateResult = { text?: string, canDeactivate: Observable | boolean } + export interface CanComponentDeactivate { - canDeactivate: () => { text?: string, canDeactivate: Observable | boolean } + canDeactivate: () => CanComponentDeactivateResult } @Injectable() diff --git a/client/src/app/shared/misc/help.component.ts b/client/src/app/shared/misc/help.component.ts index ccce1ccfa..ba0452e77 100644 --- a/client/src/app/shared/misc/help.component.ts +++ b/client/src/app/shared/misc/help.component.ts @@ -60,7 +60,7 @@ export class HelpComponent implements OnInit, OnChanges { } private createMarkdownList (rules: string[]) { - const rulesToText: any = { + const rulesToText = { 'emphasis': this.i18n('Emphasis'), 'link': this.i18n('Links'), 'newline': this.i18n('New lines'), diff --git a/client/src/app/shared/rest/rest-extractor.service.ts b/client/src/app/shared/rest/rest-extractor.service.ts index 934f6c618..f149569ef 100644 --- a/client/src/app/shared/rest/rest-extractor.service.ts +++ b/client/src/app/shared/rest/rest-extractor.service.ts @@ -33,7 +33,7 @@ export class RestExtractor { return this.applyToResultListData(result, this.convertDateToHuman, [ fieldsToConvert ]) } - convertDateToHuman (target: any, fieldsToConvert: string[]) { + convertDateToHuman (target: { [ id: string ]: string }, fieldsToConvert: string[]) { fieldsToConvert.forEach(field => target[field] = dateToHuman(target[field])) return target @@ -83,7 +83,7 @@ export class RestExtractor { errorMessage = err } - const errorObj: any = { + const errorObj: { message: string, status: string, body: string } = { message: errorMessage, status: undefined, body: undefined diff --git a/client/src/app/shared/rest/rest.service.ts b/client/src/app/shared/rest/rest.service.ts index 41824a18f..e6d4e6e5e 100644 --- a/client/src/app/shared/rest/rest.service.ts +++ b/client/src/app/shared/rest/rest.service.ts @@ -32,7 +32,7 @@ export class RestService { return newParams } - addObjectParams (params: HttpParams, object: any) { + addObjectParams (params: HttpParams, object: { [ name: string ]: any }) { for (const name of Object.keys(object)) { const value = object[name] if (!value) continue diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts index 40e05fcc7..0ec2a9b15 100644 --- a/client/src/app/shared/shared.module.ts +++ b/client/src/app/shared/shared.module.ts @@ -25,7 +25,7 @@ import { VideoAbuseService } from './video-abuse' import { VideoBlacklistService } from './video-blacklist' import { VideoOwnershipService } from './video-ownership' import { VideoMiniatureComponent } from './video/video-miniature.component' -import { VideoFeedComponent } from './video/video-feed.component' +import { FeedComponent } from './video/feed.component' import { VideoThumbnailComponent } from './video/video-thumbnail.component' import { VideoService } from './video/video.service' import { AccountService } from '@app/shared/account/account.service' @@ -82,7 +82,7 @@ import { BlocklistService } from '@app/shared/blocklist' LoaderComponent, VideoThumbnailComponent, VideoMiniatureComponent, - VideoFeedComponent, + FeedComponent, ButtonComponent, DeleteButtonComponent, EditButtonComponent, @@ -122,7 +122,7 @@ import { BlocklistService } from '@app/shared/blocklist' LoaderComponent, VideoThumbnailComponent, VideoMiniatureComponent, - VideoFeedComponent, + FeedComponent, ButtonComponent, DeleteButtonComponent, EditButtonComponent, diff --git a/client/src/app/shared/users/user.model.ts b/client/src/app/shared/users/user.model.ts index e6b612054..7c840ffa7 100644 --- a/client/src/app/shared/users/user.model.ts +++ b/client/src/app/shared/users/user.model.ts @@ -43,7 +43,6 @@ export class User implements UserServerModel { blocked: boolean blockedReason?: string - [key: string]: any constructor (hash: UserConstructorHash) { this.id = hash.id diff --git a/client/src/app/shared/video/abstract-video-list.html b/client/src/app/shared/video/abstract-video-list.html index 69a619b76..29492351b 100644 --- a/client/src/app/shared/video/abstract-video-list.html +++ b/client/src/app/shared/video/abstract-video-list.html @@ -3,7 +3,7 @@
{{ titlePage }}
- +
- abstract generateSyndicationList (): any + abstract generateSyndicationList (): void get user () { return this.authService.getUser() @@ -209,9 +210,11 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { } protected setNewRouteParams () { - const paramsObject: any = this.buildRouteParams() + const paramsObject = this.buildRouteParams() - const queryParams = Object.keys(paramsObject).map(p => p + '=' + paramsObject[p]).join('&') + const queryParams = Object.keys(paramsObject) + .map(p => p + '=' + paramsObject[p]) + .join('&') this.location.replaceState(this.currentRoute, queryParams) } diff --git a/client/src/app/shared/video/feed.component.html b/client/src/app/shared/video/feed.component.html new file mode 100644 index 000000000..16116ba88 --- /dev/null +++ b/client/src/app/shared/video/feed.component.html @@ -0,0 +1,10 @@ +
+ + + + {{ item.label }} + +
\ No newline at end of file diff --git a/client/src/app/shared/video/feed.component.scss b/client/src/app/shared/video/feed.component.scss new file mode 100644 index 000000000..385764be0 --- /dev/null +++ b/client/src/app/shared/video/feed.component.scss @@ -0,0 +1,19 @@ +@import '_mixins'; + +.video-feed { + a { + color: black; + display: block; + } + + .icon { + @include icon(12px); + + &.icon-syndication { + position: relative; + top: -2px; + background-color: var(--mainForegroundColor); + mask-image: url('../../../assets/images/global/syndication.svg'); + } + } +} \ No newline at end of file diff --git a/client/src/app/shared/video/feed.component.ts b/client/src/app/shared/video/feed.component.ts new file mode 100644 index 000000000..12507458f --- /dev/null +++ b/client/src/app/shared/video/feed.component.ts @@ -0,0 +1,11 @@ +import { Component, Input } from '@angular/core' +import { Syndication } from '@app/shared/video/syndication.model' + +@Component({ + selector: 'my-feed', + styleUrls: [ './feed.component.scss' ], + templateUrl: './feed.component.html' +}) +export class FeedComponent { + @Input() syndicationItems: Syndication[] +} diff --git a/client/src/app/shared/video/syndication.model.ts b/client/src/app/shared/video/syndication.model.ts new file mode 100644 index 000000000..a52b5771b --- /dev/null +++ b/client/src/app/shared/video/syndication.model.ts @@ -0,0 +1,7 @@ +import { FeedFormat } from '../../../../../shared/models/feeds/feed-format.enum' + +export interface Syndication { + format: FeedFormat, + label: string, + url: string +} \ No newline at end of file diff --git a/client/src/app/shared/video/video-edit.model.ts b/client/src/app/shared/video/video-edit.model.ts index a62277e04..fc772a3cf 100644 --- a/client/src/app/shared/video/video-edit.model.ts +++ b/client/src/app/shared/video/video-edit.model.ts @@ -25,7 +25,6 @@ export class VideoEdit implements VideoUpdate { uuid?: string id?: number scheduleUpdate?: VideoScheduleUpdate - [key: string]: any constructor (video?: Video & { tags: string[], commentsEnabled: boolean, support: string, thumbnailUrl: string, previewUrl: string }) { if (video) { @@ -50,14 +49,14 @@ export class VideoEdit implements VideoUpdate { } } - patch (values: any) { + patch (values: { [ id: string ]: string }) { Object.keys(values).forEach((key) => { this[ key ] = values[ key ] }) // If schedule publication, the video is private and will be changed to public privacy if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) { - const updateAt = (values['schedulePublicationAt'] as Date) + const updateAt = new Date(values['schedulePublicationAt']) updateAt.setSeconds(0) this.privacy = VideoPrivacy.PRIVATE diff --git a/client/src/app/shared/video/video-feed.component.html b/client/src/app/shared/video/video-feed.component.html deleted file mode 100644 index 16116ba88..000000000 --- a/client/src/app/shared/video/video-feed.component.html +++ /dev/null @@ -1,10 +0,0 @@ -
- - - - {{ item.label }} - -
\ No newline at end of file diff --git a/client/src/app/shared/video/video-feed.component.scss b/client/src/app/shared/video/video-feed.component.scss deleted file mode 100644 index 385764be0..000000000 --- a/client/src/app/shared/video/video-feed.component.scss +++ /dev/null @@ -1,19 +0,0 @@ -@import '_mixins'; - -.video-feed { - a { - color: black; - display: block; - } - - .icon { - @include icon(12px); - - &.icon-syndication { - position: relative; - top: -2px; - background-color: var(--mainForegroundColor); - mask-image: url('../../../assets/images/global/syndication.svg'); - } - } -} \ No newline at end of file diff --git a/client/src/app/shared/video/video-feed.component.ts b/client/src/app/shared/video/video-feed.component.ts deleted file mode 100644 index be6c80c3f..000000000 --- a/client/src/app/shared/video/video-feed.component.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Component, Input } from '@angular/core' - -@Component({ - selector: 'my-video-feed', - styleUrls: [ './video-feed.component.scss' ], - templateUrl: './video-feed.component.html' -}) -export class VideoFeedComponent { - @Input() syndicationItems: any -} diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index 6283cf84d..65297d7a1 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts @@ -274,9 +274,9 @@ export class VideoService implements VideosProvider { loadCompleteDescription (descriptionPath: string) { return this.authHttp - .get(environment.apiUrl + descriptionPath) + .get<{ description: string }>(environment.apiUrl + descriptionPath) .pipe( - map((res: any) => res[ 'description' ]), + map(res => res.description), catchError(err => this.restExtractor.handleError(err)) ) } -- cgit v1.2.3