Skip to content

Commit

Permalink
PROD-8099 Update photos and videos count relocate logic and support f…
Browse files Browse the repository at this point in the history
…or directory
  • Loading branch information
bb-yudhisthir committed Dec 16, 2024
1 parent 9b166d2 commit 01fe781
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 19 deletions.
18 changes: 18 additions & 0 deletions src/bp-templates/bp-nouveau/buddypress/media/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@
if ( ! bp_nouveau_is_object_nav_in_sidebar() ) :
bp_get_template_part( 'common/nav/directory-nav' );
endif;

$bp_nouveau = bp_nouveau();
if ( 'directory' === $bp_nouveau->displayed_nav && isset( $bp_nouveau->sorted_nav[0]->count ) ) {
$count = $bp_nouveau->sorted_nav[0]->count;
?>
<div class="bb-item-count">
<?php
if ( ! $is_send_ajax_request ) {
/* translators: %d is the photo count */
printf(
wp_kses( _n( '<span class="bb-count">%d</span> Photo', '<span class="bb-count">%d</span> Photos', $count, 'buddyboss' ), array( 'span' => array( 'class' => true ) ) ),
$count
);
}
?>
</div>
<?php
}
?>

<div class="media-options">
Expand Down
18 changes: 18 additions & 0 deletions src/bp-templates/bp-nouveau/buddypress/video/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@
if ( ! bp_nouveau_is_object_nav_in_sidebar() ) {
bp_get_template_part( 'common/nav/directory-nav' );
}

$bp_nouveau = bp_nouveau();
if ( 'directory' === $bp_nouveau->displayed_nav && isset( $bp_nouveau->sorted_nav[0]->count ) ) {
$count = $bp_nouveau->sorted_nav[0]->count;
?>
<div class="bb-item-count">
<?php
if ( ! $is_send_ajax_request ) {
/* translators: %d is the video count */
printf(
wp_kses( _n( '<span class="bb-count">%d</span> Video', '<span class="bb-count">%d</span> Videos', $count, 'buddyboss' ), array( 'span' => array( 'class' => true ) ) ),
$count
);
}
?>
</div>
<?php
}
?>

<div class="video-options">
Expand Down
38 changes: 30 additions & 8 deletions src/bp-templates/bp-nouveau/js/buddypress-media.js
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ window.bp = window.bp || {};
}
} else {
if ( response.data.media_personal_count ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 && 'yes' !== BP_Nouveau.media.is_media_directory ) {
var dir_label = BP_Nouveau.dir_labels.hasOwnProperty( 'media' ) ?
(
1 === parseInt( response.data.media_personal_count )
Expand All @@ -1295,7 +1295,7 @@ window.bp = window.bp || {};
}

if ( response.data.media_group_count ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 && 'yes' !== BP_Nouveau.media.is_media_directory ) {
var dir_label = BP_Nouveau.dir_labels.hasOwnProperty( 'media' ) ?
(
1 === parseInt( response.data.media_group_count )
Expand Down Expand Up @@ -5234,7 +5234,7 @@ window.bp = window.bp || {};
bp.Nouveau.inject( '#media-stream ul.media-list', response.data.media, 'prepend' );

if ( response.data.media_personal_count ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 && 'yes' !== BP_Nouveau.media.is_media_directory ) {
var dir_label = BP_Nouveau.dir_labels.hasOwnProperty( 'media' ) ?
(
1 === parseInt( response.data.media_personal_count )
Expand All @@ -5255,7 +5255,7 @@ window.bp = window.bp || {};
}

if ( response.data.media_group_count ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 && 'yes' !== BP_Nouveau.media.is_media_directory ) {
var dir_label = BP_Nouveau.dir_labels.hasOwnProperty( 'media' ) ?
(
1 === parseInt( response.data.media_group_count )
Expand All @@ -5276,9 +5276,31 @@ window.bp = window.bp || {};
}

if ( 'yes' === BP_Nouveau.media.is_media_directory ) {
$( '#buddypress' ).find( '.media-type-navs ul.media-nav li#media-all a span.count' ).text( response.data.media_all_count );
$( '#buddypress' ).find( '.media-type-navs ul.media-nav li#media-personal a span.count' ).text( response.data.media_personal_count );
$( '#buddypress' ).find( '.media-type-navs ul.media-nav li#media-groups a span.count' ).text( response.data.media_group_count );

if ( $( '#buddypress .bb-item-count' ).length > 0 ) {
var dir_scope = $( '#buddypress .bp-navs.dir-navs > ul > li.selected' ).data( 'bp-scope' );
var dir_count = 0;
if ( 'all' === dir_scope ) {
dir_count = response.data.media_all_count;
} else if ( 'personal' === dir_scope ) {
dir_count = response.data.media_personal_count;
} else if( 'groups' === dir_scope ) {
dir_count = response.data.media_group_count;
}

var dir_label = BP_Nouveau.dir_labels.hasOwnProperty( 'media' ) ?
(
1 === dir_count
? BP_Nouveau.dir_labels['media']['singular']
: BP_Nouveau.dir_labels['media']['plural']
)
: '';
$( '#buddypress .bb-item-count' ).html( '<span class="bb-count">' + dir_count + '</span> ' + dir_label );
} else {
$( '#buddypress' ).find( '.media-type-navs ul.media-nav li#media-all a span.count' ).text( response.data.media_all_count );
$( '#buddypress' ).find( '.media-type-navs ul.media-nav li#media-personal a span.count' ).text( response.data.media_personal_count );
$( '#buddypress' ).find( '.media-type-navs ul.media-nav li#media-groups a span.count' ).text( response.data.media_group_count );
}
}

for ( var i = 0; i < self.dropzone_media.length; i++ ) {
Expand Down Expand Up @@ -6498,7 +6520,7 @@ window.bp = window.bp || {};
if ( $( '.single-screen-navs.groups-nav' ).find( 'ul li#albums-groups-li' ).length < 1 ) {
return;
}
if ( $( '#buddypress .bb-item-count' ).length > 0 ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 && 'yes' !== BP_Nouveau.media.is_media_directory ) {
var dir_label = BP_Nouveau.dir_labels.hasOwnProperty( 'album' ) ?
(
1 === parseInt( count )
Expand Down
2 changes: 1 addition & 1 deletion src/bp-templates/bp-nouveau/js/buddypress-media.min.js

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/bp-templates/bp-nouveau/js/buddypress-nouveau.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,14 @@ window.bp = window.bp || {};
$( self.objectNavParent + ' [data-bp-scope="' + i + '"]' ).find( 'span' ).text( response.data.scopes[ i ] );
}

if ( ( $( 'body.groups' ).hasClass( 'single-item' ) || $( 'body.bp-user' ).hasClass( 'single' ) ) && ( 'media' === data.object || 'video' === data.object ) ) {
if (
(
$( 'body.groups' ).hasClass( 'single-item' ) ||
$( 'body.bp-user' ).hasClass( 'single' ) ||
$( 'body.directory' ).hasClass( 'media' ) ||
$( 'body.directory' ).hasClass( 'video' )
) && ( 'media' === data.object || 'video' === data.object )
) {
$( self.objectNavParent + ' .bb-item-count' ).html( '<span class="bb-count">' + response.data.scopes[ data.scope ] + '</span> ' + dir_label );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bp-templates/bp-nouveau/js/buddypress-nouveau.min.js

Large diffs are not rendered by default.

35 changes: 28 additions & 7 deletions src/bp-templates/bp-nouveau/js/buddypress-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ window.bp = window.bp || {};
}

if ( response.data.video_personal_count ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 && 'yes' !== BP_Nouveau.media.is_video_directory ) {
var dir_label = BP_Nouveau.dir_labels.hasOwnProperty( 'video' ) ?
(
1 === parseInt( response.data.video_personal_count )
Expand All @@ -440,7 +440,7 @@ window.bp = window.bp || {};
}

if ( response.data.video_group_count ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 && 'yes' !== BP_Nouveau.media.is_video_directory ) {
var dir_label = BP_Nouveau.dir_labels.hasOwnProperty( 'video' ) ?
(
1 === parseInt( response.data.video_group_count )
Expand All @@ -461,9 +461,30 @@ window.bp = window.bp || {};
}

if ( 'yes' === BP_Nouveau.video.is_video_directory ) {
$( '#buddypress' ).find( '.video-type-navs ul.video-nav li#video-all a span.count' ).text( response.data.video_all_count );
$( '#buddypress' ).find( '.video-type-navs ul.video-nav li#video-personal a span.count' ).text( response.data.video_personal_count );
$( '#buddypress' ).find( '.video-type-navs ul.video-nav li#video-groups a span.count' ).text( response.data.video_group_count );
if ( $( '#buddypress .bb-item-count' ).length > 0 ) {
var dir_scope = $( '#buddypress .bp-navs.dir-navs > ul > li.selected' ).data( 'bp-scope' );
var dir_count = 0;
if ( 'all' === dir_scope ) {
dir_count = response.data.video_all_count;
} else if ( 'personal' === dir_scope ) {
dir_count = response.data.video_personal_count;
} else if( 'groups' === dir_scope ) {
dir_count = response.data.video_group_count;
}

var dir_label = BP_Nouveau.dir_labels.hasOwnProperty( 'video' ) ?
(
1 === dir_count
? BP_Nouveau.dir_labels['video']['singular']
: BP_Nouveau.dir_labels['video']['plural']
)
: '';
$( '#buddypress .bb-item-count' ).html( '<span class="bb-count">' + dir_count + '</span> ' + dir_label );
} else {
$( '#buddypress' ).find( '.video-type-navs ul.video-nav li#video-all a span.count' ).text( response.data.video_all_count );
$( '#buddypress' ).find( '.video-type-navs ul.video-nav li#video-personal a span.count' ).text( response.data.video_personal_count );
$( '#buddypress' ).find( '.video-type-navs ul.video-nav li#video-groups a span.count' ).text( response.data.video_group_count );
}
}

for ( var i = 0; i < self.dropzone_video.length; i++ ) {
Expand Down Expand Up @@ -1632,7 +1653,7 @@ window.bp = window.bp || {};
'undefined' !== typeof response.data.video_personal_count
) {

if ( $( '#buddypress .bb-item-count' ).length > 0 ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 && 'yes' !== BP_Nouveau.media.is_video_directory ) {
var dir_label = BP_Nouveau.dir_labels.hasOwnProperty( 'video' ) ?
(
1 === parseInt( response.data.video_personal_count )
Expand All @@ -1650,7 +1671,7 @@ window.bp = window.bp || {};
'undefined' !== typeof response.data &&
'undefined' !== typeof response.data.video_group_count
) {
if ( $( '#buddypress .bb-item-count' ).length > 0 ) {
if ( $( '#buddypress .bb-item-count' ).length > 0 && 'yes' !== BP_Nouveau.media.is_video_directory ) {
var dir_label = BP_Nouveau.dir_labels.hasOwnProperty( 'video' ) ?
(
1 === parseInt( response.data.video_group_count )
Expand Down
2 changes: 1 addition & 1 deletion src/bp-templates/bp-nouveau/js/buddypress-video.min.js

Large diffs are not rendered by default.

0 comments on commit 01fe781

Please sign in to comment.