Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
anis
anis-client
Commits
df3ce24f
Commit
df3ce24f
authored
Aug 23, 2019
by
François Agneray
Browse files
Optimisation des search type criterion
parent
b634210b
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/app/search/components/criteria/criteria-by-family.component.html
View file @
df3ce24f
...
...
@@ -59,7 +59,7 @@
</app-time>
</div>
<div
*ngSwitchCase=
"'ts'"
>
<app-datetime
class=
"criteria"
[id]=
"attribute.id"
[label]=
"attribute.form_label"
<app-datetime
class=
"criteria"
[id]=
"attribute.id"
[label]=
"attribute.form_label"
[operator]=
"attribute.operator"
[criterion]=
"getCriterion(attribute.id)"
(add)=
"add($event)"
(delete)=
"delete($event)"
>
</app-datetime>
</div>
...
...
src/app/search/components/criteria/search-type/between-date.component.ts
View file @
df3ce24f
import
{
Component
,
Input
,
Output
,
EventEmitter
,
ChangeDetectionStrategy
}
from
'
@angular/core
'
;
import
{
FormControl
}
from
'
@angular/forms
'
;
import
{
Criterion
,
Between
Date
Criterion
}
from
'
../../../store/model
'
;
import
{
Criterion
,
BetweenCriterion
}
from
'
../../../store/model
'
;
@
Component
({
selector
:
'
app-between-date
'
,
...
...
@@ -16,7 +16,7 @@ export class BetweenDateComponent {
set
criterion
(
criterion
:
Criterion
)
{
this
.
getDefault
(
criterion
);
}
@
Output
()
add
:
EventEmitter
<
Between
Date
Criterion
>
=
new
EventEmitter
();
@
Output
()
add
:
EventEmitter
<
BetweenCriterion
>
=
new
EventEmitter
();
@
Output
()
delete
:
EventEmitter
<
number
>
=
new
EventEmitter
();
field
=
new
FormControl
(
''
);
...
...
@@ -24,7 +24,7 @@ export class BetweenDateComponent {
addCriterion
():
void
{
const
dateMin
=
this
.
getDateString
(
this
.
field
.
value
[
0
]);
const
dateMax
=
this
.
getDateString
(
this
.
field
.
value
[
1
]);
const
fd
=
new
Between
Date
Criterion
(
this
.
id
,
dateMin
,
dateMax
);
const
fd
=
new
BetweenCriterion
(
this
.
id
,
dateMin
,
dateMax
);
this
.
add
.
emit
(
fd
);
}
...
...
@@ -37,7 +37,7 @@ export class BetweenDateComponent {
this
.
field
.
setValue
(
''
);
this
.
field
.
enable
();
}
else
{
const
c
=
criterion
as
Between
Date
Criterion
;
const
c
=
criterion
as
BetweenCriterion
;
this
.
field
.
setValue
([
new
Date
(
c
.
min
),
new
Date
(
c
.
max
)]);
this
.
field
.
disable
();
}
...
...
src/app/search/components/criteria/search-type/datetime.component.ts
View file @
df3ce24f
import
{
Component
,
Input
,
Output
,
EventEmitter
,
ChangeDetectionStrategy
}
from
'
@angular/core
'
;
import
{
FormControl
}
from
'
@angular/forms
'
;
import
{
Criterion
,
Datetime
Criterion
}
from
'
../../../store/model
'
;
import
{
Criterion
,
Field
Criterion
}
from
'
../../../store/model
'
;
@
Component
({
selector
:
'
app-datetime
'
,
...
...
@@ -11,13 +11,14 @@ import { Criterion, DatetimeCriterion } from '../../../store/model';
})
export
class
DatetimeComponent
{
@
Input
()
id
:
number
;
@
Input
()
operator
:
string
;
@
Input
()
label
:
string
;
@
Input
()
placeholder
:
string
;
@
Input
()
set
criterion
(
criterion
:
Criterion
)
{
this
.
getDefault
(
criterion
);
}
@
Output
()
add
:
EventEmitter
<
Datetime
Criterion
>
=
new
EventEmitter
();
@
Output
()
add
:
EventEmitter
<
Field
Criterion
>
=
new
EventEmitter
();
@
Output
()
delete
:
EventEmitter
<
number
>
=
new
EventEmitter
();
hours
:
string
[]
=
[];
...
...
@@ -35,7 +36,11 @@ export class DatetimeComponent {
}
addCriterion
()
{
const
fd
=
new
DatetimeCriterion
(
this
.
id
,
this
.
datetime
);
const
month
=
(
'
0
'
+
(
this
.
datetime
.
getMonth
()
+
1
)).
slice
(
-
2
);
const
day
=
(
'
0
'
+
(
this
.
datetime
.
getDate
())).
slice
(
-
2
);
const
date
=
this
.
datetime
.
getFullYear
()
+
'
-
'
+
month
+
'
-
'
+
day
;
const
time
=
this
.
hh
.
value
+
'
:
'
+
this
.
mm
.
value
;
const
fd
=
new
FieldCriterion
(
this
.
id
,
this
.
operator
,
date
+
'
'
+
time
);
this
.
add
.
emit
(
fd
);
}
...
...
@@ -53,14 +58,14 @@ export class DatetimeComponent {
this
.
mm
.
enable
();
this
.
isValidFields
=
false
;
}
else
{
const
c
=
criterion
as
Datetime
Criterion
;
const
hour
=
(
'
0
'
+
(
c
.
value
.
getHours
())).
slice
(
-
2
);
const
minute
=
(
'
0
'
+
(
c
.
value
.
getMinutes
()))
.
sli
ce
(
-
2
);
this
.
date
.
setValue
(
c
.
value
);
const
c
=
criterion
as
Field
Criterion
;
const
[
d
,
t
]
=
c
.
value
.
split
(
'
'
);
const
[
h
,
m
]
=
t
.
s
p
li
t
(
'
:
'
);
this
.
date
.
setValue
(
new
Date
(
d
)
);
this
.
date
.
disable
();
this
.
hh
.
setValue
(
h
our
);
this
.
hh
.
setValue
(
h
);
this
.
hh
.
disable
();
this
.
mm
.
setValue
(
m
inute
);
this
.
mm
.
setValue
(
m
);
this
.
mm
.
disable
();
this
.
isValidFields
=
true
;
}
...
...
src/app/search/store/model/between-date-criterion.model.ts
deleted
100644 → 0
View file @
b634210b
import
{
Criterion
}
from
'
./criterion.model
'
;
export
class
BetweenDateCriterion
extends
Criterion
{
min
:
string
;
max
:
string
;
constructor
(
id
:
number
,
min
:
string
,
max
:
string
)
{
super
(
id
);
this
.
min
=
min
;
this
.
max
=
max
;
}
printCriterion
():
string
{
return
'
∈ [
'
+
this
.
min
+
'
;
'
+
this
.
max
+
'
]
'
;
}
getCriterionStr
()
{
return
this
.
id
+
'
::bd::
'
+
this
.
min
+
'
|
'
+
this
.
max
;
}
}
src/app/search/store/model/checkbox-criterion.model.ts
deleted
100644 → 0
View file @
b634210b
import
{
Criterion
}
from
'
./criterion.model
'
;
import
{
Option
}
from
'
../../../metamodel/model/option.model
'
;
export
class
CheckboxCriterion
extends
Criterion
{
values
:
Option
[];
operator
:
string
;
constructor
(
id
:
number
,
operator
:
string
,
values
:
Option
[])
{
super
(
id
);
this
.
operator
=
operator
;
this
.
values
=
values
;
}
printCriterion
():
string
{
return
'
[
'
+
this
.
values
.
map
(
option
=>
option
.
label
).
join
(
'
,
'
)
+
'
]
'
;
}
getCriterionStr
():
string
{
if
(
this
.
operator
===
'
eq
'
)
{
return
this
.
id
+
'
::in::
'
+
this
.
values
.
map
(
option
=>
option
.
value
).
join
(
'
|
'
);
}
else
{
return
this
.
values
.
map
(
option
=>
this
.
id
+
'
::
'
+
this
.
operator
+
'
::
'
+
option
.
value
).
join
(
'
;
'
);
}
}
}
src/app/search/store/model/datetime-criterion.model.ts
deleted
100644 → 0
View file @
b634210b
import
{
Criterion
}
from
'
./criterion.model
'
;
export
class
DatetimeCriterion
extends
Criterion
{
value
:
Date
;
constructor
(
id
:
number
,
value
:
Date
)
{
super
(
id
);
this
.
value
=
value
;
}
printCriterion
():
string
{
const
month
=
(
'
0
'
+
(
this
.
value
.
getMonth
()
+
1
)).
slice
(
-
2
);
const
day
=
(
'
0
'
+
(
this
.
value
.
getDate
())).
slice
(
-
2
);
const
hour
=
(
'
0
'
+
(
this
.
value
.
getHours
())).
slice
(
-
2
);
const
minute
=
(
'
0
'
+
(
this
.
value
.
getMinutes
())).
slice
(
-
2
);
const
date
=
this
.
value
.
getFullYear
()
+
'
-
'
+
month
+
'
-
'
+
day
;
const
time
=
hour
+
'
:
'
+
minute
;
return
date
+
'
'
+
time
;
}
getCriterionStr
():
string
{
const
month
=
(
'
0
'
+
(
this
.
value
.
getMonth
()
+
1
)).
slice
(
-
2
);
const
day
=
(
'
0
'
+
(
this
.
value
.
getDate
())).
slice
(
-
2
);
const
hour
=
(
'
0
'
+
(
this
.
value
.
getHours
())).
slice
(
-
2
);
const
minute
=
(
'
0
'
+
(
this
.
value
.
getMinutes
())).
slice
(
-
2
);
const
date
=
this
.
value
.
getFullYear
()
+
'
-
'
+
month
+
'
-
'
+
day
;
const
time
=
hour
+
'
:
'
+
minute
;
return
this
.
id
+
'
::eq::
'
+
date
+
'
.
'
+
time
;
}
}
src/app/search/store/model/index.ts
View file @
df3ce24f
export
*
from
'
./criterion.model
'
;
export
*
from
'
./between-criterion.model
'
;
export
*
from
'
./between-date-criterion.model
'
;
export
*
from
'
./field-criterion.model
'
;
export
*
from
'
./checkbox-criterion.model
'
;
export
*
from
'
./select-multiple-criterion.model
'
;
export
*
from
'
./search-meta.model
'
;
export
*
from
'
./datetime-criterion.model
'
;
export
*
from
'
./search-query-params.model
'
;
export
*
from
'
./json-criterion.model
'
;
src/app/search/store/search.effects.ts
View file @
df3ce24f
...
...
@@ -12,7 +12,7 @@ import * as fromRouter from '@ngrx/router-store';
import
*
as
fromSearch
from
'
./search.reducer
'
;
import
*
as
utils
from
'
../../shared/utils
'
;
import
{
SearchService
}
from
'
./search.service
'
;
import
{
BetweenCriterion
,
BetweenDateCriterion
,
SearchMeta
,
FieldCriterion
,
SelectMultipleCriterion
,
JsonCriterion
}
from
'
./model
'
;
import
{
BetweenCriterion
,
SearchMeta
,
FieldCriterion
,
SelectMultipleCriterion
,
JsonCriterion
}
from
'
./model
'
;
@
Injectable
()
export
class
SearchEffects
{
...
...
@@ -89,13 +89,13 @@ export class SearchEffects {
case
'
dl
'
:
case
'
rd
'
:
case
'
dt
'
:
case
'
ts
'
:
case
'
tm
'
:
return
new
FieldCriterion
(
parseInt
(
params
[
0
],
10
),
params
[
1
],
params
[
2
]);
case
'
bw
'
:
case
'
bd
'
:
const
bwValues
=
params
[
2
].
split
(
'
|
'
);
return
new
BetweenCriterion
(
parseInt
(
params
[
0
],
10
),
bwValues
[
0
],
bwValues
[
1
]);
case
'
bd
'
:
const
bwdValues
=
params
[
2
].
split
(
'
|
'
);
return
new
BetweenDateCriterion
(
parseInt
(
params
[
0
],
10
),
bwdValues
[
0
],
bwdValues
[
1
]);
case
'
ms
'
:
case
'
cb
'
:
const
msValues
=
params
[
2
].
split
(
'
|
'
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment