Function to order an array of pages generalized and moved to utilities
This commit is contained in:
1 parent
030db26ae2
commit
9289b6eb10
11 files changed
+246
-70
No files matched your search
+44
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"topic": "Docs Commands Errors",
|
||||
"pageNumber": "4",
|
||||
"type": "Docs Error Category Not Valid",
|
||||
"definition": {
|
||||
"text": "While executing a command, you might receive different types of error messanges. These are described below. ",
|
||||
"updated": 1609159174480
|
||||
},
|
||||
"paragraphs": [
|
||||
{
|
||||
"style": "Anchor",
|
||||
"text": "Anchor Category Not Valid"
|
||||
},
|
||||
{
|
||||
"style": "Error",
|
||||
"text": "The category you have specidied is not a valid Docs Page Category.",
|
||||
"updated": 1609160924575
|
||||
},
|
||||
{
|
||||
"style": "Success",
|
||||
"text": "Check which are the valid categories at the command's page.",
|
||||
"updated": 1610382670261
|
||||
},
|
||||
{
|
||||
"style": "Title",
|
||||
"text": "Applies to",
|
||||
"updated": 1609162854123
|
||||
},
|
||||
{
|
||||
"style": "List",
|
||||
"text": "Docs Goto Command",
|
||||
"updated": 1609177229589
|
||||
},
|
||||
{
|
||||
"style": "List",
|
||||
"text": "Docs Add Command",
|
||||
"updated": 1609180006853
|
||||
},
|
||||
{
|
||||
"style": "List",
|
||||
"text": "Docs Delete Command"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"topic": "Docs Commands Messages",
|
||||
"pageNumber": "3.1",
|
||||
"type": "Docs Message Repagination Succeed",
|
||||
"definition": {
|
||||
"text": "The docs.repaginate command you executed successfuly.",
|
||||
"updated": 1610292270590
|
||||
},
|
||||
"paragraphs": [
|
||||
{
|
||||
"style": "Important",
|
||||
"text": "To complete this procedure, you need to manually delete from disk all the files of the Topic / Tutorial you just repaginated, and execute the Docs Save Command to save the in-memory updated pages.",
|
||||
"updated": 1610292163004
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"topic": "Vaina",
|
||||
"pageNumber": "1",
|
||||
"pageNumber": 1,
|
||||
"type": "Vaina 1",
|
||||
"definition": {
|
||||
"text": "Write here a summary for this topic page."
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"topic": "Vaina",
|
||||
"pageNumber": "2",
|
||||
"pageNumber": 2,
|
||||
"type": "Vaina 2",
|
||||
"definition": {
|
||||
"text": "Write here a summary for this topic page."
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"topic": "Vaina",
|
||||
"pageNumber": "3",
|
||||
"pageNumber": 3,
|
||||
"type": "Vaina 3",
|
||||
"definition": {
|
||||
"text": "Write here a summary for this topic page."
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"topic": "Vaina",
|
||||
"pageNumber": "4",
|
||||
"pageNumber": 4,
|
||||
"type": "Vaina 4",
|
||||
"definition": {
|
||||
"text": "Write here a summary for this topic page."
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"topic": "Vaina",
|
||||
"pageNumber": "5",
|
||||
"pageNumber": 5,
|
||||
"type": "Vaina 5",
|
||||
"definition": {
|
||||
"text": "Write here a summary for this topic page."
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"topic": "Vaina",
|
||||
"pageNumber": "2.5",
|
||||
"pageNumber": 6,
|
||||
"type": "Vaina 2.5",
|
||||
"definition": {
|
||||
"text": "Write here a summary for this topic page."
|
||||
@@ -85,6 +85,7 @@ function newSuperalgosDocsCommmandInterface() {
|
||||
if (checkGotoCommand() === undefined) { return }
|
||||
if (checkAddCommand() === undefined) { return }
|
||||
if (checkDeleteCommand() === undefined) { return }
|
||||
if (checkRepaginateCommand() === undefined) { return }
|
||||
if (checkUReIndexCommand() === undefined) { return }
|
||||
if (checkUSaveCommand() === undefined) { return }
|
||||
|
||||
@@ -317,6 +318,68 @@ function newSuperalgosDocsCommmandInterface() {
|
||||
}
|
||||
}
|
||||
|
||||
function checkRepaginateCommand() {
|
||||
if (UI.projects.superalgos.spaces.docsSpace.commandInterface.command.toLowerCase() === 'docs.help docs.repaginate') {
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Repaginate Command')
|
||||
return
|
||||
}
|
||||
if (UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf('Docs.Repaginate') !== 0 && UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf('docs.repaginate') !== 0) { return 'Not Repaginate Command' }
|
||||
|
||||
let splittedCommand = UI.projects.superalgos.spaces.docsSpace.commandInterface.command.split(': ')
|
||||
if (splittedCommand[1] === undefined) {
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Missing Colon', 'Anchor Missing Colon')
|
||||
return
|
||||
}
|
||||
let primaryCommand = splittedCommand[0]
|
||||
let secondaryCommand = splittedCommand[1]
|
||||
|
||||
let splittedPrimaryCommand = primaryCommand.split(' ')
|
||||
|
||||
if (splittedPrimaryCommand[0].toLowerCase() === 'docs.repaginate') {
|
||||
if (splittedPrimaryCommand[2] !== 'from') {
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Missing From', 'Anchor Missing From')
|
||||
return
|
||||
}
|
||||
|
||||
if (splittedPrimaryCommand.length < 4) {
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Too Few Parameters', 'Anchor Too Few Paramenters')
|
||||
return
|
||||
}
|
||||
|
||||
if (secondaryCommand === '') {
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Category Not Valid', 'Anchor Category Not Valid')
|
||||
return
|
||||
}
|
||||
|
||||
switch (splittedPrimaryCommand[1].toLowerCase()) {
|
||||
case 'node': {
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Category Not Valid', 'Anchor Category Not Valid')
|
||||
return
|
||||
}
|
||||
case 'concept': {
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Category Not Valid', 'Anchor Category Not Valid')
|
||||
return
|
||||
}
|
||||
case 'topic': {
|
||||
repaginate(splittedPrimaryCommand[3], 'Topic', secondaryCommand)
|
||||
return
|
||||
}
|
||||
case 'tutorial': {
|
||||
repaginate(splittedPrimaryCommand[3], 'Tutorial', secondaryCommand)
|
||||
return
|
||||
}
|
||||
case 'book': {
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Category Not Valid', 'Anchor Category Not Valid')
|
||||
return
|
||||
}
|
||||
default: {
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Category Not Valid', 'Anchor Category Not Valid')
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkUReIndexCommand() {
|
||||
if (UI.projects.superalgos.spaces.docsSpace.commandInterface.command.toLowerCase() === 'docs.help docs.reindex') {
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Reindex Command')
|
||||
@@ -327,10 +390,10 @@ function newSuperalgosDocsCommmandInterface() {
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Message Reindexing Started')
|
||||
setTimeout(startReindexingProcess, 100)
|
||||
|
||||
function startReindexingProcess(){
|
||||
function startReindexingProcess() {
|
||||
UI.projects.superalgos.spaces.docsSpace.setUpWorkspaceSchemas()
|
||||
UI.projects.superalgos.spaces.docsSpace.searchEngine.setUpSearchEngine()
|
||||
|
||||
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Message Reindexing Succeed')
|
||||
}
|
||||
}
|
||||
@@ -475,6 +538,49 @@ function newSuperalgosDocsCommmandInterface() {
|
||||
}
|
||||
}
|
||||
|
||||
function repaginate(project, category, query) {
|
||||
if (SCHEMAS_BY_PROJECT.get(project) === undefined) {
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Project Does Not Exist', 'Anchor Project Does Not Exist')
|
||||
return
|
||||
}
|
||||
|
||||
let docsSchema
|
||||
switch (category) {
|
||||
case 'Topic': {
|
||||
docsSchema = SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema
|
||||
break
|
||||
}
|
||||
case 'Tutorial': {
|
||||
docsSchema = SCHEMAS_BY_PROJECT.get(project).array.docsTutorialSchema
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
let pageNumber = 1
|
||||
for (let i = 0; i < docsSchema.length; i++) {
|
||||
schemaDocument = docsSchema[i]
|
||||
switch (category) {
|
||||
case 'Topic': {
|
||||
if (schemaDocument.topic === query) {
|
||||
schemaDocument.pageNumber = pageNumber
|
||||
pageNumber++
|
||||
schemaDocument.updated = true
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'Tutorial': {
|
||||
if (schemaDocument.tutorial === query) {
|
||||
schemaDocument.pageNumber = pageNumber
|
||||
pageNumber++
|
||||
schemaDocument.updated = true
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Message Repagination Succeed')
|
||||
}
|
||||
|
||||
function addNode(project, type) {
|
||||
let template = {
|
||||
created: true,
|
||||
|
||||
@@ -167,9 +167,11 @@ function newSuperalgosDocsDocumentPage() {
|
||||
|
||||
if (UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.category === 'Topic') {
|
||||
|
||||
buildOrderedTopicPageIndex(thisObject.docsSchemaDocument.topic)
|
||||
|
||||
|
||||
orderedTopicPageIndexArray = UI.projects.superalgos.utilities.docs.buildOrderedPageIndex(
|
||||
UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project,
|
||||
'Topic',
|
||||
thisObject.docsSchemaDocument.topic
|
||||
)
|
||||
|
||||
/* Topic Title
|
||||
|
||||
@@ -192,7 +194,11 @@ function newSuperalgosDocsDocumentPage() {
|
||||
|
||||
if (UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.category === 'Tutorial') {
|
||||
|
||||
buildOrderedTutorialPageIndex(thisObject.docsSchemaDocument.tutorial)
|
||||
orderedTutorialPageIndexArray = UI.projects.superalgos.utilities.docs.buildOrderedPageIndex(
|
||||
UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project,
|
||||
'Tutorial',
|
||||
thisObject.docsSchemaDocument.tutorial
|
||||
)
|
||||
|
||||
/* Tutorial Title
|
||||
titleLabel = thisObject.docsSchemaDocument.tutorial + ' Tutorial Navigation'
|
||||
@@ -273,34 +279,6 @@ function newSuperalgosDocsDocumentPage() {
|
||||
|
||||
}
|
||||
|
||||
function buildOrderedTopicPageIndex(topic) {
|
||||
orderedTopicPageIndexArray = []
|
||||
let schemaArray = SCHEMAS_BY_PROJECT.get(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project).array.docsTopicSchema
|
||||
for (let i = 0; i < schemaArray.length; i++) {
|
||||
let arrayItem = schemaArray[i]
|
||||
|
||||
if (arrayItem.topic === topic) {
|
||||
let itemAdded = false
|
||||
if (orderedTopicPageIndexArray.length === 0) {
|
||||
orderedTopicPageIndexArray.push(arrayItem)
|
||||
itemAdded = true
|
||||
} else {
|
||||
for (let j = 0; j < orderedTopicPageIndexArray.length; j++) {
|
||||
let orderedArrayItem = orderedTopicPageIndexArray[j]
|
||||
if (Number(arrayItem.pageNumber) < Number(orderedArrayItem.pageNumber)) {
|
||||
orderedTopicPageIndexArray.splice(j, 0, arrayItem)
|
||||
itemAdded = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (itemAdded === false) {
|
||||
orderedTopicPageIndexArray.push(arrayItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function generateTopicPreviousAndNextPageNavigation() {
|
||||
let previousPage
|
||||
let nextPage
|
||||
@@ -350,34 +328,6 @@ function newSuperalgosDocsDocumentPage() {
|
||||
|
||||
}
|
||||
|
||||
function buildOrderedTutorialPageIndex(tutorial) {
|
||||
orderedTutorialPageIndexArray = []
|
||||
let schemaArray = SCHEMAS_BY_PROJECT.get(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project).array.docsTutorialSchema
|
||||
for (let i = 0; i < schemaArray.length; i++) {
|
||||
let arrayItem = schemaArray[i]
|
||||
|
||||
if (arrayItem.tutorial === tutorial) {
|
||||
let itemAdded = false
|
||||
if (orderedTutorialPageIndexArray.length === 0) {
|
||||
orderedTutorialPageIndexArray.push(arrayItem)
|
||||
itemAdded = true
|
||||
} else {
|
||||
for (let j = 0; j < orderedTutorialPageIndexArray.length; j++) {
|
||||
let orderedArrayItem = orderedTutorialPageIndexArray[j]
|
||||
if (Number(arrayItem.pageNumber) < Number(orderedArrayItem.pageNumber)) {
|
||||
orderedTutorialPageIndexArray.splice(j, 0, arrayItem)
|
||||
itemAdded = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (itemAdded === false) {
|
||||
orderedTutorialPageIndexArray.push(arrayItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function generateTutorialPreviousAndNextPageNavigation() {
|
||||
let previousPage
|
||||
let nextPage
|
||||
@@ -587,7 +537,11 @@ function newSuperalgosDocsDocumentPage() {
|
||||
|
||||
switch (category) {
|
||||
case 'Topic': {
|
||||
buildOrderedTopicPageIndex(chapterName)
|
||||
orderedTopicPageIndexArray = UI.projects.superalgos.utilities.docs.buildOrderedPageIndex(
|
||||
UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project,
|
||||
'Topic',
|
||||
chapterName
|
||||
)
|
||||
|
||||
if (orderedTopicPageIndexArray.length === 0) {
|
||||
return 'Chapter paragraph style Syntax Error. The Topic <i>' + chapterName + '</i> could not be found. Check the Docs Chapter Style Syntax. This error message will dissapear as soon as you fix the problem.'
|
||||
@@ -595,7 +549,11 @@ function newSuperalgosDocsDocumentPage() {
|
||||
break
|
||||
}
|
||||
case 'Tutorial': {
|
||||
buildOrderedTutorialPageIndex(chapterName)
|
||||
orderedTutorialPageIndexArray = UI.projects.superalgos.utilities.docs.buildOrderedPageIndex(
|
||||
UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project,
|
||||
'Tutorial',
|
||||
chapterName
|
||||
)
|
||||
|
||||
if (orderedTutorialPageIndexArray.length === 0) {
|
||||
return 'Chapter paragraph style Syntax Error. The Tutorial <i>' + chapterName + '</i> could not be found. Check the Docs Chapter Style Syntax. This error message will dissapear as soon as you fix the problem.'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
function newSuperalgosUtilitiesDocs() {
|
||||
thisObject = {
|
||||
buildOrderedPageIndex: buildOrderedPageIndex,
|
||||
addWarningIfTranslationIsOutdated: addWarningIfTranslationIsOutdated,
|
||||
getTextBasedOnLanguage: getTextBasedOnLanguage,
|
||||
setTextBasedOnLanguage: setTextBasedOnLanguage,
|
||||
@@ -26,6 +27,57 @@ function newSuperalgosUtilitiesDocs() {
|
||||
|
||||
return thisObject
|
||||
|
||||
function buildOrderedPageIndex(project, category, query) {
|
||||
let array = []
|
||||
let schemaArray
|
||||
|
||||
switch (category) {
|
||||
case 'Topic': {
|
||||
schemaArray = SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema
|
||||
break
|
||||
}
|
||||
case 'Tutorial': {
|
||||
schemaArray = SCHEMAS_BY_PROJECT.get(project).array.docsTutorialSchema
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < schemaArray.length; i++) {
|
||||
let arrayItem = schemaArray[i]
|
||||
|
||||
switch (category) {
|
||||
case 'Topic': {
|
||||
if (arrayItem.topic !== query) { continue }
|
||||
break
|
||||
}
|
||||
case 'Tutorial': {
|
||||
if (arrayItem.tutorial !== query) { continue }
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
let itemAdded = false
|
||||
if (array.length === 0) {
|
||||
array.push(arrayItem)
|
||||
itemAdded = true
|
||||
} else {
|
||||
for (let j = 0; j < array.length; j++) {
|
||||
let orderedArrayItem = array[j]
|
||||
if (Number(arrayItem.pageNumber) < Number(orderedArrayItem.pageNumber)) {
|
||||
array.splice(j, 0, arrayItem)
|
||||
itemAdded = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (itemAdded === false) {
|
||||
array.push(arrayItem)
|
||||
}
|
||||
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
||||
function addWarningIfTranslationIsOutdated(paragraph) {
|
||||
if (paragraph === undefined) { return '' }
|
||||
if (paragraph.updated === undefined) { return '' }
|
||||
|
||||
Reference in new issue
Block a user