Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/multilingual metadata #256

Merged
merged 3 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 52 additions & 10 deletions assets/js/brightcove-admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/js/brightcove-admin.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions assets/js/brightcove-admin.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions assets/js/src/models/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ var MediaModel = Backbone.Model.extend({
thumbnail: this.get('thumbnail'),
captions: this.get('captions'),
labels: this.get('labels'),
sub_type: this.get('subType'),
language: this.get('language'),
});

var video_ids = this.get('video_ids');
Expand Down
60 changes: 50 additions & 10 deletions assets/js/src/views/video-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,40 @@ var VideoEditView = BrightcoveView.extend({
'click .attachment .check': 'removeAttachment',
'click .caption-secondary-fields .delete': 'removeCaptionRow',
'click .add-remote-caption': 'addCaptionRow',
'change .brightcove-variant': 'changeVariant',
'click .add-bc-label': 'addLabelRow',
'keypress .brightcove-labels': 'labelAutocomplete',
'click .bc-label-secondary-fields .delete': 'removeLabelRow',
},

/**
* Changes template variant based on current variant.
* @param event
*/
changeVariant: function (event) {
const valueSelected = this.$el.find('.brightcove-variant').val(),
options = this.model.toJSON();

let template;

if (valueSelected === 'none') {
template = wp.template('brightcove-video-edit');
$('.brightcove-variant-details').replaceWith(template(options));
} else {
let variantIndex = options.variants
.map(function (variant) {
return variant.language;
})
.indexOf(valueSelected);
let variant = options.variants[variantIndex];
variant.variantList = options.variants;
variant.valueSelected = valueSelected;
template = wp.template('brightcove-variants');

$('.brightcove-variant-details').replaceWith(template(variant));
}
},

back: function (event) {
event.preventDefault();

Expand Down Expand Up @@ -359,22 +388,33 @@ var VideoEditView = BrightcoveView.extend({
);
}

// Trim whitespace and commas from tags beginning/end.
this.model.set(
'tags',
this.$el
.find('.brightcove-tags')
.val()
.trim()
.replace(/(^,)|(,$)/g, ''),
);
const brightcoveTags = this.$el.find('.brightcove-tags');

if (brightcoveTags.length !== 0) {
// Trim whitespace and commas from tags beginning/end.
this.model.set(
'tags',
brightcoveTags
.val()
.trim()
.replace(/(^,)|(,$)/g, ''),
);
}

this.model.set('mediaType', 'videos');
this.model.set('height', this.$el.find('.brightcove-height').val());
this.model.set('width', this.$el.find('.brightcove-width').val());
this.model.set('mediaType', 'videos');
this.model.set('poster', this.$el.find('.brightcove-poster').val());
this.model.set('thumbnail', this.$el.find('.brightcove-thumbnail').val());
this.model.set('folderId', this.$el.find('.brightcove-folder').val());

const isVariant = this.$el.find('.brightcove-variant').val();

if (isVariant !== 'none' && this.model.get('mediaType') === 'videos') {
this.model.set('subType', 'variant');
this.model.set('language', isVariant);
}

// Captions
var captions = [];
this.$el
Expand Down
65 changes: 32 additions & 33 deletions includes/admin/api/class-bc-admin-media-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public function bc_ajax_update_video_or_playlist() {
'state',
'scheduled_start_date',
'scheduled_end_date',
'sub_type',
'language'
);

foreach ( $fields as $field ) {
Expand Down Expand Up @@ -217,42 +219,45 @@ public function bc_ajax_update_video_or_playlist() {
$type_msg = 'playlist';

} elseif ( 'videos' === $_POST['type'] ) {

$status = $this->videos->update_bc_video( $updated_data );
$type_msg = 'video';
if ( 'variant' === $_POST['sub_type'] ) {
$status = $this->videos->update_bc_video( $updated_data, sanitize_text_field( $_POST['sub_type'] ) );
} else {
$status = $this->videos->update_bc_video( $updated_data );

if ( isset( $_POST['folderId'] ) && isset( $_POST['oldFolderId'] ) ) {
$folderId = sanitize_text_field( $_POST['folderId'] );
$oldFolderId = sanitize_text_field( $_POST['oldFolderId'] );
if ( isset( $_POST['folderId'] ) && isset( $_POST['oldFolderId'] ) ) {
$folderId = sanitize_text_field( $_POST['folderId'] );
$oldFolderId = sanitize_text_field( $_POST['oldFolderId'] );

$this->cms_api->add_folder_to_video( $oldFolderId, $folderId, $updated_data['video_id'] );
}
$this->cms_api->add_folder_to_video( $oldFolderId, $folderId, $updated_data['video_id'] );
}

// Maybe update poster
if ( isset( $_POST['poster'] ) ) {
$poster_data = json_decode( wp_unslash( $_POST['poster'] ), true );
// Maybe update poster
if ( isset( $_POST['poster'] ) ) {
$poster_data = json_decode( wp_unslash( $_POST['poster'] ), true );

if ( $poster_data ) {
// Maybe update poster
$this->ajax_poster_upload( $hash, $updated_data['video_id'], $poster_data['url'], $poster_data['width'], $poster_data['height'] );
if ( $poster_data ) {
// Maybe update poster
$this->ajax_poster_upload( $hash, $updated_data['video_id'], $poster_data['url'], $poster_data['width'], $poster_data['height'] );
}
}
}

// Maybe update thumbnail
if ( isset( $_POST['thumbnail'] ) ) {
$thumb_data = json_decode( wp_unslash( $_POST['thumbnail'] ), true );
// Maybe update thumbnail
if ( isset( $_POST['thumbnail'] ) ) {
$thumb_data = json_decode( wp_unslash( $_POST['thumbnail'] ), true );

if ( $thumb_data ) {
// Maybe update poster
$this->ajax_thumb_upload( $hash, $updated_data['video_id'], $thumb_data['url'], $thumb_data['width'], $thumb_data['height'] );
if ( $thumb_data ) {
// Maybe update poster
$this->ajax_thumb_upload( $hash, $updated_data['video_id'], $thumb_data['url'], $thumb_data['width'], $thumb_data['height'] );
}
}
}

if ( isset( $_POST['captions'] ) ) {
// Maybe update captions
$this->ajax_caption_upload( $hash, $updated_data['video_id'], $_POST['captions'] );
} else {
$this->ajax_caption_delete( $hash, $updated_data['video_id'] );
if ( isset( $_POST['captions'] ) ) {
// Maybe update captions
$this->ajax_caption_upload( $hash, $updated_data['video_id'], $_POST['captions'] );
} else {
$this->ajax_caption_delete( $hash, $updated_data['video_id'] );
}
}
}

Expand Down Expand Up @@ -434,13 +439,7 @@ public function brightcove_media_upload() {
*
* @return array An array of media items.
*/
public function fetch_all(
$type,
$posts_per_page = 100,
$page = 1,
$query_string = '',
$sort_order = 'updated_at'
) {
public function fetch_all( $type, $posts_per_page = 100, $page = 1, $query_string = '', $sort_order = 'updated_at' ) {

global $bc_accounts;

Expand Down
Loading