Commit 4c99f38f authored by Xiaohe Cao's avatar Xiaohe Cao Committed by Romain Courteaud

ERP5Storage: fix allDocs's sort_on parameter handling

parent c4e7bbde
......@@ -481,7 +481,8 @@
parsed_query,
sub_query,
result_list,
local_roles;
local_roles,
tmp_list = [];
if (options.query) {
parsed_query = jIO.QueryFactory.create(options.query);
......@@ -523,6 +524,13 @@
}
}
if (options.sort_on) {
for (i = 0; i < options.sort_on.length; i += 1) {
tmp_list.push(JSON.stringify(options.sort_on[i]));
}
options.sort_on = tmp_list;
  • @romain @xiaohe.cao @tc In my opinion, this should be declared a coding crime, a function should not modify the parameter it is given unless directly specified. What do you think?

  • 100% agree.

    And don't use plurals.

    And I don't like to use option = JSON.stringify(option) to copy options, because you can give a huge object to stringify.

    Example of how I use my option parameter :

    function couscous(option) {
      option = option || {};
      var value1 = option.value1,
          object1 = operate(option.object1),
          false_by_default = option.false_by_default,
          true_by_default = option.true_by_default === undefined || option.true_by_default,
          sort_on = operateSortOnOption(option.sort_on);
      // [..]
    }

    In this example, operate.* copy the needed values to a new object to avoid applying values to the original referred object.

  • It is more a problem of API specification than a coding crime.

Please register or sign in to reply
}
return jIO.util.ajax({
"type": "GET",
"url": UriTemplate.parse(site_hal._links.raw_search.href)
......
......@@ -13,7 +13,7 @@
domain = "https://example.org",
traverse_template = domain + "?mode=traverse{&relative_url,view}",
search_template = domain + "?mode=search{&query,select_list*,limit*," +
"local_roles*}",
"sort_on*,local_roles*}",
add_url = domain + "lets?add=somedocument",
bulk_url = domain + "lets?run=bulk",
root_hateoas = JSON.stringify({
......@@ -1102,7 +1102,9 @@
test("filter documents", function () {
var search_url = domain + "?mode=search&query=title%3A%20%22two%22&" +
"select_list=destination&select_list=source&limit=5",
"select_list=destination&select_list=source&limit=5&" +
"sort_on=%5B%22title%22%2C%22descending%22%5D&" +
"sort_on=%5B%22id%22%2C%22descending%22%5D",
search_hateoas = JSON.stringify({
"_embedded": {
......@@ -1142,7 +1144,8 @@
this.jio.allDocs({
limit: [5],
select_list: ["destination", "source"],
query: 'title: "two"'
query: 'title: "two"',
sort_on: [["title", "descending"], ["id", "descending"]]
})
.then(function (result) {
deepEqual(result, {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment