ng2-json-editor
Version:
Angular2 component for editing large json documents
112 lines • 6.85 kB
JavaScript
/*
* This file is part of ng2-json-editor.
* Copyright (C) 2017 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, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { AbstractSubscriberComponent } from '../../abstract-subscriber';
import { DomUtilService, JsonStoreService, AppGlobalsService } from '../../shared/services';
var PatchesConsoleTabComponent = (function (_super) {
__extends(PatchesConsoleTabComponent, _super);
function PatchesConsoleTabComponent(domUtilService, appGlobalsService, jsonStoreService, changeDetectorRef) {
var _this = _super.call(this) || this;
_this.domUtilService = domUtilService;
_this.appGlobalsService = appGlobalsService;
_this.jsonStoreService = jsonStoreService;
_this.changeDetectorRef = changeDetectorRef;
_this.patchesByPath = {};
return _this;
}
PatchesConsoleTabComponent.prototype.ngOnInit = function () {
var _this = this;
this.jsonStoreService.patchesByPath$
.takeUntil(this.isDestroyed)
.subscribe(function (patchesByPath) {
// filter paths with empty patch arrays to prevent from rendering empty <li> elements
var filtered = Object.entries(patchesByPath).filter(function (_a) {
var key = _a[0], value = _a[1];
return value.length > 0;
});
_this.patchesByPath = filtered.reduce(function (o, key) {
return Object.assign(o, (_a = {}, _a[key[0]] = key[1], _a));
var _a;
}, {});
_this.changeDetectorRef.markForCheck();
});
};
PatchesConsoleTabComponent.prototype.focusPatch = function (patch) {
this.domUtilService.focusPatch(patch);
};
Object.defineProperty(PatchesConsoleTabComponent.prototype, "patches", {
get: function () {
var _this = this;
return Object
.keys(this.patchesByPath)
.reduce(function (patches, path) { return patches.concat(_this.patchesByPath[path]); }, []);
},
enumerable: true,
configurable: true
});
Object.defineProperty(PatchesConsoleTabComponent.prototype, "customHeaderTemplate", {
get: function () {
return this.appGlobalsService.templates.patchesHeaderTemplate;
},
enumerable: true,
configurable: true
});
PatchesConsoleTabComponent.prototype.acceptAll = function () {
var _this = this;
this.patches
.forEach(function (patch) { return _this.jsonStoreService.applyPatch(patch); });
};
PatchesConsoleTabComponent.prototype.rejectAll = function () {
var _this = this;
this.patches
.forEach(function (patch) { return _this.jsonStoreService.rejectPatch(patch); });
};
return PatchesConsoleTabComponent;
}(AbstractSubscriberComponent));
export { PatchesConsoleTabComponent };
PatchesConsoleTabComponent.decorators = [
{ type: Component, args: [{
selector: 'patches-console-tab',
styles: [".list-group-item:hover { background-color: #faebcc; } .list-group-item:hover > .title { text-decoration: underline; } .list-group-item:hover.nested { background-color: #e2dcd1; } .list-group-item .title { cursor: pointer; color: #0074D9; } ",
".fa-bolt { color: #e67e22; } .icon-padding-left { padding-left: 8px; } .header-container { padding: 8px; } .header-container > button { margin-right: 4px; margin-left: 4px; } "],
template: "<ng-template tabHeading> <i class=\"fa fa-bolt\"></i> Conflicts <span class=\"badge\">{{patches.length}}</span> </ng-template> <div *ngIf=\"patches && patches.length > 0\" class=\"header-container\"> <ng-template [ngTemplateOutlet]=\"customHeaderTemplate\"></ng-template> <button class=\"btn btn-success\" (click)=\"acceptAll()\">Accept All<i class=\"fa fa-check icon-padding-left\"></i></button> <button class=\"btn btn-danger\" (click)=\"rejectAll()\">Reject All<i class=\"fa fa-times icon-padding-left\"></i></button> </div> <ul class=\"list-group\"> <li *ngFor=\"let path of patchesByPath | keys | sortAlphabetically\" class=\"list-group-item\"> <span *ngIf=\"patchesByPath[path].length === 1\" (click)=\"focusPatch(patchesByPath[path][0])\" role=\"button\" class=\"title\"> <i class=\"fa fa-bolt\"></i> {{patchesByPath[path][0].path}} - {{patchesByPath[path][0].op}} </span> <ng-container *ngIf=\"patchesByPath[path].length > 1\"> <span class=\"title\" role=\"button\" [attr.aria-controls]=\"path + '-collapse'\" (click)=\"collapse.toggle()\"> <i class=\"fa fa-expand\"></i> {{path}} ({{patchesByPath[path].length}}) </span> <ul class=\"list-group\" #collapse=\"bs-collapse\" [collapse]=\"true\" [attr.id]=\"path + '-collapse'\"> <li *ngFor=\"let patch of patchesByPath[path]\" class=\"list-group-item nested\"> <span class=\"title\" (click)=\"focusPatch(patch)\" role=\"button\"> <i class=\"fa fa-bolt\"></i> {{patch.path}} - {{patch.op}} </span> </li> </ul> </ng-container> </li> </ul> ",
changeDetection: ChangeDetectionStrategy.OnPush
},] },
];
/** @nocollapse */
PatchesConsoleTabComponent.ctorParameters = function () { return [
{ type: DomUtilService, },
{ type: AppGlobalsService, },
{ type: JsonStoreService, },
{ type: ChangeDetectorRef, },
]; };
//# sourceMappingURL=patches-console-tab.component.js.map