mountain-ui 1.0.55 → 1.0.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/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/src/lib/components/Nothing.svelte +26 -0
- package/src/lib/registry/entityRegistry/components/EntitiesSelector.svelte +41 -0
- package/src/lib/registry/entityRegistry/components/EntityCard.svelte +2 -2
- package/src/lib/registry/entityRegistry/components/EntityFieldContainer.svelte +13 -0
- package/src/lib/registry/entityRegistry/components/EntityForm.svelte +141 -75
- package/src/lib/registry/entityRegistry/components/EntityPage.svelte +5 -147
- package/src/lib/registry/entityRegistry/components/EntryForm.svelte +102 -0
- package/src/lib/registry/entityRegistry/components/EntryPage.svelte +155 -0
- package/src/lib/registry/entityRegistry/components/FieldBinding.svelte +90 -0
- package/src/lib/registry/entityRegistry/components/FieldRow.svelte +71 -0
- package/src/lib/registry/entityRegistry/createEntity.js +6 -0
- package/src/lib/registry/entityRegistry/utils.js +15 -0
- package/src/lib/registry/entryActionRegistry/components/EntryActionButton.svelte +21 -0
- package/src/lib/registry/entryActionRegistry/components/EntryActionsButtons.svelte +18 -0
- package/src/lib/registry/entryActionRegistry/createEntryActionType.js +17 -0
- package/src/lib/registry/entryActionRegistry/registry.svelte.js +48 -0
- package/src/lib/registry/entryActionTypeRegistry/components/EntryActionProperties.svelte +42 -0
- package/src/lib/registry/entryActionTypeRegistry/components/EntryActionTypeCard.svelte +11 -0
- package/src/lib/registry/entryActionTypeRegistry/createEntryActionType.js +24 -0
- package/src/lib/registry/entryActionTypeRegistry/entryActionTypes/PrefillNewEntry/Card.svelte +20 -0
- package/src/lib/registry/entryActionTypeRegistry/entryActionTypes/PrefillNewEntry/Properties.svelte +147 -0
- package/src/lib/registry/entryActionTypeRegistry/entryActionTypes/PrefillNewEntry/component/Binding.svelte +103 -0
- package/src/lib/registry/entryActionTypeRegistry/entryActionTypes/PrefillNewEntry/component/BindingClone.svelte +103 -0
- package/src/lib/registry/entryActionTypeRegistry/entryActionTypes/PrefillNewEntry/index.js +77 -0
- package/src/lib/registry/entryActionTypeRegistry/registerDefaultEntryActionTypes.js +7 -0
- package/src/lib/registry/entryActionTypeRegistry/registry.svelte.js +48 -0
- package/src/lib/registry/fieldTypeRegistry/createFieldType.js +8 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/Lines/index.js +52 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/Link/index.js +3 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/Primary/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/calculation/CalculationColumn/index.js +2 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/calculation/CalculationLine/index.js +2 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/list/ListRadio/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/localisation/LocalisationLand/index.js +2 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/money/MoneyCurrency/index.js +2 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/NumberInt/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/float/NumberFloatDefault/index.js +2 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/float/NumberFloatPercent/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/float/NumberFloatPrice/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/TextTextarea/index.js +2 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharDefault/index.js +2 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharEmail/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharPassword/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharPhone/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharUrl/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeCreatedAt/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeDate/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeDatetime/index.js +2 -1
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeDay/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeHour/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeMonth/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeMonthOfYear/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeUpdatedAt/index.js +1 -0
- package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeYear/index.js +1 -0
- package/src/lib/registry/viewEntriesProfilRegistery/components/ViewEntriesProfilButton.svelte +1 -1
- package/src/lib/registry/viewEntriesProfilRegistery/components/ViewEntriesProfilComponent.svelte +1 -1
- package/src/routes/exemple/[project_normalized_name]/+layout.svelte +16 -2
- package/src/routes/exemple/[project_normalized_name]/[entity_slug]/[entry_id]/+page.svelte +70 -16
- package/src/routes/exemple/[project_normalized_name]/[entity_slug]/create/+page.svelte +19 -3
- package/src/routes/exemple/[project_normalized_name]/actions/+page.svelte +62 -0
- package/src/routes/exemple/[project_normalized_name]/entities/+layout.svelte +5 -0
- package/src/routes/exemple/[project_normalized_name]/entities/+page.svelte +70 -0
- package/src/routes/exemple/[project_normalized_name]/entities/[entity_id]/+page.svelte +8 -0
- package/src/routes/exemple/[project_normalized_name]/entities/create/+page.svelte +6 -0
package/src/lib/registry/entryActionTypeRegistry/entryActionTypes/PrefillNewEntry/Properties.svelte
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import EntitiesSelector from '../../../entityRegistry/components/EntitiesSelector.svelte';
|
|
3
|
+
import EntityFieldContainer from '../../../entityRegistry/components/EntityFieldContainer.svelte';
|
|
4
|
+
import FieldBinding from '../../../entityRegistry/components/FieldBinding.svelte';
|
|
5
|
+
import FieldRow from '../../../entityRegistry/components/FieldRow.svelte';
|
|
6
|
+
import { entityRegistry } from '../../../entityRegistry/registry.svelte';
|
|
7
|
+
import { fieldTypeRegistry } from '../../../fieldTypeRegistry/registry.svelte';
|
|
8
|
+
import { Button } from 'hamzus-ui';
|
|
9
|
+
import Binding from './component/Binding.svelte';
|
|
10
|
+
|
|
11
|
+
let {
|
|
12
|
+
props = $bindable({
|
|
13
|
+
fromEntityId: null,
|
|
14
|
+
toEntityId: null,
|
|
15
|
+
bindings: [
|
|
16
|
+
// {
|
|
17
|
+
// fromFieldId:null,
|
|
18
|
+
// toFieldId:null,
|
|
19
|
+
// bindings:[] // disponible lorsque il y a un type imbriquer comme line
|
|
20
|
+
// }
|
|
21
|
+
]
|
|
22
|
+
}),
|
|
23
|
+
onChange = (props)=>{}
|
|
24
|
+
} = $props();
|
|
25
|
+
|
|
26
|
+
let fromEntityId = $derived(props.fromEntityId);
|
|
27
|
+
let toEntityId = $derived(props.toEntityId);
|
|
28
|
+
|
|
29
|
+
const fromEntity = $derived(entityRegistry.get(fromEntityId));
|
|
30
|
+
const toEntity = $derived(entityRegistry.get(toEntityId));
|
|
31
|
+
|
|
32
|
+
$effect(() => {
|
|
33
|
+
let newProps = {
|
|
34
|
+
fromEntityId: fromEntityId,
|
|
35
|
+
toEntityId: toEntityId
|
|
36
|
+
};
|
|
37
|
+
if (!fromEntity) {
|
|
38
|
+
props = {
|
|
39
|
+
...newProps,
|
|
40
|
+
bindings: []
|
|
41
|
+
};
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let newBindings = [];
|
|
46
|
+
|
|
47
|
+
for (const field of fromEntity.fields) {
|
|
48
|
+
newBindings.push({
|
|
49
|
+
fromFieldId: field.id,
|
|
50
|
+
toFieldId: null,
|
|
51
|
+
bindings: []
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
props = {
|
|
56
|
+
...newProps,
|
|
57
|
+
bindings: [...newBindings]
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
function getBinding(fieldId) {
|
|
62
|
+
return props.bindings?.find((binding) => binding?.fromFieldId === fieldId);
|
|
63
|
+
}
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<div class="props">
|
|
67
|
+
<div class="transfer">
|
|
68
|
+
<EntitiesSelector bind:activeEntityId={fromEntityId}></EntitiesSelector>
|
|
69
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
70
|
+
<path
|
|
71
|
+
d="M14.4291 18.8201C14.2391 18.8201 14.0491 18.7501 13.8991 18.6001C13.6091 18.3101 13.6091 17.8301 13.8991 17.5401L19.4391 12.0001L13.8991 6.46012C13.6091 6.17012 13.6091 5.69012 13.8991 5.40012C14.1891 5.11012 14.6691 5.11012 14.9591 5.40012L21.0291 11.4701C21.3191 11.7601 21.3191 12.2401 21.0291 12.5301L14.9591 18.6001C14.8091 18.7501 14.6191 18.8201 14.4291 18.8201Z"
|
|
72
|
+
fill="#292D32"
|
|
73
|
+
/>
|
|
74
|
+
<path
|
|
75
|
+
d="M20.33 12.75H3.5C3.09 12.75 2.75 12.41 2.75 12C2.75 11.59 3.09 11.25 3.5 11.25H20.33C20.74 11.25 21.08 11.59 21.08 12C21.08 12.41 20.74 12.75 20.33 12.75Z"
|
|
76
|
+
fill="#292D32"
|
|
77
|
+
/>
|
|
78
|
+
</svg>
|
|
79
|
+
|
|
80
|
+
<EntitiesSelector bind:activeEntityId={toEntityId}></EntitiesSelector>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
{#if fromEntity && toEntity}
|
|
84
|
+
{#key `${fromEntityId}-${toEntityId}`}
|
|
85
|
+
<EntityFieldContainer>
|
|
86
|
+
<!-- afficher les fieldId a bind dispo -->
|
|
87
|
+
{#each fromEntity.fields as field, index}
|
|
88
|
+
{#if !field.is_hidden && field.type !== 'primary'}
|
|
89
|
+
{@const binding = getBinding(field.id)}
|
|
90
|
+
|
|
91
|
+
{#if binding}
|
|
92
|
+
<Binding
|
|
93
|
+
slot="right"
|
|
94
|
+
fieldId={binding.fromFieldId}
|
|
95
|
+
{toEntityId}
|
|
96
|
+
props={binding}
|
|
97
|
+
onChange={(newBinding) => {
|
|
98
|
+
props = {
|
|
99
|
+
...props,
|
|
100
|
+
bindings: props.bindings.map((b) =>
|
|
101
|
+
b.fromFieldId === field.id ? { ...newBinding } : b
|
|
102
|
+
)
|
|
103
|
+
};
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
{/if}
|
|
107
|
+
{/if}
|
|
108
|
+
{/each}
|
|
109
|
+
</EntityFieldContainer>
|
|
110
|
+
{/key}
|
|
111
|
+
{/if}
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<style>
|
|
115
|
+
.props {
|
|
116
|
+
display: flex;
|
|
117
|
+
flex-direction: column;
|
|
118
|
+
row-gap: var(--pad-m);
|
|
119
|
+
padding: var(--pad-m);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.transfer {
|
|
123
|
+
width: 100%;
|
|
124
|
+
display: grid;
|
|
125
|
+
grid-template-columns: 1fr 50px 1fr;
|
|
126
|
+
justify-content: space-between;
|
|
127
|
+
}
|
|
128
|
+
.transfer > :global(:nth-child(3n + 1)) {
|
|
129
|
+
justify-self: start;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.transfer > :global(:nth-child(3n + 2)) {
|
|
133
|
+
justify-self: center;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.transfer > :global(:nth-child(3n)) {
|
|
137
|
+
justify-self: end;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.transfer svg {
|
|
141
|
+
width: 24px;
|
|
142
|
+
height: 24px;
|
|
143
|
+
}
|
|
144
|
+
.transfer svg path {
|
|
145
|
+
fill: var(--font-2);
|
|
146
|
+
}
|
|
147
|
+
</style>
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import FieldBinding from '../../../../entityRegistry/components/FieldBinding.svelte';
|
|
3
|
+
import BindingClone from './BindingClone.svelte';
|
|
4
|
+
import FieldRow from '../../../../entityRegistry/components/FieldRow.svelte';
|
|
5
|
+
import { entityRegistry } from '../../../../entityRegistry/registry.svelte';
|
|
6
|
+
import { fieldTypeRegistry } from '../../../../fieldTypeRegistry/registry.svelte';
|
|
7
|
+
import EntityFieldContainer from '../../../../entityRegistry/components/EntityFieldContainer.svelte';
|
|
8
|
+
|
|
9
|
+
let { fieldId, toEntityId, props = null, onChange = (newProps) => {} } = $props();
|
|
10
|
+
|
|
11
|
+
const fromField = $derived(entityRegistry.getField(props.fromFieldId));
|
|
12
|
+
const fromFieldType = $derived(fieldTypeRegistry.get(fromField.type));
|
|
13
|
+
|
|
14
|
+
const toField = $derived(entityRegistry.getField(props.toFieldId));
|
|
15
|
+
const toFieldType = $derived(fieldTypeRegistry.get(toField.type));
|
|
16
|
+
const toEntity = $derived.by(() => {
|
|
17
|
+
const childEntityId = toFieldType.getChildEntityId(toField);
|
|
18
|
+
console.log(childEntityId);
|
|
19
|
+
if (childEntityId) {
|
|
20
|
+
return entityRegistry.get(childEntityId);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
function handleBind(fromFieldId, toFieldId) {
|
|
27
|
+
let newProps = {
|
|
28
|
+
fromFieldId: fromFieldId,
|
|
29
|
+
toFieldId: toFieldId,
|
|
30
|
+
bindings: []
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const field = entityRegistry.getField(toFieldId);
|
|
34
|
+
const fieldType = fieldTypeRegistry.get(field.type);
|
|
35
|
+
|
|
36
|
+
// verifier si il y a du bindings
|
|
37
|
+
const childFieldIds = fieldType.getChildsBindings(field);
|
|
38
|
+
|
|
39
|
+
if (childFieldIds && childFieldIds.length > 0) {
|
|
40
|
+
newProps.bindings = childFieldIds.map((childFieldId) => ({
|
|
41
|
+
fromFieldId: childFieldId,
|
|
42
|
+
toFieldId: null,
|
|
43
|
+
bindings: []
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
props = { ...newProps };
|
|
48
|
+
|
|
49
|
+
onChange(props);
|
|
50
|
+
}
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<FieldRow id={fieldId}>
|
|
54
|
+
<FieldBinding
|
|
55
|
+
onChange={(toFieldId) => {
|
|
56
|
+
handleBind(fieldId, toFieldId);
|
|
57
|
+
}}
|
|
58
|
+
allowedType={(field) => {
|
|
59
|
+
if (field.entity_id != toEntityId) return false;
|
|
60
|
+
|
|
61
|
+
const allowedTypes = fromFieldType.allowBindings;
|
|
62
|
+
|
|
63
|
+
for (const allowedBind of allowedTypes) {
|
|
64
|
+
if (field.type.startsWith(allowedBind)) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return false;
|
|
70
|
+
}}
|
|
71
|
+
slot="right"
|
|
72
|
+
></FieldBinding>
|
|
73
|
+
<div slot="bottom" class="bindings" class:active={props.bindings && props.bindings.length > 0}>
|
|
74
|
+
{#if props.bindings && props.bindings.length > 0}
|
|
75
|
+
<EntityFieldContainer>
|
|
76
|
+
{#each props.bindings as binding, index}
|
|
77
|
+
<BindingClone
|
|
78
|
+
slot="right"
|
|
79
|
+
fieldId={binding.fromFieldId}
|
|
80
|
+
toEntityId={toEntity.id}
|
|
81
|
+
props={binding}
|
|
82
|
+
onChange={(newBinding) => {
|
|
83
|
+
props = {
|
|
84
|
+
...props,
|
|
85
|
+
bindings: props.bindings.map((b) =>
|
|
86
|
+
b.fromFieldId === binding.fromFieldId ? { ...newBinding } : b
|
|
87
|
+
)
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
onChange(props);
|
|
91
|
+
}}
|
|
92
|
+
/>
|
|
93
|
+
{/each}
|
|
94
|
+
</EntityFieldContainer>
|
|
95
|
+
{/if}
|
|
96
|
+
</div>
|
|
97
|
+
</FieldRow>
|
|
98
|
+
|
|
99
|
+
<style>
|
|
100
|
+
.bindings.active {
|
|
101
|
+
padding: var(--pad-m);
|
|
102
|
+
}
|
|
103
|
+
</style>
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import FieldBinding from '../../../../entityRegistry/components/FieldBinding.svelte';
|
|
3
|
+
import Binding from './Binding.svelte';
|
|
4
|
+
import FieldRow from '../../../../entityRegistry/components/FieldRow.svelte';
|
|
5
|
+
import { entityRegistry } from '../../../../entityRegistry/registry.svelte';
|
|
6
|
+
import { fieldTypeRegistry } from '../../../../fieldTypeRegistry/registry.svelte';
|
|
7
|
+
import EntityFieldContainer from '../../../../entityRegistry/components/EntityFieldContainer.svelte';
|
|
8
|
+
|
|
9
|
+
let { fieldId, toEntityId, props = null, onChange = (newProps) => {} } = $props();
|
|
10
|
+
|
|
11
|
+
const fromField = $derived(entityRegistry.getField(props.fromFieldId));
|
|
12
|
+
const fromFieldType = $derived(fieldTypeRegistry.get(fromField.type));
|
|
13
|
+
|
|
14
|
+
const toField = $derived(entityRegistry.getField(props.toFieldId));
|
|
15
|
+
const toFieldType = $derived(fieldTypeRegistry.get(toField.type));
|
|
16
|
+
const toEntity = $derived.by(() => {
|
|
17
|
+
const childEntityId = toFieldType.getChildEntityId(toField);
|
|
18
|
+
console.log(childEntityId);
|
|
19
|
+
if (childEntityId) {
|
|
20
|
+
return entityRegistry.get(childEntityId);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
function handleBind(fromFieldId, toFieldId) {
|
|
27
|
+
let newProps = {
|
|
28
|
+
fromFieldId: fromFieldId,
|
|
29
|
+
toFieldId: toFieldId,
|
|
30
|
+
bindings: []
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const field = entityRegistry.getField(toFieldId);
|
|
34
|
+
const fieldType = fieldTypeRegistry.get(field.type);
|
|
35
|
+
|
|
36
|
+
// verifier si il y a du bindings
|
|
37
|
+
const childFieldIds = fieldType.getChildsBindings(field);
|
|
38
|
+
|
|
39
|
+
if (childFieldIds && childFieldIds.length > 0) {
|
|
40
|
+
newProps.bindings = childFieldIds.map((childFieldId) => ({
|
|
41
|
+
fromFieldId: childFieldId,
|
|
42
|
+
toFieldId: null,
|
|
43
|
+
bindings: []
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
props = { ...newProps };
|
|
48
|
+
|
|
49
|
+
onChange(props);
|
|
50
|
+
}
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<FieldRow id={fieldId}>
|
|
54
|
+
<FieldBinding
|
|
55
|
+
onChange={(toFieldId) => {
|
|
56
|
+
handleBind(fieldId, toFieldId);
|
|
57
|
+
}}
|
|
58
|
+
allowedType={(field) => {
|
|
59
|
+
if (field.entity_id != toEntityId) return false;
|
|
60
|
+
|
|
61
|
+
const allowedTypes = fromFieldType.allowBindings;
|
|
62
|
+
|
|
63
|
+
for (const allowedBind of allowedTypes) {
|
|
64
|
+
if (field.type.startsWith(allowedBind)) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return false;
|
|
70
|
+
}}
|
|
71
|
+
slot="right"
|
|
72
|
+
></FieldBinding>
|
|
73
|
+
<div slot="bottom" class="bindings" class:active={props.bindings && props.bindings.length > 0}>
|
|
74
|
+
{#if props.bindings && props.bindings.length > 0}
|
|
75
|
+
<EntityFieldContainer>
|
|
76
|
+
{#each props.bindings as binding, index}
|
|
77
|
+
<Binding
|
|
78
|
+
slot="right"
|
|
79
|
+
fieldId={binding.fromFieldId}
|
|
80
|
+
toEntityId={toEntity.id}
|
|
81
|
+
props={binding}
|
|
82
|
+
onChange={(newBinding) => {
|
|
83
|
+
props = {
|
|
84
|
+
...props,
|
|
85
|
+
bindings: props.bindings.map((b) =>
|
|
86
|
+
b.fromFieldId === binding.fromFieldId ? { ...newBinding } : b
|
|
87
|
+
)
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
onChange(props);
|
|
91
|
+
}}
|
|
92
|
+
/>
|
|
93
|
+
{/each}
|
|
94
|
+
</EntityFieldContainer>
|
|
95
|
+
{/if}
|
|
96
|
+
</div>
|
|
97
|
+
</FieldRow>
|
|
98
|
+
|
|
99
|
+
<style>
|
|
100
|
+
.bindings.active {
|
|
101
|
+
padding: var(--pad-m);
|
|
102
|
+
}
|
|
103
|
+
</style>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { goto } from '$app/navigation';
|
|
2
|
+
import { page } from '$app/state';
|
|
3
|
+
import { entityRegistry } from '../../../entityRegistry/registry.svelte';
|
|
4
|
+
import { fieldTypeRegistry } from '../../../fieldTypeRegistry/registry.svelte';
|
|
5
|
+
import { createEntryActionType } from '../../createEntryActionType';
|
|
6
|
+
|
|
7
|
+
import Card from './Card.svelte'
|
|
8
|
+
import Properties from './Properties.svelte'
|
|
9
|
+
|
|
10
|
+
export default createEntryActionType({
|
|
11
|
+
type: "prefill-new-entry",
|
|
12
|
+
name: "Préremplir une nouvelle entrée",
|
|
13
|
+
description: "Permet d'ouvrir la page sur un formulaire pour crée une nouvelle entrée deja précomplété avec les infos de l'entrée initial.",
|
|
14
|
+
defaultProps: {
|
|
15
|
+
fromEntityId: null,
|
|
16
|
+
toEntityId: null,
|
|
17
|
+
bindings: [
|
|
18
|
+
// {
|
|
19
|
+
// fromFieldId:null,
|
|
20
|
+
// toFieldId:null,
|
|
21
|
+
// bindings:[] // disponible lorsque il y a un type imbriquer comme line
|
|
22
|
+
// }
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
getEntityIdFromProps: (props)=>{
|
|
26
|
+
return props?.fromEntityId ?? null
|
|
27
|
+
},
|
|
28
|
+
canPerformAction: (entity, entry, props) => {
|
|
29
|
+
if (props.fromEntityId === entity.id) return true
|
|
30
|
+
},
|
|
31
|
+
action: (entity, entry, props) => {
|
|
32
|
+
const toEntity = entityRegistry.get(props?.toEntityId ?? null)
|
|
33
|
+
if (!toEntity) {
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ici il faut convertir l entrée avec les valeur binder
|
|
38
|
+
const newEntryCtx = createNewCtxFromBinding(entity, entry, props.bindings)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
goto(`/exemple/${page.params.project_normalized_name}/${toEntity.slug}/create?prefill=${JSON.stringify(newEntryCtx)}`)
|
|
42
|
+
|
|
43
|
+
},
|
|
44
|
+
components: {
|
|
45
|
+
card: Card,
|
|
46
|
+
properties: Properties,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// fonction pour crée une entrée configuré a partir de l entrée initial et du binding
|
|
51
|
+
export function createNewCtxFromBinding(entity, entry, bindings) {
|
|
52
|
+
|
|
53
|
+
let newEntryCtx = {}
|
|
54
|
+
// parcourir le binding
|
|
55
|
+
for (const entityField of entity.fields) {
|
|
56
|
+
for (const binding of bindings) {
|
|
57
|
+
if (binding.fromFieldId !== entityField.id) continue
|
|
58
|
+
|
|
59
|
+
// récuperer le champs actuel et le prochain champs ou la valeur sera injecter
|
|
60
|
+
const fromField = entityRegistry.getField(binding.fromFieldId, entityField.entity_id)
|
|
61
|
+
const toField = entityRegistry.getField(binding.toFieldId)
|
|
62
|
+
|
|
63
|
+
const valueFromActualEntry = entry[fromField.id] ?? null
|
|
64
|
+
|
|
65
|
+
// il faux peut etre altérer le binding du field en fonction de son type
|
|
66
|
+
const fromFieldType = fieldTypeRegistry.get(fromField.type)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
newEntryCtx[toField.id] = fromFieldType.computeBindings(valueFromActualEntry, fromField, binding.bindings)
|
|
71
|
+
} catch (error) {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return newEntryCtx
|
|
77
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { writable, derived, get } from 'svelte/store';
|
|
2
|
+
|
|
3
|
+
function createEntryActionTypeRegistry() {
|
|
4
|
+
const store = writable({});
|
|
5
|
+
|
|
6
|
+
const all = derived(store, ($entryActionTypes) => Object.values($entryActionTypes));
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
subscribe: store.subscribe,
|
|
10
|
+
|
|
11
|
+
register(entryActionType) {
|
|
12
|
+
store.update((entryActionTypes) => ({
|
|
13
|
+
...entryActionTypes,
|
|
14
|
+
[entryActionType.type]: entryActionType
|
|
15
|
+
}));
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
unregister(type) {
|
|
19
|
+
store.update((entryActionTypes) => {
|
|
20
|
+
const copy = { ...entryActionTypes };
|
|
21
|
+
|
|
22
|
+
delete copy[type];
|
|
23
|
+
|
|
24
|
+
return copy;
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
unregisterAll(type) {
|
|
29
|
+
store.update((entryActionTypes) => {
|
|
30
|
+
return {};
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
get(type) {
|
|
35
|
+
return get(store)[type];
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
select(type) {
|
|
39
|
+
return derived(store, ($entryActionTypes) => $entryActionTypes[type]);
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
getAll() {
|
|
43
|
+
return all;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const entryActionTypeRegistry = createEntryActionTypeRegistry();
|
|
@@ -24,6 +24,14 @@ export function createFieldType(config) {
|
|
|
24
24
|
properties: null
|
|
25
25
|
},
|
|
26
26
|
|
|
27
|
+
|
|
28
|
+
// bindings
|
|
29
|
+
allowBindings:[],
|
|
30
|
+
getChildEntityId: (field) => { return null},
|
|
31
|
+
getChildsBindings: (field) => { return null},
|
|
32
|
+
getMoreFieldBindings: (field) => { return null},
|
|
33
|
+
computeBindings: (value, bindings) => { return value},
|
|
34
|
+
|
|
27
35
|
formatter: (value) => value,
|
|
28
36
|
parser: (value) => value,
|
|
29
37
|
|
|
@@ -6,6 +6,8 @@ import Card from './Card.svelte';
|
|
|
6
6
|
import Input from './Input.svelte';
|
|
7
7
|
import TableView from './TableView.svelte';
|
|
8
8
|
import View from './View.svelte';
|
|
9
|
+
import { entityRegistry } from '../../../entityRegistry/registry.svelte';
|
|
10
|
+
import { createNewCtxFromBinding } from '../../../entryActionTypeRegistry/entryActionTypes/PrefillNewEntry';
|
|
9
11
|
|
|
10
12
|
export default createFieldType({
|
|
11
13
|
type: 'lines',
|
|
@@ -34,6 +36,56 @@ export default createFieldType({
|
|
|
34
36
|
properties: null
|
|
35
37
|
},
|
|
36
38
|
|
|
39
|
+
|
|
40
|
+
allowBindings:["lines"],
|
|
41
|
+
getChildsBindings:(field)=>{
|
|
42
|
+
if (!field.props.linkId) return null;
|
|
43
|
+
|
|
44
|
+
const lineEntity = entityRegistry.get(field.props.linkId)
|
|
45
|
+
|
|
46
|
+
return lineEntity.fields.map(f=>f.id)
|
|
47
|
+
},
|
|
48
|
+
getChildEntityId:(field)=>{
|
|
49
|
+
if (!field.props.linkId) return null;
|
|
50
|
+
|
|
51
|
+
return parseInt(field.props.linkId)
|
|
52
|
+
},
|
|
53
|
+
getMoreFieldBindings:(field)=>{
|
|
54
|
+
if (!field.props.columns) return null;
|
|
55
|
+
|
|
56
|
+
let allFieldIds = []
|
|
57
|
+
|
|
58
|
+
for (const column of field.props.columns) {
|
|
59
|
+
for (const columnRow of column.rows) {
|
|
60
|
+
allFieldIds.push(columnRow.fieldId)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return allFieldIds
|
|
65
|
+
},
|
|
66
|
+
computeBindings:(value, field, bindings)=>{
|
|
67
|
+
if (!value) return value;
|
|
68
|
+
if (!field.props.linkId) return value;
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const lineEntity = entityRegistry.get(field.props.linkId)
|
|
72
|
+
|
|
73
|
+
if (!lineEntity) return value;
|
|
74
|
+
|
|
75
|
+
const lines = JSON.parse(value)
|
|
76
|
+
|
|
77
|
+
let newLines = []
|
|
78
|
+
|
|
79
|
+
for (const lineCtx of lines) {
|
|
80
|
+
const newLineCtx = createNewCtxFromBinding(lineEntity, lineCtx, bindings)
|
|
81
|
+
|
|
82
|
+
newLines.push(newLineCtx)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return JSON.stringify(newLines)
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
|
|
37
89
|
formatter: (value) => value,
|
|
38
90
|
parser: (value) => value,
|
|
39
91
|
|