Merge pull request #3767 from dpalou/MOBILE-4401
MOBILE-4401 wiki: Fix selected subwiki when wiki is emptymain
commit
b366ee32f7
|
@ -343,42 +343,19 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
* @param subwiki Subwiki.
|
* @param subwiki Subwiki.
|
||||||
*/
|
*/
|
||||||
protected async fetchSubwikiPages(subwiki: AddonModWikiSubwiki): Promise<void> {
|
protected async fetchSubwikiPages(subwiki: AddonModWikiSubwiki): Promise<void> {
|
||||||
const subwikiPages = await AddonModWiki.getSubwikiPages(subwiki.wikiid, {
|
const subwikiPages = subwiki.id <= 0 ?
|
||||||
groupId: subwiki.groupid,
|
[] :
|
||||||
userId: subwiki.userid,
|
await AddonModWiki.getSubwikiPages(subwiki.wikiid, {
|
||||||
cmId: this.module.id,
|
groupId: subwiki.groupid,
|
||||||
});
|
userId: subwiki.userid,
|
||||||
|
cmId: this.module.id,
|
||||||
|
});
|
||||||
|
|
||||||
if (!this.currentPage) {
|
this.setCurrentPage(subwikiPages);
|
||||||
if (!this.pageTitle) {
|
|
||||||
// No page specified, search first page.
|
|
||||||
const firstPage = subwikiPages.find((page) => page.firstpage );
|
|
||||||
if (firstPage) {
|
|
||||||
this.currentPage = firstPage.id;
|
|
||||||
this.pageTitle = firstPage.title;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Got the page title but not its ID. Search the page.
|
|
||||||
const page = subwikiPages.find((page) => page.title === this.pageTitle );
|
|
||||||
if (page) {
|
|
||||||
this.currentPage = page.id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now get the offline pages.
|
// Now get the offline pages.
|
||||||
const dbPages = await AddonModWikiOffline.getSubwikiNewPages(subwiki.id, subwiki.wikiid, subwiki.userid, subwiki.groupid);
|
const dbPages = await AddonModWikiOffline.getSubwikiNewPages(subwiki.id, subwiki.wikiid, subwiki.userid, subwiki.groupid);
|
||||||
|
|
||||||
// If no page specified, search page title in the offline pages.
|
|
||||||
if (!this.currentPage) {
|
|
||||||
const searchTitle = this.pageTitle ? this.pageTitle : this.wiki?.firstpagetitle ?? '';
|
|
||||||
const pageExists = dbPages.some((page) => page.title == searchTitle);
|
|
||||||
|
|
||||||
if (pageExists) {
|
|
||||||
this.pageTitle = searchTitle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.subwikiPages = AddonModWiki.sortPagesByTitle(
|
this.subwikiPages = AddonModWiki.sortPagesByTitle(
|
||||||
(<(AddonModWikiSubwikiPage | AddonModWikiPageDBRecord)[]> subwikiPages).concat(dbPages),
|
(<(AddonModWikiSubwikiPage | AddonModWikiPageDBRecord)[]> subwikiPages).concat(dbPages),
|
||||||
);
|
);
|
||||||
|
@ -389,6 +366,32 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set current page if needed.
|
||||||
|
*
|
||||||
|
* @param subwikiPages List of subwiki pages.
|
||||||
|
*/
|
||||||
|
setCurrentPage(subwikiPages: AddonModWikiSubwikiPage[]): void {
|
||||||
|
if (this.currentPage) {
|
||||||
|
return; // Already set, nothing to do.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.pageTitle) {
|
||||||
|
// Got the page title but not its ID. Search the page.
|
||||||
|
const page = subwikiPages.find((page) => page.title === this.pageTitle);
|
||||||
|
if (page) {
|
||||||
|
this.currentPage = page.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No page specified, search first page.
|
||||||
|
const firstPage = subwikiPages.find((page) => page.firstpage);
|
||||||
|
this.currentPage = firstPage?.id;
|
||||||
|
this.pageTitle = firstPage?.title ?? this.wiki?.firstpagetitle;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the subwikis.
|
* Get the subwikis.
|
||||||
*
|
*
|
||||||
|
@ -710,7 +713,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
* @returns Whether there is any subwiki selected.
|
* @returns Whether there is any subwiki selected.
|
||||||
*/
|
*/
|
||||||
protected isAnySubwikiSelected(): boolean {
|
protected isAnySubwikiSelected(): boolean {
|
||||||
return this.subwikiData.subwikiSelected > 0 || this.subwikiData.userSelected > 0 || this.subwikiData.groupSelected > 0;
|
return this.subwikiData.subwikiSelected !== 0 || this.subwikiData.userSelected > 0 || this.subwikiData.groupSelected > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -752,7 +755,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
* @param groupId Group ID of the subwiki to select.
|
* @param groupId Group ID of the subwiki to select.
|
||||||
*/
|
*/
|
||||||
protected setSelectedWiki(subwikiId: number | undefined, userId: number | undefined, groupId: number | undefined): void {
|
protected setSelectedWiki(subwikiId: number | undefined, userId: number | undefined, groupId: number | undefined): void {
|
||||||
this.subwikiData.subwikiSelected = AddonModWikiOffline.convertToPositiveNumber(subwikiId);
|
this.subwikiData.subwikiSelected = subwikiId ?? 0;
|
||||||
this.subwikiData.userSelected = AddonModWikiOffline.convertToPositiveNumber(userId);
|
this.subwikiData.userSelected = AddonModWikiOffline.convertToPositiveNumber(userId);
|
||||||
this.subwikiData.groupSelected = AddonModWikiOffline.convertToPositiveNumber(groupId);
|
this.subwikiData.groupSelected = AddonModWikiOffline.convertToPositiveNumber(groupId);
|
||||||
}
|
}
|
||||||
|
@ -800,7 +803,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
}
|
}
|
||||||
|
|
||||||
const sameSubwiki = this.currentSubwiki &&
|
const sameSubwiki = this.currentSubwiki &&
|
||||||
((this.currentSubwiki.id && this.currentSubwiki.id === editedPageData.subwikiId) ||
|
((this.currentSubwiki.id > 0 && this.currentSubwiki.id === editedPageData.subwikiId) ||
|
||||||
(this.currentSubwiki.userid === editedPageData.userId && this.currentSubwiki.groupid === editedPageData.groupId));
|
(this.currentSubwiki.userid === editedPageData.userId && this.currentSubwiki.groupid === editedPageData.groupId));
|
||||||
|
|
||||||
if (sameSubwiki && editedPageData.pageTitle === this.pageTitle) {
|
if (sameSubwiki && editedPageData.pageTitle === this.pageTitle) {
|
||||||
|
@ -1024,7 +1027,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
candidateSubwikiId = subwiki.id;
|
candidateSubwikiId = subwiki.id;
|
||||||
}
|
}
|
||||||
} else if (subwiki.groupid > 0) {
|
} else if (subwiki.groupid > 0) {
|
||||||
// Check if it's a current user' group.
|
// Check if it's a current user's group.
|
||||||
if (showMyGroupsLabel) {
|
if (showMyGroupsLabel) {
|
||||||
candidateSubwikiId = subwiki.id;
|
candidateSubwikiId = subwiki.id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,6 @@ Feature: Test basic usage of one course in app
|
||||||
|
|
||||||
When I press the back button in the app
|
When I press the back button in the app
|
||||||
And I press "Test wiki name" in the app
|
And I press "Test wiki name" in the app
|
||||||
And I press "OK" in the app
|
|
||||||
Then the header should be "Test wiki name" in the app
|
Then the header should be "Test wiki name" in the app
|
||||||
|
|
||||||
When I press the back button in the app
|
When I press the back button in the app
|
||||||
|
@ -199,7 +198,6 @@ Feature: Test basic usage of one course in app
|
||||||
|
|
||||||
When I press the back button in the app
|
When I press the back button in the app
|
||||||
And I press "Test wiki name" in the app
|
And I press "Test wiki name" in the app
|
||||||
And I press "OK" in the app
|
|
||||||
Then the header should be "Test wiki name" in the app
|
Then the header should be "Test wiki name" in the app
|
||||||
|
|
||||||
When I press the back button in the app
|
When I press the back button in the app
|
||||||
|
|
Loading…
Reference in New Issue