|
|
|
|
@ -21,6 +21,8 @@ function register() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchButton.on("click", ()=>{
|
|
|
|
|
let term = searchBar.val().toString();
|
|
|
|
|
if (!term || 0 === term.length) {
|
|
|
|
|
@ -36,16 +38,35 @@ function reset(){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function search(term: string) {
|
|
|
|
|
let webcards = getWebCardsWithSearchTerm(term);
|
|
|
|
|
let webCards = getWebCardsWithSearchTerm(term);
|
|
|
|
|
let fileCards = getFileCardsWithSearchTerm(term);
|
|
|
|
|
buildCardsFromConfig(webcards, fileCards);
|
|
|
|
|
|
|
|
|
|
copyMissingKeys(webCards, fileCards);
|
|
|
|
|
|
|
|
|
|
buildCardsFromConfig(webCards, fileCards);
|
|
|
|
|
expandAllContainers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function copyMissingKeys(webCards: object, fileCards: Map<string, object>){
|
|
|
|
|
let elementConfig = Configurator.loadAppConfig("resources-landing-page.json");
|
|
|
|
|
let containerKeys = Object.keys(elementConfig);
|
|
|
|
|
for (let containerKey of containerKeys) {
|
|
|
|
|
let container = webCards[containerKey];
|
|
|
|
|
let elementContainer = elementConfig[containerKey];
|
|
|
|
|
for (let [key, value] of fileCards) {
|
|
|
|
|
if (!container[key]) {
|
|
|
|
|
let original = elementContainer[key];
|
|
|
|
|
original["cards"] = [];
|
|
|
|
|
container[key] = original;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getFileCardsWithSearchTerm(term): Map<string, object> {
|
|
|
|
|
let map = new Map<string, object>()
|
|
|
|
|
let directoryPath = path.join(__dirname, "../assets/resources");
|
|
|
|
|
let fileCards = new DocumentDirectory(directoryPath).getCards();
|
|
|
|
|
console.log(fileCards);
|
|
|
|
|
for (let [key, value] of fileCards) {
|
|
|
|
|
for (let card of value) {
|
|
|
|
|
if (cardContainsTerm(term, card)) {
|
|
|
|
|
@ -53,20 +74,18 @@ function getFileCardsWithSearchTerm(term): Map<string, object> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getWebCardsWithSearchTerm(term): object {
|
|
|
|
|
let map = {};
|
|
|
|
|
let elementConfig = Configurator.loadAppConfig("resources-landing-page.json");
|
|
|
|
|
console.log(elementConfig);
|
|
|
|
|
let containerKeys = Object.keys(elementConfig);
|
|
|
|
|
for (let i = 0, l = containerKeys.length; i < l; i++) {
|
|
|
|
|
let containerKey = containerKeys[i];
|
|
|
|
|
map[containerKey] = {};
|
|
|
|
|
let container = elementConfig[containerKey];
|
|
|
|
|
let categoryKeys = Object.keys(container);
|
|
|
|
|
console.log()
|
|
|
|
|
for (let categoryIdx in categoryKeys) {
|
|
|
|
|
let categoryKey = categoryKeys[categoryIdx]
|
|
|
|
|
let category = container[categoryKey];
|
|
|
|
|
@ -106,8 +125,9 @@ function addToFileMap(map: Map<string, object>, categoryKey: string, card) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cardContainsTerm(term: string, card: object): boolean {
|
|
|
|
|
let titleContains = card["title"].toLowerCase().includes(term.toLowerCase())
|
|
|
|
|
let descriptionContains = card["description"].toLowerCase().includes(term.toLowerCase())
|
|
|
|
|
let titleContains = card["title"].toLowerCase().includes(term.toLowerCase());
|
|
|
|
|
let descriptionContains = card["description"].toLowerCase().includes(term.toLowerCase());
|
|
|
|
|
//todo: add keywords
|
|
|
|
|
return titleContains || descriptionContains;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -123,4 +143,12 @@ function escapeRegExp(term: string): string {
|
|
|
|
|
return term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function expandAllContainers(){
|
|
|
|
|
let containers = $('[id$="collapser"]')
|
|
|
|
|
for(let container of containers){
|
|
|
|
|
container.click()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
register()
|