Merge pull request #2186 from NoelDeMartin/MOBILE-3235

Mobile 3235
main
Juan Leyva 2019-12-04 15:48:31 +01:00 committed by GitHub
commit 24197e3657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 7 deletions

View File

@ -16,8 +16,9 @@ import { Component, OnInit, Injector, Input } from '@angular/core';
import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate'; import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component'; import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component';
import { CoreConstants } from '@core/constants'; import { CoreConstants, ContextLevel } from '@core/constants';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { CoreSitesProvider } from '@providers/sites';
/** /**
* Component to render an "activity modules" block. * Component to render an "activity modules" block.
@ -28,7 +29,7 @@ import { TranslateService } from '@ngx-translate/core';
}) })
export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent implements OnInit { export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent implements OnInit {
@Input() block: any; // The block to render. @Input() block: any; // The block to render.
@Input() contextLevel: string; // The context where the block will be used. @Input() contextLevel: ContextLevel; // The context where the block will be used.
@Input() instanceId: number; // The instance ID associated with the context level. @Input() instanceId: number; // The instance ID associated with the context level.
entries: any[] = []; entries: any[] = [];
@ -36,7 +37,8 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i
protected fetchContentDefaultError = 'Error getting activity modules data.'; protected fetchContentDefaultError = 'Error getting activity modules data.';
constructor(injector: Injector, protected courseProvider: CoreCourseProvider, constructor(injector: Injector, protected courseProvider: CoreCourseProvider,
protected translate: TranslateService, protected moduleDelegate: CoreCourseModuleDelegate) { protected translate: TranslateService, protected moduleDelegate: CoreCourseModuleDelegate,
protected sitesProvider: CoreSitesProvider) {
super(injector, 'AddonBlockActivityModulesComponent'); super(injector, 'AddonBlockActivityModulesComponent');
} }
@ -63,8 +65,7 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected fetchContent(): Promise<any> { protected fetchContent(): Promise<any> {
return this.courseProvider.getSections(this.instanceId, false, true).then((sections) => { return this.courseProvider.getSections(this.getCourseId(), false, true).then((sections) => {
this.entries = []; this.entries = [];
const archetypes = {}, const archetypes = {},
@ -122,4 +123,18 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i
} }
}); });
} }
/**
* Obtain the appropiate course id for the block.
*
* @return Course id.
*/
protected getCourseId(): number {
switch (this.contextLevel) {
case ContextLevel.COURSE:
return this.instanceId;
default:
return this.sitesProvider.getCurrentSiteHomeId();
}
}
} }

View File

@ -60,7 +60,7 @@
</ion-item> </ion-item>
<a ion-item text-wrap *ngIf="categoryPath"> <a ion-item text-wrap *ngIf="categoryPath">
<h2>{{ 'core.category' | translate}}</h2> <h2>{{ 'core.category' | translate}}</h2>
<p><core-format-text [text]="categoryPath" contextLevel="category" [contextInstanceId]="event.category.id"></core-format-text></p> <p><core-format-text [text]="categoryPath" contextLevel="coursecat" [contextInstanceId]="event.category.id"></core-format-text></p>
</a> </a>
<ion-item text-wrap *ngIf="event.description"> <ion-item text-wrap *ngIf="event.description">
<h2>{{ 'core.description' | translate}}</h2> <h2>{{ 'core.description' | translate}}</h2>

View File

@ -144,7 +144,7 @@ export class AddonCalendarHelperProvider {
courseId = e.course ? e.course.id : e.courseid; courseId = e.course ? e.course.id : e.courseid;
if (categoryId > 0) { if (categoryId > 0) {
e.contextLevel = 'category'; e.contextLevel = 'coursecat';
e.contextInstanceId = categoryId; e.contextInstanceId = categoryId;
} else if (courseId > 0) { } else if (courseId > 0) {
e.contextLevel = 'course'; e.contextLevel = 'course';

View File

@ -12,6 +12,18 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
/**
* Context levels enumeration.
*/
export const enum ContextLevel {
SYSTEM = 'system',
USER = 'user',
COURSECAT = 'coursecat',
COURSE = 'course',
MODULE = 'module',
BLOCK = 'block',
}
/** /**
* Static class to contain all the core constants. * Static class to contain all the core constants.
*/ */