@servicemind.tis/tis-image-and-file-upload-and-view 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,305 @@
1
+ # tis-image-and-file-upload-and-view
2
+
3
+ An all-in-one **image and file upload/view** Angular component by **Thai Informatic Systems Co. Ltd.**, designed for modern enterprise applications. This library provides a highly customizable drag-and-drop or button-triggered upload UI, with seamless preview and viewer integration for files including images, PDFs, videos, Excel, and more.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@servicemind.tis/tis-image-and-file-upload-and-view)](https://www.npmjs.com/package/@servicemind.tis/tis-image-and-file-upload-and-view)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@servicemind.tis/tis-image-and-file-upload-and-view)](https://www.npmjs.com/package/@servicemind.tis/tis-image-and-file-upload-and-view)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
8
+
9
+ ---
10
+
11
+ ## πŸš€ Features
12
+
13
+ - βœ… Image and file upload with S3-style pre-signed URL handling
14
+ - βœ… Support for images, PDFs, Excel, CSV, videos, and raw files
15
+ - βœ… Built-in preview & viewer components
16
+ - βœ… Optional confirmation dialogs
17
+ - βœ… Fully customizable UI and dialog labels
18
+ - βœ… Support for standalone and module-based Angular apps
19
+ - βœ… Supports multiple uploads, size control, and compression toggle
20
+
21
+ ---
22
+
23
+ ## πŸ“¦ Installation
24
+
25
+ ```bash
26
+ npm install @servicemind.tis/tis-image-and-file-upload-and-view
27
+ ```
28
+
29
+ ### Peer Dependencies
30
+
31
+ ```bash
32
+ npm install @angular/material @angular/cdk
33
+ ```
34
+
35
+ ---
36
+
37
+ ## 🧩 Module Setup
38
+
39
+ ```ts
40
+ import { TisImageAndFileUploadAndViewModule } from '@servicemind.tis/tis-image-and-file-upload-and-view';
41
+
42
+ @NgModule({
43
+ imports: [TisImageAndFileUploadAndViewModule]
44
+ })
45
+ export class MyFeatureModule {}
46
+ ```
47
+
48
+ ---
49
+
50
+ ## βš™οΈ Configuration Interfaces
51
+
52
+ ### `UrlConfig`
53
+
54
+ ```ts
55
+ export interface UrlConfig {
56
+ getUploadUrl: string;
57
+ attachToEntity: string;
58
+ removeImage: string;
59
+ }
60
+ ```
61
+
62
+ ### `DialogConfig`
63
+
64
+ ```ts
65
+ export interface DialogConfig {
66
+ title: string;
67
+ message: string | null;
68
+ iconClass: string;
69
+ icon: string;
70
+ approveButtonText: string | null;
71
+ approveButtonClass: string;
72
+ cancelButtonText: string | null;
73
+ cancelButtonClass: string;
74
+ }
75
+ ```
76
+
77
+ ---
78
+
79
+ ## 🧠 Component: `<tis-image-and-file-upload-and-view>`
80
+
81
+ This is the main component that allows users to upload and preview files.
82
+
83
+ ### βœ… Inputs
84
+
85
+ | Input | Type | Description |
86
+ |---------------|---------------------|-------------|
87
+ | `urlConfig` | `UrlConfig` | API endpoints for upload, attach, delete |
88
+ | `entityType` | `string` | Type of the associated entity |
89
+ | `disabled` | `boolean` | Disable upload actions |
90
+ | `viewType` | `'card'` | View format |
91
+ | `options` | `UploadOptions` | Visual and functional configurations |
92
+ | `accept` | `string` | Allowed file types (e.g., `.jpg,.png`) |
93
+ | `label` | `string` | Upload label |
94
+ | `data` | `any[]` | Existing file data to render |
95
+ | `dialogConfig`| `DialogConfig` | Custom confirmation dialog settings |
96
+
97
+ ---
98
+
99
+ ## πŸ“€ Example Usage
100
+
101
+ ### HTML
102
+
103
+ ```html
104
+ <tis-image-and-file-upload-and-view
105
+ [urlConfig]="urlConfig"
106
+ [entityType]="'announcement_details'"
107
+ [disabled]="false"
108
+ viewType="card"
109
+ [options]="{
110
+ selectorId: 'choosing-image-for-announcement-details',
111
+ height: '108px',
112
+ isStoredDb: false,
113
+ isMultiple: true,
114
+ cols: 5,
115
+ isCompressed: false
116
+ }"
117
+ accept=".png,.jpeg,.jpg"
118
+ label="Upload Image"
119
+ [data]="files"
120
+ [dialogConfig]="getImagePickerDialogConfig()">
121
+ </tis-image-and-file-upload-and-view>
122
+ ```
123
+
124
+ ### Component (TS)
125
+
126
+ ```ts
127
+ urlConfig: UrlConfig = {
128
+ getUploadUrl: 'https://your-api/get-upload-url',
129
+ attachToEntity: 'https://your-api/attach-to-entity',
130
+ removeImage: 'https://your-api/remove-url',
131
+ };
132
+
133
+ files = [
134
+ {
135
+ s3Url: 'https://bucket-url/file1.jpg',
136
+ uploadData: {
137
+ uploadURL: 'https://bucket-url/upload',
138
+ fileName: 'example.jpg',
139
+ uploadPath: '/entity/example.jpg',
140
+ resourceUrl: 'https://bucket-url/example.jpg'
141
+ }
142
+ }
143
+ ];
144
+
145
+ getImagePickerDialogConfig(): DialogConfig {
146
+ return {
147
+ title: 'Delete Image',
148
+ message: 'Are you sure you want to delete this image?',
149
+ iconClass: 'tis-text-danger',
150
+ icon: 'delete',
151
+ approveButtonText: 'Yes',
152
+ approveButtonClass: 'tis-btn-danger',
153
+ cancelButtonText: 'No',
154
+ cancelButtonClass: 'tis-btn-primary'
155
+ };
156
+ }
157
+ ```
158
+
159
+ ---
160
+
161
+ ## πŸ–ΌοΈ File Types Supported
162
+
163
+ Component auto-detects and handles:
164
+
165
+ - πŸ“„ PDF
166
+ - πŸ“· Images (`jpg`, `jpeg`, `png`)
167
+ - πŸ“Ή Videos
168
+ - πŸ“Š Excel & CSV
169
+ - πŸ“¦ Raw files (opens via download or fallback preview)
170
+
171
+ ---
172
+
173
+ ## πŸ”Œ Standalone App Integration
174
+
175
+ In `main.ts`:
176
+
177
+ ```ts
178
+ import { provideHttpClient } from '@angular/common/http';
179
+
180
+ bootstrapApplication(AppComponent, {
181
+ providers: [
182
+ provideHttpClient()
183
+ ]
184
+ });
185
+ ```
186
+
187
+ ---
188
+
189
+ ## 🎨 Styling
190
+
191
+ The component uses Angular Material β€” ensure a theme is included:
192
+
193
+ ```scss
194
+ @import "~@angular/material/prebuilt-themes/indigo-pink.css";
195
+ ```
196
+
197
+ ---
198
+
199
+
200
+
201
+ ## πŸ“‘ API Contract for Upload Integration
202
+
203
+ The component requires a pre-signed URL from your backend to upload files directly to cloud storage (like AWS S3). You must implement an API endpoint that responds with the following JSON structure:
204
+
205
+ ### βœ… Sample Response from `getUploadUrl`
206
+
207
+ ```json
208
+ {
209
+ "data": {
210
+ "uploadUrlData": {
211
+ "uploadURL": "https://your-s3-bucket/your-object-key.jpg?...",
212
+ "fileName": "your-object-key.jpg",
213
+ "uploadPath": "/folder/your-object-key.jpg",
214
+ "resourceUrl": "https://your-s3-bucket/your-object-key.jpg"
215
+ }
216
+ },
217
+ "message": "Upload Url generated successfully!"
218
+ }
219
+ ```
220
+
221
+ - **uploadURL**: This is the pre-signed `PUT` URL. The component will upload the file directly to this URL.
222
+ - **fileName**: Name of the file being uploaded.
223
+ - **uploadPath**: Optional path metadata for organizing resources.
224
+ - **resourceUrl**: The final public/accessible URL for accessing the uploaded file.
225
+
226
+ ---
227
+
228
+ ## πŸ“€ How Upload Works Internally
229
+
230
+ When a user selects a file:
231
+
232
+ 1. The component calls your `getUploadUrl` API with basic metadata (like file name/type).
233
+ 2. Your backend returns a `PUT` pre-signed URL via `uploadURL`.
234
+ 3. The component performs a **`PUT` request directly to that URL**, sending the image or file binary.
235
+ 4. After success, the `resourceUrl` is used for rendering or viewing.
236
+
237
+ ---
238
+
239
+ ## πŸ”Œ Backend API Example (Node.js)
240
+
241
+ Here’s a basic AWS S3 backend implementation in Node.js:
242
+
243
+ ```js
244
+ const AWS = require('aws-sdk');
245
+ const s3 = new AWS.S3();
246
+
247
+ app.post('/api/get-upload-url', (req, res) => {
248
+ const fileName = req.body.fileName;
249
+ const fileType = req.body.fileType;
250
+ const key = `cm_cases/${uuidv4()}.${fileType.split('/')[1]}`;
251
+
252
+ const params = {
253
+ Bucket: 'your-s3-bucket',
254
+ Key: key,
255
+ ContentType: fileType,
256
+ ACL: 'public-read',
257
+ Expires: 900,
258
+ };
259
+
260
+ const uploadURL = s3.getSignedUrl('putObject', params);
261
+ res.json({
262
+ data: {
263
+ uploadUrlData: {
264
+ uploadURL,
265
+ fileName,
266
+ uploadPath: `/${key}`,
267
+ resourceUrl: `https://your-s3-bucket.s3.amazonaws.com/${key}`
268
+ }
269
+ },
270
+ message: "Upload Url generated successfully!"
271
+ });
272
+ });
273
+ ```
274
+
275
+ ---
276
+
277
+
278
+ ## 🀝 Contributing
279
+
280
+ 1. Clone the repo
281
+ 2. Run `npm install`
282
+ 3. Use the demo app to test (`projects/` directory)
283
+ 4. Submit a PR or issue with details
284
+
285
+ ---
286
+
287
+ ## πŸš€ Publishing to npm
288
+
289
+ ```bash
290
+ git tag v1.0.0
291
+ git push origin v1.0.0
292
+ ```
293
+
294
+ GitHub Actions will build and publish to npm automatically if configured.
295
+
296
+ ---
297
+
298
+ ## πŸ“¬ Support / Questions
299
+
300
+ For bugs, suggestions, or feature requests, please open an issue on the [GitHub repository](https://github.com/Thai-Informatics-System/tis-image-and-file-upload-and-view).
301
+
302
+ ---
303
+
304
+ > Made with ❀️ by [Thai Informatic Systems Co. Ltd](https://tis.co.th/)
305
+