fa1da26bfccdb93e1ede0845250726bf49afdc14
[oweals/peertube.git] / client / src / app / +admin / follows / shared / redundancy-checkbox.component.ts
1 import { Component, Input } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
4 import { RedundancyService } from '@app/+admin/follows/shared/redundancy.service'
5
6 @Component({
7   selector: 'my-redundancy-checkbox',
8   templateUrl: './redundancy-checkbox.component.html',
9   styleUrls: [ './redundancy-checkbox.component.scss' ]
10 })
11 export class RedundancyCheckboxComponent {
12   @Input() redundancyAllowed: boolean
13   @Input() host: string
14
15   constructor (
16     private notifier: Notifier,
17     private redundancyService: RedundancyService,
18     private i18n: I18n
19   ) { }
20
21   updateRedundancyState () {
22     this.redundancyService.updateRedundancy(this.host, this.redundancyAllowed)
23         .subscribe(
24           () => {
25             const stateLabel = this.redundancyAllowed ? this.i18n('enabled') : this.i18n('disabled')
26
27             this.notifier.success(this.i18n('Redundancy for {{host}} is {{stateLabel}}', { host: this.host, stateLabel }))
28           },
29
30           err => this.notifier.error(err.message)
31         )
32   }
33 }