From 14ccd74b3aeb2337aa4d2d6f671e5023b18a6165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 5 Mar 2018 17:42:54 +0100 Subject: [PATCH] MOBILE-2340 folder: Folder activity implementation --- .../folder/components/components.module.ts | 45 ++++ .../mod/folder/components/index/index.html | 29 +++ .../mod/folder/components/index/index.ts | 212 ++++++++++++++++++ src/addon/mod/folder/folder.module.ts | 38 ++++ src/addon/mod/folder/lang/en.json | 4 + src/addon/mod/folder/pages/index/index.html | 16 ++ .../mod/folder/pages/index/index.module.ts | 33 +++ src/addon/mod/folder/pages/index/index.ts | 50 +++++ src/addon/mod/folder/providers/folder.ts | 147 ++++++++++++ src/addon/mod/folder/providers/helper.ts | 90 ++++++++ .../mod/folder/providers/module-handler.ts | 70 ++++++ src/app/app.module.ts | 2 + 12 files changed, 736 insertions(+) create mode 100644 src/addon/mod/folder/components/components.module.ts create mode 100644 src/addon/mod/folder/components/index/index.html create mode 100644 src/addon/mod/folder/components/index/index.ts create mode 100644 src/addon/mod/folder/folder.module.ts create mode 100644 src/addon/mod/folder/lang/en.json create mode 100644 src/addon/mod/folder/pages/index/index.html create mode 100644 src/addon/mod/folder/pages/index/index.module.ts create mode 100644 src/addon/mod/folder/pages/index/index.ts create mode 100644 src/addon/mod/folder/providers/folder.ts create mode 100644 src/addon/mod/folder/providers/helper.ts create mode 100644 src/addon/mod/folder/providers/module-handler.ts diff --git a/src/addon/mod/folder/components/components.module.ts b/src/addon/mod/folder/components/components.module.ts new file mode 100644 index 000000000..8edeb4c95 --- /dev/null +++ b/src/addon/mod/folder/components/components.module.ts @@ -0,0 +1,45 @@ +// (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 { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { IonicModule } from 'ionic-angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreComponentsModule } from '@components/components.module'; +import { CoreDirectivesModule } from '@directives'; +import { CoreCourseComponentsModule } from '@core/course/components/components.module'; +import { AddonModFolderIndexComponent } from './index/index'; + +@NgModule({ + declarations: [ + AddonModFolderIndexComponent + ], + imports: [ + CommonModule, + IonicModule, + TranslateModule.forChild(), + CoreComponentsModule, + CoreDirectivesModule, + CoreCourseComponentsModule + ], + providers: [ + ], + exports: [ + AddonModFolderIndexComponent + ], + entryComponents: [ + AddonModFolderIndexComponent + ] +}) +export class AddonModFolderComponentsModule {} diff --git a/src/addon/mod/folder/components/index/index.html b/src/addon/mod/folder/components/index/index.html new file mode 100644 index 000000000..48bc258e1 --- /dev/null +++ b/src/addon/mod/folder/components/index/index.html @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + +

{{file.name}}

+
+ +
+
+ + + +
diff --git a/src/addon/mod/folder/components/index/index.ts b/src/addon/mod/folder/components/index/index.ts new file mode 100644 index 000000000..326c34b61 --- /dev/null +++ b/src/addon/mod/folder/components/index/index.ts @@ -0,0 +1,212 @@ +// (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, OnInit, OnDestroy, Input, Output, EventEmitter, Optional } from '@angular/core'; +import { NavParams, NavController, Content } from 'ionic-angular'; +import { TranslateService } from '@ngx-translate/core'; +import { CoreAppProvider } from '@providers/app'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { CoreTextUtilsProvider } from '@providers/utils/text'; +import { CoreCourseProvider } from '@core/course/providers/course'; +import { CoreCourseHelperProvider } from '@core/course/providers/helper'; +import { CoreCourseModuleMainComponent } from '@core/course/providers/module-delegate'; +import { AddonModFolderProvider } from '../../providers/folder'; +import { AddonModFolderHelperProvider } from '../../providers/helper'; + +/** + * Component that displays a folder. + * @todo Adding a new file in a folder updates the revision of all the files, so they're all shown as outdated. + * To ignore revision in folders we'll have to modify $mmCoursePrefetchDelegate, core-file and $mmFilepool. + */ +@Component({ + selector: 'addon-mod-folder-index', + templateUrl: 'index.html', +}) +export class AddonModFolderIndexComponent implements OnInit, OnDestroy, CoreCourseModuleMainComponent { + @Input() module: any; // The module of the folder. + @Input() courseId: number; // Course ID the folder belongs to. + @Input() path: string; // For subfolders. Use the path instead of a boolean so Angular detects them as different states. + @Output() folderRetrieved?: EventEmitter; + + loaded: boolean; + canReload: boolean; + component = AddonModFolderProvider.COMPONENT; + componentId: number; + canGetFolder: boolean; + contents: any; + + // Data for context menu. + externalUrl: string; + description: string; + refreshIcon: string; + prefetchStatusIcon: string; + prefetchText: string; + size: string; + + protected isDestroyed; + protected statusObserver; + + constructor(private folderProvider: AddonModFolderProvider, private courseProvider: CoreCourseProvider, + private domUtils: CoreDomUtilsProvider, private appProvider: CoreAppProvider, private textUtils: CoreTextUtilsProvider, + private courseHelper: CoreCourseHelperProvider, private translate: TranslateService, + @Optional() private content: Content, private folderHelper: AddonModFolderHelperProvider) { + this.folderRetrieved = new EventEmitter(); + } + + /** + * Component being initialized. + */ + ngOnInit(): void { + this.description = this.module.description; + this.componentId = this.module.id; + this.externalUrl = this.module.url; + this.loaded = false; + this.canReload = false; + this.refreshIcon = 'spinner'; + + this.canGetFolder = this.folderProvider.isGetFolderWSAvailable(); + + if (this.path) { + // Subfolder. Use module param. + this.showModuleData(this.module); + this.loaded = true; + this.canReload = false; + this.refreshIcon = 'refresh'; + } else { + this.fetchContent().then(() => { + this.folderProvider.logView(this.module.instance).then(() => { + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + }); + }).finally(() => { + this.loaded = true; + this.canReload = true; + this.refreshIcon = 'refresh'; + }); + } + } + + /** + * Refresh the data. + * + * @param {any} [refresher] Refresher. + * @param {Function} [done] Function to call when done. + * @return {Promise} Promise resolved when done. + */ + doRefresh(refresher?: any, done?: () => void): Promise { + if (this.canReload) { + this.refreshIcon = 'spinner'; + + return this.folderProvider.invalidateContent(this.module.id, this.courseId).catch(() => { + // Ignore errors. + }).then(() => { + return this.fetchContent(true); + }).finally(() => { + this.refreshIcon = 'refresh'; + refresher && refresher.complete(); + done && done(); + }); + } + } + + /** + * Expand the description. + */ + expandDescription(): void { + this.textUtils.expandText(this.translate.instant('core.description'), this.description, this.component, this.module.id); + } + + /** + * Prefetch the module. + */ + prefetch(): void { + this.courseHelper.contextMenuPrefetch(this, this.module, this.courseId); + } + + /** + * Confirm and remove downloaded files. + */ + removeFiles(): void { + this.courseHelper.confirmAndRemoveFiles(this.module, this.courseId); + } + + /** + * Convenience function to set scope data using module. + * @param {any} module Module to show. + */ + protected showModuleData(module: any): void { + this.description = module.intro || module.description; + + this.folderRetrieved.emit(module); + + if (this.path) { + // Subfolder. + this.contents = module.contents; + } else { + this.contents = this.folderHelper.formatContents(module.contents); + } + } + + /** + * Download folder contents. + * + * @param {boolean} [refresh] Whether we're refreshing data. + * @return {Promise} Promise resolved when done. + */ + protected fetchContent(refresh?: boolean): Promise { + let promise; + + if (this.canGetFolder) { + promise = this.folderProvider.getFolder(this.courseId, this.module.id).then((folder) => { + return this.courseProvider.loadModuleContents(this.module, this.courseId).then(() => { + folder.contents = this.module.contents; + + return folder; + }); + }); + } else { + promise = this.courseProvider.getModule(this.module.id, this.courseId).then((folder) => { + if (!folder.contents.length && this.module.contents.length && !this.appProvider.isOnline()) { + // The contents might be empty due to a cached data. Use the old ones. + folder.contents = this.module.contents; + } + this.module = folder; + + return folder; + }); + } + + return promise.then((folder) => { + if (folder) { + this.description = folder.intro || folder.description; + this.folderRetrieved.emit(folder); + } + + this.showModuleData(folder); + + // All data obtained, now fill the context menu. + this.courseHelper.fillContextMenu(this, this.module, this.courseId, refresh, this.component); + }).catch((error) => { + // Error getting data, fail. + this.domUtils.showErrorModalDefault(error, 'core.course.errorgetmodule', true); + }).finally(() => { + this.loaded = true; + this.refreshIcon = 'refresh'; + }); + } + + ngOnDestroy(): void { + this.isDestroyed = true; + this.statusObserver && this.statusObserver.off(); + } +} diff --git a/src/addon/mod/folder/folder.module.ts b/src/addon/mod/folder/folder.module.ts new file mode 100644 index 000000000..b21495eb9 --- /dev/null +++ b/src/addon/mod/folder/folder.module.ts @@ -0,0 +1,38 @@ +// (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 { NgModule } from '@angular/core'; +import { AddonModFolderProvider } from './providers/folder'; +import { AddonModFolderHelperProvider } from './providers/helper'; +import { AddonModFolderModuleHandler } from './providers/module-handler'; +import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate'; +import { AddonModFolderComponentsModule } from './components/components.module'; + +@NgModule({ + declarations: [ + ], + imports: [ + AddonModFolderComponentsModule + ], + providers: [ + AddonModFolderProvider, + AddonModFolderHelperProvider, + AddonModFolderModuleHandler + ] +}) +export class AddonModFolderModule { + constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModFolderModuleHandler) { + moduleDelegate.registerHandler(moduleHandler); + } +} diff --git a/src/addon/mod/folder/lang/en.json b/src/addon/mod/folder/lang/en.json new file mode 100644 index 000000000..57d4c7f95 --- /dev/null +++ b/src/addon/mod/folder/lang/en.json @@ -0,0 +1,4 @@ +{ + "emptyfilelist": "There are no files to show.", + "errorwhilegettingfolder": "Error while getting folder data." +} \ No newline at end of file diff --git a/src/addon/mod/folder/pages/index/index.html b/src/addon/mod/folder/pages/index/index.html new file mode 100644 index 000000000..9830c28cf --- /dev/null +++ b/src/addon/mod/folder/pages/index/index.html @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/src/addon/mod/folder/pages/index/index.module.ts b/src/addon/mod/folder/pages/index/index.module.ts new file mode 100644 index 000000000..5091915b2 --- /dev/null +++ b/src/addon/mod/folder/pages/index/index.module.ts @@ -0,0 +1,33 @@ +// (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 { NgModule } from '@angular/core'; +import { IonicPageModule } from 'ionic-angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreDirectivesModule } from '@directives'; +import { AddonModFolderComponentsModule } from '../../components/components.module'; +import { AddonModFolderIndexPage } from './index'; + +@NgModule({ + declarations: [ + AddonModFolderIndexPage, + ], + imports: [ + CoreDirectivesModule, + AddonModFolderComponentsModule, + IonicPageModule.forChild(AddonModFolderIndexPage), + TranslateModule.forChild() + ], +}) +export class AddonModFolderIndexPageModule {} diff --git a/src/addon/mod/folder/pages/index/index.ts b/src/addon/mod/folder/pages/index/index.ts new file mode 100644 index 000000000..e0b187c19 --- /dev/null +++ b/src/addon/mod/folder/pages/index/index.ts @@ -0,0 +1,50 @@ +// (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, ViewChild } from '@angular/core'; +import { IonicPage, NavParams } from 'ionic-angular'; +import { AddonModFolderIndexComponent } from '../../components/index/index'; + +/** + * Page that displays a folder. + */ +@IonicPage({ segment: 'addon-mod-folder-index' }) +@Component({ + selector: 'page-addon-mod-folder-index', + templateUrl: 'index.html', +}) +export class AddonModFolderIndexPage { + @ViewChild(AddonModFolderIndexComponent) folderComponent: AddonModFolderIndexComponent; + + title: string; + module: any; + courseId: number; + path: string; + + constructor(navParams: NavParams) { + this.module = navParams.get('module') || {}; + this.courseId = navParams.get('courseId'); + this.path = navParams.get('path'); + this.title = this.module.name; + } + + /** + * Update some data based on the folder instance. + * + * @param {any} folder Folder instance. + */ + updateData(folder: any): void { + this.title = folder.name || this.title; + } +} diff --git a/src/addon/mod/folder/providers/folder.ts b/src/addon/mod/folder/providers/folder.ts new file mode 100644 index 000000000..5f019f9c8 --- /dev/null +++ b/src/addon/mod/folder/providers/folder.ts @@ -0,0 +1,147 @@ +// (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 } from '@angular/core'; +import { CoreLoggerProvider } from '@providers/logger'; +import { CoreSitesProvider } from '@providers/sites'; +import { CoreUtilsProvider } from '@providers/utils/utils'; +import { CoreCourseProvider } from '@core/course/providers/course'; + +/** + * Service that provides some features for folder. + */ +@Injectable() +export class AddonModFolderProvider { + static COMPONENT = 'mmaModFolder'; + + protected ROOT_CACHE_KEY = 'mmaModFolder:'; + protected logger; + + constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private courseProvider: CoreCourseProvider, + private utils: CoreUtilsProvider) { + this.logger = logger.getInstance('mmaModFolderProvider'); + } + + /** + * Get a folder by course module ID. + * + * @param {number} courseId Course ID. + * @param {number} cmId Course module ID. + * @param {string} [siteId] Site ID. If not defined, current site. + * @return {Promise} Promise resolved when the book is retrieved. + */ + getFolder(courseId: number, cmId: number, siteId?: string): Promise { + return this.getFolderByKey(courseId, 'coursemodule', cmId, siteId); + } + + /** + * Get a folder. + * + * @param {number} courseId Course ID. + * @param {string} key Name of the property to check. + * @param {any} value Value to search. + * @param {string} [siteId] Site ID. If not defined, current site. + * @return {Promise} Promise resolved when the book is retrieved. + */ + protected getFolderByKey(courseId: number, key: string, value: any, siteId?: string): Promise { + return this.sitesProvider.getSite(siteId).then((site) => { + const params = { + courseids: [courseId] + }, + preSets = { + cacheKey: this.getFolderCacheKey(courseId) + }; + + return site.read('mod_folder_get_folders_by_courses', params, preSets).then((response) => { + if (response && response.folders) { + const currentFolder = response.folders.find((folder) => { + return folder[key] == value; + }); + if (currentFolder) { + return currentFolder; + } + } + + return Promise.reject(null); + }); + }); + } + + /** + * Get cache key for folder data WS calls. + * + * @param {number} courseId Course ID. + * @return {string} Cache key. + */ + protected getFolderCacheKey(courseId: number): string { + return this.ROOT_CACHE_KEY + 'folder:' + courseId; + } + + /** + * Invalidate the prefetched content. + * + * @param {number} moduleId The module ID. + * @param {number} courseId Course ID of the module. + * @param {string} [siteId] Site ID. If not defined, current site. + * @return {Promise} + */ + invalidateContent(moduleId: number, courseId: number, siteId?: string): Promise { + const promises = []; + + promises.push(this.invalidateFolderData(courseId, siteId)); + promises.push(this.courseProvider.invalidateModule(moduleId, siteId)); + + return this.utils.allPromises(promises); + } + + /** + * Invalidates folder data. + * + * @param {number} courseId Course ID. + * @param {string} [siteId] Site ID. If not defined, current site. + * @return {Promise} Promise resolved when the data is invalidated. + */ + invalidateFolderData(courseId: number, siteId?: string): Promise { + return this.sitesProvider.getSite(siteId).then((site) => { + return site.invalidateWsCacheForKey(this.getFolderCacheKey(courseId)); + }); + } + + /** + * Returns whether or not getFolder WS available or not. + * + * @return {boolean} If WS is avalaible. + */ + isGetFolderWSAvailable(): boolean { + return this.sitesProvider.wsAvailableInCurrentSite('mod_folder_get_folders_by_courses'); + } + + /** + * Report a folder as being viewed. + * + * @param {number} id Module ID. + * @return {Promise} Promise resolved when the WS call is successful. + */ + logView(id: number): Promise { + if (id) { + const params = { + folderid: id + }; + + return this.sitesProvider.getCurrentSite().write('mod_folder_view_folder', params); + } + + return Promise.reject(null); + } +} diff --git a/src/addon/mod/folder/providers/helper.ts b/src/addon/mod/folder/providers/helper.ts new file mode 100644 index 000000000..0527eff2a --- /dev/null +++ b/src/addon/mod/folder/providers/helper.ts @@ -0,0 +1,90 @@ +// (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 } from '@angular/core'; +import { CoreLoggerProvider } from '@providers/logger'; +import { CoreCourseProvider } from '@core/course/providers/course'; + +/** + * Service that provides some features for folder. + */ +@Injectable() +export class AddonModFolderHelperProvider { + + constructor(logger: CoreLoggerProvider, private courseProvider: CoreCourseProvider) { + } + + /** + * Format folder contents, creating directory structure. + * Folders found in filepaths are added to the array. Each folder has the properties: name, fileicon, + * type (folder), filepath and contents (array with files and subfolders). + * + * @param {any[]} contents Folder contents. + * @return {any[]} Formatted contents. + */ + formatContents(contents: any[]): any[] { + const files = [], + folders = [], + folderIcon = this.courseProvider.getModuleIconSrc('folder'); + + contents.forEach((entry) => { + if (entry.filepath !== '/') { + // It's a file in a subfolder. Lets treat the path to add the subfolders to the array. + let directories, + currentList = folders, // Start at root level. + path = entry.filepath, + subpath = ''; + + // Remove first and last slash if needed. + if (path.substr(0, 1) === '/') { + path = path.substr(1); + } + if (path.substr(path.length - 1) === '/') { + path = path.slice(0, -1); + } + + directories = path.split('/'); + + directories.forEach((directory) => { + subpath = subpath + '/' + directory; + // Search if the directory is already stored in folders array. + const foundList = currentList.find((list) => { + return list.name === directory; + }); + + if (foundList) { + currentList = foundList.contents; + } else { + // Directory not found. Add it to the array. + const newFolder = { + name: directory, + fileicon: folderIcon, + contents: [], + filepath: subpath, + type: 'folder' + }; + currentList.push(newFolder); + currentList = newFolder.contents; + } + }); + + currentList.push(entry); + } else { + files.push(entry); + } + }); + + return folders.concat(files); + } +} diff --git a/src/addon/mod/folder/providers/module-handler.ts b/src/addon/mod/folder/providers/module-handler.ts new file mode 100644 index 000000000..e30a9b890 --- /dev/null +++ b/src/addon/mod/folder/providers/module-handler.ts @@ -0,0 +1,70 @@ +// (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 } from '@angular/core'; +import { NavController, NavOptions } from 'ionic-angular'; +import { AddonModFolderIndexComponent } from '../components/index/index'; +import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@core/course/providers/module-delegate'; +import { CoreCourseProvider } from '@core/course/providers/course'; + +/** + * Handler to support folder modules. + */ +@Injectable() +export class AddonModFolderModuleHandler implements CoreCourseModuleHandler { + name = 'folder'; + + constructor(private courseProvider: CoreCourseProvider) { } + + /** + * Check if the handler is enabled on a site level. + * + * @return {boolean|Promise} Whether or not the handler is enabled on a site level. + */ + isEnabled(): boolean | Promise { + return true; + } + + /** + * Get the data required to display the module in the course contents view. + * + * @param {any} module The module object. + * @param {number} courseId The course ID. + * @param {number} sectionId The section ID. + * @return {CoreCourseModuleHandlerData} Data to render the module. + */ + getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { + return { + icon: this.courseProvider.getModuleIconSrc('folder'), + title: module.name, + class: 'addon-mod_folder-handler', + showDownloadButton: true, + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { + navCtrl.push('AddonModFolderIndexPage', {module: module, courseId: courseId}, options); + } + }; + } + + /** + * Get the component to render the module. This is needed to support singleactivity course format. + * The component returned must implement CoreCourseModuleMainComponent. + * + * @param {any} course The course object. + * @param {any} module The module object. + * @return {any} The component to use, undefined if not found. + */ + getMainComponent(course: any, module: any): any { + return AddonModFolderIndexComponent; + } +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 615e5096f..3748cb268 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -76,6 +76,7 @@ import { AddonFilesModule } from '@addon/files/files.module'; import { AddonModBookModule } from '@addon/mod/book/book.module'; import { AddonModLabelModule } from '@addon/mod/label/label.module'; import { AddonModResourceModule } from '@addon/mod/resource/resource.module'; +import { AddonModFolderModule } from '@addon/mod/folder/folder.module'; import { AddonMessagesModule } from '@addon/messages/messages.module'; import { AddonPushNotificationsModule } from '@addon/pushnotifications/pushnotifications.module'; @@ -155,6 +156,7 @@ export const CORE_PROVIDERS: any[] = [ AddonModBookModule, AddonModLabelModule, AddonModResourceModule, + AddonModFolderModule, AddonMessagesModule, AddonPushNotificationsModule ],