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="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="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="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="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-item *ngIf="size" [priority]="500" [content]="'core.removefiles' | translate:{$a: size}" [iconDescription]="'cube'" (action)="removeFiles()" [iconAction]="'trash'"></core-context-menu-item>
</core-context-menu> </core-context-menu>
@ -17,11 +17,11 @@
<ion-list *ngIf="contents && contents.length > 0"> <ion-list *ngIf="contents && contents.length > 0">
<ng-container *ngFor="let file of contents"> <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> <ion-icon name="folder" item-start></ion-icon>
<h2>{{file.name}}</h2> <h2>{{file.name}}</h2>
</a> </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> </ng-container>
</ion-list> </ion-list>

View File

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

View File

@ -8,9 +8,9 @@
</ion-navbar> </ion-navbar>
</ion-header> </ion-header>
<ion-content> <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-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher> </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> </ion-content>

View File

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