tfabrica
Version:
library for TFabrica - TechSol
222 lines • 10.4 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);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var http_1 = require("@angular/http");
var router_1 = require("@angular/router");
var material_1 = require("@angular/material");
var material_2 = require("@angular/material");
var tfabrica_crud_service_1 = require("./tfabrica.crud.service");
var tfabrica_crud_report_model_1 = require("./tfabrica.crud.report.model");
var tfabrica_shared_service_1 = require("../main/tfabrica.shared.service");
var tfabrica_log_service_1 = require("../main/tfabrica.log.service");
var tfabrica_message_dialog_component_1 = require("../main/tfabrica.message.dialog.component");
var tfabrica_message_model_1 = require("../models/tfabrica.message.model");
var tfabrica_log_model_1 = require("../models/tfabrica.log.model");
var tfabrica_crud_selectfields_component_1 = require("./tfabrica.crud.selectfields.component");
var tfabrica_crud_filterfields_component_1 = require("./tfabrica.crud.filterfields.component");
var TfabricaCrudReadComponent = (function () {
function TfabricaCrudReadComponent(_http, _sharedService, _crudService, _logService, _router, _activatedRoute, dialog, snackBar) {
var _this = this;
this._http = _http;
this._sharedService = _sharedService;
this._crudService = _crudService;
this._logService = _logService;
this._router = _router;
this._activatedRoute = _activatedRoute;
this.dialog = dialog;
this.snackBar = snackBar;
this.initReportData();
/*
this._activatedRoute.params.subscribe((params: Params) => {
console.log("Change Parameter!");
let userId = params['userId'];
console.log(userId);
});
*/
var that = this;
this._router.events.subscribe(function (s) {
//console.log("router Events activated!");
//console.log(that._router.url);
//console.log(s);
if (s.url.startsWith("/main/(main:report)")) {
console.log("START >> initReportData");
_this.initReportData();
}
});
}
TfabricaCrudReadComponent.prototype.ngOnInit = function () {
};
TfabricaCrudReadComponent.prototype.initReportData = function () {
var that = this;
this.report = new tfabrica_crud_report_model_1.TfabricaCrudReport();
that._sharedService.returnSelectedVoice().properties.forEach(function (entry) {
//console.log(entry);
if (entry.key == "Report") {
//console.log(JSON.parse(entry.value.toString()));
try {
that.report.setFromJson(JSON.parse(entry.value.toString()));
}
catch (Err) {
that.report.setFromJson(entry.value);
}
//console.log(that.report);
that.report.setFiltersValuesFromUserParameters(that._sharedService.getUser().parameters);
that._crudService.initFromReport(that.report);
//get data from localStorage
/*
try {
let savedReport = that._crudService.getReport();
if (savedReport.title == that.report.title) {
that.report = savedReport;
that._crudService.initFromReport(that.report);
}
} catch (Err) {
}
*/
that._logService.AddLog(new tfabrica_log_model_1.TfabricaLog("initReportData", "initReportData", JSON.stringify(that.report), true));
}
});
if (that.report.executeImmediately) {
this.extractData();
}
};
TfabricaCrudReadComponent.prototype.extractData = function () {
var _this = this;
var that = this;
that.loading = true;
this._crudService.readData(that.report).subscribe(function (reportData) {
that.report = reportData;
_this._logService.AddLog(new tfabrica_log_model_1.TfabricaLog("Call Report: " + that.report.title, "Command", _this.report.composedCommand, true));
console.log(that.report);
console.log(that.report.fields);
that.loading = false;
//this.router.navigate(['/main', { outlets: { 'main': ['home'] } }]);
if (that.report.success) {
}
else {
_this.snackBar.open(that.report.message, "", {
duration: 2000,
});
var newMsg = new tfabrica_message_model_1.TfabricaMessage();
newMsg.message = that.report.message;
newMsg.success = false;
_this.displayMessage(newMsg);
}
}, function (err) {
// Log errors if any
console.log(err);
that.loading = false;
});
};
TfabricaCrudReadComponent.prototype.displayMessage = function (message) {
//this.filtersmenu.toggle();
var dialogConfig = new material_1.MdDialogConfig();
dialogConfig.data = message;
var dialogRef = this.dialog.open(tfabrica_message_dialog_component_1.TfabricaMessageDialogComponent, dialogConfig);
dialogRef.afterClosed().subscribe(function (result) {
console.log(result);
if (result != null) {
}
});
};
TfabricaCrudReadComponent.prototype.openSearchRight = function () {
console.log("filtersmenu.toggle");
this.filtersmenu.toggle();
};
TfabricaCrudReadComponent.prototype.openSearch = function () {
//this.filtersmenu.toggle();
var _this = this;
var dialogConfig = new material_1.MdDialogConfig();
//dialogConfig.width = "95%";
//dialogConfig.height = "95%";
var dialogRef = this.dialog.open(tfabrica_crud_filterfields_component_1.TfabricaCrudFilterFieldsComponent, dialogConfig);
dialogRef.afterClosed().subscribe(function (result) {
console.log(result);
if (result != null) {
_this.report.filters = result;
_this._crudService.setFilters(_this.report.filters);
_this.extractData();
}
});
};
TfabricaCrudReadComponent.prototype.startSearch = function () {
this.filtersmenu.toggle();
};
TfabricaCrudReadComponent.prototype.openFieldsList = function () {
//this.fieldsmenu.toggle();
var _this = this;
var dialogConfig = new material_1.MdDialogConfig();
dialogConfig.width = "95";
dialogConfig.height = "95";
console.log("openFieldsList()");
var dialogRef = this.dialog.open(tfabrica_crud_selectfields_component_1.TfabricaCrudSelectFieldsComponent, dialogConfig);
dialogRef.afterClosed().subscribe(function (result) {
console.log("openFieldsList()");
console.log("result");
console.log(result);
if (result != null) {
_this.report.setFields(result);
_this._crudService.setFields(_this.report.fields);
console.log("this.report.fields");
console.log(_this.report.fields);
console.log("this.report.fieldsToDisplay");
console.log(_this.report.fieldsToDisplay);
}
});
};
TfabricaCrudReadComponent.prototype.setFieldsList = function () {
this.fieldsmenu.toggle();
};
TfabricaCrudReadComponent.prototype.addNewRow = function () {
this._crudService.setOperation("I");
this._crudService.setSelectedRow(new Object());
this._crudService.setReport(this.report);
this._router.navigate(['/main', { outlets: { 'main': ['reportDetail'] } }]);
};
TfabricaCrudReadComponent.prototype.goToDetail = function (row) {
console.log("Go To Detail:");
console.log(row);
this._crudService.setOperation("U");
this._crudService.setSelectedRow(row);
this._crudService.setReport(this.report);
this._router.navigate(['/main', { outlets: { 'main': ['reportDetail'] } }]);
};
TfabricaCrudReadComponent.prototype.onRowClicked = function (row) {
console.log(row);
this.goToDetail(row);
};
return TfabricaCrudReadComponent;
}());
__decorate([
core_1.ViewChild('trightfiltersmenu'),
__metadata("design:type", Object)
], TfabricaCrudReadComponent.prototype, "filtersmenu", void 0);
__decorate([
core_1.ViewChild('trightfieldsmenu'),
__metadata("design:type", Object)
], TfabricaCrudReadComponent.prototype, "fieldsmenu", void 0);
TfabricaCrudReadComponent = __decorate([
core_1.Component({
selector: 't-crud-read',
template: require('./tfabrica.crud.read.component.html'),
}),
__metadata("design:paramtypes", [http_1.Http,
tfabrica_shared_service_1.TfabricaSharedService,
tfabrica_crud_service_1.TfabricaCrudService,
tfabrica_log_service_1.TfabricaLogService,
router_1.Router,
router_1.ActivatedRoute,
material_1.MdDialog,
material_2.MdSnackBar])
], TfabricaCrudReadComponent);
exports.TfabricaCrudReadComponent = TfabricaCrudReadComponent;
//# sourceMappingURL=tfabrica.crud.read.component.js.map