Merge pull request #3472 from dpalou/MOBILE-4081

Mobile 4081
main
Pau Ferrer Ocaña 2022-11-24 14:10:48 +01:00 committed by GitHub
commit b1bd54067c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 51 deletions

View File

@ -327,8 +327,8 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
await this.showLoadingAndFetch(true, false);
if (this.currentPage) {
CoreUtils.ignoreErrors(AddonModWiki.logPageView(this.currentPage, this.wiki!.id, this.wiki!.name));
if (this.currentPage && this.wiki) {
CoreUtils.ignoreErrors(AddonModWiki.logPageView(this.currentPage, this.wiki.id, this.wiki.name));
}
}, CoreSites.getCurrentSiteId());
}
@ -373,7 +373,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
// If no page specified, search page title in the offline pages.
if (!this.currentPage) {
const searchTitle = this.pageTitle ? this.pageTitle : this.wiki!.firstpagetitle;
const searchTitle = this.pageTitle ? this.pageTitle : this.wiki?.firstpagetitle ?? '';
const pageExists = dbPages.some((page) => page.title == searchTitle);
if (pageExists) {
@ -482,7 +482,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
`${AddonModWikiModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/edit`,
{
params: {
pageTitle: this.wiki!.firstpagetitle,
pageTitle: this.wiki?.firstpagetitle ?? '',
wikiId: this.currentSubwiki?.wikiid,
userId: this.currentSubwiki?.userid,
groupId: this.currentSubwiki?.groupid,
@ -638,17 +638,13 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
* @param subwikiId Subwiki ID.
* @param userId User ID of the subwiki.
* @param groupId Group ID of the subwiki.
* @param canEdit Whether the subwiki can be edited.
*/
goToSubwiki(subwikiId: number, userId: number, groupId: number, canEdit: boolean): void {
// Check if the subwiki is disabled.
if (subwikiId <= 0 && !canEdit) {
return;
}
if (subwikiId != this.currentSubwiki!.id || userId != this.currentSubwiki!.userid ||
groupId != this.currentSubwiki!.groupid) {
goToSubwiki(subwikiId: number, userId: number, groupId: number): void {
if (
subwikiId !== this.currentSubwiki?.id ||
userId !== this.currentSubwiki?.userid ||
groupId !== this.currentSubwiki?.groupid
) {
this.openPageOrSubwiki({
subwikiId: subwikiId,
userId: userId,
@ -716,13 +712,17 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
* @param result Data returned on the sync function.
* @return If suceed or not.
*/
protected hasSyncSucceed(result: AddonModWikiSyncWikiResult): boolean {
if (result.updated) {
protected hasSyncSucceed(result: AddonModWikiSyncWikiResult | undefined): boolean {
if (!result) {
return false;
}
if (result.updated && this.wiki) {
// Trigger event.
this.ignoreManualSyncEvent = true;
CoreEvents.trigger(AddonModWikiSyncProvider.MANUAL_SYNCED, {
...result,
wikiId: this.wiki!.id,
wikiId: this.wiki.id,
});
}
@ -828,7 +828,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
* @param event Event.
*/
async showSubwikiPicker(event: MouseEvent): Promise<void> {
const popoverData = await CoreDomUtils.openPopover<AddonModWikiSubwiki>({
const subwiki = await CoreDomUtils.openPopover<AddonModWikiSubwiki>({
component: AddonModWikiSubwikiPickerComponent,
componentProps: {
subwikis: this.subwikiData.subwikis,
@ -837,8 +837,8 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
event,
});
if (popoverData) {
this.goToSubwiki(popoverData.id, popoverData.userid, popoverData.groupid, popoverData.canedit);
if (subwiki) {
this.goToSubwiki(subwiki.id, subwiki.userid, subwiki.groupid);
}
}
@ -847,8 +847,12 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
*
* @return Promise resolved when done.
*/
protected sync(): Promise<AddonModWikiSyncWikiResult> {
return AddonModWikiSync.syncWiki(this.wiki!.id, this.courseId, this.wiki!.coursemodule);
protected async sync(): Promise<AddonModWikiSyncWikiResult | undefined> {
if (!this.wiki) {
return;
}
return AddonModWikiSync.syncWiki(this.wiki.id, this.courseId, this.wiki.coursemodule);
}
/**
@ -1069,8 +1073,9 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
this.subwikiData.subwikis.push({ label: '', subwikis: subwikiList });
}
if (this.wiki) {
AddonModWiki.setSubwikiList(
this.wiki!.id,
this.wiki.id,
this.subwikiData.subwikis,
this.subwikiData.count,
this.subwikiData.subwikiSelected,
@ -1078,6 +1083,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
this.subwikiData.groupSelected,
);
}
}
}

View File

@ -5,8 +5,7 @@
<h2>{{ group.label }}</h2>
</ion-label>
</ion-item-divider>
<ion-item class="ion-text-wrap" *ngFor="let subwiki of group.subwikis" (click)="openSubwiki(subwiki)"
[attr.disabled]="!subwiki.canedit && subwiki.id <= 0" [button]="subwiki.canedit || subwiki.id > 0"
<ion-item class="ion-text-wrap" *ngFor="let subwiki of group.subwikis" (click)="openSubwiki(subwiki)" button
[attr.aria-current]="isSubwikiSelected(subwiki) ? 'page' : 'false'" detail="false">
<ion-label>{{ subwiki.name }}</ion-label>
<ion-icon *ngIf="isSubwikiSelected(subwiki)" name="fas-check" slot="end" aria-hidden="true"></ion-icon>

View File

@ -49,13 +49,10 @@ export class AddonModWikiSubwikiPickerComponent {
* @param subwiki The subwiki to open.
*/
openSubwiki(subwiki: AddonModWikiSubwiki): void {
// Check if the subwiki is disabled.
if (subwiki.id > 0 || subwiki.canedit) {
// Check if it isn't current subwiki.
if (subwiki != this.currentSubwiki) {
if (subwiki !== this.currentSubwiki) {
PopoverController.dismiss(subwiki);
}
}
}
}

View File

@ -87,7 +87,7 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave {
this.userId = CoreNavigator.getRouteNumberParam('userId');
let pageTitle = CoreNavigator.getRouteParam<string>('pageTitle');
pageTitle = pageTitle ? pageTitle.replace(/\+/g, ' ') : '';
pageTitle = pageTitle ? CoreTextUtils.cleanTags(pageTitle.replace(/\+/g, ' '), true) : '';
this.canEditTitle = !pageTitle;
this.title = pageTitle ?

View File

@ -958,18 +958,12 @@ export class CoreSite {
// Call the WS.
const initialToken = this.token ?? '';
// Call the WS.
if (method !== 'core_webservice_get_site_info') {
// Send the language to use. Do it after checking cache to prevent losing offline data when changing language.
// Don't send it to core_webservice_get_site_info, that WS is used to check if Moodle version is supported.
// Moodle uses underscore instead of dash.
data = {
...data,
moodlewssettinglang: preSets.lang ?? await CoreLang.getCurrentLanguage(),
moodlewssettinglang: (preSets.lang ?? await CoreLang.getCurrentLanguage()).replace('-', '_'),
};
// Moodle uses underscore instead of dash.
data.moodlewssettinglang = data.moodlewssettinglang.replace('-', '_');
}
try {
return await this.callOrEnqueueRequest<T>(method, data, preSets, wsPreSets);
@ -988,6 +982,14 @@ export class CoreSite {
}
}
if (error?.errorcode === 'invalidparameter' && method === 'core_webservice_get_site_info') {
// Retry without passing the lang, this parameter isn't supported in 3.4 or older sites
// and we need this WS call to be able to determine if the site is supported or not.
delete data.moodlewssettinglang;
return await this.callOrEnqueueRequest<T>(method, data, preSets, wsPreSets);
}
throw error;
}
}