MOBILE-3134 folder: Fix componentId and description in folder

main
Dani Palou 2020-04-09 10:29:00 +02:00
parent 8c38f3a216
commit 254107075b
4 changed files with 32 additions and 26 deletions

View File

@ -4,7 +4,7 @@
<core-context-menu-item *ngIf="externalUrl" [priority]="900" [content]="'core.openinbrowser' | translate" [href]="externalUrl" [iconAction]="'open'"></core-context-menu-item>
<core-context-menu-item *ngIf="description" [priority]="800" [content]="'core.moduleintro' | translate" (action)="expandDescription()" [iconAction]="'arrow-forward'"></core-context-menu-item>
<core-context-menu-item *ngIf="blog" [priority]="750" content="{{'addon.blog.blog' | translate}}" [iconAction]="'fa-newspaper-o'" (action)="gotoBlog($event)"></core-context-menu-item>
<core-context-menu-item *ngIf="!path" [priority]="700" [content]="'core.refresh' | translate" (action)="doRefresh(null, $event)" [iconAction]="refreshIcon" [closeOnClick]="false"></core-context-menu-item>
<core-context-menu-item *ngIf="!subfolder" [priority]="700" [content]="'core.refresh' | translate" (action)="doRefresh(null, $event)" [iconAction]="refreshIcon" [closeOnClick]="false"></core-context-menu-item>
<core-context-menu-item *ngIf="prefetchStatusIcon" [priority]="600" [content]="prefetchText" (action)="prefetch($event)" [iconAction]="prefetchStatusIcon" [closeOnClick]="false"></core-context-menu-item>
<core-context-menu-item *ngIf="size" [priority]="500" [content]="'core.removefiles' | translate:{$a: size}" [iconDescription]="'cube'" (action)="removeFiles()" [iconAction]="'trash'"></core-context-menu-item>
</core-context-menu>
@ -17,11 +17,11 @@
<ion-list *ngIf="contents && contents.length > 0">
<ng-container *ngFor="let file of contents">
<a *ngIf="file.type === 'folder'" ion-item class="item-media" navPush="AddonModFolderIndexPage" [navParams]="{path: file.filepath, courseId: courseId, module: file}">
<a *ngIf="file.type === 'folder'" ion-item class="item-media" navPush="AddonModFolderIndexPage" [navParams]="{subfolder: file, courseId: courseId, module: module, folderInstance: folderInstance}">
<ion-icon name="folder" item-start></ion-icon>
<h2>{{file.name}}</h2>
</a>
<core-file *ngIf="file.type !== 'folder'" [file]="file" [component]="component" [componentId]="file.contextid"></core-file>
<core-file *ngIf="file.type !== 'folder'" [file]="file" [component]="component" [componentId]="componentId"></core-file>
</ng-container>
</ion-list>

View File

@ -29,7 +29,8 @@ import { AddonModFolderHelperProvider } from '../../providers/helper';
templateUrl: 'addon-mod-folder-index.html',
})
export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceComponent {
@Input() path: string; // For subfolders. Use the path instead of a boolean so Angular detects them as different states.
@Input() folderInstance?: any; // The mod_folder instance.
@Input() subfolder?: any; // Subfolder to show.
component = AddonModFolderProvider.COMPONENT;
canGetFolder: boolean;
@ -48,9 +49,9 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo
this.canGetFolder = this.folderProvider.isGetFolderWSAvailable();
if (this.path) {
if (this.subfolder) {
// Subfolder. Use module param.
this.showModuleData(this.module, this.module.contents);
this.showModuleData(this.subfolder.contents);
this.loaded = true;
this.refreshIcon = 'refresh';
} else {
@ -77,15 +78,14 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo
}
/**
* Convenience function to set scope data using module.
* @param module Module to show.
* Convenience function to set data to display.
*
* @param folderContents Contents to show.
*/
protected showModuleData(module: any, folderContents: any): void {
this.description = module.intro || module.description;
protected showModuleData(folderContents: any): void {
this.description = this.folderInstance ? this.folderInstance.intro : this.module.description;
this.dataRetrieved.emit(module);
if (this.path) {
if (this.subfolder) {
// Subfolder.
this.contents = folderContents;
} else {
@ -107,25 +107,29 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo
promise = this.folderProvider.getFolder(this.courseId, this.module.id).then((folder) => {
return this.courseProvider.loadModuleContents(this.module, this.courseId, undefined, false, refresh).then(() => {
folderContents = this.module.contents;
this.folderInstance = folder;
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()) {
promise = this.courseProvider.getModule(this.module.id, this.courseId).then((module) => {
if (!module.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;
module.contents = this.module.contents;
}
this.module = folder;
folderContents = folder.contents;
this.module = module;
folderContents = module.contents;
return folder;
return module;
});
}
return promise.then((folder) => {
this.showModuleData(folder, folderContents);
return promise.then(() => {
this.dataRetrieved.emit(this.folderInstance || this.module);
this.showModuleData(folderContents);
}).finally(() => {
this.fillContextMenu(refresh);
});

View File

@ -8,9 +8,9 @@
</ion-navbar>
</ion-header>
<ion-content>
<ion-refresher [enabled]="!path && folderComponent.loaded" (ionRefresh)="folderComponent.doRefresh($event)">
<ion-refresher [enabled]="!subfolder && folderComponent.loaded" (ionRefresh)="folderComponent.doRefresh($event)">
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher>
<addon-mod-folder-index [module]="module" [courseId]="courseId" [path]="path" (dataRetrieved)="updateData($event)"></addon-mod-folder-index>
<addon-mod-folder-index [module]="module" [courseId]="courseId" [folderInstance]="folderInstance" [subfolder]="subfolder" (dataRetrieved)="updateData($event)"></addon-mod-folder-index>
</ion-content>

View File

@ -30,13 +30,15 @@ export class AddonModFolderIndexPage {
title: string;
module: any;
courseId: number;
path: string;
folderInstance: any;
subfolder: any;
constructor(navParams: NavParams) {
this.module = navParams.get('module') || {};
this.courseId = navParams.get('courseId');
this.path = navParams.get('path');
this.title = this.module.name;
this.folderInstance = navParams.get('folderInstance');
this.subfolder = navParams.get('subfolder');
this.title = this.subfolder ? this.subfolder.name : this.module.name;
}
/**