mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 18:05:20 +00:00
a78c564a80
* Changed event logic along controllers and services * Removed autocomplete. Fix Discover button * Adapt Wazuh app for Kibana v6.7.0 (#1334) * Adapt kibana app for elastic 6.7.0 * Adapt kibana app for elastic 6.7.0 * Fixed discover * Prettier * Update 6.7 files * Update 6.7 loader * Prettier * Minor style fixes * Bump Kibana version, updated README * Corrected interval from "h" to "auto" * Overwrite top nav style for 6.7.0 * Backport app icon * Fix $injector
89 lines
2.1 KiB
JavaScript
89 lines
2.1 KiB
JavaScript
/*
|
|
* Wazuh app - Fetch png from visualization div
|
|
* Copyright (C) 2015-2019 Wazuh, Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Find more information about this on the LICENSE file.
|
|
*/
|
|
|
|
import domtoimage from 'dom-to-image';
|
|
|
|
export class Vis2PNG {
|
|
/**
|
|
* Class constructor
|
|
* @param {*} $rootScope
|
|
*/
|
|
constructor($rootScope) {
|
|
this.$rootScope = $rootScope;
|
|
this.rawArray = [];
|
|
this.htmlObject = {};
|
|
this.working = false;
|
|
}
|
|
|
|
/**
|
|
* Validate a visualizations array
|
|
* @param {Array<Object>} visArray
|
|
*/
|
|
async checkArray(visArray) {
|
|
try {
|
|
this.working = true;
|
|
const len = visArray.length;
|
|
let currentCompleted = 0;
|
|
await Promise.all(
|
|
visArray.map(async currentValue => {
|
|
const tmpNode = this.htmlObject[currentValue];
|
|
try {
|
|
const tmpResult = await domtoimage.toPng(tmpNode[0]);
|
|
this.rawArray.push({
|
|
element: tmpResult,
|
|
width: tmpNode.width(),
|
|
height: tmpNode.height(),
|
|
id: currentValue
|
|
});
|
|
} catch (error) {} // eslint-disable-line
|
|
currentCompleted++;
|
|
this.$rootScope.reportStatus = `Generating report...${Math.round(
|
|
(currentCompleted / len) * 100
|
|
)}%`;
|
|
this.$rootScope.$applyAsync();
|
|
})
|
|
);
|
|
|
|
this.working = false;
|
|
this.$rootScope.reportStatus = `Generating PDF document...`;
|
|
return this.rawArray;
|
|
} catch (error) {
|
|
this.working = false;
|
|
return Promise.reject(error);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if is working
|
|
*/
|
|
isWorking() {
|
|
return this.working;
|
|
}
|
|
|
|
/**
|
|
* Clear raw array
|
|
*/
|
|
clear() {
|
|
this.rawArray = [];
|
|
this.htmlObject = {};
|
|
}
|
|
|
|
/**
|
|
* Set content to a given html item
|
|
* @param {String} id
|
|
* @param {Object} content
|
|
*/
|
|
assignHTMLItem(id, content) {
|
|
this.htmlObject[id] = content;
|
|
}
|
|
}
|