Duplicate images (#2058)

* [Images] changed updateHistory to only compare the URL value and timestamp for equality
This commit is contained in:
David Milewicz
2018-06-20 14:26:13 -07:00
committed by Andrew Henry
parent 374e4afc32
commit a3e78bbf91
2 changed files with 24 additions and 3 deletions

View File

@@ -161,13 +161,30 @@ define(
* @returns {boolean} falsy when a duplicate datum is given * @returns {boolean} falsy when a duplicate datum is given
*/ */
ImageryController.prototype.updateHistory = function (datum) { ImageryController.prototype.updateHistory = function (datum) {
if (this.$scope.imageHistory.length === 0 || if (!this.datumMatchesMostRecent(datum)) {
!_.isEqual(this.$scope.imageHistory.slice(-1)[0], datum)) {
var index = _.sortedIndex(this.$scope.imageHistory, datum, this.timeFormat.format.bind(this.timeFormat)); var index = _.sortedIndex(this.$scope.imageHistory, datum, this.timeFormat.format.bind(this.timeFormat));
this.$scope.imageHistory.splice(index, 0, datum); this.$scope.imageHistory.splice(index, 0, datum);
return true; return true;
} else {
return false;
} }
};
/**
* Checks to see if the given datum is the same as the most recent in history.
* @private
* @param {object} [datum] target telemetry datum
* @returns {boolean} true if datum is most recent in history, false otherwise
*/
ImageryController.prototype.datumMatchesMostRecent = function (datum) {
if (this.$scope.imageHistory.length !== 0) {
var datumTime = this.timeFormat.format(datum);
var datumURL = this.imageFormat.format(datum);
var lastHistoryTime = this.timeFormat.format(this.$scope.imageHistory.slice(-1)[0]);
var lastHistoryURL = this.imageFormat.format(this.$scope.imageHistory.slice(-1)[0]);
return datumTime === lastHistoryTime && datumURL === lastHistoryURL;
}
return false; return false;
}; };

View File

@@ -230,10 +230,14 @@ define(
}); });
it ("doesnt append duplicate datum", function () { it ("doesnt append duplicate datum", function () {
var mockDatum = {url: 'image/url', utc: 1434600000000}; var mockDatum = {value: 'image/url', timestamp: 1434700000000};
var mockDatum2 = {value: 'image/url', timestamp: 1434700000000};
var mockDatum3 = {value: 'image/url', url: 'someval', timestamp: 1434700000000};
expect(controller.updateHistory(mockDatum)).toBe(true); expect(controller.updateHistory(mockDatum)).toBe(true);
expect(controller.updateHistory(mockDatum)).toBe(false); expect(controller.updateHistory(mockDatum)).toBe(false);
expect(controller.updateHistory(mockDatum)).toBe(false); expect(controller.updateHistory(mockDatum)).toBe(false);
expect(controller.updateHistory(mockDatum2)).toBe(false);
expect(controller.updateHistory(mockDatum3)).toBe(false);
}); });
describe("when user clicks on imagery thumbnail", function () { describe("when user clicks on imagery thumbnail", function () {