]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Improve edit config submit error
authorChocobozzz <me@florianbigard.com>
Wed, 10 Feb 2021 11:06:26 +0000 (12:06 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 10 Feb 2021 11:06:26 +0000 (12:06 +0100)
client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html
client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
client/src/app/+admin/config/edit-custom-config/edit-live-configuration.component.html

index 4596a130e4e9f3a8fcd14d03d0f95ecffd86a5e2..b6365614dcda896cd9996d7c87c1cd0f269089ae 100644 (file)
   <div class="form-row mt-4"> <!-- submit placement block -->
     <div class="col-md-7 col-xl-5"></div>
     <div class="col-md-5 col-xl-5">
-      <span class="form-error submit-error" i18n *ngIf="!form.valid">
-        It seems like the configuration is invalid. Please search for potential errors in the different tabs.
 
-        {{ formErrors }}
-      </span>
+      <div class="form-error submit-error" i18n *ngIf="!form.valid">
+        There are errors in the form:
+
+        <ul>
+          <li *ngFor="let error of grabAllErrors()">
+            {{ error }}
+          </li>
+        </ul>
+      </div>
 
       <span class="form-error submit-error" i18n *ngIf="!hasLiveAllowReplayConsistentOptions()">
         You cannot allow live replay if you don't enable transcoding.
index bbdf1bfbe027918da8bff7f5136878892005f832..2c7a1093705b933ba6ca8329aba0e98fbb48ad2d 100644 (file)
@@ -290,6 +290,25 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
     this.router.navigate([], { fragment: this.activeNav })
   }
 
+  grabAllErrors (errorObjectArg?: any) {
+    const errorObject = errorObjectArg || this.formErrors
+
+    let acc: string[] = []
+
+    for (const key of Object.keys(errorObject)) {
+      const value = errorObject[key]
+      if (!value) continue
+
+      if (typeof value === 'string') {
+        acc.push(value)
+      } else {
+        acc = acc.concat(this.grabAllErrors(value))
+      }
+    }
+
+    return acc
+  }
+
   private updateForm () {
     this.form.patchValue(this.customConfig)
   }
index 65fc314122d6e8befa51549b81c018d03371e352..5d826fbe901ffd6196d575d5d86efe0b3ecc30a2 100644 (file)
@@ -45,6 +45,8 @@
                   <input type="number" name="liveMaxInstanceLives" formControlName="maxInstanceLives" />
                   <span i18n>{form.value['live']['maxInstanceLives'], plural, =1 {live} other {lives}}</span>
                 </div>
+
+                <div *ngIf="formErrors.live.maxInstanceLives" class="form-error">{{ formErrors.live.maxInstanceLives }}</div>
               </div>
 
               <div class="form-group" [ngClass]="getDisabledLiveClass()">
@@ -56,6 +58,8 @@
                   <input type="number" name="liveMaxUserLives" formControlName="maxUserLives" />
                   <span i18n>{form.value['live']['maxUserLives'], plural, =1 {live} other {lives}}</span>
                 </div>
+
+                <div *ngIf="formErrors.live.maxUserLives" class="form-error">{{ formErrors.live.maxUserLives }}</div>
               </div>
 
               <div class="form-group" [ngClass]="getDisabledLiveClass()">
@@ -65,6 +69,8 @@
                   labelForId="liveMaxDuration" [items]="liveMaxDurationOptions" formControlName="maxDuration"
                   bindLabel="label" bindValue="value" [clearable]="false" [searchable]="true"
                 ></my-select-options>
+
+                <div *ngIf="formErrors.live.maxDuration" class="form-error">{{ formErrors.live.maxDuration }}</div>
               </div>
 
             </ng-container>