diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-12-01 14:46:22 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-12-01 14:46:22 +0100 |
commit | 9bf9d2a5c223bf006496ae7adf0c0bd7a7975108 (patch) | |
tree | 7e72814af43176ad96841046a9310af001d23a14 /client/src/app/shared | |
parent | 26c6ee80d0fecfce595e8970f15717560b4f4ceb (diff) | |
download | PeerTube-9bf9d2a5c223bf006496ae7adf0c0bd7a7975108.tar.gz PeerTube-9bf9d2a5c223bf006496ae7adf0c0bd7a7975108.tar.zst PeerTube-9bf9d2a5c223bf006496ae7adf0c0bd7a7975108.zip |
Begin videos list new design
Diffstat (limited to 'client/src/app/shared')
-rw-r--r-- | client/src/app/shared/misc/from-now.pipe.ts | 37 | ||||
-rw-r--r-- | client/src/app/shared/misc/number-formatter.pipe.ts | 19 | ||||
-rw-r--r-- | client/src/app/shared/shared.module.ts | 26 |
3 files changed, 72 insertions, 10 deletions
diff --git a/client/src/app/shared/misc/from-now.pipe.ts b/client/src/app/shared/misc/from-now.pipe.ts new file mode 100644 index 000000000..25e5d6a85 --- /dev/null +++ b/client/src/app/shared/misc/from-now.pipe.ts | |||
@@ -0,0 +1,37 @@ | |||
1 | import { Pipe, PipeTransform } from '@angular/core' | ||
2 | |||
3 | // Thanks: https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts | ||
4 | |||
5 | @Pipe({name: 'fromNow'}) | ||
6 | export class FromNowPipe implements PipeTransform { | ||
7 | |||
8 | transform (value: number) { | ||
9 | const seconds = Math.floor((Date.now() - value) / 1000) | ||
10 | |||
11 | let interval = Math.floor(seconds / 31536000) | ||
12 | if (interval > 1) { | ||
13 | return interval + ' years ago' | ||
14 | } | ||
15 | |||
16 | interval = Math.floor(seconds / 2592000) | ||
17 | if (interval > 1) return interval + ' months ago' | ||
18 | if (interval === 1) return interval + ' month ago' | ||
19 | |||
20 | interval = Math.floor(seconds / 604800) | ||
21 | if (interval > 1) return interval + ' weeks ago' | ||
22 | if (interval === 1) return interval + ' week ago' | ||
23 | |||
24 | interval = Math.floor(seconds / 86400) | ||
25 | if (interval > 1) return interval + ' days ago' | ||
26 | if (interval === 1) return interval + ' day ago' | ||
27 | |||
28 | interval = Math.floor(seconds / 3600) | ||
29 | if (interval > 1) return interval + ' hours ago' | ||
30 | if (interval === 1) return interval + ' hour ago' | ||
31 | |||
32 | interval = Math.floor(seconds / 60) | ||
33 | if (interval >= 1) return interval + ' min ago' | ||
34 | |||
35 | return Math.floor(seconds) + ' sec ago' | ||
36 | } | ||
37 | } | ||
diff --git a/client/src/app/shared/misc/number-formatter.pipe.ts b/client/src/app/shared/misc/number-formatter.pipe.ts new file mode 100644 index 000000000..2491fb1d6 --- /dev/null +++ b/client/src/app/shared/misc/number-formatter.pipe.ts | |||
@@ -0,0 +1,19 @@ | |||
1 | import { Pipe, PipeTransform } from '@angular/core' | ||
2 | |||
3 | // Thanks: https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts | ||
4 | |||
5 | @Pipe({name: 'numberFormatter'}) | ||
6 | export class NumberFormatterPipe implements PipeTransform { | ||
7 | private dictionary: Array<{max: number, type: string}> = [ | ||
8 | { max: 1000, type: '' }, | ||
9 | { max: 1000000, type: 'K' }, | ||
10 | { max: 1000000000, type: 'M' } | ||
11 | ] | ||
12 | |||
13 | transform (value: number) { | ||
14 | const format = this.dictionary.find(d => value < d.max) || this.dictionary[this.dictionary.length - 1] | ||
15 | const calc = Math.floor(value / (format.max / 1000)) | ||
16 | |||
17 | return `${calc}${format.type}` | ||
18 | } | ||
19 | } | ||
diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts index 456ce851e..c7ea6e603 100644 --- a/client/src/app/shared/shared.module.ts +++ b/client/src/app/shared/shared.module.ts | |||
@@ -1,25 +1,26 @@ | |||
1 | import { NgModule } from '@angular/core' | ||
2 | import { HttpClientModule } from '@angular/common/http' | ||
3 | import { CommonModule } from '@angular/common' | 1 | import { CommonModule } from '@angular/common' |
2 | import { HttpClientModule } from '@angular/common/http' | ||
3 | import { NgModule } from '@angular/core' | ||
4 | import { FormsModule, ReactiveFormsModule } from '@angular/forms' | 4 | import { FormsModule, ReactiveFormsModule } from '@angular/forms' |
5 | import { RouterModule } from '@angular/router' | 5 | import { RouterModule } from '@angular/router' |
6 | 6 | ||
7 | import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe' | ||
8 | import { KeysPipe } from 'angular-pipes/src/object/keys.pipe' | ||
9 | import { BsDropdownModule } from 'ngx-bootstrap/dropdown' | 7 | import { BsDropdownModule } from 'ngx-bootstrap/dropdown' |
10 | import { ProgressbarModule } from 'ngx-bootstrap/progressbar' | ||
11 | import { PaginationModule } from 'ngx-bootstrap/pagination' | ||
12 | import { ModalModule } from 'ngx-bootstrap/modal' | 8 | import { ModalModule } from 'ngx-bootstrap/modal' |
13 | import { DataTableModule } from 'primeng/components/datatable/datatable' | 9 | import { PaginationModule } from 'ngx-bootstrap/pagination' |
10 | import { ProgressbarModule } from 'ngx-bootstrap/progressbar' | ||
11 | import { BytesPipe, KeysPipe } from 'ngx-pipes' | ||
14 | import { SharedModule as PrimeSharedModule } from 'primeng/components/common/shared' | 12 | import { SharedModule as PrimeSharedModule } from 'primeng/components/common/shared' |
13 | import { DataTableModule } from 'primeng/components/datatable/datatable' | ||
15 | 14 | ||
16 | import { AUTH_INTERCEPTOR_PROVIDER } from './auth' | 15 | import { AUTH_INTERCEPTOR_PROVIDER } from './auth' |
16 | import { LoaderComponent } from './misc/loader.component' | ||
17 | import { RestExtractor, RestService } from './rest' | 17 | import { RestExtractor, RestService } from './rest' |
18 | import { SearchComponent, SearchService } from './search' | 18 | import { SearchComponent, SearchService } from './search' |
19 | import { UserService } from './users' | 19 | import { UserService } from './users' |
20 | import { VideoAbuseService } from './video-abuse' | 20 | import { VideoAbuseService } from './video-abuse' |
21 | import { VideoBlacklistService } from './video-blacklist' | 21 | import { VideoBlacklistService } from './video-blacklist' |
22 | import { LoaderComponent } from './misc/loader.component' | 22 | import { NumberFormatterPipe } from './misc/number-formatter.pipe' |
23 | import { FromNowPipe } from './misc/from-now.pipe' | ||
23 | 24 | ||
24 | @NgModule({ | 25 | @NgModule({ |
25 | imports: [ | 26 | imports: [ |
@@ -42,7 +43,9 @@ import { LoaderComponent } from './misc/loader.component' | |||
42 | BytesPipe, | 43 | BytesPipe, |
43 | KeysPipe, | 44 | KeysPipe, |
44 | SearchComponent, | 45 | SearchComponent, |
45 | LoaderComponent | 46 | LoaderComponent, |
47 | NumberFormatterPipe, | ||
48 | FromNowPipe | ||
46 | ], | 49 | ], |
47 | 50 | ||
48 | exports: [ | 51 | exports: [ |
@@ -62,7 +65,10 @@ import { LoaderComponent } from './misc/loader.component' | |||
62 | KeysPipe, | 65 | KeysPipe, |
63 | 66 | ||
64 | SearchComponent, | 67 | SearchComponent, |
65 | LoaderComponent | 68 | LoaderComponent, |
69 | |||
70 | NumberFormatterPipe, | ||
71 | FromNowPipe | ||
66 | ], | 72 | ], |
67 | 73 | ||
68 | providers: [ | 74 | providers: [ |