MOBILE-2308 calendar: Change static declarations and minor

main
Pau Ferrer Ocaña 2018-01-12 11:56:18 +01:00
parent 2cdeda17ee
commit 8794a06b9f
11 changed files with 93 additions and 65 deletions

View File

@ -1,3 +1,3 @@
page-addon-calendar-list { page-addon-calendar-event {
} }

View File

@ -86,8 +86,6 @@ export class AddonCalendarEventPage {
/** /**
* Fetches the event and updates the view. * Fetches the event and updates the view.
*
* @param {boolean} refresh Empty events array first.
*/ */
fetchEvent() { fetchEvent() {
return this.calendarProvider.getEvent(this.eventId).then((event) => { return this.calendarProvider.getEvent(this.eventId).then((event) => {

View File

@ -103,7 +103,7 @@ export class AddonCalendarListPage implements OnDestroy {
/** /**
* Fetch all the data required for the view. * Fetch all the data required for the view.
* *
* @param {boolean} refresh Empty events array first. * @param {boolean} [refresh] Empty events array first.
*/ */
fetchData(refresh = false) { fetchData(refresh = false) {
this.daysLoaded = 0; this.daysLoaded = 0;
@ -121,7 +121,7 @@ export class AddonCalendarListPage implements OnDestroy {
/** /**
* Fetches the events and updates the view. * Fetches the events and updates the view.
* *
* @param {boolean} refresh Empty events array first. * @param {boolean} [refresh] Empty events array first.
*/ */
fetchEvents(refresh = false) { fetchEvents(refresh = false) {
return this.calendarProvider.getEventsList(this.daysLoaded, AddonCalendarProvider.DAYS_INTERVAL).then((events) => { return this.calendarProvider.getEventsList(this.daysLoaded, AddonCalendarProvider.DAYS_INTERVAL).then((events) => {
@ -144,7 +144,7 @@ export class AddonCalendarListPage implements OnDestroy {
return a.timestart - b.timestart; return a.timestart - b.timestart;
}); });
events.forEach(this.calendarHelper.formatEventData); events.forEach(this.calendarHelper.formatEventData.bind(this.calendarHelper));
this.getCategories = this.shouldLoadCategories(events); this.getCategories = this.shouldLoadCategories(events);
if (refresh) { if (refresh) {
@ -253,7 +253,7 @@ export class AddonCalendarListPage implements OnDestroy {
this.categoriesRetrieved = true; this.categoriesRetrieved = true;
this.categories = {}; this.categories = {};
// Index categories by ID. // Index categories by ID.
cats.forEach(function(category) { cats.forEach((category) => {
this.categories[category.id] = category; this.categories[category.id] = category;
}); });
}).catch(() => { }).catch(() => {
@ -291,7 +291,7 @@ export class AddonCalendarListPage implements OnDestroy {
openCourseFilter(event: MouseEvent) : void { openCourseFilter(event: MouseEvent) : void {
let popover = this.popoverCtrl.create(CoreCoursePickerMenuPopoverComponent, {courses: this.courses, let popover = this.popoverCtrl.create(CoreCoursePickerMenuPopoverComponent, {courses: this.courses,
courseId: this.filter.course.id}); courseId: this.filter.course.id});
popover.onDidDismiss(course => { popover.onDidDismiss((course) => {
if (course) { if (course) {
this.filter.course = course; this.filter.course = course;
this.content.scrollToTop(); this.content.scrollToTop();
@ -322,6 +322,6 @@ export class AddonCalendarListPage implements OnDestroy {
* Page destroyed. * Page destroyed.
*/ */
ngOnDestroy() { ngOnDestroy() {
this.obsDefaultTimeChange && this.obsDefaultTimeChange.off && this.obsDefaultTimeChange.off(); this.obsDefaultTimeChange && this.obsDefaultTimeChange.off();
} }
} }

View File

@ -31,14 +31,15 @@ export class AddonCalendarProvider {
public static DAYS_INTERVAL = 30; public static DAYS_INTERVAL = 30;
public static COMPONENT = 'AddonCalendarEvents'; public static COMPONENT = 'AddonCalendarEvents';
public static DEFAULT_NOTIFICATION_TIME_CHANGED = 'AddonCalendarDefaultNotificationTimeChangedEvent'; public static DEFAULT_NOTIFICATION_TIME_CHANGED = 'AddonCalendarDefaultNotificationTimeChangedEvent';
protected static DEFAULT_NOTIFICATION_TIME_SETTING = 'mmaCalendarDefaultNotifTime'; protected DEFAULT_NOTIFICATION_TIME_SETTING = 'mmaCalendarDefaultNotifTime';
protected static DEFAULT_NOTIFICATION_TIME = 60; protected ROOT_CACHE_KEY = 'mmaCalendar:';
protected DEFAULT_NOTIFICATION_TIME = 60;
// Variables for database. // Variables for database.
protected static EVENTS_TABLE = 'calendar_events'; // Queue of files to download. protected EVENTS_TABLE = 'calendar_events';
protected static tablesSchema = [ protected tablesSchema = [
{ {
name: AddonCalendarProvider.EVENTS_TABLE, name: this.EVENTS_TABLE,
columns: [ columns: [
{ {
name: 'id', name: 'id',
@ -108,7 +109,7 @@ export class AddonCalendarProvider {
private coursesProvider: CoreCoursesProvider, private timeUtils: CoreTimeUtilsProvider, private coursesProvider: CoreCoursesProvider, private timeUtils: CoreTimeUtilsProvider,
private localNotificationsProvider: CoreLocalNotificationsProvider, private configProvider: CoreConfigProvider) { private localNotificationsProvider: CoreLocalNotificationsProvider, private configProvider: CoreConfigProvider) {
this.logger = logger.getInstance('AddonCalendarProvider'); this.logger = logger.getInstance('AddonCalendarProvider');
this.sitesProvider.createTablesFromSchema(AddonCalendarProvider.tablesSchema); this.sitesProvider.createTablesFromSchema(this.tablesSchema);
} }
/** /**
@ -120,8 +121,8 @@ export class AddonCalendarProvider {
getDefaultNotificationTime(siteId?: string) : Promise<number> { getDefaultNotificationTime(siteId?: string) : Promise<number> {
siteId = siteId || this.sitesProvider.getCurrentSiteId(); siteId = siteId || this.sitesProvider.getCurrentSiteId();
let key = AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId; let key = this.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId;
return this.configProvider.get(key, AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME); return this.configProvider.get(key, this.DEFAULT_NOTIFICATION_TIME);
} }
/** /**
@ -159,7 +160,7 @@ export class AddonCalendarProvider {
* @return {string} Cache key. * @return {string} Cache key.
*/ */
protected getEventCacheKey(id: number): string { protected getEventCacheKey(id: number): string {
return 'mmaCalendar:events:' + id; return this.ROOT_CACHE_KEY + 'events:' + id;
} }
/** /**
@ -171,7 +172,7 @@ export class AddonCalendarProvider {
*/ */
getEventFromLocalDb(id: number, siteId?: string) : Promise<any> { getEventFromLocalDb(id: number, siteId?: string) : Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecord(AddonCalendarProvider.EVENTS_TABLE, {id: id}); return site.getDb().getRecord(this.EVENTS_TABLE, {id: id});
}); });
} }
@ -263,6 +264,15 @@ export class AddonCalendarProvider {
}); });
} }
/**
* Get prefix cache key for events list WS calls.
*
* @return {string} Prefix Cache key.
*/
protected getEventsListPrefixCacheKey() : string {
return this.ROOT_CACHE_KEY + 'eventslist:';
}
/** /**
* Get cache key for events list WS calls. * Get cache key for events list WS calls.
* *
@ -271,16 +281,7 @@ export class AddonCalendarProvider {
* @return {string} Cache key. * @return {string} Cache key.
*/ */
protected getEventsListCacheKey(daysToStart: number, daysInterval: number) : string { protected getEventsListCacheKey(daysToStart: number, daysInterval: number) : string {
return this.getRootCacheKey() + 'eventslist:' + daysToStart + ':' + daysInterval; return this.getEventsListPrefixCacheKey() + daysToStart + ':' + daysInterval;
}
/**
* Get the root cache key for the WS calls related to this provider.
*
* @return {string} Root cache key.
*/
protected getRootCacheKey() : string {
return 'mmaCalendar:';
} }
/** /**
@ -298,7 +299,7 @@ export class AddonCalendarProvider {
promises.push(this.coursesProvider.invalidateUserCourses(siteId)); promises.push(this.coursesProvider.invalidateUserCourses(siteId));
promises.push(this.groupsProvider.invalidateUserGroups(courses, siteId)); promises.push(this.groupsProvider.invalidateUserGroups(courses, siteId));
promises.push(site.invalidateWsCacheForKeyStartingWith(this.getRootCacheKey())); promises.push(site.invalidateWsCacheForKeyStartingWith(this.getEventsListPrefixCacheKey()));
return Promise.all(promises); return Promise.all(promises);
}); });
} }
@ -393,8 +394,8 @@ export class AddonCalendarProvider {
let promise = time == -1 ? this.getDefaultNotificationTime(siteId) : Promise.resolve(time); let promise = time == -1 ? this.getDefaultNotificationTime(siteId) : Promise.resolve(time);
return promise.then((time) => { return promise.then((time) => {
let timeend = (event.timestart + event.timeduration) * 1000; let timeEnd = (event.timestart + event.timeduration) * 1000;
if (timeend <= new Date().getTime()) { if (timeEnd <= new Date().getTime()) {
// The event has finished already, don't schedule it. // The event has finished already, don't schedule it.
return Promise.resolve(); return Promise.resolve();
} }
@ -455,7 +456,7 @@ export class AddonCalendarProvider {
setDefaultNotificationTime(time: number, siteId?: string) : Promise<any[]> { setDefaultNotificationTime(time: number, siteId?: string) : Promise<any[]> {
siteId = siteId || this.sitesProvider.getCurrentSiteId(); siteId = siteId || this.sitesProvider.getCurrentSiteId();
let key = AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId; let key = this.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId;
return this.configProvider.set(key, time); return this.configProvider.set(key, time);
} }
@ -496,7 +497,7 @@ export class AddonCalendarProvider {
notificationtime: e.notificationtime || -1 notificationtime: e.notificationtime || -1
}; };
return db.insertOrUpdateRecord(AddonCalendarProvider.EVENTS_TABLE, eventRecord, {id: eventRecord.id}); return db.insertOrUpdateRecord(this.EVENTS_TABLE, eventRecord, {id: eventRecord.id});
})); }));
}); });
@ -521,7 +522,7 @@ export class AddonCalendarProvider {
event.notificationtime = time; event.notificationtime = time;
return site.getDb().insertOrUpdateRecord(AddonCalendarProvider.EVENTS_TABLE, event, {id: event.id}).then(() => { return site.getDb().insertOrUpdateRecord(this.EVENTS_TABLE, event, {id: event.id}).then(() => {
return this.scheduleEventNotification(event, time); return this.scheduleEventNotification(event, time);
}); });
}); });

View File

@ -21,7 +21,7 @@ import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '../../../core/main
*/ */
@Injectable() @Injectable()
export class AddonCalendarMainMenuHandler implements CoreMainMenuHandler { export class AddonCalendarMainMenuHandler implements CoreMainMenuHandler {
name = 'mmaCalendar'; name = 'AddonCalendar';
priority = 400; priority = 400;
constructor(private calendarProvider: AddonCalendarProvider) {} constructor(private calendarProvider: AddonCalendarProvider) {}
@ -46,7 +46,7 @@ export class AddonCalendarMainMenuHandler implements CoreMainMenuHandler {
icon: 'calendar', icon: 'calendar',
title: 'addon.calendar.calendar', title: 'addon.calendar.calendar',
page: 'AddonCalendarListPage', page: 'AddonCalendarListPage',
class: 'mma-calendar-handler' class: 'addon-calendar-handler'
}; };
} }
} }

View File

@ -24,7 +24,7 @@ import { CoreSitesProvider } from '../../../providers/sites';
export class AddonCalendarHelperProvider { export class AddonCalendarHelperProvider {
protected logger; protected logger;
private static eventicons = { private EVENTICONS = {
'course': 'ionic', 'course': 'ionic',
'group': 'people', 'group': 'people',
'site': 'globe', 'site': 'globe',
@ -42,7 +42,7 @@ export class AddonCalendarHelperProvider {
* @param {any} e Event to format. * @param {any} e Event to format.
*/ */
formatEventData(e: any) { formatEventData(e: any) {
e.icon = AddonCalendarHelperProvider.eventicons[e.eventtype] || false; e.icon = this.EVENTICONS[e.eventtype] || false;
if (!e.icon) { if (!e.icon) {
// @todo: It's a module event. // @todo: It's a module event.
//e.icon = this.courseProvider.getModuleIconSrc(e.modulename); //e.icon = this.courseProvider.getModuleIconSrc(e.modulename);

View File

@ -153,16 +153,16 @@ core-format-text[maxHeight], *[core-format-text][maxHeight] {
display: none; display: none;
} }
&:not(.mm-shortened) { &:not(.core-shortened) {
max-height: none !important; max-height: none !important;
} }
&.mm-shortened { &.core-shortened {
color: $gray-darker; color: $gray-darker;
overflow: hidden; overflow: hidden;
min-height: 50px; min-height: 50px;
.mm-show-more { .core-show-more {
color: color($colors, dark); color: color($colors, dark);
text-align: right; text-align: right;
font-size: 14px; font-size: 14px;

View File

@ -1,3 +1,19 @@
// (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.
// Code based on https://github.com/martinpritchardelevate/ionic-split-pane-demo
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular'; import { IonicPageModule } from 'ionic-angular';
import { CoreSplitViewPlaceholderPage } from './placeholder'; import { CoreSplitViewPlaceholderPage } from './placeholder';

View File

@ -1,8 +1,21 @@
// (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.
// Code based on https://github.com/martinpritchardelevate/ionic-split-pane-demo
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { import { IonicPage } from 'ionic-angular';
IonicPage,
NavController,
NavParams } from 'ionic-angular';
@IonicPage({segment: "core-placeholder"}) @IonicPage({segment: "core-placeholder"})
@Component({ @Component({
@ -11,6 +24,6 @@ import {
}) })
export class CoreSplitViewPlaceholderPage { export class CoreSplitViewPlaceholderPage {
constructor(public navCtrl: NavController, public navParams: NavParams) { } constructor() { }
} }

View File

@ -44,9 +44,9 @@ import { CoreSplitViewPlaceholderPage } from './placeholder/placeholder';
export class CoreSplitViewComponent implements OnInit { export class CoreSplitViewComponent implements OnInit {
// @todo Mix both panels header buttons // @todo Mix both panels header buttons
@ViewChild('detailNav') _detailNav: Nav; @ViewChild('detailNav') detailNav: Nav;
@Input() when?: string | boolean = "md"; // @Input() when?: string | boolean = "md"; //
protected _isOn: boolean = false; protected isEnabled: boolean = false;
protected masterPageName: string = ""; protected masterPageName: string = "";
protected loadDetailPage: any = false; protected loadDetailPage: any = false;
protected element: HTMLElement; // Current element. protected element: HTMLElement; // Current element.
@ -54,7 +54,7 @@ export class CoreSplitViewComponent implements OnInit {
// Empty placeholder for the 'detail' page. // Empty placeholder for the 'detail' page.
detailPage: any = null; detailPage: any = null;
constructor(private _masterNav: NavController, element: ElementRef) { constructor(private masterNav: NavController, element: ElementRef) {
this.element = element.nativeElement; this.element = element.nativeElement;
} }
@ -63,7 +63,7 @@ export class CoreSplitViewComponent implements OnInit {
*/ */
ngOnInit() { ngOnInit() {
// Get the master page name and set an empty page as a placeholder. // Get the master page name and set an empty page as a placeholder.
this.masterPageName = this._masterNav.getActive().component.name; this.masterPageName = this.masterNav.getActive().component.name;
this.emptyDetails(); this.emptyDetails();
} }
@ -73,7 +73,7 @@ export class CoreSplitViewComponent implements OnInit {
* @return {boolean} If split view is enabled. * @return {boolean} If split view is enabled.
*/ */
isOn(): boolean { isOn(): boolean {
return this._isOn; return this.isEnabled;
} }
/** /**
@ -83,14 +83,14 @@ export class CoreSplitViewComponent implements OnInit {
* @param {any} params Any NavParams you want to pass along to the next view. * @param {any} params Any NavParams you want to pass along to the next view.
*/ */
push(page: any, params?: any, element?: HTMLElement) { push(page: any, params?: any, element?: HTMLElement) {
if (this._isOn) { if (this.isEnabled) {
this._detailNav.setRoot(page, params); this.detailNav.setRoot(page, params);
} else { } else {
this.loadDetailPage = { this.loadDetailPage = {
component: page, component: page,
data: params data: params
}; };
this._masterNav.push(page, params); this.masterNav.push(page, params);
} }
} }
@ -99,7 +99,7 @@ export class CoreSplitViewComponent implements OnInit {
*/ */
emptyDetails() { emptyDetails() {
this.loadDetailPage = false; this.loadDetailPage = false;
this._detailNav.setRoot('CoreSplitViewPlaceholderPage'); this.detailNav.setRoot('CoreSplitViewPlaceholderPage');
} }
/** /**
@ -108,8 +108,8 @@ export class CoreSplitViewComponent implements OnInit {
* @param {Boolean} isOn If it fits both panels at the same time. * @param {Boolean} isOn If it fits both panels at the same time.
*/ */
onSplitPaneChanged(isOn) { onSplitPaneChanged(isOn) {
this._isOn = isOn; this.isEnabled = isOn;
if (this._masterNav && this._detailNav) { if (this.masterNav && this.detailNav) {
(isOn) ? this.activateSplitView() : this.deactivateSplitView(); (isOn) ? this.activateSplitView() : this.deactivateSplitView();
} }
} }
@ -118,17 +118,17 @@ export class CoreSplitViewComponent implements OnInit {
* Enable the split view, show both panels and do some magical navigation. * Enable the split view, show both panels and do some magical navigation.
*/ */
activateSplitView() { activateSplitView() {
let currentView = this._masterNav.getActive(), let currentView = this.masterNav.getActive(),
currentPageName = currentView.component.name; currentPageName = currentView.component.name;
if (currentPageName != this.masterPageName) { if (currentPageName != this.masterPageName) {
// CurrentView is a 'Detail' page remove it from the 'master' nav stack. // CurrentView is a 'Detail' page remove it from the 'master' nav stack.
this._masterNav.pop(); this.masterNav.pop();
// and add it to the 'detail' nav stack. // and add it to the 'detail' nav stack.
this._detailNav.setRoot(currentView.component, currentView.data); this.detailNav.setRoot(currentView.component, currentView.data);
} else if (this.loadDetailPage) { } else if (this.loadDetailPage) {
// MasterPage is shown, load the last detail page if found. // MasterPage is shown, load the last detail page if found.
this._detailNav.setRoot(this.loadDetailPage.component, this.loadDetailPage.data); this.detailNav.setRoot(this.loadDetailPage.component, this.loadDetailPage.data);
} }
this.loadDetailPage = false; this.loadDetailPage = false;
} }
@ -137,11 +137,11 @@ export class CoreSplitViewComponent implements OnInit {
* Disabled the split view, show only one panel and do some magical navigation. * Disabled the split view, show only one panel and do some magical navigation.
*/ */
deactivateSplitView() { deactivateSplitView() {
let detailView = this._detailNav.getActive(), let detailView = this.detailNav.getActive(),
currentPageName = detailView.component.name; currentPageName = detailView.component.name;
if (currentPageName != 'CoreSplitViewPlaceholderPage') { if (currentPageName != 'CoreSplitViewPlaceholderPage') {
// Current detail view is a 'Detail' page so, not the placeholder page, push it on 'master' nav stack. // Current detail view is a 'Detail' page so, not the placeholder page, push it on 'master' nav stack.
this._masterNav.push(detailView.component, detailView.data); this.masterNav.push(detailView.component, detailView.data);
} }
} }
} }

View File

@ -22,7 +22,7 @@ import { CoreCoursesMyOverviewProvider } from '../providers/my-overview';
*/ */
@Injectable() @Injectable()
export class CoreCoursesMainMenuHandler implements CoreMainMenuHandler { export class CoreCoursesMainMenuHandler implements CoreMainMenuHandler {
name = 'mmCourses'; name = 'CoreCourses';
priority = 1100; priority = 1100;
isOverviewEnabled: boolean; isOverviewEnabled: boolean;