How can I programmatically select a listview item?
I have the following listview:
listview =
select [ Html.Events.on "change" (Json.Decode.map InputContentType Html.Events.targetValue) ]
[ option [ value "instructions" ] [ text "Content Type" ]
, option [ value "Article" ] [ text "Article" ]
, option [ value "Video" ] [ text "Video" ]
, option [ value "Answer" ] [ text "Answer" ]
, option [ value "Podcast" ] [ text "Podcast" ]
]
Update:
I incorporated the posted answer below and updated the solution as follows:
( isArticle, isVideo, isAnswer, isPodcast ) =
if hasText "youtube.com" then
( False, True, False, False )
else if hasText "vimeo.com" then
( False, True, False, False )
else if hasText "wordpress.com" then
( True, False, False, False )
else if hasText "medium.com" then
( True, False, False, False )
else if hasText "stackoverflow.com" then
( False, False, True, False )
else
( False, False, False, False )
listview =
select [ Html.Events.on "change" (Json.Decode.map InputContentType Html.Events.targetValue) ]
[ option [ value "instructions" ] [ text "Content Type" ]
, option [ value "Article", selected isArticle ] [ text "Article" ]
, option [ value "Video", selected isVideo ] [ text "Video" ]
, option [ value "Answer", selected isAnswer ] [ text "Answer" ]
, option [ value "Podcast", selected isPodcast ] [ text "Podcast" ]
]
You are able to use the Html.Attributes.selected function to select programmatically one of the options. It accepts a Bool, so whenever it's True, it will select that option.
listview =
select [ Html.Events.on "change" (Json.Decode.map InputContentType Html.Events.targetValue) ]
[ option [ value "instructions" ] [ text "Content Type" ]
, option [ value "Article", selected True ] [ text "Article" ]
, option [ value "Video" ] [ text "Video" ]
, option [ value "Answer" ] [ text "Answer" ]
, option [ value "Podcast" ] [ text "Podcast" ]
]
Related
I have the following polygon displayed on a map:
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-125.59984949809844,
45.262153541142055
],
[
-64.97100463461506,
39.503280047917194
],
[
-71.53494497281665,
25.360849581306127
],
[
-121.81059696453559,
26.995032595715646
],
[
-125.59984949809844,
45.262153541142055
]
]
]
},
"properties": {}
}
Calling
console.log(booleanPointInPolygon([-98.65195, 49.42827], polygon)); //logs false
console.log(booleanPointInPolygon([-106.53965, 27.69895], polygon)); //logs true
when the expected output should be the opposite. I'm pretty sure my data is in the right form [longitude, latitude], I am wondering what's giving me the wrong output?
I am trying to update a nested collection in my Postgres table using json_set, however, my approach is resulting in a collection of null values.
id
payload
row_version
fbfd3b9d-bb20-4c1b-985f-0979890472ec
{ "slots": [ { "bannerXCreatorSettings": { "additionalFields": [ { "label": "test-label", "enabled": true, "mandatory": false, "additionalFieldId": "label", "maxCharacterLimit": 22, "additionalFieldType": "TEXT", "colorHexOptionsList": [] }, { "label": "test-label-2", "enabled": true, "mandatory": false, "additionalFieldId": "label2", "maxCharacterLimit": 55, "additionalFieldType": "TEXT", "colorHexOptionsList": [] } ] } } ]}
1
I have the following json payload stored in my table:
{
"slots": [
{
"bannerXCreatorSettings": {
"additionalFields": [
{
"label": "test-label",
"enabled": true,
"mandatory": false,
"additionalFieldId": "label",
"maxCharacterLimit": 22,
"additionalFieldType": "TEXT",
"colorHexOptionsList": []
},
{
"label": "test-label-2",
"enabled": true,
"mandatory": false,
"additionalFieldId": "label2",
"maxCharacterLimit": 55,
"additionalFieldType": "TEXT",
"colorHexOptionsList": []
}
]
}
}
]
}
Within the additionalFields collections, I want to add selectOptions. Like this:
{
"slots": [
{
"bannerXCreatorSettings": {
"additionalFields": [
{
"label": "test-label",
"enabled": true,
"mandatory": false,
"additionalFieldId": "label",
"maxCharacterLimit": 22,
"additionalFieldType": "TEXT",
"colorHexOptionsList": [],
"selectOptions": [] <-- new field
},
{
"label": "test-label-2",
"enabled": true,
"mandatory": false,
"additionalFieldId": "label2",
"maxCharacterLimit": 55,
"additionalFieldType": "TEXT",
"colorHexOptionsList": [],
"selectOptions": [] <-- new field
}
]
}
}
]
}
I have written the following SQL to try update the JSON payload within my table:
select
id,
payload,
row_version,
jsonb_set(
payload,
'{slots}',
(select
jsonb_agg(
jsonb_set(
slot_elem,
'{bannerXCreatorSettings}',
jsonb_set(
slot_elem -> 'bannerXCreatorSettings',
'{additionalFields}',
(
select
jsonb_agg(
jsonb_set(
field_element,
'{selectOptions}',
jsonb_build_array()))
from jsonb_array_elements(
slot_elem -> '{bannerXCreatorSettings}' #>'{additionalFields}') WITH ORDINALITY a_t(field_element, idx_1))
)
)
)
FROM
jsonb_array_elements(
payload #> '{slots}') WITH ORDINALITY t(slot_elem, idx))) as payload_update
My understanding of SQL is limited, however, I feel as though this should work. Unfortunally the above query results in the following:
{
"slots": [
null,
null
]
}
I am dealing with the following JSON in a Postgres database column called steps in a table called tCampaign :
[
{
"name":"Step 1",
"stepReference":"01e9f7c0-bc79-11eb-ab6f-2fa1cb676e38",
"rewardConditions": [
{
"conditionDefinitions": [
{
"instanceId":"01805260-0818-4e99-e5b1-5820d1b133cd",
"type":"registration",
"properties": null,
"name": "Registration"
},
{
"instanceId":"01e115c3-5e56-437a-5d13-6c04281e9588",
"type":"optIn",
"properties": null,
"name":"Opt In"
}
],
"rewardDefinitions":[
{
"instanceId":"01c82190-1d56-44f9-474a-513732302e28",
"type":"sportsReward",
"properties": {"activation": {"type": "onReward"}, "betFlavour": "SPORTS", "channels": ["__use_campaign_restrictions__"], "expiry": {"offset": {"days": "02", "hours": "00", "minutes": "00", "seconds": "00"}, "type": "relative"}, "inRunning": "-", "maxReward": {"USD": "1"}, "minimumOdds": "", "oddsInput": {"minimumOdds": {"american": "", "european": ""}}, "retail": "offBetBuild", "returnStakeOnPayout": "false"},
"name":"Freebet",
"calculator":{"type":"fixed","value":"100"}
}
]
}
]
},
{
"name" : "Step 2",
"stepReference" : "01daa4a0-bc79-11eb-ab6f-2fa1cb676e38",
"rewardConditions": [
{
"conditionDefinitions": [
{
"instanceId" : "01fb15ae-01d0-49e1-966a-8ff438e9a191",
"type" : "genericSportsBet",
"properties" : {"betFlavour": "SPORTS", "betTrackEventThreshold": "10", "betTypes": [ "SGL" ], "builderBetOption": "ALL", "channels": [ "__use_campaign_restrictions__" ], "currencyThresholdMap": { "USD": "1" }, "eventHierarchySelection": { "categories": [], "classes": [], "events": [], "marketTemplates": [], "markets": [ "5824" ], "retrobetEventIds": [ "1200" ], "selections": [], "selectionsMarket": [], "types": [] }, "eventHierarchySelectionUI": { "markets": [ { "id": 5824, "mapping": [], "name": "Match Result", "parentId": 1200, "parentParentId": 5, "path": [ "Category: |England|", "Class: |England Premier League|", "Type: |GK Team K| |vs| |GK Team L|" ], "selectionMapper": false, "settled": "N", "startTime": "2021-05-31 11:15:00", "status": "A" } ] }, "inRunning": "-", "legTypes": [ "WIN" ], "metOnSettlement": false, "minOdds": "", "oddsInput": { "minOdds": { "american": "", "european": "" } }, "priceTypes": [ "LP" ]},
"name" : "Sports Bet"
}
],
"rewardDefinitions":[
{
"instanceId" : "0110eb70-44f9-4d57-40bb-09ff4169136c",
"type" : "sportsReward",
"properties" : {"activation": {"type": "onReward"}, "betFlavour": "SPORTS", "channels": ["__use_campaign_restrictions__"], "expiry": {"offset": {"days": "02", "hours": "00", "minutes": "00", "seconds": "00"}, "type": "relative"}, "inRunning": "-", "maxReward": {"USD": "2"}, "minimumOdds": "", "oddsInput": {"minimumOdds": {"american": "", "european": ""}}, "retail": "offBetBuild", "returnStakeOnPayout": "false"},
"name" : "Freebet",
"calculator" : {"type":"fixed","value":"100"}
}
]
}
]
}
]
and have written the following query to extract properties from conditionDefinitions :
select conditionDefinitions->'properties' as properties from tcampaign cmp
LEFT JOIN LATERAL json_array_elements(steps) singleStep ON true
LEFT JOIN LATERAL json_array_elements(singleStep->'rewardConditions') rewardConditions on TRUE
LEFT JOIN LATERAL json_array_elements(rewardConditions->'conditionDefinitions') conditionDefinitions on TRUE
where properties is not null ;
but I get the following error :
ERROR: column "properties" does not exist
LINE 5: where properties is null ;
If I remove the where clause the query runs fine. Why do I not have access to properties in the where clause? Because I can see results coming back if I remove the WHERE clause, so the query does have results
enter code hereI am using Fusion chart through time series plotting through multiple line, but it is always plotting a single line chart. so please help me if it is possible.
[enter image description here][1]
here is the data which I am using to create Fusion chart
data =
[
[
"01-Feb-11",
"Grocery",
8866
],
[
"01-Feb-11",
"Footwear",
984
],
[
"02-Feb-11",
"Grocery",
2174
],
[
"02-Feb-11",
"Footwear",
1109
],
[
"03-Feb-11",
"Grocery",
2084
],
[
"03-Feb-11",
"Footwear",
6526
],
[
"04-Feb-11",
"Grocery",
1503
],
[
"04-Feb-11",
"Footwear",
1007
],
[
"05-Feb-11",
"Grocery",
4928
]
]
Schema :
[1]: https://i.stack.imgur.com/QwDwv.png
You can use the code below to render a multi-series chart
yaxis: [
{
plot: "Sales Value",
title: "Sale Value",
format: {
prefix: "$"
}
}
]
Here is a demo : https://jsfiddle.net/ug0af52o/
My Model type is:
type alias Model =
{ freeSyllables : List FreeSyllable
, freeSyllableInput : String
, usageStartInput : Bool
, usageMidInput : Bool
, usageEndInput : Bool
}
The FreeSyllable type looks like:
type alias FreeSyllable =
{ syllable : String
, usage : Usage
}
The Usage type has three Boolean fields:
type alias Usage =
{ start : Bool
, mid : Bool
, end : Bool
}
I tried to render each item of the model's FreeSyllables-List to a table.
I didn't succeed.
So my question is how I can dynamically render each of the model's "FreeSyllables" into a proper html table with these columns:
syllable (textbox)
start usage (checkbox)
mid usage (checkbox)
end usage (checkbox)
actions (save-Button)
You'll have to attach event handlers (that fire Msg), but here is example view:
view : Model -> Html Msg
view model =
table [] <|
[ tr []
[ th [] [ text "syllable" ]
, th [] [ text "start" ]
, th [] [ text "mid" ]
, th [] [ text "end" ]
, th [] [ text "actions" ]
]
]
++ (List.map viewItem model.freeSyllables)
viewItem : FreeSyllable -> Html Msg
viewItem s =
tr []
[ th [] [ text s.syllable ]
, th [] [ input [ type_ "checkbox", checked s.usage.start ] [] ]
, th [] [ input [ type_ "checkbox", checked s.usage.mid ] [] ]
, th [] [ input [ type_ "checkbox", checked s.usage.end ] [] ]
, th [] [ button [] [ text "save" ] ]
]