MOBILE-3660 core: Create and use popover controller singleton

main
Pau Ferrer Ocaña 2021-02-04 15:13:59 +01:00
parent 66f64c02dc
commit 67e3021e54
9 changed files with 22 additions and 51 deletions

View File

@ -13,7 +13,7 @@
// limitations under the License.
import { Component, OnInit, OnDestroy } from '@angular/core';
import { PopoverController, IonRefresher } from '@ionic/angular';
import { IonRefresher } from '@ionic/angular';
import { CoreApp } from '@services/app';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreLocalNotifications } from '@services/local-notifications';
@ -35,7 +35,7 @@ import { CoreCategoryData, CoreCourses, CoreEnrolledCourseData } from '@features
import { CoreCoursesHelper } from '@features/courses/services/courses-helper';
import { AddonCalendarFilterPopoverComponent } from '../../components/filter/filter';
import moment from 'moment';
import { Network, NgZone } from '@singletons';
import { Network, NgZone, PopoverController } from '@singletons';
import { CoreNavigator } from '@services/navigator';
import { Params } from '@angular/router';
import { Subscription } from 'rxjs';
@ -100,9 +100,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy {
category: true,
};
constructor(
private popoverCtrl: PopoverController,
) {
constructor() {
this.currentSiteId = CoreSites.instance.getCurrentSiteId();
if (CoreLocalNotifications.instance.isAvailable()) {
@ -537,7 +535,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy {
* @param event Event.
*/
async openFilter(event: MouseEvent): Promise<void> {
const popover = await this.popoverCtrl.create({
const popover = await PopoverController.instance.create({
component: AddonCalendarFilterPopoverComponent,
componentProps: {
courses: this.courses,

View File

@ -13,7 +13,7 @@
// limitations under the License.
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { PopoverController, IonRefresher } from '@ionic/angular';
import { IonRefresher } from '@ionic/angular';
import { CoreApp } from '@services/app';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreSites } from '@services/sites';
@ -23,7 +23,7 @@ import { AddonCalendar, AddonCalendarProvider, AddonCalendarUpdatedEventEvent }
import { AddonCalendarOffline } from '../../services/calendar-offline';
import { AddonCalendarSync, AddonCalendarSyncEvents, AddonCalendarSyncProvider } from '../../services/calendar-sync';
import { AddonCalendarFilter, AddonCalendarHelper } from '../../services/calendar-helper';
import { Network, NgZone } from '@singletons';
import { Network, NgZone, PopoverController } from '@singletons';
import { Subscription } from 'rxjs';
import { CoreEnrolledCourseData } from '@features/courses/services/courses';
import { ActivatedRoute, Params } from '@angular/router';
@ -83,7 +83,6 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy {
};
constructor(
protected popoverCtrl: PopoverController,
protected route: ActivatedRoute,
) {
this.currentSiteId = CoreSites.instance.getCurrentSiteId();
@ -341,7 +340,7 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy {
* @param event Event.
*/
async openFilter(event: MouseEvent): Promise<void> {
const popover = await this.popoverCtrl.create({
const popover = await PopoverController.instance.create({
component: AddonCalendarFilterPopoverComponent,
componentProps: {
courses: this.courses,

View File

@ -13,7 +13,7 @@
// limitations under the License.
import { Component, ViewChild, OnDestroy, OnInit } from '@angular/core';
import { PopoverController, IonContent, IonRefresher } from '@ionic/angular';
import { IonContent, IonRefresher } from '@ionic/angular';
import {
AddonCalendarProvider,
AddonCalendar,
@ -36,7 +36,7 @@ import { CoreConstants } from '@/core/constants';
import { AddonCalendarFilterPopoverComponent } from '../../components/filter/filter';
import { Params } from '@angular/router';
import { Subscription } from 'rxjs';
import { Network, NgZone } from '@singletons';
import { Network, NgZone, PopoverController } from '@singletons';
import { CoreCoursesHelper } from '@features/courses/services/courses-helper';
import { CoreUtils } from '@services/utils/utils';
import { CoreNavigator } from '@services/navigator';
@ -101,9 +101,7 @@ export class AddonCalendarListPage implements OnInit, OnDestroy {
category: true,
};
constructor(
private popoverCtrl: PopoverController,
) {
constructor() {
this.siteHomeId = CoreSites.instance.getCurrentSiteHomeId();
this.notificationsEnabled = CoreLocalNotifications.instance.isAvailable();
@ -624,7 +622,7 @@ export class AddonCalendarListPage implements OnInit, OnDestroy {
* @param event Event.
*/
async openFilter(event: MouseEvent): Promise<void> {
const popover = await this.popoverCtrl.create({
const popover = await PopoverController.instance.create({
component: AddonCalendarFilterPopoverComponent,
componentProps: {
courses: this.courses,

View File

@ -13,7 +13,8 @@
// limitations under the License.
import { Component } from '@angular/core';
import { NavParams, PopoverController } from '@ionic/angular';
import { NavParams } from '@ionic/angular';
import { PopoverController } from '@singletons';
import { CoreContextMenuItemComponent } from './context-menu-item';
/**
@ -32,7 +33,6 @@ export class CoreContextMenuPopoverComponent {
constructor(
navParams: NavParams,
protected popoverCtrl: PopoverController,
) {
this.title = navParams.get('title');
this.items = navParams.get('items') || [];
@ -43,7 +43,7 @@ export class CoreContextMenuPopoverComponent {
* Close the popover.
*/
closeMenu(item?: CoreContextMenuItemComponent): void {
this.popoverCtrl.dismiss(item);
PopoverController.instance.dismiss(item);
}
/**

View File

@ -15,10 +15,9 @@
import { Component, Input, OnInit, OnDestroy, ElementRef } from '@angular/core';
import { Subject } from 'rxjs';
import { auditTime } from 'rxjs/operators';
import { PopoverController } from '@ionic/angular';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils';
import { Translate } from '@singletons';
import { PopoverController, Translate } from '@singletons';
import { CoreContextMenuItemComponent } from './context-menu-item';
import { CoreContextMenuPopoverComponent } from './context-menu-popover';
@ -47,7 +46,6 @@ export class CoreContextMenuComponent implements OnInit, OnDestroy {
constructor(
protected popoverCtrl: PopoverController,
elementRef: ElementRef,
) {
// Create the stream and subscribe to it. We ignore successive changes during 250ms.
@ -179,7 +177,7 @@ export class CoreContextMenuComponent implements OnInit, OnDestroy {
*/
async showContextMenu(event: MouseEvent): Promise<void> {
if (!this.expanded) {
const popover = await this.popoverCtrl.create(
const popover = await PopoverController.instance.create(
{
event,
component: CoreContextMenuPopoverComponent,

View File

@ -13,10 +13,10 @@
// limitations under the License.
import { Component, Input, OnInit } from '@angular/core';
import { PopoverController } from '@ionic/angular';
import { CoreCourses } from '../../services/courses';
import { CoreEnrolledCourseDataWithExtraInfoAndOptions } from '../../services/courses-helper';
import { CorePrefetchStatusInfo } from '@features/course/services/course-helper';
import { PopoverController } from '@singletons';
/**
* This component is meant to display a popover with the course options.
@ -32,10 +32,6 @@ export class CoreCoursesCourseOptionsMenuComponent implements OnInit {
downloadCourseEnabled = false;
constructor(
protected popoverController: PopoverController,
) { }
/**
* Component being initialized.
*/
@ -49,7 +45,7 @@ export class CoreCoursesCourseOptionsMenuComponent implements OnInit {
* @param action Action name to take.
*/
action(action: string): void {
this.popoverController.dismiss(action);
PopoverController.instance.dismiss(action);
}
}

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
import { PopoverController } from '@ionic/angular';
import { CoreEventCourseStatusChanged, CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
@ -21,7 +20,7 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreCourses } from '@features/courses/services/courses';
import { CoreCourse, CoreCourseProvider } from '@features/course/services/course';
import { CoreCourseHelper, CorePrefetchStatusInfo } from '@features/course/services/course-helper';
import { Translate } from '@singletons';
import { PopoverController, Translate } from '@singletons';
import { CoreConstants } from '@/core/constants';
import { CoreEnrolledCourseDataWithExtraInfoAndOptions } from '../../services/courses-helper';
import { CoreCoursesCourseOptionsMenuComponent } from '../course-options-menu/course-options-menu';
@ -62,10 +61,6 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy {
protected courseStatusObserver?: CoreEventObserver;
protected siteUpdatedObserver?: CoreEventObserver;
constructor(
protected popoverCtrl: PopoverController,
) { }
/**
* Component being initialized.
*/
@ -204,7 +199,7 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy {
e.preventDefault();
e.stopPropagation();
const popover = await this.popoverCtrl.create({
const popover = await PopoverController.instance.create({
component: CoreCoursesCourseOptionsMenuComponent,
componentProps: {
course: this.course,

View File

@ -13,14 +13,12 @@
// limitations under the License.
import { Injectable } from '@angular/core';
// import { PopoverController } from '@ionic/angular';
import { CoreUtils } from '@services/utils/utils';
import { CoreSites } from '@services/sites';
import { CoreCourses, CoreCourseSearchedData, CoreCourseUserAdminOrNavOptionIndexed, CoreEnrolledCourseData } from './courses';
import { makeSingleton, Translate } from '@singletons';
import { CoreWSExternalFile } from '@services/ws';
import { AddonCourseCompletion } from '@/addons/coursecompletion/services/coursecompletion';
// import { CoreCoursePickerMenuPopoverComponent } from '@components/course-picker-menu/course-picker-menu-popover';
/**
* Helper to gather some common courses functions.
@ -276,19 +274,6 @@ export class CoreCoursesHelperProvider {
}));
}
/**
* Show a context menu to select a course, and return the courseId and categoryId of the selected course (-1 for all courses).
* Returns an empty object if popover closed without picking a course.
*
* @param event Click event.
* @param courses List of courses, from CoreCoursesHelperProvider.getCoursesForPopover.
* @param courseId The course to select at start.
* @return Promise resolved with the course ID and category ID.
*/
async selectCourse(): Promise<void> {
// @todo params and logic
}
}
export class CoreCoursesHelper extends makeSingleton(CoreCoursesHelperProvider) { }

View File

@ -25,6 +25,7 @@ import {
GestureController as GestureControllerService,
ActionSheetController as ActionSheetControllerService,
NavController as NavControllerService,
PopoverController as PopoverControllerService,
} from '@ionic/angular';
import { Badge as BadgeService } from '@ionic-native/badge/ngx';
@ -148,6 +149,7 @@ export class ActionSheetController extends makeSingleton(ActionSheetControllerSe
export class AlertController extends makeSingleton(AlertControllerService) {}
export class LoadingController extends makeSingleton(LoadingControllerService) {}
export class ModalController extends makeSingleton(ModalControllerService) {}
export class PopoverController extends makeSingleton(PopoverControllerService) {}
export class ToastController extends makeSingleton(ToastControllerService) {}
export class GestureController extends makeSingleton(GestureControllerService) {}
export class ApplicationInit extends makeSingleton(ApplicationInitStatus) {}