mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 18:29:27 +02:00
Reorganize client shared modules
This commit is contained in:
parent
0c4bacbff5
commit
67ed6552b8
510 changed files with 2321 additions and 2251 deletions
|
@ -0,0 +1,73 @@
|
|||
import { AfterContentInit, ChangeDetectorRef, Component, ContentChildren, forwardRef, Input, QueryList, TemplateRef } from '@angular/core'
|
||||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
|
||||
import { PeerTubeTemplateDirective } from '@app/shared/shared-main'
|
||||
|
||||
@Component({
|
||||
selector: 'my-peertube-checkbox',
|
||||
styleUrls: [ './peertube-checkbox.component.scss' ],
|
||||
templateUrl: './peertube-checkbox.component.html',
|
||||
providers: [
|
||||
{
|
||||
provide: NG_VALUE_ACCESSOR,
|
||||
useExisting: forwardRef(() => PeertubeCheckboxComponent),
|
||||
multi: true
|
||||
}
|
||||
]
|
||||
})
|
||||
export class PeertubeCheckboxComponent implements ControlValueAccessor, AfterContentInit {
|
||||
@Input() checked = false
|
||||
@Input() inputName: string
|
||||
@Input() labelText: string
|
||||
@Input() labelInnerHTML: string
|
||||
@Input() helpPlacement = 'top auto'
|
||||
@Input() disabled = false
|
||||
@Input() recommended = false
|
||||
|
||||
@ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective<'label' | 'help'>>
|
||||
|
||||
// FIXME: https://github.com/angular/angular/issues/10816#issuecomment-307567836
|
||||
@Input() onPushWorkaround = false
|
||||
|
||||
labelTemplate: TemplateRef<any>
|
||||
helpTemplate: TemplateRef<any>
|
||||
|
||||
constructor (private cdr: ChangeDetectorRef) { }
|
||||
|
||||
ngAfterContentInit () {
|
||||
{
|
||||
const t = this.templates.find(t => t.name === 'label')
|
||||
if (t) this.labelTemplate = t.template
|
||||
}
|
||||
|
||||
{
|
||||
const t = this.templates.find(t => t.name === 'help')
|
||||
if (t) this.helpTemplate = t.template
|
||||
}
|
||||
}
|
||||
|
||||
propagateChange = (_: any) => { /* empty */ }
|
||||
|
||||
writeValue (checked: boolean) {
|
||||
this.checked = checked
|
||||
|
||||
if (this.onPushWorkaround) {
|
||||
this.cdr.markForCheck()
|
||||
}
|
||||
}
|
||||
|
||||
registerOnChange (fn: (_: any) => void) {
|
||||
this.propagateChange = fn
|
||||
}
|
||||
|
||||
registerOnTouched () {
|
||||
// Unused
|
||||
}
|
||||
|
||||
onModelChange () {
|
||||
this.propagateChange(this.checked)
|
||||
}
|
||||
|
||||
setDisabledState (isDisabled: boolean) {
|
||||
this.disabled = isDisabled
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue