UNPKG

@angular-jz/jz

Version:

jim jz

127 lines 5.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("rxjs/add/operator/toPromise"); var angular_oauth2_oidc_1 = require("angular-oauth2-oidc"); var server_config_1 = require("../config/server.config"); var http_1 = require("@angular/common/http"); var JZPageServiceConfig = /** @class */ (function () { function JZPageServiceConfig() { } return JZPageServiceConfig; }()); exports.JZPageServiceConfig = JZPageServiceConfig; var JZPageService = /** @class */ (function () { function JZPageService(injector, config) { this.config = config; //this.http = injector.get(Http); this.http = injector.get(http_1.HttpClient); this.oAuthService = injector.get(angular_oauth2_oidc_1.OAuthService); this.appServiceUrl = server_config_1.ServerConfig.apiHostUrls[config.appCode] + config.itemType + '/'; //this.headers = new Headers({ // 'Content-Type': 'application/json', // "Authorization": "Bearer " + this.oAuthService.getAccessToken() //}); //this.requestOptions = new RequestOptions({ headers: this.headers }); //this.fileHeaders = new Headers({ // 'Content-Type': 'application/json', // "Authorization": "Bearer " + this.oAuthService.getAccessToken() //}); } JZPageService.prototype.handleError = function (error) { //if (error.statusText) return Promise.reject(error.message || error); //return Promise.reject(error.message || error); return Promise.reject(error); }; JZPageService.prototype.post = function (url, data) { //const requestOptions = new RequestOptions({ // headers: new Headers({ // 'Content-Type': 'application/json', // "Authorization": "Bearer " + this.oAuthService.getAccessToken() // }) //}); //return this.http // .post(url, JSON.stringify(data), requestOptions) // .toPromise() // .then((response: any) => { // return response.json().result; // }) // .catch(this.handleError); //return this.http // .post(url, JSON.stringify(data), this.requestOptions) // .toPromise() // .then((response: any) => { // return response.json().result; // }) // .catch(this.handleError); return this.http.post(url, data).toPromise().then(function (response) { return response.result; //return response.json().result; }) .catch(this.handleError); }; JZPageService.prototype.postObservable = function (url, data) { return null; //const requestOptions = new RequestOptions({ // headers: new Headers({ // 'Content-Type': 'application/json', // "Authorization": "Bearer " + this.oAuthService.getAccessToken() // }) //}); //return this.http // .post(url, JSON.stringify(data), requestOptions); }; //public postFile(url: string, data: any): Promise<any> { // return this.http // .post(url, JSON.stringify(data), this.requestOptions) // .toPromise() // .then((response: any) => { // return response.json().result; // }) // .catch(this.handleError); //} JZPageService.prototype.buildUrl = function (methodName) { return this.appServiceUrl + methodName; }; JZPageService.prototype.loadPage = function (input, url) { if (input.page) { input.page.maxResultCount = input.page.pageSize; input.page.skipCount = (input.page.pageNo - 1) * input.page.pageSize; } return this.post(url ? url : this.appServiceUrl + ("Load" + this.config.itemType + "Page"), input); }; JZPageService.prototype.loadItemListPage = function (input, url) { if (input.page) { input.page.maxResultCount = input.page.pageSize; input.page.skipCount = (input.page.pageNo - 1) * input.page.pageSize; } return this.post(url ? url : this.appServiceUrl + ("Load" + this.config.itemType + "ListPage"), input); }; JZPageService.prototype.searchList = function (input, url) { if (input.page) { input.page.maxResultCount = input.page.pageSize; input.page.skipCount = (input.page.pageNo - 1) * input.page.pageSize; } return this.post(url ? url : this.appServiceUrl + ("Search" + this.config.itemType + "List"), input); }; JZPageService.prototype.loadViewItemPage = function (input, url) { return this.post(url ? url : this.appServiceUrl + ("LoadView" + this.config.itemType + "Page"), input); }; JZPageService.prototype.deleteItem = function (input, url) { return this.post(url ? url : this.appServiceUrl + ("Delete" + this.config.itemType), input); }; JZPageService.prototype.loadCreateItemPage = function (input, url) { return this.post(url ? url : this.appServiceUrl + ("LoadCreate" + this.config.itemType + "Page"), input); }; JZPageService.prototype.createItem = function (input, url) { return this.post(url ? url : this.appServiceUrl + ("Create" + this.config.itemType), input); }; JZPageService.prototype.loadEditItemPage = function (input, url) { return this.post(url ? url : this.appServiceUrl + ("LoadEdit" + this.config.itemType + "Page"), input); }; JZPageService.prototype.editItem = function (input, url) { return this.post(url ? url : this.appServiceUrl + ("Edit" + this.config.itemType), input); }; return JZPageService; }()); exports.JZPageService = JZPageService; //# sourceMappingURL=jz-page.service.js.map