UNPKG

tfabrica

Version:

library for TFabrica - TechSol

79 lines 4.13 kB
"use strict"; 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"); require("rxjs/Rx"); var rxjs_1 = require("rxjs"); var tfabrica_crud_report_model_1 = require("./tfabrica.crud.report.model"); var tfabrica_shared_service_1 = require("../main/tfabrica.shared.service"); var TfabricaCrudService = (function () { function TfabricaCrudService(_http, _shared) { this._http = _http; this._shared = _shared; } TfabricaCrudService.prototype.initFromReport = function (report) { this.setFields(report.fields); this.setFieldsToDisplay(report.fieldsToDisplay); }; TfabricaCrudService.prototype.readData = function (report) { var _this = this; var urlToCall = "/api/Report/ReadData"; console.log("Start call service: " + urlToCall); var bodyString = JSON.stringify(report); var headers = new http_1.Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON var options = new http_1.RequestOptions({ headers: headers }); // Create a request option return this._http.post(urlToCall, bodyString, options) // ...using post request .map(function (res) { return _this.extractReadData(res); }) // ...and calling .json() on the response to return data .catch(function (err) { return _this.handleError(err); }); //...errors if any }; TfabricaCrudService.prototype.extractReadData = function (res) { console.log(res); if (res.status < 200 || res.status >= 300) { throw new Error('Bad response status: ' + res.status); } var reportData = new tfabrica_crud_report_model_1.TfabricaCrudReport(); reportData.setFromJson(res.json().report); return reportData; }; TfabricaCrudService.prototype.handleError = function (error) { console.error(error); // log to console instead var errMsg = error.message || 'Server error'; console.error(errMsg); // log to console instead return rxjs_1.Observable.throw(errMsg); }; TfabricaCrudService.prototype.setFieldsToDisplay = function (fields) { localStorage.setItem('fieldsToDisplay', JSON.stringify(fields)); }; TfabricaCrudService.prototype.getFieldsToDisplay = function () { return JSON.parse(localStorage.getItem('fieldsToDisplay')); }; TfabricaCrudService.prototype.setFields = function (fields) { localStorage.setItem('fields', JSON.stringify(fields)); }; TfabricaCrudService.prototype.getFields = function () { return JSON.parse(localStorage.getItem('fields')); }; TfabricaCrudService.prototype.setFilters = function (filters) { localStorage.setItem('filters', JSON.stringify(filters)); }; TfabricaCrudService.prototype.getFilters = function () { return JSON.parse(localStorage.getItem('filters')); }; return TfabricaCrudService; }()); TfabricaCrudService = __decorate([ core_1.Injectable(), __metadata("design:paramtypes", [http_1.Http, tfabrica_shared_service_1.TfabricaSharedService]) ], TfabricaCrudService); exports.TfabricaCrudService = TfabricaCrudService; //# sourceMappingURL=tfabrica.crud.service.js.map