Skip to content

Commit

Permalink
Merge pull request #7120 from IgniteUI/dmdimitrov/issue4158-8.2.x
Browse files Browse the repository at this point in the history
fix(excel-exporter): updated jszip version and added typings - 8.2.x
  • Loading branch information
DiyanDimitrov authored Apr 16, 2020
2 parents f79941d + cd97ca4 commit 26b0747
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 67 deletions.
58 changes: 23 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@
"@angular/platform-browser-dynamic": "^8.1.2",
"@angular/router": "^8.1.2",
"@types/hammerjs": "^2.0.36",
"@types/jszip": "^3.1.7",
"@types/source-map": "0.5.2",
"classlist.js": "^1.1.20150312",
"core-js": "^2.6.2",
"hammerjs": "^2.0.8",
"jszip": "^3.1.5",
"jszip": "^3.3.0",
"resize-observer-polyfill": "^1.5.1",
"rxjs": "^6.5.2",
"web-animations-js": "^2.3.2",
Expand Down
1 change: 1 addition & 0 deletions projects/igniteui-angular/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"whitelistedNonPeerDependencies": [
"@types/hammerjs",
"@types/jszip",
"hammerjs",
"jszip",
"resize-observer-polyfill"
Expand Down
1 change: 1 addition & 0 deletions projects/igniteui-angular/ng-package.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"whitelistedNonPeerDependencies": [
"@types/hammerjs",
"@types/jszip",
"hammerjs",
"jszip",
"resize-observer-polyfill"
Expand Down
3 changes: 2 additions & 1 deletion projects/igniteui-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@
],
"dependencies": {
"@types/hammerjs": "^2.0.36",
"@types/jszip": "^3.1.7",
"hammerjs": "^2.0.8",
"jszip": "^3.1.5",
"jszip": "^3.3.0",
"resize-observer-polyfill": "^1.5.1"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as JSZip from 'jszip/dist/jszip';
import * as JSZip from 'jszip';

import { EventEmitter, Injectable, Output } from '@angular/core';
import { ExcelElementsFactory } from './excel-elements-factory';
Expand Down Expand Up @@ -38,7 +38,7 @@ export interface IExcelExportEndedEventArgs extends IBaseEventArgs {
@Injectable()
export class IgxExcelExporterService extends IgxBaseExporter {

private static ZIP_OPTIONS = { compression: 'DEFLATE', type: 'base64' };
private static ZIP_OPTIONS = { compression: 'DEFLATE', type: 'base64' } as JSZip.JSZipGeneratorOptions<'base64'>;
private _xlsx: JSZip;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IExcelFile } from './excel-interfaces';
import { ExcelStrings } from './excel-strings';
import { WorksheetData } from './worksheet-data';

import * as JSZip from 'jszip/dist/jszip';
import * as JSZip from 'jszip';

/**
* @hidden
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as JSZip from 'jszip/dist/jszip';
import * as JSZip from 'jszip';

import {
ExcelFileTypes,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as JSZip from 'jszip/dist/jszip';
import * as JSZip from 'jszip';
import { ExcelFileTypes } from './excel-enums';
import { JSZipFiles } from './jszip-helper.spec';

export class JSZipWrapper {
private _zip: JSZip;
private _filesAndFolders: JSZip.ZipObject[];
private _filesAndFolders: string[];
private _fileContent = '';
private _files: any[];
private _files: {[key: string]: JSZip.JSZipObject};
private _filesContent: IFileContent[] = [];
private _hasValues = true;

Expand All @@ -19,32 +19,30 @@ export class JSZipWrapper {
}

private createFilesAndFolders() {
this._filesAndFolders = Object.keys(this._files).map((f: JSZip.ZipObject) => {
return f;
});
this._filesAndFolders = Object.keys(this._files).map(f => f);
}

get templateFilesAndFolders(): JSZip.ZipObject[] {
get templateFilesAndFolders(): string[] {
return this._filesAndFolders.filter((name) => JSZipFiles.templatesNames.indexOf(name) !== -1);
}

get dataFilesAndFolders(): JSZip.ZipObject[] {
get dataFilesAndFolders(): string[] {
return this._filesAndFolders.filter((name) => JSZipFiles.dataFilesAndFoldersNames.indexOf(name) !== -1);
}

get dataFilesOnly(): JSZip.ZipObject[] {
get dataFilesOnly(): string[] {
return this.getFiles(this.dataFilesAndFolders);
}

get templateFilesOnly(): JSZip.ZipObject[] {
get templateFilesOnly(): string[] {
return this.getFiles(this.templateFilesAndFolders);
}

get hasValues() {
return this._hasValues;
}

private getFiles(collection: JSZip.ZipObject[]) {
private getFiles(collection: string[]) {
return collection.filter((f) => this._files[f].dir === false);
}

Expand All @@ -54,14 +52,14 @@ export class JSZipWrapper {
return 'Zip file not found!';
}

await this._files[fileName].async('string')
await this._files[fileName].async('text')
.then((txt) => {
this._fileContent = txt;
});
}

/* Reads all files and stores their contents in this._filesContent. */
private async readFiles(files: any[]) {
private async readFiles(files: string[]) {
// const self = this;
this._filesContent = [];
for (const file of files) {
Expand Down Expand Up @@ -141,19 +139,6 @@ export class JSZipWrapper {
});
}

/* Verifies the contents of all files and asserts the result.
Optionally, a message can be passed in, which, if specified, will be shown in the beginning of the comparison result. */
public async verifyFilesContent(expectedData: IFileContent[], message = '') {
// const self = this;
let result;
const msg = (message !== '') ? message + '\r\n' : '';

await this.readFiles(this._files).then(() => {
result = this.compareFiles(this._filesContent, expectedData);
expect(result.areEqual).toBe(true, msg + result.differences);
});
}

/* Compares the content of two files based on the provided file type and expected value data. */
private compareFilesContent(currentContent: string, fileType: ExcelFileTypes, fileData: string) {
let result = true;
Expand Down

0 comments on commit 26b0747

Please sign in to comment.