Skip to content

Commit

Permalink
Merge pull request #4232 from crazyserver/MOBILE-4653
Browse files Browse the repository at this point in the history
Mobile 4653
  • Loading branch information
dpalou authored Nov 18, 2024
2 parents 1afe196 + f1a488d commit 84781a7
Show file tree
Hide file tree
Showing 671 changed files with 6,514 additions and 4,339 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
cat circular-dependencies
lines=$(cat circular-dependencies | wc -l)
echo "Total circular dependencies: $lines"
test $lines -eq 130
test $lines -eq 90
- name: JavaScript code compatibility
run: |
npx check-es-compat www/*.js --polyfills="\{Array,String,TypedArray\}.prototype.at,Object.hasOwn"
Expand Down
2 changes: 1 addition & 1 deletion src/addons/badges/badge-lazy.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ const routes: Routes = [
RouterModule.forChild(routes),
],
})
export class AddonBadgeLazyModule {}
export default class AddonBadgeLazyModule {}
2 changes: 1 addition & 1 deletion src/addons/badges/badgeclass-lazy.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ const routes: Routes = [
AddonBadgesBadgeClassPage,
],
})
export class AddonBadgeClassLazyModule {}
export default class AddonBadgeClassLazyModule {}
2 changes: 1 addition & 1 deletion src/addons/badges/badges-lazy.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ const routes: Routes = [
AddonBadgesUserBadgesPage,
],
})
export class AddonBadgesLazyModule {}
export default class AddonBadgesLazyModule {}
6 changes: 3 additions & 3 deletions src/addons/badges/badges.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ export async function getBadgesServices(): Promise<Type<unknown>[]> {
const mainMenuRoutes: Routes = [
{
path: 'badge',
loadChildren: () => import('./badge-lazy.module').then(m => m.AddonBadgeLazyModule),
loadChildren: () => import('./badge-lazy.module'),
},
{
path: 'badges',
loadChildren: () => import('./badges-lazy.module').then(m => m.AddonBadgesLazyModule),
loadChildren: () => import('./badges-lazy.module'),
},
{
path: 'badgeclass',
loadChildren: () => import('./badgeclass-lazy.module').then(m => m.AddonBadgeClassLazyModule),
loadChildren: () => import('./badgeclass-lazy.module'),
},
];

Expand Down
4 changes: 2 additions & 2 deletions src/addons/badges/pages/badge-class/badge-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import { Component, OnInit } from '@angular/core';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils';
import { CorePromiseUtils } from '@singletons/promise-utils';
import { CoreNavigator } from '@services/navigator';
import { ActivatedRoute } from '@angular/router';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
Expand Down Expand Up @@ -81,7 +81,7 @@ export class AddonBadgesBadgeClassPage implements OnInit {
* @param refresher Refresher.
*/
async refreshBadgeClass(refresher?: HTMLIonRefresherElement): Promise<void> {
await CoreUtils.ignoreErrors(AddonBadges.invalidateBadgeClass(this.badgeId));
await CorePromiseUtils.ignoreErrors(AddonBadges.invalidateBadgeClass(this.badgeId));

await this.fetchBadgeClass();

Expand Down
6 changes: 3 additions & 3 deletions src/addons/badges/pages/issued-badge/issued-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreSites } from '@services/sites';
import { CoreUser } from '@features/user/services/user';
import { AddonBadges, AddonBadgesUserBadge } from '../../services/badges';
import { CoreUtils } from '@services/utils/utils';
import { CorePromiseUtils } from '@singletons/promise-utils';
import { CoreCourses } from '@features/courses/services/courses';
import { CoreNavigator } from '@services/navigator';
import { ActivatedRoute } from '@angular/router';
Expand Down Expand Up @@ -151,12 +151,12 @@ export class AddonBadgesIssuedBadgePage implements OnInit, OnDestroy {
* @param refresher Refresher.
*/
async refreshBadges(refresher?: HTMLIonRefresherElement): Promise<void> {
await CoreUtils.allPromisesIgnoringErrors([
await CorePromiseUtils.allPromisesIgnoringErrors([
AddonBadges.invalidateUserBadges(this.courseId, this.userId),
AddonBadges.invalidateUserBadgeByHash(this.badgeHash),
]);

await CoreUtils.ignoreErrors(Promise.all([
await CorePromiseUtils.ignoreErrors(Promise.all([
this.fetchIssuedBadge(),
]));

Expand Down
6 changes: 3 additions & 3 deletions src/addons/badges/pages/user-badges/user-badges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { AddonBadges, AddonBadgesUserBadge } from '../../services/badges';
import { CoreTimeUtils } from '@services/utils/time';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils';
import { CorePromiseUtils } from '@singletons/promise-utils';
import { CoreSplitViewComponent } from '@components/split-view/split-view';
import { CoreNavigator } from '@services/navigator';
import { CoreListItemsManager } from '@classes/items-management/list-items-manager';
Expand Down Expand Up @@ -90,13 +90,13 @@ export class AddonBadgesUserBadgesPage implements AfterViewInit, OnDestroy {
* @param refresher Refresher.
*/
async refreshBadges(refresher?: HTMLIonRefresherElement): Promise<void> {
await CoreUtils.ignoreErrors(
await CorePromiseUtils.ignoreErrors(
AddonBadges.invalidateUserBadges(
this.badges.getSource().COURSE_ID,
this.badges.getSource().USER_ID,
),
);
await CoreUtils.ignoreErrors(this.badges.reload());
await CorePromiseUtils.ignoreErrors(this.badges.reload());

refresher?.complete();
}
Expand Down
8 changes: 4 additions & 4 deletions src/addons/badges/services/badges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import { Injectable } from '@angular/core';
import { CoreSites } from '@services/sites';
import { CoreWSExternalWarning } from '@services/ws';
import { CoreSite } from '@classes/sites/site';
import { makeSingleton } from '@singletons';
import { CoreError } from '@classes/errors/error';
import { CoreCacheUpdateFrequency } from '@/core/constants';

const ROOT_CACHE_KEY = 'mmaBadges:';

Expand Down Expand Up @@ -70,7 +70,7 @@ export class AddonBadgesProvider {
};
const preSets = {
cacheKey: this.getBadgesCacheKey(courseId, userId),
updateFrequency: CoreSite.FREQUENCY_RARELY,
updateFrequency: CoreCacheUpdateFrequency.RARELY,
};

const response = await site.read<AddonBadgesGetUserBadgesWSResponse>('core_badges_get_user_badges', data, preSets);
Expand Down Expand Up @@ -133,7 +133,7 @@ export class AddonBadgesProvider {
};
const preSets = {
cacheKey: this.getUserBadgeByHashCacheKey(hash),
updateFrequency: CoreSite.FREQUENCY_RARELY,
updateFrequency: CoreCacheUpdateFrequency.RARELY,
};

const response = await site.read<AddonBadgesGetUserBadgeByHashWSResponse>(
Expand Down Expand Up @@ -190,7 +190,7 @@ export class AddonBadgesProvider {
};
const preSets = {
cacheKey: this.getBadgeClassCacheKey(id),
updateFrequency: CoreSite.FREQUENCY_RARELY,
updateFrequency: CoreCacheUpdateFrequency.RARELY,
};

const response = await site.read<AddonBadgesGetBadgeClassWSResponse>(
Expand Down
5 changes: 3 additions & 2 deletions src/addons/badges/services/handlers/push-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

import { Injectable } from '@angular/core';

import { CoreUtils } from '@services/utils/utils';
import { CoreUtils } from '@singletons/utils';
import { CorePushNotificationsClickHandler } from '@features/pushnotifications/services/push-delegate';
import { AddonBadges } from '../badges';
import { makeSingleton } from '@singletons';
import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications';
import { CoreNavigator } from '@services/navigator';
import { AddonBadgesHelper } from '../badges-helper';
import { CorePromiseUtils } from '@singletons/promise-utils';

/**
* Handler for badges push notifications clicks.
Expand Down Expand Up @@ -72,7 +73,7 @@ export class AddonBadgesPushClickHandlerService implements CorePushNotifications
}

// No hash, open the list of user badges.
await CoreUtils.ignoreErrors(
await CorePromiseUtils.ignoreErrors(
AddonBadges.invalidateUserBadges(
0,
Number(notification.usertoid),
Expand Down
5 changes: 3 additions & 2 deletions src/addons/badges/services/handlers/tag-area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

import { Injectable, Type } from '@angular/core';
import { CoreTagFeedComponent } from '@features/tag/components/feed/feed';
import { CoreTagAreaHandler } from '@features/tag/services/tag-area-delegate';
import { CoreTagFeedElement, CoreTagHelper } from '@features/tag/services/tag-helper';
import { makeSingleton } from '@singletons';
Expand Down Expand Up @@ -45,7 +44,9 @@ export class AddonBadgesTagAreaHandlerService implements CoreTagAreaHandler {
/**
* @inheritdoc
*/
getComponent(): Type<unknown> | Promise<Type<unknown>> {
async getComponent(): Promise<Type<unknown>> {
const { CoreTagFeedComponent } = await import('@features/tag/components/feed/feed');

return CoreTagFeedComponent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CoreBlockBaseComponent } from '@features/block/classes/base-block-compo
import { CoreSites } from '@services/sites';
import { ContextLevel, CoreConstants } from '@/core/constants';
import { Translate } from '@singletons';
import { CoreUtils } from '@services/utils/utils';
import { CoreObject } from '@singletons/object';
import { CoreNavigator } from '@services/navigator';
import { CoreCourseHelper } from '@features/course/services/course-helper';
import { CoreUrl } from '@singletons/url';
Expand Down Expand Up @@ -106,7 +106,7 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i
});

// Sort the modnames alphabetically.
modFullNames = CoreUtils.sortValues(modFullNames);
modFullNames = CoreObject.sortValues(modFullNames);
for (const modName in modFullNames) {
const iconModName = modName === 'resources' ? 'page' : modName;

Expand Down
4 changes: 2 additions & 2 deletions src/addons/block/calendarmonth/services/block-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler
import { CoreCourseBlock } from '@features/course/services/course';
import { Params } from '@angular/router';
import { makeSingleton } from '@singletons';
import { AddonCalendarMainMenuHandlerService } from '@addons/calendar/services/handlers/mainmenu';
import { ContextLevel } from '@/core/constants';
import { ADDON_CALENDAR_PAGE_NAME } from '@addons/calendar/constants';

/**
* Block handler.
Expand All @@ -46,7 +46,7 @@ export class AddonBlockCalendarMonthHandlerService extends CoreBlockBaseHandler
title: 'addon.block_calendarmonth.pluginname',
class: 'addon-block-calendar-month',
component: CoreBlockOnlyTitleComponent,
link: AddonCalendarMainMenuHandlerService.PAGE_NAME,
link: ADDON_CALENDAR_PAGE_NAME,
linkParams: linkParams,
navOptions: {
preferCurrentTab: false,
Expand Down
4 changes: 2 additions & 2 deletions src/addons/block/calendarupcoming/services/block-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler
import { CoreCourseBlock } from '@features/course/services/course';
import { Params } from '@angular/router';
import { makeSingleton } from '@singletons';
import { AddonCalendarMainMenuHandlerService } from '@addons/calendar/services/handlers/mainmenu';
import { CoreSites } from '@services/sites';
import { ContextLevel } from '@/core/constants';
import { ADDON_CALENDAR_PAGE_NAME } from '@addons/calendar/constants';

/**
* Block handler.
Expand Down Expand Up @@ -51,7 +51,7 @@ export class AddonBlockCalendarUpcomingHandlerService extends CoreBlockBaseHandl
title: 'addon.block_calendarupcoming.pluginname',
class: 'addon-block-calendar-upcoming',
component: CoreBlockOnlyTitleComponent,
link: AddonCalendarMainMenuHandlerService.PAGE_NAME,
link: ADDON_CALENDAR_PAGE_NAME,
linkParams: linkParams,
};
}
Expand Down
27 changes: 16 additions & 11 deletions src/addons/block/myoverview/components/myoverview/myoverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreTimeUtils } from '@services/utils/time';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import {
CoreCoursesProvider,
CoreCourses,
CoreCoursesMyCoursesUpdatedEventData,
CoreCourseSummaryData,
Expand All @@ -27,7 +26,7 @@ import { CoreCourseHelper, CorePrefetchStatusInfo } from '@features/course/servi
import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate';
import { CoreBlockBaseComponent } from '@features/block/classes/base-block-component';
import { CoreSite } from '@classes/sites/site';
import { CoreUtils } from '@services/utils/utils';
import { CorePromiseUtils } from '@singletons/promise-utils';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreText } from '@singletons/text';
import { AddonCourseCompletion } from '@addons/coursecompletion/services/coursecompletion';
Expand All @@ -38,6 +37,12 @@ import { PageLoadsManager } from '@classes/page-loads-manager';
import { DownloadStatus } from '@/core/constants';
import { CoreSharedModule } from '@/core/shared.module';
import { CoreCoursesComponentsModule } from '@features/courses/components/components.module';
import {
CORE_COURSES_MY_COURSES_UPDATED_EVENT,
CoreCoursesMyCoursesUpdatedEventAction,
CORE_COURSES_STATE_FAVOURITE,
CORE_COURSES_STATE_HIDDEN,
} from '@features/courses/constants';

const FILTER_PRIORITY: AddonBlockMyOverviewTimeFilters[] =
['all', 'inprogress', 'future', 'past', 'favourite', 'allincludinghidden', 'hidden'];
Expand Down Expand Up @@ -137,7 +142,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
}, CoreSites.getCurrentSiteId());

this.coursesObserver = CoreEvents.on(
CoreCoursesProvider.EVENT_MY_COURSES_UPDATED,
CORE_COURSES_MY_COURSES_UPDATED_EVENT,
(data) => {
this.refreshCourseList(data);
},
Expand Down Expand Up @@ -238,7 +243,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem

// Invalidate course completion data.
promises.push(this.invalidateCourseList().finally(() =>
CoreUtils.allPromises(courseIds.map((courseId) =>
CorePromiseUtils.allPromises(courseIds.map((courseId) =>
AddonCourseCompletion.invalidateCourseCompletion(courseId)))));

if (courseIds.length == 1) {
Expand All @@ -250,7 +255,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
promises.push(CoreCourses.invalidateCoursesByField('ids', courseIds.join(',')));
}

await CoreUtils.allPromises(promises).finally(() => {
await CorePromiseUtils.allPromises(promises).finally(() => {
this.prefetchIconsInitialized = false;
});
}
Expand Down Expand Up @@ -428,37 +433,37 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
}

/**
* Refresh course list based on a EVENT_MY_COURSES_UPDATED event.
* Refresh course list based on a CORE_COURSES_MY_COURSES_UPDATED_EVENT event.
*
* @param data Event data.
* @returns Promise resolved when done.
*/
protected async refreshCourseList(data: CoreCoursesMyCoursesUpdatedEventData): Promise<void> {
if (data.action == CoreCoursesProvider.ACTION_ENROL) {
if (data.action === CoreCoursesMyCoursesUpdatedEventAction.ENROL) {
// Always update if user enrolled in a course.
return this.refreshContent(true);
}

const course = this.allCourses.find((course) => course.id == data.courseId);
if (data.action == CoreCoursesProvider.ACTION_STATE_CHANGED) {
if (data.action === CoreCoursesMyCoursesUpdatedEventAction.STATE_CHANGED) {
if (!course) {
// Not found, use WS update.
return this.refreshContent(true);
}

if (data.state == CoreCoursesProvider.STATE_FAVOURITE) {
if (data.state === CORE_COURSES_STATE_FAVOURITE) {
course.isfavourite = !!data.value;
}

if (data.state == CoreCoursesProvider.STATE_HIDDEN) {
if (data.state === CORE_COURSES_STATE_HIDDEN) {
course.hidden = !!data.value;
}

await this.invalidateCourseList();
await this.filterCourses();
}

if (data.action == CoreCoursesProvider.ACTION_VIEW && data.courseId != CoreSites.getCurrentSiteHomeId()) {
if (data.action === CoreCoursesMyCoursesUpdatedEventAction.VIEW && data.courseId != CoreSites.getCurrentSiteHomeId()) {
if (!course) {
// Not found, use WS update.
return this.refreshContent(true);
Expand Down
Loading

0 comments on commit 84781a7

Please sign in to comment.