Preparing for Plugin Management UX (#3374)

Initial work on Plugin Management UX improvements by @Teranode for #2714
This commit is contained in:
Christian 2018-02-01 19:16:31 -05:00 committed by Luke Towers
parent 678916854e
commit cc81ab25fa
8 changed files with 224 additions and 144 deletions

View File

@ -795,52 +795,93 @@ class Updates extends Controller
return $this->listRefresh('manage');
}
public function onLoadDisableForm()
public function onBulkAction()
{
try {
$this->vars['checked'] = post('checked');
}
catch (Exception $ex) {
$this->handleError($ex);
}
return $this->makePartial('disable_form');
}
public function onDisablePlugins()
{
$disable = post('disable', false);
$freeze = post('freeze', false);
if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
if (($bulkAction = post('action')) && ($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
$manager = PluginManager::instance();
foreach ($checkedIds as $objectId) {
if (!$object = PluginVersion::find($objectId)) {
foreach ($checkedIds as $pluginId) {
if (!$plugin = PluginVersion::find($pluginId)) {
continue;
}
if ($disable) {
$manager->disablePlugin($object->code, true);
}
else {
$manager->enablePlugin($object->code, true);
}
switch ($bulkAction) {
case 'freeze':
$plugin->is_frozen = 1;
Flash::success(Lang::get('system::lang.plugins.freeze_success'));
break;
case 'unfreeze':
$plugin->is_frozen = 0;
Flash::success(Lang::get('system::lang.plugins.unfreeze_success'));
break;
case 'disable':
$plugin->is_disabled = 1;
$manager->disablePlugin($plugin->code, true);
Flash::success(Lang::get('system::lang.plugins.disable_success'));
break;
case 'enable':
$plugin->is_disabled = 0;
$manager->enablePlugin($plugin->code, true);
Flash::success(Lang::get('system::lang.plugins.enable_success'));
break;
$plugin->save();
$object->is_disabled = $disable;
$object->is_frozen = $freeze;
$object->save();
}
}
return $this->listRefresh('manage');
}
public function onToggleFreeze()
{
$plugin = PluginVersion::find(post('plugin_id'));
$freeze = post('freeze_' . $plugin->id);
$plugin->is_frozen = $freeze;
$plugin->save();
if($freeze) {
Flash::success(Lang::get('system::lang.plugins.freeze_success'));
} else {
Flash::success(Lang::get('system::lang.plugins.unfreeze_success'));
}
return $this->listRefresh('manage');
}
public function onToggleDisable()
{
$manager = PluginManager::instance();
$plugin = PluginVersion::find(post('plugin_id'));
$disable = post('disable_' . $plugin->id);
if ($disable) {
$manager->disablePlugin($plugin->code, true);
}
else {
$manager->enablePlugin($plugin->code, true);
}
$plugin->is_disabled = $disable;
$plugin->save();
if ($disable) {
Flash::success(Lang::get('system::lang.plugins.disable_success'));
}
else {
else{
Flash::success(Lang::get('system::lang.plugins.enable_success'));
}
return Backend::redirect('system/updates/manage');
return $this->listRefresh('manage');
}
//

View File

@ -1,70 +0,0 @@
<?= Form::open(['id' => 'disableForm']) ?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="popup">&times;</button>
<h4 class="modal-title"><?= e(trans('system::lang.plugins.enable_or_disable_title')) ?></h4>
</div>
<div class="modal-body">
<?php if ($this->fatalError): ?>
<p class="flash-message static error"><?= $fatalError ?></p>
<?php endif ?>
<p><?= e(trans('system::lang.plugins.selected_amount', ['amount'=>count($checked)])) ?></p>
<div class="form-preview">
<div class="form-group">
<!-- Checkbox -->
<div class="checkbox custom-checkbox">
<input
type="checkbox"
name="disable"
value="1"
id="pluginDisable">
<label for="pluginDisable">
<?= e(trans('system::lang.plugins.disabled_label')) ?>
</label>
<p class="help-block"><?= e(trans('system::lang.plugins.disabled_help')) ?></p>
</div>
</div>
<div class="form-group">
<!-- Checkbox -->
<div class="checkbox custom-checkbox">
<input
type="checkbox"
name="freeze"
value="1"
id="pluginFreeze">
<label for="pluginFreeze">
<?= e(trans('system::lang.plugins.frozen_label')) ?>
</label>
<p class="help-block"><?= e(trans('system::lang.plugins.frozen_help')) ?></p>
</div>
</div>
</div>
<?php foreach ($checked as $id): ?>
<input type="hidden" name="checked[]" value="<?= $id ?>" />
<?php endforeach ?>
</div>
<div class="modal-footer">
<button
type="submit"
class="btn btn-primary"
data-request="onDisablePlugins"
data-request-confirm="<?= e(trans('system::lang.plugins.disable_confirm')) ?>"
data-stripe-load-indicator>
<?= e(trans('backend::lang.form.apply')) ?>
</button>
<button
type="button"
class="btn btn-default"
data-dismiss="popup">
<?= e(trans('backend::lang.form.cancel')) ?>
</button>
</div>
<?= Form::close() ?>

View File

@ -0,0 +1,15 @@
<label class="custom-switch" data-check="oc-disable-<?= $record->id ?>" style="margin-bottom:0">
<input data-request="onToggleDisable"
data-request-data="plugin_id: <?= $record->id ?>"
data-request-update="list_manage_toolbar: '#plugin-toolbar'"
type="checkbox"
name="disable_<?= $record->id ?>"
value="<?= $record->is_disabled ?>"
<?php if($record->is_disabled): ?>checked=checked<?php endif ?>>
<span>
<span><?= e(trans('system::lang.plugins.check_yes')) ?></span>
<span><?= e(trans('system::lang.plugins.check_no')) ?></span>
</span>
<a class="slide-button"></a>
</label>

View File

@ -0,0 +1,15 @@
<label class="custom-switch" data-check="oc-freeze-<?= $record->id ?>" style="margin-bottom:0">
<input data-request="onToggleFreeze"
data-request-data="plugin_id: <?= $record->id ?>"
data-request-update="list_manage_toolbar: '#plugin-toolbar'"
type="checkbox"
name="freeze_<?= $record->id ?>"
value="<?= $record->is_frozen ?>"
<?php if($record->is_frozen): ?>checked=checked<?php endif ?>>
<span>
<span><?= e(trans('system::lang.plugins.check_yes')) ?></span>
<span><?= e(trans('system::lang.plugins.check_no')) ?></span>
</span>
<a class="slide-button"></a>
</label>

View File

@ -1,52 +1,87 @@
<div data-control="toolbar">
<div id="plugin-toolbar">
<div data-control="toolbar">
<a href="<?= Backend::url('system/updates') ?>" class="btn btn-default oc-icon-chevron-left">
<?= e(trans('system::lang.updates.return_link')) ?>
</a>
<div class="btn-group dropdown dropdown-fixed">
<button
data-primary-button
type="button"
class="btn btn-default"
data-toggle="dropdown"
data-trigger-action="enable"
data-trigger=".control-list .list-checkbox input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).prop('disabled', true).next().prop('disabled', true)"
data-stripe-load-indicator>
<?= e(trans('system::lang.plugins.select_label')) ?>
</button>
<button
type="button"
class="btn btn-default dropdown-toggle"
data-trigger-action="enable"
data-trigger=".control-list .list-checkbox input[type=checkbox]"
data-trigger-condition="checked"
data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" data-dropdown-title="<?= e(trans('rainlab.user::lang.users.bulk_actions')) ?>">
<li>
<a href="javascript:;" class="oc-icon-snowflake-o"
data-request="onBulkAction"
data-request-data="action: 'freeze', checked: $('.control-list').listWidget('getChecked')"
data-request-update="list_manage_toolbar: '#plugin-toolbar'"
data-request-confirm="<?= e(trans('system::lang.plugins.action_confirm', ['action' => e(trans('system::lang.plugins.freeze'))])) ?>">
<?= e(trans('system::lang.plugins.freeze_label')) ?>
</a>
</li>
<li>
<a href="javascript:;" class="oc-icon-snowflake-o"
data-request="onBulkAction"
data-request-data="action: 'unfreeze', checked: $('.control-list').listWidget('getChecked')"
data-request-update="list_manage_toolbar: '#plugin-toolbar'"
data-request-confirm="<?= e(trans('system::lang.plugins.action_confirm', ['action' => e(trans('system::lang.plugins.unfreeze'))])) ?>">
<?= e(trans('system::lang.plugins.unfreeze_label')) ?>
</a>
</li>
<li role="separator" class="divider"></li>
<li>
<a href="javascript:;" class="oc-icon-power-off"
data-request="onBulkAction"
data-request-data="action: 'disable', checked: $('.control-list').listWidget('getChecked')"
data-request-update="list_manage_toolbar: '#plugin-toolbar'"
data-request-confirm="<?= e(trans('system::lang.plugins.action_confirm', ['action' => e(trans('system::lang.plugins.disable'))])) ?>">
<?= e(trans('system::lang.plugins.disable_label')) ?>
</a>
</li>
<li>
<a href="javascript:;" class="oc-icon-power-off"
data-request="onBulkAction"
data-request-data="action: 'enable', checked: $('.control-list').listWidget('getChecked')"
data-request-update="list_manage_toolbar: '#plugin-toolbar'"
data-request-confirm="<?= e(trans('system::lang.plugins.action_confirm', ['action' => e(trans('system::lang.plugins.enable'))])) ?>">
<?= e(trans('system::lang.plugins.enable_label')) ?>
</a>
</li>
</ul>
</div>
<div class="btn-group">
<button
class="btn btn-default oc-icon-magic"
disabled="disabled"
onclick="$(this).data('request-data', {
checked: $('.control-list').listWidget('getChecked')
})"
data-control="popup"
data-handler="onLoadDisableForm"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-stripe-load-indicator>
<?= e(trans('system::lang.plugins.enable_or_disable')) ?>
</button>
<!--
<button
class="btn btn-default oc-icon-refresh"
disabled="disabled"
onclick="$(this).data('request-data', {
checked: $('.control-list').listWidget('getChecked')
})"
data-request="onRefreshPlugins"
data-request-confirm="<?= e(trans('system::lang.plugins.refresh_confirm')) ?>"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-stripe-load-indicator>
<?= e(trans('system::lang.plugins.refresh')) ?>
</button>
-->
<button
class="btn btn-default oc-icon-trash-o"
disabled="disabled"
onclick="$(this).data('request-data', {
checked: $('.control-list').listWidget('getChecked')
})"
data-request="onRemovePlugins"
data-request-data="checked: $('.control-list').listWidget('getChecked')"
data-request-update="list_manage_toolbar: '#plugin-toolbar'"
data-request-confirm="<?= e(trans('system::lang.plugins.remove_confirm')) ?>"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger=".control-list .list-checkbox input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).closest('.btn-group').find('button').prop('disabled', true)"
data-stripe-load-indicator>
<?= e(trans('system::lang.plugins.remove')) ?>
</button>
</div>
</div>
</div>
</div>

View File

@ -6,3 +6,25 @@
<?php Block::endPut() ?>
<?= $this->listRender('manage') ?>
<style>
td {
vertical-align: middle !important;
}
</style>
<!-- Unable to factor in where to put this script. I want to put it in a js file for global use of switch/checkboxes, but I don't know where.
ref issue: https://github.com/octobercms/october/issues/2714
-->
<script>
$("[data-check|='oc']").each(function() {
$(this).find('input').on('change', function() {
this.value = this.checked ? 1 : 0;
});
});
$(document).ajaxComplete(function() {
$("[data-check|='oc']").each(function() {
$(this).find('input').on('change', function() {
this.value = this.checked ? 1 : 0;
});
});
});
</script>

View File

@ -99,28 +99,38 @@ return [
],
'plugins' => [
'manage' => 'Manage plugins',
'enable_or_disable' => 'Enable or disable',
'enable_or_disable_title' => 'Enable or Disable Plugins',
'enable' => 'enable',
'disable' => 'disable',
'freeze' => 'freeze',
'unfreeze' => 'unfreeze',
'install' => 'Install plugins',
'install_products' => 'Install products',
'search' => 'search plugins to install...',
'installed' => 'Installed plugins',
'no_plugins' => 'There are no plugins installed from the marketplace.',
'recommended' => 'Recommended',
'remove' => 'Remove',
'remove_label' => 'Remove Plugins',
'remove' => 'remove',
'refresh' => 'Refresh',
'disabled_label' => 'Disabled',
'disabled_help' => 'Plugins that are disabled are ignored by the application.',
'frozen_label' => 'Freeze updates',
'frozen_help' => 'Plugins that are frozen will be ignored by the update process.',
'plugin_label' => 'Plugin',
'enable_label' => 'Enable Plugins',
'disable_label' => 'Disable Plugins',
'freeze_label' => 'Freeze Updates',
'unfreeze_label' => 'Unfreeze Updates',
'selected_amount' => 'Plugins selected: :amount',
'select_label' => 'Select Action...',
'check_yes' => 'Yes',
'check_no' => 'No',
'remove_confirm' => 'Are you sure you want to remove this plugin?',
'remove_success' => 'Successfully removed those plugins from the system.',
'refresh_confirm' => 'Are you sure?',
'refresh_success' => 'Successfully refreshed those plugins in the system.',
'action_confirm' => 'Are you sure you want to :action these plugins?',
'disable_confirm' => 'Are you sure?',
'disable_success' => 'Successfully disabled those plugins.',
'enable_success' => 'Successfully enabled those plugins.',
'disable_success' => 'Successfully disabled the selected plugins.',
'enable_success' => 'Successfully enabled the selected plugins.',
'freeze_success' => 'Successfully froze the selected plugins.',
'unfreeze_success' => 'Successfully unfroze the selected plugins.',
'unknown_plugin' => 'Plugin has been removed from the file system.'
],
'project' => [

View File

@ -12,4 +12,16 @@ columns:
version:
label: system::lang.updates.plugin_version
sortable: false
sortable: false
is_frozen:
label: system::lang.plugins.freeze_label
type: partial
path: is_frozen
sortable: false
is_disabled:
label: system::lang.plugins.disable_label
type: partial
path: is_disabled
sortable: false