From 302f58b56d21a18da2250ceacf789aa9572b1530 Mon Sep 17 00:00:00 2001 From: dpalou Date: Thu, 27 Sep 2018 12:24:55 +0200 Subject: [PATCH] MOBILE-2601 calendar: Display location in calendar events --- src/addon/calendar/pages/event/event.html | 14 +++++++++++--- src/addon/calendar/pages/event/event.ts | 6 ++++++ src/core/user/pages/about/about.ts | 13 +++++-------- src/lang/en.json | 1 + src/providers/utils/text.ts | 19 ++++++++++++++++--- 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/addon/calendar/pages/event/event.html b/src/addon/calendar/pages/event/event.html index dcef19bcc..7ce5ba25e 100644 --- a/src/addon/calendar/pages/event/event.html +++ b/src/addon/calendar/pages/event/event.html @@ -9,7 +9,7 @@ - + @@ -33,11 +33,19 @@ {{event.moduleName}} - -

+ +

+ +

{{ 'core.location' | translate}}

+

+ + + +

+
{{ 'addon.calendar.gotoactivity' | translate }} diff --git a/src/addon/calendar/pages/event/event.ts b/src/addon/calendar/pages/event/event.ts index 1ddac25d8..f8e3dec31 100644 --- a/src/addon/calendar/pages/event/event.ts +++ b/src/addon/calendar/pages/event/event.ts @@ -166,6 +166,12 @@ export class AddonCalendarEventPage { this.categoryPath = event.category.nestedname; } + if (event.location) { + // Build a link to open the address in maps. + event.location = this.textUtils.decodeHTML(event.location); + event.encodedLocation = this.textUtils.buildAddressURL(event.location); + } + return Promise.all(promises); }).catch((error) => { this.domUtils.showErrorModalDefault(error, 'addon.calendar.errorloadevent', true); diff --git a/src/core/user/pages/about/about.ts b/src/core/user/pages/about/about.ts index 2054e9754..baed48158 100644 --- a/src/core/user/pages/about/about.ts +++ b/src/core/user/pages/about/about.ts @@ -13,13 +13,13 @@ // limitations under the License. import { Component } from '@angular/core'; -import { DomSanitizer } from '@angular/platform-browser'; -import { IonicPage, NavParams, Platform } from 'ionic-angular'; +import { IonicPage, NavParams } from 'ionic-angular'; import { CoreUserProvider } from '../../providers/user'; import { CoreUserHelperProvider } from '../../providers/helper'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreEventsProvider } from '@providers/events'; import { CoreSitesProvider } from '@providers/sites'; +import { CoreTextUtilsProvider } from '@providers/utils/text'; /** * Page that displays an user about page. @@ -37,17 +37,15 @@ export class CoreUserAboutPage { userLoaded = false; hasContact = false; hasDetails = false; - isAndroid = false; user: any = {}; title: string; constructor(navParams: NavParams, private userProvider: CoreUserProvider, private userHelper: CoreUserHelperProvider, - private domUtils: CoreDomUtilsProvider, private eventsProvider: CoreEventsProvider, private sanitizer: DomSanitizer, - private sitesProvider: CoreSitesProvider, private platform: Platform) { + private domUtils: CoreDomUtilsProvider, private eventsProvider: CoreEventsProvider, + private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider) { this.userId = navParams.get('userId'); this.courseId = navParams.get('courseId'); - this.isAndroid = this.platform.is('android'); this.siteId = this.sitesProvider.getCurrentSite().getId(); } @@ -69,8 +67,7 @@ export class CoreUserAboutPage { if (user.address) { user.address = this.userHelper.formatAddress(user.address, user.city, user.country); - user.encodedAddress = this.sanitizer.bypassSecurityTrustUrl( - (this.isAndroid ? 'geo:0,0?q=' : 'http://maps.google.com?q=') + encodeURIComponent(user.address)); + user.encodedAddress = this.textUtils.buildAddressURL(user.address); } this.hasContact = user.email || user.phone1 || user.phone2 || user.city || user.country || user.address; diff --git a/src/lang/en.json b/src/lang/en.json index e7920978d..50b27e26b 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -117,6 +117,7 @@ "listsep": ",", "loading": "Loading", "loadmore": "Load more", + "location": "Location", "lostconnection": "Your authentication token is invalid or has expired, you will have to reconnect to the site.", "maxsizeandattachments": "Maximum size for new files: {{$a.size}}, maximum attachments: {{$a.attachments}}", "min" : "min", diff --git a/src/providers/utils/text.ts b/src/providers/utils/text.ts index 4e5ebe842..6fa91d8be 100644 --- a/src/providers/utils/text.ts +++ b/src/providers/utils/text.ts @@ -13,7 +13,8 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { ModalController } from 'ionic-angular'; +import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; +import { ModalController, Platform } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; import { CoreLangProvider } from '../lang'; @@ -70,7 +71,19 @@ export class CoreTextUtilsProvider { protected template = document.createElement('template'); // A template element to convert HTML to element. - constructor(private translate: TranslateService, private langProvider: CoreLangProvider, private modalCtrl: ModalController) { } + constructor(private translate: TranslateService, private langProvider: CoreLangProvider, private modalCtrl: ModalController, + private sanitizer: DomSanitizer, private platform: Platform) { } + + /** + * Given an address as a string, return a URL to open the address in maps. + * + * @param {string} address The address. + * @return {SafeUrl} URL to view the address. + */ + buildAddressURL(address: string): SafeUrl { + return this.sanitizer.bypassSecurityTrustUrl((this.platform.is('android') ? 'geo:0,0?q=' : 'http://maps.google.com?q=') + + encodeURIComponent(address)); + } /** * Given a list of sentences, build a message with all of them wrapped in

. @@ -231,7 +244,7 @@ export class CoreTextUtilsProvider { .replace(/</g, '<') .replace(/>/g, '>') .replace(/"/g, '"') - .replace(/'/g, '') + .replace(/'/g, '\'') .replace(/ /g, ' '); }