From 10ba789cfccdaedbb0d3551feb74d07c875d9eba Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 22 Dec 2020 09:38:30 +0100 Subject: [PATCH] Ordered Index done --- .../UI/Spaces/Docs-Space/DocsSpace.js | 43 ++++++++++++++----- UI/AppPostLoader.js | 2 +- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index b1c241b2a..c74a79bcf 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -905,7 +905,7 @@ function newSuperalgosDocSpace() { function addTopic(project, topic, type, pageNumber) { let template = { topic: topic, - pageNumber: pageNumber, + pageNumber: pageNumber, type: type, definition: "Write here the definition of this Concept.", paragraphs: [ @@ -920,7 +920,7 @@ function newSuperalgosDocSpace() { return } SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema.push(template) - SCHEMAS_BY_PROJECT.get(project).map.docsTopicSchema.set(topic + ' ' + type, template) + SCHEMAS_BY_PROJECT.get(project).map.docsTopicSchema.set(type, template) navigateTo('Topic', type, project) } } @@ -1408,24 +1408,47 @@ function newSuperalgosDocSpace() { renderParagraph(paragraph, key) paragraphIndex++ + let orderedIndexArray = [] let schemaArray = SCHEMAS_BY_PROJECT.get(objectBeingRendered.project).array.docsTopicSchema for (let i = 0; i < schemaArray.length; i++) { let arrayItem = schemaArray[i] if (arrayItem.topic === schemaDocument.topic) { - - paragraph - key = 'auto-generated-index-paragraph-' + paragraphIndex - paragraph = { - style: "Title", - text: "" + arrayItem.pageNumber + '. ' + arrayItem.type + "" + let itemAdded = false + if (orderedIndexArray.length === 0) { + orderedIndexArray.push(arrayItem) + itemAdded = true + } else { + for (let j = 0; j < orderedIndexArray.length; j++) { + let orderedArrayItem = orderedIndexArray[j] + if (arrayItem.pageNumber < orderedArrayItem.pageNumber) { + orderedIndexArray.splice(j, 0, arrayItem) + itemAdded = true + break + } + } } - paragraphIndex++ - HTML = HTML + '

' + paragraph.text + '

' + if (itemAdded === false) { + orderedIndexArray.push(arrayItem) + } + } } + + for (let i = 0; i < orderedIndexArray.length; i++) { + let arrayItem = orderedIndexArray[i] + paragraph + key = 'auto-generated-index-paragraph-' + paragraphIndex + paragraph = { + style: "Title", + text: "" + arrayItem.pageNumber + '. ' + arrayItem.type + "" + } + paragraphIndex++ + HTML = HTML + '

' + paragraph.text + '

' + } } + function addContent() { HTML = HTML + '
' if (schemaDocument.paragraphs !== undefined) { diff --git a/UI/AppPostLoader.js b/UI/AppPostLoader.js index 3d4037091..ede56fa5a 100644 --- a/UI/AppPostLoader.js +++ b/UI/AppPostLoader.js @@ -122,7 +122,7 @@ function newAppPostLoader() { for (let j = 0; j < schemas.array.docsTopicSchema.length; j++) { let schemaDocument = schemas.array.docsTopicSchema[j] - let key = schemaDocument.topic + ' ' + schemaDocument.type + let key = schemaDocument.type schemas.map.docsTopicSchema.set(key, schemaDocument) } } catch (err) {