MOBILE-4460 core: Hide informative links if needed

main
Dani Palou 2023-11-15 12:32:25 +01:00
parent ee9daad783
commit b668af193b
25 changed files with 106 additions and 20 deletions

View File

@ -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);
}

View File

@ -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(() => {

View File

@ -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>

View File

@ -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';
/**
@ -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);
}
}

View File

@ -16,7 +16,7 @@
<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>
@ -27,7 +27,7 @@
<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>

View File

@ -34,6 +34,7 @@ export class CoreContentLinksChooseSiteModalComponent implements OnInit {
sites: CoreSiteBasicInfo[] = [];
loaded = false;
displaySiteUrl = false;
protected action?: CoreContentLinksAction;
protected isRootURL = false;
@ -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();

View File

@ -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,

View File

@ -45,7 +45,7 @@
</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>

View File

@ -72,6 +72,7 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
courseUrl = '';
progress?: number;
courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = [];
displayOpenInBrowser = false;
protected actionSheet?: HTMLIonActionSheetElement;
protected waitStart = 0;
@ -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();
}

View File

@ -11,8 +11,8 @@
</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">

View File

@ -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';
@ -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.
@ -62,6 +64,7 @@ export class CoreCourseModulePreviewPage implements OnInit {
return;
}
this.displayOpenInBrowser = CoreSites.shouldDisplayInformativeLinks();
this.debouncedUpdateModule = CoreUtils.debounce(() => {
this.doRefresh();
}, 10000);

View File

@ -32,7 +32,7 @@
<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"

View File

@ -62,6 +62,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
siteConfig?: CoreSitePublicConfigResponse;
siteCheckError = '';
isDemoModeSite = false;
displaySiteUrl = false;
protected siteCheck?: CoreSiteCheckResponse;
protected eventThrown = false;
@ -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);

View File

@ -82,12 +82,12 @@
<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>

View File

@ -53,6 +53,7 @@ export class CoreLoginEmailSignupPage implements OnInit {
signupForm: FormGroup;
siteUrl!: string;
isDemoModeSite = false;
displaySiteUrl = false;
siteConfig?: CoreSitePublicConfigResponse;
siteName?: string;
authInstructions = '';
@ -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(() => {

View File

@ -40,7 +40,7 @@
<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">

View File

@ -48,6 +48,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
siteUrl!: string;
isDemoModeSite = false;
logoUrl?: string;
displaySiteUrl = false;
showForgottenPassword = true;
showUserAvatar = false;
isBrowserSSO = false;
@ -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,
@ -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;

View File

@ -127,7 +127,7 @@
</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>

View File

@ -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);
}
}
/**

View File

@ -15,8 +15,9 @@
<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=""
@ -28,6 +29,19 @@
<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>

View File

@ -49,6 +49,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
siteLogo?: string;
siteLogoLoaded = false;
siteUrl?: string;
displaySiteUrl = false;
handlers: CoreUserProfileHandlerData[] = [];
handlersLoaded = false;
user?: CoreUserProfile;
@ -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);

View File

@ -42,7 +42,7 @@
<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>

View File

@ -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;
@ -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();

View File

@ -1329,7 +1329,6 @@ export class CoreSitesProvider {
userpictureurl: siteInfo?.userpictureurl,
siteHomeId: siteInfo?.siteid || 1,
loggedOut: !!site.loggedOut,
isDemoModeSite,
};
formattedSites.push(basicInfo);
}
@ -2138,6 +2137,30 @@ export class CoreSitesProvider {
);
}
/**
* Check whether informative links should be displayed for a certain site, or current site.
*
* @param siteOrUrl Site instance or site URL. If not defined, current site.
* @returns Whether informative links should be displayed.
*/
shouldDisplayInformativeLinks(siteOrUrl?: CoreSite | string): boolean {
if (CoreConstants.CONFIG.hideInformativeLinks) {
return false;
}
// Don't display informative links for demo sites either.
siteOrUrl = siteOrUrl ?? this.getCurrentSite();
if (!siteOrUrl) {
return true;
}
if (typeof siteOrUrl === 'string') {
return !CoreLoginHelper.isDemoModeSite(siteOrUrl);
} else {
return !siteOrUrl.isDemoModeSite();
}
}
}
export const CoreSites = makeSingleton(CoreSitesProvider);
@ -2209,7 +2232,6 @@ export type CoreSiteBasicInfo = {
badge?: number; // Badge to display in the site.
siteHomeId?: number; // Site home ID.
loggedOut: boolean; // If Site is logged out.
isDemoModeSite: boolean;
};
/**

View File

@ -74,4 +74,5 @@ export interface EnvironmentConfig {
callWSInBackgroundExpirationTime?: number; // Ms to consider an entry expired when calling WS in background. Default: 1 week.
disableTokenFile: boolean; // Disable the use of tokenpluginfile.php for downloading files (so it fallbacks to pluginfile.php)
demoMode?: boolean; // Whether to run the app in "demo mode".
hideInformativeLinks?: boolean; // Whether to hide informative links.
}