diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-29 15:33:24 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-01-03 14:20:52 +0100 |
commit | cc4bf76c13e38e9065d49161b6e0485657424577 (patch) | |
tree | d7ecc6bd58037c41587eb911776b676592985cd1 /client/src/app/+videos | |
parent | e2aeb8ad0f3055d54ac416ec5908d26b70aac4be (diff) | |
download | PeerTube-cc4bf76c13e38e9065d49161b6e0485657424577.tar.gz PeerTube-cc4bf76c13e38e9065d49161b6e0485657424577.tar.zst PeerTube-cc4bf76c13e38e9065d49161b6e0485657424577.zip |
Handle async validators
Diffstat (limited to 'client/src/app/+videos')
8 files changed, 31 insertions, 36 deletions
diff --git a/client/src/app/+videos/+video-edit/shared/video-edit.component.ts b/client/src/app/+videos/+video-edit/shared/video-edit.component.ts index 8ce36121d..be3bbe9be 100644 --- a/client/src/app/+videos/+video-edit/shared/video-edit.component.ts +++ b/client/src/app/+videos/+video-edit/shared/video-edit.component.ts | |||
@@ -2,7 +2,7 @@ import { forkJoin } from 'rxjs' | |||
2 | import { map } from 'rxjs/operators' | 2 | import { map } from 'rxjs/operators' |
3 | import { SelectChannelItem } from 'src/types/select-options-item.model' | 3 | import { SelectChannelItem } from 'src/types/select-options-item.model' |
4 | import { ChangeDetectorRef, Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' | 4 | import { ChangeDetectorRef, Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' |
5 | import { AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Validators } from '@angular/forms' | 5 | import { AbstractControl, FormArray, FormControl, FormGroup, Validators } from '@angular/forms' |
6 | import { HooksService, PluginService, ServerService } from '@app/core' | 6 | import { HooksService, PluginService, ServerService } from '@app/core' |
7 | import { removeElementFromArray } from '@app/helpers' | 7 | import { removeElementFromArray } from '@app/helpers' |
8 | import { BuildFormValidator } from '@app/shared/form-validators' | 8 | import { BuildFormValidator } from '@app/shared/form-validators' |
@@ -309,10 +309,10 @@ export class VideoEditComponent implements OnInit, OnDestroy { | |||
309 | for (const setting of this.pluginFields) { | 309 | for (const setting of this.pluginFields) { |
310 | await this.pluginService.translateSetting(setting.pluginInfo.plugin.npmName, setting.commonOptions) | 310 | await this.pluginService.translateSetting(setting.pluginInfo.plugin.npmName, setting.commonOptions) |
311 | 311 | ||
312 | const validator = (control: AbstractControl): ValidationErrors | null => { | 312 | const validator = async (control: AbstractControl) => { |
313 | if (!setting.commonOptions.error) return null | 313 | if (!setting.commonOptions.error) return null |
314 | 314 | ||
315 | const error = setting.commonOptions.error({ formValues: this.form.value, value: control.value }) | 315 | const error = await setting.commonOptions.error({ formValues: this.form.value, value: control.value }) |
316 | 316 | ||
317 | return error?.error ? { [setting.commonOptions.name]: error.text } : null | 317 | return error?.error ? { [setting.commonOptions.name]: error.text } : null |
318 | } | 318 | } |
@@ -320,7 +320,8 @@ export class VideoEditComponent implements OnInit, OnDestroy { | |||
320 | const name = setting.commonOptions.name | 320 | const name = setting.commonOptions.name |
321 | 321 | ||
322 | pluginObj[name] = { | 322 | pluginObj[name] = { |
323 | VALIDATORS: [ validator ], | 323 | ASYNC_VALIDATORS: [ validator ], |
324 | VALIDATORS: [], | ||
324 | MESSAGES: {} | 325 | MESSAGES: {} |
325 | } | 326 | } |
326 | 327 | ||
@@ -342,6 +343,9 @@ export class VideoEditComponent implements OnInit, OnDestroy { | |||
342 | 343 | ||
343 | this.cd.detectChanges() | 344 | this.cd.detectChanges() |
344 | this.pluginFieldsAdded.emit() | 345 | this.pluginFieldsAdded.emit() |
346 | |||
347 | // Plugins may need other control values to calculate potential errors | ||
348 | this.form.valueChanges.subscribe(() => this.formValidatorService.updateTreeValidity(this.pluginDataFormGroup)) | ||
345 | } | 349 | } |
346 | 350 | ||
347 | private trackPrivacyChange () { | 351 | private trackPrivacyChange () { |
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts index 46a7ebb0b..fde8c884b 100644 --- a/client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts +++ b/client/src/app/+videos/+video-edit/video-add-components/video-go-live.component.ts | |||
@@ -110,10 +110,8 @@ export class VideoGoLiveComponent extends VideoSend implements OnInit, AfterView | |||
110 | }) | 110 | }) |
111 | } | 111 | } |
112 | 112 | ||
113 | updateSecondStep () { | 113 | async updateSecondStep () { |
114 | if (this.checkForm() === false) { | 114 | if (!await this.isFormValid()) return |
115 | return | ||
116 | } | ||
117 | 115 | ||
118 | const video = new VideoEdit() | 116 | const video = new VideoEdit() |
119 | video.patch(this.form.value) | 117 | video.patch(this.form.value) |
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts index 5e758910e..c369ba2b7 100644 --- a/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts +++ b/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts | |||
@@ -123,10 +123,8 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Af | |||
123 | }) | 123 | }) |
124 | } | 124 | } |
125 | 125 | ||
126 | updateSecondStep () { | 126 | async updateSecondStep () { |
127 | if (this.checkForm() === false) { | 127 | if (!await this.isFormValid()) return |
128 | return | ||
129 | } | ||
130 | 128 | ||
131 | this.video.patch(this.form.value) | 129 | this.video.patch(this.form.value) |
132 | 130 | ||
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.ts index 2ea70ed55..0c78669c1 100644 --- a/client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.ts +++ b/client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.ts | |||
@@ -124,10 +124,8 @@ export class VideoImportUrlComponent extends VideoSend implements OnInit, AfterV | |||
124 | }) | 124 | }) |
125 | } | 125 | } |
126 | 126 | ||
127 | updateSecondStep () { | 127 | async updateSecondStep () { |
128 | if (this.checkForm() === false) { | 128 | if (!await this.isFormValid()) return |
129 | return | ||
130 | } | ||
131 | 129 | ||
132 | this.video.patch(this.form.value) | 130 | this.video.patch(this.form.value) |
133 | 131 | ||
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-send.ts b/client/src/app/+videos/+video-edit/video-add-components/video-send.ts index 5e086ef42..3d0e1bf2a 100644 --- a/client/src/app/+videos/+video-edit/video-add-components/video-send.ts +++ b/client/src/app/+videos/+video-edit/video-add-components/video-send.ts | |||
@@ -60,12 +60,6 @@ export abstract class VideoSend extends FormReactive implements OnInit { | |||
60 | }) | 60 | }) |
61 | } | 61 | } |
62 | 62 | ||
63 | checkForm () { | ||
64 | this.forceCheck() | ||
65 | |||
66 | return this.form.valid | ||
67 | } | ||
68 | |||
69 | protected updateVideoAndCaptions (video: VideoEdit) { | 63 | protected updateVideoAndCaptions (video: VideoEdit) { |
70 | this.loadingBar.useRef().start() | 64 | this.loadingBar.useRef().start() |
71 | 65 | ||
@@ -80,4 +74,11 @@ export abstract class VideoSend extends FormReactive implements OnInit { | |||
80 | }) | 74 | }) |
81 | ) | 75 | ) |
82 | } | 76 | } |
77 | |||
78 | protected async isFormValid () { | ||
79 | await this.waitPendingCheck() | ||
80 | this.forceCheck() | ||
81 | |||
82 | return this.form.valid | ||
83 | } | ||
83 | } | 84 | } |
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts index fa5800897..2251b0511 100644 --- a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts +++ b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts | |||
@@ -226,7 +226,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy | |||
226 | } | 226 | } |
227 | 227 | ||
228 | isPublishingButtonDisabled () { | 228 | isPublishingButtonDisabled () { |
229 | return !this.checkForm() || | 229 | return !this.form.valid || |
230 | this.isUpdatingVideo === true || | 230 | this.isUpdatingVideo === true || |
231 | this.videoUploaded !== true || | 231 | this.videoUploaded !== true || |
232 | !this.videoUploadedIds.id | 232 | !this.videoUploadedIds.id |
@@ -239,10 +239,9 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy | |||
239 | return $localize`Upload ${videofile.name}` | 239 | return $localize`Upload ${videofile.name}` |
240 | } | 240 | } |
241 | 241 | ||
242 | updateSecondStep () { | 242 | async updateSecondStep () { |
243 | if (this.isPublishingButtonDisabled()) { | 243 | if (!await this.isFormValid()) return |
244 | return | 244 | if (this.isPublishingButtonDisabled()) return |
245 | } | ||
246 | 245 | ||
247 | const video = new VideoEdit() | 246 | const video = new VideoEdit() |
248 | video.patch(this.form.value) | 247 | video.patch(this.form.value) |
diff --git a/client/src/app/+videos/+video-edit/video-update.component.ts b/client/src/app/+videos/+video-edit/video-update.component.ts index e44aea10a..5e4955f6a 100644 --- a/client/src/app/+videos/+video-edit/video-update.component.ts +++ b/client/src/app/+videos/+video-edit/video-update.component.ts | |||
@@ -91,12 +91,6 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { | |||
91 | return { canDeactivate: this.formChanged === false, text } | 91 | return { canDeactivate: this.formChanged === false, text } |
92 | } | 92 | } |
93 | 93 | ||
94 | checkForm () { | ||
95 | this.forceCheck() | ||
96 | |||
97 | return this.form.valid | ||
98 | } | ||
99 | |||
100 | isWaitTranscodingEnabled () { | 94 | isWaitTranscodingEnabled () { |
101 | if (this.videoDetails.getFiles().length > 1) { // Already transcoded | 95 | if (this.videoDetails.getFiles().length > 1) { // Already transcoded |
102 | return false | 96 | return false |
@@ -109,8 +103,11 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { | |||
109 | return true | 103 | return true |
110 | } | 104 | } |
111 | 105 | ||
112 | update () { | 106 | async update () { |
113 | if (this.checkForm() === false || this.isUpdatingVideo === true) { | 107 | await this.waitPendingCheck() |
108 | this.forceCheck() | ||
109 | |||
110 | if (!this.form.valid || this.isUpdatingVideo === true) { | ||
114 | return | 111 | return |
115 | } | 112 | } |
116 | 113 | ||
diff --git a/client/src/app/+videos/+video-watch/shared/comment/video-comment-add.component.ts b/client/src/app/+videos/+video-watch/shared/comment/video-comment-add.component.ts index 71fb127f6..85da83a4c 100644 --- a/client/src/app/+videos/+video-watch/shared/comment/video-comment-add.component.ts +++ b/client/src/app/+videos/+video-watch/shared/comment/video-comment-add.component.ts | |||
@@ -97,7 +97,7 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges, | |||
97 | } | 97 | } |
98 | 98 | ||
99 | onValidKey () { | 99 | onValidKey () { |
100 | this.check() | 100 | this.forceCheck() |
101 | if (!this.form.valid) return | 101 | if (!this.form.valid) return |
102 | 102 | ||
103 | this.formValidated() | 103 | this.formValidated() |