]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/buttons/action-dropdown.component.ts
Correctly delete live files from object storage
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / buttons / action-dropdown.component.ts
CommitLineData
eacb25c4 1import { Component, Input } from '@angular/core'
8bd4a1ed 2import { Params } from '@angular/router'
67ed6552 3import { GlobalIconName } from '@app/shared/shared-icons'
eacb25c4
C
4
5export type DropdownAction<T> = {
eacb25c4 6 label?: string
3a0fb65c 7 iconName?: GlobalIconName
9b82d49d
RK
8 description?: string
9 title?: string
c199c427 10 handler?: (a: T) => any
8bd4a1ed 11
c199c427 12 linkBuilder?: (a: T) => (string | number)[]
8bd4a1ed
C
13 queryParamsBuilder?: (a: T) => Params
14
c199c427 15 isDisplayed?: (a: T) => boolean
a2c3564a
C
16
17 class?: string[]
bb152476 18 isHeader?: boolean
eacb25c4
C
19}
20
3a0fb65c
C
21export type DropdownButtonSize = 'normal' | 'small'
22export type DropdownTheme = 'orange' | 'grey'
23export type DropdownDirection = 'horizontal' | 'vertical'
24
eacb25c4
C
25@Component({
26 selector: 'my-action-dropdown',
27 styleUrls: [ './action-dropdown.component.scss' ],
28 templateUrl: './action-dropdown.component.html'
29})
30
31export class ActionDropdownComponent<T> {
f97c91f7 32 @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = []
eacb25c4 33 @Input() entry: T
3a0fb65c 34
3921166d 35 @Input() placement = 'bottom-left auto'
9b4241e3 36 @Input() container: null | 'body'
3a0fb65c
C
37
38 @Input() buttonSize: DropdownButtonSize = 'normal'
39 @Input() buttonDirection: DropdownDirection = 'horizontal'
40 @Input() buttonStyled = true
41
791645e6 42 @Input() label: string
3a0fb65c 43 @Input() theme: DropdownTheme = 'grey'
f97c91f7 44
be27ef3b
C
45 getActions (): DropdownAction<T>[][] {
46 if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions as DropdownAction<T>[][]
f97c91f7 47
be27ef3b 48 return [ this.actions as DropdownAction<T>[] ]
f97c91f7 49 }
3a0fb65c 50
d50e8d1a
C
51 getQueryParams (action: DropdownAction<T>, entry: T) {
52 if (action.queryParamsBuilder) return action.queryParamsBuilder(entry)
53
54 return {}
55 }
56
3d216ea0
C
57 areActionsDisplayed (actions: Array<DropdownAction<T> | DropdownAction<T>[]>, entry: T): boolean {
58 return actions.some(a => {
59 if (Array.isArray(a)) return this.areActionsDisplayed(a, entry)
60
5b0ec7cd 61 return a.isHeader !== true && (a.isDisplayed === undefined || a.isDisplayed(entry))
3d216ea0 62 })
3a0fb65c 63 }
eacb25c4 64}