UNPKG

nakedobjects.spa

Version:

Single Page Application client for a Naked Objects application.

104 lines 5.22 kB
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 filter from 'lodash/filter'; import reduce from 'lodash/reduce'; var Goto = (function (_super) { __extends(Goto, _super); function Goto() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.shortCommand = "go"; _this.fullCommand = Usermessages.gotoCommand; _this.helpText = Usermessages.gotoHelp; _this.minArguments = 1; _this.maxArguments = 1; return _this; } Goto.prototype.isAvailableInCurrentContext = function () { return this.isObject() || this.isList(); }; Goto.prototype.doExecute = function (args, chained) { var _this = this; var arg0 = this.argumentAsString(args, 0); if (arg0 === undefined) { return this.returnResult("", Usermessages.outOfItemRange(undefined)); } if (this.isList()) { var itemNo_1; try { itemNo_1 = this.parseInt(arg0); } catch (e) { return this.returnResult("", e.message); } return this.getList().then(function (list) { return _this.attemptGotoLinkNumber(itemNo_1, list.value()); }); } if (this.isObject) { return this.getObject().then(function (obj) { if (_this.isCollection()) { var itemNo_2 = _this.argumentAsNumber(args, 0); var openCollIds = _this.ciceroRenderer.openCollectionIds(_this.routeData()); var coll = obj.collectionMember(openCollIds[0]); //Safe to assume always a List (Cicero doesn't support tables as such & must be open) return _this.context.getCollectionDetails(coll, Routedata.CollectionViewState.List, false).then(function (details) { return _this.attemptGotoLinkNumber(itemNo_2, details.value()); }); } else { var matchingProps = _this.matchingProperties(obj, arg0); var matchingRefProps = filter(matchingProps, function (p) { return !p.isScalar(); }); var matchingColls_1 = _this.matchingCollections(obj, arg0); switch (matchingRefProps.length + matchingColls_1.length) { case 0: return _this.returnResult("", Usermessages.noRefFieldMatch(arg0)); case 1: //TODO: Check for any empty reference if (matchingRefProps.length > 0) { var link = matchingRefProps[0].value().link(); if (link) { _this.urlManager.setItem(link); } return _this.returnResult("", ""); } else { return _this.returnResult("", "", function () { return _this.openCollection(matchingColls_1[0]); }); } default: var props = reduce(matchingRefProps, function (s, prop) { return s + prop.extensions().friendlyName() + "\n"; }, ""); var colls = reduce(matchingColls_1, function (s, coll) { return s + coll.extensions().friendlyName() + "\n"; }, ""); var s = "Multiple matches for " + arg0 + ":\n" + props + colls; return _this.returnResult("", s); } } }); } // should never happen return this.returnResult("", Usermessages.commandNotAvailable(this.fullCommand)); }; ; Goto.prototype.attemptGotoLinkNumber = function (itemNo, links) { var _this = this; if (itemNo < 1 || itemNo > links.length) { return this.returnResult("", Usermessages.outOfItemRange(itemNo)); } else { var link_1 = links[itemNo - 1]; // On UI, first item is '1' return this.returnResult("", "", function () { return _this.urlManager.setItem(link_1); }); } }; Goto.prototype.openCollection = function (collection) { this.closeAnyOpenCollections(); this.urlManager.setCollectionMemberState(collection.collectionId(), Routedata.CollectionViewState.List); }; return Goto; }(Command)); export { Goto }; //# sourceMappingURL=goto.js.map