Skip to content

Commit

Permalink
MIR-1362 fix empty value in the input query field, fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy 'Alex' Levshyn committed Nov 15, 2024
1 parent 82622a2 commit f51c3e6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,45 +177,45 @@ public void searchBy(String title) {
public void searchByPublication(String title, String subTitle, String author, String name, String nameIdentifier,
String metadata, String content) {

// select mods (filter query) is 'all'
if (title != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Alles")).click();
new Select(driver.waitAndFindElement(By.id("select_mods"))).selectByValue("all");
qry(title);
}

// select mods (filter query) is 'mods.title'
if (subTitle != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Titel")).click();
new Select(driver.waitAndFindElement(By.id("select_mods"))).selectByValue("mods.title");
qry(subTitle);
}

// select mods (filter query) is 'mods.author'
if (author != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Autor")).click();
new Select(driver.waitAndFindElement(By.id("select_mods"))).selectByValue("mods.author");
qry(author);
}

// select mods (filter query) is 'mods.name.top'
if (name != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Name")).click();
new Select(driver.waitAndFindElement(By.id("select_mods"))).selectByValue("mods.name.top");
qry(name);
}

// select mods (filter query) is 'mods.nameIdentifier'
if (nameIdentifier != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Namens Identifikator")).click();
new Select(driver.waitAndFindElement(By.id("select_mods"))).selectByValue("mods.nameIdentifier");
qry(nameIdentifier);
}

// select mods (filter query) is 'allMeta'
if (metadata != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Alle Metadaten")).click();
new Select(driver.waitAndFindElement(By.id("select_mods"))).selectByValue("allMeta");
qry(metadata);
}

// select mods (filter query) is 'content'
if (content != null) {
driver.waitAndFindElement(By.id("search_type_label")).click();
driver.waitAndFindElement(MCRBy.partialLinkText("Volltext")).click();
new Select(driver.waitAndFindElement(By.id("select_mods"))).selectByValue("content");
qry(content);
}

Expand Down
80 changes: 58 additions & 22 deletions mir-module/src/main/resources/META-INF/resources/js/mir/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,10 @@

// Input element in the original search
const originalSearchInputElement = "#searchInput";
// Selector for the search form
// Selector for the second search form
const subSearchFormName = "form.search_form";
// The submit button in the second search form
const secondSearchFormSubmitButtonElement = subSearchFormName + ' button[type="submit"]';
// ID of the input field for the second search text
const qrySelector = "#qry";
// ID of the select box with the filter query key
Expand All @@ -319,52 +321,86 @@

// Changes in the select box for the filter query
$(selectMods).change(() => {
setFQAndCondQueryElementsValues();
setFQAndCondQueryElementsValues('selectMods');
});

// Changes in the input field of the filter query
$(qrySelector).change(() => {
setFQAndCondQueryElementsValues();
setFQAndCondQueryElementsValues('changeQry');
});

// Key up changes in the second search input element
$(qrySelector).keyup(() => {
if ($(selectMods)) {
const queryText = $(qrySelector).val().trim();
const selectModsValue = $(selectMods).val();
// Case if selectMods is 'all' - 'everything'
if (selectModsValue !== 'all') {
if (queryText !== '') {
// Enable the submit button in the second search form
enableButton(secondSearchFormSubmitButtonElement);
} else {
// Disable the submit button in the second search form
disableButton(secondSearchFormSubmitButtonElement);
}
}
}
});

// Changes for the fq element and condQuery element
function setFQAndCondQueryElementsValues() {
function setFQAndCondQueryElementsValues(eventType = 'selectMods') {
if ($(selectMods) && $(qrySelector) && $(fqElement) && $(initialCondQuerySecond) && $(condQuery)) {
let queryText = '';
if ($(qrySelector).val() !== '') {
queryText = $(qrySelector).val().trim();
// Remove all duplicate spaces, tabs, newlines etc
queryText = queryText.replace(/\s\s+/g, ' ');
}

queryText = $(qrySelector).val().trim();
// Remove all duplicate spaces, tabs, newlines etc
queryText = queryText.replace(/\s\s+/g, ' ');
const initialCondQueryValue = $(initialCondQuerySecond).val().trim();

const selectModsValue = $(selectMods).val();
// Case if selectMods is 'all' - 'everything'
if (selectModsValue === 'all') {
$(fqElement).attr('value', '');
let condQueryValue = initialCondQueryValue;
if (initialCondQueryValue !== '') {
if (queryText !== '') {
condQueryValue += ' AND ' + queryText;
}
condQueryValue += ' AND ' + queryText;
} else {
if (queryText !== '') {
condQueryValue += queryText;
}
condQueryValue += queryText;
}
$(condQuery).attr('value', condQueryValue);
if (eventType === 'selectMods') {
// Enable the submit button in the second search form
enableButton(secondSearchFormSubmitButtonElement);
}
} else {
if (queryText !== '') {
// const selectModsValue = $(selectMods).val();
const filterQuery = selectModsValue + ':' + queryText;
$(fqElement).attr('value', filterQuery);
$(condQuery).attr('value', initialCondQueryValue);
const filterQuery = selectModsValue + ':' + queryText;
$(fqElement).attr('value', filterQuery);
$(condQuery).attr('value', initialCondQueryValue);
if (eventType === 'selectMods') {
if (queryText !== '') {
// Enable the submit button in the second search form
enableButton(secondSearchFormSubmitButtonElement);
} else {
// Disable the submit button in the second search form
disableButton(secondSearchFormSubmitButtonElement);
}
}
}
}
}

// Disable the button
function disableButton(element) {
if (element) {
$(element).attr('disabled','disabled');
}
}

// Enable the button
function enableButton(element) {
if (element) {
$(element).removeAttr('disabled');
}
}

var languageList = jQuery('#topnav .languageList');
jQuery('#topnav .languageSelect').click(function() {
languageList.toggleClass('hide');
Expand Down

0 comments on commit f51c3e6

Please sign in to comment.