From 53fe0d899cb1ecc8cb211d88f681f544abfe1bc3 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Thu, 22 Mar 2018 15:46:30 +0100 Subject: [PATCH] MOBILE-2329 notes: Split view changed to a combo box. --- .../notes/components/components.module.ts | 12 ++-- .../{pages => components}/list/list.html | 26 ++++---- .../notes/{pages => components}/list/list.ts | 49 +++++++-------- src/addon/notes/components/types/types.html | 15 ----- src/addon/notes/components/types/types.ts | 62 ------------------- src/addon/notes/pages/list/list.module.ts | 35 ----------- .../notes/providers/course-option-handler.ts | 4 +- 7 files changed, 46 insertions(+), 157 deletions(-) rename src/addon/notes/{pages => components}/list/list.html (56%) rename src/addon/notes/{pages => components}/list/list.ts (79%) delete mode 100644 src/addon/notes/components/types/types.html delete mode 100644 src/addon/notes/components/types/types.ts delete mode 100644 src/addon/notes/pages/list/list.module.ts diff --git a/src/addon/notes/components/components.module.ts b/src/addon/notes/components/components.module.ts index 4064545e6..53a7a2457 100644 --- a/src/addon/notes/components/components.module.ts +++ b/src/addon/notes/components/components.module.ts @@ -17,25 +17,29 @@ import { CommonModule } from '@angular/common'; import { IonicModule } from 'ionic-angular'; import { TranslateModule } from '@ngx-translate/core'; import { CoreComponentsModule } from '@components/components.module'; -import { AddonNotesTypesComponent } from './types/types'; +import { CoreDirectivesModule } from '@directives/directives.module'; +import { CorePipesModule } from '@pipes/pipes.module'; +import { AddonNotesListComponent } from './list/list'; @NgModule({ declarations: [ - AddonNotesTypesComponent + AddonNotesListComponent ], imports: [ CommonModule, IonicModule, TranslateModule.forChild(), CoreComponentsModule, + CoreDirectivesModule, + CorePipesModule ], providers: [ ], exports: [ - AddonNotesTypesComponent + AddonNotesListComponent ], entryComponents: [ - AddonNotesTypesComponent + AddonNotesListComponent ] }) export class AddonNotesComponentsModule {} diff --git a/src/addon/notes/pages/list/list.html b/src/addon/notes/components/list/list.html similarity index 56% rename from src/addon/notes/pages/list/list.html rename to src/addon/notes/components/list/list.html index 1431ca259..5b2fd8ebc 100644 --- a/src/addon/notes/pages/list/list.html +++ b/src/addon/notes/components/list/list.html @@ -1,15 +1,9 @@ - - - {{ 'addon.notes.notes' | translate }} - - - - - - - - - + + + + + + @@ -17,6 +11,12 @@ + + {{ 'addon.notes.sitenotes' | translate }} + {{ 'addon.notes.coursenotes' | translate }} + {{ 'addon.notes.personalnotes' | translate }} + +
{{ 'core.thereisdatatosync' | translate:{$a: 'addon.notes.notes' | translate | lowercase } }} @@ -28,7 +28,7 @@ - +

{{note.userfullname}}

{{note.lastmodified | coreDateDayOrTime}}

diff --git a/src/addon/notes/pages/list/list.ts b/src/addon/notes/components/list/list.ts similarity index 79% rename from src/addon/notes/pages/list/list.ts rename to src/addon/notes/components/list/list.ts index d64b578b9..f41af7dec 100644 --- a/src/addon/notes/pages/list/list.ts +++ b/src/addon/notes/components/list/list.ts @@ -12,43 +12,39 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, OnDestroy, Optional, ViewChild } from '@angular/core'; -import { Content, IonicPage, NavController, NavParams } from 'ionic-angular'; +import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; +import { Content } from 'ionic-angular'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreEventsProvider } from '@providers/events'; import { CoreSitesProvider } from '@providers/sites'; import { CoreTextUtilsProvider } from '@providers/utils/text'; -import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { AddonNotesProvider } from '../../providers/notes'; import { AddonNotesSyncProvider } from '../../providers/notes-sync'; /** - * Page that displays the list of notes. + * Component that displays the notes of a course. */ -@IonicPage({ segment: 'addon-notes-list' }) @Component({ - selector: 'page-addon-notes-list', + selector: 'addon-notes-list', templateUrl: 'list.html', }) -export class AddonNotesListPage implements OnDestroy { +export class AddonNotesListComponent implements OnInit, OnDestroy { + @Input() courseId: number; + @ViewChild(Content) content: Content; - protected courseId = 0; protected syncObserver: any; - type = ''; + type = 'course'; refreshIcon = 'spinner'; syncIcon = 'spinner'; notes: any[]; hasOffline = false; notesLoaded = false; - constructor(navParams: NavParams, private navCtrl: NavController, @Optional() private svComponent: CoreSplitViewComponent, - private domUtils: CoreDomUtilsProvider, private textUtils: CoreTextUtilsProvider, + constructor(private domUtils: CoreDomUtilsProvider, private textUtils: CoreTextUtilsProvider, sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider, private notesProvider: AddonNotesProvider, private notesSync: AddonNotesSyncProvider) { - this.courseId = navParams.get('courseId') || sitesProvider.getCurrentSiteHomeId(); - this.type = navParams.get('type'); // Refresh data if notes are synchronized automatically. this.syncObserver = eventsProvider.on(AddonNotesSyncProvider.AUTO_SYNCED, (data) => { if (data.courseId == this.courseId) { @@ -67,9 +63,9 @@ export class AddonNotesListPage implements OnDestroy { } /** - * View loaded. + * Component being initialized. */ - ionViewDidLoad(): void { + ngOnInit(): void { this.fetchNotes(true).then(() => { this.notesProvider.logView(this.courseId); }); @@ -124,6 +120,18 @@ export class AddonNotesListPage implements OnDestroy { }); } + /** + * Function called when the type has changed. + */ + typeChanged(): void { + this.notesLoaded = false; + this.refreshIcon = 'spinner'; + this.syncIcon = 'spinner'; + this.fetchNotes(true).then(() => { + this.notesProvider.logView(this.courseId); + }); + } + /** * Tries to synchronize course notes. * @@ -154,17 +162,6 @@ export class AddonNotesListPage implements OnDestroy { } } - /** - * Opens the profile of a user. - * - * @param {number} userId - */ - openUserProfile(userId: number): void { - // Decide which navCtrl to use. If this page is inside a split view, use the split view's master nav. - const navCtrl = this.svComponent ? this.svComponent.getMasterNav() : this.navCtrl; - navCtrl.push('CoreUserProfilePage', {userId, courseId: this.courseId}); - } - /** * Page destroyed. */ diff --git a/src/addon/notes/components/types/types.html b/src/addon/notes/components/types/types.html deleted file mode 100644 index 87c04392c..000000000 --- a/src/addon/notes/components/types/types.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - {{ 'addon.notes.sitenotes' | translate }} - - - {{ 'addon.notes.coursenotes' | translate }} - - - {{ 'addon.notes.personalnotes' | translate }} - - - - diff --git a/src/addon/notes/components/types/types.ts b/src/addon/notes/components/types/types.ts deleted file mode 100644 index 813546b6d..000000000 --- a/src/addon/notes/components/types/types.ts +++ /dev/null @@ -1,62 +0,0 @@ -// (C) Copyright 2015 Martin Dougiamas -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import { AfterViewInit, Component, Input, OnInit, ViewChild } from '@angular/core'; -import { CoreSplitViewComponent } from '@components/split-view/split-view'; -import { CoreSitesProvider } from '@providers/sites'; - -/** - * Component that displays the competencies of a course. - */ -@Component({ - selector: 'addon-notes-types', - templateUrl: 'types.html', -}) -export class AddonNotesTypesComponent implements AfterViewInit, OnInit { - @ViewChild(CoreSplitViewComponent) splitviewCtrl: CoreSplitViewComponent; - - @Input() courseId: number; - - protected type: string; - - constructor(private sitesProvider: CoreSitesProvider) { - } - - /** - * Properties initialized. - */ - ngOnInit(): void { - const siteHomeId = this.sitesProvider.getCurrentSite().getSiteHomeId(); - this.type = (this.courseId == siteHomeId ? 'site' : 'course'); - } - - /** - * View loaded. - */ - ngAfterViewInit(): void { - if (this.splitviewCtrl.isOn()) { - this.openList(this.type); - } - } - - /** - * Opens a list of notes. - * - * @param {string} type - */ - openList(type: string): void { - this.type = type; - this.splitviewCtrl.push('AddonNotesListPage', {courseId: this.courseId, type: type}); - } -} diff --git a/src/addon/notes/pages/list/list.module.ts b/src/addon/notes/pages/list/list.module.ts deleted file mode 100644 index 56f649dee..000000000 --- a/src/addon/notes/pages/list/list.module.ts +++ /dev/null @@ -1,35 +0,0 @@ -// (C) Copyright 2015 Martin Dougiamas -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import { NgModule } from '@angular/core'; -import { IonicPageModule } from 'ionic-angular'; -import { TranslateModule } from '@ngx-translate/core'; -import { CoreComponentsModule } from '@components/components.module'; -import { CoreDirectivesModule } from '@directives/directives.module'; -import { CorePipesModule } from '@pipes/pipes.module'; -import { AddonNotesListPage } from './list'; - -@NgModule({ - declarations: [ - AddonNotesListPage, - ], - imports: [ - CoreComponentsModule, - CoreDirectivesModule, - CorePipesModule, - IonicPageModule.forChild(AddonNotesListPage), - TranslateModule.forChild() - ], -}) -export class AddonNotesListPageModule {} diff --git a/src/addon/notes/providers/course-option-handler.ts b/src/addon/notes/providers/course-option-handler.ts index 8ab6dbbd1..34500726a 100644 --- a/src/addon/notes/providers/course-option-handler.ts +++ b/src/addon/notes/providers/course-option-handler.ts @@ -16,7 +16,7 @@ import { Injectable, Injector } from '@angular/core'; import { AddonNotesProvider } from './notes'; import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreCourseOptionsHandler, CoreCourseOptionsHandlerData } from '@core/course/providers/options-delegate'; -import { AddonNotesTypesComponent } from '../components/types/types'; +import { AddonNotesListComponent } from '../components/list/list'; /** * Handler to inject an option into the course main menu. @@ -68,7 +68,7 @@ export class AddonNotesCourseOptionHandler implements CoreCourseOptionsHandler { return { title: 'addon.notes.notes', class: 'addon-notes-course-handler', - component: AddonNotesTypesComponent, + component: AddonNotesListComponent, }; } }