@@ -7,32 +7,6 @@ import {
7
7
import isEqual from "lodash.isequal" ;
8
8
import { GenericDictionnary } from "./VDUSTypes"
9
9
10
- /*
11
- This function take a object in parameter that is often a form of filtering field
12
- all this field are filtered before being used to be transformed as a query url
13
- if localName is true it will no replace the param key with the real used for backend query
14
- if localName is false the name will be replaced by the correct one sended to backend
15
- */
16
- function generateQueryFromObject ( object : GenericDictionnary , schema ?: GenericDictionnary , localName : Boolean = true ) : GenericDictionnary {
17
- let queryUrl : GenericDictionnary = { } ;
18
- for ( let [ key , value ] of Object . entries ( object ) ) {
19
- // We do not want to send a default value
20
- if ( isValueDefault ( value , key , schema ) ) {
21
- continue ;
22
- }
23
-
24
- // by default the quey key is the same that the form key
25
- let queryKey = key ;
26
- // But this can be overrided if name attribute is defined in the param schema
27
- if ( ! localName && schema && schema [ key ] && schema [ key ] . name ) {
28
- queryKey = schema [ key ] . name ;
29
- }
30
-
31
- queryUrl [ queryKey ] = value ;
32
- }
33
- return queryUrl ;
34
- }
35
-
36
10
function getDefaultValueForParam ( param : string , schema ?: GenericDictionnary ) : any {
37
11
if ( schema && schema [ param ] ) {
38
12
// if there is a defautl value we change the condition to is non equality
@@ -81,6 +55,52 @@ function isValueDefault(value: any, param: string, schema?: GenericDictionnary):
81
55
return value === null || isValueDefault ;
82
56
}
83
57
58
+ /*
59
+ This function take a object in parameter that is often a form of filtering field
60
+ all this field are filtered before being used to be transformed as a query url
61
+ if localName is true it will no replace the param key with the real used for backend query
62
+ if localName is false the name will be replaced by the correct one sended to backend
63
+ */
64
+ function generateQueryFromObject ( object : GenericDictionnary , schema ?: GenericDictionnary , localName = true ) : GenericDictionnary {
65
+ const queryUrl : GenericDictionnary = { } ;
66
+ for ( const [ key , value ] of Object . entries ( object ) ) {
67
+ // We do not want to send a default value
68
+ if ( isValueDefault ( value , key , schema ) ) {
69
+ continue ;
70
+ }
71
+
72
+ // by default the quey key is the same that the form key
73
+ let queryKey = key ;
74
+ // But this can be overrided if name attribute is defined in the param schema
75
+ if ( ! localName && schema && schema [ key ] && schema [ key ] . name ) {
76
+ queryKey = schema [ key ] . name ;
77
+ }
78
+
79
+ queryUrl [ queryKey ] = value ;
80
+ }
81
+ return queryUrl ;
82
+ }
83
+
84
+ function convertParamIfTypeInSchema ( query : GenericDictionnary , param : string , schema ?: GenericDictionnary , prefix = "" ) : any {
85
+ if ( ! schema || ! schema [ param ] || ! schema [ param ] . type ) {
86
+ return query [ prefix + param ] ;
87
+ }
88
+ if ( schema [ param ] . type === "boolean" ) {
89
+ return extractBooleanValue ( query [ prefix + param ] ) ;
90
+ }
91
+ if ( schema [ param ] . type === "integer" ) {
92
+ return extractIntegerValue ( query [ prefix + param ] ) ;
93
+ }
94
+ if ( schema [ param ] . type === "arrayInt" ) {
95
+ return elementToArrayOfInt ( query [ prefix + param ] ) ;
96
+ }
97
+ if ( schema [ param ] . type === "arrayString" ) {
98
+ return elementToArrayOfString ( query [ prefix + param ] ) ;
99
+ }
100
+
101
+ return query [ prefix + param ] ;
102
+ }
103
+
84
104
/*
85
105
Transform query parameter from vue router to two javascript objects representing the filtering form and the options
86
106
*/
@@ -90,12 +110,12 @@ function readFormAndOptionsFromLocalQuery(
90
110
options : GenericDictionnary ,
91
111
schema ?: GenericDictionnary ,
92
112
removedParam : Array < string > = [ ]
93
- ) : { newOptions : GenericDictionnary , newForm : GenericDictionnary } {
113
+ ) : { newOptions : GenericDictionnary ; newForm : GenericDictionnary } {
94
114
95
- let newOptions : GenericDictionnary = { } ;
96
- let newForm : GenericDictionnary = { } ;
115
+ const newOptions : GenericDictionnary = { } ;
116
+ const newForm : GenericDictionnary = { } ;
97
117
98
- for ( let param in query ) {
118
+ for ( const param in query ) {
99
119
if ( typeof form [ param ] !== "undefined" ) {
100
120
newForm [ param ] = convertParamIfTypeInSchema ( query , param , schema ) ;
101
121
} else if ( typeof options [ param ] !== "undefined" ) {
@@ -116,26 +136,6 @@ function readFormAndOptionsFromLocalQuery(
116
136
return { newOptions, newForm } ;
117
137
}
118
138
119
- function convertParamIfTypeInSchema ( query : GenericDictionnary , param : string , schema ?: GenericDictionnary , prefix : string = "" ) : any {
120
- if ( ! schema || ! schema [ param ] || ! schema [ param ] . type ) {
121
- return query [ prefix + param ] ;
122
- }
123
- if ( schema [ param ] . type === "boolean" ) {
124
- return extractBooleanValue ( query [ prefix + param ] ) ;
125
- }
126
- if ( schema [ param ] . type === "integer" ) {
127
- return extractIntegerValue ( query [ prefix + param ] ) ;
128
- }
129
- if ( schema [ param ] . type === "arrayInt" ) {
130
- return elementToArrayOfInt ( query [ prefix + param ] ) ;
131
- }
132
- if ( schema [ param ] . type === "arrayString" ) {
133
- return elementToArrayOfString ( query [ prefix + param ] ) ;
134
- }
135
-
136
- return query [ prefix + param ] ;
137
- }
138
-
139
139
function getRemovedKeyBetweenTwoObject ( originalObject : GenericDictionnary , newObject : GenericDictionnary ) : Array < string > {
140
140
const originalObjectKeys : Array < string > = Object . keys ( originalObject ) ;
141
141
const newObjectKeys : Array < string > = Object . keys ( newObject ) ;
0 commit comments