aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/config
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-04-14 10:55:34 +0200
committerRigel Kent <par@rigelk.eu>2020-04-14 15:53:37 +0200
commitbb152476c819e4c7487d080433c616f0d523e049 (patch)
tree955b6afa140b6e83eced3cb21c8ec1d62fa6a15e /client/src/app/+admin/config
parent1055eb3a7b89bc50dc611ab933f9dbd603488747 (diff)
downloadPeerTube-bb152476c819e4c7487d080433c616f0d523e049.tar.gz
PeerTube-bb152476c819e4c7487d080433c616f0d523e049.tar.zst
PeerTube-bb152476c819e4c7487d080433c616f0d523e049.zip
Refactor follow/mute as modals in admin, add actions in abuse list
Diffstat (limited to 'client/src/app/+admin/config')
-rw-r--r--client/src/app/+admin/config/shared/batch-domains-modal.component.html43
-rw-r--r--client/src/app/+admin/config/shared/batch-domains-modal.component.scss3
-rw-r--r--client/src/app/+admin/config/shared/batch-domains-modal.component.ts54
-rw-r--r--client/src/app/+admin/config/shared/batch-domains-validators.service.ts68
4 files changed, 168 insertions, 0 deletions
diff --git a/client/src/app/+admin/config/shared/batch-domains-modal.component.html b/client/src/app/+admin/config/shared/batch-domains-modal.component.html
new file mode 100644
index 000000000..1b85c8f48
--- /dev/null
+++ b/client/src/app/+admin/config/shared/batch-domains-modal.component.html
@@ -0,0 +1,43 @@
1<ng-template #modal>
2 <div class="modal-header">
3 <h4 i18n class="modal-title">{{ action }}</h4>
4
5 <my-global-icon iconName="cross" aria-label="Close" role="button" (click)="hide()"></my-global-icon>
6 </div>
7
8 <div class="modal-body">
9 <form novalidate [formGroup]="form" (ngSubmit)="submit()">
10 <div class="form-group">
11 <label i18n for="hosts">1 host (without "http://") per line</label>
12
13 <textarea
14 [placeholder]="placeholder" formControlName="domains" type="text" id="hosts" name="hosts"
15 class="form-control" [ngClass]="{ 'input-error': formErrors['domains'] }" ngbAutofocus
16 ></textarea>
17
18 <div *ngIf="formErrors.domains" class="form-error">
19 {{ formErrors.domains }}
20
21 <div *ngIf="form.controls['domains'].errors.validDomains">
22 {{ form.controls['domains'].errors.validDomains.value }}
23 </div>
24 </div>
25 </div>
26
27 <ng-content select="warning"></ng-content>
28
29 <div class="form-group inputs">
30 <input
31 type="button" role="button" i18n-value value="Cancel" class="action-button action-button-cancel"
32 (click)="hide()" (key.enter)="hide()"
33 >
34
35 <input
36 type="submit" [value]="action" class="action-button-submit"
37 [disabled]="!form.valid"
38 >
39 </div>
40 </form>
41 </div>
42
43</ng-template>
diff --git a/client/src/app/+admin/config/shared/batch-domains-modal.component.scss b/client/src/app/+admin/config/shared/batch-domains-modal.component.scss
new file mode 100644
index 000000000..9621a566f
--- /dev/null
+++ b/client/src/app/+admin/config/shared/batch-domains-modal.component.scss
@@ -0,0 +1,3 @@
1textarea {
2 height: 200px;
3}
diff --git a/client/src/app/+admin/config/shared/batch-domains-modal.component.ts b/client/src/app/+admin/config/shared/batch-domains-modal.component.ts
new file mode 100644
index 000000000..620f2726b
--- /dev/null
+++ b/client/src/app/+admin/config/shared/batch-domains-modal.component.ts
@@ -0,0 +1,54 @@
1import { Component, OnInit, ViewChild, Input, Output, EventEmitter } from '@angular/core'
2import { I18n } from '@ngx-translate/i18n-polyfill'
3import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
4import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
5import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
6import { FormReactive } from '@app/shared/forms'
7import { BatchDomainsValidatorsService } from './batch-domains-validators.service'
8
9@Component({
10 selector: 'my-batch-domains-modal',
11 templateUrl: './batch-domains-modal.component.html',
12 styleUrls: [ './batch-domains-modal.component.scss' ]
13})
14export class BatchDomainsModalComponent extends FormReactive implements OnInit {
15 @ViewChild('modal', { static: true }) modal: NgbModal
16 @Input() placeholder = 'example.com'
17 @Input() action: string
18 @Output() domains = new EventEmitter<string[]>()
19
20 private openedModal: NgbModalRef
21
22 constructor (
23 protected formValidatorService: FormValidatorService,
24 private modalService: NgbModal,
25 private batchDomainsValidatorsService: BatchDomainsValidatorsService,
26 private i18n: I18n
27 ) {
28 super()
29 }
30
31 ngOnInit () {
32 if (!this.action) this.action = this.i18n('Process domains')
33
34 this.buildForm({
35 domains: this.batchDomainsValidatorsService.DOMAINS
36 })
37 }
38
39 openModal () {
40 this.openedModal = this.modalService.open(this.modal, { centered: true })
41 }
42
43 hide () {
44 this.openedModal.close()
45 }
46
47 submit () {
48 this.domains.emit(
49 this.batchDomainsValidatorsService.getNotEmptyHosts(this.form.controls['domains'].value)
50 )
51 this.form.reset()
52 this.hide()
53 }
54}
diff --git a/client/src/app/+admin/config/shared/batch-domains-validators.service.ts b/client/src/app/+admin/config/shared/batch-domains-validators.service.ts
new file mode 100644
index 000000000..154ef3a23
--- /dev/null
+++ b/client/src/app/+admin/config/shared/batch-domains-validators.service.ts
@@ -0,0 +1,68 @@
1import { I18n } from '@ngx-translate/i18n-polyfill'
2import { Validators, ValidatorFn } from '@angular/forms'
3import { Injectable } from '@angular/core'
4import { BuildFormValidator, validateHost } from '@app/shared'
5
6@Injectable()
7export class BatchDomainsValidatorsService {
8 readonly DOMAINS: BuildFormValidator
9
10 constructor (private i18n: I18n) {
11 this.DOMAINS = {
12 VALIDATORS: [ Validators.required, this.validDomains, this.isHostsUnique ],
13 MESSAGES: {
14 'required': this.i18n('Domain is required.'),
15 'validDomains': this.i18n('Domains entered are invalid.'),
16 'uniqueDomains': this.i18n('Domains entered contain duplicates.')
17 }
18 }
19 }
20
21 getNotEmptyHosts (hosts: string) {
22 return hosts
23 .split('\n')
24 .filter((host: string) => host && host.length !== 0) // Eject empty hosts
25 }
26
27 private validDomains: ValidatorFn = (control) => {
28 if (!control.value) return null
29
30 const newHostsErrors = []
31 const hosts = this.getNotEmptyHosts(control.value)
32
33 for (const host of hosts) {
34 if (validateHost(host) === false) {
35 newHostsErrors.push(this.i18n('{{host}} is not valid', { host }))
36 }
37 }
38
39 /* Is not valid. */
40 if (newHostsErrors.length !== 0) {
41 return {
42 'validDomains': {
43 reason: 'invalid',
44 value: newHostsErrors.join('. ') + '.'
45 }
46 }
47 }
48
49 /* Is valid. */
50 return null
51 }
52
53 private isHostsUnique: ValidatorFn = (control) => {
54 if (!control.value) return null
55
56 const hosts = this.getNotEmptyHosts(control.value)
57
58 if (hosts.every((host: string) => hosts.indexOf(host) === hosts.lastIndexOf(host))) {
59 return null
60 } else {
61 return {
62 'uniqueDomains': {
63 reason: 'invalid'
64 }
65 }
66 }
67 }
68}