nakedobjects.spa
Version:
Single Page Application client for a Naked Objects application.
132 lines • 5.79 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 { Command } from './Command';
import * as Usermessages from '../user-messages';
import * as Routedata from '../route-data';
import reduce from 'lodash/reduce';
var Show = (function (_super) {
__extends(Show, _super);
function Show() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.shortCommand = "sh";
_this.fullCommand = Usermessages.showCommand;
_this.helpText = Usermessages.showHelp;
_this.minArguments = 0;
_this.maxArguments = 1;
return _this;
}
Show.prototype.isAvailableInCurrentContext = function () {
return this.isObject() || this.isCollection() || this.isList();
};
Show.prototype.doExecute = function (args, chained) {
var _this = this;
if (this.isCollection()) {
var arg = this.argumentAsString(args, 0, true);
try {
var _a = this.parseRange(arg), start_1 = _a.start, end_1 = _a.end;
return this.getObject().then(function (obj) {
var openCollIds = _this.ciceroRenderer.openCollectionIds(_this.routeData());
var coll = obj.collectionMember(openCollIds[0]);
return _this.renderCollectionItems(coll, start_1, end_1);
});
}
catch (e1) {
return this.returnResult("", e1.message);
}
}
else if (this.isList()) {
var arg = this.argumentAsString(args, 0, true);
try {
var _b = this.parseRange(arg), start_2 = _b.start, end_2 = _b.end;
return this.getList().then(function (list) { return _this.renderItems(list, start_2, end_2); });
}
catch (e2) {
return this.returnResult("", e2.message);
}
}
else if (this.isObject()) {
var fieldName_1 = this.argumentAsString(args, 0);
return this.getObject().then(function (obj) {
var props = _this.matchingProperties(obj, fieldName_1);
var colls = _this.matchingCollections(obj, fieldName_1);
//TODO - include these
var s;
switch (props.length + colls.length) {
case 0:
s = fieldName_1 ? Usermessages.doesNotMatch(fieldName_1) : Usermessages.noVisible;
break;
case 1:
s = props.length > 0 ? _this.renderPropNameAndValue(props[0]) : _this.ciceroRenderer.renderCollectionNameAndSize(colls[0]);
break;
default:
s = reduce(props, function (s, prop) { return s + _this.renderPropNameAndValue(prop); }, "");
s += reduce(colls, function (s, coll) { return s + _this.ciceroRenderer.renderCollectionNameAndSize(coll); }, "");
}
return _this.returnResult("", s);
});
}
throw new Error("unexpected view type");
};
;
Show.prototype.renderPropNameAndValue = function (pm) {
var name = pm.extensions().friendlyName();
var value;
var parent = pm.parent;
var props = this.context.getObjectCachedValues(parent.id());
var modifiedValue = props[pm.id()];
if (this.isEdit() && !pm.disabledReason() && modifiedValue) {
value = this.ciceroRenderer.renderFieldValue(pm, modifiedValue, this.mask) + (" (" + Usermessages.modified + ")");
}
else {
value = this.ciceroRenderer.renderFieldValue(pm, pm.value(), this.mask);
}
return name + ": " + value + "\n";
};
Show.prototype.renderCollectionItems = function (coll, startNo, endNo) {
var _this = this;
if (coll.value()) {
return this.renderItems(coll, startNo, endNo);
}
else {
return this.context.getCollectionDetails(coll, Routedata.CollectionViewState.List, false).
then(function (details) { return _this.renderItems(details, startNo, endNo); });
}
};
Show.prototype.renderItems = function (source, startNo, endNo) {
//TODO: problem here is that unless collections are in-lined value will be null.
var links = source.value();
if (links == null) {
throw new Error("unexpected null value");
}
var max = links.length;
if (!startNo) {
startNo = 1;
}
if (!endNo) {
endNo = max;
}
if (startNo > max || endNo > max) {
return this.returnResult("", Usermessages.highestItem(links.length));
}
if (startNo > endNo) {
return this.returnResult("", Usermessages.startHigherEnd);
}
var output = "";
var i;
for (i = startNo; i <= endNo; i++) {
output += Usermessages.item + " " + i + ": " + links[i - 1].title() + "\n";
}
return this.returnResult("", output);
};
return Show;
}(Command));
export { Show };
//# sourceMappingURL=show.js.map