[Code Style] Use prototypes in Imagery bundle

WTD-1482
This commit is contained in:
Victor Woeltjen 2015-08-12 09:57:05 -07:00
parent d701567b70
commit a9e2d48036
2 changed files with 94 additions and 97 deletions

View File

@ -40,40 +40,29 @@ define(
* @memberof platform/features/imagery * @memberof platform/features/imagery
*/ */
function ImageryController($scope, telemetryHandler) { function ImageryController($scope, telemetryHandler) {
var date = "", var self = this;
time = "",
imageUrl = "",
paused = false,
handle;
function releaseSubscription() { function releaseSubscription() {
if (handle) { if (self.handle) {
handle.unsubscribe(); self.handle.unsubscribe();
handle = undefined; self.handle = undefined;
} }
} }
function updateValues() { function updateValuesCallback() {
var imageObject = handle && handle.getTelemetryObjects()[0], return self.updateValues();
m;
if (imageObject && !paused) {
m = moment.utc(handle.getDomainValue(imageObject));
date = m.format(DATE_FORMAT);
time = m.format(TIME_FORMAT);
imageUrl = handle.getRangeValue(imageObject);
}
} }
// Create a new subscription; telemetrySubscriber gets // Create a new subscription; telemetrySubscriber gets
// to do the meaningful work here. // to do the meaningful work here.
function subscribe(domainObject) { function subscribe(domainObject) {
releaseSubscription(); releaseSubscription();
date = ""; self.date = "";
time = ""; self.time = "";
imageUrl = ""; self.imageUrl = "";
handle = domainObject && telemetryHandler.handle( self.handle = domainObject && telemetryHandler.handle(
domainObject, domainObject,
updateValues, updateValuesCallback,
true // Lossless true // Lossless
); );
} }
@ -83,61 +72,71 @@ define(
// Unsubscribe when the plot is destroyed // Unsubscribe when the plot is destroyed
$scope.$on("$destroy", releaseSubscription); $scope.$on("$destroy", releaseSubscription);
}
// Update displayable values to reflect latest image telemetry
ImageryController.prototype.updateValues = function () {
var imageObject =
this.handle && this.handle.getTelemetryObjects()[0],
m;
if (imageObject && !this.isPaused) {
m = moment.utc(this.handle.getDomainValue(imageObject));
this.date = m.format(DATE_FORMAT);
this.time = m.format(TIME_FORMAT);
this.imageUrl = this.handle.getRangeValue(imageObject);
}
};
return {
/** /**
* Get the time portion (hours, minutes, seconds) of the * Get the time portion (hours, minutes, seconds) of the
* timestamp associated with the incoming image telemetry. * timestamp associated with the incoming image telemetry.
* @returns {string} the time * @returns {string} the time
* @memberof platform/features/imagery.ImageryController#
*/ */
getTime: function () { ImageryController.prototype.getTime = function () {
return time; return this.time;
}, };
/** /**
* Get the date portion (month, year) of the * Get the date portion (month, year) of the
* timestamp associated with the incoming image telemetry. * timestamp associated with the incoming image telemetry.
* @returns {string} the date * @returns {string} the date
* @memberof platform/features/imagery.ImageryController#
*/ */
getDate: function () { ImageryController.prototype.getDate = function () {
return date; return this.date;
}, };
/** /**
* Get the time zone for the displayed time/date corresponding * Get the time zone for the displayed time/date corresponding
* to the timestamp associated with the incoming image * to the timestamp associated with the incoming image
* telemetry. * telemetry.
* @returns {string} the time * @returns {string} the time
* @memberof platform/features/imagery.ImageryController#
*/ */
getZone: function () { ImageryController.prototype.getZone = function () {
return "UTC"; return "UTC";
}, };
/** /**
* Get the URL of the image telemetry to display. * Get the URL of the image telemetry to display.
* @returns {string} URL for telemetry image * @returns {string} URL for telemetry image
* @memberof platform/features/imagery.ImageryController#
*/ */
getImageUrl: function () { ImageryController.prototype.getImageUrl = function () {
return imageUrl; return this.imageUrl;
}, };
/** /**
* Getter-setter for paused state of the view (true means * Getter-setter for paused state of the view (true means
* paused, false means not.) * paused, false means not.)
* @param {boolean} [state] the state to set * @param {boolean} [state] the state to set
* @returns {boolean} the current state * @returns {boolean} the current state
* @memberof platform/features/imagery.ImageryController#
*/ */
paused: function (state) { ImageryController.prototype.paused = function (state) {
if (arguments.length > 0 && state !== paused) { if (arguments.length > 0 && state !== this.isPaused) {
paused = state; this.isPaused = state;
// Switch to latest image // Switch to latest image
updateValues(); this.updateValues();
}
return paused;
} }
return this.isPaused;
}; };
}
return ImageryController; return ImageryController;
} }

View File

@ -28,11 +28,12 @@ define(
/** /**
* Policy preventing the Imagery view from being made available for * Policy preventing the Imagery view from being made available for
* domain objects which do not have associated image telemetry. * domain objects which do not have associated image telemetry.
* @implements {Policy} * @implements {Policy.<View, DomainObject>}
* @constructor * @constructor
* @memberof platform/features/imagery
*/ */
function ImageryViewPolicy() { function ImageryViewPolicy() {
}
function hasImageTelemetry(domainObject) { function hasImageTelemetry(domainObject) {
var telemetry = domainObject && var telemetry = domainObject &&
domainObject.getCapability('telemetry'), domainObject.getCapability('telemetry'),
@ -45,16 +46,13 @@ define(
}); });
} }
return { ImageryViewPolicy.prototype.allow = function (view, domainObject) {
allow: function (view, domainObject) {
if (view.key === 'imagery') { if (view.key === 'imagery') {
return hasImageTelemetry(domainObject); return hasImageTelemetry(domainObject);
} }
return true; return true;
}
}; };
}
return ImageryViewPolicy; return ImageryViewPolicy;
} }