@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
55 lines • 2.85 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { ViolationState } from "./Violations/Violation";
import { EventObject } from "@aurigma/design-atoms-model/EventObject";
var ViolationViewController = /** @class */ (function () {
function ViolationViewController(_violationService) {
var _this = this;
this._violationService = _violationService;
this._timeouts = [];
this._onItemViolationStateChanged = function (args) {
var clonedNewInfo = __assign({}, args.new);
if (clonedNewInfo.state === ViolationState.Good && (args.old == null || args.old.state === ViolationState.Good || args.old.state === ViolationState.None))
clonedNewInfo.state = ViolationState.None;
_this._violationViewChangedEvent.notify(clonedNewInfo);
var itemId = clonedNewInfo.item.id;
var clearTimeout = function (id) {
var timeout = _this._timeouts.find(function (t) { return t.id === id; });
if (timeout == null)
return;
_this._timeouts = _this._timeouts.filter(function (t) { return t.id !== timeout.id; });
clearInterval(timeout.timeoutId);
};
if (clonedNewInfo.state !== ViolationState.Good)
clearTimeout(args.new.item.id);
if (clonedNewInfo.state !== ViolationState.Good)
return;
var timeoutId = setTimeout(function (info) {
var updateInfo = __assign({}, info);
updateInfo.state = ViolationState.None;
updateInfo.messages = null;
_this._violationViewChangedEvent.notify(updateInfo);
clearTimeout(updateInfo.item.id);
}, 2000, clonedNewInfo);
_this._timeouts.push({ id: itemId, timeoutId: timeoutId });
};
this._violationViewChangedEvent = new EventObject();
this._violationService.addItemViolationStateChanged(this._onItemViolationStateChanged);
}
ViolationViewController.prototype.addViolationViewChanged = function (listener) { this._violationViewChangedEvent.add(listener); };
;
ViolationViewController.prototype.removeViolationViewChanged = function (listener) { this._violationViewChangedEvent.remove(listener); };
;
return ViolationViewController;
}());
export { ViolationViewController };
//# sourceMappingURL=ViolationViewController.js.map