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

Allow creating multiple dashboard widgets #349

Merged
merged 9 commits into from
Sep 2, 2024
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
70 changes: 41 additions & 29 deletions friends-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,40 +344,52 @@ jQuery( function ( $ ) {
}
} );

var updateDashboardWidget = function() {
if ( 0 === $( '#friends-dashboard-widget' ).find( 'li.friends-post' ).length ) {
$( '#friends-dashboard-widget' ).append( ' <i class="friends-loading"></i>' );
}
$.post(
friends.ajax_url,
{
_ajax_nonce: $( '#friends-dashboard-widget' ).data( 'nonce' ),
var updateDashboardWidgets = function() {
console.log( 'updateDashboardWidgets' );
$( '.friends-dashboard-widget' ).each( function() {
const $this = $( this );
if ( $this.find( 'li.friends-post' ).length ) {
$( '#friends-dashboard-widget' ).append( ' <i class="friends-loading"></i>' );
}
const data = {
_ajax_nonce: $this.data( 'nonce' ),
action: 'friends_dashboard',
},
function ( response ) {
if ( response.success ) {
if ( 0 === $( '#friends-dashboard-widget' ).find( 'li.friends-post' ).length ) {
$( '#friends-dashboard-widget' ).html( response.data );
};
if ( $this.data( 'friend' ) ) {
data.friend = $this.data( 'friend' );
}
if ( $this.data( 'format' ) ) {
data.format = $this.data( 'format' );
}
console.log( data );
$.post(
friends.ajax_url,
data,
function ( response ) {
if ( response.success ) {
if ( ! $this.find( 'li.friends-post' ).length ) {
$this.html( response.data );
} else {
$( response.data ).find( 'li.friends-post' ).reverse().each( function () {
if ( ! document.getElementById( $( this ).attr('id') ) ) {
$this.find( 'ul' ).prepend( this );
}
} );
$( '.friends-dashboard-widget li.friends-post:gt(49)' ).remove();
}
} else {
$( response.data ).find( 'li.friends-post' ).reverse().each( function () {
if ( ! document.getElementById( $(this).attr('id') ) ) {
$( '#friends-dashboard-widget ul' ).prepend( this );
}
} );
$( '#friends-dashboard-widget li.friends-post:gt(49)' ).remove();
$this.find( 'i' )
.removeClass( 'friends-loading' )
.addClass( 'dashicons dashicons-warning' )
.prop( 'title', response.data );
}
} else {
$( '#friends-dashboard-widget i' )
.removeClass( 'friends-loading' )
.addClass( 'dashicons dashicons-warning' )
.prop( 'title', response.data );
}
}
);
);
} );
};
if ( $( '#friends-dashboard-widget' ).length ) {
updateDashboardWidget();
setInterval( updateDashboardWidget, 60000 );
if ( $( '.friends-dashboard-widget' ).length ) {
updateDashboardWidgets();
setInterval( updateDashboardWidgets, 60000 );
}

setTimeout( function () {
Expand Down
Loading
Loading