ng2-json-editor
Version:
Angular2 component for editing large json documents
91 lines • 6.58 kB
JavaScript
/*
* This file is part of ng2-json-editor.
* Copyright (C) 2016 CERN.
*
* ng2-json-editor is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* ng2-json-editor is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ng2-json-editor; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* In applying this license, CERN does not
* waive the privileges and immunities granted to it by virtue of its status
* as an Intergovernmental Organization or submit itself to any jurisdiction.
*/
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 { Component, Input, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { AbstractFieldComponent } from '../abstract-field';
import { AppGlobalsService, JsonStoreService, PathUtilService, KeysStoreService, ProblemsService } from '../shared/services';
var ObjectFieldComponent = (function (_super) {
__extends(ObjectFieldComponent, _super);
function ObjectFieldComponent(appGlobalsService, problemsService, jsonStoreService, pathUtilService, changeDetectorRef, keysStoreService) {
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;
_this.keysStoreService = keysStoreService;
_this.isComplexListFieldItem = false;
return _this;
}
Object.defineProperty(ObjectFieldComponent.prototype, "keys$", {
get: function () {
return this.keysStoreService.forPath(this.pathString);
},
enumerable: true,
configurable: true
});
ObjectFieldComponent.prototype.deleteField = function (name) {
var fieldPath = this.path.concat(name);
this.jsonStoreService.removeIn(fieldPath);
};
ObjectFieldComponent.prototype.isPropertyDisabled = function (name) {
return this.schema.properties[name].disabled && !this.appGlobalsService.adminMode;
};
ObjectFieldComponent.prototype.getTitleDropdownItemTemplateNamesForChild = function (key) {
return this.schema.properties[key].titleDropdownItemTemplateNames;
};
return ObjectFieldComponent;
}(AbstractFieldComponent));
export { ObjectFieldComponent };
ObjectFieldComponent.decorators = [
{ type: Component, args: [{
selector: 'object-field',
styles: ["table.table { background-color: #f9f9f9; } "],
template: "<div [id]=\"pathString\"> <div *ngIf=\"isComplexListFieldItem\" class=\"pull-right\"> <add-nested-field-dropdown [pathString]=\"pathString\" [schema]=\"schema\" [isDisabled]=\"disabled\"></add-nested-field-dropdown> </div> <table class=\"table\" [ngClass]=\"redLeftBorderClass\"> <tr *ngFor=\"let key of keys$ | async; trackBy:trackByElement\"> <!-- SUB FIELD TITLE MENU --> <td class=\"label-holder\"> <div> <title-dropdown [title]=\"key | underscoreToSpace\" [isDisabled]=\"isPropertyDisabled(key)\"> <li *ngIf=\"schema.properties[key].type === 'array'\" class=\"title-dropdown-item\"> <add-new-element-button [path]=\"getPathForChild(key)\" [schema]=\"schema.properties[key]\"></add-new-element-button> </li> <li class=\"title-dropdown-item\"> <button type=\"button\" class=\"editor-btn-delete editor-btn-delete-text\" (click)=\"deleteField(key)\">Delete</button> </li> <ng-container *ngIf=\"getTitleDropdownItemTemplateNamesForChild(key)\"> <li *ngFor=\"let templateName of getTitleDropdownItemTemplateNamesForChild(key)\" class=\"title-dropdown-item custom-title-dropdown-item\"> <ng-template [ngTemplateOutlet]=\"appGlobalsService.templates[templateName]\"></ng-template> </li> </ng-container> </title-dropdown> </div> </td> <!-- SUB FIELD COMPONENT --> <td> <any-type-field [value]=\"value.get(key) | selfOrEmpty:schema.properties[key]\" [schema]=schema.properties[key] [path]=\"getPathForChild(key)\"></any-type-field> </td> </tr> <!-- ADD PATCHES FOR CHILDREN --> <tr *ngFor=\"let patch of addJsonPatches\"> <td class=\"label-holder\"> <title-dropdown [title]=\"patch.path | lastPathElement | underscoreToSpace\" [isDisabled]=\"true\"></title-dropdown> </td> <td> <add-or-replace-patch [patch]=\"patch\"></add-or-replace-patch> </td> </tr> <!-- REMOVE PATCH FOR ITSELF --> <tr *ngIf=\"removeJsonPatch\"> <patch-actions [patch]=\"removeJsonPatch\"></patch-actions> </tr> <!-- ADD SUB FIELD FROM SCHEMA DROPDOWN --> <tr> <td class=\"button-holder\"> <add-field-dropdown [fields]=\"keys$ | async\" [pathString]=\"pathString\" [schema]=\"schema\" [isDisabled]=\"disabled\"> <i class=\"fa fa-plus\"></i> <i class=\"fa fa-caret-down\"></i> </add-field-dropdown> </td> </tr> </table> <!-- REPLACE PATCH FOR ITSELF --> <div *ngIf=\"replaceJsonPatches && replaceJsonPatches[0]\"> <add-or-replace-patch [patch]=\"replaceJsonPatches[0]\"></add-or-replace-patch> </div> </div> ",
changeDetection: ChangeDetectionStrategy.OnPush
},] },
];
/** @nocollapse */
ObjectFieldComponent.ctorParameters = function () { return [
{ type: AppGlobalsService, },
{ type: ProblemsService, },
{ type: JsonStoreService, },
{ type: PathUtilService, },
{ type: ChangeDetectorRef, },
{ type: KeysStoreService, },
]; };
ObjectFieldComponent.propDecorators = {
'value': [{ type: Input },],
'schema': [{ type: Input },],
'path': [{ type: Input },],
'isComplexListFieldItem': [{ type: Input },],
};
//# sourceMappingURL=object-field.component.js.map