Skip to content

Commit 437f209

Browse files
committed
Marketplace Improvements: Allow filtering by plugin type, and also display plugin type in the search results, and on landing pages.
- Also, make the retries more aggressive for raw.githubusercontent.com (it randomly fails)
1 parent 63b45f6 commit 437f209

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

htdocs/js/pages/admin/Marketplace.class.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ Page.Marketplace = class Marketplace extends Page.PageUtils {
7474
var def = config.ui.data_types[type];
7575
if (def) return { id: type, title: toTitleCase(type), icon: def.icon };
7676
else return type;
77-
} ) ),
78-
value: args.type || '',
77+
} ) ).concat( [
78+
{ id: 'p_action', title: 'Action Plugins', icon: 'gesture-tap', group: "Plugin Types" },
79+
{ id: 'p_event', title: 'Event Plugins', icon: 'calendar-clock' },
80+
{ id: 'p_monitor', title: 'Monitor Plugins', icon: 'console' },
81+
{ id: 'p_scheduler', title: 'Trigger Plugins', icon: 'rocket-launch-outline' }
82+
] ),
83+
value: args.plugin_type ? `p_${args.plugin_type}` : (args.type || ''),
7984
'data-shrinkwrap': 1
8085
})
8186
});
@@ -214,7 +219,14 @@ Page.Marketplace = class Marketplace extends Page.PageUtils {
214219
if (lic) args.license = lic;
215220

216221
var type = this.div.find('#fe_s_type').val();
217-
if (type) args.type = type;
222+
if (type) {
223+
if (type.match(/^p_(\w+)$/)) {
224+
var plugin_type = RegExp.$1;
225+
args.type = 'plugin';
226+
args.plugin_type = plugin_type;
227+
}
228+
else args.type = type;
229+
}
218230

219231
var sort = this.div.find('#fe_s_sort').val();
220232
if (sort != 'title_asc') args.sort = sort;
@@ -321,7 +333,7 @@ Page.Marketplace = class Marketplace extends Page.PageUtils {
321333
combo,
322334
self.getNiceProductAuthor( product.author ),
323335
self.getNiceProductLicense( product.license ),
324-
self.getNiceProductType( product.type ),
336+
self.getNiceProductType( product ),
325337
self.getNiceProductDate( product.created ),
326338
self.getNiceProductVersion( product.versions[0] )
327339
];
@@ -335,10 +347,12 @@ Page.Marketplace = class Marketplace extends Page.PageUtils {
335347
this.cleanupBoxButtonFloater();
336348
}
337349

338-
getNiceProductType(type) {
350+
getNiceProductType(product) {
339351
// { id: type, title: toTitleCase(type), icon: def.icon };
340-
var def = config.ui.data_types[type];
341-
if (def) return `<i class="mdi mdi-${def.icon}">&nbsp;</i>` + toTitleCase(type);
352+
if (product.plugin_type) return this.getNicePluginType(product.plugin_type);
353+
354+
var def = config.ui.data_types[product.type];
355+
if (def) return `<i class="mdi mdi-${def.icon}">&nbsp;</i>` + toTitleCase(product.type);
342356
else return type;
343357
}
344358

@@ -438,7 +452,7 @@ Page.Marketplace = class Marketplace extends Page.PageUtils {
438452
// type
439453
html += '<div>';
440454
html += '<div class="info_label">Type</div>';
441-
html += '<div class="info_value">' + this.getNiceProductType(product.type) + '</div>';
455+
html += '<div class="info_value">' + this.getNiceProductType(product) + '</div>';
442456
html += '</div>';
443457

444458
// status (installed / not)

lib/api/search.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ class Search {
441441
filename: 'README.md'
442442
} );
443443

444-
self.request.get( url, { retries: 5, retryDelay: 100 }, function(err, resp, data, perf) {
444+
self.request.get( url, { retries: 8, retryDelay: 50 }, function(err, resp, data, perf) {
445445
if (err) return self.doError( 'marketplace', "Failed to fetch README: " + err, callback );
446446

447447
// try to fix image src urls if relative
@@ -465,7 +465,7 @@ class Search {
465465
filename: 'xyops.json'
466466
} );
467467

468-
self.request.json( url, false, { retries: 5, retryDelay: 100 }, function(err, resp, data, perf) {
468+
self.request.json( url, false, { retries: 8, retryDelay: 50 }, function(err, resp, data, perf) {
469469
if (err) return self.doError( 'marketplace', "Failed to fetch data: " + err, callback );
470470
callback({ code: 0, item, version: ver, data: data });
471471
});
@@ -479,7 +479,7 @@ class Search {
479479
filename: 'logo.png'
480480
} );
481481

482-
self.request.get( url, { retries: 5, retryDelay: 100 }, function(err, resp, data, perf) {
482+
self.request.get( url, { retries: 8, retryDelay: 50 }, function(err, resp, data, perf) {
483483
if (err) return self.doError( 'marketplace', "Failed to fetch README: " + err, callback );
484484
callback( "200 OK", { 'Content-Type': 'image/png' }, data );
485485
});
@@ -489,16 +489,18 @@ class Search {
489489
} // id
490490
else if (params.fields) {
491491
// return all unique field values (tags, licenses, etc.)
492-
var fields = { types: {}, requires: {}, tags: {}, licenses: {} };
492+
var fields = { types: {}, plugin_types: {}, requires: {}, tags: {}, licenses: {} };
493493

494494
metadata.rows.forEach( function(row) {
495495
if (row.type) fields.types[ row.type ] = 1;
496+
if (row.plugin_type) fields.plugin_types[ row.plugin_type ] = 1;
496497
if (row.license) fields.licenses[ row.license ] = 1;
497498
(row.requires || []).forEach( function(req) { fields.requires[req] = 1; } );
498499
(row.tags || []).forEach( function(tag) { fields.tags[tag] = 1; } );
499500
} );
500501

501502
fields.types = Tools.hashKeysToArray(fields.types).sort();
503+
fields.plugin_types = Tools.hashKeysToArray(fields.plugin_types).sort();
502504
fields.requires = Tools.hashKeysToArray(fields.requires).sort();
503505
fields.tags = Tools.hashKeysToArray(fields.tags).sort();
504506
fields.licenses = Tools.hashKeysToArray(fields.licenses).sort();
@@ -516,6 +518,7 @@ class Search {
516518
if (!text.includes(params.query.toLowerCase())) return false;
517519
}
518520
if (params.type && (row.type != params.type)) return false;
521+
if (params.plugin_type && (row.plugin_type != params.plugin_type)) return false;
519522
if (params.license && (row.license.toLowerCase() != params.license.toLowerCase())) return false;
520523
if (params.tags && !includesAllCI(row.tags, params.tags)) return false;
521524
if (params.requires && !includesAllCI(row.requires, params.requires)) return false;
@@ -537,7 +540,7 @@ class Search {
537540
if (err || (stats.mtimeMs / 1000 < Tools.timeNow() - marketplace.ttl)) {
538541
// fetch from origin
539542
self.logDebug(5, "Fetching marketplace metadata from origin: " + marketplace.metadata_url);
540-
self.request.json( marketplace.metadata_url, false, { retries: 5, retryDelay: 100 }, function(err, resp, metadata, perf) {
543+
self.request.json( marketplace.metadata_url, false, { retries: 8, retryDelay: 50 }, function(err, resp, metadata, perf) {
541544
if (err) return self.doError('marketplace', "Failed to fetch marketplace metadata: " + marketplace.metadata_url + ": " + err, callback);
542545

543546
Tools.writeFileAtomic( cache_file, JSON.stringify(metadata), function(err) {

0 commit comments

Comments
 (0)