FEATURE: allow client side of topic list to accept custom params
- Also normalize API version to use a version comparison function instead of float
This commit is contained in:
parent
74d4209d24
commit
023bd0e9e7
|
@ -19,4 +19,14 @@ const controllerOpts = {
|
||||||
// Aliases for the values
|
// Aliases for the values
|
||||||
controllerOpts.queryParams.forEach(p => controllerOpts[p] = Ember.computed.alias(`discoveryTopics.${p}`));
|
controllerOpts.queryParams.forEach(p => controllerOpts[p] = Ember.computed.alias(`discoveryTopics.${p}`));
|
||||||
|
|
||||||
export default Ember.Controller.extend(controllerOpts);
|
const Controller = Ember.Controller.extend(controllerOpts);
|
||||||
|
|
||||||
|
export const addDiscoveryQueryParam = function(p, opts) {
|
||||||
|
queryParams[p] = opts;
|
||||||
|
const cOpts = {};
|
||||||
|
cOpts[p] = Ember.computed.alias(`discoveryTopics.${p}`);
|
||||||
|
cOpts["queryParams"] = Object.keys(queryParams);
|
||||||
|
Controller.reopen(cOpts);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Controller;
|
||||||
|
|
|
@ -13,9 +13,10 @@ import { addFlagProperty } from 'discourse/components/site-header';
|
||||||
import { addPopupMenuOptionsCallback } from 'discourse/controllers/composer';
|
import { addPopupMenuOptionsCallback } from 'discourse/controllers/composer';
|
||||||
import { extraConnectorClass } from 'discourse/lib/plugin-connectors';
|
import { extraConnectorClass } from 'discourse/lib/plugin-connectors';
|
||||||
import { addPostSmallActionIcon } from 'discourse/widgets/post-small-action';
|
import { addPostSmallActionIcon } from 'discourse/widgets/post-small-action';
|
||||||
|
import { addDiscoveryQueryParam } from 'discourse/controllers/discovery-sortable';
|
||||||
|
|
||||||
// If you add any methods to the API ensure you bump up this number
|
// If you add any methods to the API ensure you bump up this number
|
||||||
const PLUGIN_API_VERSION = 0.8;
|
const PLUGIN_API_VERSION = '0.8.1';
|
||||||
|
|
||||||
class PluginApi {
|
class PluginApi {
|
||||||
constructor(version, container) {
|
constructor(version, container) {
|
||||||
|
@ -377,12 +378,42 @@ class PluginApi {
|
||||||
addPostSmallActionIcon(key, icon) {
|
addPostSmallActionIcon(key, icon) {
|
||||||
addPostSmallActionIcon(key, icon);
|
addPostSmallActionIcon(key, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register an additional query param with topic discovery,
|
||||||
|
* this allows for filters on the topic list
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
addDiscoveryQueryParam(param, options) {
|
||||||
|
addDiscoveryQueryParam(param, options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let _pluginv01;
|
let _pluginv01;
|
||||||
|
|
||||||
|
|
||||||
|
// from http://stackoverflow.com/questions/6832596/how-to-compare-software-version-number-using-js-only-number
|
||||||
|
function cmpVersions (a, b) {
|
||||||
|
var i, diff;
|
||||||
|
var regExStrip0 = /(\.0+)+$/;
|
||||||
|
var segmentsA = a.replace(regExStrip0, '').split('.');
|
||||||
|
var segmentsB = b.replace(regExStrip0, '').split('.');
|
||||||
|
var l = Math.min(segmentsA.length, segmentsB.length);
|
||||||
|
|
||||||
|
for (i = 0; i < l; i++) {
|
||||||
|
diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10);
|
||||||
|
if (diff) {
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return segmentsA.length - segmentsB.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function getPluginApi(version) {
|
function getPluginApi(version) {
|
||||||
version = parseFloat(version);
|
version = version.toString();
|
||||||
if (version <= PLUGIN_API_VERSION) {
|
if (cmpVersions(version,PLUGIN_API_VERSION) <= 0) {
|
||||||
if (!_pluginv01) {
|
if (!_pluginv01) {
|
||||||
_pluginv01 = new PluginApi(version, Discourse.__container__);
|
_pluginv01 = new PluginApi(version, Discourse.__container__);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue