nakedobjects.spa
Version:
Single Page Application client for a Naked Objects application.
114 lines • 5.34 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Component, Input, ViewChildren, QueryList } from '@angular/core';
import { wrapAction } from '../action/action.component';
import { ActionComponent } from '../action/action.component';
import map from 'lodash/map';
import some from 'lodash/some';
import findIndex from 'lodash/findIndex';
import difference from 'lodash/difference';
import first from 'lodash/first';
import { safeUnsubscribe } from '../helpers-components';
var ActionListComponent = (function () {
function ActionListComponent() {
var _this = this;
this.actionHolders = [];
this.hasActions = function (menuItem) {
var actions = menuItem.actions;
return actions && actions.length > 0;
};
this.hasItems = function (menuItem) {
var items = menuItem.menuItems;
return items && items.length > 0;
};
this.menuName = function (menuItem) { return menuItem.name; };
this.menuItems = function (menuItem) { return menuItem.menuItems; };
this.menuActions = function (menuItem, index) {
if (!_this.actionHolders[index]) {
_this.actionHolders[index] = _this.getActionHolders(menuItem);
}
return _this.actionHolders[index];
};
this.toggleCollapsed = function (menuItem, index) { return menuItem.toggleCollapsed(); };
this.navCollapsed = function (menuItem) { return menuItem.navCollapsed; };
this.displayClass = function (menuItem) { return ({ collapsed: menuItem.navCollapsed, open: !menuItem.navCollapsed, rootMenu: !menuItem.name }); };
this.previousActionChildrenNames = [];
}
Object.defineProperty(ActionListComponent.prototype, "menuHolder", {
get: function () {
return this.holder;
},
set: function (mh) {
this.holder = mh;
this.actionHolders = []; // clear cache;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ActionListComponent.prototype, "items", {
get: function () {
return this.menuHolder.menuItems;
},
enumerable: true,
configurable: true
});
ActionListComponent.prototype.getActionHolders = function (menuItem) {
return map(menuItem.actions, function (a) { return wrapAction(a); });
};
ActionListComponent.prototype.focusFromIndex = function (actions, index) {
if (index === void 0) { index = 0; }
var toFocus = actions.toArray().slice(index);
if (toFocus && toFocus.length > 0) {
// until first element returns true
some(toFocus, function (i) { return i.focus(); });
}
};
ActionListComponent.prototype.focus = function (actions) {
if (actions && actions.length > 0) {
var actionChildrenNames = map(actions.toArray(), function (a) { return a.action.value; });
var newActions = difference(actionChildrenNames, this.previousActionChildrenNames);
var index = 0;
if (newActions && newActions.length > 0) {
var firstAction_1 = first(newActions);
index = findIndex(actions.toArray(), function (a) { return a.action.value === firstAction_1; });
index = index < 0 ? 0 : index;
}
this.previousActionChildrenNames = actionChildrenNames;
this.focusFromIndex(actions, index);
}
};
ActionListComponent.prototype.ngAfterViewInit = function () {
var _this = this;
this.focus(this.actionChildren);
this.sub = this.actionChildren.changes.subscribe(function (ql) { return _this.focus(ql); });
};
ActionListComponent.prototype.ngOnDestroy = function () {
safeUnsubscribe(this.sub);
};
return ActionListComponent;
}());
__decorate([
Input(),
__metadata("design:type", Object),
__metadata("design:paramtypes", [Object])
], ActionListComponent.prototype, "menuHolder", null);
__decorate([
ViewChildren(ActionComponent),
__metadata("design:type", QueryList)
], ActionListComponent.prototype, "actionChildren", void 0);
ActionListComponent = __decorate([
Component({
selector: 'nof-action-list',
template: require('./action-list.component.html'),
styles: [require('./action-list.component.css')]
})
], ActionListComponent);
export { ActionListComponent };
//# sourceMappingURL=action-list.component.js.map