aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-12-01 14:46:22 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-12-01 14:46:22 +0100
commit9bf9d2a5c223bf006496ae7adf0c0bd7a7975108 (patch)
tree7e72814af43176ad96841046a9310af001d23a14 /client/src/app/shared
parent26c6ee80d0fecfce595e8970f15717560b4f4ceb (diff)
downloadPeerTube-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.ts37
-rw-r--r--client/src/app/shared/misc/number-formatter.pipe.ts19
-rw-r--r--client/src/app/shared/shared.module.ts26
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 @@
1import { 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'})
6export 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 @@
1import { 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'})
6export 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 @@
1import { NgModule } from '@angular/core'
2import { HttpClientModule } from '@angular/common/http'
3import { CommonModule } from '@angular/common' 1import { CommonModule } from '@angular/common'
2import { HttpClientModule } from '@angular/common/http'
3import { NgModule } from '@angular/core'
4import { FormsModule, ReactiveFormsModule } from '@angular/forms' 4import { FormsModule, ReactiveFormsModule } from '@angular/forms'
5import { RouterModule } from '@angular/router' 5import { RouterModule } from '@angular/router'
6 6
7import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'
8import { KeysPipe } from 'angular-pipes/src/object/keys.pipe'
9import { BsDropdownModule } from 'ngx-bootstrap/dropdown' 7import { BsDropdownModule } from 'ngx-bootstrap/dropdown'
10import { ProgressbarModule } from 'ngx-bootstrap/progressbar'
11import { PaginationModule } from 'ngx-bootstrap/pagination'
12import { ModalModule } from 'ngx-bootstrap/modal' 8import { ModalModule } from 'ngx-bootstrap/modal'
13import { DataTableModule } from 'primeng/components/datatable/datatable' 9import { PaginationModule } from 'ngx-bootstrap/pagination'
10import { ProgressbarModule } from 'ngx-bootstrap/progressbar'
11import { BytesPipe, KeysPipe } from 'ngx-pipes'
14import { SharedModule as PrimeSharedModule } from 'primeng/components/common/shared' 12import { SharedModule as PrimeSharedModule } from 'primeng/components/common/shared'
13import { DataTableModule } from 'primeng/components/datatable/datatable'
15 14
16import { AUTH_INTERCEPTOR_PROVIDER } from './auth' 15import { AUTH_INTERCEPTOR_PROVIDER } from './auth'
16import { LoaderComponent } from './misc/loader.component'
17import { RestExtractor, RestService } from './rest' 17import { RestExtractor, RestService } from './rest'
18import { SearchComponent, SearchService } from './search' 18import { SearchComponent, SearchService } from './search'
19import { UserService } from './users' 19import { UserService } from './users'
20import { VideoAbuseService } from './video-abuse' 20import { VideoAbuseService } from './video-abuse'
21import { VideoBlacklistService } from './video-blacklist' 21import { VideoBlacklistService } from './video-blacklist'
22import { LoaderComponent } from './misc/loader.component' 22import { NumberFormatterPipe } from './misc/number-formatter.pipe'
23import { 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: [