@poadio/ui-angular 0.0.0-stage → 0.11.0
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.
- package/LICENSE +22 -0
- package/README.md +186 -2
- package/core/README.md +97 -0
- package/fesm2022/poadio-ui-angular-core.mjs +1158 -0
- package/fesm2022/poadio-ui-angular-core.mjs.map +1 -0
- package/fesm2022/poadio-ui-angular.mjs +39874 -0
- package/fesm2022/poadio-ui-angular.mjs.map +1 -0
- package/package.json +94 -3
- package/styles/base.scss +32 -0
- package/styles/tokens.scss +116 -0
- package/types/poadio-ui-angular-core.d.ts +510 -0
- package/types/poadio-ui-angular.d.ts +10784 -0
|
@@ -0,0 +1,1158 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, Injectable, signal, Optional, Inject, computed, inject, Injector, runInInjectionContext, effect } from '@angular/core';
|
|
3
|
+
import * as i1 from '@angular/common/http';
|
|
4
|
+
import { HttpParams } from '@angular/common/http';
|
|
5
|
+
import { Subject, Observable } from 'rxjs';
|
|
6
|
+
|
|
7
|
+
const CADRICIEL_CORE_CONFIG = new InjectionToken('CADRICIEL_CORE_CONFIG');
|
|
8
|
+
// Deprecated alias for compatibility if needed, but better use new name
|
|
9
|
+
const CADRICIEL_AUTH_ENV = CADRICIEL_CORE_CONFIG;
|
|
10
|
+
|
|
11
|
+
class ApplicationConfigService {
|
|
12
|
+
_endpointPrefix = '';
|
|
13
|
+
_endpointPrefixApiOpen = '';
|
|
14
|
+
get endpointPrefix() {
|
|
15
|
+
return this._endpointPrefix;
|
|
16
|
+
}
|
|
17
|
+
set endpointPrefix(value) {
|
|
18
|
+
this._endpointPrefix = value;
|
|
19
|
+
}
|
|
20
|
+
get endpointPrefixApiOpen() {
|
|
21
|
+
return this._endpointPrefixApiOpen;
|
|
22
|
+
}
|
|
23
|
+
set endpointPrefixApiOpen(value) {
|
|
24
|
+
this._endpointPrefixApiOpen = value;
|
|
25
|
+
}
|
|
26
|
+
getEndpointFor(api) {
|
|
27
|
+
return `${this.endpointPrefix}${api}`;
|
|
28
|
+
}
|
|
29
|
+
getEndpointForApiOpen(api) {
|
|
30
|
+
return `${this.endpointPrefixApiOpen}${api}`;
|
|
31
|
+
}
|
|
32
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: ApplicationConfigService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
33
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: ApplicationConfigService, providedIn: 'root' });
|
|
34
|
+
}
|
|
35
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: ApplicationConfigService, decorators: [{
|
|
36
|
+
type: Injectable,
|
|
37
|
+
args: [{
|
|
38
|
+
providedIn: 'root',
|
|
39
|
+
}]
|
|
40
|
+
}] });
|
|
41
|
+
|
|
42
|
+
class UserService {
|
|
43
|
+
httpClient;
|
|
44
|
+
applicationConfigService;
|
|
45
|
+
get info() {
|
|
46
|
+
const removeAt = [
|
|
47
|
+
'at_hash',
|
|
48
|
+
'aud',
|
|
49
|
+
'auth_time',
|
|
50
|
+
'azp',
|
|
51
|
+
'email_verified',
|
|
52
|
+
'exp',
|
|
53
|
+
'iss',
|
|
54
|
+
'iat',
|
|
55
|
+
'jti',
|
|
56
|
+
'nonce',
|
|
57
|
+
'resource_access',
|
|
58
|
+
'session_state',
|
|
59
|
+
'sid',
|
|
60
|
+
'sub',
|
|
61
|
+
'typ',
|
|
62
|
+
'adminDisplayName',
|
|
63
|
+
];
|
|
64
|
+
const infoStr = sessionStorage.getItem('id_token_claims_obj');
|
|
65
|
+
if (!infoStr)
|
|
66
|
+
return {};
|
|
67
|
+
const info = JSON.parse(infoStr);
|
|
68
|
+
info.uuid = info.sub;
|
|
69
|
+
for (let i = 0; i < removeAt.length; i++)
|
|
70
|
+
delete info[removeAt[i]];
|
|
71
|
+
return info;
|
|
72
|
+
}
|
|
73
|
+
_currentUser = signal(undefined, ...(ngDevMode ? [{ debugName: "_currentUser" }] : /* istanbul ignore next */ []));
|
|
74
|
+
currentUser = this._currentUser.asReadonly();
|
|
75
|
+
setCurrentUser(value) {
|
|
76
|
+
console.log('UserService: setCurrentUser called', value);
|
|
77
|
+
this._currentUser.set(value);
|
|
78
|
+
}
|
|
79
|
+
constructor(httpClient, applicationConfigService) {
|
|
80
|
+
this.httpClient = httpClient;
|
|
81
|
+
this.applicationConfigService = applicationConfigService;
|
|
82
|
+
}
|
|
83
|
+
getCurrentUser() {
|
|
84
|
+
const url = '/user';
|
|
85
|
+
return this.httpClient.get(this.applicationConfigService.getEndpointFor(url), { observe: 'response' });
|
|
86
|
+
}
|
|
87
|
+
getAvatar() {
|
|
88
|
+
const url = '/avatar';
|
|
89
|
+
return this.httpClient.get(this.applicationConfigService.getEndpointFor(url), {
|
|
90
|
+
observe: 'response',
|
|
91
|
+
responseType: 'blob'
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
userHasRole(...roles) {
|
|
95
|
+
const user = this.currentUser();
|
|
96
|
+
if (!user || !user.roleActifList)
|
|
97
|
+
return false;
|
|
98
|
+
return roles.some((role) => user.roleActifList.indexOf(role) >= 0);
|
|
99
|
+
}
|
|
100
|
+
addInfoFromClaims(identityClaims) {
|
|
101
|
+
this._currentUser.update(user => {
|
|
102
|
+
if (!user)
|
|
103
|
+
return undefined;
|
|
104
|
+
return {
|
|
105
|
+
...user,
|
|
106
|
+
nom: identityClaims.family_name,
|
|
107
|
+
prenom: identityClaims.given_name
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: UserService, deps: [{ token: i1.HttpClient }, { token: ApplicationConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
112
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: UserService, providedIn: 'root' });
|
|
113
|
+
}
|
|
114
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: UserService, decorators: [{
|
|
115
|
+
type: Injectable,
|
|
116
|
+
args: [{
|
|
117
|
+
providedIn: 'root',
|
|
118
|
+
}]
|
|
119
|
+
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: ApplicationConfigService }] });
|
|
120
|
+
|
|
121
|
+
class RealtimeService {
|
|
122
|
+
config;
|
|
123
|
+
wsBaseUrl;
|
|
124
|
+
sockets = {};
|
|
125
|
+
messageSubjects = {};
|
|
126
|
+
constructor(config) {
|
|
127
|
+
this.config = config;
|
|
128
|
+
this.wsBaseUrl = this.resolveWsBaseUrl();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Ouvre un canal WebSocket et retourne un objet contrôleur pour ce canal.
|
|
132
|
+
*/
|
|
133
|
+
channel(channel, params = {}, isEdge = false) {
|
|
134
|
+
if (!this.sockets[channel]) {
|
|
135
|
+
this.connect(channel, params, isEdge);
|
|
136
|
+
}
|
|
137
|
+
return new ChannelController(channel, this.sockets, this.messageSubjects);
|
|
138
|
+
}
|
|
139
|
+
connect(channel, params, isEdge) {
|
|
140
|
+
const token = sessionStorage.getItem('access_token');
|
|
141
|
+
if (!token) {
|
|
142
|
+
console.error('No token found in sessionStorage.');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const queryParams = new URLSearchParams(params).toString();
|
|
146
|
+
const urlSuffix = isEdge ? '/edge' : ''; // <- route dédiée aux edge functions
|
|
147
|
+
const wsUrl = `${this.wsBaseUrl}${urlSuffix}?action=${channel}&${queryParams}`;
|
|
148
|
+
const socket = new WebSocket(wsUrl, [token]);
|
|
149
|
+
this.sockets[channel] = socket;
|
|
150
|
+
this.messageSubjects[channel] = new Subject();
|
|
151
|
+
socket.onopen = () => {
|
|
152
|
+
console.log(`✅ WebSocket ${isEdge ? 'EDGE' : 'STD'} connecté pour le canal : ${channel}`);
|
|
153
|
+
};
|
|
154
|
+
socket.onmessage = (event) => {
|
|
155
|
+
try {
|
|
156
|
+
const data = JSON.parse(event.data);
|
|
157
|
+
this.messageSubjects[channel].next(data);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
console.error('❌ Erreur de parsing du message WebSocket :', error);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
socket.onclose = () => {
|
|
164
|
+
console.warn(`❌ WebSocket fermé pour le canal : ${channel}`);
|
|
165
|
+
delete this.sockets[channel];
|
|
166
|
+
};
|
|
167
|
+
socket.onerror = (error) => {
|
|
168
|
+
console.error(`❌ WebSocket erreur pour le canal : ${channel}`, error);
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
resolveWsBaseUrl() {
|
|
172
|
+
const apiUrl = this.config?.serverApiUrl ?? '';
|
|
173
|
+
if (!apiUrl) {
|
|
174
|
+
console.warn('RealtimeService: serverApiUrl not provided in CADRICIEL_CORE_CONFIG');
|
|
175
|
+
return '';
|
|
176
|
+
}
|
|
177
|
+
const normalized = apiUrl.replace(/^https?:\/\//, '').replace(/\/+$/, '');
|
|
178
|
+
return normalized ? `wss://${normalized}/ws` : '';
|
|
179
|
+
}
|
|
180
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: RealtimeService, deps: [{ token: CADRICIEL_CORE_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
181
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: RealtimeService, providedIn: 'root' });
|
|
182
|
+
}
|
|
183
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: RealtimeService, decorators: [{
|
|
184
|
+
type: Injectable,
|
|
185
|
+
args: [{
|
|
186
|
+
providedIn: 'root',
|
|
187
|
+
}]
|
|
188
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
189
|
+
type: Optional
|
|
190
|
+
}, {
|
|
191
|
+
type: Inject,
|
|
192
|
+
args: [CADRICIEL_CORE_CONFIG]
|
|
193
|
+
}] }] });
|
|
194
|
+
/**
|
|
195
|
+
* Contrôleur pour interagir avec un canal WebSocket spécifique.
|
|
196
|
+
*/
|
|
197
|
+
class ChannelController {
|
|
198
|
+
channel;
|
|
199
|
+
sockets;
|
|
200
|
+
messageSubjects;
|
|
201
|
+
constructor(channel, sockets, messageSubjects) {
|
|
202
|
+
this.channel = channel;
|
|
203
|
+
this.sockets = sockets;
|
|
204
|
+
this.messageSubjects = messageSubjects;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Écoute les événements spécifiques sur le canal.
|
|
208
|
+
*/
|
|
209
|
+
on(eventType, callback) {
|
|
210
|
+
const subject = this.getSubject();
|
|
211
|
+
subject.subscribe((message) => {
|
|
212
|
+
if (message.type === eventType) {
|
|
213
|
+
callback(message);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Envoie un message sur ce canal.
|
|
220
|
+
*/
|
|
221
|
+
send(type, payload = {}) {
|
|
222
|
+
const socket = this.sockets[this.channel];
|
|
223
|
+
if (socket && socket.readyState === WebSocket.OPEN) {
|
|
224
|
+
const message = { type, ...payload };
|
|
225
|
+
socket.send(JSON.stringify(message));
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
console.error('WebSocket is not open for channel:', this.channel);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Ferme la connexion pour ce canal.
|
|
233
|
+
*/
|
|
234
|
+
disconnect() {
|
|
235
|
+
const socket = this.sockets[this.channel];
|
|
236
|
+
if (socket) {
|
|
237
|
+
console.log(`❌ Fermeture du WebSocket pour le canal : ${this.channel}`);
|
|
238
|
+
socket.close();
|
|
239
|
+
delete this.sockets[this.channel];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
getSubject() {
|
|
243
|
+
if (!this.messageSubjects[this.channel]) {
|
|
244
|
+
this.messageSubjects[this.channel] = new Subject();
|
|
245
|
+
}
|
|
246
|
+
return this.messageSubjects[this.channel];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* CLASSE AGGREGATE BUILDER (optionnelle)
|
|
252
|
+
*
|
|
253
|
+
* Permet une construction fluide et type-safe des agrégations
|
|
254
|
+
*/
|
|
255
|
+
class AggregateBuilder {
|
|
256
|
+
queryService;
|
|
257
|
+
aggregates = [];
|
|
258
|
+
groupByColumns = [];
|
|
259
|
+
havingCondition;
|
|
260
|
+
constructor(queryService) {
|
|
261
|
+
this.queryService = queryService;
|
|
262
|
+
}
|
|
263
|
+
min(column, alias) {
|
|
264
|
+
this.aggregates.push(`min:${column}->${alias}`);
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
max(column, alias) {
|
|
268
|
+
this.aggregates.push(`max:${column}->${alias}`);
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
avg(column, alias) {
|
|
272
|
+
this.aggregates.push(`avg:${column}->${alias}`);
|
|
273
|
+
return this;
|
|
274
|
+
}
|
|
275
|
+
sum(column, alias) {
|
|
276
|
+
this.aggregates.push(`sum:${column}->${alias}`);
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
count(column, alias) {
|
|
280
|
+
this.aggregates.push(`count:${column}->${alias}`);
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
groupBy(columns) {
|
|
284
|
+
this.groupByColumns = columns;
|
|
285
|
+
return this;
|
|
286
|
+
}
|
|
287
|
+
having(condition) {
|
|
288
|
+
this.havingCondition = condition;
|
|
289
|
+
return this;
|
|
290
|
+
}
|
|
291
|
+
execute() {
|
|
292
|
+
if (this.aggregates.length === 0) {
|
|
293
|
+
throw new Error('At least one aggregate function must be specified');
|
|
294
|
+
}
|
|
295
|
+
const aggregatesString = this.aggregates.join(',');
|
|
296
|
+
return this.queryService.aggregate$(aggregatesString, this.groupByColumns.length > 0 ? this.groupByColumns : undefined, this.havingCondition);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
// Fonction utilitaire pour appliquer les opérateurs sans spread
|
|
300
|
+
function applyOperators(source, operators) {
|
|
301
|
+
return operators.reduce((obs, op) => op(obs), source);
|
|
302
|
+
}
|
|
303
|
+
class QueryService {
|
|
304
|
+
http;
|
|
305
|
+
realtime;
|
|
306
|
+
config;
|
|
307
|
+
baseUrl;
|
|
308
|
+
schemaName = '';
|
|
309
|
+
tableName = '';
|
|
310
|
+
params = new HttpParams();
|
|
311
|
+
whereStack = [];
|
|
312
|
+
selectFields = new Set();
|
|
313
|
+
includeRelations = new Set();
|
|
314
|
+
orderByFields = [];
|
|
315
|
+
constructor(http, realtime, config) {
|
|
316
|
+
this.http = http;
|
|
317
|
+
this.realtime = realtime;
|
|
318
|
+
this.config = config;
|
|
319
|
+
this.baseUrl = this.resolveModelsBaseUrl();
|
|
320
|
+
}
|
|
321
|
+
resolveModelsBaseUrl() {
|
|
322
|
+
const apiUrl = this.config?.serverApiUrl ?? '';
|
|
323
|
+
if (!apiUrl) {
|
|
324
|
+
return '/db/models';
|
|
325
|
+
}
|
|
326
|
+
const trimmed = apiUrl.replace(/\/+$/, '');
|
|
327
|
+
const base = trimmed.endsWith('/api') ? trimmed.slice(0, -4) : trimmed;
|
|
328
|
+
return `${base}/db/models`;
|
|
329
|
+
}
|
|
330
|
+
// Créer une copie de l'état actuel du service
|
|
331
|
+
clone() {
|
|
332
|
+
const clone = new QueryService(this.http, this.realtime, this.config);
|
|
333
|
+
clone.schemaName = this.schemaName;
|
|
334
|
+
clone.tableName = this.tableName;
|
|
335
|
+
clone.params = new HttpParams({ fromString: this.params.toString() });
|
|
336
|
+
clone.whereStack = JSON.parse(JSON.stringify(this.whereStack));
|
|
337
|
+
clone.selectFields = new Set(this.selectFields);
|
|
338
|
+
clone.includeRelations = new Set(this.includeRelations);
|
|
339
|
+
clone.orderByFields = [...this.orderByFields];
|
|
340
|
+
return clone;
|
|
341
|
+
}
|
|
342
|
+
from(schemaTable) {
|
|
343
|
+
const [schema, table] = schemaTable.split('.');
|
|
344
|
+
if (!schema || !table) {
|
|
345
|
+
throw new Error('Invalid format. Use "schema.table" in from() method.');
|
|
346
|
+
}
|
|
347
|
+
this.schemaName = schema;
|
|
348
|
+
this.tableName = table;
|
|
349
|
+
this.params = new HttpParams();
|
|
350
|
+
this.whereStack = [];
|
|
351
|
+
this.selectFields = new Set();
|
|
352
|
+
this.includeRelations = new Set();
|
|
353
|
+
this.orderByFields = [];
|
|
354
|
+
return this;
|
|
355
|
+
}
|
|
356
|
+
on(events, callback) {
|
|
357
|
+
if (!this.schemaName || !this.tableName) {
|
|
358
|
+
throw new Error('Appelle from("schema.table") avant on().');
|
|
359
|
+
}
|
|
360
|
+
if (!this.realtime) {
|
|
361
|
+
throw new Error('RealtimeService non injecté dans QueryService.');
|
|
362
|
+
}
|
|
363
|
+
const table = `${this.schemaName}.${this.tableName}`;
|
|
364
|
+
const channel = this.realtime.channel('watcher_io', { table });
|
|
365
|
+
const acceptedEvents = ['INSERT', 'UPDATE', 'DELETE'];
|
|
366
|
+
let eventList = [];
|
|
367
|
+
if (typeof events === 'string') {
|
|
368
|
+
if (events === '*') {
|
|
369
|
+
eventList = acceptedEvents;
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
eventList = events.split(',').map(e => e.trim().toUpperCase());
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
else if (Array.isArray(events)) {
|
|
376
|
+
eventList = events.map(e => e.toUpperCase());
|
|
377
|
+
}
|
|
378
|
+
channel.on('postgres_changes', (message) => {
|
|
379
|
+
if (eventList.includes(message.operation)) {
|
|
380
|
+
callback(message);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
select(...fields) {
|
|
386
|
+
fields.forEach(field => this.selectFields.add(field));
|
|
387
|
+
return this;
|
|
388
|
+
}
|
|
389
|
+
limit(limit) {
|
|
390
|
+
this.params = this.params.set('limit', limit.toString());
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
offset(offset) {
|
|
394
|
+
this.params = this.params.set('offset', offset.toString());
|
|
395
|
+
return this;
|
|
396
|
+
}
|
|
397
|
+
where(field, operator, value) {
|
|
398
|
+
this.whereStack.push({ field, operator, value });
|
|
399
|
+
return this;
|
|
400
|
+
}
|
|
401
|
+
and(...conditions) {
|
|
402
|
+
this.whereStack.push({ operator: 'and', conditions });
|
|
403
|
+
return this;
|
|
404
|
+
}
|
|
405
|
+
or(...conditions) {
|
|
406
|
+
this.whereStack.push({ operator: 'or', conditions });
|
|
407
|
+
return this;
|
|
408
|
+
}
|
|
409
|
+
include(...relations) {
|
|
410
|
+
relations.forEach(relation => this.includeRelations.add(relation));
|
|
411
|
+
return this;
|
|
412
|
+
}
|
|
413
|
+
orderBy(field, direction = 'asc') {
|
|
414
|
+
this.orderByFields.push({ field, direction });
|
|
415
|
+
return this;
|
|
416
|
+
}
|
|
417
|
+
// Effacer les ordres de tri existants
|
|
418
|
+
clearOrderBy() {
|
|
419
|
+
this.orderByFields = [];
|
|
420
|
+
return this;
|
|
421
|
+
}
|
|
422
|
+
// Effacer les champs de sélection existants
|
|
423
|
+
clearSelect() {
|
|
424
|
+
this.selectFields.clear();
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
// Effacer les relations incluses existantes
|
|
428
|
+
clearInclude() {
|
|
429
|
+
this.includeRelations.clear();
|
|
430
|
+
return this;
|
|
431
|
+
}
|
|
432
|
+
// Effacer les conditions where existantes
|
|
433
|
+
clearWhere() {
|
|
434
|
+
this.whereStack = [];
|
|
435
|
+
return this;
|
|
436
|
+
}
|
|
437
|
+
// FIX: Amélioration de la gestion des valeurs null et undefined
|
|
438
|
+
buildWhereString() {
|
|
439
|
+
const build = (conditions) => {
|
|
440
|
+
return conditions
|
|
441
|
+
.map((condition) => {
|
|
442
|
+
if ('conditions' in condition) {
|
|
443
|
+
return `${condition.operator}(${build(condition.conditions)})`;
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
let value = condition.value;
|
|
447
|
+
// Gestion des valeurs null/undefined
|
|
448
|
+
if (value === null || value === undefined) {
|
|
449
|
+
value = 'null';
|
|
450
|
+
}
|
|
451
|
+
else if (Array.isArray(value)) {
|
|
452
|
+
// Pour les opérateurs in, notIn, etc.
|
|
453
|
+
value = value.join('|');
|
|
454
|
+
}
|
|
455
|
+
else if (typeof value === 'string') {
|
|
456
|
+
// Échapper les valeurs string si nécessaire
|
|
457
|
+
value = value;
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
// Convertir les autres types en string
|
|
461
|
+
value = String(value);
|
|
462
|
+
}
|
|
463
|
+
return `${condition.field}.${condition.operator}.${value}`;
|
|
464
|
+
}
|
|
465
|
+
})
|
|
466
|
+
.join('&');
|
|
467
|
+
};
|
|
468
|
+
return build(this.whereStack);
|
|
469
|
+
}
|
|
470
|
+
prepareRequest() {
|
|
471
|
+
if (!this.schemaName || !this.tableName) {
|
|
472
|
+
throw new Error('Schema and table name must be defined. Use from("schema.table") to specify them.');
|
|
473
|
+
}
|
|
474
|
+
// Créer un nouvel objet HttpParams à partir du contenu actuel
|
|
475
|
+
let params = new HttpParams({ fromString: this.params.toString() });
|
|
476
|
+
// Ajout des champs sélectionnés
|
|
477
|
+
if (this.selectFields.size > 0) {
|
|
478
|
+
params = params.set('select', Array.from(this.selectFields).join(','));
|
|
479
|
+
}
|
|
480
|
+
// Ajout des relations incluses
|
|
481
|
+
if (this.includeRelations.size > 0) {
|
|
482
|
+
params = params.set('include', Array.from(this.includeRelations).join(','));
|
|
483
|
+
}
|
|
484
|
+
// Ajout des tris
|
|
485
|
+
if (this.orderByFields.length > 0) {
|
|
486
|
+
const orderValue = this.orderByFields
|
|
487
|
+
.map(order => `${order.field}.${order.direction}`)
|
|
488
|
+
.join(',');
|
|
489
|
+
params = params.set('order', orderValue);
|
|
490
|
+
}
|
|
491
|
+
// Ajout des conditions where
|
|
492
|
+
if (this.whereStack.length > 0) {
|
|
493
|
+
const whereString = this.buildWhereString();
|
|
494
|
+
params = params.set('where', whereString);
|
|
495
|
+
}
|
|
496
|
+
const url = `${this.baseUrl}/${this.schemaName}/${this.tableName}`;
|
|
497
|
+
return this.http.get(url, { params });
|
|
498
|
+
}
|
|
499
|
+
// Obtenir une requête pour un seul élément
|
|
500
|
+
findOne() {
|
|
501
|
+
return new Observable(subscriber => {
|
|
502
|
+
this.limit(1).prepareRequest().subscribe({
|
|
503
|
+
next: (results) => {
|
|
504
|
+
subscriber.next(results.length > 0 ? results[0] : null);
|
|
505
|
+
subscriber.complete();
|
|
506
|
+
},
|
|
507
|
+
error: (err) => subscriber.error(err)
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
// FIX: Utilisation de la nouvelle route /count
|
|
512
|
+
count() {
|
|
513
|
+
if (!this.schemaName || !this.tableName) {
|
|
514
|
+
throw new Error('Schema and table name must be defined. Use from("schema.table") to specify them.');
|
|
515
|
+
}
|
|
516
|
+
let params = new HttpParams();
|
|
517
|
+
// Ajout des conditions where pour le count
|
|
518
|
+
if (this.whereStack.length > 0) {
|
|
519
|
+
const whereString = this.buildWhereString();
|
|
520
|
+
params = params.set('where', whereString);
|
|
521
|
+
}
|
|
522
|
+
const url = `${this.baseUrl}/${this.schemaName}/${this.tableName}/count`;
|
|
523
|
+
return new Observable(subscriber => {
|
|
524
|
+
this.http.get(url, { params }).subscribe({
|
|
525
|
+
next: (result) => {
|
|
526
|
+
subscriber.next(result.count);
|
|
527
|
+
subscriber.complete();
|
|
528
|
+
},
|
|
529
|
+
error: (err) => subscriber.error(err)
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
asObservable() {
|
|
534
|
+
return this.prepareRequest();
|
|
535
|
+
}
|
|
536
|
+
// FIX: Passer le RealtimeService au nouveau service
|
|
537
|
+
pipe(operations) {
|
|
538
|
+
const observable = applyOperators(this.prepareRequest(), operations);
|
|
539
|
+
// Création d'une nouvelle instance avec le type R et le RealtimeService
|
|
540
|
+
const newService = new QueryService(this.http, this.realtime, this.config);
|
|
541
|
+
// Copie des propriétés existantes
|
|
542
|
+
newService.schemaName = this.schemaName;
|
|
543
|
+
newService.tableName = this.tableName;
|
|
544
|
+
newService.params = this.params;
|
|
545
|
+
newService.whereStack = this.whereStack;
|
|
546
|
+
newService.selectFields = this.selectFields;
|
|
547
|
+
newService.includeRelations = this.includeRelations;
|
|
548
|
+
newService.orderByFields = this.orderByFields;
|
|
549
|
+
// Surcharge des méthodes nécessaires
|
|
550
|
+
Object.defineProperties(newService, {
|
|
551
|
+
asObservable: {
|
|
552
|
+
value: () => observable,
|
|
553
|
+
writable: true
|
|
554
|
+
},
|
|
555
|
+
subscribe: {
|
|
556
|
+
value: (callback) => observable.subscribe({
|
|
557
|
+
next: callback.next,
|
|
558
|
+
error: callback.error || ((err) => console.error('Error:', err)),
|
|
559
|
+
complete: callback.complete || (() => { })
|
|
560
|
+
}),
|
|
561
|
+
writable: true
|
|
562
|
+
},
|
|
563
|
+
forEach: {
|
|
564
|
+
value: (fn) => observable.forEach(fn),
|
|
565
|
+
writable: true
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
return newService;
|
|
569
|
+
}
|
|
570
|
+
forEach(fn) {
|
|
571
|
+
this.prepareRequest().forEach(fn);
|
|
572
|
+
}
|
|
573
|
+
subscribe(callback) {
|
|
574
|
+
this.prepareRequest().subscribe({
|
|
575
|
+
next: callback.next,
|
|
576
|
+
error: callback.error || ((err) => console.error('Error:', err)),
|
|
577
|
+
complete: callback.complete || (() => { }),
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
// Méthode pour exécuter et obtenir le premier résultat
|
|
581
|
+
first() {
|
|
582
|
+
return new Observable(subscriber => {
|
|
583
|
+
this.limit(1).prepareRequest().subscribe({
|
|
584
|
+
next: (results) => {
|
|
585
|
+
subscriber.next(results[0]);
|
|
586
|
+
subscriber.complete();
|
|
587
|
+
},
|
|
588
|
+
error: (err) => subscriber.error(err)
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
insert(data) {
|
|
593
|
+
if (!this.schemaName || !this.tableName) {
|
|
594
|
+
throw new Error('Schema and table name must be defined. Use from("schema.table") to specify them.');
|
|
595
|
+
}
|
|
596
|
+
const url = `${this.baseUrl}/${this.schemaName}/${this.tableName}`;
|
|
597
|
+
return this.http.post(url, data);
|
|
598
|
+
}
|
|
599
|
+
// Méthode pour l'insertion en batch
|
|
600
|
+
insertMany(dataArray) {
|
|
601
|
+
if (!this.schemaName || !this.tableName) {
|
|
602
|
+
throw new Error('Schema and table name must be defined. Use from("schema.table") to specify them.');
|
|
603
|
+
}
|
|
604
|
+
const url = `${this.baseUrl}/${this.schemaName}/${this.tableName}/batch`;
|
|
605
|
+
return this.http.post(url, dataArray);
|
|
606
|
+
}
|
|
607
|
+
update(id, data) {
|
|
608
|
+
if (!this.schemaName || !this.tableName) {
|
|
609
|
+
throw new Error('Schema and table name must be defined. Use from("schema.table") to specify them.');
|
|
610
|
+
}
|
|
611
|
+
const url = `${this.baseUrl}/${this.schemaName}/${this.tableName}/${id}`;
|
|
612
|
+
return this.http.put(url, data);
|
|
613
|
+
}
|
|
614
|
+
// Mise à jour partielle avec PATCH (upsert)
|
|
615
|
+
patch(id, data) {
|
|
616
|
+
if (!this.schemaName || !this.tableName) {
|
|
617
|
+
throw new Error('Schema and table name must be defined. Use from("schema.table") to specify them.');
|
|
618
|
+
}
|
|
619
|
+
const url = `${this.baseUrl}/${this.schemaName}/${this.tableName}/${id}`;
|
|
620
|
+
return this.http.patch(url, data);
|
|
621
|
+
}
|
|
622
|
+
// Mise à jour en batch selon une condition
|
|
623
|
+
updateWhere(data) {
|
|
624
|
+
if (!this.schemaName || !this.tableName) {
|
|
625
|
+
throw new Error('Schema and table name must be defined. Use from("schema.table") to specify them.');
|
|
626
|
+
}
|
|
627
|
+
if (this.whereStack.length === 0) {
|
|
628
|
+
throw new Error('Where conditions must be specified for updateWhere operation.');
|
|
629
|
+
}
|
|
630
|
+
const whereString = this.buildWhereString();
|
|
631
|
+
const params = new HttpParams().set('where', whereString);
|
|
632
|
+
const url = `${this.baseUrl}/${this.schemaName}/${this.tableName}`;
|
|
633
|
+
return this.http.put(url, data, { params });
|
|
634
|
+
}
|
|
635
|
+
upsert(data) {
|
|
636
|
+
if (!this.schemaName || !this.tableName) {
|
|
637
|
+
throw new Error('Schema and table name must be defined. Use from("schema.table") to specify them.');
|
|
638
|
+
}
|
|
639
|
+
const url = `${this.baseUrl}/${this.schemaName}/${this.tableName}`;
|
|
640
|
+
return this.http.patch(url, data);
|
|
641
|
+
}
|
|
642
|
+
delete(id) {
|
|
643
|
+
if (!this.schemaName || !this.tableName) {
|
|
644
|
+
throw new Error('Schema and table name must be defined. Use from("schema.table") to specify them.');
|
|
645
|
+
}
|
|
646
|
+
const url = `${this.baseUrl}/${this.schemaName}/${this.tableName}/${id}`;
|
|
647
|
+
return this.http.delete(url);
|
|
648
|
+
}
|
|
649
|
+
deleteWhere() {
|
|
650
|
+
if (!this.schemaName || !this.tableName) {
|
|
651
|
+
throw new Error('Schema and table name must be defined. Use from("schema.table") to specify them.');
|
|
652
|
+
}
|
|
653
|
+
if (this.whereStack.length === 0) {
|
|
654
|
+
throw new Error('Where conditions must be specified for deleteWhere operation.');
|
|
655
|
+
}
|
|
656
|
+
const whereString = this.buildWhereString();
|
|
657
|
+
const params = new HttpParams().set('where', whereString);
|
|
658
|
+
const url = `${this.baseUrl}/${this.schemaName}/${this.tableName}`;
|
|
659
|
+
return this.http.delete(url, { params });
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Exécute des fonctions d'agrégation SQL (MIN, MAX, AVG, SUM, COUNT)
|
|
663
|
+
*
|
|
664
|
+
* @param aggregates - Chaîne d'agrégations au format "function:column->alias" séparées par virgule
|
|
665
|
+
* Exemples:
|
|
666
|
+
* - "min:date->min_date,max:date->max_date"
|
|
667
|
+
* - "sum:amount->total,count:*->count,avg:amount->average"
|
|
668
|
+
*
|
|
669
|
+
* @param groupBy - (Optionnel) Colonnes pour GROUP BY
|
|
670
|
+
* Exemple: ['user_id', 'status']
|
|
671
|
+
*
|
|
672
|
+
* @param having - (Optionnel) Condition HAVING (utiliser les alias définis dans aggregates)
|
|
673
|
+
* Exemple: "total > 1000"
|
|
674
|
+
*
|
|
675
|
+
* @returns Observable<T> - Sans GROUP BY: retourne un objet unique
|
|
676
|
+
* Avec GROUP BY: retourne un tableau d'objets
|
|
677
|
+
*/
|
|
678
|
+
aggregate$(aggregates, groupBy, having) {
|
|
679
|
+
if (!this.schemaName || !this.tableName) {
|
|
680
|
+
throw new Error('Schema and table name must be defined. Use from("schema.table") to specify them.');
|
|
681
|
+
}
|
|
682
|
+
// Validation du format des agrégations
|
|
683
|
+
this.validateAggregates(aggregates);
|
|
684
|
+
// Créer les paramètres HTTP
|
|
685
|
+
let params = new HttpParams().set('aggregates', aggregates);
|
|
686
|
+
// Ajouter les conditions WHERE existantes
|
|
687
|
+
if (this.whereStack.length > 0) {
|
|
688
|
+
const whereString = this.buildWhereString();
|
|
689
|
+
params = params.set('where', whereString);
|
|
690
|
+
}
|
|
691
|
+
// Ajouter GROUP BY
|
|
692
|
+
if (groupBy && groupBy.length > 0) {
|
|
693
|
+
params = params.set('groupBy', groupBy.join(','));
|
|
694
|
+
}
|
|
695
|
+
// Ajouter HAVING
|
|
696
|
+
if (having) {
|
|
697
|
+
params = params.set('having', having);
|
|
698
|
+
}
|
|
699
|
+
// Ajouter ORDER BY si défini
|
|
700
|
+
if (this.orderByFields.length > 0) {
|
|
701
|
+
const orderValue = this.orderByFields
|
|
702
|
+
.map(order => `${order.field}.${order.direction}`)
|
|
703
|
+
.join(',');
|
|
704
|
+
params = params.set('order', orderValue);
|
|
705
|
+
}
|
|
706
|
+
// Ajouter LIMIT si défini
|
|
707
|
+
const limitParam = this.params.get('limit');
|
|
708
|
+
if (limitParam) {
|
|
709
|
+
params = params.set('limit', limitParam);
|
|
710
|
+
}
|
|
711
|
+
// Ajouter OFFSET si défini
|
|
712
|
+
const offsetParam = this.params.get('offset');
|
|
713
|
+
if (offsetParam) {
|
|
714
|
+
params = params.set('offset', offsetParam);
|
|
715
|
+
}
|
|
716
|
+
// Construire l'URL
|
|
717
|
+
const url = `${this.baseUrl}/${this.schemaName}/${this.tableName}/aggregate`;
|
|
718
|
+
// Exécuter la requête
|
|
719
|
+
return this.http.get(url, { params });
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Valide le format de la chaîne d'agrégations
|
|
723
|
+
* @private
|
|
724
|
+
*/
|
|
725
|
+
validateAggregates(aggregates) {
|
|
726
|
+
if (!aggregates || aggregates.trim() === '') {
|
|
727
|
+
throw new Error('Aggregates parameter cannot be empty');
|
|
728
|
+
}
|
|
729
|
+
const allowedFunctions = ['min', 'max', 'avg', 'sum', 'count'];
|
|
730
|
+
const aggregateList = aggregates.split(',');
|
|
731
|
+
for (const agg of aggregateList) {
|
|
732
|
+
const trimmed = agg.trim();
|
|
733
|
+
// Vérifier le format function:column->alias
|
|
734
|
+
if (!trimmed.includes(':') || !trimmed.includes('->')) {
|
|
735
|
+
throw new Error(`Invalid aggregate format: '${trimmed}'. Use 'function:column->alias'`);
|
|
736
|
+
}
|
|
737
|
+
const [funcCol, alias] = trimmed.split('->');
|
|
738
|
+
const [func, column] = funcCol.split(':');
|
|
739
|
+
if (!func || !column || !alias) {
|
|
740
|
+
throw new Error(`Invalid aggregate format: '${trimmed}'. Use 'function:column->alias'`);
|
|
741
|
+
}
|
|
742
|
+
// Vérifier que la fonction est valide
|
|
743
|
+
if (!allowedFunctions.includes(func.trim().toLowerCase())) {
|
|
744
|
+
throw new Error(`Invalid aggregate function '${func}'. Allowed: ${allowedFunctions.join(', ')}`);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Exécute des agrégations avec un builder fluide
|
|
750
|
+
*/
|
|
751
|
+
aggregateBuilder() {
|
|
752
|
+
return new AggregateBuilder(this);
|
|
753
|
+
}
|
|
754
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: QueryService, deps: [{ token: i1.HttpClient }, { token: RealtimeService, optional: true }, { token: CADRICIEL_CORE_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
755
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: QueryService, providedIn: 'root' });
|
|
756
|
+
}
|
|
757
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: QueryService, decorators: [{
|
|
758
|
+
type: Injectable,
|
|
759
|
+
args: [{
|
|
760
|
+
providedIn: 'root',
|
|
761
|
+
}]
|
|
762
|
+
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: RealtimeService, decorators: [{
|
|
763
|
+
type: Optional
|
|
764
|
+
}] }, { type: undefined, decorators: [{
|
|
765
|
+
type: Optional
|
|
766
|
+
}, {
|
|
767
|
+
type: Inject,
|
|
768
|
+
args: [CADRICIEL_CORE_CONFIG]
|
|
769
|
+
}] }] });
|
|
770
|
+
|
|
771
|
+
class WsService {
|
|
772
|
+
http;
|
|
773
|
+
applicationConfigService;
|
|
774
|
+
baseUrl = '';
|
|
775
|
+
constructor(http, applicationConfigService) {
|
|
776
|
+
this.http = http;
|
|
777
|
+
this.applicationConfigService = applicationConfigService;
|
|
778
|
+
}
|
|
779
|
+
// Initialise le service avec une URL de base
|
|
780
|
+
setBaseUrl(url) {
|
|
781
|
+
if (!url) {
|
|
782
|
+
this.baseUrl = this.applicationConfigService.getEndpointFor('/');
|
|
783
|
+
return this;
|
|
784
|
+
}
|
|
785
|
+
if (/^https?:\/\//i.test(url)) {
|
|
786
|
+
this.baseUrl = url;
|
|
787
|
+
return this;
|
|
788
|
+
}
|
|
789
|
+
if (url?.substring(0, 1) !== '/')
|
|
790
|
+
url = '/' + url;
|
|
791
|
+
this.baseUrl = this.applicationConfigService.getEndpointFor(url);
|
|
792
|
+
return this;
|
|
793
|
+
}
|
|
794
|
+
// Effectue une requête GET avec des paramètres optionnels
|
|
795
|
+
get(params) {
|
|
796
|
+
return this.http.get(this.baseUrl, { params });
|
|
797
|
+
}
|
|
798
|
+
// get Blob
|
|
799
|
+
blob(params) {
|
|
800
|
+
return this.http.get(this.baseUrl, {
|
|
801
|
+
params,
|
|
802
|
+
responseType: 'blob'
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
downloadWithProgress(params) {
|
|
806
|
+
return this.http.request('GET', this.baseUrl, {
|
|
807
|
+
params,
|
|
808
|
+
responseType: 'blob',
|
|
809
|
+
observe: 'events',
|
|
810
|
+
reportProgress: true
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
buildUrl(params) {
|
|
814
|
+
try {
|
|
815
|
+
const url = new URL(this.baseUrl, window.location.origin);
|
|
816
|
+
if (params && typeof params === 'object') {
|
|
817
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
818
|
+
if (value === undefined || value === null)
|
|
819
|
+
return;
|
|
820
|
+
url.searchParams.append(key, String(value));
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
return url.toString();
|
|
824
|
+
}
|
|
825
|
+
catch (_) {
|
|
826
|
+
return this.baseUrl;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
// Effectue une requête POST avec un corps
|
|
830
|
+
post(body) {
|
|
831
|
+
return this.http.post(this.baseUrl, body);
|
|
832
|
+
}
|
|
833
|
+
// Effectue une requête PUT avec un ID et un objet
|
|
834
|
+
put(id, body) {
|
|
835
|
+
return this.http.put(`${this.baseUrl}/${id}`, body);
|
|
836
|
+
}
|
|
837
|
+
// Effectue une requête PATCH avec un ID et un objet partiel
|
|
838
|
+
patch(id, body) {
|
|
839
|
+
return this.http.patch(`${this.baseUrl}/${id}`, body);
|
|
840
|
+
}
|
|
841
|
+
// Effectue une requête DELETE avec un ID
|
|
842
|
+
delete(target) {
|
|
843
|
+
if (typeof target === 'object' && target !== null) {
|
|
844
|
+
return this.http.delete(this.baseUrl, { params: target });
|
|
845
|
+
}
|
|
846
|
+
return this.http.delete(`${this.baseUrl}/${target}`);
|
|
847
|
+
}
|
|
848
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: WsService, deps: [{ token: i1.HttpClient }, { token: ApplicationConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
849
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: WsService, providedIn: 'root' });
|
|
850
|
+
}
|
|
851
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: WsService, decorators: [{
|
|
852
|
+
type: Injectable,
|
|
853
|
+
args: [{
|
|
854
|
+
providedIn: 'root',
|
|
855
|
+
}]
|
|
856
|
+
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: ApplicationConfigService }] });
|
|
857
|
+
|
|
858
|
+
class MyStorageService {
|
|
859
|
+
getItem(key) {
|
|
860
|
+
return sessionStorage.getItem(key);
|
|
861
|
+
}
|
|
862
|
+
removeItem(key) {
|
|
863
|
+
sessionStorage.removeItem(key);
|
|
864
|
+
}
|
|
865
|
+
setItem(key, data) {
|
|
866
|
+
sessionStorage.setItem(key, data);
|
|
867
|
+
}
|
|
868
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MyStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
869
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MyStorageService });
|
|
870
|
+
}
|
|
871
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MyStorageService, decorators: [{
|
|
872
|
+
type: Injectable
|
|
873
|
+
}] });
|
|
874
|
+
|
|
875
|
+
class MyFilesService {
|
|
876
|
+
ws;
|
|
877
|
+
constructor(ws) {
|
|
878
|
+
this.ws = ws;
|
|
879
|
+
}
|
|
880
|
+
files = {
|
|
881
|
+
list: () => this.ws.setBaseUrl('upload/files').get(),
|
|
882
|
+
save: (id, item) => {
|
|
883
|
+
item.rid = id;
|
|
884
|
+
console.log('->', id);
|
|
885
|
+
return this.ws.setBaseUrl('upload/files').post(item);
|
|
886
|
+
},
|
|
887
|
+
delete: (id) => this.ws.setBaseUrl('oid').delete(id),
|
|
888
|
+
};
|
|
889
|
+
upload = {
|
|
890
|
+
authorize: () => this.ws.setBaseUrl('upload/authorize').get()
|
|
891
|
+
};
|
|
892
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MyFilesService, deps: [{ token: WsService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
893
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MyFilesService, providedIn: 'root' });
|
|
894
|
+
}
|
|
895
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MyFilesService, decorators: [{
|
|
896
|
+
type: Injectable,
|
|
897
|
+
args: [{ providedIn: 'root' }]
|
|
898
|
+
}], ctorParameters: () => [{ type: WsService }] });
|
|
899
|
+
|
|
900
|
+
class CadricielService {
|
|
901
|
+
queryService;
|
|
902
|
+
realtime;
|
|
903
|
+
wservice;
|
|
904
|
+
filesService;
|
|
905
|
+
appConfig;
|
|
906
|
+
http;
|
|
907
|
+
config;
|
|
908
|
+
files;
|
|
909
|
+
upload;
|
|
910
|
+
constructor(queryService, realtime, wservice, filesService, appConfig, http, config) {
|
|
911
|
+
this.queryService = queryService;
|
|
912
|
+
this.realtime = realtime;
|
|
913
|
+
this.wservice = wservice;
|
|
914
|
+
this.filesService = filesService;
|
|
915
|
+
this.appConfig = appConfig;
|
|
916
|
+
this.http = http;
|
|
917
|
+
this.config = config;
|
|
918
|
+
this.files = filesService.files;
|
|
919
|
+
this.upload = filesService.upload;
|
|
920
|
+
}
|
|
921
|
+
from(table) {
|
|
922
|
+
return this.queryService.clone().from(table);
|
|
923
|
+
}
|
|
924
|
+
rpc(functionName, params = {}) {
|
|
925
|
+
if (!functionName || !functionName.trim()) {
|
|
926
|
+
throw new Error('functionName is required');
|
|
927
|
+
}
|
|
928
|
+
const normalizedFunctionName = functionName
|
|
929
|
+
.trim()
|
|
930
|
+
.replace(/^\/?db\/rpc\//i, '')
|
|
931
|
+
.replace(/^\/?rpc\//i, '')
|
|
932
|
+
.replace(/^\//, '');
|
|
933
|
+
if (!normalizedFunctionName) {
|
|
934
|
+
throw new Error('functionName is required');
|
|
935
|
+
}
|
|
936
|
+
const endpoint = `${this.getApiRoot()}/db/rpc/${normalizedFunctionName}`;
|
|
937
|
+
return this.ws(endpoint).post(params ?? {});
|
|
938
|
+
}
|
|
939
|
+
channel(channel, params = {}) {
|
|
940
|
+
return this.realtime.channel(channel, params);
|
|
941
|
+
}
|
|
942
|
+
ws(url) {
|
|
943
|
+
return this.wservice.setBaseUrl(url);
|
|
944
|
+
}
|
|
945
|
+
getApiRoot() {
|
|
946
|
+
const configured = (this.appConfig?.endpointPrefix && this.appConfig.endpointPrefix.trim()) ||
|
|
947
|
+
this.config?.serverApiUrl ||
|
|
948
|
+
'';
|
|
949
|
+
const trimmed = configured.replace(/\/+$/, '');
|
|
950
|
+
if (trimmed.endsWith('/api')) {
|
|
951
|
+
return trimmed.slice(0, -4);
|
|
952
|
+
}
|
|
953
|
+
return trimmed;
|
|
954
|
+
}
|
|
955
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: CadricielService, deps: [{ token: QueryService }, { token: RealtimeService }, { token: WsService }, { token: MyFilesService }, { token: ApplicationConfigService }, { token: i1.HttpClient }, { token: CADRICIEL_CORE_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
956
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: CadricielService, providedIn: 'root' });
|
|
957
|
+
}
|
|
958
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: CadricielService, decorators: [{
|
|
959
|
+
type: Injectable,
|
|
960
|
+
args: [{
|
|
961
|
+
providedIn: 'root',
|
|
962
|
+
}]
|
|
963
|
+
}], ctorParameters: () => [{ type: QueryService }, { type: RealtimeService }, { type: WsService }, { type: MyFilesService }, { type: ApplicationConfigService }, { type: i1.HttpClient }, { type: undefined, decorators: [{
|
|
964
|
+
type: Optional
|
|
965
|
+
}, {
|
|
966
|
+
type: Inject,
|
|
967
|
+
args: [CADRICIEL_CORE_CONFIG]
|
|
968
|
+
}] }] });
|
|
969
|
+
|
|
970
|
+
/**
|
|
971
|
+
* Classe posée sur `<html>` quand le thème sombre est actif.
|
|
972
|
+
* Alignée sur `@poadio/ui-angular` (styles/tokens.scss) : les composants de la
|
|
973
|
+
* bibliothèque ne lisent que `--poad-*`, redéfinies sous `.theme-dark`.
|
|
974
|
+
*/
|
|
975
|
+
const THEME_DARK_CLASS = 'theme-dark';
|
|
976
|
+
const STORAGE_KEY = 'cadriciel-theme';
|
|
977
|
+
const MEDIA_QUERY = '(prefers-color-scheme: dark)';
|
|
978
|
+
/**
|
|
979
|
+
* Source de vérité du thème clair/sombre de l'application.
|
|
980
|
+
*
|
|
981
|
+
* Indépendant du layout : n'importe quel layout, ou aucun, peut l'utiliser.
|
|
982
|
+
* Le choix de l'utilisateur est persisté ; à défaut, la préférence système
|
|
983
|
+
* s'applique et reste suivie tant que le mode vaut `system`.
|
|
984
|
+
*/
|
|
985
|
+
class ThemeService {
|
|
986
|
+
/** Mode demandé : `light`, `dark`, ou `system` (défaut). */
|
|
987
|
+
mode = signal(readStoredMode(), ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
988
|
+
/** Préférence système courante, suivie à chaud. */
|
|
989
|
+
systemPrefersDark = signal(readSystemPrefersDark(), ...(ngDevMode ? [{ debugName: "systemPrefersDark" }] : /* istanbul ignore next */ []));
|
|
990
|
+
/** Thème effectivement appliqué, une fois le mode résolu. */
|
|
991
|
+
isDark = computed(() => this.mode() === 'system' ? this.systemPrefersDark() : this.mode() === 'dark', ...(ngDevMode ? [{ debugName: "isDark" }] : /* istanbul ignore next */ []));
|
|
992
|
+
injector = inject(Injector);
|
|
993
|
+
applied = null;
|
|
994
|
+
constructor() {
|
|
995
|
+
// Appliqué immédiatement pour éviter un flash au démarrage : l'effet ne
|
|
996
|
+
// s'exécuterait qu'au premier cycle de détection de changements.
|
|
997
|
+
this.apply(this.isDark(), false);
|
|
998
|
+
this.watchSystemPreference();
|
|
999
|
+
runInInjectionContext(this.injector, () => {
|
|
1000
|
+
effect(() => {
|
|
1001
|
+
this.apply(this.isDark(), true);
|
|
1002
|
+
});
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Pose le mode par défaut du projet.
|
|
1007
|
+
* Sans effet si l'utilisateur a déjà exprimé un choix (valeur persistée),
|
|
1008
|
+
* afin qu'une configuration projet n'écrase jamais une préférence.
|
|
1009
|
+
*/
|
|
1010
|
+
initialize(defaultMode) {
|
|
1011
|
+
if (!defaultMode || readStoredMode(null) !== null)
|
|
1012
|
+
return;
|
|
1013
|
+
this.mode.set(defaultMode);
|
|
1014
|
+
}
|
|
1015
|
+
/** Fixe le mode et le persiste. */
|
|
1016
|
+
set(mode) {
|
|
1017
|
+
this.mode.set(mode);
|
|
1018
|
+
writeStoredMode(mode);
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Bascule entre clair et sombre.
|
|
1022
|
+
* Depuis `system`, bascule vers l'inverse de ce qui est affiché — le geste
|
|
1023
|
+
* de l'utilisateur produit toujours un changement visible.
|
|
1024
|
+
*/
|
|
1025
|
+
toggle() {
|
|
1026
|
+
this.set(this.isDark() ? 'light' : 'dark');
|
|
1027
|
+
}
|
|
1028
|
+
/** Revient au suivi de la préférence système et oublie le choix persisté. */
|
|
1029
|
+
useSystem() {
|
|
1030
|
+
this.mode.set('system');
|
|
1031
|
+
this.systemPrefersDark.set(readSystemPrefersDark());
|
|
1032
|
+
clearStoredMode();
|
|
1033
|
+
}
|
|
1034
|
+
watchSystemPreference() {
|
|
1035
|
+
const mql = matchMediaSafe();
|
|
1036
|
+
if (!mql)
|
|
1037
|
+
return;
|
|
1038
|
+
const onChange = (event) => this.systemPrefersDark.set(event.matches);
|
|
1039
|
+
if (typeof mql.addEventListener === 'function') {
|
|
1040
|
+
mql.addEventListener('change', onChange);
|
|
1041
|
+
}
|
|
1042
|
+
else if (typeof mql.addListener === 'function') {
|
|
1043
|
+
// Safari < 14
|
|
1044
|
+
mql.addListener(onChange);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
apply(dark, animate) {
|
|
1048
|
+
if (typeof document === 'undefined')
|
|
1049
|
+
return;
|
|
1050
|
+
if (this.applied === dark)
|
|
1051
|
+
return;
|
|
1052
|
+
this.applied = dark;
|
|
1053
|
+
const commit = () => document.documentElement.classList.toggle(THEME_DARK_CLASS, dark);
|
|
1054
|
+
const startViewTransition = document.startViewTransition;
|
|
1055
|
+
if (animate && typeof startViewTransition === 'function' && !prefersReducedMotion()) {
|
|
1056
|
+
try {
|
|
1057
|
+
startViewTransition.call(document, commit);
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
catch {
|
|
1061
|
+
// Repli silencieux : la bascule doit aboutir même si la transition échoue.
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
commit();
|
|
1065
|
+
}
|
|
1066
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: ThemeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1067
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: ThemeService, providedIn: 'root' });
|
|
1068
|
+
}
|
|
1069
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: ThemeService, decorators: [{
|
|
1070
|
+
type: Injectable,
|
|
1071
|
+
args: [{ providedIn: 'root' }]
|
|
1072
|
+
}], ctorParameters: () => [] });
|
|
1073
|
+
function matchMediaSafe() {
|
|
1074
|
+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
|
|
1075
|
+
return null;
|
|
1076
|
+
return window.matchMedia(MEDIA_QUERY);
|
|
1077
|
+
}
|
|
1078
|
+
function readSystemPrefersDark() {
|
|
1079
|
+
return matchMediaSafe()?.matches ?? false;
|
|
1080
|
+
}
|
|
1081
|
+
function prefersReducedMotion() {
|
|
1082
|
+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
|
|
1083
|
+
return false;
|
|
1084
|
+
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
1085
|
+
}
|
|
1086
|
+
function readStoredMode(fallback = 'system') {
|
|
1087
|
+
if (typeof localStorage === 'undefined')
|
|
1088
|
+
return fallback;
|
|
1089
|
+
try {
|
|
1090
|
+
const raw = localStorage.getItem(STORAGE_KEY);
|
|
1091
|
+
return raw === 'light' || raw === 'dark' || raw === 'system' ? raw : fallback;
|
|
1092
|
+
}
|
|
1093
|
+
catch {
|
|
1094
|
+
return fallback;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
function writeStoredMode(mode) {
|
|
1098
|
+
if (typeof localStorage === 'undefined')
|
|
1099
|
+
return;
|
|
1100
|
+
try {
|
|
1101
|
+
localStorage.setItem(STORAGE_KEY, mode);
|
|
1102
|
+
}
|
|
1103
|
+
catch {
|
|
1104
|
+
// Stockage indisponible (mode privé, quota) : le thème reste valable pour la session.
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
function clearStoredMode() {
|
|
1108
|
+
if (typeof localStorage === 'undefined')
|
|
1109
|
+
return;
|
|
1110
|
+
try {
|
|
1111
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
1112
|
+
}
|
|
1113
|
+
catch {
|
|
1114
|
+
// idem
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/** Capacités d'un layout qui ne rend rien d'autre qu'un `<router-outlet>`. */
|
|
1119
|
+
const EMPTY_LAYOUT_CAPABILITIES = { name: 'empty' };
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* Menu de navigation de l'application, partagé par tous les layouts.
|
|
1123
|
+
*
|
|
1124
|
+
* `items` est un signal : un layout qui le lit se met à jour tout seul quand le
|
|
1125
|
+
* menu change. `getMenu()` reste disponible, mais renvoie un instantané — un
|
|
1126
|
+
* layout qui l'appelle une fois à l'initialisation ne verra aucune mise à jour.
|
|
1127
|
+
*/
|
|
1128
|
+
class MenuService {
|
|
1129
|
+
menuItems = signal([], ...(ngDevMode ? [{ debugName: "menuItems" }] : /* istanbul ignore next */ []));
|
|
1130
|
+
/** Menu courant, réactif. À privilégier dans un layout. */
|
|
1131
|
+
items = this.menuItems.asReadonly();
|
|
1132
|
+
/** Instantané du menu courant. Préférer {@link items} pour un rendu réactif. */
|
|
1133
|
+
getMenu() {
|
|
1134
|
+
return this.menuItems();
|
|
1135
|
+
}
|
|
1136
|
+
setMenu(items) {
|
|
1137
|
+
this.menuItems.set(items);
|
|
1138
|
+
}
|
|
1139
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MenuService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1140
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MenuService, providedIn: 'root' });
|
|
1141
|
+
}
|
|
1142
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MenuService, decorators: [{
|
|
1143
|
+
type: Injectable,
|
|
1144
|
+
args: [{
|
|
1145
|
+
providedIn: 'root',
|
|
1146
|
+
}]
|
|
1147
|
+
}] });
|
|
1148
|
+
|
|
1149
|
+
/*
|
|
1150
|
+
* API publique du point d'entrée secondaire @poadio/ui-angular/core (ex-@cadriciel/core 0.2.0)
|
|
1151
|
+
*/
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* Generated bundle index. Do not edit.
|
|
1155
|
+
*/
|
|
1156
|
+
|
|
1157
|
+
export { AggregateBuilder, ApplicationConfigService, CADRICIEL_AUTH_ENV, CADRICIEL_CORE_CONFIG, CadricielService, ChannelController, EMPTY_LAYOUT_CAPABILITIES, MenuService, MyFilesService, MyStorageService, QueryService, RealtimeService, THEME_DARK_CLASS, ThemeService, UserService, WsService };
|
|
1158
|
+
//# sourceMappingURL=poadio-ui-angular-core.mjs.map
|