mirror of
https://github.com/nasa/openmct.git
synced 2025-04-16 07:26:53 +00:00
Duplicate images (#2058)
* [Images] changed updateHistory to only compare the URL value and timestamp for equality
This commit is contained in:
parent
374e4afc32
commit
a3e78bbf91
@ -161,13 +161,30 @@ define(
|
||||
* @returns {boolean} falsy when a duplicate datum is given
|
||||
*/
|
||||
ImageryController.prototype.updateHistory = function (datum) {
|
||||
if (this.$scope.imageHistory.length === 0 ||
|
||||
!_.isEqual(this.$scope.imageHistory.slice(-1)[0], datum)) {
|
||||
if (!this.datumMatchesMostRecent(datum)) {
|
||||
var index = _.sortedIndex(this.$scope.imageHistory, datum, this.timeFormat.format.bind(this.timeFormat));
|
||||
this.$scope.imageHistory.splice(index, 0, datum);
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -230,10 +230,14 @@ define(
|
||||
});
|
||||
|
||||
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(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 () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user