Clean plugin action renderers based on availability
Ryan Blenis committed
Nov 1, 2019 at 22:56 UTC
39dda99fa325962f0370e3cfb8eeacb4f26f49cd
1 file changed
+42
-29
views/default.handlebars
+42
-29
@@ -2365,23 +2365,7 @@
2365
}
2366
case 'pluginVersionsAvailable': {
2367
if (pluginHandler == null) break;
2368
- try {
2369
- var td = Q('pluginRow-'+message.list.id).querySelectorAll(".pluginUpgradeAvailable");
2370
- var sel = Q('pluginRow-'+message.list.id).querySelectorAll(".pluginAction > select");
2371
- td = td[0];
2372
- sel = sel[0];
2373
- if (message.list.hasUpdate && message.list.status) {
2374
- td.innerHTML = '<a title="View Changelog" target="_blank" href="' + message.list.changelogUrl + '">' + message.list.version + '</a>';
2375
- if (sel.innerHTML.indexOf('Upgrade') === -1) {
2376
- var option = document.createElement("option");
2377
- option.value = "install"
2378
- option.text = "Upgrade";
2379
- sel.add(option);
2380
- }
2381
- } else {
2382
- td.innerHTML = "Up to date";
2383
- }
2384
- } catch (e) { }
2368
+ updatePluginList(message.list);
2369
break;
2370
}
2371
case 'plugin': {
@@ -9434,8 +9418,12 @@
9418
}
9419
}
9420
9437
- function updatePluginList() {
9421
+ function updatePluginList(versInfo) {
9422
if (installedPluginList.length) {
9423
+ if (versInfo != null) {
9424
+ if (installedPluginList['version_info'] == null) installedPluginList['version_info'] = [];
9425
+ installedPluginList['version_info'][versInfo.id] = versInfo;
9426
+ }
9427
var tr = Q('p7tbl').querySelectorAll(".p7tblRow");
9428
if (tr.length) {
9429
for (const i in Object.values(tr)) {
@@ -9458,24 +9446,51 @@
9446
'delete': 'Delete'
9447
},
9448
1: {
9461
- 'disable': 'Disable'
9449
+ 'disable': 'Disable',
9450
+ 'upgrade': 'Upgrade'
9451
}
9452
};
9453
+ var vers_not_compat = ` [ <span onclick="return setDialogMode(2, 'Compatibility Issue', 1, null, 'This plugin version is not compatible with your MeshCentral installation, please upgrade MeshCentral first.');" title="Version incompatible, please upgrade your MeshCentral installation first" style="cursor: pointer; color:red;"> ! </span> ]`;
9454
+
9455
var tbl = Q('p7tbl');
9456
installedPluginList.forEach(function(p){
9457
+ var cant_action = [];
9458
if (p.hasAdminPanel == true) {
9459
p.name = `<a onclick="return goPlugin('${p._id}');">${p.name}</a>`;
9460
}
9461
p.statusText = statusMap[p.status].text;
9462
p.statusColor = statusMap[p.status].color;
9463
9464
+
9465
+
9466
+ if (!p.status) { // It isn't technically installed, so no version number
9467
+ p.version = ' - ';
9468
+ }
9469
+ p.upgradeAvail = 'Checking...';
9470
+ if (installedPluginList['version_info'] != null && installedPluginList['version_info'][p._id] != null) {
9471
+ var vin = installedPluginList['version_info'][p._id];
9472
+ if (vin.hasUpdate) {
9473
+ p.upgradeAvail = '<a title="View Changelog" target="_blank" href="' + vin.changelogUrl + '">' + vin.version + '</a>';
9474
+ } else {
9475
+ cant_action.push('upgrade');
9476
+ if (p.status) p.upgradeAvail = 'Up to date';
9477
+ else p.upgradeAvail = '<a title="View Changelog" target="_blank" href="' + vin.changelogUrl + '">' + vin.version + '</a>';
9478
+ }
9479
+ if (!vin.meshCentralCompat) {
9480
+ p.upgradeAvail += vers_not_compat;
9481
+ cant_action.push('install');
9482
+ }
9483
+ }
9484
+
9485
p.actions = '<select onchange="return pluginAction(this, \'' + p._id + '\');"><option value=""> --</option>';
9486
for (const [k, v] of Object.entries(statusAvailability[p.status])) {
9474
- p.actions += '<option value="' + k + '">' + v + '</option>';
9487
+ if (cant_action.indexOf(k) === -1) {
9488
+ p.actions += '<option value="' + k + '">' + v + '</option>';
9489
+ }
9490
}
9476
- p.action += '</select>'
9491
+ p.actions += '</select>';
9492
9478
- let tpl = `<td>${p.name}</td><td>${p.description}</td><td><a href="${p.homepage}" target="_blank">Homepage</a></td><td>${p.version}</td><td class="pluginUpgradeAvailable">Checking...</td><td style="color: #${p.statusColor}">${p.statusText}</td><td class="pluginAction">${p.actions}</td>`;
9493
+ let tpl = `<td>${p.name}</td><td>${p.description}</td><td><a href="${p.homepage}" target="_blank">Homepage</a></td><td>${p.version}</td><td class="pluginUpgradeAvailable">${p.upgradeAvail}</td><td style="color: #${p.statusColor}">${p.statusText}</td><td class="pluginAction">${p.actions}</td>`;
9494
let tr = tbl.insertRow(-1);
9495
tr.innerHTML = tpl;
9496
tr.classList.add('p7tblRow');
@@ -9488,7 +9503,7 @@
9503
tr[i].parentNode.removeChild(tr[i]);
9504
}
9505
}
9491
- refreshPluginLatest();
9506
+ if (versInfo == null) refreshPluginLatest();
9507
}
9508
9509
function refreshPluginLatest() {
@@ -9498,18 +9513,16 @@
9513
function pluginActionEx() {
9514
var act = Q('lastPluginAct').value, id = Q('lastPluginId').value;
9515
switch(act) {
9501
- case 'install': {
9516
+ case 'upgrade':
9517
+ case 'install':
9518
meshserver.send({ "action": "installplugin", "id": id });
9519
break;
9504
- }
9505
- case 'delete': {
9520
+ case 'delete':
9521
meshserver.send({ "action": "removeplugin", "id": id });
9522
break;
9508
- }
9509
- case 'disable': {
9523
+ case 'disable':
9524
meshserver.send({ "action": "disableplugin", "id": id });
9525
break;
9512
- }
9526
}
9527
QS('pluginRestartNotice').display = '';
9528
}