Skip to content

Commit

Permalink
Merge pull request #3963 from dpalou/MOBILE-4526
Browse files Browse the repository at this point in the history
Mobile 4526
  • Loading branch information
NoelDeMartin authored Mar 13, 2024
2 parents 67ca4d2 + 4fad121 commit 0b9ee2d
Show file tree
Hide file tree
Showing 64 changed files with 525 additions and 192 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
13 changes: 6 additions & 7 deletions src/addons/blog/pages/entries/entries.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h1>{{ title | translate }}</h1>
<div class="flex-row ion-justify-content-between ion-align-items-center">
<h2>
<core-format-text [text]="entry.subject" [contextLevel]="contextLevel"
[contextInstanceId]="contextInstanceId" />
[contextInstanceId]="contextInstanceId" [courseId]="entry.courseid" />
</h2>
<ion-note class="ion-text-end">
{{ 'addon.blog.' + entry.publishTranslated! | translate}}
Expand All @@ -47,8 +47,8 @@ <h2>
<ion-card-content>
<ion-item class="ion-text-wrap">
<ion-label>
<core-format-text [text]="entry.summary" [component]="this.component" [componentId]="entry.id"
[contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" />
<core-format-text [text]="entry.summary" [component]="component" [componentId]="entry.id"
[contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" [courseId]="entry.courseid" />
</ion-label>
</ion-item>
<ion-item class="ion-text-wrap" *ngIf="tagsEnabled && entry.tags && entry.tags!.length > 0">
Expand All @@ -57,10 +57,9 @@ <h2>
<core-tag-list [tags]="entry.tags" />
</ion-label>
</ion-item>
<core-comments *ngIf="commentsEnabled" [component]="this.component" [itemId]="entry.id" area="format_blog"
[instanceId]="entry.userid" contextLevel="user" [showItem]="true" />
<core-file *ngFor="let file of entry.attachmentfiles" [file]="file" [component]="this.component"
[componentId]="entry.id" />
<core-comments *ngIf="commentsEnabled" [component]="component" [itemId]="entry.id" area="format_blog"
[instanceId]="entry.userid" contextLevel="user" [showItem]="true" [courseId]="entry.courseid" />
<core-file *ngFor="let file of entry.attachmentfiles" [file]="file" [component]="component" [componentId]="entry.id" />
<ion-item *ngIf="entry.uniquehash" [href]="entry.uniquehash" core-link [detail]="true">
<ion-label>{{ 'addon.blog.linktooriginalentry' | translate }}</ion-label>
</ion-item>
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
Loading

0 comments on commit 0b9ee2d

Please sign in to comment.