Skip to content

Commit

Permalink
MOBILE-4526 core: Use ContextLevel enum instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou committed Mar 13, 2024
1 parent 8afeac3 commit 41e4292
Show file tree
Hide file tree
Showing 62 changed files with 211 additions and 137 deletions.
5 changes: 3 additions & 2 deletions src/addons/block/calendarmonth/services/block-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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';

/**
* Block handler.
Expand All @@ -38,8 +39,8 @@ export class AddonBlockCalendarMonthHandlerService extends CoreBlockBaseHandler
* @param instanceId The instance ID associated with the context level.
* @returns Data or promise resolved with the data.
*/
getDisplayData(block: CoreCourseBlock, contextLevel: string, instanceId: number): CoreBlockHandlerData {
const linkParams: Params = contextLevel == 'course' ? { courseId: instanceId } : {};
getDisplayData(block: CoreCourseBlock, contextLevel: ContextLevel, instanceId: number): CoreBlockHandlerData {
const linkParams: Params = contextLevel === ContextLevel.COURSE ? { courseId: instanceId } : {};

return {
title: 'addon.block_calendarmonth.pluginname',
Expand Down
5 changes: 3 additions & 2 deletions src/addons/block/calendarupcoming/services/block-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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';

/**
* Block handler.
Expand All @@ -39,10 +40,10 @@ export class AddonBlockCalendarUpcomingHandlerService extends CoreBlockBaseHandl
* @param instanceId The instance ID associated with the context level.
* @returns Data or promise resolved with the data.
*/
getDisplayData(block: CoreCourseBlock, contextLevel: string, instanceId: number): CoreBlockHandlerData {
getDisplayData(block: CoreCourseBlock, contextLevel: ContextLevel, instanceId: number): CoreBlockHandlerData {
const linkParams: Params = { upcoming: true };

if (contextLevel == 'course' && instanceId !== CoreSites.getCurrentSiteHomeId()) {
if (contextLevel === ContextLevel.COURSE && instanceId !== CoreSites.getCurrentSiteHomeId()) {
linkParams.courseId = instanceId;
}

Expand Down
3 changes: 2 additions & 1 deletion src/addons/block/comments/services/block-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler
import { CoreCourseBlock } from '@features/course/services/course';
import { makeSingleton } from '@singletons';
import { CoreComments } from '@features/comments/services/comments';
import { ContextLevel } from '@/core/constants';

/**
* Block handler.
Expand All @@ -44,7 +45,7 @@ export class AddonBlockCommentsHandlerService extends CoreBlockBaseHandler {
* @param instanceId The instance ID associated with the context level.
* @returns Data or promise resolved with the data.
*/
getDisplayData(block: CoreCourseBlock, contextLevel: string, instanceId: number): CoreBlockHandlerData {
getDisplayData(block: CoreCourseBlock, contextLevel: ContextLevel, instanceId: number): CoreBlockHandlerData {
return {
title: 'addon.block_comments.pluginname',
class: 'addon-block-comments',
Expand Down
3 changes: 2 additions & 1 deletion src/addons/block/completionstatus/services/block-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler
import { CoreCourseBlock } from '@features/course/services/course';
import { makeSingleton } from '@singletons';
import { AddonCourseCompletion } from '@addons/coursecompletion/services/coursecompletion';
import { ContextLevel } from '@/core/constants';

/**
* Block handler.
Expand All @@ -41,7 +42,7 @@ export class AddonBlockCompletionStatusHandlerService extends CoreBlockBaseHandl
*/
async getDisplayData(
block: CoreCourseBlock,
contextLevel: string,
contextLevel: ContextLevel,
instanceId: number,
): Promise<undefined | CoreBlockHandlerData> {
if (contextLevel !== 'course') {
Expand Down
5 changes: 3 additions & 2 deletions src/addons/block/globalsearch/services/block-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { makeSingleton } from '@singletons';
import { CoreCourseBlock } from '@features/course/services/course';
import { CORE_SEARCH_PAGE_NAME } from '@features/search/services/handlers/mainmenu';
import { CoreSearchGlobalSearch } from '@features/search/services/global-search';
import { ContextLevel } from '@/core/constants';

/**
* Block handler.
Expand All @@ -40,8 +41,8 @@ export class AddonBlockGlobalSearchHandlerService extends CoreBlockBaseHandler {
/**
* @inheritdoc
*/
getDisplayData(block: CoreCourseBlock, contextLevel: string, instanceId: number): CoreBlockHandlerData | undefined {
const isCourseSearch = contextLevel === 'course';
getDisplayData(block: CoreCourseBlock, contextLevel: ContextLevel, instanceId: number): CoreBlockHandlerData | undefined {
const isCourseSearch = contextLevel === ContextLevel.COURSE;

return {
title: isCourseSearch ? 'core.search' : 'addon.block_globalsearch.pluginname',
Expand Down
5 changes: 3 additions & 2 deletions src/addons/block/searchforums/services/block-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { makeSingleton } from '@singletons';
import { ADDON_MOD_FORUM_SEARCH_PAGE_NAME } from '@addons/mod/forum/constants';
import { CoreCourseBlock } from '@features/course/services/course';
import { CoreSearchGlobalSearch } from '@features/search/services/global-search';
import { ContextLevel } from '@/core/constants';

/**
* Block handler.
Expand All @@ -42,10 +43,10 @@ export class AddonBlockSearchForumsHandlerService extends CoreBlockBaseHandler {
*/
async getDisplayData(
block: CoreCourseBlock,
contextLevel: string,
contextLevel: ContextLevel,
instanceId: number,
): Promise<undefined | CoreBlockHandlerData> {
if (contextLevel !== 'course') {
if (contextLevel !== ContextLevel.COURSE) {
return;
}

Expand Down
5 changes: 3 additions & 2 deletions src/addons/block/selfcompletion/services/block-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler
import { CoreCourseBlock } from '@features/course/services/course';
import { makeSingleton } from '@singletons';
import { AddonCourseCompletion } from '@addons/coursecompletion/services/coursecompletion';
import { ContextLevel } from '@/core/constants';

/**
* Block handler.
Expand All @@ -41,10 +42,10 @@ export class AddonBlockSelfCompletionHandlerService extends CoreBlockBaseHandler
*/
async getDisplayData(
block: CoreCourseBlock,
contextLevel: string,
contextLevel: ContextLevel,
instanceId: number,
): Promise<undefined | CoreBlockHandlerData> {
if (contextLevel !== 'course') {
if (contextLevel !== ContextLevel.COURSE) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/addons/blog/pages/entries/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class AddonBlogEntriesPage implements OnInit {
*/
refresh(refresher?: HTMLIonRefresherElement): void {
const promises = this.entries.map((entry) =>
CoreComments.invalidateCommentsData('user', entry.userid, this.component, entry.id, 'format_blog'));
CoreComments.invalidateCommentsData(ContextLevel.USER, entry.userid, this.component, entry.id, 'format_blog'));

promises.push(AddonBlog.invalidateEntries(this.filter));

Expand Down Expand Up @@ -304,6 +304,6 @@ export class AddonBlogEntriesPage implements OnInit {
type AddonBlogPostFormatted = AddonBlogPost & {
publishTranslated?: string; // Calculated in the app. Key of the string to translate the publish state of the post.
user?: CoreUserProfile; // Calculated in the app. Data of the user that wrote the post.
contextLevel?: string; // Calculated in the app. The context level of the entry.
contextLevel?: ContextLevel; // Calculated in the app. The context level of the entry.
contextInstanceId?: number; // Calculated in the app. The context instance id.
};
3 changes: 2 additions & 1 deletion src/addons/calendar/pages/edit-event/edit-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { CoreReminders, CoreRemindersService, CoreRemindersUnits } from '@featur
import { CoreRemindersSetReminderMenuComponent } from '@features/reminders/components/set-reminder-menu/set-reminder-menu';
import moment from 'moment-timezone';
import { ADDON_CALENDAR_COMPONENT } from '@addons/calendar/constants';
import { ContextLevel } from '@/core/constants';

/**
* Page that displays a form to create/edit an event.
Expand Down Expand Up @@ -266,7 +267,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {

const courseFillFullname = async (course: CoreCourseSearchedData | CoreEnrolledCourseData): Promise<void> => {
try {
const result = await CoreFilterHelper.getFiltersAndFormatText(course.fullname, 'course', course.id);
const result = await CoreFilterHelper.getFiltersAndFormatText(course.fullname, ContextLevel.COURSE, course.id);
course.fullname = result.text;
} catch {
// Ignore errors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class AddonCompetencyCompetenciesPage implements AfterViewInit, OnDestroy
>;

title = '';
contextLevel?: string;
contextLevel?: ContextLevel;
contextInstanceId?: number;

protected logView: () => void;
Expand Down
2 changes: 1 addition & 1 deletion src/addons/competency/pages/competency/competency.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class AddonCompetencyCompetencyPage implements OnInit, OnDestroy {
user?: CoreUserSummary;
competency?: AddonCompetencyDataForUserCompetencySummaryWSResponse;
userCompetency?: AddonCompetencyUserCompetencyPlan | AddonCompetencyUserCompetency | AddonCompetencyUserCompetencyCourse;
contextLevel?: string;
contextLevel?: ContextLevel;
contextInstanceId?: number;

protected logView: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { AddonModAssignFeedbackDelegate } from '@addons/mod/assign/services/feed
import { AddonModAssignOffline } from '@addons/mod/assign/services/assign-offline';
import { CoreUtils } from '@services/utils/utils';
import { AddonModAssignFeedbackPluginBaseComponent } from '@addons/mod/assign/classes/base-feedback-plugin-component';
import { ContextLevel } from '@/core/constants';
/**
* Component to render a comments feedback plugin.
*/
Expand Down Expand Up @@ -69,7 +70,7 @@ export class AddonModAssignFeedbackCommentsComponent extends AddonModAssignFeedb
component: this.component,
componentId: this.assign.cmid,
filter: true,
contextLevel: 'module',
contextLevel: ContextLevel.MODULE,
instanceId: this.assign.cmid,
courseId: this.assign.course,
});
Expand Down
3 changes: 2 additions & 1 deletion src/addons/mod/assign/services/assign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { CoreFormFields } from '@singletons/form';
import { CoreFileHelper } from '@services/file-helper';
import { CoreIonicColorNames } from '@singletons/colors';
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
import { ContextLevel } from '@/core/constants';

const ROOT_CACHE_KEY = 'mmaModAssign:';

Expand Down Expand Up @@ -757,7 +758,7 @@ export class AddonModAssignProvider {
promises.push(this.invalidateAssignmentUserMappingsData(assign.id, siteId));
promises.push(this.invalidateAssignmentGradesData(assign.id, siteId));
promises.push(this.invalidateListParticipantsData(assign.id, siteId));
promises.push(CoreComments.invalidateCommentsByInstance('module', assign.id, siteId));
promises.push(CoreComments.invalidateCommentsByInstance(ContextLevel.MODULE, assign.id, siteId));
promises.push(this.invalidateAssignmentData(courseId, siteId));
promises.push(CoreGrades.invalidateAllCourseGradesData(courseId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { ContextLevel } from '@/core/constants';
import { AddonModAssignSubmissionPluginBaseComponent } from '@addons/mod/assign/classes/base-submission-plugin-component';
import { Component, ViewChild } from '@angular/core';
import { CoreCommentsCommentsComponent } from '@features/comments/components/comments/comments';
Expand Down Expand Up @@ -43,7 +44,7 @@ export class AddonModAssignSubmissionCommentsComponent extends AddonModAssignSub
*/
invalidate(): Promise<void> {
return CoreComments.invalidateCommentsData(
'module',
ContextLevel.MODULE,
this.assign.cmid,
'assignsubmission_comments',
this.submission.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Injectable, Type } from '@angular/core';
import { CoreComments } from '@features/comments/services/comments';
import { makeSingleton } from '@singletons';
import { AddonModAssignSubmissionCommentsComponent } from '../component/comments';
import { ContextLevel } from '@/core/constants';

/**
* Handler for comments submission plugin.
Expand Down Expand Up @@ -68,7 +69,7 @@ export class AddonModAssignSubmissionCommentsHandlerService implements AddonModA
siteId?: string,
): Promise<void> {
await CoreComments.getComments(
'module',
ContextLevel.MODULE,
assign.cmid,
'assignsubmission_comments',
submission.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils';
import { AddonModAssignSubmissionOnlineTextPluginData } from '../services/handler';
import { ContextLevel } from '@/core/constants';

/**
* Component to render an onlinetext submission plugin.
Expand Down Expand Up @@ -86,7 +87,7 @@ export class AddonModAssignSubmissionOnlineTextComponent extends AddonModAssignS
component: this.component,
componentId: this.assign.cmid,
filter: true,
contextLevel: 'module',
contextLevel: ContextLevel.MODULE,
instanceId: this.assign.cmid,
courseId: this.assign.course,
});
Expand Down
3 changes: 2 additions & 1 deletion src/addons/mod/data/services/handlers/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons';
import { AddonModDataProvider, AddonModDataEntry, AddonModData, AddonModDataData } from '../data';
import { AddonModDataSync, AddonModDataSyncResult } from '../data-sync';
import { ContextLevel } from '@/core/constants';

/**
* Handler to prefetch databases.
Expand Down Expand Up @@ -249,7 +250,7 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet

if (commentsEnabled && database.comments) {
promises.push(CoreComments.getComments(
'module',
ContextLevel.MODULE,
database.coursemodule,
'mod_data',
entry.id,
Expand Down
18 changes: 14 additions & 4 deletions src/addons/mod/glossary/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,25 @@ export class AddonModGlossaryIndexComponent extends CoreCourseModuleMainActivity

// Listen for offline ratings saved and synced.
this.observers.push(CoreEvents.on(CoreRatingProvider.RATING_SAVED_EVENT, (data) => {
if (this.glossary && data.component == 'mod_glossary' && data.ratingArea == 'entry' && data.contextLevel == 'module'
&& data.instanceId == this.glossary.coursemodule) {
if (
this.glossary &&
data.component == 'mod_glossary' &&
data.ratingArea == 'entry' &&
data.contextLevel == ContextLevel.MODULE &&
data.instanceId == this.glossary.coursemodule
) {
this.hasOfflineRatings = true;
this.hasOffline = true;
}
}));
this.observers.push(CoreEvents.on(CoreRatingSyncProvider.SYNCED_EVENT, (data) => {
if (this.glossary && data.component == 'mod_glossary' && data.ratingArea == 'entry' && data.contextLevel == 'module'
&& data.instanceId == this.glossary.coursemodule) {
if (
this.glossary &&
data.component == 'mod_glossary' &&
data.ratingArea == 'entry' &&
data.contextLevel == ContextLevel.MODULE &&
data.instanceId == this.glossary.coursemodule
) {
this.hasOfflineRatings = false;
this.hasOffline = this.hasOfflineEntries;
}
Expand Down
3 changes: 2 additions & 1 deletion src/addons/mod/glossary/services/handlers/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons';
import { AddonModGlossary, AddonModGlossaryEntry, AddonModGlossaryGlossary, AddonModGlossaryProvider } from '../glossary';
import { AddonModGlossarySync, AddonModGlossarySyncResult } from '../glossary-sync';
import { ContextLevel } from '@/core/constants';

/**
* Handler to prefetch forums.
Expand Down Expand Up @@ -161,7 +162,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
// Don't fetch individual entries, it's too many WS calls.
if (glossary.allowcomments && commentsEnabled) {
promises.push(CoreComments.getComments(
'module',
ContextLevel.MODULE,
glossary.coursemodule,
'mod_glossary',
entry.id,
Expand Down
5 changes: 3 additions & 2 deletions src/addons/privatefiles/services/privatefiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreWSExternalWarning } from '@services/ws';
import { CoreSite } from '@classes/sites/site';
import { makeSingleton } from '@singletons';
import { ContextLevel } from '@/core/constants';

const ROOT_CACHE_KEY = 'mmaFiles:';

Expand Down Expand Up @@ -136,7 +137,7 @@ export class AddonPrivateFilesProvider {
contextid: -1,
component: 'user',
filearea: 'private',
contextlevel: 'user',
contextlevel: ContextLevel.USER,
instanceid: CoreSites.getCurrentSite()?.getUserId(),
itemid: 0,
filepath: '',
Expand Down Expand Up @@ -428,7 +429,7 @@ export type AddonPrivateFilesGetFilesWSParams = {
filepath: string; // File path.
filename: string; // File name.
modified?: number; // Timestamp to return files changed after this time.
contextlevel?: string; // The context level for the file location.
contextlevel?: ContextLevel; // The context level for the file location.
instanceid?: number; // The instance id for where the file is located.
};

Expand Down
3 changes: 2 additions & 1 deletion src/addons/qbehaviour/deferredcbm/component/deferredcbm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { ContextLevel } from '@/core/constants';
import { Component, Input, Output, EventEmitter } from '@angular/core';

import { CoreQuestionBehaviourButton, CoreQuestionQuestion } from '@features/question/services/question-helper';
Expand All @@ -30,7 +31,7 @@ export class AddonQbehaviourDeferredCBMComponent {
@Input() componentId?: number; // ID of the component the question belongs to.
@Input() attemptId?: number; // Attempt ID.
@Input() offlineEnabled?: boolean | string; // Whether the question can be answered in offline.
@Input() contextLevel?: string; // The context level.
@Input() contextLevel?: ContextLevel; // The context level.
@Input() contextInstanceId?: number; // The instance ID related to the context.
@Input() courseId?: number; // Course ID the question belongs to (if any). It can be used to improve performance with filters.
@Input() review?: boolean; // Whether the user is in review mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { ContextLevel } from '@/core/constants';
import { Component, Input, Output, EventEmitter } from '@angular/core';

import { CoreQuestionBehaviourButton, CoreQuestionQuestion } from '@features/question/services/question-helper';
Expand All @@ -30,7 +31,7 @@ export class AddonQbehaviourInformationItemComponent {
@Input() componentId?: number; // ID of the component the question belongs to.
@Input() attemptId?: number; // Attempt ID.
@Input() offlineEnabled?: boolean | string; // Whether the question can be answered in offline.
@Input() contextLevel?: string; // The context level.
@Input() contextLevel?: ContextLevel; // The context level.
@Input() contextInstanceId?: number; // The instance ID related to the context.
@Input() courseId?: number; // Course ID the question belongs to (if any). It can be used to improve performance with filters.
@Input() review?: boolean; // Whether the user is in review mode.
Expand Down
Loading

0 comments on commit 41e4292

Please sign in to comment.