forked from EVOgeek/Vmeda.Online
		
	MOBILE-4245 Dev: Add confirmation modal before reload app
This commit is contained in:
		
							parent
							
								
									fe97d32342
								
							
						
					
					
						commit
						856a8a4957
					
				| @ -30,11 +30,11 @@ | |||||||
|             </ion-label> |             </ion-label> | ||||||
|             <ion-toggle [(ngModel)]="forceSafeAreaMargins" (ionChange)="safeAreaChanged()"></ion-toggle> |             <ion-toggle [(ngModel)]="forceSafeAreaMargins" (ionChange)="safeAreaChanged()"></ion-toggle> | ||||||
|         </ion-item> |         </ion-item> | ||||||
|         <ion-item class="ion-text-wrap" *ngIf="stagingSites.length"> |         <ion-item class="ion-text-wrap" *ngIf="stagingSitesCount && enableStagingSites !== undefined"> | ||||||
|             <ion-label> |             <ion-label> | ||||||
|                 <h2>Enable staging sites</h2> |                 <h2>Enable staging sites ({{stagingSitesCount}})</h2> | ||||||
|             </ion-label> |             </ion-label> | ||||||
|             <ion-toggle [(ngModel)]="enableStagingSites" (ionChange)="setEnabledStagingSites()"></ion-toggle> |             <ion-toggle [checked]="enableStagingSites" (ionChange)="setEnabledStagingSites($event.detail.checked)"></ion-toggle> | ||||||
|         </ion-item> |         </ion-item> | ||||||
|         <ng-container *ngIf="siteId"> |         <ng-container *ngIf="siteId"> | ||||||
|             <ion-item class="ion-text-wrap"> |             <ion-item class="ion-text-wrap"> | ||||||
|  | |||||||
| @ -14,13 +14,13 @@ | |||||||
| 
 | 
 | ||||||
| import { CoreConstants } from '@/core/constants'; | import { CoreConstants } from '@/core/constants'; | ||||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||||||
| import { CoreLoginHelperProvider } from '@features/login/services/login-helper'; | import { CoreLoginHelper, CoreLoginHelperProvider } from '@features/login/services/login-helper'; | ||||||
| import { CoreSettingsHelper } from '@features/settings/services/settings-helper'; | import { CoreSettingsHelper } from '@features/settings/services/settings-helper'; | ||||||
| import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins'; | import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins'; | ||||||
| import { CoreUserTours } from '@features/usertours/services/user-tours'; | import { CoreUserTours } from '@features/usertours/services/user-tours'; | ||||||
| import { CoreConfig } from '@services/config'; | import { CoreConfig } from '@services/config'; | ||||||
| import { CorePlatform } from '@services/platform'; | import { CorePlatform } from '@services/platform'; | ||||||
| import { CoreLoginSiteInfo, CoreSites } from '@services/sites'; | import { CoreSites } from '@services/sites'; | ||||||
| import { CoreDomUtils } from '@services/utils/dom'; | import { CoreDomUtils } from '@services/utils/dom'; | ||||||
| import { CoreUtils } from '@services/utils/utils'; | import { CoreUtils } from '@services/utils/utils'; | ||||||
| 
 | 
 | ||||||
| @ -43,8 +43,8 @@ export class CoreSettingsDevPage implements OnInit { | |||||||
|     pluginStylesCount = 0; |     pluginStylesCount = 0; | ||||||
|     sitePlugins: CoreSitePluginsBasicInfo[] = []; |     sitePlugins: CoreSitePluginsBasicInfo[] = []; | ||||||
|     userToursEnabled = true; |     userToursEnabled = true; | ||||||
|     stagingSites: CoreLoginSiteInfo[] = []; |     stagingSitesCount = 0; | ||||||
|     enableStagingSites = false; |     enableStagingSites?: boolean; | ||||||
| 
 | 
 | ||||||
|     disabledFeatures: string[] = []; |     disabledFeatures: string[] = []; | ||||||
| 
 | 
 | ||||||
| @ -59,9 +59,9 @@ export class CoreSettingsDevPage implements OnInit { | |||||||
| 
 | 
 | ||||||
|         this.siteId = CoreSites.getCurrentSite()?.getId(); |         this.siteId = CoreSites.getCurrentSite()?.getId(); | ||||||
| 
 | 
 | ||||||
|         this.stagingSites = CoreConstants.CONFIG.stagingsites; |         this.stagingSitesCount = CoreConstants.CONFIG.sites.filter((site) => site.staging).length; | ||||||
| 
 | 
 | ||||||
|         if (this.stagingSites.length) { |         if (this.stagingSitesCount) { | ||||||
|             this.enableStagingSites = await CoreSettingsHelper.hasEnabledStagingSites(); |             this.enableStagingSites = await CoreSettingsHelper.hasEnabledStagingSites(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -167,8 +167,8 @@ export class CoreSettingsDevPage implements OnInit { | |||||||
|         CoreDomUtils.showToast('User tours have been reseted'); |         CoreDomUtils.showToast('User tours have been reseted'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async setEnabledStagingSites(): Promise<void> { |     async setEnabledStagingSites(enabled: boolean): Promise<void> { | ||||||
|         await CoreSettingsHelper.setEnabledStagingSites(this.enableStagingSites); |         await CoreSettingsHelper.setEnabledStagingSites(enabled); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -30,6 +30,7 @@ import { makeSingleton, Translate } from '@singletons'; | |||||||
| import { CoreError } from '@classes/errors/error'; | import { CoreError } from '@classes/errors/error'; | ||||||
| import { Observable, Subject } from 'rxjs'; | import { Observable, Subject } from 'rxjs'; | ||||||
| import { CoreTextUtils } from '@services/utils/text'; | import { CoreTextUtils } from '@services/utils/text'; | ||||||
|  | import { CoreNavigator } from '@services/navigator'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Object with space usage and cache entries that can be erased. |  * Object with space usage and cache entries that can be erased. | ||||||
| @ -477,15 +478,32 @@ export class CoreSettingsHelperProvider { | |||||||
|         return this.darkModeObservable; |         return this.darkModeObservable; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Get if user enabled staging sites or not. | ||||||
|  |      * | ||||||
|  |      * @returns Staging sites. | ||||||
|  |      */ | ||||||
|     async hasEnabledStagingSites(): Promise<boolean> { |     async hasEnabledStagingSites(): Promise<boolean> { | ||||||
|         const staging = await CoreConfig.get<string>('staging_sites', 'false'); |         const staging = await CoreConfig.get<number>('stagingSites', 0); | ||||||
| 
 | 
 | ||||||
|         return CoreUtils.isTrueOrOne(staging); |         return !!staging; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Persist staging sites enabled status and refresh app to apply changes. | ||||||
|  |      * | ||||||
|  |      * @param enabled Enabled or disabled staging sites. | ||||||
|  |      */ | ||||||
|     async setEnabledStagingSites(enabled: boolean): Promise<void> { |     async setEnabledStagingSites(enabled: boolean): Promise<void> { | ||||||
|         await CoreConfig.set('staging_sites', `${enabled}`); |         try { | ||||||
|         CoreEvents.trigger(CoreEvents.STAGING_SITES_CHANGE, { enabled }); |             await CoreConfig.set('stagingSites', enabled ? 1 : 0); | ||||||
|  |             await CoreDomUtils.showConfirm('Are you sure that you want to enable/disable staging sites?'); | ||||||
|  |         } catch { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         await CoreNavigator.navigate('/'); | ||||||
|  |         window.location.reload(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user