@adminforth/clone-row 1.1.7 → 1.2.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/build.log CHANGED
@@ -5,7 +5,8 @@
5
5
  sending incremental file list
6
6
  custom/
7
7
  custom/CloneRowButton.vue
8
+ custom/CloneRowThreeDots.vue
8
9
  custom/tsconfig.json
9
10
 
10
- sent 2,087 bytes received 58 bytes 4,290.00 bytes/sec
11
- total size is 1,869 speedup is 0.87
11
+ sent 3,616 bytes received 77 bytes 7,386.00 bytes/sec
12
+ total size is 3,322 speedup is 0.90
@@ -7,7 +7,7 @@
7
7
  values: save_btoa(JSON.stringify(redirectToCreatePage())),
8
8
  }
9
9
  }">
10
- <IconFileCloneOutline class="w-5 h-5 me-2"/>
10
+ <IconFileCloneSolid class="w-5 h-5 me-2"/>
11
11
  </RouterLink>
12
12
  <template v-slot:tooltip>
13
13
  {{ $t('Clone record') }}
@@ -18,7 +18,7 @@
18
18
  <script lang="ts" setup>
19
19
  import { Tooltip } from '@/afcl';
20
20
  import { AdminUser, type AdminForthResourceCommon } from '@/types';
21
- import { IconFileCloneOutline } from '@iconify-prerendered/vue-flowbite';
21
+ import { IconFileCloneSolid } from '@iconify-prerendered/vue-flowbite';
22
22
  import { useI18n } from 'vue-i18n';
23
23
 
24
24
  const { t } = useI18n();
@@ -0,0 +1,49 @@
1
+ <template>
2
+ <RouterLink
3
+ class="flex px-4 py-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-700 dark:text-gray-300"
4
+ :to="{
5
+ name: `resource-create`,
6
+ params: { resourceId: props.meta.resourceId },
7
+ query: {
8
+ values: save_btoa(JSON.stringify(redirectToCreatePage())),
9
+ }
10
+ }">
11
+ <IconFileCloneSolid class="w-5 h-5 me-2 text-lightPrimary dark:text-darkPrimary"/>
12
+ {{ $t('Clone record') }}
13
+ </RouterLink>
14
+ </template>
15
+
16
+ <script lang="ts" setup>
17
+ import { Tooltip } from '@/afcl';
18
+ import { AdminUser, type AdminForthResourceCommon } from '@/types';
19
+ import { IconFileCloneSolid } from '@iconify-prerendered/vue-flowbite';
20
+ import { useI18n } from 'vue-i18n';
21
+
22
+ const { t } = useI18n();
23
+
24
+ const props = defineProps<{
25
+ meta: any,
26
+ resource: AdminForthResourceCommon,
27
+ adminUser: AdminUser,
28
+ record: any,
29
+ updateRecords: Function,
30
+ }>();
31
+
32
+ function redirectToCreatePage() {
33
+ const fieldsToFill = { ...props.resource.columns.filter((col: any) => col.showIn.create === true) }
34
+ let dataToFill = {};
35
+ for (const field of Object.values(fieldsToFill)) {
36
+ if (field.foreignResource) {
37
+ dataToFill[field.name] = props.record[field.name]?.pk
38
+ continue;
39
+ }
40
+ dataToFill[field.name] = props.record[field.name];
41
+ }
42
+ return dataToFill;
43
+ }
44
+
45
+ function save_btoa(str) {
46
+ const cleaned = str.replace(/\uFEFF/g, '');
47
+ return btoa(cleaned);
48
+ }
49
+ </script>
@@ -7,7 +7,7 @@
7
7
  values: save_btoa(JSON.stringify(redirectToCreatePage())),
8
8
  }
9
9
  }">
10
- <IconFileCloneOutline class="w-5 h-5 me-2"/>
10
+ <IconFileCloneSolid class="w-5 h-5 me-2"/>
11
11
  </RouterLink>
12
12
  <template v-slot:tooltip>
13
13
  {{ $t('Clone record') }}
@@ -18,7 +18,7 @@
18
18
  <script lang="ts" setup>
19
19
  import { Tooltip } from '@/afcl';
20
20
  import { AdminUser, type AdminForthResourceCommon } from '@/types';
21
- import { IconFileCloneOutline } from '@iconify-prerendered/vue-flowbite';
21
+ import { IconFileCloneSolid } from '@iconify-prerendered/vue-flowbite';
22
22
  import { useI18n } from 'vue-i18n';
23
23
 
24
24
  const { t } = useI18n();
@@ -0,0 +1,49 @@
1
+ <template>
2
+ <RouterLink
3
+ class="flex px-4 py-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-700 dark:text-gray-300"
4
+ :to="{
5
+ name: `resource-create`,
6
+ params: { resourceId: props.meta.resourceId },
7
+ query: {
8
+ values: save_btoa(JSON.stringify(redirectToCreatePage())),
9
+ }
10
+ }">
11
+ <IconFileCloneSolid class="w-5 h-5 me-2 text-lightPrimary dark:text-darkPrimary"/>
12
+ {{ $t('Clone record') }}
13
+ </RouterLink>
14
+ </template>
15
+
16
+ <script lang="ts" setup>
17
+ import { Tooltip } from '@/afcl';
18
+ import { AdminUser, type AdminForthResourceCommon } from '@/types';
19
+ import { IconFileCloneSolid } from '@iconify-prerendered/vue-flowbite';
20
+ import { useI18n } from 'vue-i18n';
21
+
22
+ const { t } = useI18n();
23
+
24
+ const props = defineProps<{
25
+ meta: any,
26
+ resource: AdminForthResourceCommon,
27
+ adminUser: AdminUser,
28
+ record: any,
29
+ updateRecords: Function,
30
+ }>();
31
+
32
+ function redirectToCreatePage() {
33
+ const fieldsToFill = { ...props.resource.columns.filter((col: any) => col.showIn.create === true) }
34
+ let dataToFill = {};
35
+ for (const field of Object.values(fieldsToFill)) {
36
+ if (field.foreignResource) {
37
+ dataToFill[field.name] = props.record[field.name]?.pk
38
+ continue;
39
+ }
40
+ dataToFill[field.name] = props.record[field.name];
41
+ }
42
+ return dataToFill;
43
+ }
44
+
45
+ function save_btoa(str) {
46
+ const cleaned = str.replace(/\uFEFF/g, '');
47
+ return btoa(cleaned);
48
+ }
49
+ </script>
package/dist/index.js CHANGED
@@ -25,10 +25,22 @@ export default class extends AdminForthPlugin {
25
25
  if (!resourceConfig.options.pageInjections.list) {
26
26
  resourceConfig.options.pageInjections.list = {};
27
27
  }
28
- if (!resourceConfig.options.pageInjections.list.customActionIcons) {
29
- resourceConfig.options.pageInjections.list.customActionIcons = [];
28
+ if (this.options.makeCloneButtonAsQuickAction) {
29
+ if (!resourceConfig.options.pageInjections.list.customActionIcons) {
30
+ resourceConfig.options.pageInjections.list.customActionIcons = [];
31
+ }
32
+ resourceConfig.options.pageInjections.list.customActionIcons.push({ file: this.componentPath('CloneRowButton.vue'), meta: { pluginInstanceId: this.pluginInstanceId, resourceId: this.resourceConfig.resourceId } });
33
+ }
34
+ else {
35
+ //TODO: after customActionIconsThreeDotsMenuItems will be released in adminforth.main, remove ts-ignore
36
+ //@ts-ignore
37
+ if (!resourceConfig.options.pageInjections.list.customActionIconsThreeDotsMenuItems) {
38
+ //@ts-ignore
39
+ resourceConfig.options.pageInjections.list.customActionIconsThreeDotsMenuItems = [];
40
+ }
41
+ //@ts-ignore
42
+ resourceConfig.options.pageInjections.list.customActionIconsThreeDotsMenuItems.push({ file: this.componentPath('CloneRowThreeDots.vue'), meta: { pluginInstanceId: this.pluginInstanceId, resourceId: this.resourceConfig.resourceId } });
30
43
  }
31
- resourceConfig.options.pageInjections.list.customActionIcons.push({ file: this.componentPath('CloneRowButton.vue'), meta: { pluginInstanceId: this.pluginInstanceId, resourceId: this.resourceConfig.resourceId } });
32
44
  // simply modify resourceConfig or adminforth.config. You can get access to plugin options via this.options;
33
45
  });
34
46
  }
package/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AdminForthPlugin } from "adminforth";
2
- import type { IAdminForth, IHttpServer, AdminForthResourceColumn, AdminForthResource, IAdminForthHttpResponse, AdminUser, AdminForthComponentDeclaration } from "adminforth";
2
+ import type { IAdminForth, AdminForthResource, AdminForthComponentDeclaration } from "adminforth";
3
3
  import type { PluginOptions } from './types.js';
4
4
 
5
5
 
@@ -20,12 +20,25 @@ export default class extends AdminForthPlugin {
20
20
  if ( !resourceConfig.options.pageInjections.list ) {
21
21
  resourceConfig.options.pageInjections.list = {};
22
22
  }
23
- if ( !resourceConfig.options.pageInjections.list.customActionIcons ) {
24
- resourceConfig.options.pageInjections.list.customActionIcons = [];
23
+ if ( this.options.makeCloneButtonAsQuickAction ) {
24
+ if ( !resourceConfig.options.pageInjections.list.customActionIcons ) {
25
+ resourceConfig.options.pageInjections.list.customActionIcons = [];
26
+ }
27
+ (resourceConfig.options.pageInjections.list.customActionIcons as AdminForthComponentDeclaration[]).push(
28
+ { file: this.componentPath('CloneRowButton.vue'), meta: { pluginInstanceId: this.pluginInstanceId, resourceId: this.resourceConfig.resourceId } }
29
+ );
30
+ } else {
31
+ //TODO: after customActionIconsThreeDotsMenuItems will be released in adminforth.main, remove ts-ignore
32
+ //@ts-ignore
33
+ if ( !resourceConfig.options.pageInjections.list.customActionIconsThreeDotsMenuItems ) {
34
+ //@ts-ignore
35
+ resourceConfig.options.pageInjections.list.customActionIconsThreeDotsMenuItems = [];
36
+ }
37
+ //@ts-ignore
38
+ (resourceConfig.options.pageInjections.list.customActionIconsThreeDotsMenuItems as AdminForthComponentDeclaration[]).push(
39
+ { file: this.componentPath('CloneRowThreeDots.vue'), meta: { pluginInstanceId: this.pluginInstanceId, resourceId: this.resourceConfig.resourceId } }
40
+ );
25
41
  }
26
- (resourceConfig.options.pageInjections.list.customActionIcons as AdminForthComponentDeclaration[]).push(
27
- { file: this.componentPath('CloneRowButton.vue'), meta: { pluginInstanceId: this.pluginInstanceId, resourceId: this.resourceConfig.resourceId } }
28
- );
29
42
 
30
43
  // simply modify resourceConfig or adminforth.config. You can get access to plugin options via this.options;
31
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/clone-row",
3
- "version": "1.1.7",
3
+ "version": "1.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
package/types.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export interface PluginOptions {
2
-
2
+ makeCloneButtonAsQuickAction?: boolean;
3
3
  }