Merge pull request #3460 from NoelDeMartin/MOBILE-4059

MOBILE-4059: Fix issues found during testing
main
Dani Palou 2022-11-23 07:57:28 +01:00 committed by GitHub
commit 9dfe87e2b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 119 additions and 31 deletions

View File

@ -2396,6 +2396,8 @@
"core.user.sendemail": "local_moodlemobileapp",
"core.user.student": "moodle/defaultcoursestudent",
"core.user.support": "local_moodlemobileapp",
"core.user.supportmessagesent": "user",
"core.user.supportsubject": "local_moodlemobileapp",
"core.user.teacher": "moodle/noneditingteacher",
"core.user.useraccount": "moodle",
"core.user.userwithid": "local_moodlemobileapp",

View File

@ -12,24 +12,22 @@
margin-bottom: 0;
}
.core-error-info--content {
.core-error-info--code {
padding: var(--spacing-2) var(--spacing-2) 0 var(--spacing-2);
font-size: var(--font-size-normal);
}
.core-error-info--code {
font-size: var(--font-size-normal);
}
.core-error-info--details {
color: var(--gray-500);
}
.core-error-info--details p {
padding: var(--spacing-2) var(--spacing-2) 0 var(--spacing-2);
color: var(--gray-500);
}
.core-error-info--checkbox {
display: none;
& + .core-error-info--content {
max-height: calc(var(--font-size-sm) + 2 * var(--spacing-2));
& + .core-error-info--details,
& + .core-error-info--code + .core-error-info--details {
max-height: 0;
overflow: hidden;
transition: max-height 600ms ease-in-out;
@ -58,8 +56,9 @@
}
&:checked + .core-error-info--content {
max-height: 150px;
&:checked + .core-error-info--details,
&:checked + .core-error-info--code + .core-error-info--details {
max-height: 110px;
& + .core-error-info--toggle .core-error-info--hide-content {
display: flex;
@ -73,16 +72,4 @@
}
&.has-error-code .core-error-info--checkbox {
& + .core-error-info--content {
max-height: calc(var(--font-size-normal) + 2 * var(--spacing-2));
}
&:checked + .core-error-info--content {
max-height: 170px;
}
}
}

View File

@ -40,16 +40,16 @@ export class CoreErrorInfoComponent implements OnInit, OnChanges {
*/
static render(errorDetails: string, errorCode?: string): string {
const toggleId = CoreForms.uniqueId('error-info-toggle');
const errorCodeLabel = Translate.instant('core.errorcode');
const errorCodeLabel = Translate.instant('core.errorcode', { errorCode });
const hideDetailsLabel = Translate.instant('core.errordetailshide');
const showDetailsLabel = Translate.instant('core.errordetailsshow');
return `
<div class="core-error-info ${errorCode ? 'has-error-code' : ''}">
<div class="core-error-info">
<input id="${toggleId}" type="checkbox" class="core-error-info--checkbox" />
<div class="core-error-info--content">
${errorCode ? `<p class="core-error-info--code"><strong>${errorCodeLabel}: ${errorCode}</strong></p>` : ''}
<p class="core-error-info--details">${errorDetails}</p>
${errorCode ? `<div class="core-error-info--code"><strong>${errorCodeLabel}</strong></div>` : ''}
<div class="core-error-info--details">
<p>${errorDetails}</p>
</div>
<label for="${toggleId}" class="core-error-info--toggle" aria-hidden="true">
<span class="core-error-info--hide-content">

View File

@ -66,6 +66,13 @@ export class CoreUserAuthenticatedSupportConfig extends CoreUserSupportConfig {
return false;
}
/**
* @inheritdoc
*/
getSupportPageLang(): string | null {
return this.site.infos?.lang ?? null;
}
/**
* @inheritdoc
*/

View File

@ -13,6 +13,7 @@
// limitations under the License.
import { CoreSiteConfigSupportAvailability, CoreSitePublicConfigResponse } from '@classes/site';
import { CoreLoginHelper } from '@features/login/services/login-helper';
import { CoreUserNullSupportConfig } from '@features/user/classes/support/null-support-config';
import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils';
@ -51,6 +52,10 @@ export class CoreUserGuestSupportConfig extends CoreUserSupportConfig {
* @inheritdoc
*/
canContactSupport(): boolean {
if (CoreLoginHelper.isFeatureDisabled('NoDelegate_CoreUserSupport', this.config)) {
return false;
}
// This config was introduced in 4.1, if it's missing we can assume the site is 4.0 or lower.
if ('supportavailability' in this.config) {
return this.config.supportavailability === CoreSiteConfigSupportAvailability.Anyone;
@ -60,6 +65,13 @@ export class CoreUserGuestSupportConfig extends CoreUserSupportConfig {
return 'supportpage' in this.config;
}
/**
* @inheritdoc
*/
getSupportPageLang(): string | null {
return this.config.lang ?? null;
}
/**
* @inheritdoc
*/

View File

@ -29,6 +29,13 @@ export class CoreUserNullSupportConfig extends CoreUserSupportConfig {
return false;
}
/**
* @inheritdoc
*/
getSupportPageLang(): string | null {
return null;
}
/**
* @inheritdoc
*/

View File

@ -24,6 +24,13 @@ export abstract class CoreUserSupportConfig {
*/
public abstract canContactSupport(): boolean;
/**
* Get language used in the support page, if any.
*
* @return Support page language.
*/
public abstract getSupportPageLang(): string | null;
/**
* Get url to use for contacting support.
*

View File

@ -31,6 +31,8 @@
"sendemail": "Email",
"student": "Student",
"support": "Contact site support",
"supportmessagesent": "Your message has been sent.",
"supportsubject": "[App] {{subject}}",
"teacher": "Non-editing teacher",
"userwithid": "User with ID {{id}}",
"webpage": "Web page"

View File

@ -24,6 +24,7 @@ import { CoreEvents } from '@singletons/events';
import { CoreSubscriptions } from '@singletons/subscriptions';
import { AlertButton } from '@ionic/angular';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreLang } from '@services/lang';
/**
* Handle site support.
@ -44,6 +45,7 @@ export class CoreUserSupportService {
if (supportPageUrl.endsWith('/user/contactsitesupport.php')) {
this.populateSupportForm(browser, options.subject, options.message);
this.listenSupportFormSubmission(browser, supportConfig.getSupportPageLang());
}
await CoreEvents.waitUntil(CoreEvents.IAB_EXIT);
@ -90,6 +92,10 @@ export class CoreUserSupportService {
return;
}
if (subject) {
subject = Translate.instant('core.user.supportsubject', { subject });
}
const unsubscribe = CoreSubscriptions.once(browser.on('loadstop'), () => {
browser.executeScript({
code: `
@ -102,6 +108,37 @@ export class CoreUserSupportService {
CoreEvents.once(CoreEvents.IAB_EXIT, () => unsubscribe());
}
/**
* Set up listeners to close the browser when the contact form has been submitted.
*
* @param browser In App browser.
* @param lang Language used in the support page.
*/
protected async listenSupportFormSubmission(browser: InAppBrowserObject, lang: string | null): Promise<void> {
const appSuccessMessage = Translate.instant('core.user.supportmessagesent');
const lmsSuccessMessage = lang && await CoreLang.getMessage('core.user.supportmessagesent', lang);
const subscription = browser.on('loadstop').subscribe(async () => {
const result = await browser.executeScript({
code: `
[...document.querySelectorAll('.alert-success')].some(
div =>
div.textContent?.includes(${JSON.stringify(lmsSuccessMessage)}) ||
div.textContent?.includes(${JSON.stringify(appSuccessMessage)})
)
`,
});
if (!Array.isArray(result) || result[0] !== true) {
return;
}
browser.close();
CoreDomUtils.showAlert(undefined, appSuccessMessage);
});
CoreEvents.once(CoreEvents.IAB_EXIT, () => subscription.unsubscribe());
}
}
export const CoreUserSupport = makeSingleton(CoreUserSupportService);

View File

@ -102,7 +102,7 @@
"endonesteptour": "Got it",
"error": "Error",
"errorchangecompletion": "An error occurred while changing the completion status. Please try again.",
"errorcode": "Error code",
"errorcode": "Error code: {{errorCode}}",
"errordeletefile": "Error deleting the file. Please try again.",
"errordetailshide": "Hide error details",
"errordetailsshow": "Show error details",

View File

@ -119,6 +119,33 @@ export class CoreLangProvider {
return value.charAt(0).toUpperCase() + value.slice(1);
}
/**
* Get message for the given language.
*
* @param key Message key.
* @param lang Language.
* @returns Message if found, null otherwise.
*/
async getMessage(key: string, lang: string): Promise<string | null> {
const messages = await this.getMessages(lang);
return messages[key] ?? null;
}
/**
* Get messages for the given language.
*
* @param lang Language.
* @returns Messages.
*/
getMessages(lang: string): Promise<Record<string, string>> {
return new Promise(resolve => CoreSubscriptions.once(
Translate.getTranslation(lang),
messages => resolve(messages),
() => resolve({}),
));
}
/**
* Get the parent language defined on the language strings.
*