Skip to content

Commit

Permalink
MOBILE-4460 core: Hide informative links if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou committed Nov 15, 2023
1 parent ee9daad commit b668af1
Show file tree
Hide file tree
Showing 25 changed files with 106 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export class AddonModForumPostOptionsMenuComponent implements OnInit {
*/
protected setOpenInBrowserUrl(): void {
const site = CoreSites.getRequiredCurrentSite();
if (!CoreSites.shouldDisplayInformativeLinks(site)) {
return;
}

this.url = site.createSiteUrl('/mod/forum/discuss.php', { d: this.post.discussionid.toString() }, 'p' + this.post.id);
}

Expand Down
5 changes: 4 additions & 1 deletion src/addons/mod/forum/pages/discussion/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,11 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
return;
}

const currentSite = CoreSites.getCurrentSite();
this.isOnline = CoreNetwork.isOnline();
this.externalUrl = CoreSites.getCurrentSite()?.createSiteUrl('/mod/forum/discuss.php', { d: this.discussionId.toString() });
this.externalUrl = currentSite && CoreSites.shouldDisplayInformativeLinks(currentSite) ?
currentSite.createSiteUrl('/mod/forum/discuss.php', { d: this.discussionId.toString() }) :
undefined;
this.onlineObserver = CoreNetwork.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/sites-list/sites-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<h2>
<core-format-text [text]="site.siteName" clean="true" [siteId]="site.id"></core-format-text>
</h2>
<p *ngIf="!site.isDemoModeSite">
<p *ngIf="displaySiteUrl(site)">
<a [href]="site.siteUrl" core-link [autoLogin]="isCurrentSite ? 'yes' : 'no'">
{{ site.siteUrlWithoutProtocol }}
</a>
Expand Down
12 changes: 11 additions & 1 deletion src/core/components/sites-list/sites-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import { Component, ContentChild, Input, Output, TemplateRef, EventEmitter } from '@angular/core';

import { CoreSiteBasicInfo } from '@services/sites';
import { CoreSiteBasicInfo, CoreSites } from '@services/sites';
import { CoreAccountsList } from '@features/login/services/login-helper';

/**
Expand Down Expand Up @@ -77,4 +77,14 @@ export class CoreSitesListComponent<T extends CoreSiteBasicInfo> {
this.onSiteClicked.emit(site);
}

/**
* Check whether site URL should be displayed.
*
* @param site Site to check.
* @returns Whether to display URL.
*/
displaySiteUrl(site: CoreSiteBasicInfo): boolean {
return CoreSites.shouldDisplayInformativeLinks(site.siteUrl);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1>{{ 'core.contentlinks.chooseaccount' | translate }}</h1>
<ion-item class="ion-text-wrap">
<ion-label>
<h2 class="item-heading">{{ 'core.contentlinks.chooseaccounttoopenlink' | translate }}</h2>
<p>{{ url }}</p>
<p *ngIf="displaySiteUrl">{{ url }}</p>
</ion-label>
</ion-item>
<ion-item *ngFor="let site of sites" (click)="siteClicked(site.id)" detail="false" button>
Expand All @@ -27,7 +27,7 @@ <h2 class="item-heading">{{ 'core.contentlinks.chooseaccounttoopenlink' | transl
<p>
<core-format-text [text]="site.siteName" clean="true" [siteId]="site.id"></core-format-text>
</p>
<p *ngIf="!site.isDemoModeSite">{{site.siteUrl}}</p>
<p *ngIf="displaySiteUrl">{{site.siteUrl}}</p>
</ion-label>
</ion-item>
</ion-list>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class CoreContentLinksChooseSiteModalComponent implements OnInit {

sites: CoreSiteBasicInfo[] = [];
loaded = false;
displaySiteUrl = false;
protected action?: CoreContentLinksAction;
protected isRootURL = false;

Expand Down Expand Up @@ -70,6 +71,9 @@ export class CoreContentLinksChooseSiteModalComponent implements OnInit {

// Get the sites that can perform the action.
this.sites = await CoreSites.getSites(siteIds);

// All sites have the same URL, use the first one.
this.displaySiteUrl = CoreSites.shouldDisplayInformativeLinks(this.sites[0].siteUrl);
} catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'core.contentlinks.errornosites', true);
this.closeModal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class CoreCourseModuleSummaryComponent implements OnInit, OnDestroy {
}

this.displayOptions = Object.assign({
displayOpenInBrowser: true,
displayOpenInBrowser: CoreSites.shouldDisplayInformativeLinks(),
displayDescription: true,
displayRefresh: true,
displayPrefetch: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h1>
</ion-label>
</ion-chip>
</ion-label>
<ion-button fill="clear" [href]="courseUrl" core-link [showBrowserWarning]="false"
<ion-button *ngIf="displayOpenInBrowser" fill="clear" [href]="courseUrl" core-link [showBrowserWarning]="false"
[attr.aria-label]="'core.openinbrowser' | translate" slot="end">
<ion-icon name="fas-up-right-from-square" slot="icon-only" aria-hidden="true"></ion-icon>
</ion-button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
courseUrl = '';
progress?: number;
courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = [];
displayOpenInBrowser = false;

protected actionSheet?: HTMLIonActionSheetElement;
protected waitStart = 0;
Expand Down Expand Up @@ -137,6 +138,7 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
const currentSiteUrl = CoreSites.getRequiredCurrentSite().getURL();
this.enrolUrl = CorePath.concatenatePaths(currentSiteUrl, 'enrol/index.php?id=' + this.courseId);
this.courseUrl = CorePath.concatenatePaths(currentSiteUrl, 'course/view.php?id=' + this.courseId);
this.displayOpenInBrowser = CoreSites.shouldDisplayInformativeLinks();

await this.getCourse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ <h1>
</ion-title>

<ion-buttons slot="end">
<ion-button fill="clear" *ngIf="module.url && module.uservisible && !unsupported" [href]="module.url" core-link
[showBrowserWarning]="false" [attr.aria-label]="'core.openinbrowser' | translate">
<ion-button fill="clear" *ngIf="displayOpenInBrowser && module.url && module.uservisible && !unsupported" [href]="module.url"
core-link [showBrowserWarning]="false" [attr.aria-label]="'core.openinbrowser' | translate">
<ion-icon name="fas-up-right-from-square" slot="icon-only" aria-hidden="true"></ion-icon>
</ion-button>
<ion-button fill="clear" (click)="openModuleSummary()" aria-haspopup="true" [attr.aria-label]="'core.info' | translate">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { CoreCourseHelper, CoreCourseModuleData, CoreCourseSection } from '@feat
import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate';
import { IonRefresher } from '@ionic/angular';
import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils';

Expand All @@ -43,6 +44,7 @@ export class CoreCourseModulePreviewPage implements OnInit {
unsupported = false;
isDisabledInSite = false;
showManualCompletion = false;
displayOpenInBrowser = false;

protected debouncedUpdateModule?: () => void; // Update the module after a certain time.

Expand All @@ -62,6 +64,7 @@ export class CoreCourseModulePreviewPage implements OnInit {
return;
}

this.displayOpenInBrowser = CoreSites.shouldDisplayInformativeLinks();
this.debouncedUpdateModule = CoreUtils.debounce(() => {
this.doRefresh();
}, 10000);
Expand Down
2 changes: 1 addition & 1 deletion src/core/features/login/pages/credentials/credentials.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h1>{{ 'core.login.login' | translate }}</h1>
<h2 *ngIf="siteName" class="ion-margin-top ion-no-padding core-sitename">
<core-format-text [text]="siteName" [filter]="false"></core-format-text>
</h2>
<p class="core-siteurl" *ngIf="!isDemoModeSite">{{siteUrl}}</p>
<p class="core-siteurl" *ngIf="displaySiteUrl">{{siteUrl}}</p>
</div>

<core-login-exceeded-attempts *ngIf="exceededAttemptsHTML && supportConfig && loginAttempts >= 3"
Expand Down
2 changes: 2 additions & 0 deletions src/core/features/login/pages/credentials/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
siteConfig?: CoreSitePublicConfigResponse;
siteCheckError = '';
isDemoModeSite = false;
displaySiteUrl = false;

protected siteCheck?: CoreSiteCheckResponse;
protected eventThrown = false;
Expand Down Expand Up @@ -97,6 +98,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
undefined;
this.urlToOpen = CoreNavigator.getRouteParam('urlToOpen');
this.supportConfig = this.siteConfig && new CoreUserGuestSupportConfig(this.siteConfig);
this.displaySiteUrl = CoreSites.shouldDisplayInformativeLinks(this.siteUrl);
} catch (error) {
CoreDomUtils.showErrorModal(error);

Expand Down
4 changes: 2 additions & 2 deletions src/core/features/login/pages/email-signup/email-signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ <h2>{{ 'core.agelocationverification' | translate }}</h2>
<ion-item class="ion-text-wrap ion-text-center">
<ion-label>
<!-- If no sitename show big siteurl. -->
<p *ngIf="!siteName && !isDemoModeSite" class="ion-padding item-heading">{{siteUrl}}</p>
<p *ngIf="!siteName && displaySiteUrl" class="ion-padding item-heading">{{siteUrl}}</p>
<!-- If sitename, show big sitename and small siteurl. -->
<p *ngIf="siteName" class="ion-padding item-heading">
<core-format-text [text]="siteName" [filter]="false"></core-format-text>
</p>
<p *ngIf="siteName">{{siteUrl}}</p>
<p *ngIf="siteName && displaySiteUrl">{{siteUrl}}</p>
</ion-label>
</ion-item>

Expand Down
2 changes: 2 additions & 0 deletions src/core/features/login/pages/email-signup/email-signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class CoreLoginEmailSignupPage implements OnInit {
signupForm: FormGroup;
siteUrl!: string;
isDemoModeSite = false;
displaySiteUrl = false;
siteConfig?: CoreSitePublicConfigResponse;
siteName?: string;
authInstructions = '';
Expand Down Expand Up @@ -130,6 +131,7 @@ export class CoreLoginEmailSignupPage implements OnInit {

this.siteUrl = siteUrl;
this.isDemoModeSite = CoreLoginHelper.isDemoModeSite(this.siteUrl);
this.displaySiteUrl = CoreSites.shouldDisplayInformativeLinks(this.siteUrl);

// Fetch the data.
this.fetchData().finally(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/features/login/pages/reconnect/reconnect.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h1>{{ 'core.login.reconnect' | translate }}</h1>
<p *ngIf="siteInfo?.siteName" class="ion-no-margin ion-no-padding core-sitename">
<core-format-text [text]="siteInfo?.siteName" [filter]="false"></core-format-text>
</p>
<p class="core-siteurl" *ngIf="!isDemoModeSite">{{siteUrl}}</p>
<p class="core-siteurl" *ngIf="displaySiteUrl">{{siteUrl}}</p>
</div>

<div class="core-login-user">
Expand Down
3 changes: 2 additions & 1 deletion src/core/features/login/pages/reconnect/reconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
siteUrl!: string;
isDemoModeSite = false;
logoUrl?: string;
displaySiteUrl = false;
showForgottenPassword = true;
showUserAvatar = false;
isBrowserSSO = false;
Expand Down Expand Up @@ -103,6 +104,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {

this.siteUrl = site.getURL();
this.isDemoModeSite = site.isDemoModeSite();
this.displaySiteUrl = CoreSites.shouldDisplayInformativeLinks(site);

this.siteInfo = {
id: this.siteId,
Expand All @@ -114,7 +116,6 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
siteName: await site.getSiteName(),
userpictureurl: site.infos.userpictureurl,
loggedOut: true, // Not used.
isDemoModeSite: this.isDemoModeSite,
};

this.username = site.infos.username;
Expand Down
2 changes: 1 addition & 1 deletion src/core/features/login/pages/site/site.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ <h2 class="item-heading">{{ 'core.login.selectsite' | translate }}</h2>
</ion-thumbnail>
<ion-label>
<p *ngIf="site.title" class="item-heading ion-text-wrap">{{site.title}}</p>
<p *ngIf="site.noProtocolUrl">{{site.noProtocolUrl}}</p>
<p *ngIf="displaySiteUrl(site.noProtocolUrl)">{{site.noProtocolUrl}}</p>
<p *ngIf="site.location">{{site.location}}</p>
</ion-label>
</ion-item>
Expand Down
14 changes: 14 additions & 0 deletions src/core/features/login/pages/site/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,20 @@ export class CoreLoginSitePage implements OnInit {
CoreNavigator.navigate('/settings');
}

/**
* Check whether site URL should be displayed.
*
* @param siteUrl Site URL.
* @returns Whether to display URL.
*/
displaySiteUrl(siteUrl?: string): boolean {
if (!siteUrl) {
return false;
}

return CoreSites.shouldDisplayInformativeLinks(siteUrl);
}

}

/**
Expand Down
18 changes: 16 additions & 2 deletions src/core/features/mainmenu/components/user-menu/user-menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ <h1>
<ion-content>
<core-loading [hideUntil]="siteLogoLoaded && handlersLoaded">
<ion-list>
<ion-item button class="core-usermenu-siteinfo ion-text-wrap" *ngIf="siteInfo" lines="full" detail="false" [href]="siteUrl"
core-link auto-login="yes">
<!-- Site info with URL and clickable. -->
<ion-item button class="core-usermenu-siteinfo ion-text-wrap" *ngIf="siteInfo && displaySiteUrl" lines="full" detail="false"
[href]="siteUrl" core-link auto-login="yes">
<ion-label>
<!-- Show site logo. -->
<img class="core-usermenu-site-logo" *ngIf="siteLogo && siteLogoLoaded" [src]="siteLogo" role="presentation" alt=""
Expand All @@ -28,6 +29,19 @@ <h1>
<a [href]="siteUrl" core-link auto-login="yes" class="core-usermenu-siteurl">{{ siteUrl }}</a>
</ion-label>
</ion-item>
<!-- Site info without URL and not clickable. -->
<ion-item class="core-usermenu-siteinfo ion-text-wrap" *ngIf="siteInfo && !displaySiteUrl" lines="full" detail="false">
<ion-label>
<!-- Show site logo. -->
<img class="core-usermenu-site-logo" *ngIf="siteLogo && siteLogoLoaded" [src]="siteLogo" role="presentation" alt=""
onError="this.class='image-not-found'">
<p class="core-usermenu-sitename">
<core-format-text [text]="siteName" contextLevel="system" [contextInstanceId]="0" [wsNotFiltered]="true">
</core-format-text>
</p>
</ion-label>
</ion-item>

<ion-item button class="core-usermenu-handler ion-text-wrap" *ngIf="siteInfo" lines="full" (click)="openUserProfile($event)"
detail="true" [attr.aria-label]="'core.user.profile' | translate">
<core-user-avatar [user]="siteInfo" [userId]="siteInfo.userid" [linkProfile]="false" slot="start"></core-user-avatar>
Expand Down
2 changes: 2 additions & 0 deletions src/core/features/mainmenu/components/user-menu/user-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
siteLogo?: string;
siteLogoLoaded = false;
siteUrl?: string;
displaySiteUrl = false;
handlers: CoreUserProfileHandlerData[] = [];
handlersLoaded = false;
user?: CoreUserProfile;
Expand All @@ -70,6 +71,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
this.displaySwitchAccount = !currentSite.isFeatureDisabled('NoDelegate_SwitchAccount');
this.displayContactSupport = new CoreUserAuthenticatedSupportConfig(currentSite).canContactSupport();
this.removeAccountOnLogout = !!CoreConstants.CONFIG.removeaccountonlogout;
this.displaySiteUrl = CoreSites.shouldDisplayInformativeLinks(currentSite);

this.loadSiteLogo(currentSite);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h1>
<p class="item-heading">{{ 'core.settings.siteinfo' | translate }}<ng-container *ngIf="deviceInfo.isPrefixedUrl">
*</ng-container>
</p>
<p><a [href]="deviceInfo.siteUrl" core-link auto-login="yes">{{ deviceInfo.siteUrl }}</a></p>
<p *ngIf="displaySiteUrl"><a [href]="deviceInfo.siteUrl" core-link auto-login="yes">{{ deviceInfo.siteUrl }}</a></p>
<p *ngIf="deviceInfo.siteVersion">{{ deviceInfo.siteVersion }}</p>
<p *ngIf="deviceInfo.siteId">{{ deviceInfo.siteId }}</p>
</ion-label>
Expand Down
2 changes: 2 additions & 0 deletions src/core/features/settings/pages/deviceinfo/deviceinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy {
currentLangName?: string;
fsClickable = false;
showDevOptions = false;
displaySiteUrl = false;
protected devOptionsClickCounter = 0;
protected devOptionsForced = false;
protected devOptionsClickTimeout?: number;
Expand Down Expand Up @@ -201,6 +202,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy {

this.deviceInfo.siteUrl = currentSite?.getURL() || firstUrl || undefined;
this.deviceInfo.isPrefixedUrl = !!sites.length;
this.displaySiteUrl = !!this.deviceInfo.siteUrl && CoreSites.shouldDisplayInformativeLinks(this.deviceInfo.siteUrl);

if (fileProvider.isAvailable()) {
const basepath = await fileProvider.getBasePath();
Expand Down
Loading

0 comments on commit b668af1

Please sign in to comment.