Skip to content

Commit

Permalink
Merge branch 'PRESS0-1724' of github.com:newfold-labs/wp-module-solut…
Browse files Browse the repository at this point in the history
…ions into PRESS0-1724
  • Loading branch information
ramyakrishnai committed Oct 7, 2024
2 parents c3eb3d7 + be1fc18 commit d23b2f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
5 changes: 4 additions & 1 deletion includes/Solutions.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ public static function my_plugins_and_tools_tab_enqueue_assets() {
}
wp_enqueue_style( 'nfd_myplugin_solutions_css', NFD_SOLUTIONS_PLUGIN_URL . 'vendor/newfold-labs/wp-module-solutions/includes/css/myPluginsTools.css', array(), '1.0' );
wp_enqueue_script('nfd_myplugin_solutions_js', NFD_SOLUTIONS_PLUGIN_URL . 'vendor/newfold-labs/wp-module-solutions/includes/js/myPluginsTools.js', array(), '1.0', true );

wp_localize_script( 'nfd_myplugin_solutions_js', 'pluigin_details', array(
'installed_plugins' => get_plugins(),
'active_plugins' => get_option( 'active_plugins' )
) );
}

}
26 changes: 20 additions & 6 deletions includes/js/myPluginsTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,37 @@ class MyPluginTools {
.then((response) => response.json()).then(res => {

const pluginsData = res?.data?.entitlements?.filter(data => data?.type === 'plugin' );

console.log(pluginsData)
this.setUpContainer(pluginsData);
this.entitlements_list = res?.data;
const installedPlugins = Object.keys(pluigin_details?.installed_plugins)
const pluginWithStatus = pluginsData.map(val => ({
...val,
isInstalled: installedPlugins?.includes( val.basename ),
isActive: pluigin_details?.active_plugins?.includes( val.basename ),
nonce: pluigin_details?.nonce
}))
this.setUpContainer(pluginWithStatus);
})

})

}

getElementByStatus( isActive, isInstalled, pluginData ) {
if( isActive && isInstalled ){
return `<a href=${pluginData?.cta?.url} target="_blank" class="nfd-solutions-availble-list-item-button">${pluginData?.cta?.text}</a>`;
}else if ( isInstalled ){
return `<a href="plugins.php?action=activate&plugin=${pluginData?.basename}&plugin_status=all&paged=1&s&_wpnonce=${nfdplugin.restApiNonce}" class="nfd-solutions-availble-list-item-button">Activate</a>`;
}else {
return `<a href=${pluginData?.url} target="_blank" class="nfd-solutions-availble-list-item-button" data-nfd-installer-plugin-slug=${pluginData?.slug} data-nfd-installer-plugin-provider=${pluginData?.providerName}>Install</a>`;
}
}

buildPluginsBlock( pluginData ) {
return `<div class="nfd-solutions-availble-list-item">
<div><img src=${pluginData?.image?.primaryImage} width="128px" height="128px" /></div>
<div class="details">
<h3 class="nfd-solutions-availble-list-item-title">${pluginData?.name}</h3>
<div>
<a href=${pluginData?.cta?.url} target="_blank" class="nfd-solutions-availble-list-item-button">${pluginData?.cta?.text}</a>
${this.getElementByStatus( pluginData?.isActive, pluginData?.isInstalled, pluginData )}
</div>
<p>${pluginData?.description}</p>
</div>
Expand All @@ -50,4 +64,4 @@ class MyPluginTools {
}
}

const pluginList = new MyPluginTools();
const pluginList = new MyPluginTools();

0 comments on commit d23b2f6

Please sign in to comment.