Skip to content

Commit

Permalink
MOBILE-4616 url: Migrate all CoreUrlUtils to CoreUrl static singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyserver committed Jul 22, 2024
1 parent ebfba7a commit 31dd0a4
Show file tree
Hide file tree
Showing 69 changed files with 861 additions and 561 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ jobs:
cat circular-dependencies
lines=$(cat circular-dependencies | wc -l)
echo "Total circular dependencies: $lines"
test $lines -ge 138
test $lines -le 148
test $lines -ge 135
test $lines -le 145
- name: JavaScript code compatibility
run: |
npx check-es-compat www/*.js --polyfills="\{Array,String,TypedArray\}.prototype.at,Object.hasOwn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Translate } from '@singletons';
import { CoreUtils } from '@services/utils/utils';
import { CoreNavigator } from '@services/navigator';
import { CoreCourseHelper } from '@features/course/services/course-helper';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreSharedModule } from '@/core/shared.module';

/**
Expand Down Expand Up @@ -103,7 +103,7 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i
brandedIcons[mod.modname] = mod.branded;

// If this is not a theme image, leave it undefined to avoid having specific activity icons.
if (CoreUrlUtils.isThemeImageUrl(mod.modicon)) {
if (CoreUrl.isThemeImageUrl(mod.modicon)) {
modIcons[mod.modname] = mod.modicon;
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/addons/blog/pages/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { CoreNavigator } from '@services/navigator';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreUtils } from '@services/utils/utils';
import { CoreArray } from '@singletons/array';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
Expand Down Expand Up @@ -79,7 +79,7 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy {
...this.filter,
category: 'blog',
},
url: CoreUrlUtils.addParamsToUrl('/blog/index.php', {
url: CoreUrl.addParamsToUrl('/blog/index.php', {
...this.filter,
modid: this.filter.cmid,
cmid: undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/addons/calendar/components/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
import { CoreSwipeSlidesDynamicItemsManager } from '@classes/items-management/swipe-slides-dynamic-items-manager';
import moment from 'moment-timezone';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreTime } from '@singletons/time';
import { Translate } from '@singletons';

Expand Down Expand Up @@ -132,7 +132,7 @@ export class AddonCalendarCalendarComponent implements OnInit, DoCheck, OnDestro
...params,
category: 'calendar',
},
url: CoreUrlUtils.addParamsToUrl('/calendar/view.php?view=month', params),
url: CoreUrl.addParamsToUrl('/calendar/view.php?view=month', params),
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { AddonCalendarOffline } from '../../services/calendar-offline';
import { CoreCategoryData, CoreCourses } from '@features/courses/services/courses';
import { CoreConstants } from '@/core/constants';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreTime } from '@singletons/time';
import { Translate } from '@singletons';

Expand Down Expand Up @@ -103,7 +103,7 @@ export class AddonCalendarUpcomingEventsComponent implements OnInit, DoCheck, On
...params,
category: 'calendar',
},
url: CoreUrlUtils.addParamsToUrl('/calendar/view.php?view=upcoming', params),
url: CoreUrl.addParamsToUrl('/calendar/view.php?view=upcoming', params),
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/addons/calendar/pages/day/day.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker';
import { AddonCalendarEventsSource } from '@addons/calendar/classes/events-source';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreTime } from '@singletons/time';

/**
Expand Down Expand Up @@ -201,7 +201,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy {
...params,
category: 'calendar',
},
url: CoreUrlUtils.addParamsToUrl('/calendar/view.php?view=day', params),
url: CoreUrl.addParamsToUrl('/calendar/view.php?view=day', params),
});
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/addons/calendar/services/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CoreSite } from '@classes/sites/site';
import { CoreNetwork } from '@services/network';
import { CoreTextUtils } from '@services/utils/text';
import { CoreTimeUtils } from '@services/utils/time';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreUtils } from '@services/utils/utils';
import { CoreGroups } from '@services/groups';
import { CoreLocalNotifications } from '@services/local-notifications';
Expand Down Expand Up @@ -362,14 +362,14 @@ export class AddonCalendarProvider {
// Add links to the days if needed.
if (dayStart && (!seenDay || !moment(seenDay).isSame(start, 'day'))) {
promises.push(this.getViewUrl('day', event.timestart, undefined, siteId).then((url) => {
dayStart = CoreUrlUtils.buildLink(url, dayStart);
dayStart = CoreUrl.buildLink(url, dayStart);

return;
}));
}
if (dayEnd && (!seenDay || !moment(seenDay).isSame(end, 'day'))) {
promises.push(this.getViewUrl('day', end / 1000, undefined, siteId).then((url) => {
dayEnd = CoreUrlUtils.buildLink(url, dayEnd);
dayEnd = CoreUrl.buildLink(url, dayEnd);

return;
}));
Expand Down Expand Up @@ -398,7 +398,7 @@ export class AddonCalendarProvider {
// Add link to view the day.
const url = await this.getViewUrl('day', event.timestart, undefined, siteId);

return CoreUrlUtils.buildLink(url, this.getDayRepresentation(start, useCommonWords)) + ', ' + time;
return CoreUrl.buildLink(url, this.getDayRepresentation(start, useCommonWords)) + ', ' + time;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/addons/competency/pages/competency/competency.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { ActivatedRoute, ActivatedRouteSnapshot } from '@angular/router';
import { AddonCompetencyCourseCompetenciesSource } from '@addons/competency/classes/competency-course-competencies-source';
import { CoreTime } from '@singletons/time';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';

/**
* Page that displays the competency information.
Expand Down Expand Up @@ -306,7 +306,7 @@ export class AddonCompetencyCompetencyPage implements OnInit, OnDestroy {
planstatus: this.planStatus,
userid: userId,
},
url: CoreUrlUtils.addParamsToUrl('/admin/tool/lp/user_competency_in_plan.php', {
url: CoreUrl.addParamsToUrl('/admin/tool/lp/user_competency_in_plan.php', {
planid: source.PLAN_ID,
userid: userId,
competencyid: compId,
Expand All @@ -328,7 +328,7 @@ export class AddonCompetencyCompetencyPage implements OnInit, OnDestroy {
courseid: source.COURSE_ID,
userid: userId,
},
url: CoreUrlUtils.addParamsToUrl('/admin/tool/lp/user_competency_in_course.php', {
url: CoreUrl.addParamsToUrl('/admin/tool/lp/user_competency_in_course.php', {
courseid: source.COURSE_ID,
competencyid: compId,
userid: userId,
Expand Down
4 changes: 2 additions & 2 deletions src/addons/competency/services/handlers/push-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { COURSE_PAGE_NAME } from '@features/course/constants';
import { CorePushNotificationsClickHandler } from '@features/pushnotifications/services/push-delegate';
import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications';
import { CoreNavigator } from '@services/navigator';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons';
import { AddonCompetency } from '../competency';
Expand Down Expand Up @@ -49,7 +49,7 @@ export class AddonCompetencyPushClickHandlerService implements CorePushNotificat
* @inheritdoc
*/
async handleClick(notification: AddonCompetencyPushNotificationData): Promise<void> {
const contextUrlParams = CoreUrlUtils.extractUrlParams(notification.contexturl);
const contextUrlParams = CoreUrl.extractUrlParams(notification.contexturl);

if (notification.name == 'competencyplancomment') {
// Open the learning plan.
Expand Down
4 changes: 2 additions & 2 deletions src/addons/filter/displayh5p/services/handlers/displayh5p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CoreFilterDefaultHandler } from '@features/filter/services/handlers/def
import { CoreFilterFilter, CoreFilterFormatTextOptions } from '@features/filter/services/filter';
import { makeSingleton } from '@singletons';
import { CoreH5PPlayerComponent } from '@features/h5p/components/h5p-player/h5p-player';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreH5PHelper } from '@features/h5p/classes/helper';

/**
Expand Down Expand Up @@ -57,7 +57,7 @@ export class AddonFilterDisplayH5PHandlerService extends CoreFilterDefaultHandle

embeddedH5PIframes.forEach((iframe) => {
// Add the preventredirect param to allow authenticating if auto-login fails.
iframe.src = CoreUrlUtils.addParamsToUrl(iframe.src, { preventredirect: false });
iframe.src = CoreUrl.addParamsToUrl(iframe.src, { preventredirect: false });

// Add resizer script so the H5P has the right height.
CoreH5PHelper.addResizerScript();
Expand Down
4 changes: 2 additions & 2 deletions src/addons/filter/mediaplugin/services/videojs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CorePromisedValue } from '@classes/promised-value';
import { CoreExternalContentDirective } from '@directives/external-content';
import { CoreLang } from '@services/lang';
import { CoreTextUtils } from '@services/utils/text';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { makeSingleton } from '@singletons';
import { CoreDirectivesRegistry } from '@singletons/directives-registry';
import { CoreEvents } from '@singletons/events';
Expand Down Expand Up @@ -107,7 +107,7 @@ export class AddonFilterMediaPluginVideoJSService {

const dataSetupString = video.getAttribute('data-setup') || video.getAttribute('data-setup-lazy') || '{}';
const data = CoreTextUtils.parseJSON<VideoJSOptions>(dataSetupString, {});
const youtubeUrl = data.techOrder?.[0] == 'youtube' && CoreUrlUtils.getYoutubeEmbedUrl(data.sources?.[0]?.src);
const youtubeUrl = data.techOrder?.[0] == 'youtube' && CoreUrl.getYoutubeEmbedUrl(data.sources?.[0]?.src);

if (!youtubeUrl) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/addons/mod/assign/services/handlers/push-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
import { CoreCourseHelper } from '@features/course/services/course-helper';
import { CorePushNotificationsClickHandler } from '@features/pushnotifications/services/push-delegate';
import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons';
import { AddonModAssign } from '../assign';
Expand Down Expand Up @@ -50,7 +50,7 @@ export class AddonModAssignPushClickHandlerService implements CorePushNotificati
* @returns Promise resolved when done.
*/
async handleClick(notification: NotificationData): Promise<void> {
const contextUrlParams = CoreUrlUtils.extractUrlParams(notification.contexturl);
const contextUrlParams = CoreUrl.extractUrlParams(notification.contexturl);
const courseId = Number(notification.courseid);
const moduleId = Number(contextUrlParams.id);

Expand Down
4 changes: 2 additions & 2 deletions src/addons/mod/book/pages/contents/contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
AddonModBookTocChapter,
} from '../../services/book';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { ADDON_MOD_BOOK_COMPONENT, AddonModBookNavStyle } from '../../constants';

/**
Expand Down Expand Up @@ -293,7 +293,7 @@ export class AddonModBookContentsPage implements OnInit, OnDestroy {
ws: 'mod_book_view_book',
name: this.module.name,
data: { id: this.module.instance, category: 'book', chapterid: chapterId },
url: CoreUrlUtils.addParamsToUrl(`/mod/book/view.php?id=${this.module.id}`, { chapterid: chapterId }),
url: CoreUrl.addParamsToUrl(`/mod/book/view.php?id=${this.module.id}`, { chapterid: chapterId }),
});

const currentChapterIndex = this.chapters.findIndex((chapter) => chapter.id == chapterId);
Expand Down
4 changes: 2 additions & 2 deletions src/addons/mod/book/services/handlers/tag-area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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 { CoreSitesReadingStrategy } from '@services/sites';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { makeSingleton } from '@singletons';
import { AddonModBook } from '../book';

Expand Down Expand Up @@ -51,7 +51,7 @@ export class AddonModBookTagAreaHandlerService implements CoreTagAreaHandler {

// Find module ids of the returned books, they are needed by the link delegate.
await Promise.all(items.map(async (item) => {
const params = item.url ? CoreUrlUtils.extractUrlParams(item.url) : {};
const params = item.url ? CoreUrl.extractUrlParams(item.url) : {};
if (params.b && !params.id) {
const bookId = parseInt(params.b, 10);

Expand Down
4 changes: 2 additions & 2 deletions src/addons/mod/data/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { AddonModDataHelper, AddonModDatDisplayFieldsOptions } from '../../servi
import { AddonModDataAutoSyncData, AddonModDataSyncResult } from '../../services/data-sync';
import { AddonModDataPrefetchHandler } from '../../services/handlers/prefetch';
import { AddonModDataComponentsCompileModule } from '../components-compile.module';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreTime } from '@singletons/time';
import {
ADDON_MOD_DATA_AUTO_SYNCED,
Expand Down Expand Up @@ -568,7 +568,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp

this.analyticsLogEvent('mod_data_search_entries', {
data: params,
url: CoreUrlUtils.addParamsToUrl(`/mod/data/view.php?d=${this.database.id}`, params),
url: CoreUrl.addParamsToUrl(`/mod/data/view.php?d=${this.database.id}`, params),
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/addons/mod/feedback/services/handlers/push-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
import { CoreCourseHelper } from '@features/course/services/course-helper';
import { CorePushNotificationsClickHandler } from '@features/pushnotifications/services/push-delegate';
import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons';
import { AddonModFeedbackHelper } from '../feedback-helper';
Expand Down Expand Up @@ -48,7 +48,7 @@ export class AddonModFeedbackPushClickHandlerService implements CorePushNotifica
* @inheritdoc
*/
handleClick(notification: AddonModFeedbackPushNotificationData): Promise<void> {
const contextUrlParams = CoreUrlUtils.extractUrlParams(notification.contexturl!);
const contextUrlParams = CoreUrl.extractUrlParams(notification.contexturl!);
const courseId = Number(notification.courseid);
const moduleId = Number(contextUrlParams.id);

Expand Down
4 changes: 2 additions & 2 deletions src/addons/mod/forum/pages/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreUtils } from '@services/utils/utils';
import { Translate } from '@singletons';

Expand Down Expand Up @@ -116,7 +116,7 @@ export class AddonModForumSearchPage implements OnInit {
query,
filters: JSON.stringify(this.resultsSource.getFilters()),
},
url: CoreUrlUtils.addParamsToUrl('/search/index.php', {
url: CoreUrl.addParamsToUrl('/search/index.php', {
q: query,
}),
});
Expand Down
4 changes: 2 additions & 2 deletions src/addons/mod/forum/services/forum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { CoreNetwork } from '@services/network';
import { CoreFileEntry } from '@services/file-helper';
import { CoreGroups } from '@services/groups';
import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreUtils } from '@services/utils/utils';
import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning, CoreWSStoredFile } from '@services/ws';
import { makeSingleton, Translate } from '@singletons';
Expand Down Expand Up @@ -1312,7 +1312,7 @@ export class AddonModForumProvider {
protected translateWSPost(post: AddonModForumWSPost): AddonModForumPost {
(post as unknown as AddonModForumPost).tags = (post.tags || []).map((tag) => {
const viewUrl = (tag.urls && tag.urls.view) || '';
const params = CoreUrlUtils.extractUrlParams(viewUrl);
const params = CoreUrl.extractUrlParams(viewUrl);

return {
id: tag.tagid,
Expand Down
4 changes: 2 additions & 2 deletions src/addons/mod/forum/services/handlers/push-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { AddonModForum } from '@addons/mod/forum/services/forum';
import { CoreNavigator } from '@services/navigator';
import { CorePushNotificationsClickHandler } from '@features/pushnotifications/services/push-delegate';
import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUrl } from '@singletons/url';
import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons';

Expand Down Expand Up @@ -56,7 +56,7 @@ export class AddonModForumPushClickHandlerService implements CorePushNotificatio
* @returns Promise resolved when done.
*/
async handleClick(notification: NotificationData): Promise<void> {
const contextUrlParams = CoreUrlUtils.extractUrlParams(notification.contexturl);
const contextUrlParams = CoreUrl.extractUrlParams(notification.contexturl);
const data = notification.customdata || {};
const courseId = Number(notification.courseid);
const discussionId = Number(contextUrlParams.d || data.discussionid);
Expand Down
Loading

0 comments on commit 31dd0a4

Please sign in to comment.