From 33b3d7db7835cbe5f3cec4ede4a0c1053526a01f Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 5 Aug 2022 15:30:01 +0200 Subject: [PATCH 1/2] MOBILE-4035 groups: Create group selector component --- .../index/addon-mod-assign-index.html | 14 +----- .../submission-list/submission-list.html | 15 ++----- .../components/index/index.html | 23 +--------- .../mod/chat/pages/sessions/sessions.html | 13 +----- .../index/addon-mod-data-index.html | 14 +----- src/addons/mod/data/pages/edit/edit.html | 14 +----- src/addons/mod/data/pages/entry/entry.html | 14 +----- .../index/addon-mod-feedback-index.html | 14 +----- .../mod/feedback/pages/attempts/attempts.html | 15 +------ .../pages/nonrespondents/nonrespondents.html | 15 +------ .../mod/forum/components/index/index.html | 15 +------ .../index/addon-mod-lesson-index.html | 16 +------ .../index/addon-mod-workshop-index.html | 15 +------ src/core/components/components.module.ts | 3 ++ .../group-selector/group-selector.html | 22 ++++++++++ .../group-selector/group-selector.ts | 43 +++++++++++++++++++ 16 files changed, 93 insertions(+), 172 deletions(-) create mode 100644 src/core/components/group-selector/group-selector.html create mode 100644 src/core/components/group-selector/group-selector.ts diff --git a/src/addons/mod/assign/components/index/addon-mod-assign-index.html b/src/addons/mod/assign/components/index/addon-mod-assign-index.html index 028cec0b9..fc5571d40 100644 --- a/src/addons/mod/assign/components/index/addon-mod-assign-index.html +++ b/src/addons/mod/assign/components/index/addon-mod-assign-index.html @@ -20,18 +20,8 @@ - - - {{'core.groupsseparate' | translate }} - {{'core.groupsvisible' | translate }} - - - - {{groupOpt.name}} - - - + + diff --git a/src/addons/mod/assign/pages/submission-list/submission-list.html b/src/addons/mod/assign/pages/submission-list/submission-list.html index a88073d1c..f169824fc 100644 --- a/src/addons/mod/assign/pages/submission-list/submission-list.html +++ b/src/addons/mod/assign/pages/submission-list/submission-list.html @@ -21,18 +21,9 @@ - - - {{'core.groupsseparate' | translate }} - {{'core.groupsvisible' | translate }} - - - - {{groupOpt.name}} - - - + + + - - - - - {{ 'addon.mod_bigbluebuttonbn.view_groups_selection_warning' | translate }} - - - - - - {{ 'core.groupsseparate' | translate }} - {{ 'core.groupsvisible' | translate }} - - - - {{groupOpt.name}} - - - - + diff --git a/src/addons/mod/chat/pages/sessions/sessions.html b/src/addons/mod/chat/pages/sessions/sessions.html index 9676d15bb..2bfe9775d 100644 --- a/src/addons/mod/chat/pages/sessions/sessions.html +++ b/src/addons/mod/chat/pages/sessions/sessions.html @@ -14,18 +14,7 @@ - - - {{'core.groupsseparate' | translate }} - {{'core.groupsvisible' | translate }} - - - - {{groupOpt.name}} - - - + {{ 'addon.mod_chat.showincompletesessions' | translate }} diff --git a/src/addons/mod/data/components/index/addon-mod-data-index.html b/src/addons/mod/data/components/index/addon-mod-data-index.html index 6a6b4724f..e18e931ad 100644 --- a/src/addons/mod/data/components/index/addon-mod-data-index.html +++ b/src/addons/mod/data/components/index/addon-mod-data-index.html @@ -25,18 +25,8 @@ [courseId]="courseId" [hasDataToSync]="hasOffline || hasOfflineRatings" (completionChanged)="onCompletionChange()"> - - - {{'core.groupsseparate' | translate }} - {{'core.groupsvisible' | translate }} - - - - {{groupOpt.name}} - - - + + diff --git a/src/addons/mod/data/pages/edit/edit.html b/src/addons/mod/data/pages/edit/edit.html index 875d160f0..6cc1d7be4 100644 --- a/src/addons/mod/data/pages/edit/edit.html +++ b/src/addons/mod/data/pages/edit/edit.html @@ -18,18 +18,8 @@ - - - {{ 'core.groupsseparate' | translate }} - {{ 'core.groupsvisible' | translate }} - - - - {{groupOpt.name}} - - - + +
diff --git a/src/addons/mod/data/pages/entry/entry.html b/src/addons/mod/data/pages/entry/entry.html index a7be272a4..de6da59a1 100644 --- a/src/addons/mod/data/pages/entry/entry.html +++ b/src/addons/mod/data/pages/entry/entry.html @@ -25,18 +25,8 @@ - - - {{ 'core.groupsvisible' | translate }} - {{ 'core.groupsseparate' | translate }} - - - - {{groupOpt.name}} - - - + +
diff --git a/src/addons/mod/feedback/components/index/addon-mod-feedback-index.html b/src/addons/mod/feedback/components/index/addon-mod-feedback-index.html index eb378ee03..ca10c22e4 100644 --- a/src/addons/mod/feedback/components/index/addon-mod-feedback-index.html +++ b/src/addons/mod/feedback/components/index/addon-mod-feedback-index.html @@ -59,18 +59,8 @@ - - - {{ 'core.groupsseparate' | translate }} - {{ 'core.groupsvisible' | translate }} - - - - {{groupOpt.name}} - - - + + diff --git a/src/addons/mod/feedback/pages/attempts/attempts.html b/src/addons/mod/feedback/pages/attempts/attempts.html index a435f5861..85b173371 100644 --- a/src/addons/mod/feedback/pages/attempts/attempts.html +++ b/src/addons/mod/feedback/pages/attempts/attempts.html @@ -15,19 +15,8 @@ - - - {{'core.groupsseparate' | translate }} - {{'core.groupsvisible' | translate }} - - - - {{groupOpt.name}} - - - + + diff --git a/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.html b/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.html index e5634aab3..57c33c2d9 100644 --- a/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.html +++ b/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.html @@ -14,19 +14,8 @@ - - - {{'core.groupsseparate' | translate }} - {{'core.groupsvisible' | translate }} - - - - {{groupOpt.name}} - - - + + diff --git a/src/addons/mod/forum/components/index/index.html b/src/addons/mod/forum/components/index/index.html index cf24dd7d5..4c6b1c123 100644 --- a/src/addons/mod/forum/components/index/index.html +++ b/src/addons/mod/forum/components/index/index.html @@ -23,19 +23,8 @@ - - - {{'core.groupsseparate' | translate }} - {{'core.groupsvisible' | translate }} - - - - {{groupOpt.name}} - - - + + diff --git a/src/addons/mod/lesson/components/index/addon-mod-lesson-index.html b/src/addons/mod/lesson/components/index/addon-mod-lesson-index.html index a02bbbc11..2ed4ab3a1 100644 --- a/src/addons/mod/lesson/components/index/addon-mod-lesson-index.html +++ b/src/addons/mod/lesson/components/index/addon-mod-lesson-index.html @@ -56,20 +56,8 @@ - - - - {{ 'core.groupsseparate' | translate }} - {{ 'core.groupsvisible' | translate }} - - - - {{groupOpt.name}} - - - + + {{ 'addon.mod_workshop.gradesreport' | translate }} - - - {{ 'core.groupsseparate' | translate }} - - - {{ 'core.groupsvisible' | translate }} - - - - {{groupOpt.name}} - - - + + + + + {{ multipleGroupsMessage }} + + + + + + {{'core.groupsseparate' | translate }} + {{'core.groupsvisible' | translate }} + + + + {{groupOpt.name}} + + + + diff --git a/src/core/components/group-selector/group-selector.ts b/src/core/components/group-selector/group-selector.ts new file mode 100644 index 000000000..b98b5ec5e --- /dev/null +++ b/src/core/components/group-selector/group-selector.ts @@ -0,0 +1,43 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Component, Input, Output, EventEmitter, OnInit, ChangeDetectionStrategy } from '@angular/core'; +import { CoreGroupInfo } from '@services/groups'; +import { CoreUtils } from '@services/utils/utils'; + +/** + * Component to display a group selector. + */ +@Component({ + selector: 'core-group-selector', + templateUrl: 'group-selector.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class CoreGroupSelectorComponent implements OnInit { + + @Input() groupInfo?: CoreGroupInfo; + @Input() multipleGroupsMessage?: string; + @Input() selected!: number; + @Output() selectedChange = new EventEmitter(); + + id!: number; + + /** + * @inheritdoc + */ + ngOnInit(): void { + this.id = CoreUtils.getUniqueId('CoreGroupSelectorComponent'); + } + +} From 6fd5843d929a1d77a1d3cb07ee742bb5a161f066 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 18 Aug 2022 12:09:07 +0200 Subject: [PATCH 2/2] MOBILE-4035 groups: Don't call WS that will fail if no group --- scripts/langindex.json | 1 + .../mod/bigbluebuttonbn/components/index/index.ts | 5 +++++ src/addons/mod/data/components/index/index.ts | 2 +- src/addons/mod/data/pages/edit/edit.ts | 2 +- src/addons/mod/data/pages/entry/entry.ts | 2 +- src/addons/mod/forum/services/handlers/prefetch.ts | 4 ++-- src/addons/mod/lesson/services/handlers/prefetch.ts | 2 +- src/addons/mod/wiki/components/index/index.ts | 8 ++++++-- src/addons/mod/wiki/lang.json | 3 ++- src/core/components/group-selector/group-selector.html | 2 +- src/core/services/groups.ts | 10 ++++------ 11 files changed, 25 insertions(+), 16 deletions(-) diff --git a/scripts/langindex.json b/scripts/langindex.json index ae08079ec..f4057dcb9 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -984,6 +984,7 @@ "addon.mod_url.modulenameplural": "url", "addon.mod_url.pointingtourl": "local_moodlemobileapp", "addon.mod_wiki.cannoteditpage": "wiki", + "addon.mod_wiki.cannotviewpage": "wiki", "addon.mod_wiki.createpage": "wiki", "addon.mod_wiki.editingpage": "wiki", "addon.mod_wiki.errorloadingpage": "local_moodlemobileapp", diff --git a/src/addons/mod/bigbluebuttonbn/components/index/index.ts b/src/addons/mod/bigbluebuttonbn/components/index/index.ts index 444de98c2..610226d45 100644 --- a/src/addons/mod/bigbluebuttonbn/components/index/index.ts +++ b/src/addons/mod/bigbluebuttonbn/components/index/index.ts @@ -13,6 +13,7 @@ // limitations under the License. import { Component, OnInit, Optional } from '@angular/core'; +import { CoreError } from '@classes/errors/error'; import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component'; import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; import { IonContent } from '@ionic/angular'; @@ -68,6 +69,10 @@ export class AddonModBBBIndexComponent extends CoreCourseModuleMainActivityCompo this.groupId = CoreGroups.validateGroupId(this.groupId, this.groupInfo); + if (this.groupInfo.separateGroups && !this.groupInfo.groups.length) { + throw new CoreError(Translate.instant('addon.mod_bigbluebuttonbn.view_nojoin')); + } + await this.fetchMeetingInfo(); } diff --git a/src/addons/mod/data/components/index/index.ts b/src/addons/mod/data/components/index/index.ts index bb4b1b8dc..07a9190d3 100644 --- a/src/addons/mod/data/components/index/index.ts +++ b/src/addons/mod/data/components/index/index.ts @@ -218,7 +218,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp } this.groupInfo = await CoreGroups.getActivityGroupInfo(this.database.coursemodule); - if (this.groupInfo.visibleGroups && this.groupInfo.groups?.length) { + if (this.groupInfo.visibleGroups && this.groupInfo.groups.length) { // There is a bug in Moodle with All participants and visible groups (MOBILE-3597). Remove it. this.groupInfo.groups = this.groupInfo.groups.filter(group => group.id !== 0); this.groupInfo.defaultGroupId = this.groupInfo.groups[0].id; diff --git a/src/addons/mod/data/pages/edit/edit.ts b/src/addons/mod/data/pages/edit/edit.ts index 17cfb151d..00278b312 100644 --- a/src/addons/mod/data/pages/edit/edit.ts +++ b/src/addons/mod/data/pages/edit/edit.ts @@ -179,7 +179,7 @@ export class AddonModDataEditPage implements OnInit { if (refresh) { groupInfo = await CoreGroups.getActivityGroupInfo(this.database.coursemodule); - if (groupInfo.visibleGroups && groupInfo.groups?.length) { + if (groupInfo.visibleGroups && groupInfo.groups.length) { // There is a bug in Moodle with All participants and visible groups (MOBILE-3597). Remove it. groupInfo.groups = groupInfo.groups.filter(group => group.id !== 0); groupInfo.defaultGroupId = groupInfo.groups[0].id; diff --git a/src/addons/mod/data/pages/entry/entry.ts b/src/addons/mod/data/pages/entry/entry.ts index 761962bb1..bf24b7ef3 100644 --- a/src/addons/mod/data/pages/entry/entry.ts +++ b/src/addons/mod/data/pages/entry/entry.ts @@ -174,7 +174,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { this.access = await AddonModData.getDatabaseAccessInformation(this.database.id, { cmId: this.moduleId }); this.groupInfo = await CoreGroups.getActivityGroupInfo(this.database.coursemodule); - if (this.groupInfo.visibleGroups && this.groupInfo.groups?.length) { + if (this.groupInfo.visibleGroups && this.groupInfo.groups.length) { // There is a bug in Moodle with All participants and visible groups (MOBILE-3597). Remove it. this.groupInfo.groups = this.groupInfo.groups.filter(group => group.id !== 0); this.groupInfo.defaultGroupId = this.groupInfo.groups[0].id; diff --git a/src/addons/mod/forum/services/handlers/prefetch.ts b/src/addons/mod/forum/services/handlers/prefetch.ts index ed48fb29b..6574fb239 100644 --- a/src/addons/mod/forum/services/handlers/prefetch.ts +++ b/src/addons/mod/forum/services/handlers/prefetch.ts @@ -158,7 +158,7 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe return [0]; } - const allPartsGroup = groupInfo.groups?.find(group => group.id === 0); + const allPartsGroup = groupInfo.groups.find(group => group.id === 0); if (allPartsGroup) { return [0]; // Prefetch all participants. } @@ -168,7 +168,7 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe return [groupInfo.defaultGroupId]; } - return groupInfo.groups?.map(group => group.id) ?? [0]; + return groupInfo.groups.map(group => group.id) ?? [0]; } /** diff --git a/src/addons/mod/lesson/services/handlers/prefetch.ts b/src/addons/mod/lesson/services/handlers/prefetch.ts index 011b47b40..a9455ee70 100644 --- a/src/addons/mod/lesson/services/handlers/prefetch.ts +++ b/src/addons/mod/lesson/services/handlers/prefetch.ts @@ -431,7 +431,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref ): Promise { const groupInfo = await CoreGroups.getActivityGroupInfo(moduleId, false, undefined, modOptions.siteId, true); - await Promise.all(groupInfo.groups?.map(async (group) => { + await Promise.all(groupInfo.groups.map(async (group) => { await AddonModLesson.getRetakesOverview(lessonId, { groupId: group.id, ...modOptions, // Include all options. diff --git a/src/addons/mod/wiki/components/index/index.ts b/src/addons/mod/wiki/components/index/index.ts index 73444595e..830572a90 100644 --- a/src/addons/mod/wiki/components/index/index.ts +++ b/src/addons/mod/wiki/components/index/index.ts @@ -249,6 +249,10 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp // Get real groupmode, in case it's forced by the course. const groupInfo = await CoreGroups.getActivityGroupInfo(this.wiki.coursemodule); + if (groupInfo.separateGroups && !groupInfo.groups.length) { + throw new CoreError(Translate.instant('addon.mod_wiki.cannotviewpage')); + } + await this.createSubwikiList(groupInfo.groups); } else { this.subwikiData.count = subwikiList.count; @@ -867,7 +871,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp * @param userGroups Groups. * @return Promise resolved when done. */ - protected async createSubwikiList(userGroups?: CoreGroup[]): Promise { + protected async createSubwikiList(userGroups: CoreGroup[]): Promise { const subwikiList: AddonModWikiSubwikiListSubwiki[] = []; let allParticipants = false; let showMyGroupsLabel = false; @@ -895,7 +899,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp allParticipants = true; } } else { - if (subwiki.groupid != 0 && userGroups && userGroups.length > 0) { + if (subwiki.groupid != 0 && userGroups.length > 0) { // Get groupLabel if it has groupId. const group = userGroups.find(group => group.id == subwiki.groupid); groupLabel = group?.name || ''; diff --git a/src/addons/mod/wiki/lang.json b/src/addons/mod/wiki/lang.json index 246965b9c..debf37ee7 100644 --- a/src/addons/mod/wiki/lang.json +++ b/src/addons/mod/wiki/lang.json @@ -1,5 +1,6 @@ { "cannoteditpage": "You can not edit this page.", + "cannotviewpage": "You can not view this page.", "createpage": "Create page", "editingpage": "Editing this page '{{$a}}'", "errorloadingpage": "An error occurred while loading the page.", @@ -19,4 +20,4 @@ "viewpage": "View page", "wikipage": "Wiki page", "wrongversionlock": "Another user has edited this page while you were editing and your content is obsolete." -} \ No newline at end of file +} diff --git a/src/core/components/group-selector/group-selector.html b/src/core/components/group-selector/group-selector.html index 2b339bc3d..3c667d8ea 100644 --- a/src/core/components/group-selector/group-selector.html +++ b/src/core/components/group-selector/group-selector.html @@ -1,4 +1,4 @@ - + diff --git a/src/core/services/groups.ts b/src/core/services/groups.ts index 39320f09a..bdf537564 100644 --- a/src/core/services/groups.ts +++ b/src/core/services/groups.ts @@ -170,19 +170,17 @@ export class CoreGroupsProvider { }; } - if (result.groups.length <= 0) { - groupInfo.separateGroups = false; - groupInfo.visibleGroups = false; + if (!result.groups.length) { groupInfo.defaultGroupId = 0; } else { if (result.canaccessallgroups || groupInfo.visibleGroups) { - groupInfo.groups!.push({ id: 0, name: Translate.instant('core.allparticipants') }); + groupInfo.groups.push({ id: 0, name: Translate.instant('core.allparticipants') }); groupInfo.defaultGroupId = 0; } else { groupInfo.defaultGroupId = result.groups[0].id; } - groupInfo.groups = groupInfo.groups!.concat(result.groups); + groupInfo.groups = groupInfo.groups.concat(result.groups); } return groupInfo; @@ -458,7 +456,7 @@ export type CoreGroupInfo = { /** * List of groups. */ - groups?: CoreGroup[]; + groups: CoreGroup[]; /** * Whether it's separate groups.