From cc81ab25fa2d1348df2290b714611b3d039f01e5 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 1 Feb 2018 19:16:31 -0500 Subject: [PATCH] Preparing for Plugin Management UX (#3374) Initial work on Plugin Management UX improvements by @Teranode for #2714 --- modules/system/controllers/Updates.php | 97 +++++++++++----- .../controllers/updates/_disable_form.htm | 70 ------------ .../controllers/updates/_is_disabled.htm | 15 +++ .../system/controllers/updates/_is_frozen.htm | 15 +++ .../updates/_list_manage_toolbar.htm | 107 ++++++++++++------ modules/system/controllers/updates/manage.htm | 22 ++++ modules/system/lang/en/lang.php | 28 +++-- .../models/pluginversion/columns_manage.yaml | 14 ++- 8 files changed, 224 insertions(+), 144 deletions(-) delete mode 100644 modules/system/controllers/updates/_disable_form.htm create mode 100644 modules/system/controllers/updates/_is_disabled.htm create mode 100644 modules/system/controllers/updates/_is_frozen.htm diff --git a/modules/system/controllers/Updates.php b/modules/system/controllers/Updates.php index ef8c4eccc..457edbbd6 100644 --- a/modules/system/controllers/Updates.php +++ b/modules/system/controllers/Updates.php @@ -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'); } // diff --git a/modules/system/controllers/updates/_disable_form.htm b/modules/system/controllers/updates/_disable_form.htm deleted file mode 100644 index 997ed6247..000000000 --- a/modules/system/controllers/updates/_disable_form.htm +++ /dev/null @@ -1,70 +0,0 @@ - 'disableForm']) ?> - - - - - diff --git a/modules/system/controllers/updates/_is_disabled.htm b/modules/system/controllers/updates/_is_disabled.htm new file mode 100644 index 000000000..3dcdaa1cc --- /dev/null +++ b/modules/system/controllers/updates/_is_disabled.htm @@ -0,0 +1,15 @@ + diff --git a/modules/system/controllers/updates/_is_frozen.htm b/modules/system/controllers/updates/_is_frozen.htm new file mode 100644 index 000000000..25b53148b --- /dev/null +++ b/modules/system/controllers/updates/_is_frozen.htm @@ -0,0 +1,15 @@ + diff --git a/modules/system/controllers/updates/_list_manage_toolbar.htm b/modules/system/controllers/updates/_list_manage_toolbar.htm index 8b0788a64..e8e849ffc 100644 --- a/modules/system/controllers/updates/_list_manage_toolbar.htm +++ b/modules/system/controllers/updates/_list_manage_toolbar.htm @@ -1,52 +1,87 @@ -
+
+
+ +
- -
-
\ No newline at end of file +
+
diff --git a/modules/system/controllers/updates/manage.htm b/modules/system/controllers/updates/manage.htm index c96effa9f..1550998ff 100644 --- a/modules/system/controllers/updates/manage.htm +++ b/modules/system/controllers/updates/manage.htm @@ -6,3 +6,25 @@ listRender('manage') ?> + + + diff --git a/modules/system/lang/en/lang.php b/modules/system/lang/en/lang.php index 50e066b5c..8366773fa 100644 --- a/modules/system/lang/en/lang.php +++ b/modules/system/lang/en/lang.php @@ -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' => [ diff --git a/modules/system/models/pluginversion/columns_manage.yaml b/modules/system/models/pluginversion/columns_manage.yaml index fbbcf50bc..f2492bbaa 100644 --- a/modules/system/models/pluginversion/columns_manage.yaml +++ b/modules/system/models/pluginversion/columns_manage.yaml @@ -12,4 +12,16 @@ columns: version: label: system::lang.updates.plugin_version - sortable: false \ No newline at end of file + 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