@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,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 } 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 = Object.assign(Object.assign({}, file), { cdn_img_src: '' });
119
+ if (sendedFile) {
120
+ sendedFile.cdn_img_src = `${environment.CDN_URL}${file.id_shop}/`;
121
+ }
122
+ const value = {
123
+ detail: {
124
+ sendedFile,
125
+ "from": this.emitter
126
+ }
127
+ };
128
+ const event = new CustomEvent('imgSelected', value);
129
+ const imgManagerModule = document.getElementById('imgManagerModule');
130
+ imgManagerModule === null || imgManagerModule === void 0 ? void 0 : imgManagerModule.dispatchEvent(event);
131
+ }
132
+ pageAskForImg() {
133
+ return fromEvent(document.getElementById('imgManagerModule'), "openImgManager");
134
+ }
135
+ setEmitter(emitter) {
136
+ this.emitter = emitter;
137
+ }
138
+ }
139
+ EventService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EventService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
140
+ EventService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EventService });
141
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EventService, decorators: [{
142
+ type: Injectable
143
+ }], ctorParameters: function () { return []; } });
144
+
145
+ class FicheProductService {
146
+ constructor(http, imgSelectionService, eventService, canvaService) {
147
+ this.http = http;
148
+ this.imgSelectionService = imgSelectionService;
149
+ this.eventService = eventService;
150
+ this.canvaService = canvaService;
151
+ this.image_manager_api = environment.wizi_api + "/image-manager/shops/";
152
+ this.isPhotosTab = false; // State of the Photos tabs in fiche product page
153
+ this.isPreviousTabPhotos = false;
154
+ this.isVariantsTab = false;
155
+ this.loadProductImgSelection = false;
156
+ this.expectedMediaDto = {
157
+ id: '',
158
+ image_url: '',
159
+ image_width: '900',
160
+ image_height: '900',
161
+ };
162
+ this.subscriptions = [];
163
+ }
164
+ setApiConfig(shop_id, shop_token) {
165
+ this.shopToken = shop_token;
166
+ this.shopId = shop_id;
167
+ const matches = window.location.pathname.match(/\/(\w+)\/products\/(\d+)\/edit/);
168
+ const lang = matches && matches[1] ? matches[1] : 'fr';
169
+ this.productSheetApiRoute = environment.wizi_admin_api + lang + environment.product_sheet_endpoint;
170
+ this.productId = matches && matches[2] ? matches[2] : "0";
171
+ this.isProductCreation = /\/products\/create/.test(window.location.pathname);
172
+ }
173
+ /**
174
+ * There is only one instance of this img manager.
175
+ * But it is called with different config, by Photos tab and Variation tab, on fiche product page.
176
+ * The method handle the switch config between Photos and Variation tab.
177
+ * Return an observable : true => Photos tab / false => Variation tab.
178
+ * */
179
+ handleTabs() {
180
+ return new Observable(observer => {
181
+ const switchTabsSub = this.switchTabs().subscribe(data => {
182
+ if (!data || !data["detail"] || !data["detail"]["currentTab"]) {
183
+ return;
184
+ }
185
+ // Retrieve current tab
186
+ const currentTab = data["detail"]["currentTab"];
187
+ this.isPreviousTabPhotos = this.isPhotosTab;
188
+ this.isPhotosTab = currentTab === 'photos';
189
+ this.isVariantsTab = currentTab === 'variation';
190
+ // The user switch to Photos tab
191
+ if (this.isPhotosTab) {
192
+ this.loadProductImgSelection = true;
193
+ if (!this.currentProductImgSelection || !this.currentProductImgSelection.length) {
194
+ this.initProductImgSelection();
195
+ }
196
+ else {
197
+ this.applyCurrentImgSelection();
198
+ this.loadProductImgSelection = false;
199
+ }
200
+ }
201
+ else if (this.isPreviousTabPhotos) { // The user switch to another tab
202
+ // Save current img selection, in order to not lose the img selection
203
+ this.saveCurrentImgSelection();
204
+ }
205
+ observer.next(this.isPhotosTab);
206
+ });
207
+ this.subscriptions.push(switchTabsSub);
208
+ });
209
+ }
210
+ getShopImg(idFile) {
211
+ return this.http.get(`${this.image_manager_api}${this.shopId}/images/${idFile}`, this.getOptionsHeadersWithBearer());
212
+ }
213
+ initProductImgSelection() {
214
+ // Display the loader in img list selection
215
+ this.imgSelectionService.emitImgListLoading(true);
216
+ // retrieve img selection
217
+ const retrieveImgSelectionSub = this.retrieveImgSelection().subscribe(data => {
218
+ // No imgage selected
219
+ if (!data || !data["photos"] || !data["photos"]["infos"] || !data["photos"]["infos"]["files"] || !data["photos"]["infos"]["files"].length) {
220
+ this.loadProductImgSelection = false;
221
+ this.imgSelectionService.emitImgListLoading(false);
222
+ return;
223
+ }
224
+ const idImgSelectionList = data["photos"]["infos"]["files"];
225
+ const obsImg = [];
226
+ idImgSelectionList.forEach(idFile => obsImg.push(this.getShopImg(idFile.toString()).pipe(take(1))));
227
+ const allImgSub = forkJoin(obsImg).subscribe((photos) => {
228
+ // The img selection must be saved, otherwise it is lost when the user switch on variation tab
229
+ this.saveCurrentImgSelection(photos);
230
+ this.applyCurrentImgSelection();
231
+ this.loadProductImgSelection = false;
232
+ }, error => {
233
+ // Hide the loader in img list selection
234
+ this.loadProductImgSelection = false;
235
+ this.imgSelectionService.emitImgListLoading(false);
236
+ });
237
+ this.subscriptions.push(allImgSub);
238
+ });
239
+ this.subscriptions.push(retrieveImgSelectionSub);
240
+ this.canvaService.expectedImgSizesChange(this.expectedMediaDto);
241
+ }
242
+ retrieveInfoSelection() {
243
+ const formData = new FormData();
244
+ formData.append('rub', "main");
245
+ formData.append('action', "getInfos");
246
+ formData.append('prodId', this.productId);
247
+ formData.append('_token', '');
248
+ formData.append('_shid', this.shopId.toString());
249
+ return this.http.post(this.productSheetApiRoute, formData, this.getOptionsHeaders());
250
+ }
251
+ retrieveImgSelection() {
252
+ const formData = new FormData();
253
+ formData.append('rub', "main");
254
+ formData.append('action', "getAllInfos");
255
+ formData.append('prodId', this.productId);
256
+ formData.append('_token', '');
257
+ formData.append('_shid', this.shopId.toString());
258
+ return this.http.post(this.productSheetApiRoute, formData, this.getOptionsHeaders());
259
+ }
260
+ updateImgSelectionOnChange() {
261
+ // listen to the img manager change
262
+ const imgSelectionSub = this.imgSelectionService.getImgSelectionChange().subscribe(imgSelectionList => {
263
+ if (!imgSelectionList) {
264
+ return;
265
+ }
266
+ // Send the img selection
267
+ if (this.isPhotosTab && !this.loadProductImgSelection) {
268
+ // Retrieve only the img id
269
+ const idImgSelectedList = [];
270
+ imgSelectionList.forEach(img => {
271
+ idImgSelectedList.push(parseInt(img.id_file));
272
+ });
273
+ this.updateProductImgSelection(idImgSelectedList);
274
+ // On variation tab, send event with img selected
275
+ }
276
+ else if (!this.isPhotosTab && imgSelectionList.length) {
277
+ this.eventService.sendImgSelectedToPage(imgSelectionList[0]);
278
+ }
279
+ });
280
+ this.subscriptions.push(imgSelectionSub);
281
+ }
282
+ updateProductImgSelection(idsImgList) {
283
+ if ((!this.productId || this.productId === "0") && Wizi._produit.global.PROD_ID) {
284
+ this.productId = Wizi._produit.global.PROD_ID.toString();
285
+ }
286
+ Wizi._produit._dataTmp['photos'].infos = {};
287
+ Wizi._produit._dataTmp['photos'].infos.files = idsImgList;
288
+ this.emitImgSelectionChange(idsImgList);
289
+ if (this.productId && this.productId !== "0") {
290
+ const submitProd1 = this.submitProductImg(idsImgList).subscribe();
291
+ this.subscriptions.push(submitProd1);
292
+ return;
293
+ }
294
+ const createProductSub = this.createProduct().subscribe((productId) => {
295
+ if (!productId) {
296
+ throw "No product id created. Can not link image(s) to the new product.";
297
+ }
298
+ Wizi._produit.global.PROD_ID = productId;
299
+ this.productId = productId.toString();
300
+ this.submitProductImg(idsImgList).subscribe();
301
+ });
302
+ this.subscriptions.push(createProductSub);
303
+ }
304
+ submitProductImg(idsImgList) {
305
+ const data = {
306
+ files: idsImgList,
307
+ couls: []
308
+ };
309
+ const formData = new FormData();
310
+ formData.append('rub', "photos");
311
+ formData.append('action', "save");
312
+ formData.append('newProd', this.isProductCreation ? "1" : "0");
313
+ formData.append('prodId', this.productId);
314
+ formData.append('_token', this.shopToken);
315
+ formData.append('_shid', this.shopId.toString());
316
+ formData.append('data', JSON.stringify(data));
317
+ return this.http.post(this.productSheetApiRoute, formData, this.getOptionsHeaders());
318
+ }
319
+ createProduct() {
320
+ const formData = new FormData();
321
+ formData.append('rub', "main");
322
+ formData.append('action', "createProd");
323
+ formData.append('_token', '');
324
+ formData.append('_shid', this.shopId.toString());
325
+ return this.http.post(this.productSheetApiRoute, formData, this.getOptionsHeaders());
326
+ }
327
+ /* Use to know where the img manager is displayed, and to close it when switching tab */
328
+ switchTabs() {
329
+ return fromEvent(document.getElementById('imgManagerModule'), "switchTab");
330
+ }
331
+ emitImgSelectionChange(idsImgList) {
332
+ const value = {
333
+ detail: {
334
+ idsImgList
335
+ }
336
+ };
337
+ const event = new CustomEvent('onImgSelectionChange', value);
338
+ const imgManagerModule = document.getElementById('imgManagerModule');
339
+ imgManagerModule === null || imgManagerModule === void 0 ? void 0 : imgManagerModule.dispatchEvent(event);
340
+ }
341
+ saveCurrentImgSelection(imgSelection) {
342
+ this.currentProductImgSelection = imgSelection ? imgSelection : JSON.parse(JSON.stringify(this.imgSelectionService.getImgSelection()));
343
+ }
344
+ applyCurrentImgSelection() {
345
+ this.imgSelectionService.setImgSelection(this.currentProductImgSelection);
346
+ // Hide the loader in img list selection
347
+ this.imgSelectionService.emitImgListLoading(false);
348
+ }
349
+ getOptionsHeaders() {
350
+ const header = { headers: new HttpHeaders({
351
+ 'Access-Control-Allow-Origin': '*'
352
+ })
353
+ };
354
+ return header;
355
+ }
356
+ getOptionsHeadersWithBearer() {
357
+ const header = { headers: new HttpHeaders({
358
+ Authorization: 'Bearer ' + this.shopToken
359
+ })
360
+ };
361
+ return header;
362
+ }
363
+ ngOnDestroy() {
364
+ this.subscriptions.forEach(subscription => subscription.unsubscribe());
365
+ }
366
+ }
367
+ 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 });
368
+ FicheProductService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: FicheProductService });
369
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: FicheProductService, decorators: [{
370
+ type: Injectable
371
+ }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: i2.ImgSelectionService }, { type: EventService }, { type: i2.CanvaService }]; } });
372
+
373
+ class StorageService {
374
+ constructor() {
375
+ this.subscriptions = new Map();
376
+ window.addEventListener('storage', e => {
377
+ var _a;
378
+ if (this.subscriptions.has(e.key || '')) {
379
+ (_a = this.subscriptions.get(e.key || '')) === null || _a === void 0 ? void 0 : _a.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: i8.WzImgManagerComponent, selector: "wz-img-manager", inputs: ["stateDisplayed", "showSelection", "externalConfig", "forceToOpenCanva", "multipleImgMode", "showImgManagerModule"], 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