@wizishop/img-manager 15.2.54 → 15.2.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +393 -393
- package/assets/i18n/it.json +1 -1
- package/esm2020/lib/components/canva-btn/canva-btn.component.mjs +3 -3
- package/esm2020/lib/components/images-view/images-actions-handler.mjs +2 -2
- package/esm2020/lib/components/images-view/images-view.component.mjs +3 -3
- package/esm2020/lib/components/images-view/mosaic-view/img-card/img-card.component.mjs +3 -3
- package/esm2020/lib/components/images-view/mosaic-view/mosaic-view.component.mjs +3 -3
- package/esm2020/lib/components/images-view/table-view/table-view.component.mjs +1 -1
- package/esm2020/lib/components/img-editor/cropper/cropper.component.mjs +3 -3
- package/esm2020/lib/components/img-editor/img-editor.component.mjs +3 -3
- package/esm2020/lib/components/img-editor/info-section/info-section.component.mjs +3 -3
- package/esm2020/lib/components/img-selection/img-selection.component.mjs +3 -3
- package/esm2020/lib/components/img-tabs/img-tabs.component.mjs +3 -3
- package/esm2020/lib/components/img-upload/img-upload.component.mjs +3 -3
- package/esm2020/lib/components/pexels-lib/pexels-lib.component.mjs +3 -3
- package/esm2020/lib/components/shared/alert/alert.component.mjs +1 -1
- package/esm2020/lib/components/shared/pagination/page-selector/page-selector.component.mjs +3 -3
- package/esm2020/lib/components/shared/select/select.component.mjs +3 -3
- package/esm2020/lib/components/upload-list/upload-list.component.mjs +3 -3
- package/esm2020/lib/directives/table/raw.directive.mjs +1 -1
- package/esm2020/lib/dto/config/image-cdn/image-cdn-config.dto.mjs +1 -1
- package/esm2020/lib/dto/config/img-manager.mjs +1 -1
- package/esm2020/lib/dto/img-manager.dto.mjs +1 -1
- package/esm2020/lib/dto/pexels-img.dto.mjs +1 -1
- package/esm2020/lib/pipes/pagination/large-number-of-page/large-number-of-page.pipe.mjs +1 -1
- package/esm2020/lib/services/alert.service.mjs +1 -1
- package/esm2020/lib/services/api.service.mjs +1 -1
- package/esm2020/lib/services/canva.service.mjs +1 -1
- package/esm2020/lib/services/config/img-cdn.service.mjs +1 -1
- package/esm2020/lib/services/dom.service.mjs +1 -1
- package/esm2020/lib/services/icon.service.mjs +1 -1
- package/esm2020/lib/services/image-not-found.service.mjs +1 -1
- package/esm2020/lib/services/img-event.service.mjs +1 -1
- package/esm2020/lib/services/img-manager.service.mjs +1 -1
- package/esm2020/lib/services/img-selection.service.mjs +1 -1
- package/esm2020/lib/services/pexels.service.mjs +1 -1
- package/esm2020/lib/services/rename-picture.service.mjs +1 -1
- package/esm2020/lib/services/snackbar.service.mjs +1 -1
- package/esm2020/lib/services/table/filters-table.service.mjs +1 -1
- package/esm2020/lib/services/upload.service.mjs +1 -1
- package/esm2020/lib/services/user-settings.service.mjs +1 -1
- package/esm2020/lib/wz-img-manager.component.mjs +3 -3
- package/esm2020/lib/wz-img-manager.module.mjs +1 -1
- package/esm2020/public-api.mjs +1 -1
- package/fesm2015/wizishop-img-manager.mjs +31 -31
- package/fesm2015/wizishop-img-manager.mjs.map +1 -1
- package/fesm2020/wizishop-img-manager.mjs +31 -31
- package/fesm2020/wizishop-img-manager.mjs.map +1 -1
- package/package.json +2 -2
- package/wizishop-img-manager-15.2.56.tgz +0 -0
- package/wz-img-manager.scss +1965 -1965
- package/wizishop-img-manager-15.2.54.tgz +0 -0
package/README.md
CHANGED
|
@@ -1,394 +1,394 @@
|
|
|
1
|
-
# Image Manager
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@wizishop/img-manager)
|
|
4
|
-
[](https://www.npmjs.com/package/@wizishop/img-manager)
|
|
5
|
-
|
|
6
|
-
## Install
|
|
7
|
-
|
|
8
|
-
Run:
|
|
9
|
-
|
|
10
|
-
```
|
|
11
|
-
npm install @wizishop/img-manager
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Add Image Manager SCSS in your project
|
|
15
|
-
Add all the following styles in your main scss file.
|
|
16
|
-
|
|
17
|
-
### Required styles
|
|
18
|
-
The required styles must be imported before the image-manager style.
|
|
19
|
-
```
|
|
20
|
-
$img-em-base: 16px!default;
|
|
21
|
-
$img-transition-base-time: 400ms!default;
|
|
22
|
-
|
|
23
|
-
@import '~bourbon/core/bourbon';
|
|
24
|
-
@import '~bulma/bulma';
|
|
25
|
-
@import '~bulma-extensions/bulma-switch/src/sass/index';
|
|
26
|
-
@import '~bulma-extensions/bulma-tooltip/src/sass/index';
|
|
27
|
-
@import '~@wizishop/ng-wizi-bulma/ng-wizi-bulma';
|
|
28
|
-
@import '~sass-flex-mixin/flex';
|
|
29
|
-
@import '@wizishop/img-manager/wz-img-manager';
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### Custom colors
|
|
33
|
-
Optional : The following scss colors variables can be overrided.
|
|
34
|
-
```
|
|
35
|
-
$wizishop-blue: #4baed0!default;
|
|
36
|
-
$img-gray-background: #f5f8fa!default;
|
|
37
|
-
$img-placeholder: #b5b5b5!default;
|
|
38
|
-
$img-red-color: #e74c3c!default;
|
|
39
|
-
$img-dark: #6c6c6c!default;
|
|
40
|
-
$img-really-bad-bad-bad-green: #a2c739!default;
|
|
41
|
-
|
|
42
|
-
$img-amount-hover: 8%!default;
|
|
43
|
-
|
|
44
|
-
$img-main-color: #4baed0!default;
|
|
45
|
-
$img-main-color-hover: darken($img-main-color, $img-amount-hover)!default;
|
|
46
|
-
$img-bleu-color: #4baed0!default;
|
|
47
|
-
|
|
48
|
-
$img-primary-button: $img-main-color!default;
|
|
49
|
-
$img-primary-button-hover: darken($img-primary-button, $img-amount-hover)!default;
|
|
50
|
-
$img-primary-button-desable: #dbdbdb!default;
|
|
51
|
-
|
|
52
|
-
$img-grey-color: #6B7881!default;
|
|
53
|
-
$img-green-color: #2ecc71!default;
|
|
54
|
-
$img-yellow-color: #faa945!default;
|
|
55
|
-
$img-orange-color: #F39C12!default;
|
|
56
|
-
$img-bleu-action: #3498DB!default;
|
|
57
|
-
$img-bright-red-color: #E95656!default;
|
|
58
|
-
$img-second-color: #6B7881!default;
|
|
59
|
-
$img-lightened-secondary: #d8d8d8!default;
|
|
60
|
-
$img-secondary-text: #6c6c6c!default;
|
|
61
|
-
$img-input-border: #dce0e3!default;
|
|
62
|
-
$img-light-white-color: #DCE0E3!default;
|
|
63
|
-
$img-main-text: #23272b!default;
|
|
64
|
-
$img-table-selected: #ddff98!default;
|
|
65
|
-
$img-color-loader: $img-main-color!default;
|
|
66
|
-
$img-color-loader2: $img-really-bad-bad-bad-green!default;
|
|
67
|
-
|
|
68
|
-
// Colors from wizi-admin components (table, sarch-input, pagination, checkbox...)
|
|
69
|
-
$gray-background: #f5f8fa!default;
|
|
70
|
-
$textarea-border-color: #dce0e3!default;
|
|
71
|
-
$main-text: #1d2a3b!default;
|
|
72
|
-
$secondary-color: #526384!default;
|
|
73
|
-
$second-color: #526384!default;
|
|
74
|
-
$border-form: #ccd1e0!default;
|
|
75
|
-
$background-color: #ecf0f1!default;
|
|
76
|
-
$table-background-color: #fafafa!default;
|
|
77
|
-
$input-border-search: #dee2edcc!default;
|
|
78
|
-
$placeholder-color: #b4bdd0!default;
|
|
79
|
-
$input-radio-color: #d8d8d8!default;
|
|
80
|
-
$input-active-color: $wizishop-blue!default;
|
|
81
|
-
$input-radio-color-label: #6b7881!default;
|
|
82
|
-
$input-radio-color-active-label: #1e2e43!default;
|
|
83
|
-
$border-color: #dee2ed!default;
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Add Image manager assets
|
|
87
|
-
In your `angular.json` file add the image manager assets dependency.
|
|
88
|
-
```
|
|
89
|
-
"assets": [
|
|
90
|
-
...
|
|
91
|
-
{
|
|
92
|
-
"glob": "**/*",
|
|
93
|
-
"input": "./node_modules/@wizishop/img-manager/assets/",
|
|
94
|
-
"output": "./assets/img-manager/"
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Add Pro Icons from Font Awesome
|
|
100
|
-
In your `index.html` file add the following balise.
|
|
101
|
-
|
|
102
|
-
```
|
|
103
|
-
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.12.1/css/all.css" crossorigin="anonymous" />
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Add package dependencies
|
|
107
|
-
In your module like `app.module.ts` :
|
|
108
|
-
```
|
|
109
|
-
import { BrowserModule } from '@angular/platform-browser';
|
|
110
|
-
import { NgModule } from '@angular/core';
|
|
111
|
-
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|
112
|
-
import { WzImgManagerModule, ApiService } from '@wizishop/img-manager';
|
|
113
|
-
import { AppComponent } from './app.component';
|
|
114
|
-
import { TranslateModule, TranslateLoader} from '@ngx-translate/core';
|
|
115
|
-
import { HttpClient } from '@angular/common/http';
|
|
116
|
-
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
|
117
|
-
|
|
118
|
-
...
|
|
119
|
-
|
|
120
|
-
export function HttpLoaderFactory(http: HttpClient) {
|
|
121
|
-
return new TranslateHttpLoader(http, './assets/img-manager/i18n/', '.json');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
...
|
|
125
|
-
|
|
126
|
-
@NgModule({
|
|
127
|
-
declarations: [
|
|
128
|
-
AppComponent
|
|
129
|
-
],
|
|
130
|
-
imports: [
|
|
131
|
-
BrowserModule,
|
|
132
|
-
BrowserAnimationsModule,
|
|
133
|
-
WzImgManagerModule.withConfig({
|
|
134
|
-
provide: ApiService,
|
|
135
|
-
useClass: ImageManagerApiService,
|
|
136
|
-
},
|
|
137
|
-
{ // Optional
|
|
138
|
-
provide: ImageNotFoundService,
|
|
139
|
-
useClass: RemoveImageMissingService
|
|
140
|
-
}),
|
|
141
|
-
TranslateModule.forRoot({
|
|
142
|
-
defaultLanguage: 'fr',
|
|
143
|
-
loader: {
|
|
144
|
-
provide: TranslateLoader,
|
|
145
|
-
useFactory: (HttpLoaderFactory),
|
|
146
|
-
deps: [HttpClient]
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
],
|
|
150
|
-
providers: [],
|
|
151
|
-
bootstrap: [AppComponent]
|
|
152
|
-
})
|
|
153
|
-
export class AppModule { }
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### Provide the ApiService
|
|
157
|
-
You must provide the ApiService needed to fetch images, upload new images...
|
|
158
|
-
Your service should extends ApiService from `@wizishop/img-manager` in order to implements all needed properties and methods.
|
|
159
|
-
|
|
160
|
-
Example:
|
|
161
|
-
|
|
162
|
-
```
|
|
163
|
-
@Injectable()
|
|
164
|
-
export class ImageManagerApiService implements ApiService {
|
|
165
|
-
|
|
166
|
-
SHOP_ID_KEY = "shopIdKey";
|
|
167
|
-
SHOP_TOKEN_KEY = "shopTokenKey";
|
|
168
|
-
|
|
169
|
-
get shopId(): number {
|
|
170
|
-
return Number(localStorage.getItem(this.SHOP_ID_KEY)) || 0;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
get shopToken(): string {
|
|
174
|
-
return localStorage.getItem(this.SHOP_TOKEN_KEY) || '';
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
CONFIG = {
|
|
178
|
-
image_manager_route: `https://api.wizilocal.com/v3/image-manager/shops/${this.shopId}`,
|
|
179
|
-
canva_token: 'wdByHayF5v57nj2ZSLvu055O',
|
|
180
|
-
canva_url: 'https://sdk.canva.com/designbutton/v2/api.js',
|
|
181
|
-
pexels_token: '563492ad6f91700001000001e39215727d8b42c1b08498a9ce1e6b94',
|
|
182
|
-
pexels_route: 'https://api.pexels.com/v1',
|
|
183
|
-
assets_route: 'assets/img-manager/'
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
IMG_SIZE = {
|
|
187
|
-
url_raw_image: `https://mepdia.wizilocal.com/_i/${this.shopId}/RAW-`,
|
|
188
|
-
url_100_image: `https://media.wizilocal.com/_i/${this.shopId}/m100-`,
|
|
189
|
-
url_200_image: `https://media.wizilocal.com/_i/${this.shopId}/cs200-`,
|
|
190
|
-
url_400_image: `https://media.wizilocal.com/_i/${this.shopId}/cs400-`,
|
|
191
|
-
url_800_image: `https://media.wizilocal.com/_i/${this.shopId}/cs800-`
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
constructor(private http: HttpClient) {
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
getShopCategory(): string {
|
|
198
|
-
return 'other';
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
private getOptionsHeaders(params?: ParamsImgManagerDTO) {
|
|
202
|
-
const header = { headers: new HttpHeaders({
|
|
203
|
-
Authorization: 'Bearer ' + this.shopToken
|
|
204
|
-
})
|
|
205
|
-
};
|
|
206
|
-
if (params) {
|
|
207
|
-
header['params'] = params
|
|
208
|
-
}
|
|
209
|
-
return header;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
getShopImgList(params?: ParamsImgManagerDTO): Observable<ImgPicturesDTO> {
|
|
213
|
-
return this.http.get<ImgPicturesDTO>(`${this.CONFIG.image_manager_route}/images`, this.getOptionsHeaders(params));
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
getShopTotalImgList(params?: ParamsImgManagerDTO) {
|
|
217
|
-
return this.http.get<{totalRecords: string}>(`${this.CONFIG.image_manager_route}/total/image`, this.getOptionsHeaders(params)).pipe(map(data => Number(data.totalRecords)));
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
getShopImg(idFile: string): Observable<ImgPictureDTO> {
|
|
221
|
-
return this.http.get<ImgPictureDTO>(`${this.CONFIG.image_manager_route}/images/${idFile}`, this.getOptionsHeaders());
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
uploadFile(formData: FormData) {
|
|
225
|
-
return this.http.post<ImgPictureDTO>(`${this.CONFIG.image_manager_route}/images/template`, formData, this.getOptionsHeaders());
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
uploadFileByUrl(url: string, fileName?: string) {
|
|
229
|
-
return this.http.post<ImgPictureDTO>(`${this.CONFIG.image_manager_route}/images/template`, { url, fileName }, this.getOptionsHeaders());
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
replaceImg(imageBase64: string, id_file: string) {
|
|
233
|
-
const body = {
|
|
234
|
-
imageBase64,
|
|
235
|
-
type : "RAW"
|
|
236
|
-
}
|
|
237
|
-
return this.http.put<ImgPictureDTO>(`${this.CONFIG.image_manager_route}/images/${id_file}/replace`, body, this.getOptionsHeaders());
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
changeImgName(fileName: string, id_file: string) {
|
|
241
|
-
return this.http.put<ImgPictureDTO>(`${this.CONFIG.image_manager_route}/images/${id_file}?file_name=${fileName}`, null, this.getOptionsHeaders());
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
removeImg(id_file: string) {
|
|
245
|
-
return this.http.delete<ImgPictureDTO>(`${this.CONFIG.image_manager_route}/images/${id_file}`, this.getOptionsHeaders());
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
removeMultipleImg(id_array: string[]) {
|
|
249
|
-
return this.http.post<ImgPictureDTO[]>(`${this.CONFIG.image_manager_route}/images-multiple-delete`, { id_array }, this.getOptionsHeaders());
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
### Optional: Provide the ImageNotFoundService
|
|
258
|
-
Example:
|
|
259
|
-
```
|
|
260
|
-
@Injectable()
|
|
261
|
-
export class RemoveImageMissingService extends ImageNotFoundService {
|
|
262
|
-
|
|
263
|
-
http = inject(HttpClient);
|
|
264
|
-
|
|
265
|
-
constructor() {
|
|
266
|
-
super();
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
imageNotFound(url: string): void {
|
|
270
|
-
this.removeImgIfMIssing(url).subscribe((res) => {
|
|
271
|
-
console.log(res);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
private getOptionsHeaders() {
|
|
276
|
-
const header = { headers: new HttpHeaders({
|
|
277
|
-
Authorization: 'Bearer ' + this.shopToken
|
|
278
|
-
})
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
return header;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
removeImgIfMIssing(url: string) {
|
|
285
|
-
return this.http.post<boolean>(`https://api.wizilocal.com/v3/image-manager/shops/${this.shopId}/image/remove-if-missing`, {url}, this.getOptionsHeaders());
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
### Install external package dependencies
|
|
292
|
-
The list of all external package required by the image manager is listed at at the end of the installation.
|
|
293
|
-
|
|
294
|
-
Install all the dependencies packages.
|
|
295
|
-
It should look like that :
|
|
296
|
-
`npm i tslib @angular/core @ngx-translate @angular/common rxjs @wizishop/ng-wizi-bulma @angular/common @angular/forms ngx-scrollbar ngx-scrollbar/reached-event ngx-image-cropper @angular/cdk/table`
|
|
297
|
-
|
|
298
|
-
## Image Manager setup
|
|
299
|
-
### Choose the image manager display
|
|
300
|
-
You can choose the display config with the parameter passed in the getImgManagerDisplayConfig method.
|
|
301
|
-
|
|
302
|
-
```
|
|
303
|
-
imgManagerDisplayConfig = this.imgManagerService.getImgManagerDisplayConfig('wizi-block');
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
Html file :
|
|
308
|
-
```
|
|
309
|
-
<wz-img-manager
|
|
310
|
-
[stateDisplayed]="imgManagerDisplayConfig.stateDisplayed"
|
|
311
|
-
[multipleImgMode]="imgManagerDisplayConfig.multipleImgMode"
|
|
312
|
-
[showImgManagerModule]="imgManagerDisplayConfig.showImgManagerModule && openImgManager"
|
|
313
|
-
[showSelection]="imgManagerDisplayConfig.showSelection"
|
|
314
|
-
(imgManagerClosed)="onImgManagerClosed()"
|
|
315
|
-
(imgSelectionChange)="onImageSelected($event)"
|
|
316
|
-
(imageUploaded)="onImgUploaded($event)"
|
|
317
|
-
>
|
|
318
|
-
</wz-img-manager>
|
|
319
|
-
|
|
320
|
-
```
|
|
321
|
-
### Detect when an image is selected
|
|
322
|
-
|
|
323
|
-
TS file :
|
|
324
|
-
```
|
|
325
|
-
onImageSelected(imgPictures: ImgPictureDTO[]) {
|
|
326
|
-
if (!this.waitForImage) {
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
if (imgPictures && imgPictures.length) {
|
|
330
|
-
this.setImgInWiziBlock(imgPictures[0].file_name, imgPictures[0].id_file);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
```
|
|
334
|
-
### Set Canva expected image size
|
|
335
|
-
The `this.canvaService.expectedImgSizesChange(mediaDto);` send the expected size of the image asked by the wizi block. It is optional.
|
|
336
|
-
|
|
337
|
-
## Config the translations
|
|
338
|
-
This project use `ngx-translate module` for the internationalization.
|
|
339
|
-
|
|
340
|
-
In the imported project, in the `app.module.ts` :
|
|
341
|
-
|
|
342
|
-
```
|
|
343
|
-
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
|
|
344
|
-
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
|
345
|
-
import { HttpClient } from '@angular/common/http';
|
|
346
|
-
|
|
347
|
-
// Define which translations files to used
|
|
348
|
-
export function HttpLoaderFactory(http: HttpClient) {
|
|
349
|
-
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
@NgModule({
|
|
353
|
-
imports: [
|
|
354
|
-
...,
|
|
355
|
-
TranslateModule.forRoot({
|
|
356
|
-
loader: {
|
|
357
|
-
provide: TranslateLoader,
|
|
358
|
-
useFactory: HttpLoaderFactory,
|
|
359
|
-
deps: [HttpClient]
|
|
360
|
-
},
|
|
361
|
-
})
|
|
362
|
-
],
|
|
363
|
-
...
|
|
364
|
-
})
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
If you integrate the image manager module as a lazy module, in your `shared.module.ts` file:
|
|
368
|
-
|
|
369
|
-
```
|
|
370
|
-
import { TranslateModule } from '@ngx-translate/core';
|
|
371
|
-
|
|
372
|
-
@NgModule({
|
|
373
|
-
imports: [
|
|
374
|
-
...,
|
|
375
|
-
TranslateModule
|
|
376
|
-
],
|
|
377
|
-
...
|
|
378
|
-
})
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
And somewhere in the project or in a custom translate loader :
|
|
382
|
-
|
|
383
|
-
```
|
|
384
|
-
import { TranslateService } from '@ngx-translate/core';
|
|
385
|
-
|
|
386
|
-
private defaultLang = 'fr';
|
|
387
|
-
|
|
388
|
-
constructor(private translateService: TranslateService) {
|
|
389
|
-
this.translateService.setDefaultLang(this.defaultLang);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// Change the lang used
|
|
393
|
-
this.translateService.use(lang);
|
|
1
|
+
# Image Manager
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@wizishop/img-manager)
|
|
4
|
+
[](https://www.npmjs.com/package/@wizishop/img-manager)
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
Run:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm install @wizishop/img-manager
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Add Image Manager SCSS in your project
|
|
15
|
+
Add all the following styles in your main scss file.
|
|
16
|
+
|
|
17
|
+
### Required styles
|
|
18
|
+
The required styles must be imported before the image-manager style.
|
|
19
|
+
```
|
|
20
|
+
$img-em-base: 16px!default;
|
|
21
|
+
$img-transition-base-time: 400ms!default;
|
|
22
|
+
|
|
23
|
+
@import '~bourbon/core/bourbon';
|
|
24
|
+
@import '~bulma/bulma';
|
|
25
|
+
@import '~bulma-extensions/bulma-switch/src/sass/index';
|
|
26
|
+
@import '~bulma-extensions/bulma-tooltip/src/sass/index';
|
|
27
|
+
@import '~@wizishop/ng-wizi-bulma/ng-wizi-bulma';
|
|
28
|
+
@import '~sass-flex-mixin/flex';
|
|
29
|
+
@import '@wizishop/img-manager/wz-img-manager';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Custom colors
|
|
33
|
+
Optional : The following scss colors variables can be overrided.
|
|
34
|
+
```
|
|
35
|
+
$wizishop-blue: #4baed0!default;
|
|
36
|
+
$img-gray-background: #f5f8fa!default;
|
|
37
|
+
$img-placeholder: #b5b5b5!default;
|
|
38
|
+
$img-red-color: #e74c3c!default;
|
|
39
|
+
$img-dark: #6c6c6c!default;
|
|
40
|
+
$img-really-bad-bad-bad-green: #a2c739!default;
|
|
41
|
+
|
|
42
|
+
$img-amount-hover: 8%!default;
|
|
43
|
+
|
|
44
|
+
$img-main-color: #4baed0!default;
|
|
45
|
+
$img-main-color-hover: darken($img-main-color, $img-amount-hover)!default;
|
|
46
|
+
$img-bleu-color: #4baed0!default;
|
|
47
|
+
|
|
48
|
+
$img-primary-button: $img-main-color!default;
|
|
49
|
+
$img-primary-button-hover: darken($img-primary-button, $img-amount-hover)!default;
|
|
50
|
+
$img-primary-button-desable: #dbdbdb!default;
|
|
51
|
+
|
|
52
|
+
$img-grey-color: #6B7881!default;
|
|
53
|
+
$img-green-color: #2ecc71!default;
|
|
54
|
+
$img-yellow-color: #faa945!default;
|
|
55
|
+
$img-orange-color: #F39C12!default;
|
|
56
|
+
$img-bleu-action: #3498DB!default;
|
|
57
|
+
$img-bright-red-color: #E95656!default;
|
|
58
|
+
$img-second-color: #6B7881!default;
|
|
59
|
+
$img-lightened-secondary: #d8d8d8!default;
|
|
60
|
+
$img-secondary-text: #6c6c6c!default;
|
|
61
|
+
$img-input-border: #dce0e3!default;
|
|
62
|
+
$img-light-white-color: #DCE0E3!default;
|
|
63
|
+
$img-main-text: #23272b!default;
|
|
64
|
+
$img-table-selected: #ddff98!default;
|
|
65
|
+
$img-color-loader: $img-main-color!default;
|
|
66
|
+
$img-color-loader2: $img-really-bad-bad-bad-green!default;
|
|
67
|
+
|
|
68
|
+
// Colors from wizi-admin components (table, sarch-input, pagination, checkbox...)
|
|
69
|
+
$gray-background: #f5f8fa!default;
|
|
70
|
+
$textarea-border-color: #dce0e3!default;
|
|
71
|
+
$main-text: #1d2a3b!default;
|
|
72
|
+
$secondary-color: #526384!default;
|
|
73
|
+
$second-color: #526384!default;
|
|
74
|
+
$border-form: #ccd1e0!default;
|
|
75
|
+
$background-color: #ecf0f1!default;
|
|
76
|
+
$table-background-color: #fafafa!default;
|
|
77
|
+
$input-border-search: #dee2edcc!default;
|
|
78
|
+
$placeholder-color: #b4bdd0!default;
|
|
79
|
+
$input-radio-color: #d8d8d8!default;
|
|
80
|
+
$input-active-color: $wizishop-blue!default;
|
|
81
|
+
$input-radio-color-label: #6b7881!default;
|
|
82
|
+
$input-radio-color-active-label: #1e2e43!default;
|
|
83
|
+
$border-color: #dee2ed!default;
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Add Image manager assets
|
|
87
|
+
In your `angular.json` file add the image manager assets dependency.
|
|
88
|
+
```
|
|
89
|
+
"assets": [
|
|
90
|
+
...
|
|
91
|
+
{
|
|
92
|
+
"glob": "**/*",
|
|
93
|
+
"input": "./node_modules/@wizishop/img-manager/assets/",
|
|
94
|
+
"output": "./assets/img-manager/"
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Add Pro Icons from Font Awesome
|
|
100
|
+
In your `index.html` file add the following balise.
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.12.1/css/all.css" crossorigin="anonymous" />
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Add package dependencies
|
|
107
|
+
In your module like `app.module.ts` :
|
|
108
|
+
```
|
|
109
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
110
|
+
import { NgModule } from '@angular/core';
|
|
111
|
+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|
112
|
+
import { WzImgManagerModule, ApiService } from '@wizishop/img-manager';
|
|
113
|
+
import { AppComponent } from './app.component';
|
|
114
|
+
import { TranslateModule, TranslateLoader} from '@ngx-translate/core';
|
|
115
|
+
import { HttpClient } from '@angular/common/http';
|
|
116
|
+
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
|
117
|
+
|
|
118
|
+
...
|
|
119
|
+
|
|
120
|
+
export function HttpLoaderFactory(http: HttpClient) {
|
|
121
|
+
return new TranslateHttpLoader(http, './assets/img-manager/i18n/', '.json');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
...
|
|
125
|
+
|
|
126
|
+
@NgModule({
|
|
127
|
+
declarations: [
|
|
128
|
+
AppComponent
|
|
129
|
+
],
|
|
130
|
+
imports: [
|
|
131
|
+
BrowserModule,
|
|
132
|
+
BrowserAnimationsModule,
|
|
133
|
+
WzImgManagerModule.withConfig({
|
|
134
|
+
provide: ApiService,
|
|
135
|
+
useClass: ImageManagerApiService,
|
|
136
|
+
},
|
|
137
|
+
{ // Optional
|
|
138
|
+
provide: ImageNotFoundService,
|
|
139
|
+
useClass: RemoveImageMissingService
|
|
140
|
+
}),
|
|
141
|
+
TranslateModule.forRoot({
|
|
142
|
+
defaultLanguage: 'fr',
|
|
143
|
+
loader: {
|
|
144
|
+
provide: TranslateLoader,
|
|
145
|
+
useFactory: (HttpLoaderFactory),
|
|
146
|
+
deps: [HttpClient]
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
],
|
|
150
|
+
providers: [],
|
|
151
|
+
bootstrap: [AppComponent]
|
|
152
|
+
})
|
|
153
|
+
export class AppModule { }
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Provide the ApiService
|
|
157
|
+
You must provide the ApiService needed to fetch images, upload new images...
|
|
158
|
+
Your service should extends ApiService from `@wizishop/img-manager` in order to implements all needed properties and methods.
|
|
159
|
+
|
|
160
|
+
Example:
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
@Injectable()
|
|
164
|
+
export class ImageManagerApiService implements ApiService {
|
|
165
|
+
|
|
166
|
+
SHOP_ID_KEY = "shopIdKey";
|
|
167
|
+
SHOP_TOKEN_KEY = "shopTokenKey";
|
|
168
|
+
|
|
169
|
+
get shopId(): number {
|
|
170
|
+
return Number(localStorage.getItem(this.SHOP_ID_KEY)) || 0;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
get shopToken(): string {
|
|
174
|
+
return localStorage.getItem(this.SHOP_TOKEN_KEY) || '';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
CONFIG = {
|
|
178
|
+
image_manager_route: `https://api.wizilocal.com/v3/image-manager/shops/${this.shopId}`,
|
|
179
|
+
canva_token: 'wdByHayF5v57nj2ZSLvu055O',
|
|
180
|
+
canva_url: 'https://sdk.canva.com/designbutton/v2/api.js',
|
|
181
|
+
pexels_token: '563492ad6f91700001000001e39215727d8b42c1b08498a9ce1e6b94',
|
|
182
|
+
pexels_route: 'https://api.pexels.com/v1',
|
|
183
|
+
assets_route: 'assets/img-manager/'
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
IMG_SIZE = {
|
|
187
|
+
url_raw_image: `https://mepdia.wizilocal.com/_i/${this.shopId}/RAW-`,
|
|
188
|
+
url_100_image: `https://media.wizilocal.com/_i/${this.shopId}/m100-`,
|
|
189
|
+
url_200_image: `https://media.wizilocal.com/_i/${this.shopId}/cs200-`,
|
|
190
|
+
url_400_image: `https://media.wizilocal.com/_i/${this.shopId}/cs400-`,
|
|
191
|
+
url_800_image: `https://media.wizilocal.com/_i/${this.shopId}/cs800-`
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
constructor(private http: HttpClient) {
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
getShopCategory(): string {
|
|
198
|
+
return 'other';
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private getOptionsHeaders(params?: ParamsImgManagerDTO) {
|
|
202
|
+
const header = { headers: new HttpHeaders({
|
|
203
|
+
Authorization: 'Bearer ' + this.shopToken
|
|
204
|
+
})
|
|
205
|
+
};
|
|
206
|
+
if (params) {
|
|
207
|
+
header['params'] = params
|
|
208
|
+
}
|
|
209
|
+
return header;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
getShopImgList(params?: ParamsImgManagerDTO): Observable<ImgPicturesDTO> {
|
|
213
|
+
return this.http.get<ImgPicturesDTO>(`${this.CONFIG.image_manager_route}/images`, this.getOptionsHeaders(params));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
getShopTotalImgList(params?: ParamsImgManagerDTO) {
|
|
217
|
+
return this.http.get<{totalRecords: string}>(`${this.CONFIG.image_manager_route}/total/image`, this.getOptionsHeaders(params)).pipe(map(data => Number(data.totalRecords)));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
getShopImg(idFile: string): Observable<ImgPictureDTO> {
|
|
221
|
+
return this.http.get<ImgPictureDTO>(`${this.CONFIG.image_manager_route}/images/${idFile}`, this.getOptionsHeaders());
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
uploadFile(formData: FormData) {
|
|
225
|
+
return this.http.post<ImgPictureDTO>(`${this.CONFIG.image_manager_route}/images/template`, formData, this.getOptionsHeaders());
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
uploadFileByUrl(url: string, fileName?: string) {
|
|
229
|
+
return this.http.post<ImgPictureDTO>(`${this.CONFIG.image_manager_route}/images/template`, { url, fileName }, this.getOptionsHeaders());
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
replaceImg(imageBase64: string, id_file: string) {
|
|
233
|
+
const body = {
|
|
234
|
+
imageBase64,
|
|
235
|
+
type : "RAW"
|
|
236
|
+
}
|
|
237
|
+
return this.http.put<ImgPictureDTO>(`${this.CONFIG.image_manager_route}/images/${id_file}/replace`, body, this.getOptionsHeaders());
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
changeImgName(fileName: string, id_file: string) {
|
|
241
|
+
return this.http.put<ImgPictureDTO>(`${this.CONFIG.image_manager_route}/images/${id_file}?file_name=${fileName}`, null, this.getOptionsHeaders());
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
removeImg(id_file: string) {
|
|
245
|
+
return this.http.delete<ImgPictureDTO>(`${this.CONFIG.image_manager_route}/images/${id_file}`, this.getOptionsHeaders());
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
removeMultipleImg(id_array: string[]) {
|
|
249
|
+
return this.http.post<ImgPictureDTO[]>(`${this.CONFIG.image_manager_route}/images-multiple-delete`, { id_array }, this.getOptionsHeaders());
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
### Optional: Provide the ImageNotFoundService
|
|
258
|
+
Example:
|
|
259
|
+
```
|
|
260
|
+
@Injectable()
|
|
261
|
+
export class RemoveImageMissingService extends ImageNotFoundService {
|
|
262
|
+
|
|
263
|
+
http = inject(HttpClient);
|
|
264
|
+
|
|
265
|
+
constructor() {
|
|
266
|
+
super();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
imageNotFound(url: string): void {
|
|
270
|
+
this.removeImgIfMIssing(url).subscribe((res) => {
|
|
271
|
+
console.log(res);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
private getOptionsHeaders() {
|
|
276
|
+
const header = { headers: new HttpHeaders({
|
|
277
|
+
Authorization: 'Bearer ' + this.shopToken
|
|
278
|
+
})
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
return header;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
removeImgIfMIssing(url: string) {
|
|
285
|
+
return this.http.post<boolean>(`https://api.wizilocal.com/v3/image-manager/shops/${this.shopId}/image/remove-if-missing`, {url}, this.getOptionsHeaders());
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Install external package dependencies
|
|
292
|
+
The list of all external package required by the image manager is listed at at the end of the installation.
|
|
293
|
+
|
|
294
|
+
Install all the dependencies packages.
|
|
295
|
+
It should look like that :
|
|
296
|
+
`npm i tslib @angular/core @ngx-translate @angular/common rxjs @wizishop/ng-wizi-bulma @angular/common @angular/forms ngx-scrollbar ngx-scrollbar/reached-event ngx-image-cropper @angular/cdk/table`
|
|
297
|
+
|
|
298
|
+
## Image Manager setup
|
|
299
|
+
### Choose the image manager display
|
|
300
|
+
You can choose the display config with the parameter passed in the getImgManagerDisplayConfig method.
|
|
301
|
+
|
|
302
|
+
```
|
|
303
|
+
imgManagerDisplayConfig = this.imgManagerService.getImgManagerDisplayConfig('wizi-block');
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
Html file :
|
|
308
|
+
```
|
|
309
|
+
<wz-img-manager
|
|
310
|
+
[stateDisplayed]="imgManagerDisplayConfig.stateDisplayed"
|
|
311
|
+
[multipleImgMode]="imgManagerDisplayConfig.multipleImgMode"
|
|
312
|
+
[showImgManagerModule]="imgManagerDisplayConfig.showImgManagerModule && openImgManager"
|
|
313
|
+
[showSelection]="imgManagerDisplayConfig.showSelection"
|
|
314
|
+
(imgManagerClosed)="onImgManagerClosed()"
|
|
315
|
+
(imgSelectionChange)="onImageSelected($event)"
|
|
316
|
+
(imageUploaded)="onImgUploaded($event)"
|
|
317
|
+
>
|
|
318
|
+
</wz-img-manager>
|
|
319
|
+
|
|
320
|
+
```
|
|
321
|
+
### Detect when an image is selected
|
|
322
|
+
|
|
323
|
+
TS file :
|
|
324
|
+
```
|
|
325
|
+
onImageSelected(imgPictures: ImgPictureDTO[]) {
|
|
326
|
+
if (!this.waitForImage) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (imgPictures && imgPictures.length) {
|
|
330
|
+
this.setImgInWiziBlock(imgPictures[0].file_name, imgPictures[0].id_file);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
### Set Canva expected image size
|
|
335
|
+
The `this.canvaService.expectedImgSizesChange(mediaDto);` send the expected size of the image asked by the wizi block. It is optional.
|
|
336
|
+
|
|
337
|
+
## Config the translations
|
|
338
|
+
This project use `ngx-translate module` for the internationalization.
|
|
339
|
+
|
|
340
|
+
In the imported project, in the `app.module.ts` :
|
|
341
|
+
|
|
342
|
+
```
|
|
343
|
+
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
|
|
344
|
+
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
|
345
|
+
import { HttpClient } from '@angular/common/http';
|
|
346
|
+
|
|
347
|
+
// Define which translations files to used
|
|
348
|
+
export function HttpLoaderFactory(http: HttpClient) {
|
|
349
|
+
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
@NgModule({
|
|
353
|
+
imports: [
|
|
354
|
+
...,
|
|
355
|
+
TranslateModule.forRoot({
|
|
356
|
+
loader: {
|
|
357
|
+
provide: TranslateLoader,
|
|
358
|
+
useFactory: HttpLoaderFactory,
|
|
359
|
+
deps: [HttpClient]
|
|
360
|
+
},
|
|
361
|
+
})
|
|
362
|
+
],
|
|
363
|
+
...
|
|
364
|
+
})
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
If you integrate the image manager module as a lazy module, in your `shared.module.ts` file:
|
|
368
|
+
|
|
369
|
+
```
|
|
370
|
+
import { TranslateModule } from '@ngx-translate/core';
|
|
371
|
+
|
|
372
|
+
@NgModule({
|
|
373
|
+
imports: [
|
|
374
|
+
...,
|
|
375
|
+
TranslateModule
|
|
376
|
+
],
|
|
377
|
+
...
|
|
378
|
+
})
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
And somewhere in the project or in a custom translate loader :
|
|
382
|
+
|
|
383
|
+
```
|
|
384
|
+
import { TranslateService } from '@ngx-translate/core';
|
|
385
|
+
|
|
386
|
+
private defaultLang = 'fr';
|
|
387
|
+
|
|
388
|
+
constructor(private translateService: TranslateService) {
|
|
389
|
+
this.translateService.setDefaultLang(this.defaultLang);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Change the lang used
|
|
393
|
+
this.translateService.use(lang);
|
|
394
394
|
```
|