@@ -30,6 +30,7 @@ let lastSearch = '';
30
30
let theSearchCursor ;
31
31
32
32
const dom = {
33
+ searchFilterCount : null ,
33
34
thingsTableHead : null ,
34
35
thingsTableBody : null ,
35
36
searchFilterEdit : null ,
@@ -76,7 +77,7 @@ function onThingsTableClicked(event) {
76
77
* Tests if the search filter is an RQL. If yes, things search is called otherwise just things get
77
78
* @param {String } filter search filter string containing an RQL or a thingId
78
79
*/
79
- export function searchTriggered ( filter ) {
80
+ export function searchTriggered ( filter : string ) {
80
81
lastSearch = filter ;
81
82
const regex = / ^ ( e q \( | n e \( | g t \( | g e \( | l t \( | l e \( | i n \( | l i k e \( | i l i k e \( | e x i s t s \( | a n d \( | o r \( | n o t \( ) .* / ;
82
83
if ( filter === '' || regex . test ( filter ) ) {
@@ -113,13 +114,15 @@ export function performLastSearch() {
113
114
* @param {Array } thingIds Array of thingIds
114
115
*/
115
116
export function getThings ( thingIds ) {
117
+ dom . searchFilterCount . innerHTML = '' ;
116
118
dom . thingsTableBody . innerHTML = '' ;
117
119
const fieldsQueryParameter = Fields . getQueryParameter ( ) ;
118
120
if ( thingIds . length > 0 ) {
119
121
API . callDittoREST ( 'GET' ,
120
122
`/things?${ fieldsQueryParameter } &ids=${ thingIds } &option=sort(%2BthingId)` )
121
123
. then ( ( thingJsonArray ) => {
122
124
fillThingsTable ( thingJsonArray ) ;
125
+ dom . searchFilterCount . innerHTML = '#: ' + thingJsonArray . length ;
123
126
notifyAll ( thingIds , fieldsQueryParameter ) ;
124
127
} )
125
128
. catch ( ( error ) => {
@@ -134,19 +137,38 @@ export function getThings(thingIds) {
134
137
135
138
function resetAndClearViews ( retainThing = false ) {
136
139
theSearchCursor = null ;
140
+ dom . searchFilterCount . innerHTML = '' ;
137
141
dom . thingsTableHead . innerHTML = '' ;
138
142
dom . thingsTableBody . innerHTML = '' ;
139
143
if ( ! retainThing ) {
140
144
Things . setTheThing ( null ) ;
141
145
}
142
146
}
143
147
148
+ /**
149
+ * Calls Ditto search API to perform a count and adds the count to the UI.
150
+ * @param {String } filter Ditto search filter (rql)
151
+ */
152
+ function countThings ( filter : string ) {
153
+ dom . searchFilterCount . innerHTML = '' ;
154
+ const namespaces = Environments . current ( ) . searchNamespaces
155
+ API . callDittoREST ( 'GET' ,
156
+ '/search/things/count' +
157
+ ( ( filter && filter !== '' ) ? '?filter=' + encodeURIComponent ( filter ) : '' ) +
158
+ ( ( namespaces && namespaces !== '' ) ? '&namespaces=' + namespaces : '' ) , null , null
159
+ ) . then ( ( countResult ) => {
160
+ dom . searchFilterCount . innerHTML = '#: ' + countResult ;
161
+ } ) . catch ( ( error ) => {
162
+ notifyAll ( ) ;
163
+ } ) ;
164
+ }
165
+
144
166
/**
145
167
* Calls Ditto search api and fills UI with the result
146
168
* @param {String } filter Ditto search filter (rql)
147
169
* @param {boolean } isMore (optional) use cursor from previous search for additional pages
148
170
*/
149
- function searchThings ( filter , isMore = false ) {
171
+ function searchThings ( filter : string , isMore = false ) {
150
172
document . body . style . cursor = 'progress' ;
151
173
152
174
const namespaces = Environments . current ( ) . searchNamespaces ;
@@ -162,6 +184,7 @@ function searchThings(filter, isMore = false) {
162
184
if ( isMore ) {
163
185
removeMoreFromThingList ( ) ;
164
186
} else {
187
+ countThings ( filter ) ;
165
188
resetAndClearViews ( true ) ;
166
189
}
167
190
fillThingsTable ( searchResult . items ) ;
@@ -212,7 +235,7 @@ export function removeMoreFromThingList() {
212
235
* Fills the things table UI with the given things
213
236
* @param {Array } thingsList Array of thing json objects
214
237
*/
215
- function fillThingsTable ( thingsList ) {
238
+ function fillThingsTable ( thingsList : any [ ] ) {
216
239
const activeFields = Environments . current ( ) . fieldList . filter ( ( f ) => f . active ) ;
217
240
fillHeaderRow ( ) ;
218
241
let thingSelected = false ;
0 commit comments