From 3f1114f34c26ab5d32424714c0599518edc8c298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 30 Aug 2019 09:44:36 +0200 Subject: [PATCH] MOBILE-3105 wiki: Code restyling --- .../index/addon-mod-wiki-index.html | 5 +- .../mod/wiki/components/index/index.scss | 1 + src/addon/mod/wiki/components/index/index.ts | 66 +++++++------------ src/addon/mod/wiki/pages/map/map.html | 5 +- src/addon/mod/wiki/pages/map/map.ts | 4 +- 5 files changed, 33 insertions(+), 48 deletions(-) diff --git a/src/addon/mod/wiki/components/index/addon-mod-wiki-index.html b/src/addon/mod/wiki/components/index/addon-mod-wiki-index.html index 749a85458..c16f7462c 100644 --- a/src/addon/mod/wiki/components/index/addon-mod-wiki-index.html +++ b/src/addon/mod/wiki/components/index/addon-mod-wiki-index.html @@ -24,7 +24,7 @@ -
+
@@ -39,7 +39,8 @@ {{ pageWarning }}
- +
+
diff --git a/src/addon/mod/wiki/components/index/index.scss b/src/addon/mod/wiki/components/index/index.scss index e320264d2..3a0249f11 100644 --- a/src/addon/mod/wiki/components/index/index.scss +++ b/src/addon/mod/wiki/components/index/index.scss @@ -12,6 +12,7 @@ ion-app.app-root addon-mod-wiki-index { .addon-mod_wiki-page-content { background-color: $white; + border-top: 1px solid $gray; @include darkmode() { background-color: $black; } diff --git a/src/addon/mod/wiki/components/index/index.ts b/src/addon/mod/wiki/components/index/index.ts index a7eab587f..f4780f4c8 100644 --- a/src/addon/mod/wiki/components/index/index.ts +++ b/src/addon/mod/wiki/components/index/index.ts @@ -145,31 +145,20 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp protected checkPageCreatedOrDiscarded(data: any): void { if (!this.currentPage && data) { // This is an offline page. Check if the page was created. - let pageId; - - for (let i = 0, len = data.created.length; i < len; i++) { - const page = data.created[i]; - if (page.title == this.pageTitle) { - pageId = page.pageId; - break; - } - } - - if (pageId) { + const page = data.created.find((page) => page.title == this.pageTitle); + if (page) { // Page was created, set the ID so it's retrieved from server. - this.currentPage = pageId; + this.currentPage = page.pageId; this.pageIsOffline = false; } else { // Page not found in created list, check if it was discarded. - for (let i = 0, len = data.discarded.length; i < len; i++) { - const page = data.discarded[i]; - if (page.title == this.pageTitle) { - // Page discarded, show warning. - this.pageWarning = page.warning; - this.pageContent = ''; - this.pageIsOffline = false; - this.hasOffline = false; - } + const page = data.discarded.find((page) => page.title == this.pageTitle); + if (page) { + // Page discarded, show warning. + this.pageWarning = page.warning; + this.pageContent = ''; + this.pageIsOffline = false; + this.hasOffline = false; } } } @@ -328,12 +317,9 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp // If no page specified, search first page. if (!this.currentPage && !this.pageTitle) { - for (const i in subwikiPages) { - const page = subwikiPages[i]; - if (page.firstpage) { - this.currentPage = page.id; - break; - } + const firstPage = subwikiPages.find((page) => page.firstpage ); + if (firstPage) { + this.currentPage = firstPage.id; } } @@ -527,7 +513,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp * * @param page Page to view. */ - goToPage(page: any): void { + protected goToPage(page: any): void { if (!page.id) { // It's an offline page. Check if we are already in the same offline page. if (this.currentPage || !this.pageTitle || page.title != this.pageTitle) { @@ -536,8 +522,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp courseId: this.courseId, pageTitle: page.title, wikiId: this.wiki.id, - subwikiId: page.subwikiid, - action: 'page' + subwikiId: page.subwikiid }); return; @@ -551,8 +536,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp pageTitle: page.title, pageId: page.id, wikiId: page.wikiid, - subwikiId: page.subwikiid, - action: 'page' + subwikiId: page.subwikiid }); }); @@ -563,9 +547,9 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp /** * Show the map. * - * @param {MouseEvent} event Event. + * @param event Event. */ - openMap(event: MouseEvent): void { + openMap(event?: MouseEvent): void { const modal = this.modalCtrl.create('AddonModWikiMapPage', { pages: this.subwikiPages, selected: this.currentPageObj && this.currentPageObj.id, @@ -576,7 +560,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp enterAnimation: 'core-modal-lateral-transition', leaveAnimation: 'core-modal-lateral-transition' }); - // If the modal sends back a SCO, load it. + // If the modal sends back a page, load it. modal.onDidDismiss((page) => { if (page) { if (page.type == 'home') { @@ -984,9 +968,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp if (multiLevelList) { // As we loop over each subwiki, add it to the current group - for (const i in subwikiList) { - const subwiki = subwikiList[i]; - + subwikiList.forEach((subwiki) => { // Should we create a new grouping? if (subwiki.groupid !== groupValue) { grouping = {label: subwiki.groupLabel, subwikis: []}; @@ -997,16 +979,14 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp // Add the subwiki to the currently active grouping. grouping.subwikis.push(subwiki); - } + }); } else if (showMyGroupsLabel) { const noGrouping = {label: '', subwikis: []}, myGroupsGrouping = {label: this.translate.instant('core.mygroups'), subwikis: []}, otherGroupsGrouping = {label: this.translate.instant('core.othergroups'), subwikis: []}; // As we loop over each subwiki, add it to the current group - for (const i in subwikiList) { - const subwiki = subwikiList[i]; - + subwikiList.forEach((subwiki) => { // Add the subwiki to the currently active grouping. if (typeof subwiki.canedit == 'undefined') { noGrouping.subwikis.push(subwiki); @@ -1015,7 +995,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp } else { otherGroupsGrouping.subwikis.push(subwiki); } - } + }); // Add each grouping to the subwikis if (noGrouping.subwikis.length > 0) { diff --git a/src/addon/mod/wiki/pages/map/map.html b/src/addon/mod/wiki/pages/map/map.html index 4d1545519..93429cb91 100644 --- a/src/addon/mod/wiki/pages/map/map.html +++ b/src/addon/mod/wiki/pages/map/map.html @@ -21,7 +21,10 @@ {{ page.title }} - {{ 'core.offline' | translate }} + + + {{ 'core.notsent' | translate }} + diff --git a/src/addon/mod/wiki/pages/map/map.ts b/src/addon/mod/wiki/pages/map/map.ts index e1fcb25ad..30fb14133 100644 --- a/src/addon/mod/wiki/pages/map/map.ts +++ b/src/addon/mod/wiki/pages/map/map.ts @@ -38,7 +38,7 @@ export class AddonModWikiMapPage { /** * Function called when a page is clicked. * - * @param {any} page Clicked page. + * @param page Clicked page. */ goToPage(page: any): void { this.viewCtrl.dismiss({type: 'page', goto: page}); @@ -54,7 +54,7 @@ export class AddonModWikiMapPage { /** * Construct the map of pages. * - * @param {any[]} pages List of pages. + * @param pages List of pages. */ protected constructMap(pages: any[]): void { let letter,