diff options
Diffstat (limited to 'client/src/app/shared/misc')
-rw-r--r-- | client/src/app/shared/misc/button.component.scss | 27 | ||||
-rw-r--r-- | client/src/app/shared/misc/delete-button.component.html | 4 | ||||
-rw-r--r-- | client/src/app/shared/misc/delete-button.component.ts | 10 | ||||
-rw-r--r-- | client/src/app/shared/misc/edit-button.component.html | 4 | ||||
-rw-r--r-- | client/src/app/shared/misc/edit-button.component.ts | 11 | ||||
-rw-r--r-- | client/src/app/shared/misc/from-now.pipe.ts | 36 | ||||
-rw-r--r-- | client/src/app/shared/misc/number-formatter.pipe.ts | 19 | ||||
-rw-r--r-- | client/src/app/shared/misc/utils.ts | 23 |
8 files changed, 134 insertions, 0 deletions
diff --git a/client/src/app/shared/misc/button.component.scss b/client/src/app/shared/misc/button.component.scss new file mode 100644 index 000000000..5fcae4f10 --- /dev/null +++ b/client/src/app/shared/misc/button.component.scss | |||
@@ -0,0 +1,27 @@ | |||
1 | .action-button { | ||
2 | @include peertube-button-link; | ||
3 | |||
4 | font-size: 15px; | ||
5 | font-weight: $font-semibold; | ||
6 | color: #585858; | ||
7 | background-color: #E5E5E5; | ||
8 | |||
9 | &:hover { | ||
10 | background-color: #EFEFEF; | ||
11 | } | ||
12 | |||
13 | .icon { | ||
14 | @include icon(21px); | ||
15 | |||
16 | position: relative; | ||
17 | top: -2px; | ||
18 | |||
19 | &.icon-edit { | ||
20 | background-image: url('../../../assets/images/global/edit.svg'); | ||
21 | } | ||
22 | |||
23 | &.icon-delete-grey { | ||
24 | background-image: url('../../../assets/images/global/delete-grey.svg'); | ||
25 | } | ||
26 | } | ||
27 | } | ||
diff --git a/client/src/app/shared/misc/delete-button.component.html b/client/src/app/shared/misc/delete-button.component.html new file mode 100644 index 000000000..3db483882 --- /dev/null +++ b/client/src/app/shared/misc/delete-button.component.html | |||
@@ -0,0 +1,4 @@ | |||
1 | <span class="action-button action-button-delete" > | ||
2 | <span class="icon icon-delete-grey"></span> | ||
3 | Delete | ||
4 | </span> | ||
diff --git a/client/src/app/shared/misc/delete-button.component.ts b/client/src/app/shared/misc/delete-button.component.ts new file mode 100644 index 000000000..e04039f69 --- /dev/null +++ b/client/src/app/shared/misc/delete-button.component.ts | |||
@@ -0,0 +1,10 @@ | |||
1 | import { Component } from '@angular/core' | ||
2 | |||
3 | @Component({ | ||
4 | selector: 'my-delete-button', | ||
5 | styleUrls: [ './button.component.scss' ], | ||
6 | templateUrl: './delete-button.component.html' | ||
7 | }) | ||
8 | |||
9 | export class DeleteButtonComponent { | ||
10 | } | ||
diff --git a/client/src/app/shared/misc/edit-button.component.html b/client/src/app/shared/misc/edit-button.component.html new file mode 100644 index 000000000..6e9564bd7 --- /dev/null +++ b/client/src/app/shared/misc/edit-button.component.html | |||
@@ -0,0 +1,4 @@ | |||
1 | <a class="action-button" [routerLink]="routerLink"> | ||
2 | <span class="icon icon-edit"></span> | ||
3 | Edit | ||
4 | </a> | ||
diff --git a/client/src/app/shared/misc/edit-button.component.ts b/client/src/app/shared/misc/edit-button.component.ts new file mode 100644 index 000000000..201a618ec --- /dev/null +++ b/client/src/app/shared/misc/edit-button.component.ts | |||
@@ -0,0 +1,11 @@ | |||
1 | import { Component, Input } from '@angular/core' | ||
2 | |||
3 | @Component({ | ||
4 | selector: 'my-edit-button', | ||
5 | styleUrls: [ './button.component.scss' ], | ||
6 | templateUrl: './edit-button.component.html' | ||
7 | }) | ||
8 | |||
9 | export class EditButtonComponent { | ||
10 | @Input() routerLink = [] | ||
11 | } | ||
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..fac02af0b --- /dev/null +++ b/client/src/app/shared/misc/from-now.pipe.ts | |||
@@ -0,0 +1,36 @@ | |||
1 | import { Pipe, PipeTransform } from '@angular/core' | ||
2 | |||
3 | // Thanks: https://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site | ||
4 | @Pipe({ name: 'myFromNow' }) | ||
5 | export class FromNowPipe implements PipeTransform { | ||
6 | |||
7 | transform (value: number) { | ||
8 | const seconds = Math.floor((Date.now() - value) / 1000) | ||
9 | |||
10 | let interval = Math.floor(seconds / 31536000) | ||
11 | if (interval > 1) { | ||
12 | return interval + ' years ago' | ||
13 | } | ||
14 | |||
15 | interval = Math.floor(seconds / 2592000) | ||
16 | if (interval > 1) return interval + ' months ago' | ||
17 | if (interval === 1) return interval + ' month ago' | ||
18 | |||
19 | interval = Math.floor(seconds / 604800) | ||
20 | if (interval > 1) return interval + ' weeks ago' | ||
21 | if (interval === 1) return interval + ' week ago' | ||
22 | |||
23 | interval = Math.floor(seconds / 86400) | ||
24 | if (interval > 1) return interval + ' days ago' | ||
25 | if (interval === 1) return interval + ' day ago' | ||
26 | |||
27 | interval = Math.floor(seconds / 3600) | ||
28 | if (interval > 1) return interval + ' hours ago' | ||
29 | if (interval === 1) return interval + ' hour ago' | ||
30 | |||
31 | interval = Math.floor(seconds / 60) | ||
32 | if (interval >= 1) return interval + ' min ago' | ||
33 | |||
34 | return Math.floor(seconds) + ' sec ago' | ||
35 | } | ||
36 | } | ||
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..8a0756a36 --- /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: 'myNumberFormatter' }) | ||
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/misc/utils.ts b/client/src/app/shared/misc/utils.ts new file mode 100644 index 000000000..df9e0381a --- /dev/null +++ b/client/src/app/shared/misc/utils.ts | |||
@@ -0,0 +1,23 @@ | |||
1 | // Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript | ||
2 | |||
3 | function getParameterByName (name: string, url: string) { | ||
4 | if (!url) url = window.location.href | ||
5 | name = name.replace(/[\[\]]/g, '\\$&') | ||
6 | |||
7 | const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)') | ||
8 | const results = regex.exec(url) | ||
9 | |||
10 | if (!results) return null | ||
11 | if (!results[2]) return '' | ||
12 | |||
13 | return decodeURIComponent(results[2].replace(/\+/g, ' ')) | ||
14 | } | ||
15 | |||
16 | function viewportHeight () { | ||
17 | return Math.max(document.documentElement.clientHeight, window.innerHeight || 0) | ||
18 | } | ||
19 | |||
20 | export { | ||
21 | viewportHeight, | ||
22 | getParameterByName | ||
23 | } | ||