Skip to content

Commit 6621fc5

Browse files
committed
MOBILE-3411 h5pactivity: Initial support of the activity
1 parent 9b39fb9 commit 6621fc5

File tree

15 files changed

+565
-3
lines changed

15 files changed

+565
-3
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// (C) Copyright 2015 Moodle Pty Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { NgModule } from '@angular/core';
16+
import { CommonModule } from '@angular/common';
17+
import { IonicModule } from 'ionic-angular';
18+
import { TranslateModule } from '@ngx-translate/core';
19+
import { CoreComponentsModule } from '@components/components.module';
20+
import { CoreDirectivesModule } from '@directives/directives.module';
21+
import { CoreCourseComponentsModule } from '@core/course/components/components.module';
22+
import { AddonModH5PActivityIndexComponent } from './index/index';
23+
24+
@NgModule({
25+
declarations: [
26+
AddonModH5PActivityIndexComponent,
27+
],
28+
imports: [
29+
CommonModule,
30+
IonicModule,
31+
TranslateModule.forChild(),
32+
CoreComponentsModule,
33+
CoreDirectivesModule,
34+
CoreCourseComponentsModule
35+
],
36+
providers: [
37+
],
38+
exports: [
39+
AddonModH5PActivityIndexComponent,
40+
],
41+
entryComponents: [
42+
AddonModH5PActivityIndexComponent,
43+
]
44+
})
45+
export class AddonModH5PActivityComponentsModule {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!-- Buttons to add to the header. -->
2+
<core-navbar-buttons end>
3+
<core-context-menu>
4+
<core-context-menu-item *ngIf="externalUrl" [priority]="900" [content]="'core.openinbrowser' | translate" [href]="externalUrl" [iconAction]="'open'"></core-context-menu-item>
5+
<core-context-menu-item *ngIf="description" [priority]="800" [content]="'core.moduleintro' | translate" (action)="expandDescription()" [iconAction]="'arrow-forward'"></core-context-menu-item>
6+
<core-context-menu-item *ngIf="blog" [priority]="750" content="{{'addon.blog.blog' | translate}}" [iconAction]="'fa-newspaper-o'" (action)="gotoBlog($event)"></core-context-menu-item>
7+
<core-context-menu-item *ngIf="loaded && isOnline" [priority]="700" [content]="'core.refresh' | translate" (action)="doRefresh(null, $event)" [iconAction]="refreshIcon" [closeOnClick]="false"></core-context-menu-item>
8+
</core-context-menu>
9+
</core-navbar-buttons>
10+
11+
<!-- Content. -->
12+
<core-loading [hideUntil]="loaded" class="core-loading-center safe-area-page">
13+
14+
<core-course-module-description [description]="description" [component]="component" [componentId]="componentId" contextLevel="module" [contextInstanceId]="module.id" [courseId]="courseId"></core-course-module-description>
15+
16+
<!-- TODO -->
17+
</core-loading>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// (C) Copyright 2015 Moodle Pty Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { Component, Optional, Injector } from '@angular/core';
16+
import { Content } from 'ionic-angular';
17+
import { CoreCourseModuleMainActivityComponent } from '@core/course/classes/main-activity-component';
18+
import { AddonModH5PActivity, AddonModH5PActivityProvider, AddonModH5PActivityData } from '../../providers/h5pactivity';
19+
20+
/**
21+
* Component that displays an H5P activity entry page.
22+
*/
23+
@Component({
24+
selector: 'addon-mod-h5pactivity-index',
25+
templateUrl: 'addon-mod-h5pactivity-index.html',
26+
})
27+
export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActivityComponent {
28+
component = AddonModH5PActivityProvider.COMPONENT;
29+
moduleName = 'h5pactivity';
30+
31+
h5pActivity: AddonModH5PActivityData; // The H5P activity object.
32+
33+
protected fetchContentDefaultError = 'addon.mod_h5pactivity.errorgetactivity';
34+
35+
constructor(injector: Injector,
36+
@Optional() protected content: Content) {
37+
super(injector, content);
38+
}
39+
40+
/**
41+
* Component being initialized.
42+
*/
43+
ngOnInit(): void {
44+
super.ngOnInit();
45+
46+
this.loadContent();
47+
}
48+
49+
/**
50+
* Check the completion.
51+
*/
52+
protected checkCompletion(): void {
53+
this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata);
54+
}
55+
56+
/**
57+
* Get the activity data.
58+
*
59+
* @param refresh If it's refreshing content.
60+
* @param sync If it should try to sync.
61+
* @param showErrors If show errors to the user of hide them.
62+
* @return Promise resolved when done.
63+
*/
64+
protected async fetchContent(refresh: boolean = false, sync: boolean = false, showErrors: boolean = false): Promise<void> {
65+
try {
66+
this.h5pActivity = await AddonModH5PActivity.instance.getH5PActivity(this.courseId, this.module.id);
67+
68+
this.description = this.h5pActivity.intro;
69+
this.dataRetrieved.emit(this.h5pActivity);
70+
} finally {
71+
this.fillContextMenu(refresh);
72+
}
73+
}
74+
75+
/**
76+
* Perform the invalidate content function.
77+
*
78+
* @return Resolved when done.
79+
*/
80+
protected invalidateContent(): Promise<any> {
81+
return AddonModH5PActivity.instance.invalidateActivityData(this.courseId);
82+
}
83+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// (C) Copyright 2015 Moodle Pty Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { NgModule } from '@angular/core';
16+
import { AddonModH5PActivityComponentsModule } from './components/components.module';
17+
import { AddonModH5PActivityModuleHandler } from './providers/module-handler';
18+
import { AddonModH5PActivityProvider } from './providers/h5pactivity';
19+
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
20+
21+
// List of providers (without handlers).
22+
export const ADDON_MOD_H5P_ACTIVITY_PROVIDERS: any[] = [
23+
AddonModH5PActivityProvider,
24+
];
25+
26+
@NgModule({
27+
declarations: [
28+
],
29+
imports: [
30+
AddonModH5PActivityComponentsModule
31+
],
32+
providers: [
33+
AddonModH5PActivityProvider,
34+
AddonModH5PActivityModuleHandler,
35+
]
36+
})
37+
export class AddonModH5PActivityModule {
38+
constructor(moduleDelegate: CoreCourseModuleDelegate,
39+
moduleHandler: AddonModH5PActivityModuleHandler) {
40+
41+
moduleDelegate.registerHandler(moduleHandler);
42+
}
43+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"errorgetactivity": "Error getting H5P activity data.",
3+
"modulenameplural": "H5P"
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<ion-header>
2+
<ion-navbar core-back-button>
3+
<ion-title><core-format-text [text]="title" contextLevel="module" [contextInstanceId]="module.id" [courseId]="courseId"></core-format-text></ion-title>
4+
5+
<ion-buttons end>
6+
<!-- The buttons defined by the component will be added in here. -->
7+
</ion-buttons>
8+
</ion-navbar>
9+
</ion-header>
10+
<ion-content>
11+
<ion-refresher [enabled]="h5pComponent.loaded" (ionRefresh)="h5pComponent.doRefresh($event)">
12+
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
13+
</ion-refresher>
14+
15+
<addon-mod-h5pactivity-index [module]="module" [courseId]="courseId" (dataRetrieved)="updateData($event)"></addon-mod-h5pactivity-index>
16+
</ion-content>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// (C) Copyright 2015 Moodle Pty Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { NgModule } from '@angular/core';
16+
import { IonicPageModule } from 'ionic-angular';
17+
import { TranslateModule } from '@ngx-translate/core';
18+
import { CoreDirectivesModule } from '@directives/directives.module';
19+
import { AddonModH5PActivityComponentsModule } from '../../components/components.module';
20+
import { AddonModH5PActivityIndexPage } from './index';
21+
22+
@NgModule({
23+
declarations: [
24+
AddonModH5PActivityIndexPage,
25+
],
26+
imports: [
27+
CoreDirectivesModule,
28+
AddonModH5PActivityComponentsModule,
29+
IonicPageModule.forChild(AddonModH5PActivityIndexPage),
30+
TranslateModule.forChild()
31+
],
32+
})
33+
export class AddonModH5PActivityIndexPageModule {}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// (C) Copyright 2015 Moodle Pty Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { Component, ViewChild } from '@angular/core';
16+
import { IonicPage, NavParams } from 'ionic-angular';
17+
import { AddonModH5PActivityIndexComponent } from '../../components/index/index';
18+
import { AddonModH5PActivityData } from '../../providers/h5pactivity';
19+
20+
/**
21+
* Page that displays an H5P activity.
22+
*/
23+
@IonicPage({ segment: 'addon-mod-h5pactivity-index' })
24+
@Component({
25+
selector: 'page-addon-mod-h5pactivity-index',
26+
templateUrl: 'index.html',
27+
})
28+
export class AddonModH5PActivityIndexPage {
29+
@ViewChild(AddonModH5PActivityIndexComponent) h5pComponent: AddonModH5PActivityIndexComponent;
30+
31+
title: string;
32+
module: any;
33+
courseId: number;
34+
35+
constructor(navParams: NavParams) {
36+
this.module = navParams.get('module') || {};
37+
this.courseId = navParams.get('courseId');
38+
this.title = this.module.name;
39+
}
40+
41+
/**
42+
* Update some data based on the H5P activity instance.
43+
*
44+
* @param h5p H5P activity instance.
45+
*/
46+
updateData(h5p: AddonModH5PActivityData): void {
47+
this.title = h5p.name || this.title;
48+
}
49+
}

0 commit comments

Comments
 (0)