MOBILE-3213 folder: Fix opening subfolders

main
Pau Ferrer Ocaña 2019-12-12 16:40:47 +01:00
parent 9e9b4bcbbe
commit b74381c626
1 changed files with 9 additions and 9 deletions

View File

@ -34,7 +34,6 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo
component = AddonModFolderProvider.COMPONENT; component = AddonModFolderProvider.COMPONENT;
canGetFolder: boolean; canGetFolder: boolean;
contents: any; contents: any;
moduleContents: any;
constructor(injector: Injector, private folderProvider: AddonModFolderProvider, private courseProvider: CoreCourseProvider, constructor(injector: Injector, private folderProvider: AddonModFolderProvider, private courseProvider: CoreCourseProvider,
private appProvider: CoreAppProvider, private folderHelper: AddonModFolderHelperProvider) { private appProvider: CoreAppProvider, private folderHelper: AddonModFolderHelperProvider) {
@ -51,7 +50,7 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo
if (this.path) { if (this.path) {
// Subfolder. Use module param. // Subfolder. Use module param.
this.showModuleData(this.module); this.showModuleData(this.module, this.module.contents);
this.loaded = true; this.loaded = true;
this.refreshIcon = 'refresh'; this.refreshIcon = 'refresh';
} else { } else {
@ -81,16 +80,16 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo
* Convenience function to set scope data using module. * Convenience function to set scope data using module.
* @param module Module to show. * @param module Module to show.
*/ */
protected showModuleData(module: any): void { protected showModuleData(module: any, folderContents: any): void {
this.description = module.intro || module.description; this.description = module.intro || module.description;
this.dataRetrieved.emit(module); this.dataRetrieved.emit(module);
if (this.path) { if (this.path) {
// Subfolder. // Subfolder.
this.contents = this.moduleContents; this.contents = folderContents;
} else { } else {
this.contents = this.folderHelper.formatContents(this.moduleContents); this.contents = this.folderHelper.formatContents(folderContents);
} }
} }
@ -101,12 +100,13 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected fetchContent(refresh?: boolean): Promise<any> { protected fetchContent(refresh?: boolean): Promise<any> {
let promise; let promise,
folderContents = this.module.contents;
if (this.canGetFolder) { if (this.canGetFolder) {
promise = this.folderProvider.getFolder(this.courseId, this.module.id).then((folder) => { promise = this.folderProvider.getFolder(this.courseId, this.module.id).then((folder) => {
return this.courseProvider.loadModuleContents(this.module, this.courseId).then(() => { return this.courseProvider.loadModuleContents(this.module, this.courseId).then(() => {
this.moduleContents = this.module.contents; folderContents = this.module.contents;
return folder; return folder;
}); });
@ -118,14 +118,14 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo
folder.contents = this.module.contents; folder.contents = this.module.contents;
} }
this.module = folder; this.module = folder;
this.moduleContents = folder.contents; folderContents = folder.contents;
return folder; return folder;
}); });
} }
return promise.then((folder) => { return promise.then((folder) => {
this.showModuleData(folder); this.showModuleData(folder, folderContents);
}).finally(() => { }).finally(() => {
this.fillContextMenu(refresh); this.fillContextMenu(refresh);
}); });