Commit 3b651e48 authored by Utkarsh Gupta's avatar Utkarsh Gupta Committed by Martin Wortschack

Remove var from project_find_file.js

parent 0e6b59bb
/* eslint-disable func-names, no-var, consistent-return, one-var, no-cond-assign, no-return-assign */ /* eslint-disable func-names, consistent-return, no-return-assign */
import $ from 'jquery'; import $ from 'jquery';
import fuzzaldrinPlus from 'fuzzaldrin-plus'; import fuzzaldrinPlus from 'fuzzaldrin-plus';
...@@ -9,9 +9,12 @@ import sanitize from 'sanitize-html'; ...@@ -9,9 +9,12 @@ import sanitize from 'sanitize-html';
// highlight text(awefwbwgtc -> <b>a</b>wefw<b>b</b>wgt<b>c</b> ) // highlight text(awefwbwgtc -> <b>a</b>wefw<b>b</b>wgt<b>c</b> )
const highlighter = function(element, text, matches) { const highlighter = function(element, text, matches) {
var j, lastIndex, len, matchIndex, matchedChars, unmatched; let j = 0;
lastIndex = 0; let len = 0;
matchedChars = []; let lastIndex = 0;
let matchedChars = [];
let matchIndex = matches[j];
let unmatched = text.substring(lastIndex, matchIndex);
for (j = 0, len = matches.length; j < len; j += 1) { for (j = 0, len = matches.length; j < len; j += 1) {
matchIndex = matches[j]; matchIndex = matches[j];
unmatched = text.substring(lastIndex, matchIndex); unmatched = text.substring(lastIndex, matchIndex);
...@@ -55,10 +58,10 @@ export default class ProjectFindFile { ...@@ -55,10 +58,10 @@ export default class ProjectFindFile {
'keyup', 'keyup',
(function(_this) { (function(_this) {
return function(event) { return function(event) {
var oldValue, ref, target, value; const target = $(event.target);
target = $(event.target); const value = target.val();
value = target.val(); const ref = target.data('oldValue');
oldValue = (ref = target.data('oldValue')) != null ? ref : ''; const oldValue = ref != null ? ref : '';
if (value !== oldValue) { if (value !== oldValue) {
target.data('oldValue', value); target.data('oldValue', value);
_this.findFile(); _this.findFile();
...@@ -74,9 +77,8 @@ export default class ProjectFindFile { ...@@ -74,9 +77,8 @@ export default class ProjectFindFile {
} }
findFile() { findFile() {
var result, searchText; const searchText = sanitize(this.inputElement.val());
searchText = sanitize(this.inputElement.val()); const result =
result =
searchText.length > 0 ? fuzzaldrinPlus.filter(this.filePaths, searchText) : this.filePaths; searchText.length > 0 ? fuzzaldrinPlus.filter(this.filePaths, searchText) : this.filePaths;
return this.renderList(result, searchText); return this.renderList(result, searchText);
// find file // find file
...@@ -101,20 +103,21 @@ export default class ProjectFindFile { ...@@ -101,20 +103,21 @@ export default class ProjectFindFile {
// render result // render result
renderList(filePaths, searchText) { renderList(filePaths, searchText) {
var blobItemUrl, filePath, html, i, len, matches, results; let i = 0;
let len = 0;
let matches = [];
const results = [];
this.element.find('.tree-table > tbody').empty(); this.element.find('.tree-table > tbody').empty();
results = [];
for (i = 0, len = filePaths.length; i < len; i += 1) { for (i = 0, len = filePaths.length; i < len; i += 1) {
filePath = filePaths[i]; const filePath = filePaths[i];
if (i === 20) { if (i === 20) {
break; break;
} }
if (searchText) { if (searchText) {
matches = fuzzaldrinPlus.match(filePath, searchText); matches = fuzzaldrinPlus.match(filePath, searchText);
} }
blobItemUrl = `${this.options.blobUrlTemplate}/${encodeURIComponent(filePath)}`; const blobItemUrl = `${this.options.blobUrlTemplate}/${encodeURIComponent(filePath)}`;
html = ProjectFindFile.makeHtml(filePath, matches, blobItemUrl); const html = ProjectFindFile.makeHtml(filePath, matches, blobItemUrl);
results.push(this.element.find('.tree-table > tbody').append(html)); results.push(this.element.find('.tree-table > tbody').append(html));
} }
...@@ -125,8 +128,7 @@ export default class ProjectFindFile { ...@@ -125,8 +128,7 @@ export default class ProjectFindFile {
// make tbody row html // make tbody row html
static makeHtml(filePath, matches, blobItemUrl) { static makeHtml(filePath, matches, blobItemUrl) {
var $tr; const $tr = $(
$tr = $(
"<tr class='tree-item'><td class='tree-item-file-name link-container'><a><i class='fa fa-file-text-o fa-fw'></i><span class='str-truncated'></span></a></td></tr>", "<tr class='tree-item'><td class='tree-item-file-name link-container'><a><i class='fa fa-file-text-o fa-fw'></i><span class='str-truncated'></span></a></td></tr>",
); );
if (matches) { if (matches) {
...@@ -141,9 +143,9 @@ export default class ProjectFindFile { ...@@ -141,9 +143,9 @@ export default class ProjectFindFile {
} }
selectRow(type) { selectRow(type) {
var next, rows, selectedRow; const rows = this.element.find('.files-slider tr.tree-item');
rows = this.element.find('.files-slider tr.tree-item'); let selectedRow = this.element.find('.files-slider tr.tree-item.selected');
selectedRow = this.element.find('.files-slider tr.tree-item.selected'); let next = selectedRow.prev();
if (rows && rows.length > 0) { if (rows && rows.length > 0) {
if (selectedRow && selectedRow.length > 0) { if (selectedRow && selectedRow.length > 0) {
if (type === 'UP') { if (type === 'UP') {
...@@ -175,7 +177,7 @@ export default class ProjectFindFile { ...@@ -175,7 +177,7 @@ export default class ProjectFindFile {
} }
goToBlob() { goToBlob() {
var $link = this.element.find('.tree-item.selected .tree-item-file-name a'); const $link = this.element.find('.tree-item.selected .tree-item-file-name a');
if ($link.length) { if ($link.length) {
$link.get(0).click(); $link.get(0).click();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment