From cf6bfff8cc628034a46f16a561a77649cec9945a Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sat, 5 Mar 2016 20:58:19 +0100 Subject: [PATCH] Complete client-side dependencies management. Add information of which plugin needed an additional package that can now be deleted since not required any more --- themes/grav/app/plugins/index.js | 58 +++++++++---------- .../partials/plugins-details.html.twig | 10 ++-- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/themes/grav/app/plugins/index.js b/themes/grav/app/plugins/index.js index f6ec8518..6d691daa 100644 --- a/themes/grav/app/plugins/index.js +++ b/themes/grav/app/plugins/index.js @@ -43,38 +43,41 @@ $(document).on('click', '[data-plugin-action="remove-plugin"]', (event) => { } }, (response) => { if (response.status == 'success') { - // Go to Step 2 - loadPluginDependencies(slug, function(dependencies) { - $('.remove-plugin-step-1').addClass('hidden'); + $('.remove-plugin-confirm').addClass('hidden'); - if (dependencies.length > 0) { - addDependenciesToList(dependencies); - $('.remove-plugin-step-2').removeClass('hidden'); - } else { - $('.remove-plugin-done').removeClass('hidden'); - } + if (response.dependencies.length > 0) { + addDependenciesToList(response.dependencies); + $('.remove-plugin-dependencies').removeClass('hidden'); + } else { + $('.remove-plugin-done').removeClass('hidden'); + getBackToPluginsList(); + } + + //The plugin was removed. When the modal closes, move to the plugins list + $(document).on('closing', '[data-remodal-id="delete-plugin"]', function (e) { + getBackToPluginsList(); }); } }); }); -var loadPluginDependencies = function loadPluginDependencies(plugin, callback) { - let url = `${config.base_url_relative}/plugins.json/task${config.param_sep}getPluginDependencies/plugin:${plugin}/admin-nonce${config.param_sep}${config.admin_nonce}`; - request(url, { - method: 'get', - }, (response) => { - callback(response.dependencies); - }); -} - -var addDependencyToList = function addDependencyToList(dependency) { - var container = $('.plugin-dependencies-container'); - container.append(`
  • ${dependency} Remove
  • `); +var getBackToPluginsList = function getBackToPluginsList() { + window.location.href = `${config.base_url_relative}/plugins`; }; -var addDependenciesToList = function addDependenciesToList(dependencies) { +var addDependencyToList = function addDependencyToList(dependency, slug = '') { + var container = $('.plugin-dependencies-container'); + var text = `${dependency} Remove`; + if (slug) { + text += ` (was needed by ${slug})`; + } + + container.append(`
  • ${text}
  • `); +}; + +var addDependenciesToList = function addDependenciesToList(dependencies, slug = '') { dependencies.forEach(function(dependency) { - addDependencyToList(dependency); + addDependencyToList(dependency, slug); }); }; @@ -95,12 +98,9 @@ $(document).on('click', '[data-plugin-action="remove-dependency"]', (event) => { $(event.target).removeClass('button'); $(event.target).replaceWith($('Removed successfully')); - // add further dependencies i can remove to the bottom of the list - loadPluginDependencies(slug, function(dependencies) { - if (dependencies.length > 0) { - addDependenciesToList(dependencies); - } - }); + if (response.dependencies.length > 0) { + addDependenciesToList(response.dependencies, slug); + } } }); }); diff --git a/themes/grav/templates/partials/plugins-details.html.twig b/themes/grav/templates/partials/plugins-details.html.twig index 87e10079..fc8a1803 100644 --- a/themes/grav/templates/partials/plugins-details.html.twig +++ b/themes/grav/templates/partials/plugins-details.html.twig @@ -65,7 +65,7 @@ >
    -
    +

    Remove the plugin

    Are you sure you want to delete this plugin? @@ -77,13 +77,13 @@

    -