nakedobjects.spa
Version:
Single Page Application client for a Naked Objects application.
847 lines • 44.3 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 { RouteData, InteractionMode, CollectionViewState, ViewType, Pane, getOtherPane } from './route-data';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Location } from '@angular/common';
import { ConfigService } from './config.service';
import { LoggerService } from './logger.service';
import * as Models from "./models";
import * as Constants from './constants';
import filter from 'lodash/filter';
import forEach from 'lodash/forEach';
import keys from 'lodash/keys';
import map from 'lodash/map';
import fill from 'lodash/fill';
import zipObject from 'lodash/zipObject';
import mapValues from 'lodash/mapValues';
import pickBy from 'lodash/pickBy';
import reduce from 'lodash/reduce';
import some from 'lodash/some';
import pick from 'lodash/pick';
import omit from 'lodash/omit';
import values from 'lodash/values';
import mapKeys from 'lodash/mapKeys';
import merge from 'lodash/merge';
import without from 'lodash/without';
var Transition;
(function (Transition) {
Transition[Transition["Null"] = 0] = "Null";
Transition[Transition["ToHome"] = 1] = "ToHome";
Transition[Transition["ToMenu"] = 2] = "ToMenu";
Transition[Transition["ToDialog"] = 3] = "ToDialog";
Transition[Transition["FromDialog"] = 4] = "FromDialog";
Transition[Transition["FromDialogKeepHistory"] = 5] = "FromDialogKeepHistory";
Transition[Transition["ToObjectView"] = 6] = "ToObjectView";
Transition[Transition["ToList"] = 7] = "ToList";
Transition[Transition["LeaveEdit"] = 8] = "LeaveEdit";
Transition[Transition["Page"] = 9] = "Page";
Transition[Transition["ToTransient"] = 10] = "ToTransient";
Transition[Transition["ToRecent"] = 11] = "ToRecent";
Transition[Transition["ToAttachment"] = 12] = "ToAttachment";
Transition[Transition["ToObjectWithMode"] = 13] = "ToObjectWithMode";
Transition[Transition["ToMultiLineDialog"] = 14] = "ToMultiLineDialog";
})(Transition || (Transition = {}));
;
// keep in alphabetic order to help avoid name collisions
// all key map
var akm = {
action: "a",
actions: "as",
attachment: "at",
collection: "c",
dialog: "d",
errorCat: "et",
interactionMode: "i",
menu: "m",
object: "o",
page: "pg",
pageSize: "ps",
parm: "pm",
prop: "pp",
reload: "r",
selected: "s"
};
var UrlManagerService = (function () {
function UrlManagerService(router, location, configService, loggerService) {
var _this = this;
this.router = router;
this.location = location;
this.configService = configService;
this.loggerService = loggerService;
this.capturedPanes = [];
this.currentPaneId = Pane.Pane1;
this.setHome = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
_this.executeTransition({}, paneId, Transition.ToHome, function () { return true; });
};
this.setRecent = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
_this.executeTransition({}, paneId, Transition.ToRecent, function () { return true; });
};
this.setMenu = function (menuId, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var key = "" + akm.menu + paneId;
var newValues = zipObject([key], [menuId]);
_this.executeTransition(newValues, paneId, Transition.ToMenu, function (search) { return _this.getId(key, search) !== menuId; });
};
this.setDialog = function (dialogId, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var key = "" + akm.dialog + paneId;
var newValues = zipObject([key], [dialogId]);
_this.executeTransition(newValues, paneId, Transition.ToDialog, function (search) { return _this.getId(key, search) !== dialogId; });
};
this.setMultiLineDialog = function (dialogId, paneId) {
_this.pushUrlState();
var key = "" + akm.dialog + Pane.Pane1; // always on 1
var newValues = zipObject([key], [dialogId]);
_this.executeTransition(newValues, paneId, Transition.ToMultiLineDialog, function (search) { return _this.getId(key, search) !== dialogId; });
};
this.setDialogOrMultiLineDialog = function (actionRep, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
if (actionRep.extensions().multipleLines()) {
_this.setMultiLineDialog(actionRep.actionId(), paneId);
}
else {
_this.setDialog(actionRep.actionId(), paneId);
}
};
this.closeDialogKeepHistory = function (id, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
_this.closeOrCancelDialog(id, paneId, Transition.FromDialogKeepHistory);
};
this.closeDialogReplaceHistory = function (id, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
_this.closeOrCancelDialog(id, paneId, Transition.FromDialog);
};
this.setObject = function (resultObject, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var oid = resultObject.id();
var key = "" + akm.object + paneId;
var newValues = zipObject([key], [oid]);
_this.executeTransition(newValues, paneId, Transition.ToObjectView, function () { return true; });
};
this.setObjectWithMode = function (resultObject, newMode, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var oid = resultObject.id();
var okey = "" + akm.object + paneId;
var mkey = "" + akm.interactionMode + paneId;
var newValues = zipObject([okey, mkey], [oid, InteractionMode[newMode]]);
_this.executeTransition(newValues, paneId, Transition.ToObjectWithMode, function () { return true; });
};
this.setList = function (actionMember, parms, fromPaneId, toPaneId) {
if (fromPaneId === void 0) { fromPaneId = Pane.Pane1; }
if (toPaneId === void 0) { toPaneId = Pane.Pane1; }
var newValues = {};
var parent = actionMember.parent;
if (parent instanceof Models.DomainObjectRepresentation) {
newValues["" + akm.object + toPaneId] = parent.id();
}
if (parent instanceof Models.MenuRepresentation) {
newValues["" + akm.menu + toPaneId] = parent.menuId();
}
newValues["" + akm.action + toPaneId] = actionMember.actionId();
newValues["" + akm.page + toPaneId] = "1";
newValues["" + akm.pageSize + toPaneId] = _this.configService.config.defaultPageSize.toString();
newValues["" + akm.selected + toPaneId + "_"] = "0";
var newState = actionMember.extensions().renderEagerly() ? CollectionViewState[CollectionViewState.Table] : CollectionViewState[CollectionViewState.List];
newValues["" + akm.collection + toPaneId] = newState;
forEach(parms, function (p, id) { return _this.setId("" + akm.parm + toPaneId + "_" + id, p.toJsonString(_this.shortCutMarker, _this.urlShortCuts), newValues); });
_this.executeTransition(newValues, toPaneId, Transition.ToList, function () { return true; });
return newValues;
};
this.setProperty = function (href, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var oid = _this.getOidFromHref(href);
var key = "" + akm.object + paneId;
var newValues = zipObject([key], [oid]);
_this.executeTransition(newValues, paneId, Transition.ToObjectView, function () { return true; });
};
this.setItem = function (link, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var href = link.href();
var oid = _this.getOidFromHref(href);
var key = "" + akm.object + paneId;
var newValues = zipObject([key], [oid]);
_this.executeTransition(newValues, paneId, Transition.ToObjectView, function () { return true; });
};
this.setAttachment = function (attachmentlink, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var href = attachmentlink.href();
var okey = "" + akm.object + paneId;
var akey = "" + akm.attachment + paneId;
var oid = _this.getOidFromHref(href);
var pid = _this.getPidFromHref(href);
var newValues = zipObject([okey, akey], [oid, pid]);
_this.executeTransition(newValues, paneId, Transition.ToAttachment, function () { return true; });
};
this.toggleObjectMenu = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var key = akm.actions + paneId;
var actionsId = _this.getSearch()[key] ? null : "open";
var newValues = zipObject([key], [actionsId]);
_this.executeTransition(newValues, paneId, Transition.Null, function () { return true; });
};
this.setParameterValue = function (actionId, p, pv, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
return _this.checkAndSetValue(paneId, function (search) { return _this.getId("" + akm.action + paneId, search) === actionId; }, function (search) { return _this.setParameter(paneId, search, p, pv); });
};
this.setCollectionMemberState = function (collectionMemberId, state, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var key = "" + akm.collection + paneId + "_" + collectionMemberId;
var newValues = zipObject([key], [CollectionViewState[state]]);
_this.executeTransition(newValues, paneId, Transition.Null, function () { return true; });
};
this.setListState = function (state, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var key = "" + akm.collection + paneId;
var newValues = zipObject([key], [CollectionViewState[state]]);
_this.executeTransition(newValues, paneId, Transition.Null, function () { return true; });
};
this.setInteractionMode = function (newMode, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var key = "" + akm.interactionMode + paneId;
var routeParams = _this.getSearch();
var currentMode = _this.getInteractionMode(_this.getId(key, routeParams));
var transition;
if (currentMode === InteractionMode.Edit && newMode !== InteractionMode.Edit) {
transition = Transition.LeaveEdit;
}
else if (newMode === InteractionMode.Transient) {
transition = Transition.ToTransient;
}
else {
transition = Transition.Null;
}
var newValues = zipObject([key], [InteractionMode[newMode]]);
_this.executeTransition(newValues, paneId, transition, function () { return true; });
};
this.setItemSelected = function (item, isSelected, collectionId, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var key = "" + akm.selected + paneId + "_" + collectionId;
var currentSelected = _this.getSearch()[key];
var selectedArray = _this.arrayFromMask(currentSelected);
selectedArray[item] = isSelected;
var currentSelectedAsString = (_this.createMask(selectedArray)).toString();
var newValues = zipObject([key], [currentSelectedAsString]);
_this.executeTransition(newValues, paneId, Transition.Null, function () { return true; });
};
this.setAllItemsSelected = function (isSelected, collectionId, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var key = "" + akm.selected + paneId + "_" + collectionId;
var currentSelected = _this.getSearch()[key];
var selectedArray = _this.arrayFromMask(currentSelected);
fill(selectedArray, isSelected);
var currentSelectedAsString = (_this.createMask(selectedArray)).toString();
var newValues = zipObject([key], [currentSelectedAsString]);
_this.executeTransition(newValues, paneId, Transition.Null, function () { return true; });
};
this.setListPaging = function (newPage, newPageSize, state, paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var pageValues = {};
pageValues["" + akm.page + paneId] = newPage.toString();
pageValues["" + akm.pageSize + paneId] = newPageSize.toString();
pageValues["" + akm.collection + paneId] = CollectionViewState[state];
pageValues["" + akm.selected + paneId + "_"] = "0"; // clear selection
_this.executeTransition(pageValues, paneId, Transition.Page, function () { return true; });
};
this.setError = function (errorCategory, ec) {
var path = _this.getPath();
var segments = path.split("/");
var mode = segments[1];
var newPath = "/" + mode + "/error";
var search = {};
// always on pane 1
search[akm.errorCat + Pane.Pane1] = Models.ErrorCategory[errorCategory];
var result = { path: newPath, search: search, replace: false };
if (errorCategory === Models.ErrorCategory.HttpClientError &&
(ec === Models.HttpStatusCode.PreconditionFailed || ec === Models.HttpStatusCode.NotFound)) {
result.replace = true;
}
_this.setNewSearch(result);
};
this.getRouteData = function () {
var routeData = new RouteData(_this.configService, _this.loggerService);
_this.setPaneRouteData(routeData.pane1, Pane.Pane1);
_this.setPaneRouteData(routeData.pane2, Pane.Pane2);
return routeData;
};
this.getPaneRouteDataObservable = function (paneId) {
return _this.router.routerState.root.queryParams.map(function (ps) {
var routeData = new RouteData(_this.configService, _this.loggerService);
var paneRouteData = routeData.pane(paneId);
_this.setPaneRouteDataFromParms(paneRouteData, paneId, ps);
paneRouteData.location = _this.getViewType(_this.getLocation(paneId));
return paneRouteData;
});
};
this.pushUrlState = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
_this.capturedPanes[paneId] = _this.getUrlState(paneId);
};
this.getUrlState = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
_this.currentPaneId = paneId;
var path = _this.getPath();
var segments = path.split("/");
var paneType = segments[paneId + 1] || Constants.homePath;
var paneSearch = _this.capturePane(paneId);
// clear any dialogs so we don't return to a dialog
paneSearch = omit(paneSearch, "" + akm.dialog + paneId);
return { paneType: paneType, search: paneSearch };
};
this.getListCacheIndexFromSearch = function (search, paneId, newPage, newPageSize, format) {
var s1 = _this.getId("" + akm.menu + paneId, search) || "";
var s2 = _this.getId("" + akm.object + paneId, search) || "";
var s3 = _this.getId("" + akm.action + paneId, search) || "";
var parms = pickBy(search, function (v, k) { return !!k && k.indexOf(akm.parm + paneId) === 0; });
var mappedParms = mapValues(parms, function (v) { return decodeURIComponent(Models.decompress(v, _this.shortCutMarker, _this.urlShortCuts)); });
var s4 = reduce(mappedParms, function (r, n, k) { return r + (k + "=" + n + _this.keySeparator); }, "");
var s5 = "" + newPage;
var s6 = "" + newPageSize;
var s7 = format ? "" + format : "";
var ss = [s1, s2, s3, s4, s5, s6, s7];
return reduce(ss, function (r, n) { return r + _this.keySeparator + n; }, "");
};
this.getListCacheIndex = function (paneId, newPage, newPageSize, format) {
var search = _this.getSearch();
return _this.getListCacheIndexFromSearch(search, paneId, newPage, newPageSize, format);
};
this.popUrlState = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
_this.currentPaneId = paneId;
var capturedPane = _this.capturedPanes[paneId];
if (capturedPane) {
_this.capturedPanes[paneId] = null;
var search = _this.clearPane(_this.getSearch(), paneId);
search = merge(search, capturedPane.search);
var path = void 0;
var replace = void 0;
(_a = _this.setupPaneNumberAndTypes(paneId, capturedPane.paneType), path = _a.path, replace = _a.replace);
var result = { path: path, search: search, replace: replace };
_this.setNewSearch(result);
}
else {
// probably reloaded page so no state to pop.
// just go home
_this.setHome(paneId);
}
var _a;
};
this.clearUrlState = function (paneId) {
_this.currentPaneId = paneId;
_this.capturedPanes[paneId] = null;
};
this.swapPanes = function () {
var path = _this.getPath();
var segments = path.split("/");
var mode = segments[1], oldPane1 = segments[2], _a = segments[3], oldPane2 = _a === void 0 ? Constants.homePath : _a;
var newPath = "/" + mode + "/" + oldPane2 + "/" + oldPane1;
var search = _this.swapSearchIds(_this.getSearch());
_this.currentPaneId = getOtherPane(_this.currentPaneId);
var tree = _this.router.createUrlTree([newPath], { queryParams: search });
_this.router.navigateByUrl(tree);
};
this.cicero = function () { return _this.setMode(Constants.ciceroPath); };
this.gemini = function () { return _this.setMode(Constants.geminiPath); };
this.isGemini = function () { return _this.getMode() === Constants.geminiPath; };
this.applicationProperties = function () {
var newPath = "/" + Constants.geminiPath + "/" + Constants.applicationPropertiesPath;
_this.router.navigateByUrl(newPath);
};
this.logoff = function () {
var newPath = "/" + Constants.geminiPath + "/" + Constants.logoffPath;
_this.router.navigateByUrl(newPath);
};
this.currentpane = function () { return _this.currentPaneId; };
this.setHomeSinglePane = function () {
_this.currentPaneId = Pane.Pane1;
var path = _this.getPath();
var segments = path.split("/");
var mode = segments[1] || Constants.geminiPath;
var newPath = "/" + mode + "/" + Constants.homePath;
var tree = _this.router.createUrlTree([newPath]);
_this.router.navigateByUrl(tree);
};
this.singlePane = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
_this.currentPaneId = Pane.Pane1;
if (!_this.isSinglePane()) {
var paneToKeepId = paneId;
var paneToRemoveId = getOtherPane(paneToKeepId);
var path = _this.getPath();
var segments = path.split("/");
var mode = segments[1];
var paneToKeep = segments[paneToKeepId + 1];
var newPath = "/" + mode + "/" + paneToKeep;
var search = _this.getSearch();
if (paneToKeepId === Pane.Pane1) {
// just remove second pane
search = _this.clearPane(search, paneToRemoveId);
}
if (paneToKeepId === Pane.Pane2) {
// swap pane 2 to pane 1 then remove 2
search = _this.swapSearchIds(search);
search = _this.clearPane(search, Pane.Pane2);
}
var tree = _this.router.createUrlTree([newPath], { queryParams: search });
_this.router.navigateByUrl(tree);
}
};
this.isHome = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
return _this.isLocation(paneId, Constants.homePath);
};
this.isObject = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
return _this.isLocation(paneId, Constants.objectPath);
};
this.isList = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
return _this.isLocation(paneId, Constants.listPath);
};
this.isError = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
return _this.isLocation(paneId, Constants.errorPath);
};
this.isRecent = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
return _this.isLocation(paneId, Constants.recentPath);
};
this.isAttachment = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
return _this.isLocation(paneId, Constants.attachmentPath);
};
this.isApplicationProperties = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
return _this.isLocation(paneId, Constants.applicationPropertiesPath);
};
this.isMultiLineDialog = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
return _this.isLocation(paneId, Constants.multiLineDialogPath);
};
this.triggerPageReloadByFlippingReloadFlagInUrl = function (paneId) {
if (paneId === void 0) { paneId = Pane.Pane1; }
var search = _this.getSearch();
_this.toggleReloadFlag(search, paneId);
var result = { path: _this.getPath(), search: search, replace: true };
_this.setNewSearch(result);
};
this.shortCutMarker = configService.config.shortCutMarker;
this.urlShortCuts = configService.config.urlShortCuts;
this.keySeparator = this.configService.config.keySeparator;
}
UrlManagerService.prototype.createSubMask = function (arr) {
var nMask = 0;
var nFlag = 0;
if (arr.length > 31) {
var msg = "UrlManagerService:createSubMask Out of range " + arr.length;
this.loggerService.error(msg);
throw new TypeError(msg);
}
var nLen = arr.length;
for (nFlag; nFlag < nLen; nMask |= arr[nFlag] << nFlag++)
;
return nMask;
};
// convert from array of bools to mask string
UrlManagerService.prototype.createArrays = function (arr, arrays) {
arrays = arrays || [];
if (arr.length > 31) {
arrays.push(arr.slice(0, 31));
return this.createArrays(arr.slice(31), arrays);
}
arrays.push(arr);
return arrays;
};
UrlManagerService.prototype.createMask = function (arr) {
// split into smaller arrays if necessary
var _this = this;
var arrays = this.createArrays(arr);
var masks = map(arrays, function (a) { return _this.createSubMask(a).toString(); });
return reduce(masks, function (res, val) { return res + "-" + val; });
};
// convert from mask string to array of bools
UrlManagerService.prototype.arrayFromSubMask = function (sMask) {
var nMask = parseInt(sMask);
// nMask must be between 0 and 2147483647 - to keep simple we stick to 31 bits
if (nMask > 0x7fffffff || nMask < -0x80000000) {
var msg = "UrlManagerService:arrayFromSubMask Out of range " + nMask;
this.loggerService.error(msg);
throw new TypeError(msg);
}
var aFromMask = [];
var len = 31; // make array always 31 bit long as we may concat another on end
for (var nShifted = nMask; len > 0; aFromMask.push(Boolean(nShifted & 1)), nShifted >>>= 1, --len)
;
return aFromMask;
};
UrlManagerService.prototype.arrayFromMask = function (sMask) {
var _this = this;
sMask = sMask || "0";
var sMasks = sMask.split("-");
var maskArrays = map(sMasks, function (s) { return _this.arrayFromSubMask(s); });
return reduce(maskArrays, function (res, val) { return res.concat(val); }, []);
};
UrlManagerService.prototype.getSearch = function () {
var url = this.router.url;
return this.router.parseUrl(url).queryParams;
};
UrlManagerService.prototype.getPath = function () {
var url = this.router.url;
var end = url.indexOf(";");
end = end === -1 ? url.indexOf("?") : end;
var path = url.substring(0, end > 0 ? end : url.length);
return path;
};
UrlManagerService.prototype.setNewSearch = function (result) {
var tree = this.router.createUrlTree([result.path], { queryParams: result.search });
this.router.navigateByUrl(tree);
if (result.replace) {
var u = this.router.serializeUrl(tree);
this.location.replaceState(u);
}
};
UrlManagerService.prototype.getIds = function (typeOfId, paneId) {
return pickBy(this.getSearch(), function (v, k) { return !!k && k.indexOf(typeOfId + paneId) === 0; });
};
UrlManagerService.prototype.mapIds = function (ids) {
return mapKeys(ids, function (v, k) { return k.substr(k.indexOf("_") + 1); });
};
UrlManagerService.prototype.getAndMapIds = function (typeOfId, paneId) {
var ids = this.getIds(typeOfId, paneId);
return this.mapIds(ids);
};
UrlManagerService.prototype.getMappedValues = function (mappedIds) {
var _this = this;
return mapValues(mappedIds, function (v) { return Models.Value.fromJsonString(v, _this.shortCutMarker, _this.urlShortCuts); });
};
UrlManagerService.prototype.getInteractionMode = function (rawInteractionMode) {
return rawInteractionMode ? InteractionMode[rawInteractionMode] : InteractionMode.View;
};
UrlManagerService.prototype.getPaneParams = function (params, paneId) {
var paneIds = filter(keys(params), function (k) { return (k.indexOf(paneId.toString()) >= 0); });
var allRawParams = pick(params, paneIds);
var rawParamsWithoutReload = omit(allRawParams, akm.reload + paneId);
return { rp: allRawParams, rpwr: rawParamsWithoutReload };
};
UrlManagerService.prototype.setPaneRouteDataFromParms = function (paneRouteData, paneId, routeParams) {
var _this = this;
(_a = this.getPaneParams(routeParams, paneId), paneRouteData.rawParms = _a.rp, paneRouteData.rawParmsWithoutReload = _a.rpwr);
paneRouteData.menuId = this.getId(akm.menu + paneId, routeParams);
paneRouteData.actionId = this.getId(akm.action + paneId, routeParams);
paneRouteData.dialogId = this.getId(akm.dialog + paneId, routeParams);
var rawErrorCategory = this.getId(akm.errorCat + paneId, routeParams);
paneRouteData.errorCategory = rawErrorCategory ? Models.ErrorCategory[rawErrorCategory] : null;
paneRouteData.objectId = this.getId(akm.object + paneId, routeParams);
paneRouteData.actionsOpen = this.getId(akm.actions + paneId, routeParams);
var rawCollectionState = this.getId(akm.collection + paneId, routeParams);
paneRouteData.state = rawCollectionState ? CollectionViewState[rawCollectionState] : CollectionViewState.List;
var rawInteractionMode = this.getId(akm.interactionMode + paneId, routeParams);
paneRouteData.interactionMode = this.getInteractionMode(rawInteractionMode);
var collKeyMap = this.getAndMapIds(akm.collection, paneId);
paneRouteData.collections = mapValues(collKeyMap, function (v) { return CollectionViewState[v]; });
var collSelectedKeyMap = this.getAndMapIds(akm.selected, paneId);
paneRouteData.selectedCollectionItems = mapValues(collSelectedKeyMap, function (v) { return _this.arrayFromMask(v); });
var parmKeyMap = this.getAndMapIds(akm.parm, paneId);
paneRouteData.actionParams = this.getMappedValues(parmKeyMap);
paneRouteData.page = parseInt(this.getId(akm.page + paneId, routeParams));
paneRouteData.pageSize = parseInt(this.getId(akm.pageSize + paneId, routeParams));
paneRouteData.attachmentId = this.getId(akm.attachment + paneId, routeParams);
var _a;
};
UrlManagerService.prototype.setPaneRouteData = function (paneRouteData, paneId) {
var routeParams = this.getSearch();
this.setPaneRouteDataFromParms(paneRouteData, paneId, routeParams);
paneRouteData.validate(this.location.path());
};
UrlManagerService.prototype.isSinglePane = function () {
return this.getPath().split("/").length <= 3;
};
UrlManagerService.prototype.searchKeysForPane = function (search, paneId, raw) {
var ids = map(raw, function (s) { return s + paneId; });
return filter(keys(search), function (k) { return some(ids, function (id) { return k.indexOf(id) === 0; }); });
};
UrlManagerService.prototype.allSearchKeysForPane = function (search, paneId) {
var raw = values(akm);
return this.searchKeysForPane(search, paneId, raw);
};
UrlManagerService.prototype.clearPane = function (search, paneId) {
var toClear = this.allSearchKeysForPane(search, paneId);
return omit(search, toClear);
};
UrlManagerService.prototype.clearSearchKeys = function (search, paneId, keys) {
var toClear = this.searchKeysForPane(search, paneId, keys);
return omit(search, toClear);
};
UrlManagerService.prototype.paneIsAlwaysSingle = function (paneType) {
return paneType === Constants.multiLineDialogPath;
};
UrlManagerService.prototype.setupPaneNumberAndTypes = function (pane, newPaneType, newMode) {
var path = this.getPath();
var segments = path.split("/");
var mode = segments[1], pane1Type = segments[2], pane2Type = segments[3];
var changeMode = false;
var mayReplace = true;
var newPath = path;
if (newMode) {
var newModeString = newMode.toString().toLowerCase();
changeMode = mode !== newModeString;
mode = newModeString;
}
// changing item on pane 1
// make sure pane is of correct type
if (pane === Pane.Pane1 && pane1Type !== newPaneType) {
var single = this.isSinglePane() || this.paneIsAlwaysSingle(newPaneType);
newPath = "/" + mode + "/" + newPaneType + (single ? "" : "/" + pane2Type);
changeMode = false;
mayReplace = false;
}
// changing item on pane 2
// either single pane so need to add new pane of appropriate type
// or double pane with second pane of wrong type.
if (pane === Pane.Pane2 && (this.isSinglePane() || pane2Type !== newPaneType)) {
newPath = "/" + mode + "/" + pane1Type + "/" + newPaneType;
changeMode = false;
mayReplace = false;
}
if (changeMode) {
newPath = "/" + mode + "/" + pane1Type + "/" + pane2Type;
mayReplace = false;
}
return { path: newPath, replace: mayReplace };
};
UrlManagerService.prototype.capturePane = function (paneId) {
var search = this.getSearch();
var toCapture = this.allSearchKeysForPane(search, paneId);
return pick(search, toCapture);
};
UrlManagerService.prototype.getOidFromHref = function (href) {
var oid = Models.ObjectIdWrapper.fromHref(href, this.keySeparator);
return oid.getKey();
};
UrlManagerService.prototype.getPidFromHref = function (href) {
return Models.propertyIdFromUrl(href);
};
UrlManagerService.prototype.setValue = function (paneId, search, p, pv, valueType) {
this.setId("" + valueType + paneId + "_" + p.id(), pv.toJsonString(this.shortCutMarker, this.urlShortCuts), search);
};
UrlManagerService.prototype.setParameter = function (paneId, search, p, pv) {
this.setValue(paneId, search, p, pv, akm.parm);
};
UrlManagerService.prototype.getId = function (key, search) {
return Models.decompress(search[key], this.shortCutMarker, this.urlShortCuts);
};
UrlManagerService.prototype.setId = function (key, id, search) {
search[key] = Models.compress(id, this.shortCutMarker, this.urlShortCuts);
};
UrlManagerService.prototype.clearId = function (key, search) {
delete search[key];
};
UrlManagerService.prototype.validKeysForHome = function () {
return [akm.menu, akm.dialog, akm.reload];
};
UrlManagerService.prototype.validKeysForObject = function () {
return [akm.object, akm.interactionMode, akm.reload, akm.actions, akm.dialog, akm.collection, akm.prop, akm.selected];
};
UrlManagerService.prototype.validKeysForMultiLineDialog = function () {
return [akm.object, akm.dialog, akm.menu];
};
UrlManagerService.prototype.validKeysForList = function () {
return [akm.reload, akm.actions, akm.dialog, akm.menu, akm.action, akm.page, akm.pageSize, akm.selected, akm.collection, akm.parm, akm.object];
};
UrlManagerService.prototype.validKeysForAttachment = function () {
return [akm.object, akm.attachment];
};
UrlManagerService.prototype.validKeys = function (path) {
switch (path) {
case Constants.homePath:
return this.validKeysForHome();
case Constants.objectPath:
return this.validKeysForObject();
case Constants.listPath:
return this.validKeysForList();
case Constants.multiLineDialogPath:
return this.validKeysForMultiLineDialog();
case Constants.attachmentPath:
return this.validKeysForAttachment();
}
return [];
};
UrlManagerService.prototype.clearInvalidParmsFromSearch = function (paneId, search, path) {
if (path) {
var vks = this.validKeys(path);
var ivks = without.apply(void 0, [values(akm)].concat(vks));
return this.clearSearchKeys(search, paneId, ivks);
}
return search;
};
UrlManagerService.prototype.handleTransition = function (paneId, search, transition) {
var replace = true;
var path = this.getPath();
switch (transition) {
case (Transition.ToHome):
(_a = this.setupPaneNumberAndTypes(paneId, Constants.homePath), path = _a.path, replace = _a.replace);
search = this.clearPane(search, paneId);
break;
case (Transition.ToMenu):
search = this.clearPane(search, paneId);
break;
case (Transition.FromDialog):
replace = true;
break;
case (Transition.ToDialog):
case (Transition.FromDialogKeepHistory):
replace = false;
break;
case (Transition.ToObjectView):
(_b = this.setupPaneNumberAndTypes(paneId, Constants.objectPath), path = _b.path, replace = _b.replace);
replace = false;
search = this.clearPane(search, paneId);
this.setId(akm.interactionMode + paneId, InteractionMode[InteractionMode.View], search);
break;
case (Transition.ToObjectWithMode):
(_c = this.setupPaneNumberAndTypes(paneId, Constants.objectPath), path = _c.path, replace = _c.replace);
replace = false;
search = this.clearPane(search, paneId);
break;
case (Transition.ToList):
(_d = this.setupPaneNumberAndTypes(paneId, Constants.listPath), path = _d.path, replace = _d.replace);
this.clearId(akm.menu + paneId, search);
this.clearId(akm.object + paneId, search);
this.clearId(akm.dialog + paneId, search);
break;
case (Transition.LeaveEdit):
search = this.clearSearchKeys(search, paneId, [akm.prop]);
break;
case (Transition.Page):
replace = false;
break;
case (Transition.ToTransient):
replace = false;
break;
case (Transition.ToRecent):
(_e = this.setupPaneNumberAndTypes(paneId, Constants.recentPath), path = _e.path, replace = _e.replace);
search = this.clearPane(search, paneId);
break;
case (Transition.ToAttachment):
(_f = this.setupPaneNumberAndTypes(paneId, Constants.attachmentPath), path = _f.path, replace = _f.replace);
search = this.clearPane(search, paneId);
break;
case (Transition.ToMultiLineDialog):
(_g = this.setupPaneNumberAndTypes(Pane.Pane1, Constants.multiLineDialogPath), path = _g.path, replace = _g.replace); // always on 1
if (paneId === Pane.Pane2) {
// came from 2
search = this.swapSearchIds(search);
}
search = this.clearPane(search, Pane.Pane2); // always on pane 1
break;
default:
// null transition
break;
}
var segments = path.split("/");
var pane1Type = segments[2], pane2Type = segments[3];
search = this.clearInvalidParmsFromSearch(Pane.Pane1, search, pane1Type);
search = this.clearInvalidParmsFromSearch(Pane.Pane2, search, pane2Type);
return { path: path, search: search, replace: replace };
var _a, _b, _c, _d, _e, _f, _g;
};
UrlManagerService.prototype.executeTransition = function (newValues, paneId, transition, condition) {
var _this = this;
this.currentPaneId = paneId;
var search = this.getSearch();
if (condition(search)) {
var result = this.handleTransition(paneId, search, transition);
(search = result.search);
forEach(newValues, function (v, k) {
// k should always be non null
if (v)
_this.setId(k, v, search);
else
_this.clearId(k, search);
});
this.setNewSearch(result);
}
};
UrlManagerService.prototype.closeOrCancelDialog = function (id, paneId, transition) {
var key = "" + akm.dialog + paneId;
var existingValue = this.getSearch()[key];
if (existingValue === id) {
var newValues = zipObject([key], [null]);
this.executeTransition(newValues, paneId, transition, function () { return true; });
}
};
UrlManagerService.prototype.checkAndSetValue = function (paneId, check, set) {
this.currentPaneId = paneId;
var search = this.getSearch();
// only add field if matching dialog or dialog (to catch case when swapping panes)
if (check(search)) {
set(search);
var result = { path: this.getPath(), search: search, replace: false };
this.setNewSearch(result);
}
};
UrlManagerService.prototype.getViewType = function (view) {
switch (view) {
case Constants.homePath: return ViewType.Home;
case Constants.objectPath: return ViewType.Object;
case Constants.listPath: return ViewType.List;
case Constants.errorPath: return ViewType.Error;
case Constants.recentPath: return ViewType.Recent;
case Constants.attachmentPath: return ViewType.Attachment;
case Constants.applicationPropertiesPath: return ViewType.ApplicationProperties;
case Constants.multiLineDialogPath: return ViewType.MultiLineDialog;
}
return this.loggerService.throw("UrlManagerService:getViewType " + view + " is not a valid ViewType");
};
UrlManagerService.prototype.swapSearchIds = function (search) {
return mapKeys(search, function (v, k) { return k.replace(/(\D+)(\d{1})(\w*)/, function (match, p1, p2, p3) { return "" + p1 + (p2 === "1" ? "2" : "1") + p3; }); });
};
UrlManagerService.prototype.setMode = function (newMode) {
var path = this.getPath();
var segments = path.split("/");
var pane1 = segments[2];
var newPath = "/" + newMode + "/" + pane1;
var search = this.clearPane(this.getSearch(), Pane.Pane2);
var tree = this.router.createUrlTree([newPath], { queryParams: search });
this.router.navigateByUrl(tree);
};
UrlManagerService.prototype.getMode = function () {
var path = this.getPath();
var segments = path.split("/");
var mode = segments[1];
return mode;
};
UrlManagerService.prototype.getLocation = function (paneId) {
var path = this.getPath();
var segments = path.split("/");
return segments[paneId + 1]; // e.g. segments 0=~/1=cicero/2=home/3=home
};
UrlManagerService.prototype.isLocation = function (paneId, location) {
return this.getLocation(paneId) === location; // e.g. segments 0=~/1=cicero/2=home/3=home
};
UrlManagerService.prototype.toggleReloadFlag = function (search, paneId) {
var currentFlag = search[akm.reload + paneId];
var newFlag = currentFlag === "1" ? 0 : 1;
search[akm.reload + paneId] = newFlag;
return search;
};
return UrlManagerService;
}());
UrlManagerService = __decorate([
Injectable(),
__metadata("design:paramtypes", [Router,
Location,
ConfigService,
LoggerService])
], UrlManagerService);
export { UrlManagerService };
//# sourceMappingURL=url-manager.service.js.map