nakedobjects.spa
Version:
Single Page Application client for a Naked Objects application.
156 lines • 7.61 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 { Component, ElementRef, Renderer, ViewChild } from '@angular/core';
import reduce from 'lodash/reduce';
import { CiceroCommandFactoryService } from '../cicero-command-factory.service';
import { CiceroContextService } from '../cicero-context.service';
import { CiceroRendererService } from '../cicero-renderer.service';
import { ContextService } from '../context.service';
import { ErrorService } from '../error.service';
import { focus, safeUnsubscribe } from '../helpers-components';
import * as Ro from '../models';
import * as RtD from '../route-data';
import { UrlManagerService } from '../url-manager.service';
var CiceroComponent = (function () {
function CiceroComponent(commandFactory, ciceroRendererService, error, urlManager, ciceroContext, context, renderer) {
var _this = this;
this.commandFactory = commandFactory;
this.ciceroRendererService = ciceroRendererService;
this.error = error;
this.urlManager = urlManager;
this.ciceroContext = ciceroContext;
this.context = context;
this.renderer = renderer;
this.selectPreviousInput = function () { return setTimeout(function () { return _this.inputText = _this.previousInput; }); };
this.clearInput = function () { return _this.inputText = ""; };
}
CiceroComponent.prototype.render = function () {
switch (this.lastPaneRouteData.location) {
case RtD.ViewType.Home:
return this.ciceroRendererService.renderHome(this.lastPaneRouteData);
case RtD.ViewType.Object:
return this.ciceroRendererService.renderObject(this.lastPaneRouteData);
case RtD.ViewType.List:
return this.ciceroRendererService.renderList(this.lastPaneRouteData);
default:
return this.ciceroRendererService.renderError("unknown render error");
}
};
CiceroComponent.prototype.ngOnInit = function () {
var _this = this;
if (!this.paneRouteDataSub) {
this.paneRouteDataSub =
this.urlManager.getPaneRouteDataObservable(1)
.subscribe(function (paneRouteData) {
if (!paneRouteData.isEqual(_this.lastPaneRouteData)) {
_this.lastPaneRouteData = paneRouteData;
_this.render().
then(function (result) {
_this.writeInputOutput(result);
_this.executeCommands(_this.ciceroContext.chainedCommands);
}).
catch(function (reject) {
if (reject.category === Ro.ErrorCategory.ClientError && reject.clientErrorCode === Ro.ClientErrorCode.ExpiredTransient) {
_this.outputText = "The requested view of unsaved object details has expired.";
}
else {
var display = function (em) { return _this.outputText = em.invalidReason() || em.warningMessage; };
_this.error.handleErrorAndDisplayMessages(reject, display);
}
});
}
});
}
;
this.warnSub = this.context.warning$.subscribe(function (ws) { return _this.warnings = ws; });
this.errorSub = this.context.messages$.subscribe(function (ms) { return _this.messages = ms; });
};
CiceroComponent.prototype.ngOnDestroy = function () {
safeUnsubscribe(this.paneRouteDataSub);
safeUnsubscribe(this.warnSub);
safeUnsubscribe(this.errorSub);
};
CiceroComponent.prototype.executeCommand = function (cmd) {
var _this = this;
cmd.execute().
then(function (result) {
_this.writeInputOutput(result);
result.changeState();
}).
catch(function (reject) {
var display = function (em) { return _this.outputText = em.invalidReason() || em.warningMessage; };
_this.error.handleErrorAndDisplayMessages(reject, display);
});
};
CiceroComponent.prototype.executeCommands = function (cmds) {
if (cmds && cmds.length > 0) {
var cmd = cmds[0], chained = cmds.slice(1);
this.ciceroContext.chainedCommands = chained;
this.executeCommand(cmd);
}
};
CiceroComponent.prototype.writeInputOutput = function (result) {
if (result.input != null) {
this.inputText = result.input;
}
if (result.output != null) {
var warning = this.warnings && this.warnings.length > 0 ? reduce(this.warnings, function (s, w) { return "" + s + w + "\n"; }, "Warning: ") : "";
var messages = this.messages && this.messages.length > 0 ? reduce(this.messages, function (s, w) { return "" + s + w + "\n"; }, "") : "";
var prefix = "" + warning + messages;
var output = result.output != null ? result.output : "";
this.outputText = "" + prefix + output;
}
this.focusOnInput();
};
CiceroComponent.prototype.parseInput = function (input) {
var prevInput = this.commandFactory.preParse(input).input;
this.previousInput = prevInput ? prevInput.trim() : "";
var parseResult = this.commandFactory.getCommands(input);
if (parseResult.commands) {
this.executeCommands(parseResult.commands);
}
else if (parseResult.error) {
this.outputText = parseResult.error;
this.inputText = "";
}
};
;
CiceroComponent.prototype.autocomplete = function (input) {
input = input.trim();
var res = this.commandFactory.preParse(input);
this.writeInputOutput(res);
return false;
};
;
CiceroComponent.prototype.focusOnInput = function () {
focus(this.renderer, this.inputField);
};
return CiceroComponent;
}());
__decorate([
ViewChild("inputField"),
__metadata("design:type", ElementRef)
], CiceroComponent.prototype, "inputField", void 0);
CiceroComponent = __decorate([
Component({
selector: 'nof-cicero',
template: require('./cicero.component.html'),
styles: [require('./cicero.component.css')]
}),
__metadata("design:paramtypes", [CiceroCommandFactoryService,
CiceroRendererService,
ErrorService,
UrlManagerService,
CiceroContextService,
ContextService,
Renderer])
], CiceroComponent);
export { CiceroComponent };
//# sourceMappingURL=cicero.component.js.map