UNPKG

nakedobjects.spa

Version:

Single Page Application client for a Naked Objects application.

60 lines 2.71 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 filter from 'lodash/filter'; import reduce from 'lodash/reduce'; var Menu = (function (_super) { __extends(Menu, _super); function Menu() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.shortCommand = "me"; _this.fullCommand = Usermessages.menuCommand; _this.helpText = Usermessages.menuHelp; _this.minArguments = 0; _this.maxArguments = 1; return _this; } Menu.prototype.isAvailableInCurrentContext = function () { return true; }; Menu.prototype.doExecute = function (args, chained) { var _this = this; var name = this.argumentAsString(args, 0); return this.context.getMenus() .then(function (menus) { var links = menus.value(); if (name) { //TODO: do multi-clause match var exactMatches = filter(links, function (t) { return (t.title() || "").toLowerCase() === name; }); var partialMatches = filter(links, function (t) { return (t.title() || "").toLowerCase().indexOf(name) > -1; }); links = exactMatches.length === 1 ? exactMatches : partialMatches; } switch (links.length) { case 0: return _this.returnResult("", Usermessages.doesNotMatchMenu(name)); case 1: var menuId_1 = links[0].rel().parms[0].value; _this.urlManager.setHome(); _this.urlManager.clearUrlState(1); return _this.returnResult("", "", function () { return _this.urlManager.setMenu(menuId_1); }); default: var label = name ? Usermessages.matchingMenus + "\n" : Usermessages.allMenus + "\n"; var ss = reduce(links, function (s, t) { return s + t.title() + "\n"; }, label); return _this.returnResult("", ss); } }); }; ; return Menu; }(Command)); export { Menu }; //# sourceMappingURL=menu.js.map