Skip to content

Commit 3489a2f

Browse files
committed
Merge branch 'main' of github.com:devforth/adminforth
AdminForth/1746/add-missing-resource-registrat AdminForth/1746/add-missing-resource-registrat
2 parents 1af1a55 + f0611e7 commit 3489a2f

7 files changed

Lines changed: 81 additions & 12 deletions

File tree

adminforth/documentation/docs/tutorial/03-Customization/02-customFieldRendering.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ For fields containing sensitive data (like passwords, API keys, tokens, or other
605605
606606
The renderer wraps the standard value output and adds a click-to-reveal blur effect. Clicking again hides the value.
607607
608-
For long values (like API keys) you can enable compact mode by passing `compact: true` via `meta`. When set, the value is shortened the same way as the `CompactUUID` renderer (first 4 + `...` + last 4 characters). In compact mode you can additionally pass `copy: true` to render a copy-to-clipboard button next to the value:
608+
For long values (like API keys) you can enable compact mode by passing `compact: true` via `meta`. When set, the value is shortened the same way as the `CompactUUID` renderer (first 4 + `...` + last 4 characters). In compact mode you can additionally pass `copy: true` to render a copy-to-clipboard button next to the value. The copy button is only shown once the value is revealed (blur removed):
609609
610610
```ts title='./resources/anyResource.ts'
611611
columns: [

adminforth/documentation/docs/tutorial/03-Customization/04-hooks.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ When user opens edit page, AdminForth makes a request to the backend to get the
4242

4343
![Initial data for edit page flow](get_resource_data.png)
4444

45-
Practically you can use `show.afterDatasourceResponse` to modify or add some data before it is displayed on the edit page.
45+
Practically you can use `show.afterDatasourceResponse` to modify or add some data before it is displayed on the edit page. In other words, at this stage you can enrich the data with some additional metadata which might be handy on edit page for custom Vue fields.
4646

47-
For example [upload plugin](/docs/tutorial/Plugins/upload/) uses this hook to generate signed preview URL so user can see existing uploaded file preview in form, and at the same time database stores only original file path which might be not accessible without presigned URL.
47+
For example [upload plugin](/docs/tutorial/Plugins/upload/) uses this hook to generate signed preview URL so user can see existing uploaded file preview in form, and at the same time database stores only original file path which might be not accessible without presigned URL.
4848

4949
## Saving data on edit page
5050

@@ -177,6 +177,28 @@ For example, you can change the way columns value is displayed by changing the v
177177
}
178178
```
179179

180+
Also you can use this hook to enrich the returned records list with some additional data fields which might be handy for custom Vue components defined in `components.list` or `components.show` for this resource. For example you can use [key-value adapter](/docs/tutorial/06-Adapters/07-key-value-adapters/) to get some global configuration values and add them to each record in the list:
181+
182+
```ts title='./resources/apartments.ts'
183+
184+
{
185+
...
186+
hooks: {
187+
list: {
188+
//diff-add
189+
afterDatasourceResponse: async ({ response }: { response: any }) => {
190+
//diff-add
191+
response.forEach((r: any) => {
192+
const taxRate = await kvAdapter.getValue('taxRate');
193+
r.priceWithTax = r.price * (1 + taxRate);
194+
});
195+
return { ok: true, error: "" };
196+
},
197+
},
198+
},
199+
}
200+
```
201+
180202
### Dropdown list of foreignResource
181203

182204
By default if there is `foreignResource` like we use for demo on `realtor_id` column, the filter will suggest a

adminforth/documentation/docs/tutorial/06-Adapters/07-key-value-adapters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
description: "Reference page for AdminForth key-value adapters, including RAM, Redis, and LevelDB backends for temporary state, caching, and plugin storage."
2+
description: "Reference page for prebuilt key-value adapters created by AdminForth team, including simplest RAM Adapter (in-memory, no dependencies but ephemeral), Redis-based adapter, LevelDB - based (requires a mounted volume DevOps), Resource-based (Works on top of a resource persistable with your native SQL/NoSQL database)"
33
---
44

55
# Key-value Adapters

adminforth/spa/src/renderers/SensitiveBlurCell.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
</template>
2323
</Tooltip>
2424

25-
<IconFileCopyAltSolid
26-
v-if="showCopy && rawValue"
27-
@click.stop="copyToCB"
28-
class="shrink-0 min-w-5 min-h-5 cursor-pointer text-lightPrimary dark:text-darkPrimary"
29-
/>
25+
<span v-if="showCopy && rawValue" class="shrink-0 w-5 h-5">
26+
<IconFileCopyAltSolid
27+
v-if="show"
28+
@click.stop="copyToCB"
29+
class="w-5 h-5 cursor-pointer text-lightPrimary dark:text-darkPrimary"
30+
/>
31+
</span>
3032
</div>
3133
</template>
3234

adminforth/spa/src/stores/toast.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ref, watch, type Ref } from 'vue'
22
import { defineStore } from 'pinia'
33
import { useRoute } from 'vue-router';
4+
import { randomBrowserUUID } from '@/utils/browserUuid';
45

56

67

@@ -22,7 +23,7 @@ export const useToastStore = defineStore('toast', () => {
2223
buttons?: { value: any; label: string }[];
2324
onResolve?: (value?: any) => void;
2425
}): string => {
25-
const toastId = crypto.randomUUID();
26+
const toastId = randomBrowserUUID();
2627
toasts.value.push({
2728
...toast,
2829
id: toastId,
@@ -45,4 +46,4 @@ export const useToastStore = defineStore('toast', () => {
4546
};
4647

4748
return { toasts, addToast, removeToast, resolveToast };
48-
});
49+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const UUID_BYTE_LENGTH = 16;
2+
3+
const UUID_HEX = Array.from(
4+
{ length: 256 },
5+
(_, index) => index.toString(16).padStart(2, '0'),
6+
);
7+
8+
export function randomBrowserUUID(): string {
9+
if (typeof crypto.randomUUID === 'function') {
10+
return crypto.randomUUID();
11+
}
12+
13+
const bytes = crypto.getRandomValues(
14+
new Uint8Array(UUID_BYTE_LENGTH),
15+
);
16+
17+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
18+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
19+
20+
return [
21+
UUID_HEX[bytes[0]],
22+
UUID_HEX[bytes[1]],
23+
UUID_HEX[bytes[2]],
24+
UUID_HEX[bytes[3]],
25+
'-',
26+
UUID_HEX[bytes[4]],
27+
UUID_HEX[bytes[5]],
28+
'-',
29+
UUID_HEX[bytes[6]],
30+
UUID_HEX[bytes[7]],
31+
'-',
32+
UUID_HEX[bytes[8]],
33+
UUID_HEX[bytes[9]],
34+
'-',
35+
UUID_HEX[bytes[10]],
36+
UUID_HEX[bytes[11]],
37+
UUID_HEX[bytes[12]],
38+
UUID_HEX[bytes[13]],
39+
UUID_HEX[bytes[14]],
40+
UUID_HEX[bytes[15]],
41+
].join('');
42+
}

adminforth/spa/src/utils/clientId.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { randomBrowserUUID } from './browserUuid';
2+
13
const ADMINFORTH_CLIENT_ID_STORAGE_KEY = 'adminforthClientId';
24

35
export const ADMINFORTH_CLIENT_ID_HEADER = 'x-adminforth-client-id';
@@ -8,7 +10,7 @@ export function getAdminForthClientId(): string {
810
return existingClientId;
911
}
1012

11-
const clientId = crypto.randomUUID();
13+
const clientId = randomBrowserUUID();
1214
sessionStorage.setItem(ADMINFORTH_CLIENT_ID_STORAGE_KEY, clientId);
1315
return clientId;
1416
}

0 commit comments

Comments
 (0)