Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ export const enum LMSBadgeStyle {
INFO = 'info',
}

export enum CoreLinkOpenMethod {
APP = 'app',
INAPPBROWSER = 'inappbrowser',
BROWSER = 'browser',
EMBEDDED = 'embedded',
}

/**
* Static class to contain all the core constants.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/core/directives/external-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { CoreLogger } from '@singletons/logger';
import { CoreError } from '@classes/errors/error';
import { CoreSite } from '@classes/sites/site';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { DownloadStatus } from '../constants';
import { CoreLinkOpenMethod, DownloadStatus } from '../constants';
import { CoreNetwork } from '@services/network';
import { Translate } from '@singletons';
import { AsyncDirective } from '@classes/async-directive';
Expand Down Expand Up @@ -370,7 +370,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O
const tagName = this.element.tagName;
const openIn = tagName === 'A' && this.element.getAttribute('data-open-in');

if (openIn === 'app' || openIn === 'browser') {
if (openIn === CoreLinkOpenMethod.APP || openIn === CoreLinkOpenMethod.BROWSER) {
// The file is meant to be opened in browser or InAppBrowser, don't use the downloaded URL because it won't work.
if (!site.isSitePluginFileUrl(url)) {
return url;
Expand Down
4 changes: 2 additions & 2 deletions src/core/directives/format-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { MediaElementController } from '@classes/element-controllers/MediaElemen
import { FrameElement, FrameElementController } from '@classes/element-controllers/FrameElementController';
import { CoreUrl } from '@singletons/url';
import { CoreIcons } from '@singletons/icons';
import { ContextLevel } from '../constants';
import { ContextLevel, CoreLinkOpenMethod } from '../constants';
import { CoreWait } from '@singletons/wait';
import { toBoolean } from '../transforms/boolean';
import { CoreViewer } from '@features/viewer/services/viewer';
Expand Down Expand Up @@ -839,7 +839,7 @@ export class CoreFormatTextDirective implements OnDestroy, AsyncDirective {
// Try to convert the URL to absolute if needed.
url = CoreUrl.toAbsoluteURL(site.getURL(), url);
const confirmMessage = element.dataset.appUrlConfirm;
const openInApp = element.dataset.openIn === 'app';
const openInApp = element.dataset.openIn === CoreLinkOpenMethod.APP;
const refreshOnResume = element.dataset.appUrlResumeAction === 'refresh';

if (confirmMessage) {
Expand Down
6 changes: 3 additions & 3 deletions src/core/directives/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CoreFileHelper } from '@services/file-helper';
import { CoreSites } from '@services/sites';
import { CoreUrl } from '@singletons/url';
import { CoreOpener } from '@singletons/opener';
import { CoreConstants } from '@/core/constants';
import { CoreConstants, CoreLinkOpenMethod } from '@/core/constants';
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
import { CoreCustomURLSchemes } from '@services/urlschemes';
import { DomSanitizer } from '@singletons';
Expand Down Expand Up @@ -187,8 +187,8 @@ export class CoreLinkDirective implements OnInit {
protected async openExternalLink(href: string, openIn?: string | null): Promise<void> {
// Priority order is: core-link inApp attribute > forceOpenLinksIn setting > data-open-in HTML attribute.
const openInApp = this.inApp ??
(CoreConstants.CONFIG.forceOpenLinksIn !== 'browser' &&
(CoreConstants.CONFIG.forceOpenLinksIn === 'app' || openIn === 'app'));
(CoreConstants.CONFIG.forceOpenLinksIn !== CoreLinkOpenMethod.BROWSER &&
(CoreConstants.CONFIG.forceOpenLinksIn === CoreLinkOpenMethod.APP || openIn === CoreLinkOpenMethod.APP));

// Check if we need to auto-login.
if (!CoreSites.isLoggedIn()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@if (type() !== 'embedded') {
<ion-item button [href]="url()" [attr.aria-label]="label()" core-link [capture]="type() === 'app'"
[inApp]="type() === 'inappbrowser'" class="core-usermenu-customitem" [detail]="true"
[detailIcon]="type() === 'browser' ? 'open-outline' : 'chevron-forward'">
<ion-icon [name]="icon()" slot="start" aria-hidden="true" />
<ion-label>
<p class="item-heading">{{label()}}</p>
</ion-label>
</ion-item>
} @else {
<ion-item button (click)="openItem()" [attr.aria-label]="label()" class="core-usermenu-customitem" [detail]="true">
<ion-icon [name]="icon()" slot="start" aria-hidden="true" />
<ion-label>
<p class="item-heading">{{label()}}</p>
</ion-label>
</ion-item>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// (C) Copyright 2015 Moodle Pty Ltd.
//
// 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.

import { CoreLinkOpenMethod } from '@/core/constants';
import { CoreSharedModule } from '@/core/shared.module';
import { Component, input } from '@angular/core';
import { CoreViewer } from '@features/viewer/services/viewer';

/**
* Component to display a custom menu item.
*/
@Component({
selector: 'core-custom-menu-item',
templateUrl: 'custom-menu-item.html',
imports: [
CoreSharedModule,
],
})
export class CoreCustomMenuItemComponent {

/**
* Type of the item: app, inappbrowser, browser or embedded.
*/
readonly type = input.required<CoreLinkOpenMethod>();

/**
* Url of the item.
*/
readonly url = input.required<string>();

/**
* Label to display for the item.
*/
readonly label = input.required<string>();

/**
* Name of the icon to display for the item.
*/
readonly icon = input.required<string>();

/**
* Open an embedded custom item.
*/
openItem(): void {
CoreViewer.openIframeViewer(this.label(), this.url());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ <h1>
}
</ion-item>

@for (item of customItems; track item) {
<core-custom-menu-item [type]="item.type" [label]="item.label" [icon]="item.icon" [url]="item.url" />
}

<ion-item button *ngFor="let handler of accountHandlers; let first = first"
(click)="handlerClicked($event, handler)"
[class]="['ion-text-wrap', 'core-user-account-menu-handler', handler.class]"
Expand Down
13 changes: 13 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 @@ -34,6 +34,8 @@ import { Subscription } from 'rxjs';
import { CoreLoginHelper } from '@features/login/services/login-helper';
import { CoreSiteLogoComponent } from '@/core/components/site-logo/site-logo';
import { CoreAlerts } from '@services/overlays/alerts';
import { CoreCustomMenu, CoreCustomMenuItem } from '@features/mainmenu/services/custommenu';
import { CoreCustomMenuItemComponent } from '../custom-menu-item/custom-menu-item';

/**
* Component to display a user menu.
Expand All @@ -45,6 +47,7 @@ import { CoreAlerts } from '@services/overlays/alerts';
imports: [
CoreSharedModule,
CoreSiteLogoComponent,
CoreCustomMenuItemComponent,
],
})
export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
Expand All @@ -53,6 +56,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
siteUrl?: string;
displaySiteUrl = false;
handlers: CoreUserProfileHandlerData[] = [];
customItems?: CoreCustomMenuItem[];
accountHandlers: CoreUserProfileHandlerData[] = [];
handlersLoaded = false;
user?: CoreUserProfile;
Expand All @@ -78,6 +82,8 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
this.removeAccountOnLogout = !!CoreConstants.CONFIG.removeaccountonlogout;
this.displaySiteUrl = currentSite.shouldDisplayInformativeLinks();

this.loadCustomMenuItems();

if (!this.siteInfo) {
return;
}
Expand Down Expand Up @@ -122,6 +128,13 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
});
}

/**
* Load custom menu items.
*/
protected async loadCustomMenuItems(): Promise<void> {
this.customItems = await CoreCustomMenu.getUserCustomMenuItems();
}

/**
* Opens User profile page.
*
Expand Down
22 changes: 3 additions & 19 deletions src/core/features/mainmenu/pages/more/more.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,9 @@ <h1>{{ 'core.more' | translate }}</h1>
}
}
</ion-item>
<ng-container *ngFor="let item of customItems">
@if (item.type !== 'embedded') {
<ion-item button [href]="item.url" [attr.aria-label]="item.label" core-link [capture]="item.type === 'app'"
[inApp]="item.type === 'inappbrowser'" class="core-moremenu-customitem" [detail]="true"
[detailIcon]="item.type === 'browser' ? 'open-outline' : 'chevron-forward'">
<ion-icon [name]="item.icon" slot="start" aria-hidden="true" />
<ion-label>
<p class="item-heading">{{item.label}}</p>
</ion-label>
</ion-item>
} @else {
<ion-item button (click)="openItem(item)" [attr.aria-label]="item.label" class="core-moremenu-customitem" [detail]="true">
<ion-icon [name]="item.icon" slot="start" aria-hidden="true" />
<ion-label>
<p class="item-heading">{{item.label}}</p>
</ion-label>
</ion-item>
}
</ng-container>
@for (item of customItems; track item) {
<core-custom-menu-item [type]="item.type" [label]="item.label" [icon]="item.icon" [url]="item.url" />
}
@if (showScanQR) {
<ion-item button (click)="scanQR()" [detail]="true">
<ion-icon name="fas-qrcode" slot="start" aria-hidden="true" />
Expand Down
20 changes: 7 additions & 13 deletions src/core/features/mainmenu/pages/more/more.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Subscription } from 'rxjs';
import { CoreSites } from '@services/sites';
import { CoreQRScan } from '@services/qrscan';
import { CoreMainMenuDelegate, CoreMainMenuHandlerData } from '../../services/mainmenu-delegate';
import { CoreMainMenu, CoreMainMenuCustomItem } from '../../services/mainmenu';
import { CoreMainMenu } from '../../services/mainmenu';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreNavigator } from '@services/navigator';
import { Translate } from '@singletons';
Expand All @@ -28,6 +28,8 @@ import { CoreSharedModule } from '@/core/shared.module';
import { CoreMainMenuUserButtonComponent } from '../../components/user-menu-button/user-menu-button';
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
import { CoreUrl } from '@singletons/url';
import { CoreCustomMenu, CoreCustomMenuItem } from '@features/mainmenu/services/custommenu';
import { CoreCustomMenuItemComponent } from '@features/mainmenu/components/custom-menu-item/custom-menu-item';

/**
* Page that displays the more page of the app.
Expand All @@ -39,14 +41,15 @@ import { CoreUrl } from '@singletons/url';
imports: [
CoreSharedModule,
CoreMainMenuUserButtonComponent,
CoreCustomMenuItemComponent,
],
})
export default class CoreMainMenuMorePage implements OnInit, OnDestroy {

handlers?: CoreMainMenuHandlerData[];
handlersLoaded = false;
showScanQR: boolean;
customItems?: CoreMainMenuCustomItem[];
customItems?: CoreCustomMenuItem[];

protected allHandlers?: CoreMainMenuHandlerData[];
protected subscription!: Subscription;
Expand All @@ -58,7 +61,7 @@ export default class CoreMainMenuMorePage implements OnInit, OnDestroy {
this.langObserver = CoreEvents.on(CoreEvents.LANGUAGE_CHANGED, () => this.loadCustomMenuItems());

this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, async () => {
this.customItems = await CoreMainMenu.getCustomMenuItems();
this.customItems = await CoreCustomMenu.getCustomMainMenuItems();
}, CoreSites.getCurrentSiteId());

this.loadCustomMenuItems();
Expand Down Expand Up @@ -118,7 +121,7 @@ export default class CoreMainMenuMorePage implements OnInit, OnDestroy {
* Load custom menu items.
*/
protected async loadCustomMenuItems(): Promise<void> {
this.customItems = await CoreMainMenu.getCustomMenuItems();
this.customItems = await CoreCustomMenu.getCustomMainMenuItems();
}

/**
Expand All @@ -132,15 +135,6 @@ export default class CoreMainMenuMorePage implements OnInit, OnDestroy {
CoreNavigator.navigateToSitePath(handler.page, { params });
}

/**
* Open an embedded custom item.
*
* @param item Item to open.
*/
openItem(item: CoreMainMenuCustomItem): void {
CoreViewer.openIframeViewer(item.label, item.url);
}

/**
* Open settings.
*/
Expand Down
Loading