diff --git a/src/app/components/spb2aug/spb2aug.component.ts b/src/app/components/spb2aug/spb2aug.component.ts index 8dbf3497d..9547ff279 100644 --- a/src/app/components/spb2aug/spb2aug.component.ts +++ b/src/app/components/spb2aug/spb2aug.component.ts @@ -1,14 +1,14 @@ -import { Component, OnInit } from '@angular/core'; -import { MultilinguismService } from '../../services/multilinguism.service'; -import { Grid, GridElement, Page } from '../../types'; -import { BoardService } from '../../services/board.service'; -import { Router } from '@angular/router'; -import { IndexeddbaccessService } from '../../services/indexeddbaccess.service'; -import { ConfigurationService } from '../../services/configuration.service'; -import { SafeUrl } from '@angular/platform-browser'; +import {Component, OnInit} from '@angular/core'; +import {MultilinguismService} from '../../services/multilinguism.service'; +import {FolderGoTo, Grid, GridElement, Page} from '../../types'; +import {BoardService} from '../../services/board.service'; +import {Router} from '@angular/router'; +import {IndexeddbaccessService} from '../../services/indexeddbaccess.service'; +import {ConfigurationService} from '../../services/configuration.service'; import arasaacColoredJson from '../../../assets/arasaac-color-symbol-info.json'; -import { ArasaacObject } from '../../libTypes'; -import { LayoutService } from '../../services/layout.service'; +import {ArasaacObject} from '../../libTypes'; +import {LayoutService} from '../../services/layout.service'; + declare const initSqlJs: any; @Component({ @@ -72,9 +72,11 @@ export class Spb2augComponent implements OnInit { alert(ex); return; } - this.getGridDimension(); + this.getGridDimensionFromDatabase(); this.getGridFromDatabase(); + this.fillPageWithDashboard(); this.getPolice(); + this.switchLinkedPage(); console.log(this.newGrid); this.statErrorImage(); let that = this; @@ -93,63 +95,45 @@ export class Spb2augComponent implements OnInit { * the main function where we get the grid from the database */ getGridFromDatabase() { - this.AdjustBDD(); this.getAllPagesFromDatabase(); this.setMainPage(); } - /** - * Here I have to adjust BDD because a useless element is present in table ElementReference at pageId 3 on SPB and somewhere in the base in SPS (elementType = 1) - */ - AdjustBDD(){ - const indexElementType1 = this.db.prepare('SELECT Id FROM ElementReference WHERE ElementType > 0'); - indexElementType1.step(); - const ElementType1Id = indexElementType1.getAsObject().Id; - this.db.run('DELETE FROM ElementReference WHERE Id = ' + ElementType1Id); - - const queryIndexButton = this.db.prepare("SELECT Id,ElementReferenceId FROM Button"); - while(queryIndexButton.step()){ - const indexButton = queryIndexButton.getAsObject().Id; - const indexElementReferenceId = queryIndexButton.getAsObject().ElementReferenceId; - if(indexButton+ 1 == indexElementReferenceId){ - this.db.run('DELETE FROM ElementReference WHERE Id = ' + indexButton); - this.db.run('UPDATE ElementReference SET Id = Id - 1 WHERE Id >= '+ indexButton); - this.db.run('UPDATE ElementPlacement SET ElementReferenceId = ElementReferenceId -1 WHERE ElementReferenceId >= '+ indexButton); - return; - } - } - console.log("Update finish"); - } - /** * this function import every Pages from the Database */ - getAllPagesFromDatabase(){ + getAllPagesFromDatabase() { //need to swap UniqueId and Id because folderButton target ID and we need the value UniqueId in - const buttonTable = this.db.prepare('SELECT ElementPlacement.GridPosition,ElementPlacement.GridSpan,ElementPlacement.PageLayoutId,ElementReference.BackgroundColor,ElementReference.PageId AS ERPageId,Button.UniqueId AS ButtonUniqueId,Button.BorderColor,ButtonPageLink.PageUniqueId as PageLink,Button.Label,Button.Message FROM ElementReference INNER JOIN ElementPlacement ON ElementReference.Id = ElementPlacement.ElementReferenceId LEFT JOIN Button ON ElementReference.Id = Button.Id LEFT JOIN ButtonPageLink ON Button.Id = ButtonPageLink.ButtonId WHERE ElementReference.ElementType = 0 ORDER BY ElementReference.PageId ASC,ElementPlacement.PageLayoutId'); - const queryPage = this.db.prepare('SELECT Id as uniqueId, UniqueId as id, Title FROM Page '); + const buttonTable = this.db.prepare('SELECT ElementPlacement.GridPosition,ElementPlacement.GridSpan,ElementPlacement.PageLayoutId,ElementPlacement.Visible,ElementReference.BackgroundColor,ElementReference.PageId AS ERPageId,Button.UniqueId AS ButtonUniqueId,Button.BorderColor,ButtonPageLink.PageUniqueId as PageLink,Button.Label,Button.Message FROM ElementReference INNER JOIN ElementPlacement ON ElementReference.Id = ElementPlacement.ElementReferenceId LEFT JOIN Button ON ElementReference.Id = Button.ElementReferenceId LEFT JOIN ButtonPageLink ON Button.Id = ButtonPageLink.ButtonId WHERE ElementReference.ElementType = 0 ORDER BY ElementReference.PageId ASC,ElementPlacement.PageLayoutId'); + const queryPage = this.db.prepare('SELECT Id as uniqueId, UniqueId as id, Title, PageType, GridDimension FROM Page '); buttonTable.step(); - while(queryPage.step()){ + while (queryPage.step()) { let newPage = new Page(); newPage.ID = String(queryPage.getAsObject().id); newPage.UniquePageId = String(queryPage.getAsObject().uniqueId); + newPage.PageType = queryPage.getAsObject().PageType; newPage.Name = queryPage.getAsObject().Title; - if(newPage.Name == null){ + let pageDimension = queryPage.getAsObject().GridDimension; + if (newPage.Name == null) { newPage.Name = newPage.ID; } newPage.ElementIDsList = []; const queryPageLayout = this.db.prepare('SELECT Id,PageLayoutSetting FROM PageLayout WHERE PageId =' + queryPage.getAsObject().uniqueId); - const tabNumberOfColsRowsPagelayoutid = this.getPageDimensionMax(queryPageLayout); + const tabNumberOfColsRowsPagelayoutid = this.getPageDimension(queryPageLayout, pageDimension, queryPage); queryPageLayout.free(); newPage.NumberOfRows = Number(tabNumberOfColsRowsPagelayoutid[0]); - newPage.NumberOfCols = Number(tabNumberOfColsRowsPagelayoutid[1]); + //page 2 (dashboard) will be placed between the 0 and 1 position + if (newPage.UniquePageId == "2") { + newPage.NumberOfCols = Number(tabNumberOfColsRowsPagelayoutid[1]); + } else { + newPage.NumberOfCols = Number(tabNumberOfColsRowsPagelayoutid[1]) + 1; + } this.addButtonsToPage(tabNumberOfColsRowsPagelayoutid[2], newPage, buttonTable); this.newGrid.PageList.push(newPage); //TODO la barre de chargement ici chaque page se charge une à une, tu peux incrémenter ici, n'oublie pas que je crée une page pour les "pages suivantes" du coup le max faudra le up dynamiquement va voir la fonction goDownPage() } buttonTable.free(); queryPage.free(); - } /** @@ -158,36 +142,37 @@ export class Spb2augComponent implements OnInit { * @param currentPage the page we are filling * @param buttonTable the query who contain information about buttons */ - addButtonsToPage(pageLayoutId:any, currentPage: Page, buttonTable:any ){ - let gridElement:GridElement; + addButtonsToPage(pageLayoutId: any, currentPage: Page, buttonTable: any) { + let gridElement: GridElement; let ElementPlacementPageLayoutId = buttonTable.getAsObject().PageLayoutId; let ElementReferencePageId = buttonTable.getAsObject().ERPageId; //good page but bad layoutSetting, step until LayoutId is good too - while(ElementPlacementPageLayoutId != pageLayoutId && ElementReferencePageId == currentPage.UniquePageId){ + while (ElementPlacementPageLayoutId != pageLayoutId && ElementReferencePageId == currentPage.UniquePageId) { buttonTable.step(); ElementPlacementPageLayoutId = buttonTable.getAsObject().PageLayoutId; ElementReferencePageId = buttonTable.getAsObject().ERPageId; } - //it's the great button - while(ElementPlacementPageLayoutId == pageLayoutId && ElementReferencePageId == currentPage.UniquePageId){ + while (ElementPlacementPageLayoutId == pageLayoutId && ElementReferencePageId == currentPage.UniquePageId) { let gridPosition = buttonTable.getAsObject().GridPosition; const gridSpan = buttonTable.getAsObject().GridSpan; let buttonUniqueId: string = buttonTable.getAsObject().ButtonUniqueId; - // si le bouton n'a pas d'id unique je saute ce bouton, on sait pas ce que c'est - if(buttonUniqueId != null){ + // If the button doesn't have a unique ID, I skip this button; we don't know what it is. + if (buttonUniqueId != null) { let label: string = buttonTable.getAsObject().Label; let linkFolder = buttonTable.getAsObject().PageLink; let message: string = buttonTable.getAsObject().Message; let borderColor = buttonTable.getAsObject().BorderColor; let color = buttonTable.getAsObject().BackgroundColor; + let visibilityLevel: number = buttonTable.getAsObject().Visible; + visibilityLevel = visibilityLevel == 0 ? 1 : 0; //here is button prediction, they don't got label or message, but they have ButtonUniqueId - if(label == null && message == null){ + if (label == null && message == null) { label = "Prediction"; message = "Prediction"; } @@ -206,7 +191,7 @@ export class Spb2augComponent implements OnInit { const tabResPos = gridPosition.split(','); const tabResSpan = gridSpan.split(','); - if(linkFolder !== null) { + if (linkFolder !== null) { gridElement = new GridElement(buttonUniqueId, {GoTo: String(linkFolder)}, '', @@ -218,10 +203,10 @@ export class Spb2augComponent implements OnInit { DisplayedText: (message) !== null ? message : label, VoiceText: (message) !== null ? message : label, LexicInfos: [{default: true}], - ImageID: (label) !== null? label : '', + ImageID: (label) !== null ? label : '', } ], [{ID: 'click', ActionList: [{ID: 'display', Options: []}, {ID: 'say', Options: []}]}]) - }else{ + } else { gridElement = new GridElement(buttonUniqueId, 'button', '', @@ -233,18 +218,23 @@ export class Spb2augComponent implements OnInit { DisplayedText: (message) !== null ? message : label, VoiceText: (message) !== null ? message : label, LexicInfos: [{default: true}], - ImageID: (label) !== null? label : '', + ImageID: (label) !== null ? label : '', } ], [{ID: 'click', ActionList: [{ID: 'display', Options: []}, {ID: 'say', Options: []}]}]) } - gridElement.x = Number(tabResPos[0]); + if (currentPage.UniquePageId == "2" || currentPage.PageType == 3) { + gridElement.x = Number(tabResPos[0]); + } else { + gridElement.x = Number(tabResPos[0]) + 1; + } gridElement.y = Number(tabResPos[1]); gridElement.rows = Number(tabResSpan[1]); gridElement.cols = Number(tabResSpan[0]); + gridElement.VisibilityLevel = visibilityLevel; const pathImage = this.getPathImageArsaacLibrary(label, message); this.newGrid.ImageList.push({ - ID: (label) !== null? label : '', - OriginalName: (label) !== null? label : '', + ID: (label) !== null ? label : '', + OriginalName: (label) !== null ? label : '', Path: pathImage, }); this.newGrid.ElementList.push(gridElement); @@ -253,14 +243,14 @@ export class Spb2augComponent implements OnInit { buttonTable.step(); ElementPlacementPageLayoutId = buttonTable.getAsObject().PageLayoutId; ElementReferencePageId = buttonTable.getAsObject().ERPageId; - }else{ + } else { buttonTable.step(); ElementPlacementPageLayoutId = buttonTable.getAsObject().PageLayoutId; ElementReferencePageId = buttonTable.getAsObject().ERPageId; } } // still the good page but it's the next LayoutId and we don't care about it, step until next page - while(ElementPlacementPageLayoutId != pageLayoutId && ElementReferencePageId <= currentPage.UniquePageId){ + while (ElementPlacementPageLayoutId != pageLayoutId && ElementReferencePageId <= currentPage.UniquePageId) { buttonTable.step(); ElementPlacementPageLayoutId = buttonTable.getAsObject().PageLayoutId; ElementReferencePageId = buttonTable.getAsObject().ERPageId; @@ -272,14 +262,14 @@ export class Spb2augComponent implements OnInit { * @param gridElement current gridElement I am checking if he can be filled in the page or if we need more * @param currentPage current page to take his weight and height */ - goDownPage(gridElement:GridElement, currentPage:Page){ - if(gridElement.y >= currentPage.NumberOfRows){ + goDownPage(gridElement: GridElement, currentPage: Page) { + if (gridElement.y >= currentPage.NumberOfRows) { let numeroPage = String(Math.ceil((gridElement.y + 1) / currentPage.NumberOfRows)); //test if the page already exist if yes do nothing - const indexNextPage = this.newGrid.PageList.findIndex(page => 'goDown' + currentPage.ID + numeroPage === page.ID); - if(indexNextPage == -1){ - let goDownElement = new GridElement('goDown' + currentPage.ID + numeroPage, - { GoTo: 'goDown' + currentPage.ID + numeroPage }, + const indexNextPage = this.newGrid.PageList.findIndex(page => 'goDown' + numeroPage + "Page" + currentPage.ID === page.ID); + if (indexNextPage == -1) { + let goDownElement = new GridElement('goDown' + numeroPage + "Page" + currentPage.ID, + {GoTo: 'goDown' + numeroPage + "Page" + currentPage.ID}, '', "rgb(253,251,250)", '', @@ -288,51 +278,52 @@ export class Spb2augComponent implements OnInit { { DisplayedText: 'go Down', VoiceText: '', - LexicInfos: [{ default: true }], + LexicInfos: [{default: true}], ImageID: '', } - ], [{ ID: 'click', ActionList: [{ ID: 'display', Options: [] }, { ID: 'say', Options: [] }] }]) + ], [{ID: 'click', ActionList: [{ID: 'display', Options: []}, {ID: 'say', Options: []}]}]) goDownElement.cols = 1; goDownElement.rows = 1; goDownElement.y = currentPage.NumberOfRows - 1; goDownElement.x = currentPage.NumberOfCols - 1; this.newGrid.ElementList.push(goDownElement); - if(numeroPage == "2"){ + if (numeroPage == "2") { currentPage.ElementIDsList.push(goDownElement.ID); - }else{ - let indexNextPage = this.newGrid.PageList.findIndex(page => 'goDown' + currentPage.ID + String(Number(numeroPage) - 1) === page.ID); - //si la page n'existe pas, elle devra l'être plus tard autant le faire dessuite - if(indexNextPage === -1){ + } else { + let indexNextPage = this.newGrid.PageList.findIndex(page => 'goDown' + String(Number(numeroPage) - 1) + "Page" + currentPage.ID === page.ID); + //If the page doesn't exist, create it. + if (indexNextPage === -1) { let nextPage: Page = new Page(); - nextPage.ID = 'goDown' + String(currentPage.ID)+ String(Number(numeroPage) - 1); - nextPage.UniquePageId = currentPage.UniquePageId + String(Number(numeroPage) - 1); - nextPage.Name = currentPage.Name + String(Number(numeroPage) - 1); + nextPage.ID = 'goDown' + String(Number(numeroPage) - 1) + "Page" + String(currentPage.ID); + nextPage.UniquePageId = currentPage.UniquePageId + String(Number(numeroPage) - 1) + "Page"; + nextPage.Name = currentPage.Name + String(Number(numeroPage) - 1) + "Page"; nextPage.ElementIDsList = []; nextPage.NumberOfRows = currentPage.NumberOfRows; nextPage.NumberOfCols = currentPage.NumberOfCols; + nextPage.PageType = currentPage.PageType; this.newGrid.PageList.push(nextPage); - this.newGrid.PageList[this.newGrid.PageList.length-1].ElementIDsList.push(goDownElement.ID); - }else{ + this.newGrid.PageList[this.newGrid.PageList.length - 1].ElementIDsList.push(goDownElement.ID); + } else { this.newGrid.PageList[indexNextPage].ElementIDsList.push(goDownElement.ID); } } - //la page suivante let nextPage: Page = new Page(); - nextPage.ID = 'goDown' + String(currentPage.ID)+ String(numeroPage); - nextPage.UniquePageId = currentPage.UniquePageId + numeroPage; - nextPage.Name = currentPage.Name + numeroPage; + nextPage.ID = 'goDown' + String(numeroPage) + "Page" + String(currentPage.ID); + nextPage.UniquePageId = currentPage.UniquePageId + numeroPage + "Page"; + nextPage.Name = currentPage.Name + numeroPage + "Page"; nextPage.ElementIDsList = []; nextPage.NumberOfRows = currentPage.NumberOfRows; nextPage.NumberOfCols = currentPage.NumberOfCols; gridElement.y = gridElement.y % currentPage.NumberOfRows; nextPage.ElementIDsList.push(gridElement.ID); + nextPage.PageType = currentPage.PageType; this.newGrid.PageList.push(nextPage); - }else{ + } else { + gridElement.y = gridElement.y % currentPage.NumberOfRows; this.newGrid.PageList[indexNextPage].ElementIDsList.push(gridElement.ID); } - } - else{ + } else { currentPage.ElementIDsList.push(gridElement.ID); } } @@ -340,16 +331,16 @@ export class Spb2augComponent implements OnInit { /** * function after everything is charged, will set the main page */ - setMainPage(){ - let defaultHomePageUniqueId:any; - if(this.myFileNameExtension == "sps"){ + setMainPage() { + let defaultHomePageUniqueId: any; + if (this.myFileNameExtension == "sps") { const pageSetProperties = this.db.prepare('SELECT DefaultHomePageUniqueId FROM PageSetProperties'); pageSetProperties.step(); defaultHomePageUniqueId = pageSetProperties.getAsObject().DefaultHomePageUniqueId; let homePage = this.newGrid.PageList.find(page => page.ID === defaultHomePageUniqueId); homePage.ID = '#HOME'; pageSetProperties.free(); - }else{ + } else { const queryHomePageForSpb = this.db.prepare('SELECT Id,UniqueId FROM Page WHERE Id = 4'); queryHomePageForSpb.step(); defaultHomePageUniqueId = queryHomePageForSpb.getAsObject().UniqueId; @@ -357,21 +348,6 @@ export class Spb2augComponent implements OnInit { homePage.ID = '#HOME'; queryHomePageForSpb.free(); } - this.SwitchPageLinkTargetMainPage(defaultHomePageUniqueId); - } - - /** - * Warning : This function is not tested, i don't have a test for this be careful here - * function who switch the link from folder button who linked on the unique ID, but I switched it to #HOME for our grid - * @param defaultHomePageUniqueId id unique for the home page - * @constructor - */ - SwitchPageLinkTargetMainPage(defaultHomePageUniqueId: any){ - this.newGrid.ElementList.forEach(elem => { - if(elem.Type == {GoTo : String(defaultHomePageUniqueId)}) { - elem.Type = {GoTo : "#HOME"} - } - }); } /** @@ -401,39 +377,71 @@ export class Spb2augComponent implements OnInit { return ''; } + /** * Search in the database and set the number of rows and colomns in the grid */ - getGridDimension() { + getGridDimensionFromDatabase() { const gridDim = this.db.prepare('SELECT GridDimension FROM PageSetProperties'); while (gridDim.step()) { const result = gridDim.getAsObject().GridDimension; const gridDimension = result.split(','); - this.newGrid.NumberOfCols = Number(gridDimension[0]); + this.newGrid.NumberOfCols = Number(gridDimension[0]) + 1; this.newGrid.NumberOfRows = Number(gridDimension[1]); } gridDim.free(); } /** - * get the max of rows and columns for every pages and return the pageLayoutId - * @param page query from the database for page in PageLayout table + * this function calculate the dimension of the page and return it + * @param queryPageLayout query indicate the Layout of the page + * @param pageDimension array who indicate dimension of this page + * @param queryPage query to know the PageType of our page */ - getPageDimensionMax(page: any): number[] { - let numberOfRowsMax = 0; - let numberOfColsMax = 0; - let pageLayoutId = 0; - while (page.step()) { - const pageLayoutSetting = page.getAsObject().PageLayoutSetting; - const pageLayoutIdDataBase = page.getAsObject().Id; - const tabLayoutSetting = pageLayoutSetting.split(','); - if (numberOfRowsMax <= Number(tabLayoutSetting[1]) && numberOfColsMax <= Number(tabLayoutSetting[0])) { - numberOfRowsMax = Number(tabLayoutSetting[1]); - numberOfColsMax = Number(tabLayoutSetting[0]); - pageLayoutId = pageLayoutIdDataBase; + getPageDimension(queryPageLayout: any, pageDimension: any, queryPage: any): number[] { + { + let numberOfRowsMax = 0; + let numberOfColsMax = 0; + let pageLayoutId = 0; + + let pageType: number = queryPage.getAsObject().PageType; + + while (queryPageLayout.step()) { + const pageLayoutSetting = queryPageLayout.getAsObject().PageLayoutSetting; + const pageLayoutIdDataBase = queryPageLayout.getAsObject().Id; + const tabLayoutSetting = pageLayoutSetting.split(','); + if (pageDimension != null) { + let tabPageDimension = pageDimension.split(','); + //Condition for the grid size to match the one specified in the Page table (i.e., the one that specifies a size) + if (Number(tabLayoutSetting[0]) == Number(tabPageDimension[0]) && Number(tabLayoutSetting[1]) == Number(tabPageDimension[1])) { + numberOfRowsMax = Number(tabLayoutSetting[1]); + numberOfColsMax = Number(tabLayoutSetting[0]); + pageLayoutId = pageLayoutIdDataBase; + return [numberOfRowsMax, numberOfColsMax, pageLayoutId]; + } + //Condition for the grid size to match the one specified in the PageSetProperty table + } else if (Number(tabLayoutSetting[0]) == this.newGrid.NumberOfCols - 1 && Number(tabLayoutSetting[1]) == this.newGrid.NumberOfRows) { + numberOfRowsMax = Number(tabLayoutSetting[1]); + numberOfColsMax = Number(tabLayoutSetting[0]); + pageLayoutId = pageLayoutIdDataBase; + return [numberOfRowsMax, numberOfColsMax, pageLayoutId]; + } + //Condition for the dashboard: it differs from the standard, its column is always one higher, it never has a page specialization, so it doesn't fit in the right place. + else if (pageType == 3 && Number(tabLayoutSetting[1]) == this.newGrid.NumberOfRows) { + numberOfRowsMax = Number(tabLayoutSetting[1]); + numberOfColsMax = Number(tabLayoutSetting[0]); + pageLayoutId = pageLayoutIdDataBase; + return [numberOfRowsMax, numberOfColsMax, pageLayoutId]; + } + //Condition to take the largest possible grid size + else if (numberOfRowsMax <= Number(tabLayoutSetting[1]) && numberOfColsMax <= Number(tabLayoutSetting[0])) { + numberOfRowsMax = Number(tabLayoutSetting[1]); + numberOfColsMax = Number(tabLayoutSetting[0]); + pageLayoutId = pageLayoutIdDataBase; + } } + return [numberOfRowsMax, numberOfColsMax, pageLayoutId]; } - return [numberOfRowsMax, numberOfColsMax, pageLayoutId]; } /** @@ -452,6 +460,7 @@ export class Spb2augComponent implements OnInit { }); console.log('pourcentage d\'erreur : ', this.numberErrorImage / this.newGrid.ImageList.length * 100 + '%'); } + /** * query the database to set the police */ @@ -462,4 +471,86 @@ export class Spb2augComponent implements OnInit { this.configuration.STYLE_FONTFAMILY_VALUE = String(police); po.free(); } + + /** + * add the dashboard on every page + */ + fillPageWithDashboard() { + let howManyPages: number = 2; + + if (this.myFileNameExtension == "spb") { + let dashboard: Page = this.newGrid.PageList.find(page => page.UniquePageId == "2"); + this.newGrid.PageList.forEach(page => { + if (page.UniquePageId != "2") { + dashboard.ElementIDsList.forEach(el => { + if (el.includes("goDown") == false) { + page.ElementIDsList.push(el); + } + }); + } + }); + let goDownIDPage: string = "goDown" + String(howManyPages); + let dashboardGoDown: Page = this.newGrid.PageList.find(page => page.UniquePageId == "2" && page.ID.includes(goDownIDPage)); + if (dashboardGoDown != undefined) { + while (dashboardGoDown) { + this.newGrid.PageList.forEach(page => { + if (page.UniquePageId != "2" && page.ID.includes(goDownIDPage) == true) { + dashboardGoDown.ElementIDsList.forEach(el => { + if (el.includes("goDown") == false) { + page.ElementIDsList.push(el); + } + }); + } + }); + howManyPages += 1; + goDownIDPage = "goDown" + String(howManyPages); + dashboardGoDown = this.newGrid.PageList.find(page => page.UniquePageId == "2" && page.ID.includes(goDownIDPage)); + } + } + } + if (this.myFileNameExtension == "sps") { + let dashboard: Page = this.newGrid.PageList.find(page => page.PageType == 3 && !page.ID.includes("goDown")); + this.newGrid.PageList.forEach(page => { + if (page.PageType != 3 && page.ID.includes("goDown") == false) { + dashboard.ElementIDsList.forEach(el => { + if (el.includes("goDown") == false) { + page.ElementIDsList.push(el); + } + }); + } + }); + let goDownIDPage: string = "goDown" + String(howManyPages) + "Page"; + let dashboardGoDown: Page = this.newGrid.PageList.find(page => page.PageType == 3 && page.ID.includes(goDownIDPage)); + if (dashboardGoDown != undefined) { + while (dashboardGoDown) { + this.newGrid.PageList.forEach(page => { + if (page.PageType != 3 && page.ID.includes(goDownIDPage) == true) { + dashboardGoDown.ElementIDsList.forEach(el => { + if (el.includes("goDown") == false) { + page.ElementIDsList.push(el); + } + }); + } + }); + howManyPages += 1; + goDownIDPage = "goDown" + String(howManyPages); + dashboardGoDown = this.newGrid.PageList.find(page => page.PageType == 3 && page.ID.includes(goDownIDPage)); + } + } + } + } + + /** + * This function look at the folder pointed by the GridElement, if the folder doesn't it switch the pointer to HomePage + */ + switchLinkedPage() { + this.newGrid.ElementList.forEach(gridElem => { + if ((gridElem.Type as FolderGoTo).GoTo !== undefined) { + const pagelinked = this.newGrid.PageList.find(page => page.ID == (gridElem.Type as FolderGoTo).GoTo); + if (pagelinked == undefined) { + (gridElem.Type as FolderGoTo).GoTo = "#HOME"; + } + } + }); + } } diff --git a/src/app/types.ts b/src/app/types.ts index a89367727..4d9102f56 100644 --- a/src/app/types.ts +++ b/src/app/types.ts @@ -171,6 +171,7 @@ export class ElementForm { export class Page { ID: string; UniquePageId?: string; + PageType?: number; Name: string; ElementIDsList: string[]; NumberOfCols: number;