Merge pull request #2993 from crazyserver/MOBILE-3833

Mobile 3833
main
Dani Palou 2021-11-15 08:02:58 +01:00 committed by GitHub
commit 80f1b96f61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 168 additions and 141 deletions

View File

@ -15,7 +15,12 @@
import { Component, OnInit, OnDestroy, Input, OnChanges, SimpleChange } from '@angular/core'; import { Component, OnInit, OnDestroy, Input, OnChanges, SimpleChange } from '@angular/core';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreCoursesProvider, CoreCoursesMyCoursesUpdatedEventData, CoreCourses } from '@features/courses/services/courses'; import {
CoreCoursesProvider,
CoreCoursesMyCoursesUpdatedEventData,
CoreCourses,
CoreCourseSummaryData,
} from '@features/courses/services/courses';
import { CoreCourseSearchedDataWithExtraInfoAndOptions, CoreCoursesHelper } from '@features/courses/services/courses-helper'; import { CoreCourseSearchedDataWithExtraInfoAndOptions, CoreCoursesHelper } from '@features/courses/services/courses-helper';
import { CoreCourseHelper, CorePrefetchStatusInfo } from '@features/course/services/course-helper'; import { CoreCourseHelper, CorePrefetchStatusInfo } from '@features/course/services/course-helper';
import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate'; import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate';
@ -35,7 +40,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
@Input() downloadEnabled = false; @Input() downloadEnabled = false;
courses: CoreCourseSearchedDataWithExtraInfoAndOptions[] = []; courses: (Omit<CoreCourseSummaryData, 'visible'> & CoreCourseSearchedDataWithExtraInfoAndOptions)[] = [];
prefetchCoursesData: CorePrefetchStatusInfo = { prefetchCoursesData: CorePrefetchStatusInfo = {
icon: '', icon: '',
statusTranslatable: 'core.loading', statusTranslatable: 'core.loading',
@ -52,7 +57,6 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
protected isDestroyed = false; protected isDestroyed = false;
protected coursesObserver?: CoreEventObserver; protected coursesObserver?: CoreEventObserver;
protected updateSiteObserver?: CoreEventObserver; protected updateSiteObserver?: CoreEventObserver;
protected courseIds = [];
protected fetchContentDefaultError = 'Error getting recent courses data.'; protected fetchContentDefaultError = 'Error getting recent courses data.';
constructor() { constructor() {
@ -60,7 +64,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
} }
/** /**
* Component being initialized. * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
// Generate unique id for scroll element. // Generate unique id for scroll element.
@ -82,12 +86,8 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
this.coursesObserver = CoreEvents.on( this.coursesObserver = CoreEvents.on(
CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, CoreCoursesProvider.EVENT_MY_COURSES_UPDATED,
(data) => { (data) => {
this.refreshCourseList(data);
if (this.shouldRefreshOnUpdatedEvent(data)) {
this.refreshCourseList();
}
}, },
CoreSites.getCurrentSiteId(), CoreSites.getCurrentSiteId(),
); );
@ -95,7 +95,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
} }
/** /**
* Detect changes on input properties. * @inheritdoc
*/ */
ngOnChanges(changes: {[name: string]: SimpleChange}): void { ngOnChanges(changes: {[name: string]: SimpleChange}): void {
if (changes.downloadEnabled && !changes.downloadEnabled.previousValue && this.downloadEnabled && this.loaded) { if (changes.downloadEnabled && !changes.downloadEnabled.previousValue && this.downloadEnabled && this.loaded) {
@ -105,21 +105,35 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
} }
/** /**
* Perform the invalidate content function. * @inheritdoc
*
* @return Resolved when done.
*/ */
protected async invalidateContent(): Promise<void> { protected async invalidateContent(): Promise<void> {
const courseIds = this.courses.map((course) => course.id);
await this.invalidateCourses(courseIds);
}
/**
* Helper function to invalidate only selected courses.
*
* @param courseIds Course Id array.
* @return Promise resolved when done.
*/
protected async invalidateCourses(courseIds: number[]): Promise<void> {
const promises: Promise<void>[] = []; const promises: Promise<void>[] = [];
// Invalidate course completion data.
promises.push(CoreCourses.invalidateRecentCourses().finally(() => promises.push(CoreCourses.invalidateRecentCourses().finally(() =>
// Invalidate course completion data. CoreUtils.allPromises(courseIds.map((courseId) =>
CoreUtils.allPromises(this.courseIds.map((courseId) =>
AddonCourseCompletion.invalidateCourseCompletion(courseId))))); AddonCourseCompletion.invalidateCourseCompletion(courseId)))));
promises.push(CoreCourseOptionsDelegate.clearAndInvalidateCoursesOptions()); if (courseIds.length == 1) {
if (this.courseIds.length > 0) { promises.push(CoreCourseOptionsDelegate.clearAndInvalidateCoursesOptions(courseIds[0]));
promises.push(CoreCourses.invalidateCoursesByField('ids', this.courseIds.join(','))); } else {
promises.push(CoreCourseOptionsDelegate.clearAndInvalidateCoursesOptions());
}
if (courseIds.length > 0) {
promises.push(CoreCourses.invalidateCoursesByField('ids', courseIds.join(',')));
} }
await CoreUtils.allPromises(promises).finally(() => { await CoreUtils.allPromises(promises).finally(() => {
@ -128,9 +142,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
} }
/** /**
* Fetch the courses for recent courses. * @inheritdoc
*
* @return Promise resolved when done.
*/ */
protected async fetchContent(): Promise<void> { protected async fetchContent(): Promise<void> {
const showCategories = this.block.configsRecord && this.block.configsRecord.displaycategories && const showCategories = this.block.configsRecord && this.block.configsRecord.displaycategories &&
@ -140,17 +152,17 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
const courseIds = recentCourses.map((course) => course.id); const courseIds = recentCourses.map((course) => course.id);
// Get the courses using getCoursesByField to get more info about each course. // Get the courses using getCoursesByField to get more info about each course.
const courses: CoreCourseSearchedDataWithExtraInfoAndOptions[] = await CoreCourses.getCoursesByField( const courses = await CoreCourses.getCoursesByField('ids', courseIds.join(','));
'ids',
courseIds.join(','),
);
// Sort them in the original order. this.courses = recentCourses.map((recentCourse) => {
courses.sort((courseA, courseB) => courseIds.indexOf(courseA.id) - courseIds.indexOf(courseB.id)); const course = courses.find((course) => recentCourse.id == course.id);
return Object.assign(recentCourse, course);
});
// Get course options and extra info. // Get course options and extra info.
const options = await CoreCourses.getCoursesAdminAndNavOptions(courseIds); const options = await CoreCourses.getCoursesAdminAndNavOptions(courseIds);
courses.forEach((course) => { this.courses.forEach((course) => {
course.navOptions = options.navOptions[course.id]; course.navOptions = options.navOptions[course.id];
course.admOptions = options.admOptions[course.id]; course.admOptions = options.admOptions[course.id];
@ -161,24 +173,9 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
await CoreCoursesHelper.loadCoursesColorAndImage(courses); await CoreCoursesHelper.loadCoursesColorAndImage(courses);
this.courses = courses;
this.initPrefetchCoursesIcons(); this.initPrefetchCoursesIcons();
} }
/**
* Refresh the list of courses.
*
* @return Promise resolved when done.
*/
protected async refreshCourseList(): Promise<void> {
CoreEvents.trigger(CoreCoursesProvider.EVENT_MY_COURSES_REFRESHED);
await CoreUtils.ignoreErrors(CoreCourses.invalidateRecentCourses());
await this.loadContent(true);
}
/** /**
* Initialize the prefetch icon for selected courses. * Initialize the prefetch icon for selected courses.
*/ */
@ -194,44 +191,39 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
} }
/** /**
* Whether list should be refreshed based on a EVENT_MY_COURSES_UPDATED event. * Refresh course list based on a EVENT_MY_COURSES_UPDATED event.
* *
* @param data Event data. * @param data Event data.
* @return Whether to refresh. * @return Promise resolved when done.
*/ */
protected shouldRefreshOnUpdatedEvent(data: CoreCoursesMyCoursesUpdatedEventData): boolean { protected async refreshCourseList(data: CoreCoursesMyCoursesUpdatedEventData): Promise<void> {
if (data.action == CoreCoursesProvider.ACTION_ENROL) { if (data.action == CoreCoursesProvider.ACTION_ENROL) {
// Always update if user enrolled in a course. // Always update if user enrolled in a course.
return true; return await this.refreshContent();
} }
if (data.action == CoreCoursesProvider.ACTION_VIEW && data.courseId != CoreSites.getCurrentSiteHomeId() && const courseIndex = this.courses.findIndex((course) => course.id == data.courseId);
this.courses[0] && data.courseId != this.courses[0].id) { const course = this.courses[courseIndex];
// Update list if user viewed a course that isn't the most recent one and isn't site home. if (data.action == CoreCoursesProvider.ACTION_VIEW && data.courseId != CoreSites.getCurrentSiteHomeId()) {
return true; if (!course) {
// Not found, use WS update.
return await this.refreshContent();
}
// Place at the begining.
this.courses.splice(courseIndex, 1);
this.courses.unshift(course);
await this.invalidateCourses([course.id]);
} }
if (data.action == CoreCoursesProvider.ACTION_STATE_CHANGED && data.state == CoreCoursesProvider.STATE_FAVOURITE && if (data.action == CoreCoursesProvider.ACTION_STATE_CHANGED &&
data.courseId && this.hasCourse(data.courseId)) { data.state == CoreCoursesProvider.STATE_FAVOURITE && course) {
// Update list if a visible course is now favourite or unfavourite. course.isfavourite = !!data.value;
return true; await this.invalidateCourses([course.id]);
this.initPrefetchCoursesIcons();
} }
return false;
}
/**
* Check if a certain course is in the list of courses.
*
* @param courseId Course ID to search.
* @return Whether it's in the list.
*/
protected hasCourse(courseId: number): boolean {
if (!this.courses) {
return false;
}
return !!this.courses.find((course) => course.id == courseId);
} }
/** /**
@ -253,7 +245,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
} }
/** /**
* Component being destroyed. * @inheritdoc
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.isDestroyed = true; this.isDestroyed = true;

View File

@ -52,7 +52,6 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
protected isDestroyed = false; protected isDestroyed = false;
protected coursesObserver?: CoreEventObserver; protected coursesObserver?: CoreEventObserver;
protected updateSiteObserver?: CoreEventObserver; protected updateSiteObserver?: CoreEventObserver;
protected courseIds: number[] = [];
protected fetchContentDefaultError = 'Error getting starred courses data.'; protected fetchContentDefaultError = 'Error getting starred courses data.';
constructor() { constructor() {
@ -60,7 +59,7 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
} }
/** /**
* Component being initialized. * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
// Generate unique id for scroll element. // Generate unique id for scroll element.
@ -76,17 +75,12 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => {
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
}, CoreSites.getCurrentSiteId()); }, CoreSites.getCurrentSiteId());
this.coursesObserver = CoreEvents.on( this.coursesObserver = CoreEvents.on(
CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, CoreCoursesProvider.EVENT_MY_COURSES_UPDATED,
(data) => { (data) => {
this.refreshCourseList(data);
if (this.shouldRefreshOnUpdatedEvent(data)) {
this.refreshCourseList();
}
this.refreshContent();
}, },
CoreSites.getCurrentSiteId(), CoreSites.getCurrentSiteId(),
@ -96,7 +90,7 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
} }
/** /**
* Detect changes on input properties. * @inheritdoc
*/ */
ngOnChanges(changes: {[name: string]: SimpleChange}): void { ngOnChanges(changes: {[name: string]: SimpleChange}): void {
if (changes.downloadEnabled && !changes.downloadEnabled.previousValue && this.downloadEnabled && this.loaded) { if (changes.downloadEnabled && !changes.downloadEnabled.previousValue && this.downloadEnabled && this.loaded) {
@ -106,21 +100,35 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
} }
/** /**
* Perform the invalidate content function. * @inheritdoc
*
* @return Resolved when done.
*/ */
protected async invalidateContent(): Promise<void> { protected async invalidateContent(): Promise<void> {
const courseIds = this.courses.map((course) => course.id);
await this.invalidateCourses(courseIds);
}
/**
* Helper function to invalidate only selected courses.
*
* @param courseIds Course Id array.
* @return Promise resolved when done.
*/
protected async invalidateCourses(courseIds: number[]): Promise<void> {
const promises: Promise<void>[] = []; const promises: Promise<void>[] = [];
// Invalidate course completion data.
promises.push(CoreCourses.invalidateUserCourses().finally(() => promises.push(CoreCourses.invalidateUserCourses().finally(() =>
// Invalidate course completion data. CoreUtils.allPromises(courseIds.map((courseId) =>
CoreUtils.allPromises(this.courseIds.map((courseId) =>
AddonCourseCompletion.invalidateCourseCompletion(courseId))))); AddonCourseCompletion.invalidateCourseCompletion(courseId)))));
promises.push(CoreCourseOptionsDelegate.clearAndInvalidateCoursesOptions()); if (courseIds.length == 1) {
if (this.courseIds.length > 0) { promises.push(CoreCourseOptionsDelegate.clearAndInvalidateCoursesOptions(courseIds[0]));
promises.push(CoreCourses.invalidateCoursesByField('ids', this.courseIds.join(','))); } else {
promises.push(CoreCourseOptionsDelegate.clearAndInvalidateCoursesOptions());
}
if (courseIds.length > 0) {
promises.push(CoreCourses.invalidateCoursesByField('ids', courseIds.join(',')));
} }
await CoreUtils.allPromises(promises).finally(() => { await CoreUtils.allPromises(promises).finally(() => {
@ -129,54 +137,54 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
} }
/** /**
* Fetch the courses. * @inheritdoc
*
* @return Promise resolved when done.
*/ */
protected async fetchContent(): Promise<void> { protected async fetchContent(): Promise<void> {
const showCategories = this.block.configsRecord && this.block.configsRecord.displaycategories && const showCategories = this.block.configsRecord && this.block.configsRecord.displaycategories &&
this.block.configsRecord.displaycategories.value == '1'; this.block.configsRecord.displaycategories.value == '1';
// @TODO: Sort won't coincide with website because timemodified is not informed.
this.courses = await CoreCoursesHelper.getUserCoursesWithOptions('timemodified', 0, 'isfavourite', showCategories); this.courses = await CoreCoursesHelper.getUserCoursesWithOptions('timemodified', 0, 'isfavourite', showCategories);
this.initPrefetchCoursesIcons(); this.initPrefetchCoursesIcons();
} }
/** /**
* Refresh the list of courses. * Refresh course list based on a EVENT_MY_COURSES_UPDATED event.
*
* @return Promise resolved when done.
*/
protected async refreshCourseList(): Promise<void> {
CoreEvents.trigger(CoreCoursesProvider.EVENT_MY_COURSES_REFRESHED);
try {
await CoreCourses.invalidateUserCourses();
} catch (error) {
// Ignore errors.
}
await this.loadContent(true);
}
/**
* Whether list should be refreshed based on a EVENT_MY_COURSES_UPDATED event.
* *
* @param data Event data. * @param data Event data.
* @return Whether to refresh. * @return Promise resolved when done.
*/ */
protected shouldRefreshOnUpdatedEvent(data: CoreCoursesMyCoursesUpdatedEventData): boolean { protected async refreshCourseList(data: CoreCoursesMyCoursesUpdatedEventData): Promise<void> {
if (data.action == CoreCoursesProvider.ACTION_ENROL) { if (data.action == CoreCoursesProvider.ACTION_ENROL) {
// Always update if user enrolled in a course. // Always update if user enrolled in a course.
// New courses shouldn't be favourite by default, but just in case. // New courses shouldn't be favourite by default, but just in case.
return true; return await this.refreshContent();
} }
if (data.action == CoreCoursesProvider.ACTION_STATE_CHANGED && data.state == CoreCoursesProvider.STATE_FAVOURITE) { if (data.action == CoreCoursesProvider.ACTION_STATE_CHANGED && data.state == CoreCoursesProvider.STATE_FAVOURITE) {
// Update list when making a course favourite or not. const courseIndex = this.courses.findIndex((course) => course.id == data.courseId);
return true; if (courseIndex < 0) {
} // Not found, use WS update. Usually new favourite.
return await this.refreshContent();
}
return false; const course = this.courses[courseIndex];
if (data.value === false) {
// Unfavourite, just remove.
this.courses.splice(courseIndex, 1);
} else {
// List is not synced, favourite course and place it at the begining.
course.isfavourite = !!data.value;
this.courses.splice(courseIndex, 1);
this.courses.unshift(course);
}
await this.invalidateCourses([course.id]);
this.initPrefetchCoursesIcons();
}
} }
/** /**
@ -212,7 +220,7 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
} }
/** /**
* Component being destroyed. * @inheritdoc
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.isDestroyed = true; this.isDestroyed = true;

View File

@ -47,6 +47,6 @@
[course]="course" [from]="dataFrom" [to]="dataTo"></addon-block-timeline-events> [course]="course" [from]="dataFrom" [to]="dataTo"></addon-block-timeline-events>
</ng-container> </ng-container>
<core-empty-box *ngIf="timelineCourses.courses.length == 0" image="assets/img/icons/courses.svg" inline="true" <core-empty-box *ngIf="timelineCourses.courses.length == 0" image="assets/img/icons/courses.svg" inline="true"
[message]="'addon.block_timeline.nocoursesinprogress' | translate"></core-empty-box> [message]="'addon.block_timeline.noevents' | translate"></core-empty-box>
</core-loading> </core-loading>
</core-loading> </core-loading>

View File

@ -176,9 +176,15 @@ export class AddonBlockTimelineComponent extends CoreBlockBaseComponent implemen
const courseEvents = await AddonBlockTimeline.getActionEventsByCourses(this.courseIds); const courseEvents = await AddonBlockTimeline.getActionEventsByCourses(this.courseIds);
this.timelineCourses.courses.forEach((course) => { this.timelineCourses.courses = this.timelineCourses.courses.filter((course) => {
if (courseEvents[course.id].events.length == 0) {
return false;
}
course.events = courseEvents[course.id].events; course.events = courseEvents[course.id].events;
course.canLoadMore = courseEvents[course.id].canLoadMore; course.canLoadMore = courseEvents[course.id].canLoadMore;
return true;
}); });
} }
} }

View File

@ -26,7 +26,7 @@ export class AddonBlogMainMenuHandlerService implements CoreMainMenuHandler {
static readonly PAGE_NAME = 'blog'; static readonly PAGE_NAME = 'blog';
name = 'AddonBlog'; name = 'AddonBlog';
priority = 450; priority = 500;
/** /**
* @inheritdoc * @inheritdoc

View File

@ -26,7 +26,7 @@ export class AddonCalendarMainMenuHandlerService implements CoreMainMenuHandler
static readonly PAGE_NAME = 'calendar'; static readonly PAGE_NAME = 'calendar';
name = 'AddonCalendar'; name = 'AddonCalendar';
priority = 900; priority = 800;
/** /**
* Check if the handler is enabled on a site level. * Check if the handler is enabled on a site level.

View File

@ -38,7 +38,7 @@ export class AddonMessagesMainMenuHandlerService implements CoreMainMenuHandler,
static readonly PAGE_NAME = 'messages'; static readonly PAGE_NAME = 'messages';
name = 'AddonMessages'; name = 'AddonMessages';
priority = 800; priority = 700;
protected handler: CoreMainMenuHandlerToDisplay = { protected handler: CoreMainMenuHandlerToDisplay = {
icon: 'fas-comments', icon: 'fas-comments',

View File

@ -33,7 +33,7 @@ export class AddonNotificationsMainMenuHandlerService implements CoreMainMenuHan
static readonly PAGE_NAME = 'notifications'; static readonly PAGE_NAME = 'notifications';
name = 'AddonNotifications'; name = 'AddonNotifications';
priority = 700; priority = 600;
protected handlerData: CoreMainMenuHandlerData = { protected handlerData: CoreMainMenuHandlerData = {
icon: 'fas-bell', icon: 'fas-bell',

View File

@ -29,7 +29,7 @@ export class CoreCoursesMyCoursesMainMenuHandlerService implements CoreMainMenuH
static readonly PAGE_NAME = 'courses'; static readonly PAGE_NAME = 'courses';
name = 'CoreCoursesMyCourses'; name = 'CoreCoursesMyCourses';
priority = 850; priority = 900;
/** /**
* @inheritdoc * @inheritdoc

View File

@ -1,3 +1,12 @@
:host-context(ion-tabs.placement-side div.tabs-inner) { core-user-avatar {
padding: 0;
}
:host-context(ion-tabs.placement-side ion-toolbar) {
display: none; display: none;
} }
:host-context(ion-toolbar) core-user-avatar ::ng-deep img {
padding: 2px !important;
border: 1px solid var(--color);
}

View File

@ -13,6 +13,9 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreDashboardHomeHandler } from '@features/courses/services/handlers/dashboard-home';
import { CoreSiteHomeHomeHandler } from '@features/sitehome/services/handlers/sitehome-home';
import { CoreSites } from '@services/sites';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '../mainmenu-delegate'; import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '../mainmenu-delegate';
@ -25,13 +28,18 @@ export class CoreMainMenuHomeHandlerService implements CoreMainMenuHandler {
static readonly PAGE_NAME = 'home'; static readonly PAGE_NAME = 'home';
name = 'CoreHome'; name = 'CoreHome';
priority = 1100; priority = 1000;
/** /**
* @inheritdoc * @inheritdoc
*/ */
async isEnabled(): Promise<boolean> { async isEnabled(): Promise<boolean> {
return true; const siteId = CoreSites.getCurrentSiteId();
const dashboardEnabled = await CoreDashboardHomeHandler.isEnabledForSite(siteId);
const siteHomeEnabled = await CoreSiteHomeHomeHandler.isEnabledForSite(siteId);
return dashboardEnabled || siteHomeEnabled;
} }
/** /**

View File

@ -27,7 +27,7 @@ export class CoreTagMainMenuHandlerService implements CoreMainMenuHandler {
static readonly PAGE_NAME = 'tag'; static readonly PAGE_NAME = 'tag';
name = 'CoreTag'; name = 'CoreTag';
priority = 300; priority = 400;
/** /**
* Check if the handler is enabled on a site level. * Check if the handler is enabled on a site level.

View File

@ -1090,7 +1090,7 @@ export class CoreSitesProvider {
} }
/** /**
* Get the list of sites stored, sorted by URL and full name. * Get the list of sites stored, sorted by sitename, URL and fullname.
* *
* @param ids IDs of the sites to get. If not defined, return all sites. * @param ids IDs of the sites to get. If not defined, return all sites.
* @return Promise resolved when the sites are retrieved. * @return Promise resolved when the sites are retrieved.
@ -1098,24 +1098,28 @@ export class CoreSitesProvider {
async getSortedSites(ids?: string[]): Promise<CoreSiteBasicInfo[]> { async getSortedSites(ids?: string[]): Promise<CoreSiteBasicInfo[]> {
const sites = await this.getSites(ids); const sites = await this.getSites(ids);
// Sort sites by url and fullname. // Sort sites by site name, url and then fullname.
sites.sort((a, b) => { sites.sort((a, b) => {
// First compare by site url without the protocol. // First compare by site name.
const compare = a.siteUrlWithoutProtocol.localeCompare(b.siteUrlWithoutProtocol); let textA = CoreTextUtils.cleanTags(a.siteName).toLowerCase().trim();
let textB = CoreTextUtils.cleanTags(b.siteName).toLowerCase().trim();
let compare = textA.localeCompare(textB);
if (compare !== 0) { if (compare !== 0) {
return compare; return compare;
} }
// If site url is the same, use fullname instead. // If site name is the same, use site url without the protocol.
const fullNameA = a.fullName?.toLowerCase().trim(); compare = a.siteUrlWithoutProtocol.localeCompare(b.siteUrlWithoutProtocol);
const fullNameB = b.fullName?.toLowerCase().trim(); if (compare !== 0) {
return compare;
if (!fullNameA || !fullNameB) {
return 0;
} }
return fullNameA.localeCompare(fullNameB); // Finally use fullname.
textA = a.fullName?.toLowerCase().trim() || '';
textB = b.fullName?.toLowerCase().trim() || '';
return textA.localeCompare(textB);
}); });
return sites; return sites;