Custom object array binding? - handsontable

I've looked through the documentation, but perhaps I've overlooked what I assume to be a straightforward task. Is it possible to provide a custom binding function so that, in an array of objects, each object corresponds to one cell, rather than each object corresponding to a full row? Would this binding maintain the reference to the original object so that the data would change after being modified in the spreadsheet?
For example, I'd want to create the following sheet:
With JSON in this structure:
[
{
"name": "USA",
"year": 2015,
"sales": 1,
},
{
"name": "USA",
"year": 2016,
"sales": 2,
},
{
"name": "USA",
"year": 2017,
"sales": 3,
},
{
"name": "Canada",
"year": 2015,
"sales": 4,
},
{
"name": "Canada",
"year": 2016,
"sales": 5,
},
{
"name": "Canada",
"year": 2017,
"sales": 6,
}
]

You should look at the columns definition. In there you can define the data source for each column such that it will iterate through your objects and set the values of each column given the id for that column. And yes, it uses references so if you edit them, your objects get edited as well.

Related

Accomplish the select box Vuetify behavior into a text field

I want to accomplish the following, but using a textfield (v-text-field) input instead:
<v-select
:items="addresses"
label="Address Field"
item-value="id"
item-text="address_line1"
v-model="address_id"
>
</v-select>
The select box returns all the "address_line1" (item-text) values from the addresses array (:items) and the default selected value is the one that matches with address_id (v-model) in the zones array. The data comes from two arrays of objects, that are related and comes from two external API. I want a textfield with the related value, and because I want the user to be able to update the field freely.
zones: [
{
"id": 1,
"name": "Museum",
"description": "description",
"address_id": 1,
"branch_id": 1,
"parent_zone_id": 2,
"provider_id": 10
},
{
"id": 2,
"name": "Restaurant",
"description": "description",
"address_id": 2,
"branch_id": 1,
"parent_zone_id": 2,
"provider_id": 10
},
]
addresses: [
{
"id": 1,
"name": "Address Name",
"address_line1": "7210 Euismod Rd.",
"address_line2": null,
"address_line3": null,
"zip_code": "6301",
"city": "Some City",
"state_id": 3296,
"country_id": 238,
"latitude": "10.99710000",
"longitude": "63.91130000",
"user_id": 11
},
{
"id": 2,
"name": "Address Name 2",
"address_line1": "2110 Elmond St.",
"address_line2": null,
"address_line3": null,
"zip_code": "6301",
"city": "Some Other City",
"state_id": 3296,
"country_id": 238,
"latitude": "10.99710000",
"longitude": "63.91130000",
"user_id": 11
}
]
The only way I can think of, is by hidding the select box, which picks the value selected. And then ref the value to the input text field somehow.
In this use case, v-autocomplete might be useful for you. It allows you to type on the field freely and will actively search for the addresses as you type.
<v-autocomplete
:items="addresses"
label="Address Field"
item-value="id"
item-text="address_line1"
v-model="address_id"
></v-autocomplete>
Here's a sample demo.
Also, you might want to update your vuetify to the latest version (vuetify 2.3.10 as of now) because I have encountered problems in lower versions, specifically vuetify 2.0.1. The problem is that v-autocomplete's displayed text is not updating properly when you try to select an option that is equal to its v-model value. Fortunately, this is fixed in later versions.

Spring Cloud Contract Verifier - Body matching

I'm using Spring Cloud Contract Verifier
org.springframework.cloud:spring-cloud-starter-contract-verifier:jar:2.0.0.M8
org.springframework.cloud:spring-cloud-contract-maven-plugin:1.2.4.RELEASE
And I have the following contract:
request:
method: GET
url: /cars/list
response:
status: 200
headers:
Content-Type: application/json;charset=UTF-8
body:
cars:
[
{
"make": "Ford",
"model": "Fiesta",
"year": 2016,
"price": 16500.50
},
{
"make": "BMW",
"model": "X1",
"year": 2014,
"price": 22000.00
},
{
"make": "NISSAN",
"model": "Juke",
"year": 2017,
"price": 19300.00
}
]
Which is then converted in following java code:
DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
assertThatJson(parsedJson).array("['cars']").contains("['model']").isEqualTo("Juke");
assertThatJson(parsedJson).array("['cars']").contains("['make']").isEqualTo("Ford");
assertThatJson(parsedJson).array("['cars']").contains("['year']").isEqualTo(2014);
assertThatJson(parsedJson).array("['cars']").contains("['year']").isEqualTo(2016);
assertThatJson(parsedJson).array("['cars']").contains("['model']").isEqualTo("Fiesta");
assertThatJson(parsedJson).array("['cars']").contains("['make']").isEqualTo("BMW");
assertThatJson(parsedJson).array("['cars']").contains("['year']").isEqualTo(2017);
assertThatJson(parsedJson).array("['cars']").contains("['make']").isEqualTo("NISSAN");
assertThatJson(parsedJson).array("['cars']").contains("['price']").isEqualTo(16500.5);
assertThatJson(parsedJson).array("['cars']").contains("['model']").isEqualTo("X1");
assertThatJson(parsedJson).array("['cars']").contains("['price']").isEqualTo(22000.0);
assertThatJson(parsedJson).array("['cars']").contains("['price']").isEqualTo(19300.0);
I have a few issues with this test:
1) It does not take order into account, meaning the following body would still be considered valid:
{
"cars": [
{
"make": "NISSAN",
"model": "Juke",
"year": 2017,
"price": 19300.00
},
{
"make": "BMW",
"model": "X1",
"year": 2014,
"price": 22000.00
},
{
"make": "Ford",
"model": "Fiesta",
"year": 2016,
"price": 16500.50
}
]
}
2) It just verifies that certain property is present anywhere in the response, meaning the following body would still be considered valid:
{
"cars": [
{
"make": "Ford",
"model": "Juke",
"year": 2016,
"price": 19300.00
},
{
"make": "BMW",
"model": "X1",
"year": 2017,
"price": 22000.00
},
{
"make": "NISSAN",
"model": "Fiesta",
"year": 2014,
"price": 16500.50
}
]
}
3) It ignores any extra values present in the response, meaning the following body would still be considered valid:
{
"cars": [
{
"make": "Ford",
"model": "Fiesta",
"year": 2017,
"price": 22000.00,
"state": "good"
},
{
"make": "NISSAN",
"model": "Juke",
"year": 2016,
"price": 19300.00,
"state": "ok"
},
{
"make": "BMW",
"model": "X1",
"year": 2014,
"price": 16500.50
},
{
"make": "Volkswagen",
"model": "Golf",
"year": 2018,
"price": 12500.00,
"state": "new"
}
]
}
I would like the generated test to be more strict and fail on any differences outlined in cases above.
Can it be achieved with Spring Cloud Contract Verifier?
To begin with you have a mismatch of versions
org.springframework.cloud:spring-cloud-starter-contract-verifier:jar:2.0.0.M8 org.springframework.cloud:spring-cloud-contract-maven-plugin:1.2.4.RELEASE
You are using a plugin in version different than the verifier. Those should match.
Now for your questions
1) It does not take order into account, meaning the following body would still be considered valid:
Yes, we don't test it out of the box. You can do it manually by providing your own JSON path matchers for the whole body (https://cloud.spring.io/spring-cloud-contract/single/spring-cloud-contract.html#contract-matchers)
2) It just verifies that certain property is present anywhere in the response, meaning the following body would still be considered valid:
Yeah, we assert that the structure is ok, that's the idea of contract tests. If you want more precise verifiactions use the matchers section (https://cloud.spring.io/spring-cloud-contract/single/spring-cloud-contract.html#contract-matchers)
3) It ignores any extra values present in the response, meaning the following body would still be considered valid:
And that's absolutely what you should be doing. Ignore unknown fields. You can read more about Postel's law here (https://en.wikipedia.org/wiki/Robustness_principle)
I would like the generated test to be more strict and fail on any differences outlined in cases above.
I think you're looking for a schema not a contract test or definition. You can use the Spring Rest Docs integration (https://cloud.spring.io/spring-cloud-contract/single/spring-cloud-contract.html#_generating_stubs_using_rest_docs) and over there enforce how exactly the stub must look like. But IMO (of course I don't know your domain) you're too restrictive.

Pagination in many-to-many mapping in Spring Boot

I have two tables with Many-To-Many mappings. Tables are content and tag. So, I have another table content_tag to normalize the many-to-many relationship. But, I am having problem in pagination. As example, when I am fetching a tag by name it returns a single tag object, but with multiple content object nested inside. I know how to do pagination for tag, but my question is how can I make pagination for the nested content object in a single tag object. Please see my result below, which I am getting from POSTMAN.
{
"id": 12,
"tag": "Viral",
"contents": [
{
"id": 15,
"idHide": "0",
"listCategory": {
"id": 11,
"title": "Dramai",
"titleBn": "ড্রামাই",
"status": "active"
},
"title": "Cat",
"titleBn": "#99",
"brief": "uytyyyy",
"briefBn": "#495",
"highlight": "0",
"dim": "0",
"sticky": "0",
"status": "active",
"createdAt": "Jan 24, 2018 3:08:34 PM",
"listTag": [
{
"id": 12,
"title": "Viral"
},
{
"id": 13,
"title": "Progress"
},
{
"id": 14,
"title": "Limit"
}
]
}
]
}
Please note contents tag in response is a list of content object for viral tag. Sometimes contents array size gone over 50 objects. So, I want to implement pagination for that. How can I implement pagination for content?

Microsoft LUIS builtin.number

I used builtin.number in my LUIS app trying to collect a 4 digit pin number. The following is what's returned from LUIS when my input is "one two three four".
"entities": [
{
"entity": "one",
"type": "builtin.number",
"startIndex": 0,
"endIndex": 2,
"resolution": {
"value": "1"
}
},
{
"entity": "two",
"type": "builtin.number",
"startIndex": 4,
"endIndex": 6,
"resolution": {
"value": "2"
}
},
{
"entity": "three",
"type": "builtin.number",
"startIndex": 8,
"endIndex": 12,
"resolution": {
"value": "3"
}
},
{
"entity": "four",
"type": "builtin.number",
"startIndex": 14,
"endIndex": 17,
"resolution": {
"value": "4"
}
},
As you can see, it's returning individual digits in both text and digit format. Seems to me that it's more important to return the whole digit than the individual ones. Is there a way to do it so that I get '1234' as result for builtin.number?
Thanks!
It's not possible to do what you're asking for by only using LUIS. The way LUIS does its tokenization is that it recognizes each word/number individually due to the whitespace. It goes without saying that 'onetwothreefour' will also not return 1234.
Additionally, users are unable to modify the recognition of the prebuilt entities on an individual model level. The recognizers for certain languages are open-source, and contributions from the community are welcome.
All of that said, a way you could achieve what you're asking for is by concatenating the numbers. A JavaScript example might be something like the following:
var pin = '';
entities.forEach(entity => {
if (entity.type == 'builtin.number') {
pin += entity.resolution.value;
}
}
console.log(pin); // '1234'
After that you would need to perform your own handling/regexp, but I'll leave that to you. (after all, what if someone provides "seven eight nine ten"? Or "twenty seventeen"?)

Does Kendo UI DropDownList support grouping?

I'm using Kendo UI DropDownList but cannot find a way to group values in it. is this feature available?
saw the following post from early 2013 which says that this was on the roadmap, but not sure if it was implemented or not.
http://www.telerik.com/forums/option-group-for-datasource-in-dropdownlist
As of the Q1 2015 release, this is supported on the datasource. It doesn't look like you can do this when binding to local data though.
UserVoice Item
Demo
Grouping actually is supported now, in conjunction with the datasource. Here is a code snippet that will create a dropdown list using Kendo UI 2015.3.1111 and jQuery 1.9.1, grouping by team colors. The datasource, candidates, is a local array of data items. The dropdown list will replace an HTML element on the page, <input id="victim"/>.
var candidates = [
{ "id": 1, "name": "Alice", "team": "Red" },
{ "id": 2, "name": "Bob", "team": "Red" },
{ "id": 3, "name": "Charlie", "team": "Blue" },
{ "id": 4, "name": "Dorothy", "team": "Blue" },
{ "id": 5, "name": "Ed", "team": "Green" },
{ "id": 6, "name": "Frances", "team": "Green" },
{ "id": 7, "name": "George", "team": "Purple" },
{ "id": 8, "name": "Helen", "team": "Purple" },
];
$("#victim").kendoDropDownList({
"dataTextField": "name",
"dataValueField": "id",
"dataSource": { "data": candidates, "group": "team" },
"index": 0
});
This is what the dropdown looks like with stock styling in FireFox:
I hadn't noticed before, but the widget also orders the groups.
Grouping is not supported by the Kendo DropDownList widget.

Resources