From 3f2bd1c673a8bdf4e92fc9b34c5be02e8b5797f3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 31 Dec 2020 09:59:06 +0100 Subject: [PATCH 1/3] Ready to reorganize into different files --- .../UI/Spaces/Design-Space/DesignSpace.js | 2 - .../UI/Spaces/Docs-Space/DocsSpace.js | 68 ++++++++++++++----- .../UI/Spaces/Docs-Space/DocumentPage.js | 16 +++++ .../Superalgos/UI/Spaces/Docs-Space/Footer.js | 16 +++++ .../UI/Spaces/Docs-Space/MainSearchPage.js | 16 +++++ .../UI/Spaces/Docs-Space/SearchEngine.js | 16 +++++ .../UI/Spaces/Docs-Space/SearchResultsPage.js | 16 +++++ 7 files changed, 131 insertions(+), 19 deletions(-) create mode 100644 Projects/Superalgos/UI/Spaces/Docs-Space/DocumentPage.js create mode 100644 Projects/Superalgos/UI/Spaces/Docs-Space/Footer.js create mode 100644 Projects/Superalgos/UI/Spaces/Docs-Space/MainSearchPage.js create mode 100644 Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js create mode 100644 Projects/Superalgos/UI/Spaces/Docs-Space/SearchResultsPage.js diff --git a/Projects/Superalgos/UI/Spaces/Design-Space/DesignSpace.js b/Projects/Superalgos/UI/Spaces/Design-Space/DesignSpace.js index 09a05e437..23e4647f3 100644 --- a/Projects/Superalgos/UI/Spaces/Design-Space/DesignSpace.js +++ b/Projects/Superalgos/UI/Spaces/Design-Space/DesignSpace.js @@ -1,6 +1,4 @@ - function newSuperalgosDesignSpace() { - const MODULE_NAME = 'Designe Space' let thisObject = { container: undefined, iconsByProjectAndName: undefined, diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index 63f2c76a0..3d2c17a84 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -1,10 +1,15 @@ function newSuperalgosDocSpace() { const MODULE_NAME = 'Doc Space' let thisObject = { - changeLanguage: changeLanguage, isVisible: undefined, sidePanelTab: undefined, container: undefined, + searchEngine: undefined, + mainSearchPage: undefined, + searchResultsPage: undefined, + footer: undefined, + documentPage: undefined, + changeLanguage: changeLanguage, openSpaceAreaAndNavigateTo: openSpaceAreaAndNavigateTo, navigateTo: navigateTo, scrollToElement: scrollToElement, @@ -54,28 +59,43 @@ function newSuperalgosDocSpace() { function initialize() { docsIndex = [] - thisObject.sidePanelTab = newSidePanelTab() - thisObject.sidePanelTab.container.connectToParent(thisObject.container, false, false) - thisObject.sidePanelTab.initialize('right') - openingEventSubscriptionId = thisObject.sidePanelTab.container.eventHandler.listenToEvent('opening', onOpening) - closingEventSubscriptionId = thisObject.sidePanelTab.container.eventHandler.listenToEvent('closing', onClosing) - browserResizedEventSubscriptionId = canvas.eventHandler.listenToEvent('Browser Resized', resize) + setupSidePanelTab() setUpContextMenu() setUpMenuItemsMap() + setupUserLanguage() - /* - Getting the used preferred languague - */ - if (window.localStorage.getItem('Docs Language') !== null && window.localStorage.getItem('Docs Language') !== undefined && window.localStorage.getItem('Docs Language') !== 'undefined') { - language = window.localStorage.getItem('Docs Language') - } else { - window.localStorage.setItem('Docs Language', DEFAULT_LANGUAGE) - language = DEFAULT_LANGUAGE - } + thisObject.searchEngine = newSuperalgosDocsSearchEngine() + thisObject.mainSearchPage = newSuperalgosDocsMainSearchPage() + thisObject.searchResultsPage = newSuperalgosDocsSearchResultsPage() + thisObject.documentPage = newSuperalgosDocsDocumentPage() + thisObject.footer = newSuperalgosDocsFooter() isInitialized = true + function setupUserLanguage() { + /* + Getting the used preferred languague + */ + if (window.localStorage.getItem('Docs Language') !== null && window.localStorage.getItem('Docs Language') !== undefined && window.localStorage.getItem('Docs Language') !== 'undefined') { + language = window.localStorage.getItem('Docs Language') + } else { + window.localStorage.setItem('Docs Language', DEFAULT_LANGUAGE) + language = DEFAULT_LANGUAGE + } + + } + + function setupSidePanelTab() { + thisObject.sidePanelTab = newSidePanelTab() + thisObject.sidePanelTab.container.connectToParent(thisObject.container, false, false) + thisObject.sidePanelTab.initialize('right') + openingEventSubscriptionId = thisObject.sidePanelTab.container.eventHandler.listenToEvent('opening', onOpening) + closingEventSubscriptionId = thisObject.sidePanelTab.container.eventHandler.listenToEvent('closing', onClosing) + + browserResizedEventSubscriptionId = canvas.eventHandler.listenToEvent('Browser Resized', resize) + } + function setUpContextMenu() { window.contextMenu = { editParagraph: editParagraph, @@ -386,6 +406,18 @@ function newSuperalgosDocSpace() { thisObject.sidePanelTab.container.eventHandler.stopListening(openingEventSubscriptionId) thisObject.sidePanelTab.container.eventHandler.stopListening(closingEventSubscriptionId) + thisObject.searchEngine.finalize() + thisObject.mainSearchPage.finalize() + thisObject.searchResultsPage.finalize() + thisObject.documentPage.finalize() + thisObject.footer.finalize() + + thisObject.searchEngine = undefined + thisObject.mainSearchPage = undefined + thisObject.searchResultsPage = undefined + thisObject.documentPage = undefined + thisObject.footer = undefined + objectBeingRendered = undefined paragraphMap = undefined appSchemaDocument = undefined @@ -393,6 +425,8 @@ function newSuperalgosDocSpace() { menuLabelsMap = undefined docsIndex = undefined isInitialized = false + + } function reset() { @@ -2075,7 +2109,7 @@ function newSuperalgosDocSpace() { } } if (objectBeingRendered.category === 'Node') { - autoGeneratedHtml() + autoGeneratedHtml() } HTML = HTML + '' // Content Ends diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocumentPage.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocumentPage.js new file mode 100644 index 000000000..b5bd237be --- /dev/null +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocumentPage.js @@ -0,0 +1,16 @@ +function newSuperalgosDocsDocumentPage() { + let thisObject = { + initialize: initialize, + finalize: finalize + } + + return thisObject + + function initialize() { + + } + + function finalize() { + + } +} \ No newline at end of file diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/Footer.js b/Projects/Superalgos/UI/Spaces/Docs-Space/Footer.js new file mode 100644 index 000000000..ae1a15040 --- /dev/null +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/Footer.js @@ -0,0 +1,16 @@ +function newSuperalgosDocsFooter() { + let thisObject = { + initialize: initialize, + finalize: finalize + } + + return thisObject + + function initialize() { + + } + + function finalize() { + + } +} \ No newline at end of file diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/MainSearchPage.js b/Projects/Superalgos/UI/Spaces/Docs-Space/MainSearchPage.js new file mode 100644 index 000000000..e4fa00871 --- /dev/null +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/MainSearchPage.js @@ -0,0 +1,16 @@ +function newSuperalgosDocsMainSearchPage() { + let thisObject = { + initialize: initialize, + finalize: finalize + } + + return thisObject + + function initialize() { + + } + + function finalize() { + + } +} \ No newline at end of file diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js b/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js new file mode 100644 index 000000000..4a10b7d43 --- /dev/null +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js @@ -0,0 +1,16 @@ +function newSuperalgosDocsSearchEngine() { + let thisObject = { + initialize: initialize, + finalize: finalize + } + + return thisObject + + function initialize() { + + } + + function finalize() { + + } +} \ No newline at end of file diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/SearchResultsPage.js b/Projects/Superalgos/UI/Spaces/Docs-Space/SearchResultsPage.js new file mode 100644 index 000000000..8cbc7a0c8 --- /dev/null +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/SearchResultsPage.js @@ -0,0 +1,16 @@ +function newSuperalgosDocsSearchResultsPage() { + let thisObject = { + initialize: initialize, + finalize: finalize + } + + return thisObject + + function initialize() { + + } + + function finalize() { + + } +} \ No newline at end of file From 89991bbd72d058d0d8313f43338ecc2063b6e530 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 31 Dec 2020 10:26:51 +0100 Subject: [PATCH 2/3] Search Engine moved to its own page --- .../UI/Spaces/Docs-Space/DocsSpace.js | 225 ++---------------- .../UI/Spaces/Docs-Space/SearchEngine.js | 149 +++++++++++- Projects/Superalgos/UI/Utilities/Strings.js | 58 ++++- 3 files changed, 219 insertions(+), 213 deletions(-) diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index 3d2c17a84..30da657bd 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -52,13 +52,11 @@ function newSuperalgosDocSpace() { let docsSchemaDocument let menuLabelsMap = new Map() let command - let docsIndex = [] let language return thisObject function initialize() { - docsIndex = [] setupSidePanelTab() setUpContextMenu() @@ -71,6 +69,12 @@ function newSuperalgosDocSpace() { thisObject.documentPage = newSuperalgosDocsDocumentPage() thisObject.footer = newSuperalgosDocsFooter() + thisObject.searchEngine.initialize() + thisObject.mainSearchPage.initialize() + thisObject.searchResultsPage.initialize() + thisObject.documentPage.initialize() + thisObject.footer.initialize() + isInitialized = true function setupUserLanguage() { @@ -423,10 +427,7 @@ function newSuperalgosDocSpace() { appSchemaDocument = undefined docsSchemaDocument = undefined menuLabelsMap = undefined - docsIndex = undefined isInitialized = false - - } function reset() { @@ -441,60 +442,6 @@ function newSuperalgosDocSpace() { navigateTo('Superalgos', 'Topic', 'Docs In ' + languageLabel) } - function cleanTextForSearch(text) { - let result = replaceSpecialCharactersForSpaces(text) - result = result.replaceAll(' ', '') - result = result.replaceAll('s', '') - result = result.replaceAll('ing', '') - result = result.replaceAll('ed', '') - result = result.replaceAll('y', '') - result = result.replaceAll('ies', '') - return result - } - - function replaceSpecialCharactersForSpaces(text) { - let result = text - result = result.replaceAll('. ', ' ') - result = result.replaceAll(', ', ' ') - result = result.replaceAll('- ', ' ') - result = result.replaceAll('/ ', ' ') - result = result.replaceAll('_ ', ' ') - result = result.replaceAll(': ', ' ') - result = result.replaceAll('; ', ' ') - result = result.replaceAll('( ', ' ') - result = result.replaceAll(') ', ' ') - result = result.replaceAll('{ ', ' ') - result = result.replaceAll('} ', ' ') - result = result.replaceAll('[ ', ' ') - result = result.replaceAll('] ', ' ') - result = result.replaceAll('" ', ' ') - result = result.replaceAll('\\n ', ' ') - result = result.replaceAll('\\ ', ' ') - - result = result.replaceAll('.', ' ') - result = result.replaceAll(',', ' ') - result = result.replaceAll('-', ' ') - result = result.replaceAll('/', ' ') - result = result.replaceAll('_', ' ') - result = result.replaceAll(':', ' ') - result = result.replaceAll(';', ' ') - result = result.replaceAll('(', ' ') - result = result.replaceAll(')', ' ') - result = result.replaceAll('{', ' ') - result = result.replaceAll('}', ' ') - result = result.replaceAll('[', ' ') - result = result.replaceAll(']', ' ') - result = result.replaceAll('"', ' ') - result = result.replaceAll('\\n', ' ') - result = result.replaceAll("\\", ' ') - - result = result.replaceAll('@', ' ') - result = result.replaceAll(' ', ' ') - result = result.replaceAll(' ', ' ') - result = result.replaceAll(' ', ' ') - return result - } - function onKeyDown(event) { /* When an editor is on focus we will only @@ -888,149 +835,6 @@ function newSuperalgosDocSpace() { } } - function setUpSearchEngine() { - for (let j = 0; j < PROJECTS_ARRAY.length; j++) { - let project = PROJECTS_ARRAY[j] - - let documentIndex - - /* Search in Nodes */ - for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema.length; i++) { - documentIndex = { - phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. - docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema[i], - category: 'Node', - project: project - } - indexDocument(documentIndex) - docsIndex.push(documentIndex) - } - /* Search in Concepts */ - for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema.length; i++) { - documentIndex = { - phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. - docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema[i], - category: 'Concept', - project: project - } - indexDocument(documentIndex) - docsIndex.push(documentIndex) - } - /* Search in Topics */ - for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema.length; i++) { - documentIndex = { - phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. - docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema[i], - category: 'Topic', - project: project - } - indexDocument(documentIndex) - docsIndex.push(documentIndex) - } - /* Search in Workspace */ - for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.workspaceSchema.length; i++) { - documentIndex = { - phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. - docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.workspaceSchema[i], - category: 'Workspace', - project: project - } - indexDocument(documentIndex) - docsIndex.push(documentIndex) - } - } - - function indexDocument(documentIndex) { - - if (documentIndex.docsSchemaDocument === undefined) { - return - } - - if (documentIndex.docsSchemaDocument.topic !== undefined) { - let paragraph = { - style: 'Topic', - text: documentIndex.docsSchemaDocument.topic - } - indexParagraph(paragraph) - } - if (documentIndex.docsSchemaDocument.type !== undefined) { - let paragraph = { - style: 'Type', - text: documentIndex.docsSchemaDocument.type - } - indexParagraph(paragraph) - } - if (documentIndex.docsSchemaDocument.definition !== undefined) { - let paragraph = { - style: 'Definition', - text: documentIndex.docsSchemaDocument.definition.text, - translations: documentIndex.docsSchemaDocument.definition.translations - } - indexParagraph(paragraph) - indexAllTranslations(paragraph) - } - if (documentIndex.docsSchemaDocument.paragraphs !== undefined) { - for (let k = 0; k < documentIndex.docsSchemaDocument.paragraphs.length; k++) { - let paragraph = documentIndex.docsSchemaDocument.paragraphs[k] - indexParagraph(paragraph) - indexAllTranslations(paragraph) - } - } - - function indexAllTranslations(paragraph) { - if (paragraph.translations === undefined) { return } - for (i = 0; i < paragraph.translations.length; i++) { - let translation = paragraph.translations[i] - translation.style = paragraph.style - indexParagraph(translation) - } - } - - function indexParagraph(paragraph) { - if (paragraph.text === undefined) { - return - } - if (paragraph.style === undefined) { - return - } - - let text = paragraph.text.toLowerCase() - let style = paragraph.style.toLowerCase() - let stylePhraseCount = documentIndex.phraseCount[style] - - if (stylePhraseCount === undefined) { - stylePhraseCount = new Map() - documentIndex.phraseCount[style] = stylePhraseCount - } - - text = replaceSpecialCharactersForSpaces(text) - - let splittedText = text.split(' ') - - for (n = 0; n < splittedText.length; n++) { - let phrase = '' - for (let m = 0; m < 10; m++) { - let word = splittedText[n + m] - if (word !== undefined) { - if (m === 0) { - phrase = phrase + word - } else { - phrase = phrase + ' ' + word - } - let key = cleanTextForSearch(phrase) - - let thisPhraseCount = stylePhraseCount.get(key) - if (thisPhraseCount === undefined) { thisPhraseCount = 0 } - thisPhraseCount++ - - stylePhraseCount.set(key, thisPhraseCount) - } - } - } - } - } - } - function onClosing() { objectBeingRendered = undefined thisObject.isVisible = false @@ -1259,9 +1063,8 @@ function newSuperalgosDocSpace() { } if (command.indexOf('Docs.Reindex') !== 0 && command.indexOf('docs.reindex') !== 0) { return 'Not Reindex Command' } - docsIndex = [] setUpWorkspaceSchemas() - setUpSearchEngine() + thisObject.searchEngine.setUpSearchEngine() renderCommandResultsPage(["Succesfully rebuild the search engine indexes."]) } @@ -1507,24 +1310,24 @@ function newSuperalgosDocSpace() { buildHTML() function buildResultsArray() { - for (let i = 0; i < docsIndex.length; i++) { - let documentIndex = docsIndex[i] + for (let i = 0; i < thisObject.searchEngine.docsIndex.length; i++) { + let documentIndex = thisObject.searchEngine.docsIndex[i] let documentPoints = 0 for (const style in documentIndex.phraseCount) { - let key = cleanTextForSearch(command.toLowerCase()) + let key = UI.projects.superalgos.utilities.strings.cleanTextOfCommonWordEndings(command.toLowerCase()) let thisPhraseCount = documentIndex.phraseCount[style].get(key) if (thisPhraseCount === undefined) { thisPhraseCount = 0 } if (documentIndex.docsSchemaDocument.type !== undefined) { - if (key === cleanTextForSearch(documentIndex.docsSchemaDocument.type.toLowerCase())) { + if (key === UI.projects.superalgos.utilities.strings.cleanTextOfCommonWordEndings(documentIndex.docsSchemaDocument.type.toLowerCase())) { documentPoints = documentPoints + thisPhraseCount * 100 } } if (documentIndex.docsSchemaDocument.topic !== undefined) { - if (key === cleanTextForSearch(documentIndex.docsSchemaDocument.topic.toLowerCase())) { + if (key === UI.projects.superalgos.utilities.strings.cleanTextOfCommonWordEndings(documentIndex.docsSchemaDocument.topic.toLowerCase())) { documentPoints = documentPoints + thisPhraseCount * 200 } } @@ -4025,9 +3828,9 @@ function newSuperalgosDocSpace() { if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return } if (UI.projects.superalgos.spaces.designSpace.workspace.isInitialized === false) { return } - if (docsIndex && docsIndex.length === 0) { + if (thisObject.searchEngine.docsIndex && thisObject.searchEngine.docsIndex.length === 0) { setUpWorkspaceSchemas() - setUpSearchEngine() + thisObject.searchEngine.setUpSearchEngine() } } } diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js b/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js index 4a10b7d43..d2c52eea5 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js @@ -1,5 +1,7 @@ function newSuperalgosDocsSearchEngine() { let thisObject = { + docsIndex: undefined, + setUpSearchEngine: setUpSearchEngine, initialize: initialize, finalize: finalize } @@ -7,10 +9,155 @@ function newSuperalgosDocsSearchEngine() { return thisObject function initialize() { - + thisObject.docsIndex = [] } function finalize() { + thisObject.docsIndex = undefined + } + function setUpSearchEngine() { + thisObject.docsIndex = [] + + for (let j = 0; j < PROJECTS_ARRAY.length; j++) { + let project = PROJECTS_ARRAY[j] + + let documentIndex + + /* Search in Nodes */ + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema.length; i++) { + documentIndex = { + phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. + docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema[i], + category: 'Node', + project: project + } + indexDocument(documentIndex) + thisObject.docsIndex.push(documentIndex) + } + /* Search in Concepts */ + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema.length; i++) { + documentIndex = { + phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. + docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema[i], + category: 'Concept', + project: project + } + indexDocument(documentIndex) + thisObject.docsIndex.push(documentIndex) + } + /* Search in Topics */ + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema.length; i++) { + documentIndex = { + phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. + docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema[i], + category: 'Topic', + project: project + } + indexDocument(documentIndex) + thisObject.docsIndex.push(documentIndex) + } + /* Search in Workspace */ + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.workspaceSchema.length; i++) { + documentIndex = { + phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. + docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.workspaceSchema[i], + category: 'Workspace', + project: project + } + indexDocument(documentIndex) + thisObject.docsIndex.push(documentIndex) + } + } + + function indexDocument(documentIndex) { + + if (documentIndex.docsSchemaDocument === undefined) { + return + } + + if (documentIndex.docsSchemaDocument.topic !== undefined) { + let paragraph = { + style: 'Topic', + text: documentIndex.docsSchemaDocument.topic + } + indexParagraph(paragraph) + } + if (documentIndex.docsSchemaDocument.type !== undefined) { + let paragraph = { + style: 'Type', + text: documentIndex.docsSchemaDocument.type + } + indexParagraph(paragraph) + } + if (documentIndex.docsSchemaDocument.definition !== undefined) { + let paragraph = { + style: 'Definition', + text: documentIndex.docsSchemaDocument.definition.text, + translations: documentIndex.docsSchemaDocument.definition.translations + } + indexParagraph(paragraph) + indexAllTranslations(paragraph) + } + if (documentIndex.docsSchemaDocument.paragraphs !== undefined) { + for (let k = 0; k < documentIndex.docsSchemaDocument.paragraphs.length; k++) { + let paragraph = documentIndex.docsSchemaDocument.paragraphs[k] + indexParagraph(paragraph) + indexAllTranslations(paragraph) + } + } + + function indexAllTranslations(paragraph) { + if (paragraph.translations === undefined) { return } + for (i = 0; i < paragraph.translations.length; i++) { + let translation = paragraph.translations[i] + translation.style = paragraph.style + indexParagraph(translation) + } + } + + function indexParagraph(paragraph) { + if (paragraph.text === undefined) { + return + } + if (paragraph.style === undefined) { + return + } + + let text = paragraph.text.toLowerCase() + let style = paragraph.style.toLowerCase() + let stylePhraseCount = documentIndex.phraseCount[style] + + if (stylePhraseCount === undefined) { + stylePhraseCount = new Map() + documentIndex.phraseCount[style] = stylePhraseCount + } + + text = UI.projects.superalgos.utilities.strings.replaceSpecialCharactersForSpaces(text) + + let splittedText = text.split(' ') + + for (n = 0; n < splittedText.length; n++) { + let phrase = '' + for (let m = 0; m < 10; m++) { + let word = splittedText[n + m] + if (word !== undefined) { + if (m === 0) { + phrase = phrase + word + } else { + phrase = phrase + ' ' + word + } + let key = UI.projects.superalgos.utilities.strings.cleanTextOfCommonWordEndings(phrase) + + let thisPhraseCount = stylePhraseCount.get(key) + if (thisPhraseCount === undefined) { thisPhraseCount = 0 } + thisPhraseCount++ + + stylePhraseCount.set(key, thisPhraseCount) + } + } + } + } + } } } \ No newline at end of file diff --git a/Projects/Superalgos/UI/Utilities/Strings.js b/Projects/Superalgos/UI/Utilities/Strings.js index 66f61f02b..92d87ea65 100644 --- a/Projects/Superalgos/UI/Utilities/Strings.js +++ b/Projects/Superalgos/UI/Utilities/Strings.js @@ -1,7 +1,9 @@ function newSuperalgosUtilitiesStrings() { thisObject = { fromCamelCaseToUpperWithSpaces: fromCamelCaseToUpperWithSpaces, - isCamelCase: isCamelCase + isCamelCase: isCamelCase, + replaceSpecialCharactersForSpaces: replaceSpecialCharactersForSpaces, + cleanTextOfCommonWordEndings: cleanTextOfCommonWordEndings } return thisObject @@ -53,4 +55,58 @@ function newSuperalgosUtilitiesStrings() { } return true } + + function replaceSpecialCharactersForSpaces(text) { + let result = text + result = result.replaceAll('. ', ' ') + result = result.replaceAll(', ', ' ') + result = result.replaceAll('- ', ' ') + result = result.replaceAll('/ ', ' ') + result = result.replaceAll('_ ', ' ') + result = result.replaceAll(': ', ' ') + result = result.replaceAll('; ', ' ') + result = result.replaceAll('( ', ' ') + result = result.replaceAll(') ', ' ') + result = result.replaceAll('{ ', ' ') + result = result.replaceAll('} ', ' ') + result = result.replaceAll('[ ', ' ') + result = result.replaceAll('] ', ' ') + result = result.replaceAll('" ', ' ') + result = result.replaceAll('\\n ', ' ') + result = result.replaceAll('\\ ', ' ') + + result = result.replaceAll('.', ' ') + result = result.replaceAll(',', ' ') + result = result.replaceAll('-', ' ') + result = result.replaceAll('/', ' ') + result = result.replaceAll('_', ' ') + result = result.replaceAll(':', ' ') + result = result.replaceAll(';', ' ') + result = result.replaceAll('(', ' ') + result = result.replaceAll(')', ' ') + result = result.replaceAll('{', ' ') + result = result.replaceAll('}', ' ') + result = result.replaceAll('[', ' ') + result = result.replaceAll(']', ' ') + result = result.replaceAll('"', ' ') + result = result.replaceAll('\\n', ' ') + result = result.replaceAll("\\", ' ') + + result = result.replaceAll('@', ' ') + result = result.replaceAll(' ', ' ') + result = result.replaceAll(' ', ' ') + result = result.replaceAll(' ', ' ') + return result + } + + function cleanTextOfCommonWordEndings(text) { + let result = UI.projects.superalgos.utilities.strings.replaceSpecialCharactersForSpaces(text) + result = result.replaceAll(' ', '') + result = result.replaceAll('s', '') + result = result.replaceAll('ing', '') + result = result.replaceAll('ed', '') + result = result.replaceAll('y', '') + result = result.replaceAll('ies', '') + return result + } } \ No newline at end of file From 1c138d5f8b776b700f00219f6b16e643ee06e50c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 31 Dec 2020 11:10:48 +0100 Subject: [PATCH 3/3] Main Search Page and Footer moved to own page --- .../UI/Spaces/Docs-Space/DocsSpace.js | 97 ++++--------------- .../Superalgos/UI/Spaces/Docs-Space/Footer.js | 46 +++++++++ .../UI/Spaces/Docs-Space/MainSearchPage.js | 11 +++ 3 files changed, 78 insertions(+), 76 deletions(-) diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index 30da657bd..13fe41e75 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -9,6 +9,7 @@ function newSuperalgosDocSpace() { searchResultsPage: undefined, footer: undefined, documentPage: undefined, + language: undefined, changeLanguage: changeLanguage, openSpaceAreaAndNavigateTo: openSpaceAreaAndNavigateTo, navigateTo: navigateTo, @@ -52,7 +53,6 @@ function newSuperalgosDocSpace() { let docsSchemaDocument let menuLabelsMap = new Map() let command - let language return thisObject @@ -82,10 +82,10 @@ function newSuperalgosDocSpace() { Getting the used preferred languague */ if (window.localStorage.getItem('Docs Language') !== null && window.localStorage.getItem('Docs Language') !== undefined && window.localStorage.getItem('Docs Language') !== 'undefined') { - language = window.localStorage.getItem('Docs Language') + UI.projects.superalgos.spaces.docsSpace.language = window.localStorage.getItem('Docs Language') } else { window.localStorage.setItem('Docs Language', DEFAULT_LANGUAGE) - language = DEFAULT_LANGUAGE + UI.projects.superalgos.spaces.docsSpace.language = DEFAULT_LANGUAGE } } @@ -436,9 +436,9 @@ function newSuperalgosDocSpace() { } function changeLanguage(pLanguage) { - language = pLanguage - window.localStorage.setItem('Docs Language', language) - let languageLabel = UI.projects.superalgos.utilities.languages.getLaguageLabel(language) + UI.projects.superalgos.spaces.docsSpace.language = pLanguage + window.localStorage.setItem('Docs Language', UI.projects.superalgos.spaces.docsSpace.language) + let languageLabel = UI.projects.superalgos.utilities.languages.getLaguageLabel(UI.projects.superalgos.spaces.docsSpace.language) navigateTo('Superalgos', 'Topic', 'Docs In ' + languageLabel) } @@ -507,7 +507,7 @@ function newSuperalgosDocSpace() { /* Deleting paragarphs is only possible in the default language. */ - if (language === DEFAULT_LANGUAGE) { + if (UI.projects.superalgos.spaces.docsSpace.language === DEFAULT_LANGUAGE) { docsSchemaDocument.paragraphs.splice(selectededitableParagraphIndex, 1) if (docsSchemaDocument.paragraphs.length === 0) { let newParagraph = { @@ -522,7 +522,7 @@ function newSuperalgosDocSpace() { /* Adding paragarphs is only possible in the default language. */ - if (language === DEFAULT_LANGUAGE) { + if (UI.projects.superalgos.spaces.docsSpace.language === DEFAULT_LANGUAGE) { /* We will update the one paragraph we have and we will add the rest. */ @@ -762,7 +762,9 @@ function newSuperalgosDocSpace() { function onOpening() { thisObject.isVisible = true if (objectBeingRendered === undefined) { - renderSearchPage() + thisObject.mainSearchPage.render() + detectEnterOnSearchBox() + setFocusOnSearchBox() } else { navigateTo(objectBeingRendered.project, objectBeingRendered.category, objectBeingRendered.type) } @@ -840,18 +842,6 @@ function newSuperalgosDocSpace() { thisObject.isVisible = false } - function renderSearchPage() { - let HTML = '' - HTML = HTML + '
' - HTML = HTML + '
' - HTML = HTML + '
' - HTML = HTML + '
' - let docsContentDiv = document.getElementById('docs-content-div') - docsContentDiv.innerHTML = HTML + addFooter() - detectEnterOnSearchBox() - setFocusOnSearchBox() - } - function detectCommands() { if (checkHelpCommand() === undefined) { return } @@ -933,7 +923,7 @@ function newSuperalgosDocSpace() { } if (command.indexOf('Docs.Add') !== 0 && command.indexOf('docs.add') !== 0) { return 'Not Add Command' } - if (language !== DEFAULT_LANGUAGE) { + if (UI.projects.superalgos.spaces.docsSpace.language !== DEFAULT_LANGUAGE) { navigateTo('Superalgos', 'Topic', 'Docs Error Only In English', 'Anchor Only In English') return } @@ -998,7 +988,7 @@ function newSuperalgosDocSpace() { } if (command.indexOf('Docs.Delete') !== 0 && command.indexOf('docs.delete') !== 0) { return 'Not Delete Command' } - if (language !== DEFAULT_LANGUAGE) { + if (UI.projects.superalgos.spaces.docsSpace.language !== DEFAULT_LANGUAGE) { navigateTo('Superalgos', 'Topic', 'Docs Error Only In English', 'Anchor Only In English') return } @@ -1295,7 +1285,7 @@ function newSuperalgosDocSpace() { HTML = HTML + '' let docsContentDiv = document.getElementById('docs-content-div') - docsContentDiv.innerHTML = HTML + addFooter() + docsContentDiv.innerHTML = HTML + UI.projects.superalgos.spaces.docsSpace.footer.addFooter() detectEnterOnSearchBox() setFocusOnSearchBox() @@ -1565,7 +1555,7 @@ function newSuperalgosDocSpace() { } let docsContentDiv = document.getElementById('docs-content-div') - docsContentDiv.innerHTML = HTML + addFooter() + docsContentDiv.innerHTML = HTML + UI.projects.superalgos.spaces.docsSpace.footer.addFooter() detectEnterOnSearchBox() setFocusOnSearchBox() @@ -1789,7 +1779,7 @@ function newSuperalgosDocSpace() { Here we inject the HTML we built into the DOM at the Docs Space Div. */ let docsContentDiv = document.getElementById('docs-content-div') - docsContentDiv.innerHTML = HTML + addFooter() + docsContentDiv.innerHTML = HTML + UI.projects.superalgos.spaces.docsSpace.footer.addFooter() console.log(docsContentDiv.innerHTML) @@ -3178,51 +3168,6 @@ function newSuperalgosDocSpace() { return HTML } - function addFooter() { - let languageLabel = UI.projects.superalgos.utilities.languages.getLaguageLabel(language) - - let HTML = '' - - HTML = HTML + '' // Container Ends - - return HTML - } - function addWarningIfTranslationIsOutdated(paragraph) { if (paragraph === undefined) { return '' } if (paragraph.updated === undefined) { return '' } @@ -3231,7 +3176,7 @@ function newSuperalgosDocSpace() { for (let i = 0; i < paragraph.translations.length; i++) { let translation = paragraph.translations[i] if (translation.updated === undefined) { continue } - if (translation.language === language) { + if (translation.language === UI.projects.superalgos.spaces.docsSpace.language) { if (paragraph.updated < translation.updated) { return '' } else { @@ -3248,13 +3193,13 @@ function newSuperalgosDocSpace() { if (paragraph.translations.length === 0) { return paragraph.text } for (let i = 0; i < paragraph.translations.length; i++) { let translation = paragraph.translations[i] - if (translation.language === language) { return translation.text } + if (translation.language === UI.projects.superalgos.spaces.docsSpace.language) { return translation.text } } return paragraph.text } function setTextBasedOnLanguage(paragraph, text) { - if (language === DEFAULT_LANGUAGE) { + if (UI.projects.superalgos.spaces.docsSpace.language === DEFAULT_LANGUAGE) { if (paragraph.text !== text) { paragraph.text = text paragraph.updated = (new Date()).valueOf() @@ -3274,7 +3219,7 @@ function newSuperalgosDocSpace() { } for (let i = 0; i < paragraph.translations.length; i++) { let translation = paragraph.translations[i] - if (translation.language === language) { + if (translation.language === UI.projects.superalgos.spaces.docsSpace.language) { if (translation.text !== text) { translation.text = text translation.updated = (new Date()).valueOf() @@ -3283,7 +3228,7 @@ function newSuperalgosDocSpace() { } } let translation = { - language: language, + language: UI.projects.superalgos.spaces.docsSpace.language, text: text, updated: (new Date()).valueOf() } diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/Footer.js b/Projects/Superalgos/UI/Spaces/Docs-Space/Footer.js index ae1a15040..8c9626d2b 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/Footer.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/Footer.js @@ -1,5 +1,6 @@ function newSuperalgosDocsFooter() { let thisObject = { + addFooter: addFooter, initialize: initialize, finalize: finalize } @@ -13,4 +14,49 @@ function newSuperalgosDocsFooter() { function finalize() { } + + function addFooter() { + let languageLabel = UI.projects.superalgos.utilities.languages.getLaguageLabel(UI.projects.superalgos.spaces.docsSpace.language) + + let HTML = '' + + HTML = HTML + '' // Container Ends + + return HTML + } } \ No newline at end of file diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/MainSearchPage.js b/Projects/Superalgos/UI/Spaces/Docs-Space/MainSearchPage.js index e4fa00871..4f895631a 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/MainSearchPage.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/MainSearchPage.js @@ -1,5 +1,6 @@ function newSuperalgosDocsMainSearchPage() { let thisObject = { + render: render, initialize: initialize, finalize: finalize } @@ -13,4 +14,14 @@ function newSuperalgosDocsMainSearchPage() { function finalize() { } + + function render() { + let HTML = '' + HTML = HTML + '
' + HTML = HTML + '
' + HTML = HTML + '
' + HTML = HTML + '
' + let docsContentDiv = document.getElementById('docs-content-div') + docsContentDiv.innerHTML = HTML + UI.projects.superalgos.spaces.docsSpace.footer.addFooter() + } } \ No newline at end of file