MOBILE-2201 course: Tag area handler for courses
parent
7546ac9e28
commit
eed78c8b6f
|
@ -1795,6 +1795,7 @@
|
|||
"core.submit": "moodle",
|
||||
"core.success": "moodle",
|
||||
"core.tablet": "local_moodlemobileapp",
|
||||
"core.tag.tagarea_course": "moodle",
|
||||
"core.tag.tags": "moodle",
|
||||
"core.teachers": "moodle",
|
||||
"core.thereisdatatosync": "local_moodlemobileapp",
|
||||
|
|
|
@ -1795,6 +1795,7 @@
|
|||
"core.submit": "Submit",
|
||||
"core.success": "Success",
|
||||
"core.tablet": "Tablet",
|
||||
"core.tag.tagarea_course": "Courses",
|
||||
"core.tag.tags": "Tags",
|
||||
"core.teachers": "Teachers",
|
||||
"core.thereisdatatosync": "There are offline {{$a}} to be synchronised.",
|
||||
|
|
|
@ -22,6 +22,7 @@ import { CoreCourseFormatComponent } from './format/format';
|
|||
import { CoreCourseModuleComponent } from './module/module';
|
||||
import { CoreCourseModuleCompletionComponent } from './module-completion/module-completion';
|
||||
import { CoreCourseModuleDescriptionComponent } from './module-description/module-description';
|
||||
import { CoreCourseTagAreaComponent } from './tag-area/tag-area';
|
||||
import { CoreCourseUnsupportedModuleComponent } from './unsupported-module/unsupported-module';
|
||||
|
||||
@NgModule({
|
||||
|
@ -30,6 +31,7 @@ import { CoreCourseUnsupportedModuleComponent } from './unsupported-module/unsup
|
|||
CoreCourseModuleComponent,
|
||||
CoreCourseModuleCompletionComponent,
|
||||
CoreCourseModuleDescriptionComponent,
|
||||
CoreCourseTagAreaComponent,
|
||||
CoreCourseUnsupportedModuleComponent
|
||||
],
|
||||
imports: [
|
||||
|
@ -46,10 +48,12 @@ import { CoreCourseUnsupportedModuleComponent } from './unsupported-module/unsup
|
|||
CoreCourseModuleComponent,
|
||||
CoreCourseModuleCompletionComponent,
|
||||
CoreCourseModuleDescriptionComponent,
|
||||
CoreCourseTagAreaComponent,
|
||||
CoreCourseUnsupportedModuleComponent
|
||||
],
|
||||
entryComponents: [
|
||||
CoreCourseUnsupportedModuleComponent
|
||||
CoreCourseUnsupportedModuleComponent,
|
||||
CoreCourseTagAreaComponent
|
||||
]
|
||||
})
|
||||
export class CoreCourseComponentsModule {}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<a ion-item text-wrap *ngFor="let item of items" (click)="openCourse(item.courseId)" [title]="item.courseName">
|
||||
<core-icon name="fa-graduation-cap" item-start></core-icon>
|
||||
<h2>{{ item.courseName }}</h2>
|
||||
<p *ngIf="item.categoryName">{{ 'core.category' | translate }}: {{ item.categoryName }}</p>
|
||||
</a>
|
|
@ -0,0 +1,43 @@
|
|||
// (C) Copyright 2015 Martin Dougiamas
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Component, Input, Optional } from '@angular/core';
|
||||
import { NavController } from 'ionic-angular';
|
||||
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||
|
||||
/**
|
||||
* Component that renders the course tag area.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'core-course-tag-area',
|
||||
templateUrl: 'core-course-tag-area.html'
|
||||
})
|
||||
export class CoreCourseTagAreaComponent {
|
||||
@Input() items: any[]; // Area items to render.
|
||||
|
||||
constructor(private navCtrl: NavController, @Optional() private splitviewCtrl: CoreSplitViewComponent,
|
||||
private courseHelper: CoreCourseHelperProvider) {}
|
||||
|
||||
/**
|
||||
* Open a course.
|
||||
*
|
||||
* @param {number} courseId The course to open.
|
||||
*/
|
||||
openCourse(courseId: number): void {
|
||||
// If this component is inside a split view, use the master nav to open it.
|
||||
const navCtrl = this.splitviewCtrl ? this.splitviewCtrl.getMasterNav() : this.navCtrl;
|
||||
this.courseHelper.getAndOpenCourse(navCtrl, courseId);
|
||||
}
|
||||
}
|
|
@ -33,6 +33,8 @@ import { CoreCourseFormatWeeksModule } from './formats/weeks/weeks.module';
|
|||
import { CoreCourseSyncProvider } from './providers/sync';
|
||||
import { CoreCourseSyncCronHandler } from './providers/sync-cron-handler';
|
||||
import { CoreCourseLogCronHandler } from './providers/log-cron-handler';
|
||||
import { CoreTagAreaDelegate } from '@core/tag/providers/area-delegate';
|
||||
import { CoreCourseTagAreaHandler } from './providers/course-tag-area-handler';
|
||||
|
||||
// List of providers (without handlers).
|
||||
export const CORE_COURSE_PROVIDERS: any[] = [
|
||||
|
@ -68,15 +70,18 @@ export const CORE_COURSE_PROVIDERS: any[] = [
|
|||
CoreCourseFormatDefaultHandler,
|
||||
CoreCourseModuleDefaultHandler,
|
||||
CoreCourseSyncCronHandler,
|
||||
CoreCourseLogCronHandler
|
||||
CoreCourseLogCronHandler,
|
||||
CoreCourseTagAreaHandler
|
||||
],
|
||||
exports: []
|
||||
})
|
||||
export class CoreCourseModule {
|
||||
constructor(cronDelegate: CoreCronDelegate, syncHandler: CoreCourseSyncCronHandler, logHandler: CoreCourseLogCronHandler,
|
||||
platform: Platform, eventsProvider: CoreEventsProvider) {
|
||||
platform: Platform, eventsProvider: CoreEventsProvider, tagAreaDelegate: CoreTagAreaDelegate,
|
||||
courseTagAreaHandler: CoreCourseTagAreaHandler) {
|
||||
cronDelegate.register(syncHandler);
|
||||
cronDelegate.register(logHandler);
|
||||
tagAreaDelegate.registerHandler(courseTagAreaHandler);
|
||||
|
||||
platform.resume.subscribe(() => {
|
||||
// Log the app is open to keep user in online status.
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
// (C) Copyright 2015 Martin Dougiamas
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreTagAreaHandler } from '@core/tag/providers/area-delegate';
|
||||
import { CoreCourseTagAreaComponent } from '../components/tag-area/tag-area';
|
||||
|
||||
/**
|
||||
* Handler to support tags.
|
||||
*/
|
||||
@Injectable()
|
||||
export class CoreCourseTagAreaHandler implements CoreTagAreaHandler {
|
||||
name = 'CoreCourseTagAreaHandler';
|
||||
type = 'core/course';
|
||||
|
||||
constructor(private domUtils: CoreDomUtilsProvider) {}
|
||||
|
||||
/**
|
||||
* Whether or not the handler is enabled on a site level.
|
||||
* @return {boolean|Promise<boolean>} Whether or not the handler is enabled on a site level.
|
||||
*/
|
||||
isEnabled(): boolean | Promise<boolean> {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the rendered content of a tag index and returns the items.
|
||||
*
|
||||
* @param {string} content Rendered content.
|
||||
* @return {any[]|Promise<any[]>} Area items (or promise resolved with the items).
|
||||
*/
|
||||
parseContent(content: string): any[] | Promise<any[]> {
|
||||
const items = [];
|
||||
const element = this.domUtils.convertToElement(content);
|
||||
|
||||
Array.from(element.querySelectorAll('div.coursebox')).forEach((coursebox) => {
|
||||
const courseId = parseInt(coursebox.getAttribute('data-courseid'), 10);
|
||||
const courseLink = coursebox.querySelector('.coursename > a');
|
||||
const categoryLink = coursebox.querySelector('.coursecat > a');
|
||||
|
||||
if (courseId > 0 && courseLink) {
|
||||
items.push({
|
||||
courseId,
|
||||
courseName: courseLink.innerHTML,
|
||||
categoryName: categoryLink ? categoryLink.innerHTML : null
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component to use to display items.
|
||||
*
|
||||
* @param {Injector} injector Injector.
|
||||
* @return {any|Promise<any>} The component (or promise resolved with component) to use, undefined if not found.
|
||||
*/
|
||||
getComponent(injector: Injector): any | Promise<any> {
|
||||
return CoreCourseTagAreaComponent;
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
{
|
||||
"tagarea_course": "Courses",
|
||||
"tags": "Tags"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue