@wizishop/img-manager-webelement 15.2.52 → 18.2.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.
Files changed (27) hide show
  1. package/README.md +24 -24
  2. package/{esm2020 → esm2022}/lib/environments/environment.mjs +1 -1
  3. package/esm2022/lib/img-manager-webelement.component.mjs +135 -0
  4. package/esm2022/lib/img-manager-webelement.module.mjs +50 -0
  5. package/{esm2020 → esm2022}/lib/services/auth-credentials.service.mjs +4 -4
  6. package/esm2022/lib/services/event.service.mjs +40 -0
  7. package/esm2022/lib/services/fiche_products.service.mjs +253 -0
  8. package/esm2022/lib/services/webelement-image-manager-api.config.mjs +89 -0
  9. package/{esm2020 → esm2022}/public-api.mjs +1 -1
  10. package/{fesm2020 → fesm2022}/wizishop-img-manager-webelement.mjs +104 -97
  11. package/fesm2022/wizishop-img-manager-webelement.mjs.map +1 -0
  12. package/img-manager-webelement.scss +1 -0
  13. package/lib/img-manager-webelement.component.d.ts +2 -2
  14. package/lib/img-manager-webelement.module.d.ts +0 -3
  15. package/package.json +20 -25
  16. package/esm2020/lib/img-manager-webelement.component.mjs +0 -122
  17. package/esm2020/lib/img-manager-webelement.module.mjs +0 -58
  18. package/esm2020/lib/services/event.service.mjs +0 -37
  19. package/esm2020/lib/services/fiche_products.service.mjs +0 -242
  20. package/esm2020/lib/services/icon-webelement.service.mjs +0 -17
  21. package/esm2020/lib/services/webelement-image-manager-api.config.mjs +0 -88
  22. package/fesm2015/wizishop-img-manager-webelement.mjs +0 -660
  23. package/fesm2015/wizishop-img-manager-webelement.mjs.map +0 -1
  24. package/fesm2020/wizishop-img-manager-webelement.mjs.map +0 -1
  25. package/img-manager-webelement.css +0 -1
  26. package/lib/services/icon-webelement.service.d.ts +0 -6
  27. /package/{esm2020 → esm2022}/wizishop-img-manager-webelement.mjs +0 -0
@@ -1,660 +0,0 @@
1
- import * as i0 from '@angular/core';
2
- import { Injectable, inject, Component, NgModule } from '@angular/core';
3
- import * as i1$1 from '@ngx-translate/core';
4
- import { TranslateModule } from '@ngx-translate/core';
5
- import * as i2 from '@wizishop/img-manager';
6
- import { WzImgManagerModule, ApiService } from '@wizishop/img-manager';
7
- import * as i1 from '@angular/common/http';
8
- import { HttpHeaders, HttpClientModule } from '@angular/common/http';
9
- import { fromEvent, Observable, forkJoin, map, tap } from 'rxjs';
10
- import { take } from 'rxjs/operators';
11
- import { StorageByKey } from '@wizishop/ng-web-storages/shared';
12
- import { LocalStorageService } from '@wizishop/ng-web-storages/local-storage';
13
- import * as i6 from '@angular/common';
14
- import { CommonModule } from '@angular/common';
15
-
16
- // Use locally for this project
17
- const environmentWiziDevLocal = {
18
- isWizishopcom: false,
19
- production: false,
20
- wizi_admin_api: "https://admin.wizilocal.com/",
21
- wizi_api: "https://api.wizilocal.com/v3",
22
- CDN_URL: "http://debugshop.wizilocal.com/_i/",
23
- assets_route: "assets/img-manager/",
24
- translations_route: "./assets/img-manager/i18n/",
25
- wiziApiCredentialsKey: 'wizi_api_credentials_key',
26
- local: {
27
- shopId: 131,
28
- token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo2LCJ1c2VyX2xvY2FsZSI6ImZyX0ZSIiwiaXNVc2VyQ29ubmVjdGVkRnJvbVZwbiI6ZmFsc2UsImV4cCI6MTY3NDM3NDkxMSwiaWF0IjoxNjcxNzgyOTExfQ.DbdBTaVLzLx5pE2FHTg8K0FcMsOY7yg7hAz7bjBQt4afke2ef_MfhXZx9ajtj6BciOsY5eYRgDp3r747iLc7CSThC6cNgPYZ9oMtN3MbFRYi5bktmPUVfbs2oxfWe9sNDwdpgMtw00d8YIO3ZTFZb3XzXW1hQIS2Ooy5x0GTGRgegIDAJYrVyVs8AC3TG8ZaC8g73iSMFnCrG85TAFbgjJb8ccU0HfB-h1I9LPE2LUzI5QE2vbsd6qo1XU59belW1SPv92Wgcd9IiHwuoeO3C2S2rQGUp-L8qprT6f5IeX-rp3XVmOVhTCNM4Dc0FdPdpL6p2jMVhhhu62fOZtNEXA'
29
- },
30
- product_sheet_endpoint: "/products/ajax",
31
- isPhotosTab: true,
32
- pexels_token: '563492ad6f91700001000001e39215727d8b42c1b08498a9ce1e6b94'
33
- };
34
- const environmentWiziDev = {
35
- isWizishopcom: true,
36
- production: false,
37
- wizi_admin_api: "https://admin.wizilocal.com/",
38
- wizi_api: "https://api.wizilocal.com/v3",
39
- CDN_URL: "https://media.wizilocal.com/_i/",
40
- assets_route: "https://js.wizilocal.com/a/libs/img-manager-webelement/assets/img-manager/",
41
- translations_route: "https://js.wizilocal.com/a/libs/img-manager-webelement/assets/img-manager/i18n/",
42
- wiziApiCredentialsKey: 'wizi_api_credentials_key',
43
- local: {
44
- shopId: null,
45
- token: null
46
- },
47
- product_sheet_endpoint: "/products/ajax",
48
- pexels_token: '563492ad6f91700001000001e39215727d8b42c1b08498a9ce1e6b94'
49
- };
50
- const environmentWizishopProd = {
51
- isWizishopcom: true,
52
- production: true,
53
- wizi_admin_api: "https://admin.wizishop.com/",
54
- wizi_api: "https://api.wizishop.com/v3",
55
- CDN_URL: "https://media.cdnws.com/_i/",
56
- assets_route: "https://js.wizishop.com/a/libs/img-manager-webelement/assets/img-manager/",
57
- translations_route: "https://js.wizishop.com/a/libs/img-manager-webelement/assets/img-manager/i18n/",
58
- wiziApiCredentialsKey: 'wizi_api_credentials_key',
59
- local: {
60
- shopId: null,
61
- token: null
62
- },
63
- product_sheet_endpoint: "/products/ajax",
64
- pexels_token: '563492ad6f91700001000001e39215727d8b42c1b08498a9ce1e6b94'
65
- };
66
- const environmentEvolupProd = Object.assign(Object.assign({}, environmentWizishopProd), { pexels_token: 'Q3qRBpJpomRu9AOFc2bOzRPfhIUou2LxZkqYYyKCZm2kGY19DxYdTMpE' });
67
- const environmentDropiziDev = {
68
- isWizishopcom: true,
69
- production: false,
70
- wizi_admin_api: "https://admin.dropilocal.com/",
71
- wizi_api: "https://api.dropilocal.com/v3",
72
- CDN_URL: "https://media.dropilocal.com/_i/",
73
- assets_route: "https://js.dropilocal.fr/a/libs/img-manager-webelement/assets/img-manager/",
74
- translations_route: "https://js.dropilocal.com/a/libs/img-manager-webelement/assets/img-manager/i18n/",
75
- wiziApiCredentialsKey: 'wizi_api_credentials_key',
76
- local: {
77
- shopId: null,
78
- token: null
79
- },
80
- product_sheet_endpoint: "/products/ajax",
81
- pexels_token: 'QWTAGfv4wb14tTP62xxBE2DDnzdGxsBaTr4NXh1te2qDZ9lVPLDSWx0U'
82
- };
83
- const environmentDropiziProd = {
84
- isWizishopcom: true,
85
- production: true,
86
- wizi_admin_api: "https://admin.dropizi.fr/",
87
- wizi_api: "https://api.wizishop.com/v3",
88
- CDN_URL: "https://media.cdnws.com/_i/",
89
- assets_route: "https://js.dropizi.fr/a/libs/img-manager-webelement/assets/img-manager/",
90
- translations_route: "https://js.dropizi.fr/a/libs/img-manager-webelement/assets/img-manager/i18n/",
91
- wiziApiCredentialsKey: 'wizi_api_credentials_key',
92
- local: {
93
- shopId: null,
94
- token: null
95
- },
96
- product_sheet_endpoint: "/products/ajax",
97
- pexels_token: 'QWTAGfv4wb14tTP62xxBE2DDnzdGxsBaTr4NXh1te2qDZ9lVPLDSWx0U'
98
- };
99
- function getCurrentEnv() {
100
- const isDev = !!window.location.hostname.match(/local/);
101
- const isWizi = !!window.location.hostname.match(/wizi/);
102
- const isEvolup = !!window.location.hostname.match(/evolup/);
103
- const serverLocal = !!window.location.port;
104
- if (serverLocal) {
105
- return environmentWiziDevLocal;
106
- }
107
- if (isDev) {
108
- if (isWizi) {
109
- return environmentWiziDev;
110
- }
111
- return environmentDropiziDev;
112
- }
113
- if (isEvolup) {
114
- return environmentEvolupProd;
115
- }
116
- if (isWizi) {
117
- return environmentWizishopProd;
118
- }
119
- return environmentDropiziProd;
120
- }
121
- const environment = Object.assign({}, getCurrentEnv());
122
-
123
- class EventService {
124
- constructor() { }
125
- sendImgSelectedToPage(file) {
126
- const sendedFile = Object.assign(Object.assign({}, file), { cdn_img_src: '' });
127
- if (sendedFile) {
128
- sendedFile.cdn_img_src = `${environment.CDN_URL}${file.id_shop}/`;
129
- }
130
- const value = {
131
- detail: {
132
- "file": sendedFile,
133
- "from": this.emitter
134
- }
135
- };
136
- const event = new CustomEvent('imgSelected', value);
137
- const imgManagerModule = document.getElementById('imgManagerModule');
138
- imgManagerModule === null || imgManagerModule === void 0 ? void 0 : imgManagerModule.dispatchEvent(event);
139
- }
140
- pageAskForImg() {
141
- return fromEvent(document.getElementById('imgManagerModule'), "openImgManager");
142
- }
143
- setEmitter(emitter) {
144
- this.emitter = emitter;
145
- }
146
- }
147
- EventService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: EventService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
148
- EventService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: EventService });
149
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: EventService, decorators: [{
150
- type: Injectable
151
- }], ctorParameters: function () { return []; } });
152
-
153
- class AuthCredentialsService extends StorageByKey {
154
- }
155
- AuthCredentialsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: AuthCredentialsService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
156
- AuthCredentialsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: AuthCredentialsService });
157
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: AuthCredentialsService, decorators: [{
158
- type: Injectable
159
- }] });
160
- const provideAuthCredentialsService = () => ({
161
- provide: AuthCredentialsService,
162
- useFactory: () => new StorageByKey(inject(LocalStorageService), environment.wiziApiCredentialsKey),
163
- });
164
- ;
165
-
166
- class FicheProductService {
167
- constructor(http, imgSelectionService, eventService, canvaService, authCredentialsService) {
168
- this.http = http;
169
- this.imgSelectionService = imgSelectionService;
170
- this.eventService = eventService;
171
- this.canvaService = canvaService;
172
- this.authCredentialsService = authCredentialsService;
173
- this.image_manager_api = environment.wizi_api + "/image-manager/shops/";
174
- this.shopToken = this.authCredentialsService.getSync().data.token;
175
- this.shopId = this.authCredentialsService.getSync().data.shop_id;
176
- this.isPhotosTab = false; // State of the Photos tabs in fiche product page
177
- this.isPreviousTabPhotos = false;
178
- this.isVariantsTab = false;
179
- this.loadProductImgSelection = false;
180
- this.expectedMediaDto = {
181
- id: '',
182
- image_url: '',
183
- image_width: '900',
184
- image_height: '900',
185
- };
186
- this.subscriptions = [];
187
- }
188
- setApiConfig() {
189
- const matches = window.location.pathname.match(/\/(\w+)\/products\/(\d+)\/edit/);
190
- const lang = matches && matches[1] ? matches[1] : 'fr';
191
- this.productSheetApiRoute = environment.wizi_admin_api + lang + environment.product_sheet_endpoint;
192
- this.productId = matches && matches[2] ? matches[2] : "0";
193
- this.isProductCreation = /\/products\/create/.test(window.location.pathname);
194
- }
195
- /**
196
- * There is only one instance of this img manager.
197
- * But it is called with different config, by Photos tab and Variation tab, on fiche product page.
198
- * The method handle the switch config between Photos and Variation tab.
199
- * Return an observable : true => Photos tab / false => Variation tab.
200
- * */
201
- handleTabs() {
202
- return new Observable(observer => {
203
- const switchTabsSub = this.switchTabs().subscribe(data => {
204
- if (!data || !data["detail"] || !data["detail"]["currentTab"]) {
205
- return;
206
- }
207
- // Retrieve current tab
208
- const currentTab = data["detail"]["currentTab"];
209
- this.isPreviousTabPhotos = this.isPhotosTab;
210
- this.isPhotosTab = currentTab === 'photos';
211
- this.isVariantsTab = currentTab === 'variation';
212
- // The user switch to Photos tab
213
- if (this.isPhotosTab) {
214
- this.loadProductImgSelection = true;
215
- if (!this.currentProductImgSelection || !this.currentProductImgSelection.length) {
216
- this.initProductImgSelection();
217
- }
218
- else {
219
- this.applyCurrentImgSelection();
220
- this.loadProductImgSelection = false;
221
- }
222
- }
223
- else if (this.isPreviousTabPhotos) { // The user switch to another tab
224
- // Save current img selection, in order to not lose the img selection
225
- this.saveCurrentImgSelection();
226
- }
227
- observer.next(this.isPhotosTab);
228
- });
229
- this.subscriptions.push(switchTabsSub);
230
- });
231
- }
232
- getShopImg(idFile) {
233
- return this.http.get(`${this.image_manager_api}${this.shopId}/images/${idFile}`, this.getOptionsHeadersWithBearer());
234
- }
235
- initProductImgSelection() {
236
- // Display the loader in img list selection
237
- this.imgSelectionService.imgSelectedListLoading$.next(true);
238
- // retrieve img selection
239
- const retrieveImgSelectionSub = this.retrieveImgSelection().subscribe(data => {
240
- // No image selected
241
- if (!data || !data["photos"] || !data["photos"]["infos"] || !data["photos"]["infos"]["files"] || !data["photos"]["infos"]["files"].length) {
242
- this.loadProductImgSelection = false;
243
- this.imgSelectionService.imgSelectedListLoading$.next(false);
244
- return;
245
- }
246
- const idImgSelectionList = data["photos"]["infos"]["files"];
247
- const obsImg = [];
248
- idImgSelectionList.forEach(idFile => obsImg.push(this.getShopImg(idFile.toString()).pipe(take(1))));
249
- const allImgSub = forkJoin(obsImg).subscribe({
250
- next: (photos) => {
251
- // The img selection must be saved, otherwise it is lost when the user switch on variation tab
252
- this.saveCurrentImgSelection(photos);
253
- this.applyCurrentImgSelection();
254
- this.loadProductImgSelection = false;
255
- },
256
- error: error => {
257
- // Hide the loader in img list selection
258
- this.loadProductImgSelection = false;
259
- this.imgSelectionService.imgSelectedListLoading$.next(false);
260
- }
261
- });
262
- this.subscriptions.push(allImgSub);
263
- });
264
- this.subscriptions.push(retrieveImgSelectionSub);
265
- this.canvaService.expectedImgSizesChange(this.expectedMediaDto);
266
- }
267
- retrieveInfoSelection() {
268
- const formData = new FormData();
269
- formData.append('rub', "main");
270
- formData.append('action', "getInfos");
271
- formData.append('prodId', this.productId);
272
- formData.append('_token', '');
273
- formData.append('_shid', this.shopId.toString());
274
- return this.http.post(this.productSheetApiRoute, formData, this.getOptionsHeaders());
275
- }
276
- retrieveImgSelection() {
277
- const formData = new FormData();
278
- formData.append('rub', "main");
279
- formData.append('action', "getAllInfos");
280
- formData.append('prodId', this.productId);
281
- formData.append('_token', '');
282
- formData.append('_shid', this.shopId.toString());
283
- return this.http.post(this.productSheetApiRoute, formData, this.getOptionsHeaders());
284
- }
285
- updateImgSelectionOnChange() {
286
- // listen to the img manager change
287
- const imgSelectionSub = this.imgSelectionService.imgSelection$.subscribe(imgSelectionList => {
288
- if (!imgSelectionList) {
289
- return;
290
- }
291
- // Send the img selection
292
- if (this.isPhotosTab && !this.loadProductImgSelection) {
293
- // Retrieve only the img id
294
- const idImgSelectedList = [];
295
- imgSelectionList.forEach(img => {
296
- idImgSelectedList.push(parseInt(img.id_file));
297
- });
298
- this.updateProductImgSelection(idImgSelectedList);
299
- // On variation tab, send event with img selected
300
- }
301
- else if (!this.isPhotosTab && imgSelectionList.length) {
302
- this.eventService.sendImgSelectedToPage(imgSelectionList[0]);
303
- }
304
- });
305
- this.subscriptions.push(imgSelectionSub);
306
- }
307
- updateProductImgSelection(idsImgList) {
308
- if ((!this.productId || this.productId === "0") && Wizi._produit.global.PROD_ID) {
309
- this.productId = Wizi._produit.global.PROD_ID.toString();
310
- }
311
- Wizi._produit._dataTmp['photos'].infos = {};
312
- Wizi._produit._dataTmp['photos'].infos.files = idsImgList;
313
- this.emitImgSelectionChange(idsImgList);
314
- if (this.productId && this.productId !== "0") {
315
- const submitProd1 = this.submitProductImg(idsImgList).subscribe();
316
- this.subscriptions.push(submitProd1);
317
- return;
318
- }
319
- const createProductSub = this.createProduct().subscribe((productId) => {
320
- if (!productId) {
321
- throw "No product id created. Can not link image(s) to the new product.";
322
- }
323
- Wizi._produit.global.PROD_ID = productId;
324
- this.productId = productId.toString();
325
- this.submitProductImg(idsImgList).subscribe();
326
- });
327
- this.subscriptions.push(createProductSub);
328
- }
329
- submitProductImg(idsImgList) {
330
- const data = {
331
- files: idsImgList,
332
- couls: []
333
- };
334
- const formData = new FormData();
335
- formData.append('rub', "photos");
336
- formData.append('action', "save");
337
- formData.append('newProd', this.isProductCreation ? "1" : "0");
338
- formData.append('prodId', this.productId);
339
- formData.append('_token', this.shopToken);
340
- formData.append('_shid', this.shopId.toString());
341
- formData.append('data', JSON.stringify(data));
342
- return this.http.post(this.productSheetApiRoute, formData, this.getOptionsHeaders());
343
- }
344
- createProduct() {
345
- const formData = new FormData();
346
- formData.append('rub', "main");
347
- formData.append('action', "createProd");
348
- formData.append('_token', '');
349
- formData.append('_shid', this.shopId.toString());
350
- return this.http.post(this.productSheetApiRoute, formData, this.getOptionsHeaders());
351
- }
352
- /* Use to know where the img manager is displayed, and to close it when switching tab */
353
- switchTabs() {
354
- return fromEvent(document.getElementById('imgManagerModule'), "switchTab");
355
- }
356
- emitImgSelectionChange(idsImgList) {
357
- const value = {
358
- detail: {
359
- idsImgList
360
- }
361
- };
362
- const event = new CustomEvent('onImgSelectionChange', value);
363
- const imgManagerModule = document.getElementById('imgManagerModule');
364
- imgManagerModule === null || imgManagerModule === void 0 ? void 0 : imgManagerModule.dispatchEvent(event);
365
- }
366
- saveCurrentImgSelection(imgSelection) {
367
- this.currentProductImgSelection = imgSelection ? imgSelection : JSON.parse(JSON.stringify(this.imgSelectionService.getImgSelection()));
368
- }
369
- applyCurrentImgSelection() {
370
- this.imgSelectionService.setImgSelection(this.currentProductImgSelection);
371
- // Hide the loader in img list selection
372
- this.imgSelectionService.imgSelectedListLoading$.next(false);
373
- }
374
- getOptionsHeaders() {
375
- const header = { headers: new HttpHeaders({
376
- 'Access-Control-Allow-Origin': '*'
377
- })
378
- };
379
- return header;
380
- }
381
- getOptionsHeadersWithBearer() {
382
- const header = { headers: new HttpHeaders({
383
- Authorization: 'Bearer ' + this.shopToken
384
- })
385
- };
386
- return header;
387
- }
388
- ngOnDestroy() {
389
- this.subscriptions.forEach(subscription => subscription.unsubscribe());
390
- }
391
- }
392
- FicheProductService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: FicheProductService, deps: [{ token: i1.HttpClient }, { token: i2.ImgSelectionService }, { token: EventService }, { token: i2.CanvaService }, { token: AuthCredentialsService }], target: i0.ɵɵFactoryTarget.Injectable });
393
- FicheProductService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: FicheProductService });
394
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: FicheProductService, decorators: [{
395
- type: Injectable
396
- }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: i2.ImgSelectionService }, { type: EventService }, { type: i2.CanvaService }, { type: AuthCredentialsService }]; } });
397
-
398
- class ImgManagerWebElementComponent {
399
- constructor(translateService, canvaService, ficheProductService, authCredentialsService, eventService, imgManagerService, imgSelectionService) {
400
- this.translateService = translateService;
401
- this.canvaService = canvaService;
402
- this.ficheProductService = ficheProductService;
403
- this.authCredentialsService = authCredentialsService;
404
- this.eventService = eventService;
405
- this.imgManagerService = imgManagerService;
406
- this.imgSelectionService = imgSelectionService;
407
- // shop config
408
- this.id_shop = this.authCredentialsService.getSync().data.shop_id;
409
- this.token_shop = this.authCredentialsService.getSync().data.token;
410
- // img manger config
411
- this.openImgManager = false;
412
- this.loading = true;
413
- this.pageFicheProductConfig = this.imgManagerService.getImgManagerDisplayConfig("fiche-product");
414
- this.pageEventConfig = this.imgManagerService.getImgManagerDisplayConfig("wizi-block");
415
- // fiche product config
416
- this.isPhotosTab = !!environment.isPhotosTab;
417
- this.subscriptions = [];
418
- }
419
- ngOnInit() {
420
- this.loading = true;
421
- this.setCurrentLanguage();
422
- // Search on which page is display the img manger
423
- this.setDisplayedPageConfig();
424
- this.loading = false;
425
- this.initVariables(this.authCredentialsService.getSync().data);
426
- // Fiche product page
427
- if (this.imgManagerDisplayConfig.pageficheProduct) {
428
- this.setFicheProductPage();
429
- }
430
- else {
431
- this.setPageWithEvents();
432
- }
433
- }
434
- initVariables(authCredentials) {
435
- if (!authCredentials) {
436
- if (environment.isWizishopcom) {
437
- return;
438
- }
439
- // Run on local Server
440
- this.imgManagerDisplayConfig = this.pageFicheProductConfig;
441
- return;
442
- }
443
- }
444
- setFicheProductPage() {
445
- this.ficheProductService.setApiConfig();
446
- this.handleFicheProductTab(); // Display different img manager config according to the tab
447
- this.closeImgManagerOnSwitchingTab();
448
- this.subscribePageAskForImg(); // Use for images in variations tab
449
- this.ficheProductService.updateImgSelectionOnChange();
450
- }
451
- setPageWithEvents() {
452
- this.subscribePageAskForImg();
453
- // Send img selected
454
- const subImgSelection = this.imgSelectionService.imgSelection$.subscribe(imgSelectionList => {
455
- if (imgSelectionList && imgSelectionList.length) {
456
- this.eventService.sendImgSelectedToPage(imgSelectionList[0]);
457
- }
458
- });
459
- this.subscriptions.push(subImgSelection);
460
- }
461
- subscribePageAskForImg() {
462
- // Listen to page editor ask for img event
463
- const subAskForImg = this.eventService.pageAskForImg().subscribe(data => {
464
- // Retrieve which img manager send the event
465
- const emitter = data && data["detail"] ? data["detail"]["from"] : null;
466
- this.eventService.setEmitter(emitter);
467
- this.imgSelectionService.setImgSelection([]);
468
- this.open();
469
- });
470
- this.subscriptions.push(subAskForImg);
471
- }
472
- open() {
473
- this.openImgManager = true;
474
- }
475
- onImgManagerClosed() {
476
- // Close img manager
477
- this.openImgManager = false;
478
- }
479
- setCurrentLanguage() {
480
- const matches = window.location.pathname.match(/^\/(\w+)\//);
481
- this.translateService.use(matches && matches[1] ? matches[1] : 'fr');
482
- }
483
- setDisplayedPageConfig() {
484
- const isFicheProductPage = /\/products\/(\d+\/edit|create)/.test(window.location.pathname);
485
- this.imgManagerDisplayConfig = isFicheProductPage ? this.pageFicheProductConfig : this.pageEventConfig;
486
- }
487
- handleFicheProductTab() {
488
- const tabsSub = this.ficheProductService.handleTabs().subscribe(isPhotosTab => {
489
- this.imgManagerDisplayConfig = isPhotosTab ? this.pageFicheProductConfig : this.pageEventConfig;
490
- this.isPhotosTab = isPhotosTab;
491
- });
492
- this.subscriptions.push(tabsSub);
493
- }
494
- closeImgManagerOnSwitchingTab() {
495
- const tabsCloseSub = this.ficheProductService.switchTabs().subscribe(data => {
496
- this.openImgManager = false;
497
- });
498
- this.subscriptions.push(tabsCloseSub);
499
- }
500
- ngOnDestroy() {
501
- this.subscriptions.forEach(sub => sub.unsubscribe());
502
- }
503
- }
504
- ImgManagerWebElementComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: ImgManagerWebElementComponent, deps: [{ token: i1$1.TranslateService }, { token: i2.CanvaService }, { token: FicheProductService }, { token: AuthCredentialsService }, { token: EventService }, { token: i2.ImgManagerService }, { token: i2.ImgSelectionService }], target: i0.ɵɵFactoryTarget.Component });
505
- ImgManagerWebElementComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.0.4", type: ImgManagerWebElementComponent, selector: "img-manager-webelement", ngImport: i0, template: "<div class=\"info-bulle\">\n <p class=\"info-bulle-content\" [innerHTML]=\"'ImgManager.webElement.infoBulle' | translate\"></p>\n\n <ng-container *ngIf=\"imgManagerDisplayConfig.pageficheProduct && isPhotosTab\">\n <h3 class=\"wizicss-sous-titre\">{{'ImgManager.webElement.photosTitle' | translate }}</h3>\n </ng-container>\n\n <ng-container *ngIf=\"!loading && id_shop && imgManagerDisplayConfig\">\n\n <p class=\"img-manager-open\" *ngIf=\"imgManagerDisplayConfig.displayBtn && isPhotosTab\">\n <a (click)=\"open()\">{{'ImgManager.webElement.OpenBtn' | translate }}</a>\n </p>\n\n <div class=\"imgManagerBox\">\n <wz-img-manager\n #wzImgManager\n [stateDisplayed]=\"imgManagerDisplayConfig.stateDisplayed\"\n [multipleImgMode]=\"imgManagerDisplayConfig.multipleImgMode\"\n [showImgManagerModule]=\"imgManagerDisplayConfig.showImgManagerModule && openImgManager\"\n [showSelection]=\"imgManagerDisplayConfig.showSelection\"\n (imgManagerClosed)=\"onImgManagerClosed()\">\n </wz-img-manager>\n </div>\n </ng-container>\n</div>", styles: [""], dependencies: [{ kind: "directive", type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2.WzImgManagerComponent, selector: "wz-img-manager", inputs: ["stateDisplayed", "showSelection", "forceToOpenCanva", "multipleImgMode", "showImgManagerModule"], outputs: ["imgManagerClosed", "imgSelectionChange", "imageUploaded"] }, { kind: "pipe", type: i1$1.TranslatePipe, name: "translate" }] });
506
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: ImgManagerWebElementComponent, decorators: [{
507
- type: Component,
508
- args: [{ selector: 'img-manager-webelement', template: "<div class=\"info-bulle\">\n <p class=\"info-bulle-content\" [innerHTML]=\"'ImgManager.webElement.infoBulle' | translate\"></p>\n\n <ng-container *ngIf=\"imgManagerDisplayConfig.pageficheProduct && isPhotosTab\">\n <h3 class=\"wizicss-sous-titre\">{{'ImgManager.webElement.photosTitle' | translate }}</h3>\n </ng-container>\n\n <ng-container *ngIf=\"!loading && id_shop && imgManagerDisplayConfig\">\n\n <p class=\"img-manager-open\" *ngIf=\"imgManagerDisplayConfig.displayBtn && isPhotosTab\">\n <a (click)=\"open()\">{{'ImgManager.webElement.OpenBtn' | translate }}</a>\n </p>\n\n <div class=\"imgManagerBox\">\n <wz-img-manager\n #wzImgManager\n [stateDisplayed]=\"imgManagerDisplayConfig.stateDisplayed\"\n [multipleImgMode]=\"imgManagerDisplayConfig.multipleImgMode\"\n [showImgManagerModule]=\"imgManagerDisplayConfig.showImgManagerModule && openImgManager\"\n [showSelection]=\"imgManagerDisplayConfig.showSelection\"\n (imgManagerClosed)=\"onImgManagerClosed()\">\n </wz-img-manager>\n </div>\n </ng-container>\n</div>" }]
509
- }], ctorParameters: function () { return [{ type: i1$1.TranslateService }, { type: i2.CanvaService }, { type: FicheProductService }, { type: AuthCredentialsService }, { type: EventService }, { type: i2.ImgManagerService }, { type: i2.ImgSelectionService }]; } });
510
-
511
- class WebelementImageManagerApiService {
512
- constructor(http) {
513
- this.http = http;
514
- this.authCredentialsService = inject(AuthCredentialsService);
515
- this.shopId = this.authCredentialsService.getSync().data.shop_id;
516
- this.shopToken = this.authCredentialsService.getSync().data.token;
517
- this.CONFIG = {
518
- image_manager_route: environment.wizi_api + "/image-manager/shops/" + this.shopId,
519
- canva_token: 'wdByHayF5v57nj2ZSLvu055O',
520
- canva_url: 'https://sdk.canva.com/designbutton/v2/api.js',
521
- pexels_token: environment.pexels_token,
522
- pexels_route: 'https://api.pexels.com/v1',
523
- shop_category: 'other',
524
- assets_route: environment.assets_route,
525
- };
526
- this.IMG_SIZE = {
527
- url_raw_image: `${environment.CDN_URL}${this.shopId}/RAW-`,
528
- url_100_image: `${environment.CDN_URL}${this.shopId}/m100-`,
529
- url_200_image: `${environment.CDN_URL}${this.shopId}/cs200-`,
530
- url_400_image: `${environment.CDN_URL}${this.shopId}/cs400-`,
531
- url_800_image: `${environment.CDN_URL}${this.shopId}/cs800-`
532
- };
533
- }
534
- getOptionsHeaders(params) {
535
- const header = { headers: new HttpHeaders({
536
- Authorization: 'Bearer ' + this.shopToken
537
- })
538
- };
539
- if (params) {
540
- header['params'] = params;
541
- }
542
- return header;
543
- }
544
- getShopCategory() {
545
- return 'other';
546
- }
547
- getShopImgList(params) {
548
- return this.http.get(`${this.CONFIG.image_manager_route}/images`, this.getOptionsHeaders(params));
549
- }
550
- getShopTotalImgList(params) {
551
- return this.http.get(`${this.CONFIG.image_manager_route}/total/images`, this.getOptionsHeaders(params)).pipe(map(res => res.totalRecords));
552
- }
553
- getShopImg(idFile) {
554
- return this.http.get(`${this.CONFIG.image_manager_route}/images/${idFile}`, this.getOptionsHeaders());
555
- }
556
- uploadFile(formData) {
557
- return this.http.post(`${this.CONFIG.image_manager_route}/images/template`, formData, this.getOptionsHeaders());
558
- }
559
- uploadFileByUrl(url, fileName) {
560
- return this.http.post(`${this.CONFIG.image_manager_route}/images/template`, { url, fileName }, this.getOptionsHeaders());
561
- }
562
- replaceImg(imageBase64, id_file) {
563
- const body = {
564
- imageBase64,
565
- type: "RAW"
566
- };
567
- return this.http.put(`${this.CONFIG.image_manager_route}/images/${id_file}/replace`, body, this.getOptionsHeaders());
568
- }
569
- changeImgName(fileName, id_file) {
570
- return this.http.put(`${this.CONFIG.image_manager_route}/images/${id_file}?file_name=${fileName}`, null, this.getOptionsHeaders());
571
- }
572
- removeImg(id_file) {
573
- return this.http.delete(`${this.CONFIG.image_manager_route}/images/${id_file}`, this.getOptionsHeaders());
574
- }
575
- removeMultipleImg(id_array) {
576
- return this.http.post(`${this.CONFIG.image_manager_route}/images-multiple-delete`, { id_array }, this.getOptionsHeaders());
577
- }
578
- setShopCategory(shopId) {
579
- return this.http.get(`${environment.wizi_api}/shops/${shopId}`, this.getOptionsHeaders()).pipe(tap((shop => {
580
- if (shop && shop['category']) {
581
- this.CONFIG.shop_category = shop['category'];
582
- }
583
- })));
584
- }
585
- }
586
- WebelementImageManagerApiService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: WebelementImageManagerApiService, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
587
- WebelementImageManagerApiService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: WebelementImageManagerApiService });
588
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: WebelementImageManagerApiService, decorators: [{
589
- type: Injectable
590
- }], ctorParameters: function () { return [{ type: i1.HttpClient }]; } });
591
-
592
- class IconWebelementService {
593
- loadIconLib() {
594
- const link = document.createElement('link');
595
- link.href = 'https://pro.fontawesome.com/releases/v5.12.1/css/all.css';
596
- link.rel = 'stylesheet';
597
- link.crossOrigin = "anonymous";
598
- document.getElementsByTagName('head')[0].appendChild(link);
599
- }
600
- }
601
- IconWebelementService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: IconWebelementService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
602
- IconWebelementService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: IconWebelementService });
603
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: IconWebelementService, decorators: [{
604
- type: Injectable
605
- }] });
606
-
607
- class ImgManagerWebElementModule {
608
- constructor(iconWebelementService) {
609
- this.iconWebelementService = iconWebelementService;
610
- this.iconWebelementService.loadIconLib();
611
- }
612
- }
613
- ImgManagerWebElementModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: ImgManagerWebElementModule, deps: [{ token: IconWebelementService }], target: i0.ɵɵFactoryTarget.NgModule });
614
- ImgManagerWebElementModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.0.4", ngImport: i0, type: ImgManagerWebElementModule, declarations: [ImgManagerWebElementComponent], imports: [CommonModule,
615
- HttpClientModule, i2.WzImgManagerModule, TranslateModule], exports: [ImgManagerWebElementComponent] });
616
- ImgManagerWebElementModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: ImgManagerWebElementModule, providers: [
617
- FicheProductService,
618
- EventService,
619
- provideAuthCredentialsService(),
620
- IconWebelementService
621
- ], imports: [CommonModule,
622
- HttpClientModule,
623
- WzImgManagerModule.withConfig({
624
- provide: ApiService,
625
- useClass: WebelementImageManagerApiService,
626
- }),
627
- TranslateModule] });
628
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: ImgManagerWebElementModule, decorators: [{
629
- type: NgModule,
630
- args: [{
631
- declarations: [ImgManagerWebElementComponent],
632
- imports: [
633
- CommonModule,
634
- HttpClientModule,
635
- WzImgManagerModule.withConfig({
636
- provide: ApiService,
637
- useClass: WebelementImageManagerApiService,
638
- }),
639
- TranslateModule,
640
- ],
641
- exports: [ImgManagerWebElementComponent],
642
- providers: [
643
- FicheProductService,
644
- EventService,
645
- provideAuthCredentialsService(),
646
- IconWebelementService
647
- ]
648
- }]
649
- }], ctorParameters: function () { return [{ type: IconWebelementService }]; } });
650
-
651
- /*
652
- * Public API Surface of img-manager-webelement
653
- */
654
-
655
- /**
656
- * Generated bundle index. Do not edit.
657
- */
658
-
659
- export { ImgManagerWebElementComponent, ImgManagerWebElementModule };
660
- //# sourceMappingURL=wizishop-img-manager-webelement.mjs.map