@wizishop/img-manager-webelement 1.0.3 → 14.0.5

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