diff --git a/src/assets/storybook/sites/companylisa.ts b/src/assets/storybook/sites/companylisa.ts new file mode 100644 index 00000000000..3689523d7d7 --- /dev/null +++ b/src/assets/storybook/sites/companylisa.ts @@ -0,0 +1,32 @@ +// (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 { CoreSiteFixture } from '@/storybook/stubs/classes/site'; + +export const companyLisaSite: CoreSiteFixture = { + id: 'companylisasite', + info: { + version: '2022041900', + sitename: 'Company', + username: 'lisa', + firstname: 'Lisa', + lastname: 'Díaz', + fullname: 'Lisa Díaz', + lang: 'en', + userid: 1, + siteurl: 'https://company.example.edu', + userpictureurl: 'https://i.pravatar.cc/300?user=companylisa', + functions: [], + }, +}; diff --git a/src/assets/storybook/sites/school.json b/src/assets/storybook/sites/school.json deleted file mode 100644 index 1260527ba16..00000000000 --- a/src/assets/storybook/sites/school.json +++ /dev/null @@ -1 +0,0 @@ -{"id":"123456","info":{"version":"2022041900","sitename":"School","username":"barbara","firstname":"Barbara","lastname":"Gardner","fullname":"Barbara Gardner","lang":"en","userid":1,"siteurl":"https://campus.example.edu","userpictureurl":"","functions":[]}} diff --git a/src/assets/storybook/sites/schoolbarbara.ts b/src/assets/storybook/sites/schoolbarbara.ts new file mode 100644 index 00000000000..c4fa3eda3a7 --- /dev/null +++ b/src/assets/storybook/sites/schoolbarbara.ts @@ -0,0 +1,32 @@ +// (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 { CoreSiteFixture } from '@/storybook/stubs/classes/site'; + +export const schoolBarbaraSite: CoreSiteFixture = { + id: 'schoolbarbarasite', + info: { + version: '2022041900', + sitename: 'School', + username: 'barbara', + firstname: 'Barbara', + lastname: 'Gardner', + fullname: 'Barbara Gardner', + lang: 'en', + userid: 1, + siteurl: 'https://campus.example.edu', + userpictureurl: 'https://i.pravatar.cc/300?user=schoolbarbara', + functions: [], + }, +}; diff --git a/src/assets/storybook/sites/schooljeffery.ts b/src/assets/storybook/sites/schooljeffery.ts new file mode 100644 index 00000000000..c7823f2b069 --- /dev/null +++ b/src/assets/storybook/sites/schooljeffery.ts @@ -0,0 +1,32 @@ +// (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 { CoreSiteFixture } from '@/storybook/stubs/classes/site'; + +export const schoolJefferySite: CoreSiteFixture = { + id: 'schooljefferysite', + info: { + version: '2022041900', + sitename: 'School', + username: 'jeffery', + firstname: 'Jeffery', + lastname: 'Sanders', + fullname: 'Jeffery Sanders', + lang: 'en', + userid: 2, + siteurl: 'https://campus.example.edu', + userpictureurl: 'https://i.pravatar.cc/300?user=schooljeffery', + functions: [], + }, +}; diff --git a/src/core/classes/site.ts b/src/core/classes/site.ts index 6c1a98b9528..0c5a101bc56 100644 --- a/src/core/classes/site.ts +++ b/src/core/classes/site.ts @@ -296,14 +296,18 @@ export class CoreSite { * @returns Site name. */ async getSiteName(): Promise { + if (this.isDemoModeSite()) { + return CoreConstants.CONFIG.appname; + } + if (this.infos?.sitename) { return this.infos?.sitename; } // Fallback. - const isSigleFixedSite = await CoreLoginHelper.isSingleFixedSite(); + const isSingleFixedSite = await CoreLoginHelper.isSingleFixedSite(); - if (isSigleFixedSite) { + if (isSingleFixedSite) { const sites = await CoreLoginHelper.getAvailableSites(); return sites[0].name; @@ -2459,6 +2463,17 @@ export class CoreSite { }); } + /** + * Check if the site is a demo mode site. + * + * @returns Whether the site is a demo mode site. + */ + isDemoModeSite(): boolean { + const demoSiteData = CoreLoginHelper.getDemoModeSiteInfo(); + + return this.containsUrl(demoSiteData?.url); + } + } /** diff --git a/src/core/components/components.module.ts b/src/core/components/components.module.ts index fc64175b110..fd78701a693 100644 --- a/src/core/components/components.module.ts +++ b/src/core/components/components.module.ts @@ -65,6 +65,7 @@ import { CoreGroupSelectorComponent } from './group-selector/group-selector'; import { CoreRefreshButtonModalComponent } from './refresh-button-modal/refresh-button-modal'; import { CoreSheetModalComponent } from '@components/sheet-modal/sheet-modal'; import { CoreCourseImageComponent } from '@components/course-image/course-image'; +import { CoreSitesListComponent } from './sites-list/sites-list'; @NgModule({ declarations: [ @@ -112,6 +113,7 @@ import { CoreCourseImageComponent } from '@components/course-image/course-image' CoreSwipeNavigationTourComponent, CoreRefreshButtonModalComponent, CoreSheetModalComponent, + CoreSitesListComponent, ], imports: [ CommonModule, @@ -166,6 +168,7 @@ import { CoreCourseImageComponent } from '@components/course-image/course-image' CoreSwipeNavigationTourComponent, CoreRefreshButtonModalComponent, CoreSheetModalComponent, + CoreSitesListComponent, ], }) export class CoreComponentsModule {} diff --git a/src/core/components/sites-list/sites-list.html b/src/core/components/sites-list/sites-list.html new file mode 100644 index 00000000000..99cc0bc5314 --- /dev/null +++ b/src/core/components/sites-list/sites-list.html @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +

+ +

+

+ + {{ site.siteUrlWithoutProtocol }} + +

+
+
+
+ + + + + + + + +

{{site.fullname}}

+ + +
+ + + +
+
diff --git a/src/core/features/login/sitelist.scss b/src/core/components/sites-list/sites-list.scss similarity index 71% rename from src/core/features/login/sitelist.scss rename to src/core/components/sites-list/sites-list.scss index 22a83f842f0..57b45009f93 100644 --- a/src/core/features/login/sitelist.scss +++ b/src/core/components/sites-list/sites-list.scss @@ -1,5 +1,5 @@ -ion-list.core-sitelist { - .core-sitelist-sitename { +ion-list.core-sites-list { + .core-sites-list-sitename { ion-label { margin-top: 8px; margin-bottom: 8px; diff --git a/src/core/components/sites-list/sites-list.ts b/src/core/components/sites-list/sites-list.ts new file mode 100644 index 00000000000..57477b12516 --- /dev/null +++ b/src/core/components/sites-list/sites-list.ts @@ -0,0 +1,80 @@ +// (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, ContentChild, Input, Output, TemplateRef, EventEmitter } from '@angular/core'; + +import { CoreSiteBasicInfo } from '@services/sites'; +import { CoreAccountsList } from '@features/login/services/login-helper'; + +/** + * Component to display a list of sites (accounts). + * + * By default this component will display the avatar and user fullname for each site, but it allows adding more information + * in the item and in the label for each site, using #siteItem and #siteLabel ng-templates. These templates will receive the + * site being rendered and whether it's the current site or not. Example: + * + * + * + * - - - - - -

{{site.fullname}}

-
- - - {{ 'core.login.sitebadgedescription' | translate:{ count: site.badge } - }} - - - - -
-
diff --git a/src/core/features/login/pages/credentials/credentials.html b/src/core/features/login/pages/credentials/credentials.html index be6df430171..3c76002c638 100644 --- a/src/core/features/login/pages/credentials/credentials.html +++ b/src/core/features/login/pages/credentials/credentials.html @@ -32,7 +32,7 @@

{{ 'core.login.login' | translate }}

-

{{siteUrl}}

+

{{siteUrl}}

{{ 'core.agelocationverification' | translate }} -

{{siteUrl}}

+

{{siteUrl}}

diff --git a/src/core/features/login/pages/email-signup/email-signup.ts b/src/core/features/login/pages/email-signup/email-signup.ts index f0d0f3f3ff6..c3f2da50f70 100644 --- a/src/core/features/login/pages/email-signup/email-signup.ts +++ b/src/core/features/login/pages/email-signup/email-signup.ts @@ -34,6 +34,7 @@ import { CoreForms } from '@singletons/form'; import { CoreRecaptchaComponent } from '@components/recaptcha/recaptcha'; import { CorePath } from '@singletons/path'; import { CoreDom } from '@singletons/dom'; +import { CoreConstants } from '@/core/constants'; /** * Page to signup using email. @@ -51,6 +52,7 @@ export class CoreLoginEmailSignupPage implements OnInit { signupForm: FormGroup; siteUrl!: string; + isDemoModeSite = false; siteConfig?: CoreSitePublicConfigResponse; siteName?: string; authInstructions = ''; @@ -127,6 +129,7 @@ export class CoreLoginEmailSignupPage implements OnInit { } this.siteUrl = siteUrl; + this.isDemoModeSite = CoreLoginHelper.isDemoModeSite(this.siteUrl); // Fetch the data. this.fetchData().finally(() => { @@ -235,7 +238,7 @@ export class CoreLoginEmailSignupPage implements OnInit { */ protected treatSiteConfig(): boolean { if (this.siteConfig?.registerauth == 'email' && !CoreLoginHelper.isEmailSignupDisabled(this.siteConfig)) { - this.siteName = this.siteConfig.sitename; + this.siteName = this.isDemoModeSite ? CoreConstants.CONFIG.appname : this.siteConfig.sitename; this.authInstructions = this.siteConfig.authinstructions; this.ageDigitalConsentVerification = this.siteConfig.agedigitalconsentverification; this.supportName = this.siteConfig.supportname; diff --git a/src/core/features/login/pages/reconnect/reconnect.html b/src/core/features/login/pages/reconnect/reconnect.html index c5baa268646..bfc6ed6b1d8 100644 --- a/src/core/features/login/pages/reconnect/reconnect.html +++ b/src/core/features/login/pages/reconnect/reconnect.html @@ -40,7 +40,7 @@

{{ 'core.login.reconnect' | translate }}

-

{{siteUrl}}

+

{{siteUrl}}