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

[4.0] Adding a manage button to the sample data module #33169

Merged
merged 6 commits into from
Apr 19, 2021

Conversation

Bakual
Copy link
Contributor

@Bakual Bakual commented Apr 16, 2021

As an partial alternative to #33165

Summary of Changes

Adds a button to the sample data module which leads to the plugin manager. Sampledata plugins will be prefiltered.

This certainly needs improvement on the design aspect (where I suck badly). So if anyone has an idea how this can be improved I'm open to suggestions or PRs :-)

Testing Instructions

Just use the button

Actual result BEFORE applying this Pull Request

image

Expected result AFTER applying this Pull Request

image

Buttons leads to
image

Documentation Changes Required

None

… plugin manager with sampledata plugins prefiltered.
@Quy
Copy link
Contributor

Quy commented Apr 16, 2021

Why not select Unpublish under the cog icon or add Manage to it if it is possible?

@Bakual
Copy link
Contributor Author

Bakual commented Apr 16, 2021

Why not select Unpublish under the cog icon or add Manage to it if it is possible?

Because that cog icon comes from the module chrome (not from the module itself). To my knowledge the module can't manipulate this part.

@ChristineWk
Copy link

I have tested this item ✅ successfully on df52e89

about the design: removing bottom border, as shown here #33106 and maybe .float-end margin? to hv alignment with the other (Install)


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33169.

@infograf768
Copy link
Member

please solve conflicts as #33168 was merged

@infograf768
Copy link
Member

I may have another solution to directly edit the plugin (color can be modified)

sampledata_plugins

@Bakual
Copy link
Contributor Author

Bakual commented Apr 17, 2021

A button to directly edit (or unpublish) the sample data plugin isn't possible easy because we don't know the ID of the plugin.
That would require changes in each sample data plugins onSampledataGetOverview method.
It can certainly be done, but has much more impact.

@infograf768
Copy link
Member

infograf768 commented Apr 17, 2021

We need to fetch the db. here is the modified file

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  mod_sampledata
 *
 * @copyright   (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Uri\Uri;

$app->getDocument()->getWebAssetManager()
	->registerAndUseScript('mod_sampledata', 'mod_sampledata/sampledata-process.js', [], ['defer' => true], ['core']);

Text::script('MOD_SAMPLEDATA_CONFIRM_START');
Text::script('MOD_SAMPLEDATA_ITEM_ALREADY_PROCESSED');
Text::script('MOD_SAMPLEDATA_INVALID_RESPONSE');

$app->getDocument()->addScriptOptions(
	'sample-data',
	[
		'icon' => Uri::root(true) . '/media/system/images/ajax-loader.gif'
	]
);
?>
<?php if ($items) : ?>
	<ul id="sample-data-wrapper" class="list-group list-group-flush">
		<?php foreach($items as $i => $item) : ?>
			<?php
				$db    = Factory::getDbo();
				$query = $db->getQuery(true)
					->select($db->quoteName('extension_id'))
					->from($db->quoteName('#__extensions'))
					->where(
						[
							$db->quoteName('folder') . ' = ' . $db->quote('sampledata'),
							$db->quoteName('type') . ' = ' . $db->quote('plugin'),
							$db->quoteName('element') . ' = ' . $db->quote($item->name),
						]
					);

				$db->setQuery($query);

				$id = $db->loadResult();
				$loadUrl = 'index.php?option=com_plugins&view=plugin&task=plugin.edit&extension_id=' . $id . '&amp;' . Session::getFormToken() . '=1';
			?>
			<li class="list-group-item sampledata-<?php echo $item->name; ?>">
				<div class="d-flex justify-content-between align-items-center">
					<div class="me-2">
						<span class="icon-<?php echo $item->icon; ?>" aria-hidden="true"></span>
						<?php echo htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8'); ?>
					</div>
					<div class="btn-group">
						<button type="button" class="btn btn-secondary btn-sm apply-sample-data" data-type="<?php echo $item->name; ?>" data-steps="<?php echo $item->steps; ?>">
							<span class="icon-upload" aria-hidden="true"></span> <?php echo Text::_('JLIB_INSTALLER_INSTALL'); ?>
							<span class="visually-hidden"><?php echo $item->title; ?></span>
						</button>
						<button type=button" class="btn btn-danger btn-sm manage-sample-data" onclick="location.href='<?php echo Route::_($loadUrl); ?>'">
							<span class="icon-tasks" aria-hidden="true"></span> <?php echo Text::_('JACTION_EDIT'); ?>
							<span class="visually-hidden"><?php echo Text::_('JACTION_EDIT'); ?></span>
						</button>
					</div>
				</div>
				<p class="small mt-1"><?php echo $item->description; ?></p>
				<?php // Progress bar ?>
				<div class="sampledata-progress-<?php echo $item->name; ?> d-none mb-3">
					<div class="progress">
						<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar"></div>
					</div>
				</div>
				<?php // Progress messages ?>
				<div class="sampledata-progress-<?php echo $item->name; ?> d-none">
					<ul class="list-unstyled"></ul>
				</div>
			</li>
		<?php endforeach; ?>
	</ul>
<?php endif; ?>

@Bakual
Copy link
Contributor Author

Bakual commented Apr 17, 2021

I've resolved the conflicts and added some margins to the button.
The border was already removed with a different PR elsewhere.

Looks now like this:
image

@Bakual
Copy link
Contributor Author

Bakual commented Apr 17, 2021

Fetching the DB is a no-go in my eyes. Also technically "name" doesn't necessary have to be the name of the plugin. It could be anything. It just happens to be the same name for the core plugins.

So if we want to have a direct button, we need to adjust the overview method so the plugin returns its own ID.

@particthistle
Copy link
Member

I have tested this item ✅ successfully on 91c4cac

@Bakual solution is straight forward and elegant. Only feedback is whether the button string should be "Manage Sample Data Plugins"

@infograf768 though I get what you're trying to allow for there, the buttons indicating "Edit" are misleading IMO... you're not "Editing" the sample data, you're managing the availability of the plugin.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33169.

@Bakual
Copy link
Contributor Author

Bakual commented Apr 17, 2021

Regarding the name of the button, I think "Manage Sample Data Plugins" gets to long. Maybe @brianteeman has a better idea for the text (I'm no no native english speaker).

@Bakual Bakual changed the title [4.0] RFC Adding a manage button to the sample data module [4.0] Adding a manage button to the sample data module Apr 17, 2021
@ChristineWk
Copy link

Buttons:
You don't have e.g: Install Sample Data, therefore there is no need for: Manage Sample Data :-)
In short:
Install
Manage


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33169.

@Bakual
Copy link
Contributor Author

Bakual commented Apr 17, 2021

Good point with the string, thanks! Change it.

image

@ChristineWk
Copy link

I have tested this item ✅ successfully on 29274b6


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33169.

@particthistle
Copy link
Member

I have tested this item ✅ successfully on ab2019e

Tested after code clean up and button name change. All works.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33169.

@ChristineWk
Copy link

I have tested this item ✅ successfully on ab2019e


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33169.

@Quy
Copy link
Contributor

Quy commented Apr 18, 2021

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33169.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Apr 18, 2021
@Quy Quy added this to the Joomla 4.0 milestone Apr 18, 2021
@rdeutz rdeutz merged commit a6e93b2 into joomla:4.0-dev Apr 19, 2021
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Apr 19, 2021
@Bakual Bakual deleted the 4_AddSampleDataManageButton branch April 19, 2021 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language Change This is for Translators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants