From c24ac1c18e26b6a24a4d294744908fb0c53ddf3c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 May 2017 14:29:58 +0200 Subject: [PATCH] Fix unset video language on video update --- client/src/app/videos/shared/video.service.ts | 5 ++++- .../app/videos/video-edit/video-update.component.ts | 10 ++++++++++ server/controllers/api/videos.js | 12 ++++++------ server/helpers/custom-validators/videos.js | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts index ba83c72fd..ef683dea6 100644 --- a/client/src/app/videos/shared/video.service.ts +++ b/client/src/app/videos/shared/video.service.ts @@ -81,14 +81,17 @@ export class VideoService { } updateVideo(video: Video) { + const language = video.language ? video.language : null; + const body = { name: video.name, category: video.category, licence: video.licence, - language: video.language, + language, description: video.description, tags: video.tags }; + const headers = new Headers({ 'Content-Type': 'application/json' }); const options = new RequestOptions({ headers: headers }); 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 adb3d295c..933132cc0 100644 --- a/client/src/app/videos/video-edit/video-update.component.ts +++ b/client/src/app/videos/video-edit/video-update.component.ts @@ -98,7 +98,17 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { ); } + checkForm() { + this.forceCheck(); + + return this.form.valid; + } + update() { + if (this.checkForm() === false) { + return; + } + this.video.patch(this.form.value); this.videoService.updateVideo(this.video) diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js index 4a4c5e162..aeefaa555 100644 --- a/server/controllers/api/videos.js +++ b/server/controllers/api/videos.js @@ -444,12 +444,12 @@ function updateVideo (req, res, finalCallback) { transaction: t } - if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name) - if (videoInfosToUpdate.category) videoInstance.set('category', videoInfosToUpdate.category) - if (videoInfosToUpdate.licence) videoInstance.set('licence', videoInfosToUpdate.licence) - if (videoInfosToUpdate.language) videoInstance.set('language', videoInfosToUpdate.language) - if (videoInfosToUpdate.nsfw) videoInstance.set('nsfw', videoInfosToUpdate.nsfw) - if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description) + if (videoInfosToUpdate.name !== undefined) videoInstance.set('name', videoInfosToUpdate.name) + if (videoInfosToUpdate.category !== undefined) videoInstance.set('category', videoInfosToUpdate.category) + if (videoInfosToUpdate.licence !== undefined) videoInstance.set('licence', videoInfosToUpdate.licence) + if (videoInfosToUpdate.language !== undefined) videoInstance.set('language', videoInfosToUpdate.language) + if (videoInfosToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfosToUpdate.nsfw) + if (videoInfosToUpdate.description !== undefined) videoInstance.set('description', videoInfosToUpdate.description) videoInstance.save(options).asCallback(function (err) { return callback(err, t, tagInstances) diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index 8dabb828d..196731e04 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js @@ -53,7 +53,7 @@ function isVideoLicenceValid (value) { } function isVideoLanguageValid (value) { - return constants.VIDEO_LANGUAGES[value] !== undefined + return value === null || constants.VIDEO_LANGUAGES[value] !== undefined } function isVideoNSFWValid (value) { -- 2.25.1