Commit 71b3c92c authored by Bas Lijnse's avatar Bas Lijnse

Implemented proper handling of list manipulation edit events

parent 8d105ac0
......@@ -273,6 +273,7 @@ itasks.Component = {
},
moveChild: function(sidx,didx) {
var me = this, child;
if(me.initialized) {
if(didx == (me.containerEl.children.length - 1)) {
me.containerEl.appendChild(me.containerEl.children[sidx]);
......@@ -280,8 +281,9 @@ itasks.Component = {
me.containerEl.insertBefore(me.containerEl.children[sidx],me.containerEl.children[(didx > sidx) ? (didx + 1) : didx]);
}
}
child = me.children.splice(sidx,1)[0]; //Remove followed by insert...
me.children.splice((didx > sidx) ? (didx - 1) : didx, 0, child);
me.children.splice(didx, 0, child);
},
beforeChildRemove: function(idx) {},
setAttribute: function(name,value) {
......@@ -326,7 +328,7 @@ itasks.Component = {
}
//Handle child changes
childChanges.forEach(function(change) {
idx = change[0];
var idx = change[0];
switch(change[1]) {
case 'change':
if(idx >= 0 && idx < me.children.length) {
......@@ -343,6 +345,7 @@ itasks.Component = {
break;
case 'move':
me.moveChild(idx,change[2]);
break;
}
});
},
......
......@@ -53,19 +53,29 @@ where
# [op,id:_] = split "_" e
# id = toInt id
# index = itemIndex id ids
# num = length items
| op == "mup" && reorder
| index < 1 || index >= (length items) = (Error "List move-up out of bounds",items,vst)
= (Ok (ChangeUI [] [(index,MoveChild (index - 1))],CompoundMask {fields=(swap masks index),state=toJSON (swap ids index)}), (swap items index), vst)
| index < 1 || index >= num = (Error "List move-up out of bounds",items,vst)
# changes = if (index == 1) [(index,toggle 1 False),(index - 1,toggle 1 True)] [] //Update 'move-up' buttons
++ if (index == num - 1) [(index,toggle 2 True),(index - 1,toggle 2 False)] [] //Update 'move-down' buttons
++ [(index,MoveChild (index - 1))] //Actually move the item
= (Ok (ChangeUI [] changes,CompoundMask {fields=(swap masks index),state=toJSON (swap ids index)}), (swap items index), vst)
| op == "mdn" && reorder
| index < 0 || index > (length items - 2) = (Error "List move-down out of bounds",items,vst)
= (Ok (ChangeUI [] [(index,MoveChild (index + 1))],CompoundMask {fields=(swap masks (index + 1)),state=toJSON (swap ids (index + 1))}), (swap items (index + 1)), vst)
# changes = if (index == 0) [(index,toggle 1 True),(index + 1,toggle 1 False)] [] //Update 'move-up' buttons
++ if (index == num - 2) [(index,toggle 2 False),(index + 1,toggle 2 True)] [] //Update 'move-down' buttons
++ [(index,MoveChild (index + 1))]
= (Ok (ChangeUI [] changes,CompoundMask {fields=(swap masks (index + 1)),state=toJSON (swap ids (index + 1))}), (swap items (index + 1)), vst)
| op == "rem" && remove
| index < 0 || index >= (length items) = (Error "List remove out of bounds",items,vst)
= (Ok (ChangeUI [] [(index,RemoveChild)],CompoundMask {fields=removeAt index masks,state=toJSON (removeAt index ids)}), (removeAt index items), vst)
| index < 0 || index >= num = (Error "List remove out of bounds",items,vst)
# changes = if (index == 0 && num > 1) [(index + 1, toggle 1 False)] []
++ if (index == num - 1 && index > 0) [(index - 1, toggle 2 False)] []
++ [(index,RemoveChild)]
= (Ok (ChangeUI [] changes, CompoundMask {fields=removeAt index masks,state=toJSON (removeAt index ids)}), (removeAt index items), vst)
| op == "add" && add =: (Just _)
# f = fromJust add
# nx = f items
# ni = length items
# ni = num
# nid = nextId ids
= case itemEditor.Editor.genUI (dp++[nid]) nx vst of
(Error e,vst) = (Error e,items,vst)
......@@ -75,7 +85,7 @@ where
# nids = ids ++ [nid]
# insert = [(ni,InsertChild (listItemUI taskId dp (ni + 1) ni nid ui))]
# counter = maybe [] (\f -> [(ni + 1, ChangeChild (ChangeUI [] [(0,ChangeChild (ChangeUI [SetAttribute "value" (JSONString (f nitems))] []))]))]) count
# prevdown = if (ni > 0) [(ni - 1,ChangeChild (ChangeUI [] [(2,ChangeChild (ChangeUI [SetAttribute "enabled" (JSONBool True)] []))]))] []
# prevdown = if (ni > 0) [(ni - 1,toggle 2 True)] []
# change = ChangeUI [] (insert ++ counter ++ prevdown)
= (Ok (change,CompoundMask {fields=nmasks,state=toJSON nids}),nitems,vst)
= (Ok (NoChange,CompoundMask {fields=masks,state=toJSON ids}),items,vst)
......@@ -88,7 +98,7 @@ where
# f = list !! (index-1)
# l = list !! (index)
= updateAt (index-1) l (updateAt index f list)
toggle idx value = ChangeChild (ChangeUI [] [(idx,ChangeChild (ChangeUI [SetAttribute "enabled" (JSONBool value)] []))])
//Edits inside the list
onEdit dp ([id:tp],e) items (CompoundMask {fields=masks,state}) vst
# ids = fromMaybe [] (fromJSON state)
......@@ -119,3 +129,4 @@ where
where
itemIndex` _ _ [] = -1
itemIndex` i id [x:xs] = if (id == x) i (itemIndex` (i + 1) id xs)
......@@ -90,27 +90,27 @@ where
])
maskExp n = FieldMask {touched = False, valid = True, state = JSONInt n}
testMultipleConsesUpdate = skip "Touched constructor selection"
/* testGenUI "Touched constructor selection"
(uia UIDropdown
('DM'.fromList[("optional",JSONBool False),("hint-type",JSONString "valid"),("hint",JSONString "You have correctly selected an option")
,("taskId",JSONString "STUB"),("editorId",JSONString "v")
,("value",JSONArray [JSONInt 0]),("options",JSONArray [JSONString "ConsA",JSONString "ConsB"]) ]))
ConsA Touched
*/
testConsesWithFieldTouched = skip "Touched constructor with field"
/* testGenUI "Touched constructor with field"
(uiac UICompoundContent ('DM'.fromList [("optional",JSONBool False)]) [consExp,fieldsExp])
ConsWithFieldA Touched
testMultipleConsesUpdate = testGenUI "Update constructor selection"
(uic UIVarCons [uia UIDropdown
('DM'.fromList[("taskId",JSONString "STUB"),("editorId",JSONString "v")
,("value",JSONArray [JSONInt 0])
,("options",JSONArray [JSONObject [("id",JSONInt 0),("text",JSONString "ConsA")],JSONObject [("id",JSONInt 1),("text",JSONString "ConsB")]]) ])]
,CompoundMask {fields=[FieldMask {touched=False,valid=True,state=JSONInt 0}],state=JSONNull})
ConsA Update
testConsesWithFieldTouched = testGenUI "Touched constructor with field"
(uic UIVarCons [consExp,fieldsExp],expMask)
ConsWithFieldA Update
where
consExp = (uia UIDropdown
('DM'.fromList[("optional",JSONBool False),("hint-type",JSONString "valid"),("hint",JSONString "You have correctly selected an option")
,("taskId",JSONString "STUB"),("editorId",JSONString "v")
,("value",JSONArray [JSONInt 0]),("options",JSONArray [JSONString "ConsWithFieldA",JSONString "ConsWithFieldB"])]))
,("value",JSONArray [JSONInt 0])
,("options",JSONArray [JSONObject [("id",JSONInt 0),("text",JSONString "ConsWithFieldA")],JSONObject [("id",JSONInt 1),("text",JSONString "ConsWithFieldB")]])])
)
expMask = CompoundMask {fields=[FieldMask {touched=False,valid=True,state=JSONInt 0}],state=JSONNull}
fieldsExp = ui UIEmpty//Placeholder
*/
testRecordTouched = skip "Touched record"
/* testGenUI "Touched record"
......@@ -157,6 +157,7 @@ testGenericEditorEdits = testsuite "Generic edits" "Tests for processing edits b
,testAddListElement
,testMoveListElementUp
,testMoveListElementDown
,testMoveFirstListElementDown
,testRemoveListElement
]
......@@ -179,18 +180,19 @@ testEditConsChange = skip "Change constructor"
*/
testEditListElement = testGenEdit "List element edit"
([42],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 42}],state=JSONNull}
,ChangeUI [] [(0, ChangeChild (ChangeUI [SetAttribute "value" (JSONInt 42), SetAttribute "hint" (JSONString "You have correctly entered a whole number"), SetAttribute "hint-type" (JSONString "valid")] []))])
([0],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONNull}],state=JSONNull})
([42],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 42}],state=JSONArray [JSONInt 0]}
,ChangeUI [] [(0,ChangeChild (ChangeUI [] [(0, ChangeChild (ChangeUI [SetAttribute "value" (JSONInt 42), SetAttribute "hint" (JSONString "You have correctly entered a whole number"), SetAttribute "hint-type" (JSONString "valid")] []))]))])
([0],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONNull}],state=JSONArray [JSONInt 0]})
([0],JSONInt 42)
testAddListElement = testGenEdit "List element add"
([42,0],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 42},FieldMask {touched=False,valid=False,state=JSONNull}],state=JSONNull}
([42,0],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 42},FieldMask {touched=False,valid=False,state=JSONNull}],state=JSONArray[JSONInt 0,JSONInt 1]}
,ChangeUI [] [(1,InsertChild elui)
,(2,ChangeChild (ChangeUI [] [(0, ChangeChild (ChangeUI [SetAttribute "value" (JSONString "2 items")] []))]))
,(0,ChangeChild (ChangeUI [] [(2, ChangeChild (ChangeUI [SetAttribute "enabled" (JSONBool True)] []))]))
])
([42],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 42}],state=JSONNull})
([42],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 42}],state=JSONArray [JSONInt 0]})
([],JSONString "add")
where
elui = uiac UIContainer ('DM'.fromList [("direction",JSONString "horizontal"),("halign",JSONString "right"),("height",JSONString "wrap")]) [inui:buis]
......@@ -206,18 +208,36 @@ where
]
testMoveListElementUp = testGenEdit "Move list element up"
([2,1,3],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 2},FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 3}],state=JSONNull},ChangeUI [] [(1,MoveChild 0)])
([1,2,3], CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 2},FieldMask {touched=True,valid=True,state=JSONInt 3}],state=JSONNull})
([2,1,3],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 2},FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 3}],state=JSONArray [JSONInt 1,JSONInt 0,JSONInt 2]}
,ChangeUI [] [(1,ChangeChild (ChangeUI [] [(1,ChangeChild (ChangeUI [SetAttribute "enabled" (JSONBool False)] []))]))
,(0,ChangeChild (ChangeUI [] [(1,ChangeChild (ChangeUI [SetAttribute "enabled" (JSONBool True)] []))]))
,(1,MoveChild 0)])
([1,2,3], CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 2},FieldMask {touched=True,valid=True,state=JSONInt 3}],state=JSONArray [JSONInt 0,JSONInt 1,JSONInt 2]})
([],JSONString "mup_1")
testMoveListElementDown = testGenEdit "Move list element down"
([1,3,2],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 3},FieldMask {touched=True,valid=True,state=JSONInt 2}],state=JSONNull},ChangeUI [] [(1,MoveChild 2)])
([1,2,3], CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 2},FieldMask {touched=True,valid=True,state=JSONInt 3}],state=JSONNull})
([1,3,2],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 3},FieldMask {touched=True,valid=True,state=JSONInt 2}],state=JSONArray [JSONInt 0,JSONInt 2,JSONInt 1]}
,ChangeUI [] [(1,ChangeChild (ChangeUI [] [(2,ChangeChild (ChangeUI [SetAttribute "enabled" (JSONBool False)] []))]))
,(2,ChangeChild (ChangeUI [] [(2,ChangeChild (ChangeUI [SetAttribute "enabled" (JSONBool True)] []))]))
,(1,MoveChild 2)])
([1,2,3], CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 2},FieldMask {touched=True,valid=True,state=JSONInt 3}],state=JSONArray [JSONInt 0,JSONInt 1,JSONInt 2]})
([],JSONString "mdn_1")
testMoveFirstListElementDown = testGenEdit "Move first list element down"
([2,1,3],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 2},FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 3}],state=JSONArray [JSONInt 1,JSONInt 0,JSONInt 2]}
,ChangeUI [] [(0,ChangeChild (ChangeUI [] [(1,ChangeChild (ChangeUI [SetAttribute "enabled" (JSONBool True)] []))]))
,(1,ChangeChild (ChangeUI [] [(1,ChangeChild (ChangeUI [SetAttribute "enabled" (JSONBool False)] []))]))
,(0,MoveChild 1)])
([1,2,3], CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 2},FieldMask {touched=True,valid=True,state=JSONInt 3}],state=JSONArray [JSONInt 0,JSONInt 1,JSONInt 2]})
([],JSONString "mdn_0")
testRemoveListElement = testGenEdit "Remove list element"
([1,2],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 2}],state=JSONNull},ChangeUI [] [(2,RemoveChild)])
([1,2,3], CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 2},FieldMask {touched=True,valid=True,state=JSONInt 3}],state=JSONNull})
([1,2],CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 2}],state=JSONArray [JSONInt 0,JSONInt 1]},ChangeUI [] [(1,ChangeChild (ChangeUI [] [(2,ChangeChild (ChangeUI [SetAttribute "enabled" (JSONBool False)] []))]))
,(2,RemoveChild)])
([1,2,3], CompoundMask {fields=[FieldMask {touched=True,valid=True,state=JSONInt 1},FieldMask {touched=True,valid=True,state=JSONInt 2},FieldMask {touched=True,valid=True,state=JSONInt 3}],state=JSONArray [JSONInt 0,JSONInt 1,JSONInt 2]})
([],JSONString "rem_2")
testGenericEditorRefreshes :: TestSuite
......
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