Commit 7ab9440a authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'project_find' into 'master'

Remove var from project_find_file.js

Closes #36275

See merge request gitlab-org/gitlab!20114
parents 0e6b59bb 3b651e48
/* 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 fuzzaldrinPlus from 'fuzzaldrin-plus';
......@@ -9,9 +9,12 @@ import sanitize from 'sanitize-html';
// highlight text(awefwbwgtc -> <b>a</b>wefw<b>b</b>wgt<b>c</b> )
const highlighter = function(element, text, matches) {
var j, lastIndex, len, matchIndex, matchedChars, unmatched;
lastIndex = 0;
matchedChars = [];
let j = 0;
let len = 0;
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) {
matchIndex = matches[j];
unmatched = text.substring(lastIndex, matchIndex);
......@@ -55,10 +58,10 @@ export default class ProjectFindFile {
'keyup',
(function(_this) {
return function(event) {
var oldValue, ref, target, value;
target = $(event.target);
value = target.val();
oldValue = (ref = target.data('oldValue')) != null ? ref : '';
const target = $(event.target);
const value = target.val();
const ref = target.data('oldValue');
const oldValue = ref != null ? ref : '';
if (value !== oldValue) {
target.data('oldValue', value);
_this.findFile();
......@@ -74,9 +77,8 @@ export default class ProjectFindFile {
}
findFile() {
var result, searchText;
searchText = sanitize(this.inputElement.val());
result =
const searchText = sanitize(this.inputElement.val());
const result =
searchText.length > 0 ? fuzzaldrinPlus.filter(this.filePaths, searchText) : this.filePaths;
return this.renderList(result, searchText);
// find file
......@@ -101,20 +103,21 @@ export default class ProjectFindFile {
// render result
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();
results = [];
for (i = 0, len = filePaths.length; i < len; i += 1) {
filePath = filePaths[i];
const filePath = filePaths[i];
if (i === 20) {
break;
}
if (searchText) {
matches = fuzzaldrinPlus.match(filePath, searchText);
}
blobItemUrl = `${this.options.blobUrlTemplate}/${encodeURIComponent(filePath)}`;
html = ProjectFindFile.makeHtml(filePath, matches, blobItemUrl);
const blobItemUrl = `${this.options.blobUrlTemplate}/${encodeURIComponent(filePath)}`;
const html = ProjectFindFile.makeHtml(filePath, matches, blobItemUrl);
results.push(this.element.find('.tree-table > tbody').append(html));
}
......@@ -125,8 +128,7 @@ export default class ProjectFindFile {
// make tbody row html
static makeHtml(filePath, matches, blobItemUrl) {
var $tr;
$tr = $(
const $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) {
......@@ -141,9 +143,9 @@ export default class ProjectFindFile {
}
selectRow(type) {
var next, rows, selectedRow;
rows = this.element.find('.files-slider tr.tree-item');
selectedRow = this.element.find('.files-slider tr.tree-item.selected');
const rows = this.element.find('.files-slider tr.tree-item');
let selectedRow = this.element.find('.files-slider tr.tree-item.selected');
let next = selectedRow.prev();
if (rows && rows.length > 0) {
if (selectedRow && selectedRow.length > 0) {
if (type === 'UP') {
......@@ -175,7 +177,7 @@ export default class ProjectFindFile {
}
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) {
$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