Yarn prettier

This commit is contained in:
Jesús Ángel 2019-03-12 12:55:07 +01:00
parent f355db5925
commit b7a0e1f63c
9 changed files with 128 additions and 86 deletions

View File

@ -168,7 +168,7 @@ import './utils/fontawesome/css/font-awesome.min.css';
// Dev tools
import './utils/codemirror';
import './utils/table-col-resizable'
import './utils/table-col-resizable';
// Material
import 'angular-material/angular-material.css';

View File

@ -83,7 +83,7 @@ export class DevToolsController {
}
);
// Register plugin for code mirror
CodeMirror.commands.autocomplete = function (cm) {
CodeMirror.commands.autocomplete = function(cm) {
CodeMirror.showHint(cm, CodeMirror.hint.dictionaryHint, {
completeSingle: false
});
@ -332,7 +332,7 @@ export class DevToolsController {
this.apiInputBox.setSize('auto', '100%');
this.apiInputBox.model = [];
this.getAvailableMethods();
this.apiInputBox.on('keyup', function (cm, e) {
this.apiInputBox.on('keyup', function(cm, e) {
if (!ExcludedIntelliSenseTriggerKeys[(e.keyCode || e.which).toString()]) {
cm.execCommand('autocomplete', null, {
completeSingle: false
@ -356,22 +356,22 @@ export class DevToolsController {
this.highlightGroup(currentGroup);
// Register our custom Codemirror hint plugin.
CodeMirror.registerHelper('hint', 'dictionaryHint', function (editor) {
CodeMirror.registerHelper('hint', 'dictionaryHint', function(editor) {
const model = editor.model;
function getDictionary(line, word) {
let hints = [];
const exp = line.split(/\s+/g);
if (exp[0] && exp[0].match(/^(?:GET|PUT|POST|DELETE).*$/)) {
let method = model.find(function (item) {
let method = model.find(function(item) {
return item.method === exp[0];
});
const forbidChars = /^[^?{]+$/;
if (method && !exp[2] && forbidChars.test(word)) {
method.endpoints.forEach(function (endpoint) {
method.endpoints.forEach(function(endpoint) {
endpoint.path = endpoint.name;
if (endpoint.args && endpoint.args.length > 0) {
let argSubs = [];
endpoint.args.forEach(function (arg) {
endpoint.args.forEach(function(arg) {
const pathSplitted = endpoint.name.split('/');
const arrayIdx = pathSplitted.indexOf(arg.name);
const wordSplitted = word.split('/');
@ -383,7 +383,7 @@ export class DevToolsController {
}
});
let auxPath = endpoint.name;
argSubs.forEach(function (arg) {
argSubs.forEach(function(arg) {
auxPath = auxPath.replace(arg.id, arg.value);
});
endpoint.path = auxPath;
@ -404,26 +404,26 @@ export class DevToolsController {
const whiteSpace = /\s/;
while (end < curLine.length && !whiteSpace.test(curLine.charAt(end)))
++end;
while (start && !whiteSpace.test(curLine.charAt(start - 1)))--start;
while (start && !whiteSpace.test(curLine.charAt(start - 1))) --start;
const curWord = start !== end && curLine.slice(start, end);
return {
list: (!curWord
? []
: getDictionary(curLine, curWord).filter(function (item) {
return item.toUpperCase().includes(curWord.toUpperCase());
})
: getDictionary(curLine, curWord).filter(function(item) {
return item.toUpperCase().includes(curWord.toUpperCase());
})
).sort(),
from: CodeMirror.Pos(cur.line, start),
to: CodeMirror.Pos(cur.line, end)
};
});
const evtDocument = this.$document[0];
$('.wz-dev-column-separator').mousedown(function (e) {
$('.wz-dev-column-separator').mousedown(function(e) {
e.preventDefault();
$('.wz-dev-column-separator').addClass('active');
const leftOrigWidth = $('#wz-dev-left-column').width();
const rightOrigWidth = $('#wz-dev-right-column').width();
$(evtDocument).mousemove(function (e) {
$(evtDocument).mousemove(function(e) {
const leftWidth = e.pageX - 215 + 14;
let rightWidth = leftOrigWidth - leftWidth;
$('#wz-dev-left-column').css('width', leftWidth);
@ -431,7 +431,7 @@ export class DevToolsController {
});
});
$(evtDocument).mouseup(function () {
$(evtDocument).mouseup(function() {
$('.wz-dev-column-separator').removeClass('active');
$(evtDocument).unbind('mousemove');
});
@ -458,10 +458,10 @@ export class DevToolsController {
const desiredGroup = firstTime
? this.groups.filter(item => item.requestText)
: this.groups.filter(
item =>
item.requestText &&
(item.end >= selection.line && item.start <= selection.line)
);
item =>
item.requestText &&
(item.end >= selection.line && item.start <= selection.line)
);
// Place play button at first line from the selected group
const cords = this.apiInputBox.cursorCoords({
@ -517,12 +517,12 @@ export class DevToolsController {
const method = desiredGroup.requestText.startsWith('GET')
? 'GET'
: desiredGroup.requestText.startsWith('POST')
? 'POST'
: desiredGroup.requestText.startsWith('PUT')
? 'PUT'
: desiredGroup.requestText.startsWith('DELETE')
? 'DELETE'
: 'GET';
? 'POST'
: desiredGroup.requestText.startsWith('PUT')
? 'PUT'
: desiredGroup.requestText.startsWith('DELETE')
? 'DELETE'
: 'GET';
const requestCopy = desiredGroup.requestText.includes(method)
? desiredGroup.requestText.split(method)[1].trim()

View File

@ -256,7 +256,8 @@ export class DecodersController {
`/decoders/${this.currentDecoder.name}`,
{}
);
const response = (((decoderReload || {}).data || {}).data || {}).items || [];
const response =
(((decoderReload || {}).data || {}).data || {}).items || [];
if (!response.length) {
this.currentDecoder = null;
this.closeDetailView(true);

View File

@ -43,9 +43,9 @@ export class FilesController {
clusterInfo.status === 'enabled' ? 'cluster' : 'manager';
this.$scope.doingSaving = true;
const objParam = { showRestartManager };
this.$scope.currentFile.type === 'rule' ?
objParam.rule = this.$scope.currentFile :
objParam.decoder = this.$scope.currentFile;
this.$scope.currentFile.type === 'rule'
? (objParam.rule = this.$scope.currentFile)
: (objParam.decoder = this.$scope.currentFile);
this.$scope.$broadcast('saveXmlFile', objParam);
this.$scope.$applyAsync();
};
@ -74,10 +74,17 @@ export class FilesController {
this.$scope.editingFile = true;
try {
this.$scope.currentFile = params.file;
this.$scope.currentFile.type = params.path.includes('rules') ? 'rule' : 'decoder';
this.$scope.fetchedXML = this.$scope.currentFile.type === 'rule' ?
await this.rulesetHandler.getRuleConfiguration(this.$scope.currentFile.file) :
await this.rulesetHandler.getDecoderConfiguration(this.$scope.currentFile.file);
this.$scope.currentFile.type = params.path.includes('rules')
? 'rule'
: 'decoder';
this.$scope.fetchedXML =
this.$scope.currentFile.type === 'rule'
? await this.rulesetHandler.getRuleConfiguration(
this.$scope.currentFile.file
)
: await this.rulesetHandler.getDecoderConfiguration(
this.$scope.currentFile.file
);
this.$scope.$applyAsync();
this.$scope.$broadcast('fetchedFile', { data: this.$scope.fetchedXML });
} catch (error) {

View File

@ -60,10 +60,12 @@ export class LogsController {
parseLogsToText(logs) {
let result = '';
logs.forEach(function (log, idx) {
logs.forEach(function(log, idx) {
if (log) {
result = result.concat(
`${log.timestamp} ${log.tag} ${(log.level || "").toUpperCase()}: ${log.description}`
`${log.timestamp} ${log.tag} ${(log.level || '').toUpperCase()}: ${
log.description
}`
);
if (idx !== logs.length - 1) {
result = result.concat('\n');
@ -192,10 +194,10 @@ export class LogsController {
const data = clusterEnabled
? await this.apiReq.request(
'GET',
`/cluster/${this.selectedNode}/logs/summary`,
{}
)
'GET',
`/cluster/${this.selectedNode}/logs/summary`,
{}
)
: await this.apiReq.request('GET', '/manager/logs/summary', {});
const daemons = data.data.data;
this.daemons = Object.keys(daemons).map(item => ({ title: item }));
@ -206,6 +208,4 @@ export class LogsController {
}
return;
}
}
}

View File

@ -163,10 +163,10 @@ export function RulesController(
coloredString = coloredString.replace(
/\$\(((?!<\/span>).)*?\)(?!<\/span>)/im,
'<span style="color: ' +
colors[i] +
' ">' +
valuesArray[i] +
'</span>'
colors[i] +
' ">' +
valuesArray[i] +
'</span>'
);
}
}
@ -253,7 +253,8 @@ export function RulesController(
`/rules/${$scope.currentRule.id}`,
{}
);
const response = (((ruleReloaded || {}).data || {}).data || {}).items || [];
const response =
(((ruleReloaded || {}).data || {}).data || {}).items || [];
if (!response.length) {
$scope.currentRule = null;
$scope.showingLocalRules = true;

View File

@ -74,7 +74,7 @@ class WzConfigViewer {
}
if ($scope.jsoncontent != false) {
$scope.jsonCodeBox.setValue($scope.jsoncontent.replace(/\\\\/g, '\\'));
setTimeout(function () {
setTimeout(function() {
$scope.jsonCodeBox.refresh();
$scope.$applyAsync();
}, 100);
@ -88,7 +88,7 @@ class WzConfigViewer {
}
if ($scope.xmlcontent != false) {
$scope.xmlCodeBox.setValue($scope.xmlcontent);
setTimeout(function () {
setTimeout(function() {
$scope.xmlCodeBox.refresh();
$scope.$applyAsync();
}, 100);
@ -109,17 +109,23 @@ class WzConfigViewer {
const bindXmlListener = () => {
var scrollElement = $scope.xmlCodeBox.getScrollerElement();
$(scrollElement).bind('scroll', function (e) {
$(scrollElement).bind('scroll', function(e) {
var element = $(e.currentTarget)[0];
if (element.scrollHeight - element.scrollTop === element.clientHeight) {
$scope.$emit('scrolledToBottom', { lines: $scope.xmlCodeBox.lineCount() });
$scope.$emit('scrolledToBottom', {
lines: $scope.xmlCodeBox.lineCount()
});
}
});
}
};
$scope.$on('viewerScrollBottom', (ev, params) => {
var t = $scope.xmlCodeBox.charCoords({ line: params.line, ch: 0 }, "local").top;
var middleHeight = $scope.xmlCodeBox.getScrollerElement().offsetHeight / 2;
var t = $scope.xmlCodeBox.charCoords(
{ line: params.line, ch: 0 },
'local'
).top;
var middleHeight =
$scope.xmlCodeBox.getScrollerElement().offsetHeight / 2;
$scope.xmlCodeBox.scrollTo(null, t - middleHeight - 10);
});
}

View File

@ -16,7 +16,7 @@ import { uiModules } from 'ui/modules';
const app = uiModules.get('app/wazuh', []);
app.directive('wzTagFilter', function () {
app.directive('wzTagFilter', function() {
return {
restrict: 'E',
scope: {
@ -71,7 +71,13 @@ app.directive('wzTagFilter', function () {
};
const idxSearch = $scope.tagList.find(x => x.type === 'search');
if (!isFilter && idxSearch) {
$scope.removeTag(idxSearch.id, false, $scope.searchIdx, undefined, true);
$scope.removeTag(
idxSearch.id,
false,
$scope.searchIdx,
undefined,
true
);
}
if (
!$scope.tagList.find(x => {
@ -111,7 +117,10 @@ app.directive('wzTagFilter', function () {
$scope.searchIdx = idx;
queryObj.search = search.value.name;
if (idx === groups.length - 1)
queryObj.query = queryObj.query.substring(0, queryObj.query.length - 1);
queryObj.query = queryObj.query.substring(
0,
queryObj.query.length - 1
);
} else {
const twoOrMoreElements = group.length > 1;
if (twoOrMoreElements) {
@ -122,7 +131,8 @@ app.directive('wzTagFilter', function () {
.forEach((tag, idx2) => {
queryObj.query += tag.key + '=' + tag.value.value;
if (idx2 != group.length - 1) {
queryObj.query += $scope.connectors[idx].subgroup[idx2].value;
queryObj.query +=
$scope.connectors[idx].subgroup[idx2].value;
}
});
if (twoOrMoreElements) {
@ -159,37 +169,47 @@ app.directive('wzTagFilter', function () {
return result;
};
const addConnectors = (groups) => {
const addConnectors = groups => {
const result = [];
groups
.forEach((group, index) => {
result.push({});
const subGroup = [];
group
.forEach((tag, idx) => {
if (idx != group.length - 1) {
subGroup.push({ value: (((($scope.connectors || [])[index] || {}).subgroup || [])[idx] || {}).value || ',' });
}
groups.forEach((group, index) => {
result.push({});
const subGroup = [];
group.forEach((tag, idx) => {
if (idx != group.length - 1) {
subGroup.push({
value:
(
((($scope.connectors || [])[index] || {}).subgroup || [])[
idx
] || {}
).value || ','
});
if (subGroup.length > 0)
result[index].subgroup = subGroup;
if (index != groups.length - 1) {
result[index].value = (($scope.connectors || [])[index] || {}).value || ';';
}
});
if (subGroup.length > 0) result[index].subgroup = subGroup;
if (index != groups.length - 1) {
result[index].value =
(($scope.connectors || [])[index] || {}).value || ';';
}
});
return result;
};
$scope.changeConnector = (parentIdx, idx) => {
if ((parentIdx === $scope.searchIdx - 1 || parentIdx === $scope.searchIdx) && idx === undefined) {
if (
(parentIdx === $scope.searchIdx - 1 ||
parentIdx === $scope.searchIdx) &&
idx === undefined
) {
$scope.connectors[parentIdx].value = ';';
} else {
if (idx !== undefined) {
const value = $scope.connectors[parentIdx].subgroup[idx].value;
$scope.connectors[parentIdx].subgroup[idx].value = value === ';' ? ',' : ';'
$scope.connectors[parentIdx].subgroup[idx].value =
value === ';' ? ',' : ';';
} else {
const value = $scope.connectors[parentIdx].value;
$scope.connectors[parentIdx].value = value === ';' ? ',' : ';'
$scope.connectors[parentIdx].value = value === ';' ? ',' : ';';
}
buildQuery($scope.groupedTagList);
}
@ -218,7 +238,13 @@ app.directive('wzTagFilter', function () {
/**
* This remove tag from search bar
*/
$scope.removeTag = (id, deleteGroup, parentIdx, idx, overwrite = false) => {
$scope.removeTag = (
id,
deleteGroup,
parentIdx,
idx,
overwrite = false
) => {
if (deleteGroup) {
$scope.tagList = $scope.tagList.filter(x => x.key !== id);
$scope.connectors.splice(parentIdx, 1);
@ -227,10 +253,12 @@ app.directive('wzTagFilter', function () {
if (idx < 0) {
idx = 0;
}
if ($scope.connectors[parentIdx] && $scope.connectors[parentIdx].subgroup) {
if (
$scope.connectors[parentIdx] &&
$scope.connectors[parentIdx].subgroup
) {
$scope.connectors[parentIdx].subgroup.splice(idx, 1);
} else
$scope.connectors.splice(parentIdx, 1);
} else $scope.connectors.splice(parentIdx, 1);
}
if ($scope.tagList.length <= 1) {
$scope.connectors = [{}];
@ -241,8 +269,7 @@ app.directive('wzTagFilter', function () {
$scope.searchIdx = false;
}
$scope.connectors = addConnectors($scope.groupedTagList);
if (!overwrite)
buildQuery($scope.groupedTagList);
if (!overwrite) buildQuery($scope.groupedTagList);
$scope.showAutocomplete(false);
};
@ -364,7 +391,7 @@ app.directive('wzTagFilter', function () {
/**
* This set to bar a keydown listener to show the autocomplete
*/
$('#wz-search-filter-bar-input').bind('keydown', function (e) {
$('#wz-search-filter-bar-input').bind('keydown', function(e) {
let $current = $('#wz-search-filter-bar-autocomplete-list li.selected');
if ($current.length === 0 && (e.keyCode === 38 || e.keyCode === 40)) {
$('#wz-search-filter-bar-autocomplete-list li')
@ -413,4 +440,4 @@ app.directive('wzTagFilter', function () {
},
template
};
});
});

View File

@ -209,7 +209,7 @@ export default [
_source: {
title: 'Top 10 Agent alerts',
visState:
'{"title":"Top 10 Agent alerts","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"timeseries","series":[{"id":"0eba6ef0-41a1-11e9-b2ca-a3f8ee4d0e71","color":"rgba(0,156,224,1)","split_mode":"terms","metrics":[{"id":"0eba6ef1-41a1-11e9-b2ca-a3f8ee4d0e71","type":"count"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","terms_field":"agent.name","terms_size":"10"}],"time_field":"@timestamp","index_pattern":"wazuh-alerts","interval":"auto","axis_position":"left","axis_formatter":"number","axis_scale":"normal","show_legend":1,"show_grid":1,"legend_position":"left"},"aggs":[]}',
'{"title":"Top 10 Agent alerts","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"timeseries","series":[{"id":"0eba6ef0-41a1-11e9-b2ca-a3f8ee4d0e71","color":"rgba(0,156,224,1)","split_mode":"terms","metrics":[{"id":"0eba6ef1-41a1-11e9-b2ca-a3f8ee4d0e71","type":"count"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","terms_field":"agent.name","terms_size":"10"}],"time_field":"@timestamp","index_pattern":"wazuh-alerts","interval":"auto","axis_position":"left","axis_formatter":"number","axis_scale":"normal","show_legend":1,"show_grid":1,"legend_position":"left"},"aggs":[]}',
uiStateJSON: '{}',
description: '',
version: 1,
@ -219,13 +219,13 @@ export default [
}
},
_type: 'visualization'
},
},
{
_id: 'Wazuh-App-Overview-General-Alert-level-evolution',
_source: {
title: 'Alert level evolution',
visState:
'{"title":"Alert level evolution","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"timeseries","series":[{"id":"61ca57f1-469d-11e7-af02-69e470af7417","color":"rgba(0,156,224,1)","split_mode":"terms","metrics":[{"id":"61ca57f2-469d-11e7-af02-69e470af7417","type":"count"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"bar","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","terms_field":"rule.level","terms_size":"16"}],"time_field":"@timestamp","index_pattern":"wazuh-alerts","interval":"auto","axis_position":"left","axis_formatter":"number","axis_scale":"normal","show_legend":1,"show_grid":1,"background_color":null,"background_color_rules":[{"id":"2eaf6f30-367a-11e9-a875-698afd42ed2c"}],"bar_color_rules":[{"id":"2f685ef0-367a-11e9-a875-698afd42ed2c"}],"gauge_color_rules":[{"id":"339f78f0-367a-11e9-a875-698afd42ed2c"}],"gauge_width":10,"gauge_inner_width":10,"gauge_style":"half"},"aggs":[]}',
'{"title":"Alert level evolution","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"timeseries","series":[{"id":"61ca57f1-469d-11e7-af02-69e470af7417","color":"rgba(0,156,224,1)","split_mode":"terms","metrics":[{"id":"61ca57f2-469d-11e7-af02-69e470af7417","type":"count"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"bar","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","terms_field":"rule.level","terms_size":"16"}],"time_field":"@timestamp","index_pattern":"wazuh-alerts","interval":"auto","axis_position":"left","axis_formatter":"number","axis_scale":"normal","show_legend":1,"show_grid":1,"background_color":null,"background_color_rules":[{"id":"2eaf6f30-367a-11e9-a875-698afd42ed2c"}],"bar_color_rules":[{"id":"2f685ef0-367a-11e9-a875-698afd42ed2c"}],"gauge_color_rules":[{"id":"339f78f0-367a-11e9-a875-698afd42ed2c"}],"gauge_width":10,"gauge_inner_width":10,"gauge_style":"half"},"aggs":[]}',
uiStateJSON: '{}',
description: '',
version: 1,