mountain-ui 1.0.28 → 1.0.30

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.
Files changed (103) hide show
  1. package/package.json +1 -1
  2. package/src/lib/registry/entityRegistry/components/EntityPage.svelte +158 -0
  3. package/src/lib/registry/entityRegistry/components/FieldTableView.svelte +23 -0
  4. package/src/lib/registry/entityRegistry/components/FieldView.svelte +24 -0
  5. package/src/lib/registry/entityRegistry/createEntity.js +2 -0
  6. package/src/lib/registry/fieldTypeRegistry/components/FieldTypeTableView.svelte +11 -0
  7. package/src/lib/registry/fieldTypeRegistry/components/FieldTypeView.svelte +11 -0
  8. package/src/lib/registry/fieldTypeRegistry/components/LineView.svelte +33 -0
  9. package/src/lib/registry/fieldTypeRegistry/components/ViewText.svelte +5 -0
  10. package/src/lib/registry/fieldTypeRegistry/fieldTypes/Lines/View.svelte +61 -0
  11. package/src/lib/registry/fieldTypeRegistry/fieldTypes/Link/TableView.svelte +8 -0
  12. package/src/lib/registry/fieldTypeRegistry/fieldTypes/Link/View.svelte +19 -0
  13. package/src/lib/registry/fieldTypeRegistry/fieldTypes/Link/index.js +4 -1
  14. package/src/lib/registry/fieldTypeRegistry/fieldTypes/Primary/TableView.svelte +8 -0
  15. package/src/lib/registry/fieldTypeRegistry/fieldTypes/Primary/View.svelte +15 -0
  16. package/src/lib/registry/fieldTypeRegistry/fieldTypes/Primary/index.js +4 -1
  17. package/src/lib/registry/fieldTypeRegistry/fieldTypes/calculation/CalculationColumn/TableView.svelte +8 -0
  18. package/src/lib/registry/fieldTypeRegistry/fieldTypes/calculation/CalculationColumn/View.svelte +52 -0
  19. package/src/lib/registry/fieldTypeRegistry/fieldTypes/calculation/CalculationColumn/index.js +4 -1
  20. package/src/lib/registry/fieldTypeRegistry/fieldTypes/calculation/CalculationLine/Button.svelte +8 -0
  21. package/src/lib/registry/fieldTypeRegistry/fieldTypes/calculation/CalculationLine/Card.svelte +6 -0
  22. package/src/lib/registry/fieldTypeRegistry/fieldTypes/calculation/CalculationLine/Icon.svelte +30 -0
  23. package/src/lib/registry/fieldTypeRegistry/fieldTypes/calculation/CalculationLine/Input.svelte +153 -0
  24. package/src/lib/registry/fieldTypeRegistry/fieldTypes/calculation/CalculationLine/TableView.svelte +8 -0
  25. package/src/lib/registry/fieldTypeRegistry/fieldTypes/calculation/CalculationLine/View.svelte +52 -0
  26. package/src/lib/registry/fieldTypeRegistry/fieldTypes/calculation/CalculationLine/index.js +41 -0
  27. package/src/lib/registry/fieldTypeRegistry/fieldTypes/list/ListCheckbox/TableView.svelte +28 -0
  28. package/src/lib/registry/fieldTypeRegistry/fieldTypes/list/ListCheckbox/View.svelte +31 -0
  29. package/src/lib/registry/fieldTypeRegistry/fieldTypes/list/ListCheckbox/index.js +4 -1
  30. package/src/lib/registry/fieldTypeRegistry/fieldTypes/list/ListRadio/TableView.svelte +13 -0
  31. package/src/lib/registry/fieldTypeRegistry/fieldTypes/list/ListRadio/View.svelte +18 -0
  32. package/src/lib/registry/fieldTypeRegistry/fieldTypes/list/ListRadio/index.js +4 -1
  33. package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/NumberInt/TableView.svelte +8 -0
  34. package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/NumberInt/View.svelte +12 -0
  35. package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/NumberInt/index.js +4 -1
  36. package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/float/NumberFloatDefault/TableView.svelte +8 -0
  37. package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/float/NumberFloatDefault/View.svelte +12 -0
  38. package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/float/NumberFloatDefault/index.js +4 -1
  39. package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/float/NumberFloatPercent/TableView.svelte +8 -0
  40. package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/float/NumberFloatPercent/View.svelte +12 -0
  41. package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/float/NumberFloatPercent/index.js +4 -1
  42. package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/float/NumberFloatPrice/TableView.svelte +8 -0
  43. package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/float/NumberFloatPrice/View.svelte +12 -0
  44. package/src/lib/registry/fieldTypeRegistry/fieldTypes/number/float/NumberFloatPrice/index.js +4 -1
  45. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/TextTextarea/TableView.svelte +8 -0
  46. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/TextTextarea/View.svelte +12 -0
  47. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/TextTextarea/index.js +4 -1
  48. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharDefault/TableView.svelte +8 -0
  49. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharDefault/View.svelte +12 -0
  50. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharDefault/index.js +4 -1
  51. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharEmail/TableView.svelte +8 -0
  52. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharEmail/View.svelte +13 -0
  53. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharEmail/index.js +4 -1
  54. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharPassword/TableView.svelte +8 -0
  55. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharPassword/View.svelte +12 -0
  56. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharPassword/index.js +4 -1
  57. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharPhone/TableView.svelte +8 -0
  58. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharPhone/View.svelte +13 -0
  59. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharPhone/index.js +4 -1
  60. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharUrl/TableView.svelte +8 -0
  61. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharUrl/View.svelte +24 -0
  62. package/src/lib/registry/fieldTypeRegistry/fieldTypes/text/varchar/TextVarcharUrl/index.js +4 -1
  63. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeCreatedAt/TableView.svelte +9 -0
  64. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeCreatedAt/View.svelte +13 -0
  65. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeCreatedAt/index.js +4 -1
  66. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeDate/TableView.svelte +9 -0
  67. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeDate/View.svelte +13 -0
  68. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeDate/index.js +4 -1
  69. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeDatetime/TableView.svelte +9 -0
  70. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeDatetime/View.svelte +13 -0
  71. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeDatetime/index.js +4 -1
  72. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeDay/TableView.svelte +8 -0
  73. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeDay/View.svelte +12 -0
  74. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeDay/index.js +4 -1
  75. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeHour/TableView.svelte +8 -0
  76. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeHour/View.svelte +12 -0
  77. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeHour/index.js +4 -1
  78. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeMonth/TableView.svelte +8 -0
  79. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeMonth/View.svelte +12 -0
  80. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeMonth/index.js +4 -1
  81. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeMonthOfYear/TableView.svelte +8 -0
  82. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeMonthOfYear/View.svelte +12 -0
  83. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeMonthOfYear/index.js +4 -1
  84. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeUpdatedAt/TableView.svelte +9 -0
  85. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeUpdatedAt/View.svelte +13 -0
  86. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeUpdatedAt/index.js +4 -1
  87. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeYear/TableView.svelte +8 -0
  88. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeYear/View.svelte +12 -0
  89. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/TimeYear/index.js +4 -1
  90. package/src/lib/registry/fieldTypeRegistry/fieldTypes/time/formatDate.js +155 -0
  91. package/src/lib/registry/fieldTypeRegistry/registerDefaultFieldTypes.js +2 -0
  92. package/src/lib/registry/viewTypeRegistry/components/ViewTypeButton.svelte +27 -0
  93. package/src/lib/registry/viewTypeRegistry/components/ViewTypeComponent.svelte +30 -0
  94. package/src/lib/registry/viewTypeRegistry/createViewType.js +17 -0
  95. package/src/lib/registry/viewTypeRegistry/registerDefaultViewTypes.js +7 -0
  96. package/src/lib/registry/viewTypeRegistry/registry.svelte.js +44 -0
  97. package/src/lib/registry/viewTypeRegistry/viewTypes/Table/Icon.svelte +16 -0
  98. package/src/lib/registry/viewTypeRegistry/viewTypes/Table/component/Component copy.svelte +11 -0
  99. package/src/lib/registry/viewTypeRegistry/viewTypes/Table/component/Component.svelte +12 -0
  100. package/src/lib/registry/viewTypeRegistry/viewTypes/Table/component/StructureTable.svelte +287 -0
  101. package/src/lib/registry/viewTypeRegistry/viewTypes/Table/index.js +14 -0
  102. package/src/routes/+layout.svelte +31 -1
  103. package/src/routes/+page.svelte +22 -1
@@ -0,0 +1,155 @@
1
+
2
+ export function formatDateFromTimestamp(timestamp) {
3
+ // Créer une instance Date à partir du timestamp
4
+ const date = new Date(timestamp);
5
+
6
+ // Utiliser Intl.DateTimeFormat pour formater la date
7
+ const formatter = new Intl.DateTimeFormat('fr-FR', {
8
+ year: 'numeric',
9
+ month: '2-digit',
10
+ day: '2-digit',
11
+ hour: '2-digit',
12
+ minute: '2-digit',
13
+ second: '2-digit',
14
+ hour12: false // Utiliser l'heure au format 24 heures
15
+ });
16
+
17
+ // Formatage de la date avec Intl.DateTimeFormat
18
+ const parts = formatter.formatToParts(date);
19
+
20
+ // Extraire les différentes parties de la date
21
+ const year = parts.find(part => part.type === 'year').value;
22
+ const month = parts.find(part => part.type === 'month').value;
23
+ const day = parts.find(part => part.type === 'day').value;
24
+ const hour = parts.find(part => part.type === 'hour').value;
25
+ const minute = parts.find(part => part.type === 'minute').value;
26
+ const second = parts.find(part => part.type === 'second').value;
27
+
28
+ // Formater la date selon le format souhaité
29
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
30
+ }
31
+
32
+ export function formatDate(dateOrigine) {
33
+ dateOrigine = new Date(dateOrigine);
34
+
35
+ // Extraction des composants de la date
36
+ let annee = dateOrigine.getFullYear();
37
+ let mois = dateOrigine.getMonth() + 1; // Les mois commencent à 0, donc ajoutez 1
38
+ let jour = dateOrigine.getDate();
39
+
40
+ // Formatage des composants de la date
41
+ let dateFormatee = (jour < 10 ? '0' : '') + jour + '/' +
42
+ (mois < 10 ? '0' : '') + mois + '/' +
43
+ annee
44
+ return dateFormatee;
45
+ }
46
+
47
+ export function formatDateTime(dateOrigine) {
48
+ dateOrigine = new Date(convertToLocalDateTime(dateOrigine));
49
+
50
+ // Extraction des composants de la date
51
+ let annee = dateOrigine.getFullYear();
52
+ let mois = dateOrigine.getMonth() + 1; // Les mois commencent à 0, donc ajoutez 1
53
+ let jour = dateOrigine.getDate();
54
+ let heures = dateOrigine.getHours();
55
+ let minutes = dateOrigine.getMinutes();
56
+ let secondes = dateOrigine.getSeconds();
57
+
58
+ // Formatage des composants de la date
59
+ let dateFormatee = (jour < 10 ? '0' : '') + jour + '/' +
60
+ (mois < 10 ? '0' : '') + mois + '/' +
61
+ annee + ' à ' +
62
+ (heures < 10 ? '0' : '') + heures + ':' +
63
+ (minutes < 10 ? '0' : '') + minutes + ":" +
64
+ (secondes < 10 ? '0' : '') + secondes;
65
+ return dateFormatee;
66
+ }
67
+ export function formatTime(dateOrigine) {
68
+ dateOrigine = new Date(convertToLocalDateTime(dateOrigine));
69
+
70
+ let heures = dateOrigine.getHours();
71
+ let minutes = dateOrigine.getMinutes();
72
+
73
+ // Formatage des composants de la date
74
+ let dateFormatee = (heures < 10 ? '0' : '') + heures + 'h' +
75
+ (minutes < 10 ? '0' : '') + minutes;
76
+ return dateFormatee;
77
+ }
78
+ export function convertirSec(secondes) {
79
+ const heures = Math.floor(secondes / 3600);
80
+ let minutes = Math.floor((secondes % 3600) / 60);
81
+ if (heures !== 0) {
82
+ minutes = minutes.toString().length == 1 ? '0' + minutes : minutes
83
+
84
+ return `${heures}h${minutes}`;
85
+ }else{
86
+ return `${minutes}min`;
87
+ }
88
+ }
89
+
90
+ export function formatMonth(dateString) {
91
+ const date = new Date(dateString);
92
+
93
+ // Formatage en "mois année" (par exemple, "octobre 2024" en français)
94
+ const options = { year: 'numeric', month: 'long' };
95
+ return new Intl.DateTimeFormat('fr-FR', options).format(date);
96
+ }
97
+ export function timeSince(date) {
98
+ const now = new Date();
99
+ const past = new Date(convertToLocalDateTime(date));
100
+ const diffMs = now - past; // en millisecondes
101
+
102
+ const seconds = Math.floor(diffMs / 1000);
103
+ const minutes = Math.floor(diffMs / (1000 * 60));
104
+ const hours = Math.floor(diffMs / (1000 * 60 * 60));
105
+ const days = Math.floor(diffMs / (1000 * 60 * 60 * 24));
106
+
107
+ if (seconds < 60) {
108
+ return `il y a ${seconds} sec`;
109
+ } else if (minutes < 60) {
110
+ return `il y a ${minutes} min`;
111
+ } else if (hours < 24) {
112
+ return `il y a ${hours} h`;
113
+ } else {
114
+ return `il y a ${days} j`;
115
+ }
116
+ }
117
+
118
+ export function convertToLocalDateTime(Datetime) {
119
+ // Convertir la chaîne en objet Date UTC
120
+ const utcDate = new Date(Datetime.replace(' ', 'T') + 'Z');
121
+
122
+ // Extraire les composants de la date locale
123
+ const year = utcDate.getFullYear();
124
+ const month = String(utcDate.getMonth() + 1).padStart(2, '0'); // Mois de 0 à 11, on ajoute donc 1
125
+ const day = String(utcDate.getDate()).padStart(2, '0');
126
+
127
+ // Extraire les composants de l'heure locale
128
+ const hours = String(utcDate.getHours()).padStart(2, '0');
129
+ const minutes = String(utcDate.getMinutes()).padStart(2, '0');
130
+ const seconds = String(utcDate.getSeconds()).padStart(2, '0');
131
+
132
+ // Formater la date et l'heure en YYYY-MM-DD HH:mm:SS
133
+ const localDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
134
+
135
+ return localDateTime;
136
+ }
137
+ export function convertToLocalDateTimeForDateTime(Datetime) {
138
+ // Convertir la chaîne en objet Date UTC
139
+ const utcDate = new Date(Datetime.replace(' ', 'T') + 'Z');
140
+
141
+ // Extraire les composants de la date locale
142
+ const year = utcDate.getFullYear();
143
+ const month = String(utcDate.getMonth() + 1).padStart(2, '0'); // Mois de 0 à 11, on ajoute donc 1
144
+ const day = String(utcDate.getDate()).padStart(2, '0');
145
+
146
+ // Extraire les composants de l'heure locale
147
+ const hours = String(utcDate.getHours()).padStart(2, '0');
148
+ const minutes = String(utcDate.getMinutes()).padStart(2, '0');
149
+
150
+ // Formater la date et l'heure en YYYY-MM-DD HH:mm:SS
151
+ const localDateTime = `${year}-${month}-${day} ${hours}:${minutes}`;
152
+
153
+ return localDateTime;
154
+ }
155
+
@@ -6,6 +6,7 @@ import NumberFloatDefault from './fieldTypes/number/float/NumberFloatDefault';
6
6
  import NumberFloatPrice from './fieldTypes/number/float/NumberFloatPrice';
7
7
  import NumberFloatPercent from './fieldTypes/number/float/NumberFloatPercent';
8
8
  import CalculationColumn from './fieldTypes/calculation/CalculationColumn';
9
+ import CalculationLine from './fieldTypes/calculation/CalculationLine';
9
10
  import TextTextarea from './fieldTypes/text/TextTextarea';
10
11
  import TextVarcharDefault from './fieldTypes/text/varchar/TextVarcharDefault';
11
12
  import TextVarcharEmail from './fieldTypes/text/varchar/TextVarcharEmail';
@@ -35,6 +36,7 @@ export function registerDefaultFieldTypes() {
35
36
  fieldTypeRegistry.register(NumberFloatPercent);
36
37
  // calculation
37
38
  fieldTypeRegistry.register(CalculationColumn);
39
+ fieldTypeRegistry.register(CalculationLine);
38
40
  // text
39
41
  fieldTypeRegistry.register(TextTextarea);
40
42
 
@@ -0,0 +1,27 @@
1
+ <script>
2
+ import { Button } from 'hamzus-ui';
3
+ import { viewTypeRegistry } from '../registry.svelte';
4
+
5
+ let { type, variant = 'ghost', ...props } = $props();
6
+
7
+ const viewType = viewTypeRegistry.get(type);
8
+ </script>
9
+
10
+ {#if viewType}
11
+ <Button {...props} {variant} style="padding:var(--pad-s) var(--pad-l) var(--pad-s) var(--pad-s);width:100%;">
12
+ <div class="ico">
13
+ <svelte:component this={viewType.components.icon}></svelte:component>
14
+ </div>
15
+ <h5>{viewType.name}</h5>
16
+ </Button>
17
+ {/if}
18
+
19
+ <style>
20
+ .ico {
21
+ display: flex;
22
+ align-items: center;
23
+ justify-content: center;
24
+ width: 16px;
25
+ height: 16px;
26
+ }
27
+ </style>
@@ -0,0 +1,30 @@
1
+ <script>
2
+ import { Button, RotativeLoader } from 'hamzus-ui';
3
+ import { viewTypeRegistry } from '../registry.svelte';
4
+
5
+ let { type, ...props } = $props();
6
+
7
+ const viewType = viewTypeRegistry.get(type);
8
+
9
+ console.log(viewType);
10
+
11
+ </script>
12
+
13
+ {#if viewType}
14
+ <svelte:component this={viewType.components.component} {...props}></svelte:component>
15
+ {:else}
16
+ <div class="loader">
17
+ <RotativeLoader></RotativeLoader>
18
+ </div>
19
+ {/if}
20
+
21
+ <style>
22
+
23
+ .loader {
24
+ display: flex;
25
+ align-items: center;
26
+ justify-content: center;
27
+ padding: 60px var(--pad-m);
28
+ }
29
+ </style>
30
+
@@ -0,0 +1,17 @@
1
+ export function createViewType(config = {}) {
2
+ const viewType = {
3
+ type:"",
4
+ name:"",
5
+ description:"",
6
+ components : {
7
+ component:null,
8
+ icon:null,
9
+ }
10
+ };
11
+
12
+ Object.assign(viewType, config);
13
+
14
+ // viewType.get = () => "test";
15
+
16
+ return viewType;
17
+ }
@@ -0,0 +1,7 @@
1
+ import { viewTypeRegistry } from './registry.svelte';
2
+ import Table from './viewTypes/Table';
3
+
4
+
5
+ export function registerDefaultViewTypes() {
6
+ viewTypeRegistry.register(Table)
7
+ }
@@ -0,0 +1,44 @@
1
+ import { writable, derived, get } from 'svelte/store';
2
+
3
+ function createViewTypeRegistry() {
4
+ const store = writable({});
5
+
6
+ const all = derived(store, ($viewTypes) => Object.values($viewTypes));
7
+
8
+ return {
9
+ subscribe: store.subscribe,
10
+
11
+ register(viewType) {
12
+ store.update((viewTypes) => ({
13
+ ...viewTypes,
14
+ [viewType.type]: viewType
15
+ }));
16
+ },
17
+
18
+ unregister(type) {
19
+ store.update((viewTypes) => {
20
+ const copy = { ...viewTypes };
21
+
22
+ delete copy[type];
23
+
24
+ return copy;
25
+ });
26
+ },
27
+
28
+ get(type) {
29
+ return get(store)[type];
30
+ },
31
+
32
+ select(type) {
33
+ return derived(store, ($viewTypes) => $viewTypes[type]);
34
+ },
35
+
36
+
37
+
38
+ getAll() {
39
+ return all;
40
+ }
41
+ };
42
+ }
43
+
44
+ export const viewTypeRegistry = createViewTypeRegistry();
@@ -0,0 +1,16 @@
1
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path
3
+ d="M4.1 11L19.9 11C21.4 11 22 10.36 22 8.77L22 4.73C22 3.14 21.4 2.5 19.9 2.5L4.1 2.5C2.6 2.5 2 3.14 2 4.73L2 8.77C2 10.36 2.6 11 4.1 11Z"
4
+ fill="#00C0E8"
5
+ />
6
+ <path
7
+ opacity="0.4"
8
+ d="M13.1 21.5L19.9 21.5C21.4 21.5 22 20.86 22 19.27L22 15.23C22 13.64 21.4 13 19.9 13L13.1 13C11.6 13 11 13.64 11 15.23L11 19.27C11 20.86 11.6 21.5 13.1 21.5Z"
9
+ fill="#00C0E8"
10
+ />
11
+ <path
12
+ opacity="0.4"
13
+ d="M4.1 21.5L6.9 21.5C8.4 21.5 9 20.86 9 19.27L9 15.23C9 13.64 8.4 13 6.9 13L4.1 13C2.6 13 2 13.64 2 15.23L2 19.27C2 20.86 2.6 21.5 4.1 21.5Z"
14
+ fill="#00C0E8"
15
+ />
16
+ </svg>
@@ -0,0 +1,11 @@
1
+ <script>
2
+ import { page } from '$app/stores';
3
+ import { Button, DropdownMenu, IconButton } from 'hamzus-ui';
4
+ import StructureTable from './StructureTable.svelte';
5
+
6
+ let { structureId = 0, columns = [], defaultProps = null, ...props } = $props();
7
+ </script>
8
+
9
+ <StructureTable bind:defaultProps structureColumns={columns} {structureId} {...props}>
10
+ <slot slot="actions" name="actions"></slot>
11
+ </StructureTable>
@@ -0,0 +1,12 @@
1
+ <script>
2
+ import { page } from '$app/stores';
3
+ import { Button, DropdownMenu, IconButton } from 'hamzus-ui';
4
+ import StructureTable from './StructureTable.svelte';
5
+
6
+ let { entityId, ...props } = $props();
7
+
8
+ </script>
9
+
10
+ <StructureTable {entityId} {...props}>
11
+ <slot slot="actions" name="actions"></slot>
12
+ </StructureTable>
@@ -0,0 +1,287 @@
1
+ <script>
2
+ // import
3
+ import { RotativeLoader, sendRequest, TableV2 } from 'hamzus-ui';
4
+ import { page } from '$app/stores';
5
+ import { onMount } from 'svelte';
6
+ import { goto } from '$app/navigation';
7
+ import { fieldTypeRegistry } from '$lib/registry/fieldTypeRegistry/registry.svelte';
8
+ import { entityRegistry } from '$lib/registry/entityRegistry/registry.svelte';
9
+
10
+ let {
11
+ entityId = null,
12
+ path = '/get-all-entries',
13
+ data = {},
14
+ slug = null,
15
+ onChange = () => {},
16
+ invisibleFilters = {},
17
+ structureColumns = [],
18
+ defaultColumns = {},
19
+ defaultProps = {},
20
+ ...props
21
+ } = $props();
22
+
23
+ const entity = entityRegistry.select(entityId);
24
+
25
+ let error = $state(null);
26
+
27
+ let mounted = false;
28
+
29
+ let columns = $state([]);
30
+
31
+ $effect(() => {
32
+ getColumnsFromStructureColumns($entity);
33
+ });
34
+
35
+ onMount(() => {
36
+ mounted = true;
37
+ getColumnsFromStructureColumns($entity);
38
+ });
39
+
40
+ // function
41
+ function getColumnsFromStructureColumns(entity) {
42
+ // on evite d'executé coté serveur
43
+ if (!mounted) {
44
+ return;
45
+ }
46
+
47
+ // parcourir les colonne et generer l objet columns pour le composant table
48
+ let columnsList = [];
49
+
50
+ for (const field of entity.fields) {
51
+ if (field.is_hidden) {
52
+ continue;
53
+ }
54
+
55
+ let additionalData = {};
56
+
57
+ const fieldType = fieldTypeRegistry.get(field.type);
58
+
59
+ if (fieldType.tableAttributes) {
60
+ if (typeof fieldType.tableAttributes === 'function') {
61
+ additionalData = fieldType.tableAttributes(field.props);
62
+ } else {
63
+ additionalData = fieldType.tableAttributes;
64
+ }
65
+ }
66
+
67
+ // si il y a un composent de visualisation on l ajoute
68
+ if (fieldType.components.tableView) {
69
+ additionalData = {
70
+ ...additionalData,
71
+ componentForVisualisation: fieldType.components.tableView
72
+ };
73
+ }
74
+
75
+ if (defaultColumns?.[field.normalized_name]?.skipLine) additionalData.skipLine = true;
76
+ if (defaultColumns?.[field.normalized_name]?.width)
77
+ additionalData.width = defaultColumns[field.normalized_name].width;
78
+ if (defaultColumns?.[field.normalized_name]?.hidden) additionalData.hidden = true;
79
+
80
+ columnsList.push({
81
+ name: field.normalized_name,
82
+ label: field.name,
83
+ initialWidth: field.width ?? 50,
84
+ isSearchable: true,
85
+ isSortable: true,
86
+ ...additionalData
87
+ });
88
+ }
89
+
90
+ columns = columnsList;
91
+ }
92
+
93
+ async function getRows(filters, sort, limit, offset) {
94
+ // convertir les filter en post data
95
+ let postFilter = {};
96
+ let index = 0;
97
+ for (const columnName in filters) {
98
+ postFilter = {
99
+ ...postFilter,
100
+ [`filters[${columnName}]`]: filters[columnName]
101
+ };
102
+
103
+ index++;
104
+ }
105
+ for (const columnName in invisibleFilters) {
106
+ postFilter = {
107
+ ...postFilter,
108
+ [`filters[${columnName}]`]: invisibleFilters[columnName]
109
+ };
110
+
111
+ index++;
112
+ }
113
+ // convertir sort en post data
114
+ let postSort = {};
115
+ if (sort.direction) {
116
+ postSort = {
117
+ [`sort[${sort.columnName}]`]: sort.direction
118
+ };
119
+ }
120
+
121
+ const request = await sendRequest({
122
+ path: path,
123
+ data: {
124
+ entityId: entityId,
125
+ limit: limit,
126
+ offset,
127
+ ...postFilter,
128
+ ...postSort,
129
+ ...data
130
+ }
131
+ });
132
+
133
+ if (request.statusType === 'error') {
134
+ if (request.statusCode === 403) {
135
+ error = 403;
136
+ } else {
137
+ error === 'error';
138
+ }
139
+ return;
140
+ }
141
+
142
+ const requestData = request.data;
143
+
144
+ let returnedData = {
145
+ rows: [],
146
+ totalOfRows: requestData.totalOfRows
147
+ };
148
+ for (const row of requestData.rows) {
149
+ let newRow = {};
150
+
151
+ for (const column of columns) {
152
+ // composent
153
+ if (column.componentForVisualisation) {
154
+ newRow[`${column.name}`] = {
155
+ component: column.componentForVisualisation,
156
+ props: {
157
+ // injecter la valeur
158
+ value: row[column.name],
159
+ // injecter les props de colonne
160
+ ...column.componentPropsForVisualisation
161
+ }
162
+ };
163
+ continue;
164
+ }
165
+ // function de formatage
166
+ if (column.functionForVisualisation) {
167
+ newRow[`${column.name}`] = column.functionForVisualisation(row[column.name]);
168
+ continue;
169
+ }
170
+
171
+ newRow[`${column.name}`] = row[column.name].flat;
172
+ }
173
+
174
+ returnedData.rows.push(newRow);
175
+ }
176
+
177
+ return returnedData;
178
+ }
179
+
180
+ function handleChange(table) {
181
+ // copier les filtres
182
+ let defaultFilters = { ...table.filters };
183
+ let defaultColumns = null;
184
+
185
+ for (const column of table.columns) {
186
+ if (!column.hidden && !column.width && !column.skipLine) continue;
187
+
188
+ if (defaultColumns === null) defaultColumns = {};
189
+
190
+ let newColumn = {
191
+ name: column.name
192
+ };
193
+
194
+ // push les données
195
+ if (column.hidden) newColumn.hidden = true;
196
+ if (column.width) newColumn.width = column.width;
197
+ if (column.skipLine) newColumn.skipLine = true;
198
+
199
+ defaultColumns[column.name] = newColumn;
200
+ }
201
+
202
+ defaultProps = {
203
+ defaultFilters: defaultFilters,
204
+ defaultColumns: defaultColumns
205
+ };
206
+ }
207
+
208
+ function onClick(rowData) {
209
+ // rediriger vers
210
+ goto(`/${$page.params.projet_slug}/${$page.params.origin}/${slug ?? $page.params.structure_slug}/${rowData.id}`);
211
+ }
212
+ </script>
213
+
214
+ {#if error === 403}
215
+ <div class="error">
216
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
217
+ <path
218
+ opacity="0.4"
219
+ d="M10.9608 2.10989L5.46078 4.16989C4.41078 4.56989 3.55078 5.80989 3.55078 6.93989V15.0399C3.55078 15.8499 4.08078 16.9199 4.73078 17.3999L10.2308 21.5099C11.2008 22.2399 12.7908 22.2399 13.7608 21.5099L19.2608 17.3999C19.9108 16.9099 20.4408 15.8499 20.4408 15.0399V6.93989C20.4408 5.81989 19.5808 4.56988 18.5308 4.17988L13.0308 2.11989C12.4708 1.89989 11.5308 1.89989 10.9608 2.10989Z"
220
+ fill="#292D32"
221
+ />
222
+ <path
223
+ d="M14.5 10.5C14.5 9.12 13.38 8 12 8C10.62 8 9.5 9.12 9.5 10.5C9.5 11.62 10.24 12.55 11.25 12.87V15.5C11.25 15.91 11.59 16.25 12 16.25C12.41 16.25 12.75 15.91 12.75 15.5V12.87C13.76 12.55 14.5 11.62 14.5 10.5Z"
224
+ fill="#292D32"
225
+ />
226
+ </svg>
227
+
228
+ <h3>Vous n'avez pas accès a cet ressource</h3>
229
+ <p>Vous ne pouvez pas consulté les element lié a cette entité !</p>
230
+ </div>
231
+ {:else if error === 'error'}
232
+ <div class="error">
233
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
234
+ <path
235
+ opacity="0.4"
236
+ d="M21.7605 15.92L15.3605 4.4C14.5005 2.85 13.3105 2 12.0005 2C10.6905 2 9.50047 2.85 8.64047 4.4L2.24047 15.92C1.43047 17.39 1.34047 18.8 1.99047 19.91C2.64047 21.02 3.92047 21.63 5.60047 21.63H18.4005C20.0805 21.63 21.3605 21.02 22.0105 19.91C22.6605 18.8 22.5705 17.38 21.7605 15.92Z"
237
+ fill="#292D32"
238
+ />
239
+ <path
240
+ d="M12 14.75C11.59 14.75 11.25 14.41 11.25 14V9C11.25 8.59 11.59 8.25 12 8.25C12.41 8.25 12.75 8.59 12.75 9V14C12.75 14.41 12.41 14.75 12 14.75Z"
241
+ fill="#292D32"
242
+ />
243
+ <path
244
+ d="M12 18.0001C11.94 18.0001 11.87 17.9901 11.8 17.9801C11.74 17.9701 11.68 17.9501 11.62 17.9201C11.56 17.9001 11.5 17.8701 11.44 17.8301C11.39 17.7901 11.34 17.7501 11.29 17.7101C11.11 17.5201 11 17.2601 11 17.0001C11 16.7401 11.11 16.4801 11.29 16.2901C11.34 16.2501 11.39 16.2101 11.44 16.1701C11.5 16.1301 11.56 16.1001 11.62 16.0801C11.68 16.0501 11.74 16.0301 11.8 16.0201C11.93 15.9901 12.07 15.9901 12.19 16.0201C12.26 16.0301 12.32 16.0501 12.38 16.0801C12.44 16.1001 12.5 16.1301 12.56 16.1701C12.61 16.2101 12.66 16.2501 12.71 16.2901C12.89 16.4801 13 16.7401 13 17.0001C13 17.2601 12.89 17.5201 12.71 17.7101C12.66 17.7501 12.61 17.7901 12.56 17.8301C12.5 17.8701 12.44 17.9001 12.38 17.9201C12.32 17.9501 12.26 17.9701 12.19 17.9801C12.13 17.9901 12.06 18.0001 12 18.0001Z"
245
+ fill="#292D32"
246
+ />
247
+ </svg>
248
+
249
+ <h3>Une erreur est survenue !</h3>
250
+ <p>Impossible de récuperer l'entrée !</p>
251
+ </div>
252
+ {:else if columns.length > 0}
253
+ <TableV2.Root {getRows} onChange={handleChange} {onClick} {columns} {...props}>
254
+ <TableV2.ActionsBar slot="actions-bar"
255
+ ><slot name="actions" slot="actions" /></TableV2.ActionsBar
256
+ >
257
+ <TableV2.Header slot="header"></TableV2.Header>
258
+ <TableV2.Content slot="content"></TableV2.Content>
259
+ </TableV2.Root>
260
+ {:else}
261
+ <div class="loader">
262
+ <RotativeLoader></RotativeLoader>
263
+ </div>
264
+ {/if}
265
+
266
+ <style>
267
+ .loader {
268
+ padding: 60px var(--pad-m);
269
+ display: flex;
270
+ align-items: center;
271
+ justify-content: center;
272
+ }
273
+ .error {
274
+ padding: 60px var(--pad-m);
275
+ display: flex;
276
+ flex-direction: column;
277
+ align-items: center;
278
+ row-gap: var(--pad-m);
279
+ }
280
+ .error > svg {
281
+ width: 60px;
282
+ height: auto;
283
+ }
284
+ .error > svg path {
285
+ fill: var(--red);
286
+ }
287
+ </style>
@@ -0,0 +1,14 @@
1
+ import { createViewType } from '../../createViewType';
2
+
3
+ import Icon from '../Table/Icon.svelte';
4
+ import Component from '../Table/component/Component.svelte';
5
+
6
+ export default createViewType({
7
+ type: "table",
8
+ name: "Tableau",
9
+ description: "",
10
+ components: {
11
+ component: Component,
12
+ icon: Icon,
13
+ },
14
+ });