/*-------------------------------------------------------------------------------------------------------------- * Copyright (c) insite-gmbh. All rights reserved. * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------------------------*/ import { Observable } from 'rxjs/Rx'; import { Injectable } from '@angular/core'; import { Http, Headers, Response } from '@angular/http'; import { InaxConfiguration, ProfileService, Result} from '../../../@inax/common'; @Injectable() /** * Service class to communicate with inax to handle excel read and write operations. * @class InaxExcelService * @classdesc Service class to communicate with inax to handle excel read and write operations. * @author insite-gmbh */ export class InaxExcelService { /** * constructor. * @param {Http} _http http service to handle web api calls. * @param {Configuration} _configuration configuration specifies signalRHubs, serveraddress,... . * @param {ProfileService} _profileService this service adds authentication data to the webApiRequests. */ constructor(private _http: Http, private _configuration: InaxConfiguration, private _profileService: ProfileService) { } /*********************************************************************** * WEB API * ********************************************************************/ /** * Determine all sheet names of the workbook. * @method sheets * @param {string} bookname This parameter is the name of the workbook.(Filename) * @return {Observable} returns a Observable which is called with a list of the existing sheet * names when the operation was finished. */ public sheets(bookname: string): Observable> { let accessUrl = this._configuration.buildRestUrl("Excel","GetSheets") + "?bookName=" + bookname; let headers = this._profileService.addAuthorization(new Headers()); return this._http.get(accessUrl, { headers }).map(res => res.json()); } /** * Create a new sheet and/or a new workbook (File) * @method create * @param {string} bookname This parameter is the name of the workbook.(Filename) * @param {string} sheetName This parameter is the name of the sheet we want to create. * @return {Observable} returns a http response to see if the operation succeeded. */ public create(bookName:string, sheetName:string): Observable { let accessUrl = this._configuration.buildRestUrl("Excel","Create") + "?bookName=" + bookName + "&sheetName=" + sheetName; let headers = this._profileService.addAuthorization(new Headers()); return this._http.post(accessUrl, null, { headers }); } /** * read a given datareference (for details see documentation of the matrix modul) * @method read * @param {string} dataRef specifies the read operation * @return {Observable>} returns the read result when the operation finished. */ public read(dataRef:string): Observable> { let accessUrl = this._configuration.buildRestUrl("Excel","Read") + "?dataRef=" + dataRef; let headers = this._profileService.addAuthorization(new Headers()); return this._http.get(accessUrl, { headers }).map(res => res.json()); } /** * write a value to the given datareference (for details see documentation of the matrix modul) * @method write * @param {string} dataRef specifies the write operation. * @param {string} val the data to write. * @return {Observable} returns a http response to see if the operation succeeded. */ public write(dataRef:string, val:any): Observable { let accessUrl = this._configuration.buildRestUrl("Excel","Write"); let headers = this._profileService.addAuthorization(new Headers()); return this._http.post(accessUrl, val, { headers }); } }