Passed
Push — master ( db8da5...c2ef0a )
by Eduardo
02:35
created

app/js/renderer/bwa/analyser.js   A

Complexity

Total Complexity 10
Complexity/F 1.67

Size

Lines of Code 77
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 10
eloc 47
c 1
b 0
f 0
nc 1
mnd 2
bc 9
fnc 6
dl 0
loc 77
rs 10
bpm 1.5
cpm 1.6666
noi 6

6 Functions

Rating   Name   Duplication   Size   Complexity  
A $(ꞌ#bwaAnalyserButtonCloseꞌ).click 0 3 1
A analyser.js ➔ getInitials 0 9 2
A analyser.js ➔ showTable 0 37 4
A $(ꞌ#bwaAnalyserModalCloseButtonNoꞌ).click 0 3 1
A ipcRenderer.bwa:analyser.tablegen 0 4 1
A $(ꞌ#bwaAnalyserModalCloseButtonYesꞌ).click 0 5 1
1
/** global: appSettings */
2
var whois = require('../../common/whoiswrapper.js'),
3
  conversions = require('../../common/conversions.js'),
4
  fs = require('fs'),
5
  Papa = require('papaparse'),
6
  dt = require('datatables')(),
7
  bwaFileContents;
8
9
const {
10
  ipcRenderer
11
} = require('electron');
12
13
ipcRenderer.on('bwa:analyser.tablegen', function(event, contents) {
14
  bwaFileContents = contents;
15
  showTable();
16
});
17
18
$('#bwaAnalyserButtonClose').click(function() {
19
  $('#bwaAnalyserModalClose').addClass('is-active');
20
});
21
22
$('#bwaAnalyserModalCloseButtonYes').click(function() {
23
  $('#bwaAnalyser').addClass('is-hidden');
24
  $('#bwaAnalyserModalClose').removeClass('is-active');
25
  $('#bwaEntry').removeClass('is-hidden');
26
});
27
28
$('#bwaAnalyserModalCloseButtonNo').click(function() {
29
  $('#bwaAnalyserModalClose').removeClass('is-active');
30
});
31
32
function showTable() {
33
  var header = {},
34
    body = {};
35
  header.columns = Object.keys(bwaFileContents.data[0]);
36
  console.log(header.columns);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
37
  body.records = bwaFileContents.data;
38
39
  // Generate header column content
40
  header.content = '<tr>\n';
41
  for (column in header.columns) {
0 ignored issues
show
Bug introduced by
The variable column seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.column.
Loading history...
42
    header.content += '\t<th><abbr title="{0}">{1}</abbr></th>\n'.format(header.columns[column], getInitials(header.columns[column]));
43
  }
44
  header.content += '</tr>';
45
46
  $('#bwaAnalyserTableThead').html(header.content);
47
  //console.log(header.content);
48
49
  // Generate record fields
50
  body.content = '';
51
  for (record in body.records) {
0 ignored issues
show
Bug introduced by
The variable record seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.record.
Loading history...
52
    body.content += '<tr>\n';
53
    //console.log(body.content);
54
    //console.log(body.records[record]);
55
56
    for (field in body.records[record]) {
0 ignored issues
show
Bug introduced by
The variable field seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.field.
Loading history...
57
      body.content += '\t<td>{0}</td>\n'.format(body.records[record][field]);
58
    }
59
    body.content += '</tr>\n';
60
  }
61
  //console.log(body.content);
62
  $('#bwaAnalyserTableTbody').html(body.content);
63
  basetable = $('#bwaAnalyserTable').dataTable();
0 ignored issues
show
Bug introduced by
The variable basetable seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.basetable.
Loading history...
64
  //$('#bwaAnalyserTable_paginate > a').addClass('button is-small')
65
66
  $('#bwaFileinputconfirm').addClass('is-hidden');
67
  $('#bwaAnalyser').removeClass('is-hidden');
68
}
69
70
function getInitials(string, threshold = 1) {
71
  initials = string.match(/\b\w/g);
0 ignored issues
show
Bug introduced by
The variable initials seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.initials.
Loading history...
72
73
  (initials.length > threshold) ?
74
    initials = initials.join("").toString() :
75
    initials = string.substring(0, threshold + 1);
76
77
  return initials;
78
}
79