Skip to content

Commit

Permalink
= 4.2.2,4 =
Browse files Browse the repository at this point in the history
~ Display notify new version Addons.
  • Loading branch information
tungnxt89 committed Mar 29, 2023
1 parent 6888175 commit f09148b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
38 changes: 36 additions & 2 deletions assets/src/apps/js/admin/admin-notices.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,38 @@ let dataHtml = null;
const queryString = window.location.search;
const urlParams = new URLSearchParams( queryString );
const tab = urlParams.get( 'tab' );
const notifyAddonsNewVersion = () => {
try {
const elAdminMenu = document.querySelector( '#adminmenu' );
if ( ! elAdminMenu ) {
return;
}
const elTabLP = elAdminMenu.querySelector( '#toplevel_page_learn_press' );
if ( ! elTabLP ) {
return;
}
const elTabLPName = elTabLP.querySelector( '.wp-menu-name' );
if ( ! elTabLPName ) {
return;
}
const htmlNotifyLP = `<span class="tab-lp-admin-notice"></span>`;
elTabLPName.insertAdjacentHTML( 'beforeend', htmlNotifyLP );
const elTabLPAddons = elTabLP.querySelector( 'a[href="admin.php?page=learn-press-addons"]' );
if ( ! elTabLPAddons ) {
return;
}
const elAddonsNewVerTotal = document.querySelector( 'input[name=lp-addons-new-version-totals]' );
if ( ! elAddonsNewVerTotal ) {
return;
}
const total = elAddonsNewVerTotal.value;
const html = `<span style="margin-left: 5px" class="update-plugins">${ total }</span>`;
elTabLPAddons.setAttribute( 'href', 'admin.php?page=learn-press-addons&tab=update' );
elTabLPAddons.insertAdjacentHTML( 'beforeend', html );
} catch ( e ) {
console.log( e );
}
};

const callAdminNotices = ( set = '' ) => {
if ( ! lpGlobalSettings.is_admin ) {
Expand Down Expand Up @@ -54,6 +86,8 @@ document.addEventListener( 'DOMContentLoaded', () => {
if ( dataHtml.length > 0 ) {
elLPAdminNotices.innerHTML = dataHtml;
elLPAdminNotices.style.display = 'block';
// Handle notify addons new version.
notifyAddonsNewVersion();
}

clearInterval( interval );
Expand All @@ -70,10 +104,10 @@ document.addEventListener( 'click', ( e ) => {

// eslint-disable-next-line no-alert
if ( confirm( 'Are you sure you want to dismiss this notice?' ) ) {
const parent = el.closest( '.lp-admin-notice' );
const parent = el.closest( '.lp-notice' );
callAdminNotices( `dismiss=${ el.getAttribute( 'data-dismiss' ) }` );
parent.remove();
if ( elLPAdminNotices.querySelectorAll( '.lp-admin-notice' ).length === 0 ) {
if ( elLPAdminNotices.querySelectorAll( '.lp-notice' ).length === 0 ) {
elLPAdminNotices.style.display = 'none';
}
}
Expand Down
10 changes: 10 additions & 0 deletions assets/src/scss/admin/_tool.scss
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,13 @@
}
}
}

.tab-lp-admin-notice {
margin-left: 5px;
width: 4px;
height: 4px;
background: #ff1919;
display: inline-flex;
border-radius: 999px;
vertical-align: middle
}
3 changes: 2 additions & 1 deletion inc/admin/views/admin-notices/addons-new-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<?php
Template::instance()->get_admin_template( 'admin-notices/button-dismiss.php', array( 'key' => 'lp-addons-new-version' ) );
?>
<p><?php echo sprintf( '<strong>%s</strong>', __( 'LearnPress has new version Addons.', 'learnpress' ) ); ?></p>
<p><?php echo sprintf( '<strong>%s</strong>', __( 'New version Addons.', 'learnpress' ) ); ?></p>
<p style="display: flex;gap: 5px">
<?php
foreach ( $data['addons'] as $addon ) {
Expand All @@ -32,4 +32,5 @@
}
?>
</p>
<input type="hidden" name="lp-addons-new-version-totals" value="<?php echo count( $data['addons'] ); ?>" />
</div>

0 comments on commit f09148b

Please sign in to comment.