Skip to content

Commit

Permalink
Fixed banner, filter and search result issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
chuanlin2018 committed Aug 26, 2024
1 parent 935a3f7 commit 41cd332
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 47 deletions.
59 changes: 20 additions & 39 deletions angular/src/app/landing/filters/filters.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ export class FiltersComponent implements OnInit {
this.filterResults();
}

/**
* Replace reserved chars with char name to avoid problems
* when parsing filter string in the result list component.
* For example, replace "&" with "aaamp". result list component
* restore "aaamp" back to "&".
* @param strng input string
*/
escapeReservedChars(inputStrng: string) {
let outputString: string;
if(!inputStrng || inputStrng.trim() == "")
return "";
else
return inputStrng.replace(new RegExp("&", "g"), "aaamp")
}

/**
* Form the filter string and refresh the result page
Expand All @@ -203,62 +217,29 @@ export class FiltersComponent implements OnInit {
let compType = '';
let resourceType = '';

// Resource type
// if (this.selectedResourceTypeNode.length > 0) {
// lFilterString += "@type=";

// for (let res of this.selectedResourceTypeNode) {
// if (res && typeof res.data !== 'undefined' && res.data !== 'undefined') {
// resourceTypesSelected = true;
// this.selectedResourceType.push(res.data);
// resourceType += res.data[0] + ',';

// lFilterString += res.data[0].replace(/\s/g, "") + ",";
// }
// }

// lFilterString = this.removeEndingComma(lFilterString);
// }

// Resource type
if(this.filterStrings["@type"]) {
if(lFilterString != '') lFilterString += "&";
lFilterString += this.filterStrings["@type"];
lFilterString += this.escapeReservedChars(this.filterStrings["@type"]);
lFilterString = this.removeEndingComma(lFilterString);
}

// Collections
for(let col of this.collectionOrder) {
if(this.filterStrings[col]) {
if(lFilterString != '') lFilterString += "&";
lFilterString += this.filterStrings[col];
lFilterString += this.escapeReservedChars(this.filterStrings[col]);
lFilterString = this.removeEndingComma(lFilterString);
}
}

// Record has
// if (this.selectedComponentsNode.length > 0) {
// if(lFilterString != '') lFilterString += "&";

// lFilterString += "components.@type=";

// for (let comp of this.selectedComponentsNode) {
// if (comp != 'undefined' && typeof comp.data !== 'undefined' && comp.data !== 'undefined') {
// componentSelected = true;
// this.selectedComponents.push(comp.data);
// compType += comp.data[0] + ',';

// lFilterString += comp.data[0].replace(/\s/g, "") + ",";
// }
// }
// }

if(this.filterStrings["components.@type"]) {
if(lFilterString != '') lFilterString += "&";
lFilterString += this.filterStrings["components.@type"];
lFilterString += this.escapeReservedChars(this.filterStrings["components.@type"]);
lFilterString = this.removeEndingComma(lFilterString);
}

// lFilterString = this.removeEndingComma(lFilterString);

// Authors and contributors
if (this.selectedAuthor.length > 0) {
if(lFilterString != '') lFilterString += "&";
Expand All @@ -278,7 +259,7 @@ export class FiltersComponent implements OnInit {

lFilterString += "keyword=";
for (let keyword of this.selectedKeywords) {
lFilterString += this.suggestedKeywordsLkup[keyword] + ",";
lFilterString += this.escapeReservedChars(this.suggestedKeywordsLkup[keyword]) + ",";
}
}

Expand Down
2 changes: 1 addition & 1 deletion angular/src/app/landing/landingpage.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class LandingPageComponent implements OnInit, AfterViewInit {
let metadataError = "";
this.displaySpecialMessage = false;
this.CART_ACTIONS = CartActions.cartActions;
this.imageURL = 'assets/images/fingerprint.jpg';
this.imageURL = '';

// Only listen to storage change if we are not in edit mode
if(this.inBrowser && !this.editEnabled){
Expand Down
22 changes: 17 additions & 5 deletions angular/src/app/landing/resultlist/resultlist.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class ResultlistComponent implements OnInit {
//Pagination
totalResultItems: number = 0;
totalPages: number = 0;
itemsPerPage: number = 10;
itemsPerPage: number = 20;
pages = [{name:'Page 1', value:1},{name:'Page 2', value:2}];
currentPage: any = {name:'Page 1', value:1};

Expand Down Expand Up @@ -370,6 +370,17 @@ export class ResultlistComponent implements OnInit {
}
}

/**
* Restore reserved chars. For example, change "aaamp" back to "&".
* @param inputString
*/
restoreReservedChars(inputString: string) {
if(!inputString || inputString.trim() == "")
return "";
else
return inputString.replace(new RegExp("aaamp", "g"), "&");
}

/**
* Apply filters from left side panel and the search word(s) from the search text box
*/
Expand Down Expand Up @@ -397,7 +408,7 @@ export class ResultlistComponent implements OnInit {
object["@type"].forEach((oType) => {
let types = filter.split("=")[1].split(",");
types.forEach(type => {
if(oType.toLowerCase().includes(type.toLowerCase()))
if(oType.toLowerCase().includes(this.restoreReservedChars(type).toLowerCase()))
object.active = true;
});
})
Expand All @@ -415,7 +426,7 @@ export class ResultlistComponent implements OnInit {
for(let oTopic of resultItem["topic"]) {
for(let topic of topics) {
let collection = topic.split("----")[0];
let topicValue = topic.split("----")[1];
let topicValue = this.restoreReservedChars(topic.split("----")[1]);

if(oTopic['scheme'].indexOf(this.taxonomyURI[collection]) >= 0) {
if(collection == Collections.DEFAULT) {
Expand All @@ -442,7 +453,7 @@ export class ResultlistComponent implements OnInit {
component["@type"].forEach((cType) => {
let types = filter.split("=")[1].split(",");
types.forEach(type => {
if(cType.toLowerCase().includes(type.toLowerCase()))
if(cType.toLowerCase().includes(this.restoreReservedChars(type).toLowerCase()))
object.active = true;
});
})
Expand Down Expand Up @@ -475,7 +486,7 @@ export class ResultlistComponent implements OnInit {
object["keyword"].forEach((keyword) => {
//Loop through each search keyword from keyword filter
filter.split("=")[1].split(",").forEach(kw => {
if(keyword.toLowerCase().includes(kw)){
if(keyword.toLowerCase().includes(this.restoreReservedChars(kw))){
object.active = true;
}
})
Expand Down Expand Up @@ -511,6 +522,7 @@ export class ResultlistComponent implements OnInit {
this.searchResultsForDisplay = JSON.parse(JSON.stringify(this.searchResultsForDisplayOriginal));

this.refreshResult();
event.target.value = "";
return;
}

Expand Down
4 changes: 2 additions & 2 deletions angular/src/app/landing/taxonomy/taxonomy.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class TaxonomyComponent implements OnInit {
tempTotal: number = 0;
totalNodes: number = 0;
totalSelectedNodes: number = 0;
allChecked: boolean = true;
allChecked: boolean = false;

researchTopicStyle: any;

Expand All @@ -64,7 +64,7 @@ export class TaxonomyComponent implements OnInit {
ngAfterViewInit(): void {
//Called after ngAfterContentInit when the component's view has been initialized. Applies to components only.
//Add 'implements AfterViewInit' to the class.
this.checkAll();
this.uncheckAll();
}

ngOnChanges(changes: SimpleChanges): void {
Expand Down

0 comments on commit 41cd332

Please sign in to comment.