all files / actions/ pdf-export.js

98.62% Statements 143/145
97.53% Branches 79/81
100% Functions 16/16
98.62% Lines 143/145
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240   204× 204× 204× 204×   27959×     118× 118×   120× 120× 120×         120× 120×     119×   120×     118× 118×     118× 118× 118× 51×   118× 36×   35×     34×   36× 36×     82×           78×     118× 118×       118×   118× 106× 106×     105×   106×     118× 118× 118× 118× 118× 118× 118× 114× 113×   113× 113× 113× 112× 106×   33× 33× 33× 33× 33× 33× 33× 33× 33× 33× 33× 33× 33× 33× 33× 33× 33× 33×   106× 69× 69×   106× 104× 103×     102×         104×   106×     118× 118× 118×     117×   118× 39×   118× 118×     109×             153×                                                         87×          
define(["require", "exports", "./../export/pdf-base/pdf-style/gantt-theme", "./../export/pdf-base/index", "@syncfusion/ej2-base", "../export/export-helper", "@syncfusion/ej2-pdf-export", "../export/pdf-gantt"], function (require, exports, gantt_theme_1, index_1, ej2_base_1, export_helper_1, ej2_pdf_export_1, pdf_gantt_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfExport = (function () {
        function PdfExport(parent) {
            this.isPdfExport = false;
            this.parent = parent;
            this.helper = new export_helper_1.ExportHelper(this.parent);
            this.pdfDocument = undefined;
        }
        PdfExport.prototype.getModuleName = function () {
            return 'pdfExport';
        };
        PdfExport.prototype.destroy = function () {
        };
        PdfExport.prototype.initGantt = function () {
            this.pdfDocument = undefined;
            this.gantt = new pdf_gantt_1.PdfGantt(this.parent);
        };
        PdfExport.prototype.export = function (pdfExportProperties, isMultipleExport, pdfDoc, isBlob) {
            var _this = this;
            this.isBlob = isBlob;
            var args = {
                requestType: 'beforePdfExport',
                ganttObject: this.parent,
                cancel: false
            };
            this.parent.trigger('beforePdfExport', args);
            if (!ej2_base_1.isNullOrUndefined(this.parent.loadingIndicator) && this.parent.loadingIndicator.indicatorType === 'Shimmer') {
                this.parent.showMaskRow();
            }
            else {
                this.parent.showSpinner();
            }
            if (ej2_base_1.getValue('cancel', args)) {
                return new Promise(function (resolve, reject) {
                    return resolve();
                });
            }
            return new Promise(function (resolve, reject) {
                _this.exportWithData(pdfDoc, resolve, pdfExportProperties, isMultipleExport);
            });
        };
        PdfExport.prototype.exportWithData = function (pdfDoc, resolve, pdfExportProperties, isMultipleExport) {
            var _this = this;
            var data = [];
            if (ej2_base_1.isNullOrUndefined(pdfExportProperties)) {
                pdfExportProperties = {};
            }
            if (pdfExportProperties.fitToWidthSettings && pdfExportProperties.fitToWidthSettings.isFitToWidth) {
                if (pdfExportProperties.exportType === 'CurrentViewData') {
                    this.helper.beforeSinglePageExport['cloneFlatData'] = ej2_base_1.extend([], this.parent.currentViewData, null, true);
                }
                else if (pdfExportProperties.exportType === 'AllData') {
                    this.helper.beforeSinglePageExport['cloneFlatData'] = ej2_base_1.extend([], this.parent.flatData, null, true);
                }
                else {
                    this.helper.beforeSinglePageExport['cloneFlatData'] = ej2_base_1.extend([], this.parent.updatedRecords, null, true);
                }
                this.helper.beforeSinglePageExport['cloneCurrentViewData'] = ej2_base_1.extend([], this.parent.currentViewData, null, true);
                data = this.helper.beforeSinglePageExport['cloneFlatData'];
            }
            else {
                if (!ej2_base_1.isNullOrUndefined(pdfExportProperties.exportType)) {
                    if (pdfExportProperties.exportType === 'CurrentViewData') {
                        data = this.parent.currentViewData;
                    }
                    else {
                        data = this.parent.flatData;
                    }
                }
                else {
                    data = this.parent.updatedRecords;
                }
            }
            this.initGantt();
            Iif (!ej2_base_1.isNullOrUndefined(pdfDoc)) {
                this.pdfDocument = pdfDoc;
            }
            else {
                this.pdfDocument = new ej2_pdf_export_1.PdfDocument();
            }
            this.processExport(data, pdfExportProperties, isMultipleExport).then(function () {
                _this.parent.trigger('pdfExportComplete', _this.isBlob ? { promise: _this.blobPromise } : {});
                if (!ej2_base_1.isNullOrUndefined(_this.parent.loadingIndicator) && _this.parent.loadingIndicator.indicatorType === 'Shimmer') {
                    _this.parent.hideMaskRow();
                }
                else {
                    _this.parent.hideSpinner();
                }
                resolve(_this.pdfDocument);
            });
        };
        PdfExport.prototype.processExport = function (data, pdfExportProperties, isMultipleExport) {
            var _this = this;
            var section = this.pdfDocument.sections.add();
            this.processSectionExportProperties(section, pdfExportProperties);
            this.pdfPage = section.pages.add();
            this.pdfPageDimensions = this.pdfPage.getClientSize();
            return new Promise(function (resolve, reject) {
                _this.helper.processGridExport(data, _this.gantt, pdfExportProperties);
                _this.helper.initializePdf(_this.pdfDocument);
                resolve();
            }).then(function () {
                var format = new index_1.PdfTreeGridLayoutFormat();
                format.break = ej2_pdf_export_1.PdfLayoutBreakType.FitElement;
                var layouter = _this.gantt.drawGrid(_this.pdfPage, 0, 0, format);
                _this.gantt.drawChart(layouter);
                if (_this.helper.exportProps && _this.helper.exportProps.fitToWidthSettings &&
                    _this.helper.exportProps.fitToWidthSettings.isFitToWidth) {
                    _this.parent.zoomingProjectStartDate = _this.helper.beforeSinglePageExport['zoomingProjectStartDate'];
                    _this.parent.zoomingProjectEndDate = _this.helper.beforeSinglePageExport['zoomingProjectEndDate'];
                    _this.parent.cloneProjectStartDate = _this.helper.beforeSinglePageExport['cloneProjectStartDate'];
                    _this.parent.cloneProjectEndDate = _this.helper.beforeSinglePageExport['cloneProjectEndDate'];
                    _this.parent.timelineModule.customTimelineSettings = _this.helper.beforeSinglePageExport['customTimelineSettings'];
                    _this.parent.isTimelineRoundOff = _this.helper.beforeSinglePageExport['isTimelineRoundOff'];
                    _this.parent.timelineModule.topTier = _this.helper.beforeSinglePageExport['topTier'];
                    _this.parent.timelineModule.topTierCellWidth = _this.helper.beforeSinglePageExport['topTierCellWidth'];
                    _this.parent.timelineModule.topTierCollection = _this.helper.beforeSinglePageExport['topTierCollection'];
                    _this.parent.timelineModule.bottomTier = _this.helper.beforeSinglePageExport['bottomTier'];
                    _this.parent.timelineModule.bottomTierCellWidth = _this.helper.beforeSinglePageExport['bottomTierCellWidth'];
                    _this.parent.timelineModule.bottomTierCollection = _this.helper.beforeSinglePageExport['bottomTierCollection'];
                    _this.parent.timelineModule.totalTimelineWidth = _this.helper.beforeSinglePageExport['totalTimelineWidth'];
                    _this.parent.timelineModule.timelineStartDate = _this.helper.beforeSinglePageExport['timelineStartDate'];
                    _this.parent.timelineModule.timelineEndDate = _this.helper.beforeSinglePageExport['timelineEndDate'];
                    _this.parent.timelineModule.timelineRoundOffEndDate = _this.helper.beforeSinglePageExport['timelineRoundOffEndDate'];
                    _this.parent.perDayWidth = _this.helper.beforeSinglePageExport['perDayWidth'];
                    _this.parent.updatedConnectorLineCollection = _this.helper.beforeSinglePageExport['updatedConnectorLineCollection'];
                }
                if (_this.gantt.changeCloneProjectDates) {
                    _this.parent.cloneProjectStartDate.setHours(0);
                    _this.gantt.changeCloneProjectDates = false;
                }
                if (!isMultipleExport) {
                    if (!_this.isBlob) {
                        if (!ej2_base_1.isNullOrUndefined(pdfExportProperties) && pdfExportProperties.fileName) {
                            _this.pdfDocument.save(pdfExportProperties.fileName);
                        }
                        else {
                            _this.pdfDocument.save('Export.pdf');
                        }
                    }
                    else {
                        _this.blobPromise = _this.pdfDocument.save();
                    }
                    _this.pdfDocument.destroy();
                }
                return _this.pdfDocument;
            });
        };
        PdfExport.prototype.processSectionExportProperties = function (section, pdfExportProperties) {
            Eif (!ej2_base_1.isNullOrUndefined(pdfExportProperties)) {
                var pdfPageSettings = new ej2_pdf_export_1.PdfPageSettings();
                if (!ej2_base_1.isNullOrUndefined(pdfExportProperties.pageOrientation) && pdfExportProperties.pageOrientation === 'Portrait') {
                    pdfPageSettings.orientation = ej2_pdf_export_1.PdfPageOrientation.Portrait;
                }
                else {
                    pdfPageSettings.orientation = ej2_pdf_export_1.PdfPageOrientation.Landscape;
                }
                if (!ej2_base_1.isNullOrUndefined(pdfExportProperties.pageSize)) {
                    pdfPageSettings.size = this.getPageSize(pdfExportProperties.pageSize);
                }
                section.setPageSettings(pdfPageSettings);
                if (!ej2_base_1.isNullOrUndefined(pdfExportProperties.ganttStyle)) {
                    var defaultGanttTheme = new gantt_theme_1.PdfGanttTheme(pdfExportProperties.theme).style;
                    this.gantt.ganttStyle = ej2_base_1.extend({}, defaultGanttTheme, pdfExportProperties.ganttStyle, true);
                }
                else {
                    this.gantt.ganttStyle = new gantt_theme_1.PdfGanttTheme(pdfExportProperties.theme).style;
                }
            }
            else {
                this.gantt.ganttStyle = new gantt_theme_1.PdfGanttTheme(pdfExportProperties.theme).style;
            }
        };
        PdfExport.prototype.getPageSize = function (pageSize) {
            switch (pageSize) {
                case 'Letter':
                    return new ej2_pdf_export_1.SizeF(612, 792);
                case 'Note':
                    return new ej2_pdf_export_1.SizeF(540, 720);
                case 'Legal':
                    return new ej2_pdf_export_1.SizeF(612, 1008);
                case 'A0':
                    return new ej2_pdf_export_1.SizeF(2380, 3368);
                case 'A1':
                    return new ej2_pdf_export_1.SizeF(1684, 2380);
                case 'A2':
                    return new ej2_pdf_export_1.SizeF(1190, 1684);
                case 'A3':
                    return new ej2_pdf_export_1.SizeF(842, 1190);
                case 'A5':
                    return new ej2_pdf_export_1.SizeF(421, 595);
                case 'A6':
                    return new ej2_pdf_export_1.SizeF(297, 421);
                case 'A7':
                    return new ej2_pdf_export_1.SizeF(210, 297);
                case 'A8':
                    return new ej2_pdf_export_1.SizeF(148, 210);
                case 'A9':
                    return new ej2_pdf_export_1.SizeF(105, 148);
                case 'B0':
                    return new ej2_pdf_export_1.SizeF(2836, 4008);
                case 'B1':
                    return new ej2_pdf_export_1.SizeF(2004, 2836);
                case 'B2':
                    return new ej2_pdf_export_1.SizeF(1418, 2004);
                case 'B3':
                    return new ej2_pdf_export_1.SizeF(1002, 1418);
                case 'B4':
                    return new ej2_pdf_export_1.SizeF(709, 1002);
                case 'B5':
                    return new ej2_pdf_export_1.SizeF(501, 709);
                case 'Archa':
                    return new ej2_pdf_export_1.SizeF(648, 864);
                case 'Archb':
                    return new ej2_pdf_export_1.SizeF(864, 1296);
                case 'Archc':
                    return new ej2_pdf_export_1.SizeF(1296, 1728);
                case 'Archd':
                    return new ej2_pdf_export_1.SizeF(1728, 2592);
                case 'Arche':
                    return new ej2_pdf_export_1.SizeF(2592, 3456);
                case 'Flsa':
                    return new ej2_pdf_export_1.SizeF(612, 936);
                case 'HalfLetter':
                    return new ej2_pdf_export_1.SizeF(396, 612);
                case 'Letter11x17':
                    return new ej2_pdf_export_1.SizeF(792, 1224);
                case 'Ledger':
                    return new ej2_pdf_export_1.SizeF(1224, 792);
                default:
                    return new ej2_pdf_export_1.SizeF(595, 842);
            }
        };
        return PdfExport;
    }());
    exports.PdfExport = PdfExport;
});