Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add bulk action to videos

Chocobozzzb7542c17b6b9
diff --git a/client/src/app/+admin/overview/videos/video-list.component.html b/client/src/app/+admin/overview/videos/video-list.component.html
index 438cad3c16..906ec7a880 100644
--- a/client/src/app/+admin/overview/videos/video-list.component.html
+++ b/client/src/app/+admin/overview/videos/video-list.component.html
@@ -172,3 +172,5 @@
</my-table>
<my-video-block #videoBlockModal (videoBlocked)="table.loadData()"></my-video-block>
+
+<my-bulk-update-videos-modal #bulkUpdateVideosModal (saved)="table.loadData()"></my-bulk-update-videos-modal>
diff --git a/client/src/app/+admin/overview/videos/video-list.component.ts b/client/src/app/+admin/overview/videos/video-list.component.ts
index 7f1e713973..211e8ce926 100644
--- a/client/src/app/+admin/overview/videos/video-list.component.ts
+++ b/client/src/app/+admin/overview/videos/video-list.component.ts
@@ -12,6 +12,7 @@ import { AccountBlockBadgeInput } from '@app/shared/shared-moderation/account-bl
import { BlocklistService } from '@app/shared/shared-moderation/blocklist.service'
import { VideoBlockComponent } from '@app/shared/shared-moderation/video-block.component'
import { VideoBlockService } from '@app/shared/shared-moderation/video-block.service'
+import { BulkUpdateVideosModalComponent } from '@app/shared/shared-video/bulk-update-videos-modal.component'
import { PrivacyBadgeComponent } from '@app/shared/shared-video/privacy-badge.component'
import { getAllVideoStates, getVideoStateBadgeClass, getVideoStateLabel } from '@app/shared/shared-video/video-state-utils'
import { getAllFiles } from '@peertube/peertube-core-utils'
@@ -64,6 +65,7 @@ type ColumnName =
BytesPipe,
PrivacyBadgeComponent,
VideoNSFWBadgeComponent,
+ BulkUpdateVideosModalComponent,
TableComponent,
NumberFormatterPipe
]
@@ -81,6 +83,7 @@ export class VideoListComponent implements OnInit {
private blocklistService = inject(BlocklistService)
readonly videoBlockModal = viewChild<VideoBlockComponent>('videoBlockModal')
+ readonly bulkUpdateVideosModal = viewChild<BulkUpdateVideosModalComponent>('bulkUpdateVideosModal')
readonly table = viewChild<TableComponent<Video, DataLoaderParameter, ColumnName>>('table')
bulkActions: DropdownAction<Video[]>[][] = []
@@ -228,6 +231,12 @@ export class VideoListComponent implements OnInit {
this.bulkActions = [
[
+ {
+ label: $localize`Update...`,
+ handler: videos => this.bulkUpdateVideosModal().show({ videos }),
+ isDisplayed: () => this.authUser.hasRight(UserRight.UPDATE_ANY_VIDEO),
+ iconName: 'edit'
+ },
{
label: $localize`Delete`,
handler: videos => this.removeVideos(videos),
diff --git a/client/src/app/+my-library/my-videos/my-videos.component.html b/client/src/app/+my-library/my-videos/my-videos.component.html
index ad7c18fc34..1248e5d384 100644
--- a/client/src/app/+my-library/my-videos/my-videos.component.html
+++ b/client/src/app/+my-library/my-videos/my-videos.component.html
@@ -104,6 +104,14 @@
</td>
}
+ @if (table.isColumnDisplayed('category')) {
+ <td>
+ @if (video.category?.id) {
+ {{ video.category.label }}
+ }
+ </td>
+ }
+
@if (table.isColumnDisplayed('language')) {
<td>
@if (video.language?.id) {
@@ -112,6 +120,14 @@
</td>
}
+ @if (table.isColumnDisplayed('licence')) {
+ <td>
+ @if (video.licence?.id) {
+ {{ video.licence.label }}
+ }
+ </td>
+ }
+
@if (table.isColumnDisplayed('playlists')) {
<td>
<div class="badges playlists">
@@ -141,3 +157,5 @@
</my-table>
<my-bulk-update-videos-in-playlist-modal #bulkUpdateVideosInPlaylistModal (saved)="fetchVideosContainedInPlaylists($event)"></my-bulk-update-videos-in-playlist-modal>
+
+<my-bulk-update-videos-modal #bulkUpdateVideosModal (saved)="table.loadData()"></my-bulk-update-videos-modal>
diff --git a/client/src/app/+my-library/my-videos/my-videos.component.ts b/client/src/app/+my-library/my-videos/my-videos.component.ts
index 7448ff8d49..6223693e74 100644
--- a/client/src/app/+my-library/my-videos/my-videos.component.ts
+++ b/client/src/app/+my-library/my-videos/my-videos.component.ts
@@ -27,6 +27,7 @@ import {
VideoActionsDisplayType,
VideoActionsDropdownComponent
} from '../../shared/shared-video-miniature/video-actions-dropdown.component'
+import { BulkUpdateVideosModalComponent } from '../../shared/shared-video/bulk-update-videos-modal.component'
import { PrivacyBadgeComponent } from '../../shared/shared-video/privacy-badge.component'
import { VideoNSFWBadgeComponent } from '../../shared/shared-video/video-nsfw-badge.component'
import { VideoStateBadgeComponent } from '../../shared/shared-video/video-state-badge.component'
@@ -41,6 +42,8 @@ type ColumnName =
| 'playlists'
| 'insights'
| 'published'
+ | 'category'
+ | 'licence'
| 'state'
| 'comments'
@@ -68,7 +71,8 @@ type DataLoaderParameter = Parameters<MyVideosComponent['_dataLoader']>[0]
VideoNSFWBadgeComponent,
TableComponent,
PrivacyBadgeComponent,
- BulkUpdateVideosInPlaylistModalComponent
+ BulkUpdateVideosInPlaylistModalComponent,
+ BulkUpdateVideosModalComponent
]
})
export class MyVideosComponent implements OnInit, OnDestroy {
@@ -84,6 +88,7 @@ export class MyVideosComponent implements OnInit, OnDestroy {
readonly table = viewChild<TableComponent<Video, DataLoaderParameter, ColumnName, QueryParams>>('table')
readonly bulkUpdateVideosInPlaylistModal = viewChild<BulkUpdateVideosInPlaylistModalComponent>('bulkUpdateVideosInPlaylistModal')
+ readonly bulkUpdateVideosModal = viewChild<BulkUpdateVideosModalComponent>('bulkUpdateVideosModal')
videosContainedInPlaylists: VideosExistInPlaylists = {}
@@ -140,7 +145,9 @@ export class MyVideosComponent implements OnInit, OnDestroy {
{ id: 'comments', label: $localize`Comments`, selected: true, sortable: true },
{ id: 'published', label: $localize`Published`, selected: true, sortable: true, sortKey: 'publishedAt' },
{ id: 'state', label: $localize`State`, selected: true, sortable: false },
+ { id: 'category', label: $localize`Category`, selected: false, sortable: false },
{ id: 'language', label: $localize`Language`, selected: false, sortable: false },
+ { id: 'licence', label: $localize`Licence`, selected: false, sortable: false },
{ id: 'playlists', label: $localize`Playlists`, selected: true, sortable: false }
]
@@ -228,7 +235,7 @@ export class MyVideosComponent implements OnInit, OnDestroy {
private _dataLoader (options: {
pagination: RestPagination
sort: SortMeta
- search: string
+ search?: string
isLive?: boolean
privacyOneOf?: VideoPrivacyType
tagsOneOf?: string[]
@@ -306,6 +313,11 @@ export class MyVideosComponent implements OnInit, OnDestroy {
this.bulkUpdateVideosInPlaylistModal().show({ videos, videosContainedInPlaylists: this.videosContainedInPlaylists })
},
iconName: 'playlist-add'
+ },
+ {
+ label: $localize`Update...`,
+ handler: videos => this.bulkUpdateVideosModal().show({ videos }),
+ iconName: 'edit'
}
],
diff --git a/client/src/app/modal/admin-config-wizard/admin-config-wizard-modal.component.html b/client/src/app/modal/admin-config-wizard/admin-config-wizard-modal.component.html
index 06d17374ed..66ab2ea89c 100644
--- a/client/src/app/modal/admin-config-wizard/admin-config-wizard-modal.component.html
+++ b/client/src/app/modal/admin-config-wizard/admin-config-wizard-modal.component.html
@@ -1,6 +1,6 @@
<ng-template #modal>
<div class="modal-body">
- <my-admin-config-wizard-stepper #stepper>
+ <my-common-stepper #stepper>
@if (showWelcome) {
<cdk-step i18n-label label="Welcome introduction">
<my-admin-config-wizard-welcome (back)="stepper.previous()" (next)="stepper.next()" (hide)="hide($event)"></my-admin-config-wizard-welcome>
@@ -35,6 +35,6 @@
<my-admin-config-wizard-documentation (hide)="hide({ doNotOpenAgain: true })"></my-admin-config-wizard-documentation>
</cdk-step>
}
- </my-admin-config-wizard-stepper>
+ </my-common-stepper>
</div>
</ng-template>
diff --git a/client/src/app/modal/admin-config-wizard/admin-config-wizard-modal.component.ts b/client/src/app/modal/admin-config-wizard/admin-config-wizard-modal.component.ts
index 16ab0236f7..f5ad12c8d9 100644
--- a/client/src/app/modal/admin-config-wizard/admin-config-wizard-modal.component.ts
+++ b/client/src/app/modal/admin-config-wizard/admin-config-wizard-modal.component.ts
@@ -1,10 +1,10 @@
import { CdkStepperModule } from '@angular/cdk/stepper'
import { Component, ElementRef, OnInit, inject, output, viewChild } from '@angular/core'
import { Notifier, User, UserService } from '@app/core'
+import { CommonStepperComponent } from '@app/shared/shared-main/common/common-stepper.component'
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
import { logger } from '@root-helpers/logger'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
-import { AdminConfigWizardStepperComponent } from './admin-config-wizard-stepper.component'
import { getNoWelcomeModalLocalStorageKey } from './shared/admin-config-wizard-modal-utils'
import { AdminConfigWizardDocumentationComponent } from './steps/admin-config-wizard-documentation.component'
import { AdminConfigWizardEditInfoComponent, FormEditInfo } from './steps/admin-config-wizard-edit-info.component'
@@ -19,7 +19,7 @@ import { UsageType } from './steps/usage-type/usage-type.model'
styleUrls: [ './admin-config-wizard-modal.component.scss' ],
imports: [
CdkStepperModule,
- AdminConfigWizardStepperComponent,
+ CommonStepperComponent,
AdminConfigWizardWelcomeComponent,
AdminConfigWizardEditInfoComponent,
AdminConfigWizardFormComponent,
@@ -33,7 +33,7 @@ export class AdminConfigWizardModalComponent implements OnInit {
private notifier = inject(Notifier)
readonly modal = viewChild<ElementRef>('modal')
- readonly stepper = viewChild<AdminConfigWizardStepperComponent>('stepper')
+ readonly stepper = viewChild<CommonStepperComponent>('stepper')
readonly created = output()
diff --git a/client/src/app/modal/admin-config-wizard/admin-config-wizard-stepper.component.html b/client/src/app/modal/admin-config-wizard/admin-config-wizard-stepper.component.html
deleted file mode 100644
index 8f207574dc..0000000000
--- a/client/src/app/modal/admin-config-wizard/admin-config-wizard-stepper.component.html
+++ /dev/null
@@ -1,3 +0,0 @@
-<div>
- <div [ngTemplateOutlet]="selected ? selected.content : null"></div>
-</div>
diff --git a/client/src/app/modal/admin-config-wizard/admin-config-wizard-stepper.component.ts b/client/src/app/modal/admin-config-wizard/admin-config-wizard-stepper.component.ts
deleted file mode 100644
index e8de4a8df8..0000000000
--- a/client/src/app/modal/admin-config-wizard/admin-config-wizard-stepper.component.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { CdkStepper } from '@angular/cdk/stepper'
-import { CommonModule, NgTemplateOutlet } from '@angular/common'
-import { Component } from '@angular/core'
-
-@Component({
- selector: 'my-admin-config-wizard-stepper',
- templateUrl: './admin-config-wizard-stepper.component.html',
- providers: [ { provide: CdkStepper, useExisting: AdminConfigWizardStepperComponent } ],
- imports: [ CommonModule, NgTemplateOutlet ]
-})
-export class AdminConfigWizardStepperComponent extends CdkStepper {
-}
diff --git a/client/src/app/shared/form-validators/video-validators.ts b/client/src/app/shared/form-validators/video-validators.ts
index 86a46dbccf..2e83172d4b 100644
--- a/client/src/app/shared/form-validators/video-validators.ts
+++ b/client/src/app/shared/form-validators/video-validators.ts
@@ -1,4 +1,5 @@
-import { AbstractControl, ValidationErrors, ValidatorFn, Validators, FormControl } from '@angular/forms'
+import { AbstractControl, FormControl, ValidationErrors, ValidatorFn, Validators } from '@angular/forms'
+import { maxLength, minLength, SchemaPath } from '@angular/forms/signals'
import { BuildFormValidator } from './form-validator.model'
export const trimValidator: ValidatorFn = (control: FormControl) => {
@@ -86,6 +87,11 @@ export const VIDEO_SUPPORT_VALIDATOR: BuildFormValidator = {
}
}
+export function videoSupportValidator (support: SchemaPath<string>) {
+ minLength(support, 3, { message: $localize`Support must be at least 3 characters long.` })
+ maxLength(support, 1000, { message: $localize`Support cannot be more than 1000 characters long.` })
+}
+
export const VIDEO_NSFW_SUMMARY_VALIDATOR: BuildFormValidator = {
VALIDATORS: [ Validators.minLength(3), Validators.maxLength(250) ],
MESSAGES: {
diff --git a/client/src/app/shared/shared-forms/select/select-options.component.html b/client/src/app/shared/shared-forms/select/select-options.component.html
index 665f9cb2df..8fbad47f2b 100644
--- a/client/src/app/shared/shared-forms/select/select-options.component.html
+++ b/client/src/app/shared/shared-forms/select/select-options.component.html
@@ -8,6 +8,8 @@
optionValue="id"
+ label
+
[showClear]="clearable()"
[filter]="filter()"
@@ -24,6 +26,8 @@
[appendTo]="appendTo()"
[class.small]="small()"
+
+ [placeholder]="placeholder()"
>
<ng-template #itemTemplate let-item let-description="description">
@if (selectOptionTemplate) {
diff --git a/client/src/app/shared/shared-forms/select/select-options.component.ts b/client/src/app/shared/shared-forms/select/select-options.component.ts
index 07518df906..46eac2b55a 100644
--- a/client/src/app/shared/shared-forms/select/select-options.component.ts
+++ b/client/src/app/shared/shared-forms/select/select-options.component.ts
@@ -40,6 +40,7 @@ export class SelectOptionsComponent implements ControlValueAccessor {
readonly clearable = input(false, { transform: booleanAttribute })
readonly filter = input(false, { transform: booleanAttribute })
readonly small = input(false, { transform: booleanAttribute })
+ readonly placeholder = input('')
readonly appendTo = input<'body'>()
diff --git a/client/src/app/shared/shared-main/common/common-stepper.component.ts b/client/src/app/shared/shared-main/common/common-stepper.component.ts
new file mode 100644
index 0000000000..65ac34fadd
--- /dev/null
+++ b/client/src/app/shared/shared-main/common/common-stepper.component.ts
@@ -0,0 +1,14 @@
+import { CdkStepper } from '@angular/cdk/stepper'
+import { CommonModule, NgTemplateOutlet } from '@angular/common'
+import { Component } from '@angular/core'
+
+@Component({
+ selector: 'my-common-stepper',
+ template: `<div>
+ <div [ngTemplateOutlet]="selected ? selected.content : null"></div>
+ </div>`,
+ providers: [ { provide: CdkStepper, useExisting: CommonStepperComponent } ],
+ imports: [ CommonModule, NgTemplateOutlet ]
+})
+export class CommonStepperComponent extends CdkStepper {
+}
diff --git a/client/src/app/shared/shared-video/bulk-update-videos-modal.component.html b/client/src/app/shared/shared-video/bulk-update-videos-modal.component.html
new file mode 100644
index 0000000000..2382909892
--- /dev/null
+++ b/client/src/app/shared/shared-video/bulk-update-videos-modal.component.html
@@ -0,0 +1,131 @@
+<ng-template #modal>
+ <div class="modal-header">
+ <h4 i18n class="modal-title">{videos.length, plural, =1 {Bulk update 1 video} other {Bulk update {{ videos.length }} videos}}</h4>
+
+ <button class="border-0 p-0" title="Close this modal" i18n-title (click)="hide()">
+ <my-global-icon iconName="cross"></my-global-icon>
+ </button>
+ </div>
+
+ <my-common-stepper #stepper>
+ <cdk-step i18n-label label="Configure">
+ <div class="modal-body">
+ @if (activeAvailableFields().length > 0) {
+ <div class="bulk-update-add-field">
+ <select class="form-control" (change)="onAddFieldSelect($event)">
+ <option value="" disabled selected i18n>Add a field to update...</option>
+
+ @for (field of activeAvailableFields(); track field.key) {
+ <option [value]="field.key">{{ field.label }}</option>
+ }
+ </select>
+ </div>
+ }
+
+ <div class="bulk-update-fields">
+ @for (def of allFields; track def.key) {
+ @if (activeFields().has(def.key)) {
+ <div class="bulk-update-field-section">
+ <div class="bulk-update-field-header">
+ <label [for]="'bulk-' + def.key" class="m-0">{{ def.label }}</label>
+
+ <button class="remove-field-btn" (click)="removeField(def.key)" i18n-title title="Remove this field">
+ <my-global-icon iconName="cross"></my-global-icon>
+ </button>
+ </div>
+
+ @if (def.key === 'channelId') {
+ <my-select-channel
+ [inputId]="'bulk-' + def.key"
+ [items]="userChannels"
+ [formField]="bulkUpdateForm[def.key]"
+ >
+ </my-select-channel>
+ } @else if (def.key === 'support') {
+ <textarea class="form-control" rows="3" [formField]="bulkUpdateForm[def.key]"></textarea>
+ } @else if (def.key === 'downloadEnabled') {
+ <my-peertube-checkbox
+ inputName="bulk-downloadEnabled"
+ [labelText]="def.label"
+ [formField]="bulkUpdateForm[def.key]"
+ >
+ </my-peertube-checkbox>
+ } @else if (def.key === 'language') {
+ <my-select-options
+ [inputId]="'bulk-' + def.key"
+ [items]="videoLanguages"
+ filter="true"
+ clearable="true"
+ [formField]="bulkUpdateForm[def.key]"
+ virtualScroll="true"
+ placeholder="Remove the language"
+ i18n-placeholder
+ >
+ </my-select-options>
+ } @else if (def.key === 'category') {
+ <my-select-options
+ [inputId]="'bulk-' + def.key"
+ [items]="videoCategories"
+ clearable="true"
+ [formField]="bulkUpdateForm[def.key]"
+ placeholder="Remove the category"
+ i18n-placeholder
+ >
+ </my-select-options>
+ } @else if (def.key === 'licence') {
+ <my-select-options
+ [inputId]="'bulk-' + def.key"
+ [items]="videoLicences"
+ clearable="true"
+ [formField]="bulkUpdateForm[def.key]"
+ placeholder="Remove the licence"
+ i18n-placeholder
+ >
+ </my-select-options>
+ } @else {
+ <my-select-options
+ [inputId]="'bulk-' + def.key"
+ [items]="getSelectItemsForField(def.key)"
+ [formField]="bulkUpdateForm[def.key]"
+ >
+ </my-select-options>
+ }
+
+ <my-form-error [field]="bulkUpdateForm[def.key]()"></my-form-error>
+ </div>
+ }
+ }
+ </div>
+ </div>
+
+ <div class="modal-footer inputs">
+ <input type="button" role="button" i18n-value value="Cancel" class="peertube-button secondary-button" (click)="hide()" (key.enter)="hide()">
+
+ <my-button theme="primary" [disabled]="!bulkUpdateForm().valid() || activeFields().size === 0 || isSaving()" (click)="stepper.next()" i18n>Next</my-button>
+ </div>
+ </cdk-step>
+
+ <cdk-step i18n-label label="Confirm">
+ <div class="modal-body">
+ <p i18n>
+ You are about to update the following {activeFields().size, plural, =1 {field} other {fields}} for
+ <strong>{videos.length, plural, =1 {1 video} other {{{ videos.length }} videos}}:</strong>
+ </p>
+
+ <ul>
+ @for (def of allFields; track def.key) {
+ @if (activeFields().has(def.key)) {
+ <li><strong>{{ def.label }}</strong>: {{ getFieldSummary(def.key) }}</li>
+ }
+ }
+ </ul>
+ </div>
+
+ <div class="modal-footer inputs">
+ <input type="button" role="button" i18n-value value="Back" class="peertube-button secondary-button" (click)="stepper.previous()" (key.enter)="stepper.previous()">
+
+ <my-button theme="primary" [loading]="isSaving()" [disabled]="isSaving()" (click)="save()" i18n>Update</my-button>
+ </div>
+ </cdk-step>
+ </my-common-stepper>
+</ng-template>
diff --git a/client/src/app/shared/shared-video/bulk-update-videos-modal.component.scss b/client/src/app/shared/shared-video/bulk-update-videos-modal.component.scss
new file mode 100644
index 0000000000..65b960543d
--- /dev/null
+++ b/client/src/app/shared/shared-video/bulk-update-videos-modal.component.scss
@@ -0,0 +1,27 @@
+@use "_variables" as *;
+@use "_mixins" as *;
+@use "_form-mixins" as *;
+
+.bulk-update-field-section {
+ border: 1px solid pvar(--input-border-color);
+ border-radius: 4px;
+ padding: 1rem;
+ margin-bottom: 1.5rem;
+}
+
+.bulk-update-field-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ margin-bottom: 1rem;
+
+ .remove-field-btn {
+ border: 0;
+ cursor: pointer;
+ padding: 0;
+ }
+}
+
+.bulk-update-add-field {
+ margin-bottom: 1rem;
+}
diff --git a/client/src/app/shared/shared-video/bulk-update-videos-modal.component.ts b/client/src/app/shared/shared-video/bulk-update-videos-modal.component.ts
new file mode 100644
index 0000000000..ec66faad81
--- /dev/null
+++ b/client/src/app/shared/shared-video/bulk-update-videos-modal.component.ts
@@ -0,0 +1,278 @@
+import { CdkStepperModule } from '@angular/cdk/stepper'
+import { Component, computed, ElementRef, inject, output, signal, viewChild } from '@angular/core'
+import { FormsModule } from '@angular/forms'
+import { form, FormField, required } from '@angular/forms/signals'
+import { AuthService, Notifier, ServerService } from '@app/core'
+import { formatICU } from '@app/helpers'
+import { listUserChannelsForSelect } from '@app/helpers/utils/channel'
+import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal'
+import { ConstantLabel, Video, VideoCommentPolicyType, VideoPrivacy, VideoPrivacyType, VideoUpdate } from '@peertube/peertube-models'
+import { SelectChannelItem } from '@pt-types'
+import { concatMap, from, toArray } from 'rxjs'
+import { videoSupportValidator } from '../form-validators/video-validators'
+import { FormErrorComponent } from '../shared-forms/form-error.component'
+import { PeertubeCheckboxComponent } from '../shared-forms/peertube-checkbox.component'
+import { SelectChannelComponent } from '../shared-forms/select/select-channel.component'
+import { SelectOptionsComponent } from '../shared-forms/select/select-options.component'
+import { GlobalIconComponent } from '../shared-icons/global-icon.component'
+import { ButtonComponent } from '../shared-main/buttons/button.component'
+import { CommonStepperComponent } from '../shared-main/common/common-stepper.component'
+import { VideoService } from '../shared-main/video/video.service'
+
+type BulkVideoUpdateModel = {
+ channelId: number | null
+ language: string | null
+ category: number | null
+ support: string | null
+ privacy: VideoPrivacyType | null
+ licence: number | null
+ downloadEnabled: boolean
+ commentsPolicy: VideoCommentPolicyType | null
+}
+
+type FieldName = keyof BulkVideoUpdateModel
+
+type FieldDefinition = {
+ key: FieldName
+ label: string
+}
+
+const BULK_PRIVACY_EXCLUDE = new Set<VideoPrivacyType>([ VideoPrivacy.PASSWORD_PROTECTED ])
+
+@Component({
+ selector: 'my-bulk-update-videos-modal',
+ styleUrls: [ './bulk-update-videos-modal.component.scss' ],
+ templateUrl: './bulk-update-videos-modal.component.html',
+ imports: [
+ FormsModule,
+ CdkStepperModule,
+ GlobalIconComponent,
+ ButtonComponent,
+ SelectOptionsComponent,
+ SelectChannelComponent,
+ PeertubeCheckboxComponent,
+ FormErrorComponent,
+ FormField,
+ CommonStepperComponent
+ ]
+})
+export class BulkUpdateVideosModalComponent {
+ private authService = inject(AuthService)
+ private modalService = inject(NgbModal)
+ private notifier = inject(Notifier)
+ private server = inject(ServerService)
+ private videoService = inject(VideoService)
+
+ readonly saved = output()
+
+ readonly modal = viewChild<ElementRef>('modal')
+
+ private openedModal: NgbModalRef
+
+ videos: Video[] = []
+
+ readonly activeFields = signal(new Set<FieldName>())
+
+ private readonly bulkUpdateModel = signal<BulkVideoUpdateModel>({
+ channelId: null,
+ language: null,
+ category: null,
+ support: null,
+ privacy: null,
+ licence: null,
+ downloadEnabled: true,
+ commentsPolicy: null
+ })
+
+ readonly bulkUpdateForm = form(this.bulkUpdateModel, f => {
+ required(f.channelId, { when: () => this.activeFields().has('channelId'), message: $localize`Channel is required.` })
+ required(f.privacy, { when: () => this.activeFields().has('privacy'), message: $localize`Privacy is required.` })
+ required(f.commentsPolicy, { when: () => this.activeFields().has('commentsPolicy'), message: $localize`Comments policy is required.` })
+
+ videoSupportValidator(f.support)
+ })
+
+ readonly allFields: FieldDefinition[] = [
+ { key: 'category', label: $localize`Category` },
+ { key: 'channelId', label: $localize`Channel` },
+ { key: 'commentsPolicy', label: $localize`Comment policy` },
+ { key: 'downloadEnabled', label: $localize`Enable download` },
+ { key: 'language', label: $localize`Language` },
+ { key: 'licence', label: $localize`Licence` },
+ { key: 'privacy', label: $localize`Privacy` },
+ { key: 'support', label: $localize`Support` }
+ ]
+
+ readonly activeAvailableFields = computed(() => this.allFields.filter(f => !this.activeFields().has(f.key)))
+
+ readonly isSaving = signal(false)
+
+ userChannels: SelectChannelItem[] = []
+
+ videoCategories: ConstantLabel<number>[] = []
+ videoLicences: ConstantLabel<number>[] = []
+ videoLanguages: ConstantLabel<string>[] = []
+ videoPrivacies: ConstantLabel<VideoPrivacyType>[] = []
+ commentPolicies: ConstantLabel<VideoCommentPolicyType>[]
+
+ get authUser () {
+ return this.authService.getUser()
+ }
+
+ show (options: {
+ videos: Video[]
+ }) {
+ this.videos = options.videos
+
+ // Keep the form and active fields reset when opening the modal so the user can easily re-apply the same update to another set of videos
+
+ this.activeFields.set(new Set())
+ this.isSaving.set(false)
+
+ // Load metadata if not yet loaded
+ this.server.getVideoCategories().subscribe(categories => this.videoCategories = categories)
+ this.server.getVideoLicences().subscribe(licences => this.videoLicences = licences)
+ this.server.getVideoLanguages().subscribe(languages => this.videoLanguages = languages)
+ this.server.getCommentPolicies().subscribe(policies => this.commentPolicies = policies)
+
+ this.server.getVideoPrivacies().subscribe(privacies => {
+ this.videoPrivacies = privacies.filter(p => !BULK_PRIVACY_EXCLUDE.has(p.id))
+ })
+
+ // Load user channels
+ listUserChannelsForSelect(this.authService, { includeCollaborations: true })
+ .subscribe(channels => this.userChannels = channels)
+
+ this.openedModal = this.modalService.open(this.modal(), { centered: true, keyboard: false })
+ }
+
+ hide () {
+ this.openedModal.close()
+ }
+
+ addField (key: FieldName) {
+ this.activeFields.update(fields => {
+ const newSet = new Set(fields)
+ newSet.add(key)
+
+ return newSet
+ })
+ }
+
+ removeField (key: FieldName) {
+ this.activeFields.update(fields => {
+ const newSet = new Set(fields)
+ newSet.delete(key)
+ return newSet
+ })
+
+ this.bulkUpdateModel.update(model => ({
+ ...model,
+ [key]: key === 'downloadEnabled' ? true : null
+ }))
+ }
+
+ getSelectItemsForField (key: FieldName): ConstantLabel<any>[] {
+ switch (key) {
+ case 'privacy':
+ return this.videoPrivacies
+ case 'commentsPolicy':
+ return this.commentPolicies
+ default:
+ return []
+ }
+ }
+
+ getFieldSummary (key: FieldName) {
+ const model = this.bulkUpdateModel()
+ const value = model[key]
+
+ if (value === null || value === undefined) return $localize`Not set`
+
+ switch (key) {
+ case 'channelId':
+ return this.userChannels.find(c => c.id === value)?.label
+
+ case 'language':
+ return this.videoLanguages.find(l => l.id === value)?.label
+
+ case 'category':
+ return this.videoCategories.find(c => c.id === value)?.label
+
+ case 'licence':
+ return this.videoLicences.find(l => l.id === value)?.label
+
+ case 'privacy':
+ return this.videoPrivacies.find(p => p.id === value)?.label
+
+ case 'commentsPolicy':
+ return this.commentPolicies?.find(p => p.id === value)?.label
+
+ case 'downloadEnabled':
+ return value ? $localize`Yes` : $localize`No`
+
+ case 'support':
+ return (value as string) || $localize`Not set`
+
+ default:
+ return String(value)
+ }
+ }
+
+ save () {
+ const model = this.bulkUpdateModel()
+ const active = this.activeFields()
+
+ this.isSaving.set(true)
+
+ const videos = this.videos
+
+ const buildUpdate = (): VideoUpdate => {
+ const update: VideoUpdate = {}
+ if (active.has('channelId')) update.channelId = model.channelId
+ if (active.has('language')) update.language = model.language
+ if (active.has('category')) update.category = model.category
+ if (active.has('support')) update.support = model.support
+ if (active.has('privacy')) update.privacy = model.privacy
+ if (active.has('licence')) update.licence = model.licence
+ if (active.has('downloadEnabled')) update.downloadEnabled = model.downloadEnabled
+ if (active.has('commentsPolicy')) update.commentsPolicy = model.commentsPolicy
+
+ return update
+ }
+
+ const updatePayload = buildUpdate()
+
+ from(videos)
+ .pipe(
+ concatMap(v => this.videoService.updateVideo(v.uuid, updatePayload)),
+ toArray()
+ ).subscribe({
+ next: () => this.onSaveSuccess(),
+ error: err => {
+ this.isSaving.set(false)
+
+ this.notifier.handleError(err)
+ }
+ })
+ }
+
+ onAddFieldSelect (event: Event) {
+ const select = event.target as HTMLSelectElement
+ this.addField(select.value as FieldName)
+ select.value = ''
+ }
+
+ private onSaveSuccess () {
+ this.isSaving.set(false)
+
+ const message = formatICU(
+ $localize`{count, plural, =1 {1 video updated} other {{count} videos updated}}`,
+ { count: this.videos.length }
+ )
+
+ this.notifier.success(message)
+ this.saved.emit()
+ this.hide()
+ }
+}