Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions client/src/components/Panels/Common/ToolSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import axios from "axios";
import { getAppRoot } from "onload/loadConfig";
import { getGalaxyInstance } from "app";
import DelayedInput from "components/Common/DelayedInput";
import MockAdapter from "axios-mock-adapter";
import testToolsSearchResponse from "./../../ToolsView/testData/toolsSearch";

export default {
name: "ToolSearch",
Expand Down Expand Up @@ -48,12 +50,26 @@ export default {
this.$emit("onResults", this.favoritesResults);
} else {
this.loading = true;

let axiosMock;
axiosMock = new MockAdapter(axios);
axiosMock.onGet(`${getAppRoot()}api/tools`).reply(200, testToolsSearchResponse);

axios
.get(`${getAppRoot()}api/tools`, {
params: { q, view: this.currentPanelView },
})
.then((response) => {
this.loading = false;

if (axiosMock) {
let toolID = [];
(response.data).forEach(function(tool) {
toolID.push(tool.id);
});
response.data = toolID;
}

this.$emit("onResults", response.data);
})
.catch((err) => {
Expand Down
43 changes: 31 additions & 12 deletions client/src/components/Panels/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ export function filterToolSections(layout, results) {
if (section.elems) {
section.elems.forEach((el) => {
if (
(!el.text && results.includes(el.id)) ||
(el.tool_shed_repository && results.includes(el.tool_shed_repository.name))
(!el.text && toolNameExistsInResults(el.id, results)) ||
(el.tool_shed_repository && toolNameExistsInResults(el.tool_shed_repository.name, results))
) {
toolRes.push(el);
}
});
}
// sort tools in section by rank in results
toolRes.sort((tool1, tool2) => {
return results.indexOf(tool1.id) - results.indexOf(tool2.id);
});

toolRes = sortToolsByResultsScore(toolRes, results);

return {
...section,
Expand All @@ -34,7 +32,7 @@ export function filterToolSections(layout, results) {
if (sect1.elems.length == 0 || sect2.elems.length == 0) {
return 0;
}
return results.indexOf(sect1.elems[0].id) - results.indexOf(sect2.elems[0].id);
return results.indexOf(sect1.elems[0].id) - results.indexOf(sect2.elems[0].id); //TODO may need updates to Object
});
} else {
return layout;
Expand All @@ -56,8 +54,8 @@ export function filterTools(layout, results) {
if (section.elems) {
section.elems.forEach((el) => {
if (
(!el.text && results.includes(el.id)) ||
(el.tool_shed_repository && results.includes(el.tool_shed_repository.name))
(!el.text && toolNameExistsInResults(el.id, results)) ||
(el.tool_shed_repository && toolNameExistsInResults(el.tool_shed_repository.name, results))
) {
toolsResults.push(el);
}
Expand All @@ -66,9 +64,10 @@ export function filterTools(layout, results) {
toolsResults.push(section);
}
});
return toolsResults.sort((tool1, tool2) => {
return results.indexOf(tool1.id) - results.indexOf(tool2.id);
});

toolsResults = sortToolsByResultsScore(toolsResults, results);

return toolsResults;
} else {
return layout;
}
Expand All @@ -84,3 +83,23 @@ function normalize_results(results) {
});
return norm_results;
}

/**
* Where `results` is an Array of Objects
*/
function sortToolsByResultsScore(tools, results) {
tools.sort((tool1, tool2) => {
return results.indexOf(tool1.score) - results.indexOf(tool2.score);
});

return tools;
}

/**
* Where `results` is an Array of Objects
*/
function toolNameExistsInResults(toolname, results) {
let matchedTools = results.filter((r) => r.id === toolname);

return matchedTools && matchedTools.length > 0;
}
Loading