UNPKG

stimulsoft-viewer-angular

Version:
1,219 lines (1,215 loc) 792 kB
import * as i0 from '@angular/core'; import { Injectable, EventEmitter, Component, Input, Output, ViewChild, NgModule } from '@angular/core'; import { Subject, throwError, EMPTY, catchError as catchError$1 } from 'rxjs'; import * as i1 from '@angular/common/http'; import { HttpParams } from '@angular/common/http'; import { timeout, catchError } from 'rxjs/operators'; import * as i4 from '@angular/common'; import { CommonModule } from '@angular/common'; import { trigger, state, style, transition, animate, keyframes } from '@angular/animations'; class ComponentDescription { constructor(type, caption, img, action, tooltip, arrow, menuItems, margin, selected) { this.type = type; this.caption = caption; this.img = img; this.action = action; this.tooltip = tooltip; this.arrow = arrow; this.menuItems = menuItems; this.margin = margin; this.selected = selected; this.selected = false; } } class ViewerEvent { constructor(name, value, bookmarkPage, bookmarkAnchor, componentGuid) { this.name = name; this.value = value; this.bookmarkPage = bookmarkPage; this.bookmarkAnchor = bookmarkAnchor; this.componentGuid = componentGuid; } } class ControlClass { constructor() { this.toolbar = new ControlProps(); this.reportPanel = new ControlProps(); this.drillDownPanel = new ControlProps(); this.findPanel = new ControlProps(); this.resourcesPanel = new ControlProps(); this.bookmarksPanel = new ControlProps(); this.navigatePanel = new ControlProps(); this.parametersPanel = new ControlProps(); this.dashboardsPanel = new ControlProps(); this.viewer = new ControlProps(); this.tooltip = new ControlProps(); this.aboutPanel = new ControlProps(); } get head() { return document.getElementsByTagName('head')[0]; } } class ControlProps { constructor(pageService, el) { this.pageService = pageService; this.el = el; this._visible = false; this.subject = new Subject(); this.enabled = true; this.layout = new Rectangle(); } get offsetHeight() { return this.el?.nativeElement.offsetHeight || 0; } get offsetWidth() { return this.el?.nativeElement.offsetWidth || 0; } set visible(value) { this._visible = value; this.subject.next(value); this.pageService?.calculateLayout(); } get visible() { return this._visible; } getVisibility() { return this.subject.asObservable(); } get exists() { return this.el != null; } } class Rectangle { set top(value) { this._top = value; } get top() { return this._top; } constructor(width = 0, height = 0, left = 0, bottom = 0, right = 0) { this.width = width; this.height = height; this.left = left; this.bottom = bottom; this.right = right; this._top = 0; } } class BookmarkNode { constructor(name, url, page, compunentGuid, nodes, open, selected) { this.name = name; this.url = url; this.page = page; this.compunentGuid = compunentGuid; this.nodes = nodes; this.open = open; this.selected = selected; } } class InteractionParams { constructor(action, drillDownParameters, drillDownGuid, dashboardDrillDownGuid, variables, sortingParameters, collapsingParameters, isBindingVariable) { this.action = action; this.drillDownParameters = drillDownParameters; this.drillDownGuid = drillDownGuid; this.dashboardDrillDownGuid = dashboardDrillDownGuid; this.variables = variables; this.sortingParameters = sortingParameters; this.collapsingParameters = collapsingParameters; this.isBindingVariable = isBindingVariable; } } class InteractionObject { constructor(paramsVariables, countColumns, countInColumn) { this.paramsVariables = paramsVariables; this.countColumns = countColumns; this.countInColumn = countInColumn; } } class Variable { constructor(name, alias, description, basicType, type, allowUserValues, dateTimeType, items, key, value, keyTo, isChecked = true, focusOnCreate, visible = true, binding, isNull, isFirstInitialization, checkedStates, isChanged, allowNullableString) { this.name = name; this.alias = alias; this.description = description; this.basicType = basicType; this.type = type; this.allowUserValues = allowUserValues; this.dateTimeType = dateTimeType; this.items = items; this.key = key; this.value = value; this.keyTo = keyTo; this.isChecked = isChecked; this.focusOnCreate = focusOnCreate; this.visible = visible; this.binding = binding; this.isNull = isNull; this.isFirstInitialization = isFirstInitialization; this.checkedStates = checkedStates; this.isChanged = isChanged; this.allowNullableString = allowNullableString; } } class DateTimeObject { constructor(year, month, day, hours, minutes, seconds) { this.year = year; this.month = month; this.day = day; this.hours = hours; this.minutes = minutes; this.seconds = seconds; } } class Item { constructor(name, caption, imageName, key, haveSubMenu, imageSizes, selected, type) { this.name = name; this.caption = caption; this.imageName = imageName; this.key = key; this.haveSubMenu = haveSubMenu; this.imageSizes = imageSizes; this.selected = selected; this.type = type; } } class Message { constructor(action, data, subAction) { this.action = action; this.data = data; this.subAction = subAction; } } class Form { constructor(name, left, top, isMooving = false, level, formData) { this.name = name; this.left = left; this.top = top; this.isMooving = isMooving; this.level = level; this.formData = formData; } } class ExportFormSettings { constructor(components, cSettings, openAfterExport, groups, update) { this.components = components; this.cSettings = cSettings; this.openAfterExport = openAfterExport; this.groups = groups; this.update = update; } } class ExportGroup { constructor(opened) { this.opened = opened; } } class ExportComponent { constructor(name, type, margin, label, tooltip, caption, checked, width, disabled, items, key) { this.name = name; this.type = type; this.margin = margin; this.label = label; this.tooltip = tooltip; this.caption = caption; this.checked = checked; this.width = width; this.disabled = disabled; this.items = items; this.key = key; } } class DrillDown { constructor(caption, selected = false, reportParams, visible) { this.caption = caption; this.selected = selected; this.reportParams = reportParams; this.visible = visible; } } class ErrorMessage { constructor(error, type) { this.error = error; this.type = type; } } class Resource { constructor(name, type, alias, id) { this.name = name; this.type = type; this.alias = alias; this.id = id; } } class NotificationFormOptions { constructor(image, message, description, buttonCaption, cancelAction, action) { this.image = image; this.message = message; this.description = description; this.buttonCaption = buttonCaption; this.cancelAction = cancelAction; this.action = action; } } class ModelService { constructor() { this._reportParams = {}; this.showDashboard = false; this.controls = new ControlClass(); this.pages = []; this.months = []; this.dayOfWeek = []; this.dateRanges = []; this.encodingData = []; this.pdfSecurityCertificates = []; this.paperSizes = []; this.drillDownButtons = []; this.showProgress = false; } get reportParams() { return this._reportParams; } set reportParams(parameters) { this._reportParams.pagesArray = parameters.pagesArray; // Apply new report parameters, if not update current page if (parameters.action && parameters.action !== 'GetPages') { this.reportParams.type = parameters.reportType; this.reportParams.drillDownGuid = parameters.drillDownGuid; this.reportParams.dashboardDrillDownGuid = parameters.dashboardDrillDownGuid; this.reportParams.pagesCount = parameters.pagesCount; if (parameters.pageNumber != null) { this.reportParams.pageNumber = parameters.pageNumber; } this.reportParams.zoom = parameters.zoom; this.reportParams.viewMode = parameters.viewMode; this.reportParams.reportFileName = parameters.reportFileName; this.reportParams.collapsingStates = parameters.collapsingStates; if (parameters.bookmarksContent) { this.reportParams.bookmarksContent = parameters.bookmarksContent; } if (parameters.resources) { this.reportParams.resources = parameters.resources; } this.reportParams.isCompilationMode = parameters.isCompilationMode; if (parameters.variablesValues) { this.reportParams.variablesValues = parameters.variablesValues; } if (parameters.parametersDateFormat) { this.options.appearance.parametersPanelDateFormat = parameters.parametersDateFormat; } if (parameters.tableOfContentsPointers) this.reportParams.tableOfContentsPointers = parameters.tableOfContentsPointers; this.reportParams.isEditableReport = parameters.isEditableReport; if (parameters.userValues) { this.options.userValues = parameters.userValues; } this.reportParams.dashboards = parameters.dashboards; this.reportParams.previewSettings = parameters.previewSettings; } } setReportParams(parameters) { this._reportParams = parameters; } getReportParams() { return this.copyObject(this._reportParams); } copyObject(o) { if (!o || 'object' !== typeof o) { return o; } const c = 'function' === typeof o.pop ? [] : {}; let p; let v; for (p in o) { if (o.hasOwnProperty(p) && p !== 'pagesArray') { v = o[p]; if (v && 'object' === typeof v) { c[p] = this.copyObject(v); } else { c[p] = v; } } } return c; } set options(data) { this._options = this.toLower(data.options); if (data.jsOptions) { for (const key in data.jsOptions) { if (data.jsOptions.hasOwnProperty(key)) { this._options[key] = data.jsOptions[key]; } } } if (data.defaultSettings?.StiExcelExportSettings?.ExcelType != null) { let excelType = data.defaultSettings.StiExcelExportSettings.ExcelType; if (excelType == 'Excel2007') { excelType = 'Excel'; } else if (excelType == 'ExcelBinary') { excelType = 'ExcelBiff'; } data.defaultSettings.StiExcelExportSettings.ExcelType = excelType; } this._options.exports.defaultSettings = data.defaultSettings; this.localization = data.loc; this.months = data.months; this.dayOfWeek = data.dayOfWeek; this.images = data.images; this.dateRanges = data.dateRanges; this.paperSizes = data.paperSizes; this.encodingData = data.encodingData; this.pdfSecurityCertificates = data.pdfSecurityCertificates; this.clearViewerState(); this.setupOptions(); } get options() { return this._options; } loc(attr) { return this.localization[attr] ?? attr; } img(name) { if (name != null && name.length > 0 && !this.images[name]) { //console.warn(`Image: ${name} not found`); } return this.images[name] ?? ''; } toLower(obj) { const result = {}; Object.keys(obj).forEach(key => { result[key.substr(0, 1).toLowerCase() + key.substr(1)] = (typeof (obj[key]) === 'object' && obj[key] !== null) ? this.toLower(obj[key]) : obj[key]; }); return result; } clear() { this._options = undefined; this._reportParams = {}; this._imagesForBookmark = undefined; this.pages = []; this.form = null; } clearViewerState() { this.reportParams = {}; this.reportParams.type = 'Auto'; this.reportParams.pageNumber = 0; this.reportParams.originalPageNumber = 0; this.reportParams.drillDownGuid = null; this.reportParams.dashboardDrillDownGuid = null; this.reportParams.collapsingStates = null; this.reportParams.bookmarksContent = null; this.reportParams.editableParameters = null; this.reportParams.resources = null; this.reportParams.drillDownParameters = []; this.reportParams.elementName = null; this.reportParams.variablesValues = null; this.reportParams.tableOfContentsPointers = []; this.reportParams.isEditableReport = false; //this.options.viewerId = this.newToken(); this.options.clientGuid = this.newToken(); this.options.paramsVariables = null; this.options.multiFilterStates = null; this.options.isParametersReceived = false; this.options.drillDownInProgress = false; this.options.displayModeFromReport = null; this.options.currentParameterWidth = null; this.options.currentParameterAlignment = "Left"; // this.controls.mainPanel.style.background = ''; // this.tableElementGridStates = {}; // Restore current page number, if reload current report if (this.reportParams.prevPageNumber) { this.reportParams.pageNumber = this.reportParams.prevPageNumber; delete this.reportParams.prevPageNumber; } this.fullScreenOptions = null; this.drillDownButtons = []; this.controls.parametersPanel.visible = false; this.controls.bookmarksPanel.visible = false; this.interactions = null; /* this.controls.drillDownPanel.visible = false; this.controls.findPanel.visible = false; this.controls.parametersPanel.visible = false; this.controls.resourcesPanel.visible = false;*/ } style(value) { return value !== '' && value != null ? value : ''; } createPostParameters(data, asObject = true, useOptions = true) { let params; // Object params const postParams = { stiweb_component: 'Viewer', stiweb_imagesScalingFactor: this.getImagesScalingFactor() }; if (this.properties) { postParams['properties'] = this.encode(JSON.stringify(this.properties)); } if (this.options && useOptions) { params = { viewerId: this.options.viewerId, routes: this.options.routes, formValues: this.options.formValues, clientGuid: this.options.clientGuid, drillDownGuid: this.reportParams.drillDownGuid, dashboardDrillDownGuid: this.reportParams.dashboardDrillDownGuid, cacheMode: this.options.server.cacheMode, cacheTimeout: this.options.server.cacheTimeout, cacheItemPriority: this.options.server.cacheItemPriority, pageNumber: this.reportParams.pageNumber, originalPageNumber: this.reportParams.originalPageNumber, reportType: this.reportParams.type, zoom: (this.reportParams.zoom && this.reportParams.zoom > 0) ? this.reportParams.zoom : (this.options?.toolbar?.zoom > 0 ? this.options?.toolbar?.zoom : 100), viewMode: this.reportParams.viewMode || this.options.toolbar.viewMode, multiPageWidthCount: this.reportParams.multiPageWidthCount, multiPageHeightCount: this.reportParams.multiPageHeightCount, multiPageContainerWidth: this.reportParams.multiPageContainerWidth, multiPageContainerHeight: this.reportParams.multiPageContainerHeight, multiPageMargins: this.reportParams.multiPageMargins, showBookmarks: this.options.toolbar.showBookmarksButton, openLinksWindow: this.options.appearance.openLinksWindow, chartRenderType: this.options.appearance.chartRenderType, reportDisplayMode: (this.options.displayModeFromReport || this.options.appearance.reportDisplayMode), drillDownParameters: this.reportParams.drillDownParameters, editableParameters: this.reportParams.editableParameters, useRelativeUrls: this.options.server.useRelativeUrls, passQueryParametersForResources: this.options.server.passQueryParametersForResources, passQueryParametersToReport: this.options.server.passQueryParametersToReport, version: this.options.shortProductVersion, reportDesignerMode: this.options.reportDesignerMode, imagesQuality: this.options.appearance.imagesQuality, parametersPanelSortDataItems: this.options.appearance.parametersPanelSortDataItems, combineReportPages: this.options.appearance.combineReportPages, isAngular: true, CSPNonce: this.options.cSPNonce, allowAutoUpdateCookies: this.options.server.allowAutoUpdateCookies }; if (this.options.server.useLocalizedCache && this.options.localization) { params['useLocalizedCache'] = true; params['localization'] = this.options.localization; } if (this.options.userValues) { params['userValues'] = this.options.userValues; } } else { params = {}; } if (data) { Object.keys(data).forEach(key => params[key] = data[key]); } // Object params if (params.action) { postParams['stiweb_action'] = params.action; delete params.action; } if (data?.viewerRequestUrl) { postParams['stiweb_viewerRequestUrl'] = data.viewerRequestUrl; } if (params.base64Data) { postParams['stiweb_data'] = params.base64Data; delete params.base64Data; } if (this.options && useOptions) { // Params const jsonParams = JSON.stringify(params); if (this.options.server.useCompression) { // postParams['stiweb_packed_parameters'] = StiGZipHelper.pack(jsonParams); postParams['stiweb_parameters'] = this.encode(jsonParams); } else { postParams['stiweb_parameters'] = this.encode(jsonParams); } } if (this.postParametersFunction) { let postParamsF = this.postParametersFunction(data); if (postParamsF) { Object.keys(postParamsF).forEach(key => postParams[key] = postParamsF[key]); } } if (asObject) { return postParams; } } newToken() { const a = '1234567890abcdefghijklmnopqrstuvwxyz'.split(''); const b = []; const length = 32; b[0] = "s"; for (let i = 1; i < length; i++) { const j = (Math.random() * (a.length - 1)).toFixed(0); b[i] = a[j]; } return b.join(''); } setupOptions() { if (!this.options.exports.showExportToPowerPoint && !this.options.exports.showExportToPdf && !this.options.exports.showExportToXps && !this.options.exports.showExportToOpenDocumentWriter && !this.options.exports.showExportToOpenDocumentCalc && !this.options.exports.showExportToText && !this.options.exports.showExportToRtf && !this.options.exports.showExportToWord && !this.options.exports.showExportToCsv && !this.options.exports.showExportToJson && !this.options.exports.showExportToDbf && !this.options.exports.showExportToXml && !this.options.exports.showExportToDif && !this.options.exports.showExportToSylk && !this.options.exports.showExportToExcelBiff && !this.options.exports.showExportToExcel && !this.options.exports.showExportToExcelXml && !this.options.exports.showExportToHtml && !this.options.exports.showExportToHtml5 && !this.options.exports.showExportToMht && !this.options.exports.showExportToImageBmp && !this.options.exports.showExportToImageGif && !this.options.exports.showExportToImageJpeg && !this.options.exports.showExportToImageMetafile && !this.options.exports.showExportToImagePcx && !this.options.exports.showExportToImagePng && !this.options.exports.showExportToImageTiff && !this.options.exports.showExportToImageSvg && !this.options.exports.showExportToImageSvgz) { if (!this.options.exports.showExportToDocument) { this.options.toolbar.showSaveButton = false; } this.options.toolbar.showSendEmailButton = false; } // Options this.options.isTouchDevice = this.options.appearance.interfaceType === 'Auto' ? this.isTouchDevice() && this.isMobileDevice() : this.options.appearance.interfaceType === 'Touch'; this.options.isMobileDevice = this.options.appearance.interfaceType === 'Auto' && !this.options.reportDesignerMode ? this.isTouchDevice() && this.isMobileDevice() : this.options.appearance.interfaceType === 'Mobile'; if (this.options.isMobileDevice) { this.initializeMobile(); } else { this.options.toolbar.showPinToolbarButton = false; } this.options.menuAnimDuration = 150; this.options.formAnimDuration = 200; this.options.scrollDuration = 350; this.options.menuHideDelay = 250; this.options.server.timeoutAutoUpdateCache = 180000; this.options.toolbar.backgroundColor = this.getHTMLColor(this.options.toolbar.backgroundColor); this.options.toolbar.borderColor = this.getHTMLColor(this.options.toolbar.borderColor); this.options.toolbar.fontColor = this.getHTMLColor(this.options.toolbar.fontColor); this.options.appearance.pageBorderColor = this.getHTMLColor(this.options.appearance.pageBorderColor); this.options.parametersValues = {}; this.options.parameterRowHeight = this.options.isTouchDevice ? 35 : 30; // First Day Of Week if (this.options.appearance.datePickerFirstDayOfWeek === 'Sunday') { this.dayOfWeek.splice(6, 1); this.dayOfWeek.splice(0, 0, 'Sunday'); } if (this.options?.toolbar?.zoom === -1 || this.options?.toolbar?.zoom === -2) { this.reportParams.autoZoom = this.options?.toolbar?.zoom; } // Actions if (!this.options.actions.getReport) { this.options.actions.getReport = this.options.actions.viewerEvent; } if (!this.options.actions.printReport) { this.options.actions.printReport = this.options.actions.viewerEvent; } if (!this.options.actions.openReport) { this.options.actions.openReport = this.options.actions.viewerEvent; } if (!this.options.actions.exportReport) { this.options.actions.exportReport = this.options.actions.viewerEvent; } if (!this.options.actions.interaction) { this.options.actions.interaction = this.options.actions.viewerEvent; } if (!(window.File && window.FileReader && window.FileList && window.Blob)) { this.options.toolbar.showOpenButton = false; } // Render JsViewer styles into HEAD if (this.options.requestResourcesUrl || this.options.appearance.customStylesUrl) { const viewerStyles = document.createElement('link'); viewerStyles.setAttribute('type', 'text/css'); viewerStyles.setAttribute('rel', 'stylesheet'); viewerStyles.setAttribute('href', this.options.appearance.customStylesUrl || this.getResourceUrl('styles')); this.controls.head.appendChild(viewerStyles); } this.options.viewerId = this.options.viewerId || this.newToken(); } pagesNavigationIsActive() { return (this.options.appearance.fullScreenMode || this.options.appearance.scrollbarsMode) && this.reportParams.viewMode === 'Continuous'; } get imagesForBookmark() { if (!this._imagesForBookmark) { const names = ['root', 'folder', 'folderOpen', 'node', 'empty', 'line', 'join', 'joinBottom', 'plus', 'plusBottom', 'minus', 'minusBottom']; const imagesForBookmarks = {}; names.forEach(name => imagesForBookmarks[name] = this.images['Bookmarks' + name + '.png']); this._imagesForBookmark = imagesForBookmarks; } return this._imagesForBookmark; } isTouchDevice() { return ('ontouchstart' in document.documentElement); } isMobileDevice() { return /iPhone|iPad|iPod|Macintosh|Android|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); } initializeMobile() { let isViewPortExist = false; const metas = this.controls.head.getElementsByTagName('meta'); for (const meta of metas) { if (meta.name && meta.name.toLowerCase() === 'viewport') { isViewPortExist = true; break; } } if (!isViewPortExist) { const viewPortTag = document.createElement('meta'); viewPortTag.id = 'viewport'; viewPortTag.name = 'viewport'; viewPortTag.content = 'initial-scale=1.0,width=device-width,user-scalable=0'; this.controls.head.appendChild(viewPortTag); } this.options.appearance.fullScreenMode = true; this.options.appearance.scrollbarsMode = true; this.options.appearance.currentParametersPanelPosition = 'Left'; this.options.appearance.parametersPanelPosition = 'Left'; this.options.appearance.parametersPanelColumnsCount = 1; this.options.toolbar.displayMode = 'Separated'; this.options.toolbar.viewMode = 'SinglePage'; this.options.toolbar.showZoomButton = false; const defaultZoom = this.options.toolbar.zoom === -2 ? -2 : -1; // PageWidth or PageHeight this.options.toolbar.zoom = this.reportParams.zoom = defaultZoom; this.options.toolbar.showButtonCaptions = false; this.options.toolbar.showOpenButton = false; this.options.toolbar.showFindButton = false; this.options.toolbar.showEditorButton = false; this.options.toolbar.showFullScreenButton = false; this.options.toolbar.showAboutButton = false; this.options.toolbar.showViewModeButton = false; } getImagesScalingFactor() { const wnd = window; const devicePixelRatio = window.devicePixelRatio || (wnd.deviceXDPI && wnd.logicalXDPI ? wnd.deviceXDPI / wnd.logicalXDPI : 1); if (!devicePixelRatio || devicePixelRatio <= 1) { return '1'; } else { return devicePixelRatio.toString(); } } getHTMLColor(color) { if (color.indexOf(',') > 0 && color.indexOf('rgb') < 0) { return `rgb(${color})`; } return color; } getResourceUrl(resourceParameter) { let url = this.getActionRequestUrl(this.options.requestResourcesUrl, this.options.actions.viewerEvent); url += url.indexOf('?') > 0 ? '&' : '?'; url += 'stiweb_component=Viewer&stiweb_action=Resource&stiweb_data=' + resourceParameter + '&stiweb_theme=' + this.options.theme; url += '&stiweb_cachemode=' + (this.options.server.useCacheForResources ? this.options.server.cacheMode === 'ObjectSession' || this.options.server.cacheMode === 'StringSession' ? 'session' : 'cache' : 'none'); url += '&stiweb_version=' + this.options.shortProductVersion; return url; } getActionRequestUrl(requestUrl, action) { if (!action) { return requestUrl; } if (action.indexOf('?') < 0) { return requestUrl.replace('{action}', action); } const query = action.substring(action.indexOf('?') + 1); action = action.substring(0, action.indexOf('?')); return requestUrl.replace('{action}', action) + (requestUrl.indexOf('?') > 0 ? '&' : '?') + query; } encode(input) { // Decode from UTF-8 text if (typeof unescape != 'undefined') { input = unescape(encodeURIComponent(input)); } else { input = input.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < input.length; n++) { var c = input.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } input = utftext; } // Encode to Base64 string if (typeof window.btoa != 'undefined') return window.btoa(input); var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) enc3 = enc4 = 64; else if (isNaN(chr3)) enc4 = 64; output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; } decode(input) { var output = ""; // Decode from Base64 string if (typeof window.atob != 'undefined') { output = window.atob(input); } else { var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } } // Encode to UTF-8 string if (typeof escape != 'undefined') return decodeURIComponent(escape(output)); var string = ""; var i = 0; var c = 0; var c1 = 0; var c2 = 0; var c3 = 0; while (i < output.length) { c = output.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if ((c > 191) && (c < 224)) { c2 = output.charCodeAt(i + 1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = output.charCodeAt(i + 1); c3 = output.charCodeAt(i + 2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ModelService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ModelService }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ModelService, decorators: [{ type: Injectable }], ctorParameters: () => [] }); class AnimationService { constructor(model) { this.model = model; } showAnimationForScroll(reportPanel, finishScrollTop, endTime, completeFunction) { if (!reportPanel) { return; } let currentScrollTop = 0; if (this.model.options.appearance.scrollbarsMode) { currentScrollTop = reportPanel.scrollTop; } else { currentScrollTop = document.documentElement.scrollTop; if (currentScrollTop === 0) { currentScrollTop = document.getElementsByTagName('BODY')[0].scrollTop; } } clearTimeout(reportPanel.animationTimer); const d = new Date(); const t = d.getTime(); let step = Math.round((finishScrollTop - currentScrollTop) / ((Math.abs(endTime - t) + 1) / 30)); // Last step if (Math.abs(step) > Math.abs(finishScrollTop - currentScrollTop)) { step = finishScrollTop - currentScrollTop; } currentScrollTop += step; let resultScrollTop; if (t < endTime) { resultScrollTop = currentScrollTop; reportPanel.animationTimer = setTimeout(() => { this.showAnimationForScroll(reportPanel, finishScrollTop, endTime, completeFunction); }, 30); } else { resultScrollTop = finishScrollTop; if (completeFunction) { completeFunction(); } } if (this.model.options.appearance.scrollbarsMode) { reportPanel.scrollTop = resultScrollTop; } else { window.scrollTo(0, resultScrollTop); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AnimationService, deps: [{ token: ModelService }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AnimationService }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AnimationService, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: ModelService }] }); class HelperService { constructor(model, animationService) { this.model = model; this.animationService = animationService; } val(value, def) { return value != null && value.trim() !== '' ? value : (def || ''); } findPosY(obj, mainClassName, noScroll) { let curtop = noScroll ? 0 : this.getScrollYOffset(obj, mainClassName); if (obj.offsetParent) { while (obj.className !== mainClassName) { curtop += obj.offsetTop; if (!obj.offsetParent) { break; } obj = obj.offsetParent; } } else if (obj.y) { curtop += obj.y; } return curtop; } getScrollYOffset(obj, mainClassName) { let scrolltop = 0; if (obj.parentElement) { while (obj.className !== mainClassName) { if ('scrollTop' in obj) { scrolltop -= obj.scrollTop; } if (!obj.parentElement) { break; } obj = obj.parentElement; } } return scrolltop; } findPosX(obj, mainClassName, noScroll) { let curleft = noScroll ? 0 : this.getScrollXOffset(obj, mainClassName); if (obj.offsetParent) { while (obj.className !== mainClassName) { curleft += obj.offsetLeft; if (!obj.offsetParent) { break; } obj = obj.offsetParent; } } else if (obj.x) { curleft += obj.x; } return curleft; } getScrollXOffset(obj, mainClassName) { let scrollleft = 0; if (obj.parentElement) { while (obj.className !== mainClassName) { if ('scrollLeft' in obj) { scrollleft -= obj.scrollLeft; } if (!obj.parentElement) { break; } obj = obj.parentElement; } } return scrollleft; } showHelpWindow(url) { let helpLanguage = 'en'; switch (this.model.options.cultureName) { case 'ru': helpLanguage = 'ru'; // case 'de': helpLanguage = 'de'; } this.openNewWindow('https://www.stimulsoft.com/' + helpLanguage + '/documentation/online/' + url); } openNewWindow(url, name, specs) { return window.open(url, name, specs); } scrollToAnchor(anchorName, componentGuid) { let aHyperlinks = this.model.controls.reportPanel.el.nativeElement.getElementsByTagName("a"); const identicalAnchors = []; if (anchorName) { anchorName = anchorName.replace(/!!#92/g, '\\'); } if (componentGuid) { for (let i = 0; i < aHyperlinks.length; i++) { if (aHyperlinks[i].getAttribute('guid') === componentGuid) { identicalAnchors.push(aHyperlinks[i]); } } } if (identicalAnchors.length === 0) { let guidIndex = anchorName.indexOf("#GUID#"); if (identicalAnchors.length == 0) { let aHyperlinks = this.model.controls.reportPanel.el.nativeElement.getElementsByTagName("a"); for (var i = 0; i < aHyperlinks.length; i++) { if (aHyperlinks[i].name && ((guidIndex >= 0 && (aHyperlinks[i].name.indexOf(anchorName.substring(guidIndex + 6)) >= 0 || anchorName.substring(0, guidIndex) == aHyperlinks[i].name)) || aHyperlinks[i].name == anchorName)) identicalAnchors.push(aHyperlinks[i]); } } } if (identicalAnchors.length > 0) { const anchor = identicalAnchors[0]; const anchorParent = anchor.parentElement || anchor; let anchorHeight = anchorParent.offsetHeight; const anchorOffsetTop = anchorParent.offsetTop; identicalAnchors.forEach((identicalAnchor) => { const nextAnchorParent = identicalAnchor.parentElement || identicalAnchor; if (nextAnchorParent.offsetTop > anchorOffsetTop) { anchorHeight = Math.max(anchorHeight, nextAnchorParent.offsetTop - anchorOffsetTop + nextAnchorParent.offsetHeight); } }); const date = new Date(); const endTime = date.getTime() + this.model.options.scrollDuration; const targetTop = this.findPosY(anchor, this.model.options.appearance.scrollbarsMode ? 'stiJsViewerReportPanel' : null, true) - anchorParent.offsetHeight * 2; this.animationService.showAnimationForScroll(this.model.controls.reportPanel.el.nativeElement, targetTop, endTime, () => { const page = this.getPageFromAnchorElement(anchor); const anchorParentTopPos = this.findPosY(anchorParent, 'stiJsViewerReportPanel', true); const pageTopPos = page ? this.findPosY(page, 'stiJsViewerReportPanel', true) : anchorParentTopPos; this.removeBookmarksLabel(); const label = document.createElement('div'); this.model.controls.bookmarksLabel = label; label.className = 'stiJsViewerBookmarksLabel'; const labelMargin = 20 * (this.model.reportParams.zoom / 100); const labelWidth = page ? page.offsetWidth - labelMargin - 6 : anchorParent.offsetWidth; const labelHeight = anchorHeight - 2; label.style.width = labelWidth + 'px'; label.style.height = labelHeight + 'px'; const margins = page.pageAttributes.margins?.replace('px', '').split(' '); const pageLeftMargin = page.pageAttributes.margins ? this.strToInt(margins[3]) : 0; const pageTopMargin = page.pageAttributes.margins ? this.strToInt(margins[0]) : 0; label.style.marginLeft = (labelMargin / 2 - pageLeftMargin) + 'px'; label.style.marginTop = (anchorParentTopPos - pageTopPos - pageTopMargin - (this.model.reportParams.zoom / 100) - 1) + 'px'; page.insertBefore(label, page.childNodes[0]); }); } } removeBookmarksLabel() { if (this.model.controls.bookmarksLabel) { this.model.controls.bookmarksLabel.parentElement.removeChild(this.model.controls.bookmarksLabel); this.model.controls.bookmarksLabel = null; } } getPageFromAnchorElement(anchorElement) { let obj = anchorElement; while (obj.parentElement) { if (obj.className && obj.className.indexOf('stiJsViewerPage') === 0) { return obj; } obj = obj.parentElement; } return obj; } strToInt(value) { const result = parseInt(value, 10); return result || 0; } strToDouble(value) { if (value === null) { return null; } const result = parseFloat(value.toString().replace(',', '.').trim()); return result || 0; } copyObject(o) { if (!o || 'object' !== typeof o) { return o; } const c = 'function' === typeof o.pop ? [] : {}; let p; let v; for (p in o) { if (o.hasOwnProperty(p)) { v = o[p]; if (v && 'object' === typeof v) { c[p] = this.copyObject(v); } else { c[p] = v; } } } return c; } getCountObjects(objectArray) { let count = 0; if (objectArray) { for (const singleObject in objectArray) { count++; } } return count; } replaceMonths(value) { for (let i = 1; i <= 12; i++) { let enName = ''; let locName = ''; switch (i) { case 1: enName = 'January'; locName = this.model.loc('MonthJanuary'); break; case 2: enName = 'February'; locName = this.model.loc('MonthFebruary'); break; case 3: enName = 'March'; locName = this.model.loc('MonthMarch'); break; case 4: enName = 'April'; locName = this.model.loc('MonthApril'); break; case 5: enName = 'May'; locName = this.model.loc('MonthMay'); break; case 6: enName = 'June'; locName = this.model.loc('MonthJune'); break; case 7: enName = 'July'; locName = this.model.loc('MonthJuly'); break; case 8: enName = 'August'; locName = this.model.loc('MonthAugust'); break; case 9: enName = 'September'; locName = this.model.loc('MonthSeptember'); break; case 10: enName = 'October'; locName = this.model.loc('MonthOctober'); break; case 11: enName = 'November'; locName = this.model.loc('MonthNovember'); break; case 12: enName = 'December'; locName = this.model.loc('MonthDecember'); break; } const enShortName = enName.substring(0, 3); const locShortName = locName.substring(0, 3); value = value.replace(enName, i).replace(enName.toLowerCase(), i).replace(enShortName, i).replace(enShortName.toLowerCase(), i); value = value.replace(locName, i).replace(locName.toLowerCase(), i).replace(locShortName, i).replace(locShortName.toLowerCase(), i); } return value; } getDate(dateTimeObj) { return new Date(dateTimeObj.year, dateTimeObj.month - 1, dateTimeObj.day, dateTimeObj.hours, dateTimeObj.minutes, dateTimeObj.seconds); } getDateTimeObject(date) { if (!date) { date = new Date(); } const dateTimeObject = new DateTimeObject(); dateTimeObject.year = date.getFullYear(); dateTimeObject.month = date.getMonth() + 1; dateTimeObject.day = date.getDate(); dateTimeObject.hours = date.getHours(); dateTimeObject.minutes = date.getMinutes(); dateTimeObject.seconds = date.getSeconds(); return dateTimeObject; } getDateTimeFromString(value, format) { const charIsDigit = (ch) => { return ('0123456789'.indexOf(ch) >= 0); }; if (!value) { return new Date(); } value = this.replaceMonths(value); let dateTime = new Date(); // If the date format is not specified, then deserializator for getting date and time is applied if (format === null) { format = 'dd.MM.yyyy hh:mm:ss'; } // Otherwise the format is parsed. Now only numeric date and time formats are supported let year = 1970; let month = 1; let day = 1; let hour = 0; let minute = 0; let second = 0; let millisecond = 0; let char = ''; let pos = 0; const values = []; // Parse date and time into separate numeric values while (pos < value.length) { char = value.charAt(pos); if (charIsDigit(char)) { values.push(char); pos++; while (pos < value.length && charIsDigit(value.charAt(pos))) { values[values.length - 1] += value.charAt(pos); pos++; } values[values.length - 1] = this.strToInt(values[values.length - 1]); } pos++; } pos = 0; let charCount = 0; let index = -1; let is12hour = false; // Parsing format and replacement of appropriate values of date and time while (pos < format.length) { char = format.charAt(pos); charCount = 0; if (char === 'Y' || char === 'y' || char === 'M' || char === 'd' || char === 'h' || char === 'H' || char === 'm' || char === 's' || char === 'f' || char === 'F' || char === 't' || char === 'z') { index++; while (pos < format.length && format.charAt(pos) === char) { pos++; charCount++; } } switch (char) { case 'Y': // full year year = values[index]; break; case 'y': // year if (values[index] < 1000) { year = 2000 + values[index]; } else { year = values[index]; } break; case 'M': // month month