View | Details | Raw Unified | Return to bug 40876
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (-8 / +10 lines)
Lines 493-510 function _dt_default_ajax(params) { Link Here
493
            function build_query(col, value) {
493
            function build_query(col, value) {
494
                var parts = [];
494
                var parts = [];
495
                var attributes = col.data.split(":");
495
                var attributes = col.data.split(":");
496
497
                let criteria = options.criteria;
498
                if (value.match(/^\^(.*)\$$/)) {
499
                    value = value.replace(/^\^/, "").replace(/\$$/, "");
500
                    criteria = "exact";
501
                } else {
502
                    // escape SQL LIKE special characters %
503
                    value = value.replace(/(\%|\\)/g, "\\$1");
504
                }
505
496
                for (var i = 0; i < attributes.length; i++) {
506
                for (var i = 0; i < attributes.length; i++) {
497
                    var part = {};
507
                    var part = {};
498
                    var attr = attributes[i];
508
                    var attr = attributes[i];
499
                    let default_build = true;
509
                    let default_build = true;
500
                    let criteria = options.criteria;
501
                    if (value.match(/^\^(.*)\$$/)) {
502
                        value = value.replace(/^\^/, "").replace(/\$$/, "");
503
                        criteria = "exact";
504
                    } else {
505
                        // escape SQL LIKE special characters %
506
                        value = value.replace(/(\%|\\)/g, "\\$1");
507
                    }
508
510
509
                    let built_value;
511
                    let built_value;
510
                    if (col.type == "date") {
512
                    if (col.type == "date") {
(-)a/t/cypress/integration/KohaTable/PatronSearch_spec.ts (-1 / +90 lines)
Lines 180-183 describe("Filters", () => { Link Here
180
            ).should("have.value", null);
180
            ).should("have.value", null);
181
        });
181
        });
182
    });
182
    });
183
184
    describe.only("Exact search for all attributes", () => {
185
        // In this case the library column is bind to library.name and library.library_id
186
        it("From the form", () => {
187
            cy.task("buildSampleObjects", {
188
                object: "patron",
189
                count: RESTdefaultPageSize,
190
                values: {},
191
            }).then(patrons => {
192
                // Needs more properties to not explode
193
                // account_balace: balance_str.escapeHtml(...).format_price is not a function
194
                patrons = patrons.map(p => ({ ...p, account_balance: 0 }));
195
196
                cy.intercept("GET", "/api/v1/patrons*", {
197
                    statusCode: 200,
198
                    body: patrons,
199
                    headers: {
200
                        "X-Base-Total-Count": baseTotalCount,
201
                        "X-Total-Count": baseTotalCount,
202
                    },
203
                }).as("searchPatrons");
204
205
                cy.visit("/cgi-bin/koha/members/members-home.pl");
206
207
                cy.window().then(win => {
208
                    win.categories_map = patrons.reduce((map, p) => {
209
                        map[p.category_id.toLowerCase()] = p.category_id;
210
                        return map;
211
                    }, {});
212
                });
213
214
                cy.get("form.patron_search_form .branchcode_filter").select(
215
                    "CPL"
216
                );
217
                cy.get("form.patron_search_form input[type='submit']").click();
218
219
                cy.wait("@searchPatrons").then(interception => {
220
                    const q = interception.request.query.q;
221
                    expect(q).to.equal(
222
                        '[{"library.name":"CPL"},{"me.library_id":"CPL"}]'
223
                    );
224
                });
225
            });
226
        });
227
228
        it("From the column filter", () => {
229
            cy.task("buildSampleObjects", {
230
                object: "patron",
231
                count: RESTdefaultPageSize,
232
                values: {},
233
            }).then(patrons => {
234
                // Needs more properties to not explode
235
                // account_balace: balance_str.escapeHtml(...).format_price is not a function
236
                patrons = patrons.map(p => ({ ...p, account_balance: 0 }));
237
238
                cy.intercept("GET", "/api/v1/patrons*", {
239
                    statusCode: 200,
240
                    body: patrons,
241
                    headers: {
242
                        "X-Base-Total-Count": baseTotalCount,
243
                        "X-Total-Count": baseTotalCount,
244
                    },
245
                }).as("searchPatrons");
246
247
                cy.visit("/cgi-bin/koha/members/members-home.pl");
248
249
                cy.window().then(win => {
250
                    win.categories_map = patrons.reduce((map, p) => {
251
                        map[p.category_id.toLowerCase()] = p.category_id;
252
                        return map;
253
                    }, {});
254
                });
255
256
                cy.get("form.patron_search_form input[type='submit']").click();
257
258
                cy.wait("@searchPatrons");
259
260
                cy.get(
261
                    `#${table_id} thead tr th[data-filter='libraries'] select`
262
                ).select("^CPL$");
263
264
                cy.wait("@searchPatrons").then(interception => {
265
                    const q = interception.request.query.q;
266
                    expect(q).to.equal(
267
                        '[{"library.name":"CPL"},{"me.library_id":"CPL"}]'
268
                    );
269
                });
270
            });
271
        });
272
    });
183
});
273
});
184
- 

Return to bug 40876