[Code Style] Use prototypes for Events bundle

WTD-1482
This commit is contained in:
Victor Woeltjen 2015-08-11 16:01:14 -07:00
parent 7911909c5f
commit d701567b70
5 changed files with 189 additions and 188 deletions

View File

@ -35,6 +35,7 @@ define(
*
* @memberof platform/features/events
* @constructor
* @implements {platform/features/events.EventsColumn}
* @param domainMetadata an object with the machine- and human-
* readable names for this domain (in `key` and `name`
* fields, respectively.)
@ -42,28 +43,20 @@ define(
* formatting service, for making values human-readable.
*/
function DomainColumn(domainMetadata, telemetryFormatter) {
return {
/**
* Get the title to display in this column's header.
* @returns {string} the title to display
* @memberof platform/features/events.DomainColumn#
*/
getTitle: function () {
return domainMetadata.name;
},
/**
* Get the text to display inside a row under this
* column.
* @returns {string} the text to display
* @memberof platform/features/events.DomainColumn#
*/
getValue: function (domainObject, data, index) {
return telemetryFormatter.formatDomainValue(
data.getDomainValue(index, domainMetadata.key)
);
this.domainMetadata = domainMetadata;
this.telemetryFormatter = telemetryFormatter;
}
DomainColumn.prototype.getTitle = function () {
return this.domainMetadata.name;
};
DomainColumn.prototype.getValue = function (domainObject, data, index) {
var domainKey = this.domainMetadata.key;
return this.telemetryFormatter.formatDomainValue(
data.getDomainValue(index, domainKey)
);
};
}
return DomainColumn;
}

View File

@ -135,6 +135,30 @@ define(
}
return EventListController;
/**
* A description of how to display a certain column of data in an
* Events view.
* @interface platform/features/events.EventColumn
* @private
*/
/**
* Get the title to display in this column's header.
* @returns {string} the title to display
* @method platform/features/events.EventColumn#getTitle
*/
/**
* Get the text to display inside a row under this
* column.
* @param {DomainObject} domainObject the domain object associated
* with this row
* @param {TelemetrySeries} series the telemetry data associated
* with this row
* @param {number} index the index of the telemetry datum associated
* with this row
* @returns {string} the text to display
* @method platform/features/events.EventColumn#getValue
*/
}
);

View File

@ -35,6 +35,9 @@ define(
* @param {Column[]} columns the columns to be populated
*/
function EventListPopulator(columns) {
this.columns = columns;
}
/*
* Look up the most recent values from a set of data objects.
* Returns an array of objects in the order in which data
@ -112,19 +115,18 @@ define(
return latest;
}
return {
/**
* Get the text which should appear in headers for the
* provided columns.
* @memberof platform/features/events.EventListPopulator
* @returns {string[]} column headers
*/
getHeaders: function () {
return columns.map(function (column) {
EventListPopulator.prototype.getHeaders = function () {
return this.columns.map(function (column) {
return column.getTitle();
});
},
};
/**
* Get the contents of rows for the event list view.
* @param {TelemetrySeries[]} datas the data sets
@ -137,8 +139,9 @@ define(
* is an array of values which should appear
* in that row
*/
getRows: function (datas, objects, count) {
var values = getLatestDataValues(datas, count);
EventListPopulator.prototype.getRows = function (datas, objects, count) {
var values = getLatestDataValues(datas, count),
columns = this.columns;
// Each value will become a row, which will contain
// some value in each column (rendering by the
@ -154,9 +157,7 @@ define(
);
});
}).reverse();
}
};
}
return EventListPopulator;

View File

@ -35,6 +35,7 @@ define(
*
* @memberof platform/features/events
* @constructor
* @implements {platform/features/events.EventsColumn}
* @param rangeMetadata an object with the machine- and human-
* readable names for this range (in `key` and `name`
* fields, respectively.)
@ -42,28 +43,19 @@ define(
* formatting service, for making values human-readable.
*/
function RangeColumn(rangeMetadata, telemetryFormatter) {
return {
/**
* Get the title to display in this column's header.
* @returns {string} the title to display
* @memberof platform/features/events.RangeColumn#
*/
getTitle: function () {
return rangeMetadata.name;
},
/**
* Get the text to display inside a row under this
* column.
* @returns {string} the text to display
* @memberof platform/features/events.RangeColumn#
*/
getValue: function (domainObject, data, index) {
return telemetryFormatter.formatRangeValue(
data.getRangeValue(index, rangeMetadata.key)
);
this.rangeMetadata = rangeMetadata;
this.telemetryFormatter = telemetryFormatter;
}
RangeColumn.prototype.getTitle = function () {
return this.rangeMetadata.name;
};
RangeColumn.prototype.getValue = function (domainObject, data, index) {
var rangeKey = this.rangeMetadata.key;
return this.telemetryFormatter.formatRangeValue(
data.getRangeValue(index, rangeKey)
);
};
}
return RangeColumn;
}

View File

@ -33,8 +33,9 @@ define(
* Policy controlling when the Messages view should be avaliable.
* @memberof platform/features/events
* @constructor
* @implements {Policy.<View, DomainObject>}
*/
function MessagesViewPolicy() {
function MessagesViewPolicy() {}
function hasStringTelemetry(domainObject) {
var telemetry = domainObject &&
@ -46,16 +47,8 @@ define(
return range.format === 'string';
});
}
return {
/**
* Check whether or not a given action is allowed by this
* policy.
* @param {Action} action the action
* @param domainObject the domain object which will be viewed
* @returns {boolean} true if not disallowed
* @memberof platform/features/events.MessagesViewPolicy#
*/
allow: function (view, domainObject) {
MessagesViewPolicy.prototype.allow = function (view, domainObject) {
// This policy only applies for the Messages view
if (view.key === 'messages') {
// The Messages view is allowed only if the domain
@ -67,9 +60,7 @@ define(
// Like all policies, allow by default.
return true;
}
};
}
return MessagesViewPolicy;
}