nakedobjects.spa
Version:
Single Page Application client for a Naked Objects application.
100 lines • 6.16 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 { CollectionViewState, InteractionMode } from '../route-data';
import { ContributedActionParentViewModel } from './contributed-action-parent-view-model';
import * as Helpers from './helpers-view-models';
import find from 'lodash/find';
import some from 'lodash/some';
var CollectionViewModel = (function (_super) {
__extends(CollectionViewModel, _super);
function CollectionViewModel(viewModelFactory, colorService, error, context, urlManager, configService, loggerService, collectionRep, routeData, forceReload) {
var _this = _super.call(this, context, viewModelFactory, urlManager, error, routeData.paneId) || this;
_this.colorService = colorService;
_this.configService = configService;
_this.loggerService = loggerService;
_this.collectionRep = collectionRep;
_this.routeData = routeData;
_this.reset = function (routeData, resetting) {
var state = routeData.collections[_this.collectionRep.collectionId()];
// collections are always shown as summary on transient
if (routeData.interactionMode === InteractionMode.Transient) {
state = CollectionViewState.Summary;
}
function getDefaultTableState(exts) {
if (exts.renderEagerly()) {
return exts.tableViewColumns() || exts.tableViewTitle() ? CollectionViewState.Table : CollectionViewState.List;
}
return CollectionViewState.Summary;
}
if (state == null) {
state = getDefaultTableState(_this.collectionRep.extensions());
}
_this.editing = routeData.interactionMode === InteractionMode.Edit;
if (resetting || state !== _this.currentState) {
var size = _this.collectionRep.size();
var itemLinks = _this.collectionRep.value();
if (size == null || size > 0) {
_this.mayHaveItems = true;
}
_this.details = Helpers.getCollectionDetails(size);
var getDetails = itemLinks == null || state === CollectionViewState.Table;
var actions = _this.collectionRep.actionMembers();
_this.setActions(actions, routeData);
if (state === CollectionViewState.Summary) {
_this.items = [];
}
else if (getDetails) {
_this.context.getCollectionDetails(_this.collectionRep, state, resetting).
then(function (details) {
_this.items = _this.viewModelFactory.getItems(details.value(), state === CollectionViewState.Table, routeData, _this);
_this.details = Helpers.getCollectionDetails(_this.items.length);
}).
catch(function (reject) { return _this.error.handleError(reject); });
}
else {
_this.items = _this.viewModelFactory.getItems(itemLinks, _this.currentState === CollectionViewState.Table, routeData, _this);
}
_this.currentState = state;
}
};
_this.doSummary = function () { return _this.urlManager.setCollectionMemberState(_this.collectionRep.collectionId(), CollectionViewState.Summary, _this.onPaneId); };
_this.doList = function () { return _this.urlManager.setCollectionMemberState(_this.collectionRep.collectionId(), CollectionViewState.List, _this.onPaneId); };
_this.doTable = function () { return _this.urlManager.setCollectionMemberState(_this.collectionRep.collectionId(), CollectionViewState.Table, _this.onPaneId); };
_this.hasTableData = function () { return _this.items && some(_this.items, function (i) { return i.tableRowViewModel; }); };
_this.description = function () { return _this.details.toString(); };
_this.noActions = function () { return _this.editing || !_this.actions || _this.actions.length === 0; };
_this.actionMember = function (id) {
var actionViewModel = find(_this.actions, function (a) { return a.actionRep.actionId() === id; });
if (actionViewModel) {
return actionViewModel.actionRep;
}
return _this.loggerService.throw("CollectionViewModel:actionMember no member " + id + " on " + _this.name);
};
_this.hasMatchingLocallyContributedAction = function (id) {
return id && _this.actions && _this.actions.length > 0 && _this.hasActionMember(id);
};
_this.title = collectionRep.extensions().friendlyName();
_this.presentationHint = collectionRep.extensions().presentationHint();
_this.pluralName = collectionRep.extensions().pluralName();
_this.name = collectionRep.collectionId().toLowerCase();
_this.colorService.toColorNumberFromType(collectionRep.extensions().elementType()).
then(function (c) { return _this.color = "" + _this.configService.config.linkColor + c; }).
catch(function (reject) { return _this.error.handleError(reject); });
_this.reset(routeData, forceReload);
return _this;
}
CollectionViewModel.prototype.hasActionMember = function (id) {
return !!find(this.actions, function (a) { return a.actionRep.actionId() === id; });
};
return CollectionViewModel;
}(ContributedActionParentViewModel));
export { CollectionViewModel };
//# sourceMappingURL=collection-view-model.js.map