MOBILE-3833 blocks: Fix side-blocks contexts

main
Noel De Martin 2022-03-28 14:23:40 +02:00
parent caf2375dcd
commit 831ae1789c
8 changed files with 23 additions and 17 deletions

View File

@ -20,6 +20,7 @@ import { CoreCourseBlock } from '@features/course/services/course';
import { Params } from '@angular/router'; import { Params } from '@angular/router';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonCalendarMainMenuHandlerService } from '@addons/calendar/services/handlers/mainmenu'; import { AddonCalendarMainMenuHandlerService } from '@addons/calendar/services/handlers/mainmenu';
import { CoreSites } from '@services/sites';
/** /**
* Block handler. * Block handler.
@ -39,8 +40,11 @@ export class AddonBlockCalendarUpcomingHandlerService extends CoreBlockBaseHandl
* @return Data or promise resolved with the data. * @return Data or promise resolved with the data.
*/ */
getDisplayData(block: CoreCourseBlock, contextLevel: string, instanceId: number): CoreBlockHandlerData { getDisplayData(block: CoreCourseBlock, contextLevel: string, instanceId: number): CoreBlockHandlerData {
const linkParams: Params = contextLevel == 'course' ? { courseId: instanceId } : {}; const linkParams: Params = { upcoming: true };
linkParams.upcoming = true;
if (contextLevel == 'course' && instanceId !== CoreSites.getCurrentSiteHomeId()) {
linkParams.courseId = instanceId;
}
return { return {
title: 'addon.block_calendarupcoming.pluginname', title: 'addon.block_calendarupcoming.pluginname',
@ -48,9 +52,6 @@ export class AddonBlockCalendarUpcomingHandlerService extends CoreBlockBaseHandl
component: CoreBlockOnlyTitleComponent, component: CoreBlockOnlyTitleComponent,
link: AddonCalendarMainMenuHandlerService.PAGE_NAME, link: AddonCalendarMainMenuHandlerService.PAGE_NAME,
linkParams: linkParams, linkParams: linkParams,
navOptions: {
preferCurrentTab: false,
},
}; };
} }

View File

@ -30,7 +30,8 @@ import { CoreBlockSideBlocksComponent } from '../side-blocks/side-blocks';
}) })
export class CoreBlockSideBlocksButtonComponent implements OnInit, OnDestroy { export class CoreBlockSideBlocksButtonComponent implements OnInit, OnDestroy {
@Input() courseId!: number; @Input() contextLevel!: string;
@Input() instanceId!: number;
@ViewChild('button', { read: ElementRef }) button?: ElementRef<HTMLElement>; @ViewChild('button', { read: ElementRef }) button?: ElementRef<HTMLElement>;
protected element: HTMLElement; protected element: HTMLElement;
@ -54,7 +55,8 @@ export class CoreBlockSideBlocksButtonComponent implements OnInit, OnDestroy {
CoreDomUtils.openSideModal({ CoreDomUtils.openSideModal({
component: CoreBlockSideBlocksComponent, component: CoreBlockSideBlocksComponent,
componentProps: { componentProps: {
courseId: this.courseId, contextLevel: this.contextLevel,
instanceId: this.instanceId,
}, },
}); });
} }

View File

@ -14,7 +14,7 @@
<core-loading [hideUntil]="loaded"> <core-loading [hideUntil]="loaded">
<ion-list *ngIf="blocks.length > 0"> <ion-list *ngIf="blocks.length > 0">
<ng-container *ngFor="let block of blocks"> <ng-container *ngFor="let block of blocks">
<core-block *ngIf="block.visible" [block]="block" contextLevel="course" [instanceId]="courseId"></core-block> <core-block *ngIf="block.visible" [block]="block" [contextLevel]="contextLevel" [instanceId]="instanceId"></core-block>
</ng-container> </ng-container>
</ion-list> </ion-list>

View File

@ -32,7 +32,8 @@ import { CoreCoursesDashboard } from '@features/courses/services/dashboard';
}) })
export class CoreBlockSideBlocksComponent implements OnInit { export class CoreBlockSideBlocksComponent implements OnInit {
@Input() courseId?: number; @Input() contextLevel!: string;
@Input() instanceId!: number;
@ViewChildren(CoreBlockComponent) blocksComponents?: QueryList<CoreBlockComponent>; @ViewChildren(CoreBlockComponent) blocksComponents?: QueryList<CoreBlockComponent>;
@ -56,8 +57,8 @@ export class CoreBlockSideBlocksComponent implements OnInit {
async invalidateBlocks(): Promise<void> { async invalidateBlocks(): Promise<void> {
const promises: Promise<void>[] = []; const promises: Promise<void>[] = [];
if (this.courseId) { if (this.contextLevel === 'course') {
promises.push(CoreCourse.invalidateCourseBlocks(this.courseId)); promises.push(CoreCourse.invalidateCourseBlocks(this.instanceId));
} else { } else {
promises.push(CoreCoursesDashboard.invalidateDashboardBlocks()); promises.push(CoreCoursesDashboard.invalidateDashboardBlocks());
} }
@ -79,8 +80,8 @@ export class CoreBlockSideBlocksComponent implements OnInit {
*/ */
async loadContent(): Promise<void> { async loadContent(): Promise<void> {
try { try {
if (this.courseId) { if (this.contextLevel === 'course') {
this.blocks = await CoreBlockHelper.getCourseBlocks(this.courseId); this.blocks = await CoreBlockHelper.getCourseBlocks(this.instanceId);
} else { } else {
const blocks = await CoreCoursesDashboard.getDashboardBlocks(); const blocks = await CoreCoursesDashboard.getDashboardBlocks();

View File

@ -44,7 +44,8 @@
</core-dynamic-component> </core-dynamic-component>
<core-block-side-blocks-button slot="fixed" *ngIf="loaded && course && displayBlocks && hasBlocks" [courseId]="course.id"> <core-block-side-blocks-button slot="fixed" *ngIf="loaded && course && displayBlocks && hasBlocks" contextlevel="course"
[instanceId]="course.id">
</core-block-side-blocks-button> </core-block-side-blocks-button>
<!-- Course Index button. --> <!-- Course Index button. -->

View File

@ -2,5 +2,5 @@
<core-dynamic-component [component]="componentClass" [data]="data"></core-dynamic-component> <core-dynamic-component [component]="componentClass" [data]="data"></core-dynamic-component>
</div> </div>
<core-block-side-blocks-button slot="fixed" *ngIf="course && hasBlocks" [courseId]="course.id"> <core-block-side-blocks-button slot="fixed" *ngIf="course && hasBlocks" contextLevel="course" [instanceId]="course.id">
</core-block-side-blocks-button> </core-block-side-blocks-button>

View File

@ -15,7 +15,8 @@
</ng-container> </ng-container>
</ion-list> </ion-list>
<core-block-side-blocks-button slot="fixed" *ngIf="hasSideBlocks"></core-block-side-blocks-button> <core-block-side-blocks-button slot="fixed" *ngIf="hasSideBlocks" contextLevel="user" [instanceId]="userId">
</core-block-side-blocks-button>
<core-empty-box *ngIf="blocks.length == 0" icon="fas-cubes" [message]="'core.course.nocontentavailable' | translate"> <core-empty-box *ngIf="blocks.length == 0" icon="fas-cubes" [message]="'core.course.nocontentavailable' | translate">
</core-empty-box> </core-empty-box>

View File

@ -45,7 +45,7 @@
</ng-container> </ng-container>
</ng-container> </ng-container>
</ion-list> </ion-list>
<core-block-side-blocks-button slot="fixed" *ngIf="hasBlocks" [courseId]="siteHomeId"> <core-block-side-blocks-button slot="fixed" *ngIf="hasBlocks" contextLevel="course" [instanceId]="siteHomeId">
</core-block-side-blocks-button> </core-block-side-blocks-button>
<core-empty-box *ngIf="!hasContent" icon="fas-box-open" [message]="'core.course.nocontentavailable' | translate"> <core-empty-box *ngIf="!hasContent" icon="fas-box-open" [message]="'core.course.nocontentavailable' | translate">