UNPKG

@aurigma/design-atoms

Version:

Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.

41 lines 2.17 kB
import { ViolationState } from "./Violations/Violation"; import { EventObject } from "@aurigma/design-atoms-model/EventObject"; export class ViolationViewController { constructor(_violationService) { this._violationService = _violationService; this._timeouts = []; this._onItemViolationStateChanged = (args) => { const clonedNewInfo = Object.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); const itemId = clonedNewInfo.item.id; const clearTimeout = (id) => { var timeout = this._timeouts.find(t => t.id === id); if (timeout == null) return; this._timeouts = this._timeouts.filter(t => t.id !== timeout.id); clearInterval(timeout.timeoutId); }; if (clonedNewInfo.state !== ViolationState.Good) clearTimeout(args.new.item.id); if (clonedNewInfo.state !== ViolationState.Good) return; const timeoutId = setTimeout((info) => { const updateInfo = Object.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); } addViolationViewChanged(listener) { this._violationViewChangedEvent.add(listener); } ; removeViolationViewChanged(listener) { this._violationViewChangedEvent.remove(listener); } ; } //# sourceMappingURL=ViolationViewController.js.map