Skip to content

Commit

Permalink
Added an option to reinstall a plugin/theme already installed #984
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviocopes committed Feb 19, 2017
1 parent 063c501 commit 0c91ca5
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 48 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v1.2.15
## 02/xx/2017

1. [](#new)
* Added an option to reinstall a plugin/theme already installed [#984](https://github.com/getgrav/grav-plugin-admin/issues/984)

# v1.2.14
## 02/17/2017

Expand Down
21 changes: 18 additions & 3 deletions classes/admincontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ protected function taskInstallDependenciesOfPackages()
return true;
}

protected function taskInstallPackage()
protected function taskInstallPackage($reinstall = false)
{
$data = $this->post;
$package = isset($data['package']) ? $data['package'] : '';
Expand Down Expand Up @@ -994,12 +994,16 @@ protected function taskInstallPackage()
'status' => 'success',
'message' => $this->admin->translate(is_string($result)
? $result
: sprintf($this->admin->translate('PLUGIN_ADMIN.PACKAGE_X_INSTALLED_SUCCESSFULLY', null), $package))
: sprintf($this->admin->translate(
$reinstall ? 'PLUGIN_ADMIN.PACKAGE_X_REINSTALLED_SUCCESSFULLY' : 'PLUGIN_ADMIN.PACKAGE_X_INSTALLED_SUCCESSFULLY'
, null), $package))
];
} else {
$this->admin->json_response = [
'status' => 'error',
'message' => $this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED')
'message' => $this->admin->translate(
$reinstall ? 'PLUGIN_ADMIN.REINSTALLATION_FAILED' : 'PLUGIN_ADMIN.INSTALLATION_FAILED'
)
];
}

Expand Down Expand Up @@ -1066,6 +1070,17 @@ protected function taskRemovePackage()
return true;
}

/**
* Handle reinstalling a package
*
* @return bool
*/
protected function taskReinstallPackage()
{
$reinstall = true;
$this->taskInstallPackage($reinstall);
}

/**
* Handle the email password recovery procedure.
*
Expand Down
10 changes: 9 additions & 1 deletion languages/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,12 @@ PLUGIN_ADMIN:
ALLOW_WEBSERVER_GZIP_HELP: "Off by default. When enabled, WebServer-configured Gzip/Deflate compression will work, but http connection will not be closed before onShutDown() event causing slower page loading"
OFFLINE_WARNING: "The connection to the GPM cannot be established"
CLI_COMPATIBILITY: "CLI Compatibility"
CLI_COMPATIBILITY_HELP: "Ensures that only non-volatile Cache drivers are used (file, redis, memcache, etc.)"
CLI_COMPATIBILITY_HELP: "Ensures that only non-volatile Cache drivers are used (file, redis, memcache, etc.)"
REINSTALL_PLUGIN: "Reinstall Plugin"
REINSTALL_THEME: "Reinstall Theme"
REINSTALL_THE: "Reinstall the %"
CONFIRM_REINSTALL: "Are you sure you want to reinstall this %s?"
REINSTALLED_SUCCESSFULLY: "%s reinstalled successfully"
ERROR_REINSTALLING_THE: "Error reinstalling the %s"
PACKAGE_X_REINSTALLED_SUCCESSFULLY: "Package %s reinstalled successfully"
REINSTALLATION_FAILED: "Reinstallation failed"
5 changes: 5 additions & 0 deletions themes/grav/app/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ $(document).on('click', '[data-plugin-action="remove-package"]', (event) => {
packages.handleRemovingPackage('plugin', event);
});

// Reinstall plugin
$(document).on('click', '[data-plugin-action="reinstall-package"]', (event) => {
packages.handleReinstallPackage('plugin', event);
});

$(document).on('click', '[data-plugin-action="remove-dependency-package"]', (event) => {
packages.handleRemovingDependency('plugin', event);
});
Expand Down
5 changes: 5 additions & 0 deletions themes/grav/app/themes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ $(document).on('click', '[data-theme-action="remove-package"]', (event) => {
packages.handleRemovingPackage('theme', event);
});

// Reinstall theme
$(document).on('click', '[data-plugin-action="reinstall-package"]', (event) => {
packages.handleReinstallPackage('theme', event);
});

$(document).on('click', '[data-theme-action="remove-dependency-package"]', (event) => {
packages.handleRemovingDependency('theme', event);
});
Expand Down
19 changes: 13 additions & 6 deletions themes/grav/app/updates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default class Updates {
return this.maintenance('hide');
}

let is_single_package_latest = true;
let map = ['plugins', 'themes'];
let singles = ['plugin', 'theme'];
let { plugins, themes } = this.payload.resources;
Expand Down Expand Up @@ -145,18 +146,24 @@ export default class Updates {
if (details.length) {
let releaseType = resources[item].type === 'testing' ? '<span class="gpm-testing">test release</span>' : '';
details.html(`
<p>
<a href="#" class="button button-small secondary" data-remodal-target="update-packages" data-packages-slugs="${item}" data-${singles[index]}-action="start-package-installation">${translations.PLUGIN_ADMIN.UPDATE} ${singles[index].charAt(0).toUpperCase() + singles[index].substr(1).toLowerCase()}</a>
<i class="fa fa-bullhorn"></i>
<strong>v${resources[item].available}</strong> ${releaseType} ${translations.PLUGIN_ADMIN.OF_THIS} ${singles[index]} ${translations.PLUGIN_ADMIN.IS_NOW_AVAILABLE}!
</p>
`).css('display', 'block');
<p>
<a href="#" class="button button-small secondary" data-remodal-target="update-packages" data-packages-slugs="${item}" data-${singles[index]}-action="start-package-installation">${translations.PLUGIN_ADMIN.UPDATE} ${singles[index].charAt(0).toUpperCase() + singles[index].substr(1).toLowerCase()}</a>
<i class="fa fa-bullhorn"></i>
<strong>v${resources[item].available}</strong> ${releaseType} ${translations.PLUGIN_ADMIN.OF_THIS} ${singles[index]} ${translations.PLUGIN_ADMIN.IS_NOW_AVAILABLE}!
</p>
`).css('display', 'block');

is_single_package_latest = false;
}
}
});

$('[data-update-packages]').removeClass('hidden');
});

if (is_single_package_latest) {
$('.button-reinstall-package').removeClass('hidden');
}
}
}

Expand Down
36 changes: 36 additions & 0 deletions themes/grav/app/utils/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class Packages {
return `${Packages.getTaskUrl(type, 'removePackage')}`;
}

static getReinstallPackageUrl(type) {
return `${Packages.getTaskUrl(type, 'reinstallPackage')}`;
}

static getGetPackagesDependenciesUrl(type) {
return `${Packages.getTaskUrl(type, 'getPackagesDependencies')}`;
}
Expand Down Expand Up @@ -145,6 +149,30 @@ class Packages {
});
}

reinstallPackage(type, slug) {
let url = Packages.getReinstallPackageUrl(type);

request(url, {
method: 'post',
body: {
package: slug
}
}, (response) => {
if (response.status === 'success') {
$('.reinstall-package-confirm').addClass('hidden');
$('.reinstall-package-done').removeClass('hidden');

// The package was reinstalled. When the modal closes, move to the packages list
$(document).on('closing', '[data-remodal-id="reinstall-package"]', () => {
Packages.getBackToList(type);
});
} else {
$('.reinstall-package-confirm').addClass('hidden');
$('.reinstall-package-error').removeClass('hidden');
}
});
}

removeDependency(type, slug, button) {
let url = Packages.getRemovePackageUrl(type);

Expand Down Expand Up @@ -401,6 +429,14 @@ class Packages {
this.removePackage(type, slug);
}

handleReinstallPackage(type, event) {
let slug = $(event.target).attr('data-packages-slugs');
event.preventDefault();
event.stopPropagation();

this.reinstallPackage(type, slug);
}

handleRemovingDependency(type, event) {
let slug = $(event.target).attr('data-dependency-slug');
let button = $(event.target);
Expand Down
32 changes: 16 additions & 16 deletions themes/grav/js/admin.min.js

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions themes/grav/js/vendor.min.js

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions themes/grav/templates/partials/modal-reinstall-package.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="remodal"
data-remodal-id="reinstall-package"
data-remodal-options="hashTracking: false">
<form>
<div class="reinstall-package-confirm">
<h1>{{ "PLUGIN_ADMIN.REINSTALL_THE"|tu([("PLUGIN_ADMIN." ~ type|upper)|tu]) }}</h1>
<p class="bigger">
{{ "PLUGIN_ADMIN.CONFIRM_REINSTALL"|tu([("PLUGIN_ADMIN." ~ type|upper)|tu]) }}
</p>

<div class="button-bar">
<button data-remodal-action="cancel" class="button secondary remodal-cancel"><i class="fa fa-fw fa-close"></i> {{ "PLUGIN_ADMIN.CANCEL"|tu }}</button>
<button data-{{ type }}-action="reinstall-package" data-packages-slugs="{{ package.slug }}" class="button"><i class="fa fa-fw fa-check"></i> {{ "PLUGIN_ADMIN.CONTINUE"|tu }}</button>
</div>
</div>

<div class="reinstall-package-done hidden">
<h1>{{ "PLUGIN_ADMIN.REINSTALLED_SUCCESSFULLY"|tu([("PLUGIN_ADMIN." ~ type|upper)|tu]) }}</h1>
<div class="button-bar">
<a href="{{ base_url_relative ~ '/' ~ type ~ 's' }}" class="button secondary"><i class="fa fa-fw fa-close"></i> {{ "PLUGIN_ADMIN.CLOSE"|tu }}</a>
</div>
</div>

<div class="reinstall-package-error hidden">
<h1>{{ "PLUGIN_ADMIN.ERROR_REINSTALLING_THE"|tu([("PLUGIN_ADMIN." ~ type|upper)|tu]) }}</h1>
<div class="button-bar">
<button data-remodal-action="cancel" class="button secondary remodal-cancel"><i class="fa fa-fw fa-close"></i> {{ "PLUGIN_ADMIN.CANCEL"|tu }}</button>
</div>
</div>
</form>
</div>
2 changes: 2 additions & 0 deletions themes/grav/templates/partials/plugins-details.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
{% if (plugin.form.fields.enabled.type != 'hidden' and plugin.form.fields.tabs.fields.login.fields.enabled.type != 'hidden') %}
<div class="button-bar danger">
<span class="danger-zone"></span>
<a class="button hidden button-reinstall-package" href="#" data-remodal-target="reinstall-package"><i class="fa fa-fw fa-repeat"></i> {{ "PLUGIN_ADMIN.REINSTALL_PLUGIN"|tu }}</a>
<a class="button" href="#" data-remodal-target="remove-package"><i class="fa fa-fw fa-warning"></i> {{ "PLUGIN_ADMIN.REMOVE_PLUGIN"|tu }}</a>
</div>
{% endif %}
Expand All @@ -56,3 +57,4 @@
{% include 'partials/modal-add-package.html.twig' with { type: 'plugin' } %}
{% include 'partials/modal-update-packages.html.twig' with { type: 'plugin' } %}
{% include 'partials/modal-remove-package.html.twig' with { type: 'plugin', package: plugin } %}
{% include 'partials/modal-reinstall-package.html.twig' with { type: 'plugin', package: plugin } %}
2 changes: 2 additions & 0 deletions themes/grav/templates/partials/themes-details.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
{% if (config.get('system.pages.theme') != admin.route) %}
<div class="button-bar danger">
<span class="danger-zone"></span>
<a class="button hidden button-reinstall-package" href="#" data-remodal-target="reinstall-package"><i class="fa fa-fw fa-repeat"></i> {{ "PLUGIN_ADMIN.REINSTALL_THEME"|tu }}</a>
<a class="button" href="#" data-remodal-target="remove-package"><i class="fa fa-fw fa-warning"></i> {{ "PLUGIN_ADMIN.REMOVE_THEME"|tu }}</a>
</div>
{% endif %}
Expand All @@ -114,3 +115,4 @@
{% include 'partials/modal-remove-package.html.twig' with { type: 'theme', package: theme } %}
{% include 'partials/modal-add-package.html.twig' with { type: 'theme' } %}
{% include 'partials/modal-update-packages.html.twig' with { type: 'theme' } %}
{% include 'partials/modal-reinstall-package.html.twig' with { type: 'theme', package: theme } %}

0 comments on commit 0c91ca5

Please sign in to comment.