@rolatech/angular-services 20.0.5 → 20.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, viewChild, ViewContainerRef, OutputEmitterRef, EventEmitter, HostListener, Component, Injectable, signal, computed, PLATFORM_ID, Directive, APP_INITIALIZER, makeEnvironmentProviders } from '@angular/core';
|
|
2
|
+
import { inject, viewChild, ViewContainerRef, OutputEmitterRef, EventEmitter, HostListener, Component, Injectable, signal, computed, PLATFORM_ID, REQUEST, Directive, APP_INITIALIZER, makeEnvironmentProviders } from '@angular/core';
|
|
3
3
|
import { MAT_DIALOG_DATA, MatDialogRef, MatDialogActions, MatDialogTitle, MatDialogContent, MatDialog } from '@angular/material/dialog';
|
|
4
4
|
import * as i1 from '@angular/material/button';
|
|
5
5
|
import { MatButtonModule } from '@angular/material/button';
|
|
@@ -7,7 +7,7 @@ import { switchMap, map, take, BehaviorSubject, Observable, Subject, firstValueF
|
|
|
7
7
|
import _ from 'lodash';
|
|
8
8
|
import { HttpClient, HttpParams, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
9
9
|
import { APP_CONFIG } from '@rolatech/angular-common';
|
|
10
|
-
import { Location, isPlatformBrowser } from '@angular/common';
|
|
10
|
+
import { Location, isPlatformBrowser, isPlatformServer } from '@angular/common';
|
|
11
11
|
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
|
|
12
12
|
import { BreakpointObserver, Breakpoints, MediaMatcher } from '@angular/cdk/layout';
|
|
13
13
|
import { map as map$1, shareReplay, finalize } from 'rxjs/operators';
|
|
@@ -3083,11 +3083,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0", ngImpor
|
|
|
3083
3083
|
}] });
|
|
3084
3084
|
|
|
3085
3085
|
class LoadingInterceptor {
|
|
3086
|
-
loadingService;
|
|
3086
|
+
loadingService = inject(LoadingService);
|
|
3087
3087
|
activeRequests = 0;
|
|
3088
|
-
constructor(loadingService) {
|
|
3089
|
-
this.loadingService = loadingService;
|
|
3090
|
-
}
|
|
3091
3088
|
intercept(request, next) {
|
|
3092
3089
|
if (this.activeRequests === 0) {
|
|
3093
3090
|
this.loadingService.start();
|
|
@@ -3100,7 +3097,7 @@ class LoadingInterceptor {
|
|
|
3100
3097
|
}
|
|
3101
3098
|
}));
|
|
3102
3099
|
}
|
|
3103
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0", ngImport: i0, type: LoadingInterceptor, deps: [
|
|
3100
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0", ngImport: i0, type: LoadingInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
3104
3101
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.0", ngImport: i0, type: LoadingInterceptor, providedIn: 'root' });
|
|
3105
3102
|
}
|
|
3106
3103
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0", ngImport: i0, type: LoadingInterceptor, decorators: [{
|
|
@@ -3108,7 +3105,80 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0", ngImpor
|
|
|
3108
3105
|
args: [{
|
|
3109
3106
|
providedIn: 'root',
|
|
3110
3107
|
}]
|
|
3111
|
-
}]
|
|
3108
|
+
}] });
|
|
3109
|
+
|
|
3110
|
+
// language.service.ts
|
|
3111
|
+
class LanguageService {
|
|
3112
|
+
platformId = inject(PLATFORM_ID);
|
|
3113
|
+
req = inject(REQUEST);
|
|
3114
|
+
storageKey = 'hl';
|
|
3115
|
+
lang = signal(this.detectInitial(), ...(ngDevMode ? [{ debugName: "lang" }] : []));
|
|
3116
|
+
acceptLanguage = computed(() => this.lang(), ...(ngDevMode ? [{ debugName: "acceptLanguage" }] : [])); // 'en' | 'zh-Hans'
|
|
3117
|
+
detectInitial() {
|
|
3118
|
+
// Default to English when header is null/blank/unknown
|
|
3119
|
+
if (isPlatformServer(this.platformId)) {
|
|
3120
|
+
const hdr = this.req?.headers?.['accept-language'] ?? '';
|
|
3121
|
+
return hdr.toLowerCase().startsWith('zh') ? 'zh-Hans' : 'en';
|
|
3122
|
+
}
|
|
3123
|
+
// Browser
|
|
3124
|
+
const saved = typeof localStorage !== 'undefined' ? localStorage.getItem(this.storageKey) : null;
|
|
3125
|
+
if (saved === 'en' || saved === 'zh-Hans')
|
|
3126
|
+
return saved;
|
|
3127
|
+
const nav = (navigator.language || (navigator.languages?.[0] ?? '')).toLowerCase();
|
|
3128
|
+
return nav.startsWith('zh') ? 'zh-Hans' : 'en';
|
|
3129
|
+
}
|
|
3130
|
+
set(lang) {
|
|
3131
|
+
this.lang.set(lang);
|
|
3132
|
+
if (isPlatformBrowser(this.platformId)) {
|
|
3133
|
+
localStorage.setItem(this.storageKey, lang);
|
|
3134
|
+
// Optional: keep <html lang="..."> in sync
|
|
3135
|
+
document.documentElement.lang = lang.startsWith('zh') ? 'zh' : 'en';
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0", ngImport: i0, type: LanguageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
3139
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.0", ngImport: i0, type: LanguageService, providedIn: 'root' });
|
|
3140
|
+
}
|
|
3141
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0", ngImport: i0, type: LanguageService, decorators: [{
|
|
3142
|
+
type: Injectable,
|
|
3143
|
+
args: [{ providedIn: 'root' }]
|
|
3144
|
+
}] });
|
|
3145
|
+
|
|
3146
|
+
// Adjust to your app:
|
|
3147
|
+
const API_PREFIXES = ['/api', '/auth', '/properties']; // relative paths you own
|
|
3148
|
+
const API_HOSTS = new Set([
|
|
3149
|
+
'localhost:9001', // dev backend
|
|
3150
|
+
'api.primecasa.co.uk', // prod backend
|
|
3151
|
+
]);
|
|
3152
|
+
const acceptLanguageInterceptor = (req, next) => {
|
|
3153
|
+
const lang = (inject(LanguageService).acceptLanguage() ?? 'en');
|
|
3154
|
+
const url = req.url;
|
|
3155
|
+
const isAbsolute = /^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(url);
|
|
3156
|
+
// Ignore static assets and obvious 3rd-party calls early
|
|
3157
|
+
if (!isAbsolute && url.startsWith('/assets')) {
|
|
3158
|
+
return next(req);
|
|
3159
|
+
}
|
|
3160
|
+
// Decide if we should attach the header
|
|
3161
|
+
let shouldAttach = false;
|
|
3162
|
+
if (!isAbsolute) {
|
|
3163
|
+
// Same-origin (dev proxy or app backend behind the UI origin)
|
|
3164
|
+
shouldAttach = API_PREFIXES.some(p => url.startsWith(p) || url.startsWith('/' + p.replace(/^\//, ''))) || url.startsWith('/'); // fallback: any relative app call
|
|
3165
|
+
}
|
|
3166
|
+
else {
|
|
3167
|
+
// Absolute URL: only attach for whitelisted API hosts
|
|
3168
|
+
try {
|
|
3169
|
+
const u = new URL(url);
|
|
3170
|
+
shouldAttach = API_HOSTS.has(u.host);
|
|
3171
|
+
}
|
|
3172
|
+
catch {
|
|
3173
|
+
shouldAttach = false;
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
// Don’t duplicate if header is already present
|
|
3177
|
+
if (!shouldAttach || req.headers.has('Accept-Language')) {
|
|
3178
|
+
return next(req);
|
|
3179
|
+
}
|
|
3180
|
+
return next(req.clone({ setHeaders: { 'Accept-Language': lang || 'en' } }));
|
|
3181
|
+
};
|
|
3112
3182
|
|
|
3113
3183
|
class BackButtonDirective {
|
|
3114
3184
|
navigation = inject(NavigationService);
|
|
@@ -3176,5 +3246,5 @@ function provideAngularServices() {
|
|
|
3176
3246
|
* Generated bundle index. Do not edit.
|
|
3177
3247
|
*/
|
|
3178
3248
|
|
|
3179
|
-
export { AmenityService, BackButtonDirective, BaseService, BookingService, BreadcrumbService, CartEventType, CartService, CategoryService, ConversationInitService, ConversationService, DialogComponent, DialogService, FacilityService, FeatureService, FulfillmentService, HideFooterDirective, InventoryService, LayoutService, LoadingInterceptor, LoadingService, MediaService, MembershipService, NavigationService, NotificationService, NotificationStore, NotificationTemplateService, OfferingService, OrderPayoutService, OrderService, PaymentService, PostService, ProductCategoryService, ProductService, PropertySearchService, PropertyService, ResourceCategoryService, ResourceService, SERVICE_DIRECTIVES, SidenavService, SnackBarService, SupportService, ThemeService, TimeZoneService, TitleService, provideAngularServices };
|
|
3249
|
+
export { AmenityService, BackButtonDirective, BaseService, BookingService, BreadcrumbService, CartEventType, CartService, CategoryService, ConversationInitService, ConversationService, DialogComponent, DialogService, FacilityService, FeatureService, FulfillmentService, HideFooterDirective, InventoryService, LayoutService, LoadingInterceptor, LoadingService, MediaService, MembershipService, NavigationService, NotificationService, NotificationStore, NotificationTemplateService, OfferingService, OrderPayoutService, OrderService, PaymentService, PostService, ProductCategoryService, ProductService, PropertySearchService, PropertyService, ResourceCategoryService, ResourceService, SERVICE_DIRECTIVES, SidenavService, SnackBarService, SupportService, ThemeService, TimeZoneService, TitleService, acceptLanguageInterceptor, provideAngularServices };
|
|
3180
3250
|
//# sourceMappingURL=rolatech-angular-services.mjs.map
|