@adminforth/upload 2.0.1 → 2.1.1

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/build.log CHANGED
@@ -11,5 +11,5 @@ custom/preview.vue
11
11
  custom/tsconfig.json
12
12
  custom/uploader.vue
13
13
 
14
- sent 44,046 bytes received 134 bytes 88,360.00 bytes/sec
15
- total size is 43,557 speedup is 0.99
14
+ sent 46,106 bytes received 134 bytes 92,480.00 bytes/sec
15
+ total size is 45,617 speedup is 0.99
@@ -21,15 +21,46 @@
21
21
  </div>
22
22
  <!-- Modal body -->
23
23
  <div class="p-4 md:p-5 space-y-4">
24
- <textarea id="message" rows="3" class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
25
- :placeholder="$t('Prompt which will be passed to AI network')" v-model="prompt"
24
+ <!-- PROMPT TEXTAREA -->
25
+ <!-- Textarea -->
26
+ <textarea
27
+ id="message"
28
+ rows="3"
29
+ class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
30
+ :placeholder="$t('Prompt which will be passed to AI network')"
31
+ v-model="prompt"
26
32
  :title="$t('Prompt which will be passed to AI network')"
27
- ></textarea>
33
+ ></textarea>
34
+
35
+ <!-- Thumbnails -->
36
+ <div class="mt-2 flex flex-wrap gap-2">
37
+ <img
38
+ v-for="(img, idx) in attachmentFiles"
39
+ :key="idx"
40
+ :src="img"
41
+ class="w-20 h-20 object-cover rounded cursor-pointer border hover:border-blue-500 transition"
42
+ :alt="`Generated image ${idx + 1}`"
43
+ @click="zoomImage(img)"
44
+ />
45
+ </div>
46
+
47
+ <!-- Fullscreen Modal -->
48
+ <div
49
+ v-if="zoomedImage"
50
+ class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-80"
51
+ @click.self="closeZoom"
52
+ >
53
+ <img
54
+ :src="zoomedImage"
55
+ ref="zoomedImg"
56
+ class="max-w-full max-h-full rounded-lg object-contain cursor-grab z-75"
57
+ />
58
+ </div>
28
59
 
29
60
  <div class="flex flex-col items-center justify-center w-full relative">
30
61
  <div
31
62
  v-if="loading"
32
- class=" absolute flex items-center justify-center w-full h-full z-50 bg-white/80 dark:bg-gray-900/80 rounded-lg"
63
+ class=" absolute flex items-center justify-center w-full h-full z-40 bg-white/80 dark:bg-gray-900/80 rounded-lg"
33
64
  >
34
65
  <div role="status" class="absolute -translate-x-1/2 -translate-y-1/2 top-2/4 left-1/2">
35
66
  <svg aria-hidden="true" class="w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
@@ -37,7 +68,7 @@
37
68
  </div>
38
69
  </div>
39
70
 
40
- <div v-if="loadingTimer" class="absolute pt-12 flex items-center justify-center w-full h-full z-50 bg-white/80 dark:bg-gray-900/80 rounded-lg">
71
+ <div v-if="loadingTimer" class="absolute pt-12 flex items-center justify-center w-full h-full z-40 bg-white/80 dark:bg-gray-900/80 rounded-lg">
41
72
  <div class="text-gray-800 dark:text-gray-100 text-lg font-semibold"
42
73
  v-if="!historicalAverage"
43
74
  >
@@ -57,7 +88,7 @@
57
88
  </div>
58
89
  </div>
59
90
 
60
- <div v-if="errorMessage" class="absolute flex items-center justify-center w-full h-full z-50 bg-white/80 dark:bg-gray-900/80 rounded-lg">
91
+ <div v-if="errorMessage" class="absolute flex items-center justify-center w-full h-full z-40 bg-white/80 dark:bg-gray-900/80 rounded-lg">
61
92
  <div class="pt-20 text-red-500 dark:text-red-400 text-lg font-semibold">
62
93
  {{ errorMessage }}
63
94
  </div>
@@ -66,7 +97,7 @@
66
97
 
67
98
  <div id="gallery" class="relative w-full" data-carousel="static">
68
99
  <!-- Carousel wrapper -->
69
- <div class="relative h-56 overflow-hidden rounded-lg md:h-[calc(100vh-350px)]">
100
+ <div class="relative h-56 overflow-hidden rounded-lg md:h-[calc(100vh-400px)]">
70
101
  <!-- Item 1 -->
71
102
  <div v-for="(img, index) in images" :key="index" class="hidden duration-700 ease-in-out" data-carousel-item>
72
103
  <img :src="img" class="absolute block max-w-full max-h-full -translate-x-1/2 -translate-y-1/2 top-1/2 left-1/2 object-cover"
@@ -144,7 +175,7 @@
144
175
 
145
176
  <script setup lang="ts">
146
177
 
147
- import { ref, onMounted, nextTick, Ref, h, computed } from 'vue'
178
+ import { ref, onMounted, nextTick, Ref, h, computed, watch, reactive } from 'vue'
148
179
  import { Carousel } from 'flowbite';
149
180
  import { callAdminForthApi } from '@/utils';
150
181
  import { useI18n } from 'vue-i18n';
@@ -158,6 +189,7 @@ const emit = defineEmits(['close', 'uploadImage']);
158
189
  const props = defineProps(['meta', 'record']);
159
190
  const images = ref([]);
160
191
  const loading = ref(false);
192
+ const attachmentFiles = ref<string[]>([])
161
193
 
162
194
  function minifyField(field: string): string {
163
195
  if (field.length > 100) {
@@ -167,7 +199,7 @@ function minifyField(field: string): string {
167
199
  }
168
200
 
169
201
  const caurosel = ref(null);
170
- onMounted(() => {
202
+ onMounted(async () => {
171
203
  // Initialize carousel
172
204
  const context = {
173
205
  field: props.meta.pathColumnLabel,
@@ -203,7 +235,24 @@ onMounted(() => {
203
235
  prompt.value = template.replace(regex, (_, field) => {
204
236
  return context[field.trim()] || '';
205
237
  });
238
+
239
+ const recordId = props.record[props.meta.recorPkFieldName];
240
+ if (!recordId) return;
241
+
242
+ try {
243
+ const resp = await callAdminForthApi({
244
+ path: `/plugin/${props.meta.pluginInstanceId}/get_attachment_files`,
245
+ method: 'POST',
246
+ body: { recordId },
247
+ });
206
248
 
249
+ if (resp?.files?.length) {
250
+ attachmentFiles.value = resp.files;
251
+ console.log('attachmentFiles', attachmentFiles.value);
252
+ }
253
+ } catch (err) {
254
+ console.error('Failed to fetch attachment files', err);
255
+ }
207
256
  });
208
257
 
209
258
  async function slide(direction: number) {
@@ -357,6 +406,27 @@ async function generateImages() {
357
406
  loading.value = false;
358
407
  }
359
408
 
409
+ import mediumZoom from 'medium-zoom'
360
410
 
411
+ const zoomedImage = ref(null)
412
+ const zoomedImg = ref(null)
413
+
414
+ function zoomImage(img) {
415
+ zoomedImage.value = img
416
+ }
361
417
 
418
+ function closeZoom() {
419
+ zoomedImage.value = null
420
+ }
421
+
422
+ watch(zoomedImage, async (val) => {
423
+ await nextTick()
424
+ if (val && zoomedImg.value) {
425
+ mediumZoom(zoomedImg.value, {
426
+ margin: 24,
427
+ background: 'rgba(0, 0, 0, 0.9)',
428
+ scrollOffset: 150
429
+ }).show()
430
+ }
431
+ })
362
432
  </script>
@@ -21,15 +21,46 @@
21
21
  </div>
22
22
  <!-- Modal body -->
23
23
  <div class="p-4 md:p-5 space-y-4">
24
- <textarea id="message" rows="3" class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
25
- :placeholder="$t('Prompt which will be passed to AI network')" v-model="prompt"
24
+ <!-- PROMPT TEXTAREA -->
25
+ <!-- Textarea -->
26
+ <textarea
27
+ id="message"
28
+ rows="3"
29
+ class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
30
+ :placeholder="$t('Prompt which will be passed to AI network')"
31
+ v-model="prompt"
26
32
  :title="$t('Prompt which will be passed to AI network')"
27
- ></textarea>
33
+ ></textarea>
34
+
35
+ <!-- Thumbnails -->
36
+ <div class="mt-2 flex flex-wrap gap-2">
37
+ <img
38
+ v-for="(img, idx) in attachmentFiles"
39
+ :key="idx"
40
+ :src="img"
41
+ class="w-20 h-20 object-cover rounded cursor-pointer border hover:border-blue-500 transition"
42
+ :alt="`Generated image ${idx + 1}`"
43
+ @click="zoomImage(img)"
44
+ />
45
+ </div>
46
+
47
+ <!-- Fullscreen Modal -->
48
+ <div
49
+ v-if="zoomedImage"
50
+ class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-80"
51
+ @click.self="closeZoom"
52
+ >
53
+ <img
54
+ :src="zoomedImage"
55
+ ref="zoomedImg"
56
+ class="max-w-full max-h-full rounded-lg object-contain cursor-grab z-75"
57
+ />
58
+ </div>
28
59
 
29
60
  <div class="flex flex-col items-center justify-center w-full relative">
30
61
  <div
31
62
  v-if="loading"
32
- class=" absolute flex items-center justify-center w-full h-full z-50 bg-white/80 dark:bg-gray-900/80 rounded-lg"
63
+ class=" absolute flex items-center justify-center w-full h-full z-40 bg-white/80 dark:bg-gray-900/80 rounded-lg"
33
64
  >
34
65
  <div role="status" class="absolute -translate-x-1/2 -translate-y-1/2 top-2/4 left-1/2">
35
66
  <svg aria-hidden="true" class="w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
@@ -37,7 +68,7 @@
37
68
  </div>
38
69
  </div>
39
70
 
40
- <div v-if="loadingTimer" class="absolute pt-12 flex items-center justify-center w-full h-full z-50 bg-white/80 dark:bg-gray-900/80 rounded-lg">
71
+ <div v-if="loadingTimer" class="absolute pt-12 flex items-center justify-center w-full h-full z-40 bg-white/80 dark:bg-gray-900/80 rounded-lg">
41
72
  <div class="text-gray-800 dark:text-gray-100 text-lg font-semibold"
42
73
  v-if="!historicalAverage"
43
74
  >
@@ -57,7 +88,7 @@
57
88
  </div>
58
89
  </div>
59
90
 
60
- <div v-if="errorMessage" class="absolute flex items-center justify-center w-full h-full z-50 bg-white/80 dark:bg-gray-900/80 rounded-lg">
91
+ <div v-if="errorMessage" class="absolute flex items-center justify-center w-full h-full z-40 bg-white/80 dark:bg-gray-900/80 rounded-lg">
61
92
  <div class="pt-20 text-red-500 dark:text-red-400 text-lg font-semibold">
62
93
  {{ errorMessage }}
63
94
  </div>
@@ -66,7 +97,7 @@
66
97
 
67
98
  <div id="gallery" class="relative w-full" data-carousel="static">
68
99
  <!-- Carousel wrapper -->
69
- <div class="relative h-56 overflow-hidden rounded-lg md:h-[calc(100vh-350px)]">
100
+ <div class="relative h-56 overflow-hidden rounded-lg md:h-[calc(100vh-400px)]">
70
101
  <!-- Item 1 -->
71
102
  <div v-for="(img, index) in images" :key="index" class="hidden duration-700 ease-in-out" data-carousel-item>
72
103
  <img :src="img" class="absolute block max-w-full max-h-full -translate-x-1/2 -translate-y-1/2 top-1/2 left-1/2 object-cover"
@@ -144,7 +175,7 @@
144
175
 
145
176
  <script setup lang="ts">
146
177
 
147
- import { ref, onMounted, nextTick, Ref, h, computed } from 'vue'
178
+ import { ref, onMounted, nextTick, Ref, h, computed, watch, reactive } from 'vue'
148
179
  import { Carousel } from 'flowbite';
149
180
  import { callAdminForthApi } from '@/utils';
150
181
  import { useI18n } from 'vue-i18n';
@@ -158,6 +189,7 @@ const emit = defineEmits(['close', 'uploadImage']);
158
189
  const props = defineProps(['meta', 'record']);
159
190
  const images = ref([]);
160
191
  const loading = ref(false);
192
+ const attachmentFiles = ref<string[]>([])
161
193
 
162
194
  function minifyField(field: string): string {
163
195
  if (field.length > 100) {
@@ -167,7 +199,7 @@ function minifyField(field: string): string {
167
199
  }
168
200
 
169
201
  const caurosel = ref(null);
170
- onMounted(() => {
202
+ onMounted(async () => {
171
203
  // Initialize carousel
172
204
  const context = {
173
205
  field: props.meta.pathColumnLabel,
@@ -203,7 +235,24 @@ onMounted(() => {
203
235
  prompt.value = template.replace(regex, (_, field) => {
204
236
  return context[field.trim()] || '';
205
237
  });
238
+
239
+ const recordId = props.record[props.meta.recorPkFieldName];
240
+ if (!recordId) return;
241
+
242
+ try {
243
+ const resp = await callAdminForthApi({
244
+ path: `/plugin/${props.meta.pluginInstanceId}/get_attachment_files`,
245
+ method: 'POST',
246
+ body: { recordId },
247
+ });
206
248
 
249
+ if (resp?.files?.length) {
250
+ attachmentFiles.value = resp.files;
251
+ console.log('attachmentFiles', attachmentFiles.value);
252
+ }
253
+ } catch (err) {
254
+ console.error('Failed to fetch attachment files', err);
255
+ }
207
256
  });
208
257
 
209
258
  async function slide(direction: number) {
@@ -357,6 +406,27 @@ async function generateImages() {
357
406
  loading.value = false;
358
407
  }
359
408
 
409
+ import mediumZoom from 'medium-zoom'
360
410
 
411
+ const zoomedImage = ref(null)
412
+ const zoomedImg = ref(null)
413
+
414
+ function zoomImage(img) {
415
+ zoomedImage.value = img
416
+ }
361
417
 
418
+ function closeZoom() {
419
+ zoomedImage.value = null
420
+ }
421
+
422
+ watch(zoomedImage, async (val) => {
423
+ await nextTick()
424
+ if (val && zoomedImg.value) {
425
+ mediumZoom(zoomedImg.value, {
426
+ margin: 24,
427
+ background: 'rgba(0, 0, 0, 0.9)',
428
+ scrollOffset: 150
429
+ }).show()
430
+ }
431
+ })
362
432
  </script>
package/dist/index.js CHANGED
@@ -362,5 +362,26 @@ export default class UploadPlugin extends AdminForthPlugin {
362
362
  return null;
363
363
  })
364
364
  });
365
+ server.endpoint({
366
+ method: 'POST',
367
+ path: `/plugin/${this.pluginInstanceId}/get_attachment_files`,
368
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser }) {
369
+ var _b;
370
+ const { recordId } = body;
371
+ if (!recordId)
372
+ return { error: 'Missing recordId' };
373
+ const record = yield this.adminforth.resource(this.resourceConfig.resourceId).get([
374
+ Filters.EQ((_b = this.resourceConfig.columns.find((col) => col.primaryKey)) === null || _b === void 0 ? void 0 : _b.name, recordId),
375
+ ]);
376
+ if (!record)
377
+ return { error: 'Record not found' };
378
+ if (!this.options.generation.attachFiles)
379
+ return { files: [] };
380
+ const files = yield this.options.generation.attachFiles({ record, adminUser });
381
+ return {
382
+ files: Array.isArray(files) ? files : [files],
383
+ };
384
+ }),
385
+ });
365
386
  }
366
387
  }
package/index.ts CHANGED
@@ -423,6 +423,30 @@ export default class UploadPlugin extends AdminForthPlugin {
423
423
  return null
424
424
  }
425
425
  });
426
+
427
+ server.endpoint({
428
+ method: 'POST',
429
+ path: `/plugin/${this.pluginInstanceId}/get_attachment_files`,
430
+ handler: async ({ body, adminUser }) => {
431
+ const { recordId } = body;
432
+
433
+ if (!recordId) return { error: 'Missing recordId' };
434
+
435
+ const record = await this.adminforth.resource(this.resourceConfig.resourceId).get([
436
+ Filters.EQ(this.resourceConfig.columns.find((col: any) => col.primaryKey)?.name, recordId),
437
+ ]);
438
+
439
+ if (!record) return { error: 'Record not found' };
440
+
441
+ if (!this.options.generation.attachFiles) return { files: [] };
442
+
443
+ const files = await this.options.generation.attachFiles({ record, adminUser });
444
+
445
+ return {
446
+ files: Array.isArray(files) ? files : [files],
447
+ };
448
+ },
449
+ });
426
450
 
427
451
  }
428
452
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/upload",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
4
  "description": "Plugin for uploading files for adminforth",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",