Sort views by priority (#2174)

This commit is contained in:
Andrew Henry 2018-09-26 20:32:48 +01:00 committed by Pegah Sarram
parent c7b73bdc3f
commit c5187d8509
3 changed files with 33 additions and 3 deletions

View File

@ -3,6 +3,16 @@ define([
], function (
) {
const DEFAULT_VIEW_PRIORITY = 100;
const PRIORITY_LEVELS = {
"fallback": Number.NEGATIVE_INFINITY,
"default": -100,
"none": 0,
"optional": DEFAULT_VIEW_PRIORITY,
"preferred": 1000,
"mandatory": Number.POSITIVE_INFINITY
};
function LegacyViewProvider(legacyView, openmct, convertToLegacyObject) {
console.warn(`DEPRECATION WARNING: Migrate ${legacyView.key} from ${legacyView.bundle.path} to use the new View APIs. Legacy view support will be removed soon.`);
@ -84,6 +94,13 @@ define([
scope.$destroy();
}
}
},
priority: function () {
let priority = legacyView.priority || DEFAULT_VIEW_PRIORITY;
if (typeof priority === 'string') {
priority = PRIORITY_LEVELS[priority];
}
return priority;
}
};
};

View File

@ -8,7 +8,7 @@ define([
objectUtils
) {
const DEFAULT_VIEW_PRIORITY = 100;
/**
*
*/
@ -34,7 +34,11 @@ define([
},
editable: true,
priority: function (domainObject) {
return 1;
if (domainObject.type === 'summary-widget') {
return Number.MAX_VALUE;
} else {
return DEFAULT_VIEW_PRIORITY;
}
}
};
}

View File

@ -22,6 +22,8 @@
/*global console */
define([], function () {
const DEFAULT_VIEW_PRIORITY = 100;
/**
* A ViewRegistry maintains the definitions for different kinds of views
* that may occur in different places in the user interface.
@ -40,10 +42,17 @@ define([], function () {
* which can provide views of this object
*/
ViewRegistry.prototype.get = function (item) {
function byPriority(providerA, providerB) {
let priorityA = providerA.priority ? providerA.priority(item) : DEFAULT_VIEW_PRIORITY;
let priorityB = providerB.priority ? providerB.priority(item) : DEFAULT_VIEW_PRIORITY;
return priorityB - priorityA;
}
return this.getAllProviders()
.filter(function (provider) {
return provider.canView(item);
});
}).sort(byPriority);
};
/**