ng2-json-editor
Version:
Angular2 component for editing large json documents
64 lines • 3.29 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { List } from 'immutable';
import { AbstractFieldComponent } from '../abstract-field';
/**
* Abstract component to share code of common operations of all array fields
*
* Instance properties declared here only to resolve syntax errors.
* Hence they need to be declared in children extending components (with decarators if necessary)
*/
var AbstractListFieldComponent = (function (_super) {
__extends(AbstractListFieldComponent, _super);
function AbstractListFieldComponent(appGlobalsService, problemsService, jsonStoreService, pathUtilService, changeDetectorRef) {
var _this = _super.call(this, appGlobalsService, problemsService, pathUtilService, changeDetectorRef, jsonStoreService) || this;
_this.appGlobalsService = appGlobalsService;
_this.problemsService = problemsService;
_this.jsonStoreService = jsonStoreService;
_this.pathUtilService = pathUtilService;
_this.changeDetectorRef = changeDetectorRef;
return _this;
}
/**
* @param index - Index of the element that is moved
* @param direction - Movement direction. -1 for UP, +1 for DOWN
*/
AbstractListFieldComponent.prototype.moveElement = function (index, direction) {
this.jsonStoreService.moveIn(this.path, index, direction);
};
/**
* @param index - Index of the element to be deleted
*/
AbstractListFieldComponent.prototype.deleteElement = function (index, value) {
var elementPath = this.path.concat(index);
var patchIndex = this.supportValues.indexOf(value);
this.jsonStoreService.removeIn(elementPath);
// empty list as notSetValue, because there can be lists rendered on the UI, while they are absent in json (alwaysShow)
this.values = this.jsonStoreService.getIn(this.path, List());
// remove patches for this element
if (this.jsonStoreService.hasPatch(this.pathString)) {
this.jsonStoreService.deletePatchForElement(this.pathString);
}
// if patch is in child path that will be removed
if (this.jsonStoreService.hasPatchOrChildrenHavePatch(this.getPathStringForChild(patchIndex))) {
this.jsonStoreService.deletePatchForElement(this.getPathStringForChild(patchIndex));
}
};
AbstractListFieldComponent.prototype.getPathStringForChild = function (index) {
return "" + this.pathString + this.pathUtilService.separator + index;
};
AbstractListFieldComponent.prototype.hasPatchOrChildrenHavePatch = function () {
return this.jsonStoreService.hasPatchOrChildrenHavePatch(this.pathString);
};
return AbstractListFieldComponent;
}(AbstractFieldComponent));
export { AbstractListFieldComponent };
//# sourceMappingURL=abstract-list-field.component.js.map