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