MOBILE-3833 dev: Add the option to reset user tours

main
Pau Ferrer Ocaña 2022-04-05 11:01:10 +02:00
parent 568f161550
commit de9a478633
3 changed files with 47 additions and 1 deletions

View File

@ -45,6 +45,14 @@
</ion-label>
<ion-toggle [(ngModel)]="pluginStyles" (ionChange)="pluginStylesChanged()"></ion-toggle>
</ion-item>
<ion-item class="ion-text-wrap" *ngIf="userToursEnabled">
<ion-label>
<h2>Reset user tours</h2>
</ion-label>
<ion-button (click)="resetUserTours()" aria-label="Reset user tours" fill="clear" slot="end">
<ion-icon slot="icon-only" aria-hidden="true" name="fas-broom"></ion-icon>
</ion-button>
</ion-item>
<ion-item-divider>
<ion-label>

View File

@ -14,7 +14,9 @@
import { Component, OnInit } from '@angular/core';
import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins';
import { CoreUserTours } from '@features/usertours/services/user-tours';
import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils';
import { Platform } from '@singletons';
@ -36,6 +38,7 @@ export class CoreSettingsDevPage implements OnInit {
pluginStyles = true;
pluginStylesCount = 0;
sitePlugins: CoreSitePluginsBasicInfo[] = [];
userToursEnabled = true;
disabledFeatures: string[] = [];
@ -60,6 +63,8 @@ export class CoreSettingsDevPage implements OnInit {
this.pluginStyles = false;
this.pluginStylesCount = 0;
this.userToursEnabled = !CoreUserTours.isDisabled();
document.head.querySelectorAll('style').forEach((style) => {
if (this.siteId && style.id.endsWith(this.siteId)) {
if (style.innerHTML.length > 0) {
@ -139,6 +144,14 @@ export class CoreSettingsDevPage implements OnInit {
CoreUtils.copyToClipboard(JSON.stringify({ disabledFeatures: this.disabledFeatures, sitePlugins: this.sitePlugins }));
}
/**
* Reset all user tours.
*/
async resetUserTours(): Promise<void> {
await CoreUserTours.resetTours();
CoreDomUtils.showToast('User tours have been reseted');
}
}
// Basic site plugin info.

View File

@ -63,7 +63,7 @@ export class CoreUserToursService {
* @returns Whether the User Tour is pending or not.
*/
async isPending(id: string): Promise<boolean> {
if (CoreConstants.CONFIG.disableUserTours || CoreConstants.CONFIG.disabledUserTours?.includes(id)) {
if (this.isDisabled(id)) {
return false;
}
@ -252,6 +252,31 @@ export class CoreUserToursService {
}
}
/**
* Is user Tour disabled?
*
* @param tourId Tour Id or undefined to check all user tours.
* @return Wether a particular or all user tours are disabled.
*/
isDisabled(tourId?: string): boolean {
if (CoreConstants.CONFIG.disableUserTours) {
return true;
}
return !!tourId && !!CoreConstants.CONFIG.disabledUserTours?.includes(tourId);
}
/**
* It will reset all user tours.
*/
async resetTours(): Promise<void> {
if (this.isDisabled()) {
return;
}
await this.table.delete();
}
}
export const CoreUserTours = makeSingleton(CoreUserToursService);