Set/read plugin-installed flag

This commit is contained in:
billz 2024-12-26 08:04:16 -08:00
parent 92ba7df9c6
commit ad36695224
4 changed files with 49 additions and 38 deletions

View File

@ -471,54 +471,65 @@ $('#js-sys-reboot, #js-sys-shutdown').on('click', function (e) {
$('#install-user-plugin').on('shown.bs.modal', function (e) { $('#install-user-plugin').on('shown.bs.modal', function (e) {
var button = $(e.relatedTarget); var button = $(e.relatedTarget);
var manifestData = button.data('plugin-manifest'); var manifestData = button.data('plugin-manifest');
var installed = button.data('plugin-installed');
if (manifestData) { if (manifestData) {
$('#plugin-uri').html(manifestData.plugin_uri $('#plugin-uri').html(manifestData.plugin_uri
? `<a href="${manifestData.plugin_uri}" target="_blank">${manifestData.plugin_uri}</a>` ? `<a href="${manifestData.plugin_uri}" target="_blank">${manifestData.plugin_uri}</a>`
: 'Unknown' : 'Unknown'
);
$('#plugin-icon').attr('class', `${manifestData.icon || 'fas fa-plug'} link-secondary h5 me-2`);
$('#plugin-name').text(manifestData.name || 'Unknown');
$('#plugin-version').text(manifestData.version || 'Unknown');
$('#plugin-description').text(manifestData.description || 'No description provided');
$('#plugin-author').html(manifestData.author
? manifestData.author + (manifestData.author_uri
? ` (<a href="${manifestData.author_uri}" target="_blank">profile</a>)` : '') : 'Unknown'
); );
$('#plugin-icon').attr('class', `${manifestData.icon || 'fas fa-plug'} link-secondary h5 me-2`); $('#plugin-license').text(manifestData.license || 'Unknown');
$('#plugin-name').text(manifestData.name || 'Unknown'); $('#plugin-locale').text(manifestData.default_locale || 'Unknown');
$('#plugin-version').text(manifestData.version || 'Unknown'); $('#plugin-configuration').html(formatProperty(manifestData.configuration || {}));
$('#plugin-description').text(manifestData.description || 'No description provided'); $('#plugin-dependencies').html(formatProperty(manifestData.dependencies || {}));
$('#plugin-author').html(manifestData.author $('#plugin-sudoers').html(formatProperty(manifestData.sudoers || []));
? manifestData.author + (manifestData.author_uri $('#plugin-user-name').html(manifestData.user_nonprivileged.name || 'None');
? ` (<a href="${manifestData.author_uri}" target="_blank">profile</a>)` : '') : 'Unknown' }
); if (installed) {
$('#plugin-license').text(manifestData.license || 'Unknown'); $('#js-install-plugin-confirm').html('OK');
$('#plugin-locale').text(manifestData.default_locale || 'Unknown'); } else {
$('#plugin-configuration').html(formatProperty(manifestData.configuration || {})); $('#js-install-plugin-confirm').html('Install now');
$('#plugin-dependencies').html(formatProperty(manifestData.dependencies || {})); }
$('#plugin-sudoers').html(formatProperty(manifestData.sudoers || []));
$('#plugin-user-name').html(manifestData.user_nonprivileged.name || 'None');
}
}); });
$('#js-install-plugin-confirm').on('click', function (e) { $('#js-install-plugin-confirm').on('click', function (e) {
var progressText = $('#js-install-plugin-confirm').attr('data-message'); var progressText = $('#js-install-plugin-confirm').attr('data-message');
var successHtml = $('#plugin-install-message').attr('data-message'); var successHtml = $('#plugin-install-message').attr('data-message');
var closeHtml = $('#js-system-reset-cancel').attr('data-message');
var pluginUri = $('#plugin-uri a').attr('href'); var pluginUri = $('#plugin-uri a').attr('href');
var pluginVersion = $('#plugin-version').text(); var pluginVersion = $('#plugin-version').text();
var csrfToken = $('meta[name=csrf_token]').attr('content'); var csrfToken = $('meta[name=csrf_token]').attr('content');
$("#install-user-plugin").modal('hide'); $("#install-user-plugin").modal('hide');
$("#install-plugin-progress").modal('show');
$.post('ajax/plugins/do_plugin_install.php?',{'plugin_uri': pluginUri, 'plugin_version': pluginVersion, 'csrf_token': csrfToken},function(data){ if ($('#js-install-plugin-confirm').text() === 'Install now') {
setTimeout(function(){ $("#install-plugin-progress").modal('show');
response = JSON.parse(data);
if(response === true) { $.post('ajax/plugins/do_plugin_install.php?',{'plugin_uri': pluginUri,
$('#plugin-install-message').text(successHtml); 'plugin_version': pluginVersion, 'csrf_token': csrfToken},function(data){
$('#plugin-install-message').find('i').removeClass('fas fa-cog fa-spin link-secondary').addClass('fas fa-check'); setTimeout(function(){
$('#js-install-plugin-ok').removeAttr("disabled"); response = JSON.parse(data);
} else { if (response === true) {
$('#plugin-install-message').text('An error occurred installing the plugin.'); $('#plugin-install-message').contents().first().replaceWith(successHtml);
$('#plugin-install-message').find('i').removeClass('fas fa-cog fa-spin link-secondary'); $('#plugin-install-message').find('i')
$('#js-install-plugin-ok').removeAttr("disabled"); .removeClass('fas fa-cog fa-spin link-secondary')
} .addClass('fas fa-check');
},300); $('#js-install-plugin-ok').removeAttr("disabled");
}); } else {
$('#plugin-install-message').contents().first().replaceWith('An error occurred installing the plugin.');
$('#plugin-install-message').find('i').removeClass('fas fa-cog fa-spin link-secondary');
$('#js-install-plugin-ok').removeAttr("disabled");
}
},200);
});
}
}); });
$('#js-install-plugin-ok').on('click', function (e) { $('#js-install-plugin-ok').on('click', function (e) {

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# #
# PluginInstaller helper for RaspAP # PluginInstaller helper for RaspAP
# # @author billz # @author billz
# license: GNU General Public License v3.0 # license: GNU General Public License v3.0
# Exit on error # Exit on error

View File

@ -428,7 +428,7 @@ class PluginInstaller
if ($installed === true ) { if ($installed === true ) {
$button = '<button type="button" class="btn btn-outline btn-primary btn-sm text-nowrap" $button = '<button type="button" class="btn btn-outline btn-primary btn-sm text-nowrap"
name="plugin-details" data-bs-toggle="modal" data-bs-target="#install-user-plugin" name="plugin-details" data-bs-toggle="modal" data-bs-target="#install-user-plugin"
data-plugin-manifest="' .$manifest. '"> ' . _("Installed") .'</button>'; data-plugin-manifest="' .$manifest. '" data-plugin-installed="' .$installed. '"> ' . _("Installed") .'</button>';
} else { } else {
$button = '<button type="button" class="btn btn-outline btn-primary btn-sm text-nowrap" $button = '<button type="button" class="btn btn-outline btn-primary btn-sm text-nowrap"
name="install-plugin" data-bs-toggle="modal" data-bs-target="#install-user-plugin" name="install-plugin" data-bs-toggle="modal" data-bs-target="#install-user-plugin"

View File

@ -164,7 +164,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal"><?php echo _("Cancel"); ?></button> <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal"><?php echo _("Cancel"); ?></button>
<button type="button" id="js-install-plugin-confirm" data-message="<?php echo _("Plugin installation in progress..."); ?>" class="btn btn-outline-success btn-activate"><?php echo _("Install now"); ?></button> <button type="button" id="js-install-plugin-confirm" data-message="<?php echo _("Plugin installation in progress..."); ?>" class="btn btn-outline-success btn-activate"></button>
</div> </div>
</div> </div>
</div> </div>