Moved "DynamicHeight" method to static methods

This commit is contained in:
Jesús Ángel 2019-08-29 14:48:59 +02:00
parent 9c2809cccc
commit 160282c77f
5 changed files with 34 additions and 30 deletions

View File

@ -50,7 +50,6 @@ export class DevToolsController {
this.multipleKeyPressed = [];
this.IS_DARK_THEME = chrome.getUiSettingsClient().get('theme:darkMode');
this.$scope = $scope;
this.dh = new DynamicHeight();
}
/**
@ -470,7 +469,7 @@ export class DevToolsController {
dynamicHeight();
};
const dynamicHeight = () => this.dh.dynamicHeightDevTools(this, this.$window);
const dynamicHeight = () => DynamicHeight.dynamicHeightDevTools(this, this.$window);
dynamicHeight();
}

View File

@ -37,7 +37,6 @@ export class ConfigurationController {
this.$scope.integrations = {};
this.$scope.selectedItem = 0;
this.showHelp = false;
this.dh = new DynamicHeight();
}
/**
@ -100,7 +99,7 @@ export class ConfigurationController {
};
$(window).on('resize', () => {
this.dh.dynamicHeight('d-height', 50);
DynamicHeight.dynamicHeight('d-height', 50);
});
}
@ -117,7 +116,7 @@ export class ConfigurationController {
'sca'
);
}
this.dh.dynamicHeight('d-height', 50);
DynamicHeight.dynamicHeight('d-height', 50);
}
/**
@ -139,7 +138,7 @@ export class ConfigurationController {
false,
(this.$scope.mctrl || {}).selectedNode
);
this.dh.dynamicHeight('d-height', 50);
DynamicHeight.dynamicHeight('d-height', 50);
}
/**
@ -215,7 +214,7 @@ export class ConfigurationController {
});
this.$location.search('configSubTab', true);
}
this.dh.dynamicHeight('d-height', 50);
DynamicHeight.dynamicHeight('d-height', 50);
} catch (error) {
this.errorHandler.handle(error, 'Set configuration path');
}

View File

@ -33,7 +33,6 @@ class WzConfigViewer {
}
controller($scope, $document, $window) {
const dh = new DynamicHeight();
const window = $window;
const IS_DARK_THEME = chrome.getUiSettingsClient().get('theme:darkMode');
const setJsonBox = () => {
@ -75,7 +74,7 @@ class WzConfigViewer {
};
$(window).on('resize', () => {
dh.dynamicHeight('configViewer', 30);
DynamicHeight.dynamicHeight('configViewer', 30);
});
const refreshJsonBox = json => {
@ -104,7 +103,7 @@ class WzConfigViewer {
$scope.xmlCodeBox.refresh();
$scope.$applyAsync();
isLogs
? dh.dynamicHeight('configViewer', 30, isLogs)
? DynamicHeight.dynamicHeight('configViewer', 30, isLogs)
: window.dispatchEvent(new Event('resize')); // eslint-disable-line
}, 200);
}

View File

@ -44,7 +44,6 @@ app.directive('wzXmlFileEditor', function() {
) {
const window = $window;
const IS_DARK_THEME = chrome.getUiSettingsClient().get('theme:darkMode');
const dh = new DynamicHeight();
$scope.targetNameShown = $scope.targetName;
$scope.configError = false;
/**
@ -110,7 +109,7 @@ app.directive('wzXmlFileEditor', function() {
}
checkingXmlError = false;
$scope.$applyAsync();
dh.dynamicHeightXmlEditor();
DynamicHeight.dynamicHeightXmlEditor();
return;
};
@ -215,7 +214,7 @@ app.directive('wzXmlFileEditor', function() {
if (!isOk && Array.isArray(data.details)) {
$scope.configError = data.details;
$scope.$applyAsync();
dh.dynamicHeightXmlEditor();
DynamicHeight.dynamicHeightXmlEditor();
throw new Error('Validation error');
}
return true;
@ -339,14 +338,14 @@ app.directive('wzXmlFileEditor', function() {
);
$(window).on('resize', function() {
dh.dynamicHeightXmlEditor();
DynamicHeight.dynamicHeightXmlEditor();
});
const init = (data = false) => {
try {
$('.wzXmlEditor').height(0);
$scope.xmlError = false;
dh.dynamicHeightXmlEditor();
DynamicHeight.dynamicHeightXmlEditor();
$scope.xmlCodeBox.setValue(autoFormat(data || $scope.data));
firstTime = false;
setTimeout(() => {
@ -380,7 +379,7 @@ app.directive('wzXmlFileEditor', function() {
$scope.restartBtn = true;
$scope.$applyAsync();
$scope.$emit('showRestartBtn', { msg, target });
dh.dynamicHeightXmlEditor();
DynamicHeight.dynamicHeightXmlEditor();
};
$scope.$on('saveXmlFile', (ev, params) => saveFile(params));
@ -388,7 +387,7 @@ app.directive('wzXmlFileEditor', function() {
$scope.$on('removeRestartMsg', () => {
$scope.restartBtn = false;
$scope.$applyAsync();
dh.dynamicHeightXmlEditor();
DynamicHeight.dynamicHeightXmlEditor();
});
$rootScope.$on('changedInputFileName', (ev, params) => {

View File

@ -1,14 +1,22 @@
/*
* Wazuh app - Helper class for div heights
* 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.
*/
export class DynamicHeight {
constructor() {
}
/**
* Calculates dynamically the height
* @param {String} classElement
* @param {Number} extraHeight
*/
dynamicHeight(classElement, extraHeight, isLogs = false) {
static dynamicHeight(classElement, extraHeight, isLogs = false) {
let editorContainer;
const codeMirror = $('.CodeMirror');
const interval = setInterval(() => {
@ -17,7 +25,7 @@ export class DynamicHeight {
clearInterval(interval);
setTimeout(() => {
const windows = $(window).height();
const offsetTop = this.getPosition(editorContainer[0]).y;
const offsetTop = DynamicHeight.getPosition(editorContainer[0]).y;
const bottom = isLogs ? 75 : 20;
const headerContainer = $('.wzXmlEditorHeader');
const headerContainerHeight =
@ -44,7 +52,7 @@ export class DynamicHeight {
/**
* Calculate the dynamic height for the XML editor
*/
dynamicHeightXmlEditor() {
static dynamicHeightXmlEditor() {
let editorContainer;
const interval = setInterval(() => {
editorContainer = $('.wzXmlEditor');
@ -54,7 +62,7 @@ export class DynamicHeight {
const editorContainer = $('.wzXmlEditor');
const headerContainer = $('#wzXmlEditorHeader');
const windows = $(window).height();
const offsetTop = this.getPosition(editorContainer[0]).y;
const offsetTop = DynamicHeight.getPosition(editorContainer[0]).y;
editorContainer.height(windows - (offsetTop + 20));
$('.wzXmlEditorBody .CodeMirror').css({
height: 'calc(100% - ' + (headerContainer.height() - 22) + 'px)'
@ -69,7 +77,7 @@ export class DynamicHeight {
* @param {Object} self
* @param {Object} window
*/
dynamicHeightDevTools(self, window) {
static dynamicHeightDevTools(self, window) {
let devToolsElement;
const interval = setInterval(() => {
devToolsElement = $('#wz-dev-left-column');
@ -78,24 +86,24 @@ export class DynamicHeight {
setTimeout(() => {
const windows = $(window).height();
$('#wz-dev-left-column').height(
windows - (this.getPosition($('#wz-dev-left-column')[0]).y + 20)
windows - (DynamicHeight.getPosition($('#wz-dev-left-column')[0]).y + 20)
);
$('.wz-dev-column-separator').height(
windows - (this.getPosition($('.wz-dev-column-separator')[0]).y + 20)
windows - (DynamicHeight.getPosition($('.wz-dev-column-separator')[0]).y + 20)
);
$('#wz-dev-right-column').height(
windows - (this.getPosition($('#wz-dev-right-column')[0]).y + 20)
windows - (DynamicHeight.getPosition($('#wz-dev-right-column')[0]).y + 20)
);
$('.wz-dev-column-separator span').height(
windows -
(this.getPosition($('.wz-dev-column-separator span')[0]).y + 20)
(DynamicHeight.getPosition($('.wz-dev-column-separator span')[0]).y + 20)
);
}, 1);
}
});
}
getPosition(element) {
static getPosition(element) {
let xPosition = 0;
let yPosition = 0;