Commit 8e4cf248 authored by Bas Lijnse's avatar Bas Lijnse

Simplified confirmation of applied effects in layout rules

parent c1ac965f
......@@ -155,10 +155,6 @@ sequenceLayouts :: [LayoutRule] -> LayoutRule
| ESToBeApplied a
| ESToBeUpdated a a
| ESToBeRemoved a
//Moving nodes happens in two steps, therefore we need additional intermediate states
| ESPartiallyApplied a
| ESPartiallyUpdated a a
| ESPartiallyRemoved a
//Nodes that are moved by a moveSubUIs rule need to be accesible both in their source location (to apply changes)
//and in their destination location (to apply further effects).
......@@ -187,11 +183,12 @@ instance toString LUINo
initLUI :: UI -> LUI
initLUIMoves :: LUIMoves
extractResetChange :: (LUI,LUIMoves) -> (UIChange,(LUI,LUIMoves))
applyUpstreamChange :: UIChange (LUI,LUIMoves) -> (LUI,LUIMoves)
extractDownstreamChange :: (LUI,LUIMoves) -> (!UIChange,!(LUI,LUIMoves))
extractUIWithEffects :: (LUI,LUIMoves) -> (!Maybe UI,!(LUI,LUIMoves))
//Helper functions (exported for unit testing)
scanToPosition_ :: LUINo Int [LUI] LUIMoves -> (Int,Bool,Maybe LUI)
......@@ -204,4 +201,5 @@ selectAttributes_ :: UIAttributeSelection UIAttributes -> UIAttributes
overwriteAttribute_ :: LUINo UIAttribute (Map UIAttributeKey (LUIEffectStage (LUINo,JSONNode))) -> (Map UIAttributeKey (LUIEffectStage (LUINo,JSONNode)))
hideAttribute_ :: LUINo (UIAttributeKey -> Bool) UIAttributeKey (Map UIAttributeKey (LUIEffectStage LUINo)) -> (Map UIAttributeKey (LUIEffectStage LUINo))
matchAttributeKey_ :: UIAttributeSelection UIAttributeKey -> Bool
extractUIWithEffects_ :: (LUI,LUIMoves) -> Maybe UI
fullyApplied_ :: (LUI,LUIMoves) -> Bool
This diff is collapsed.
......@@ -44,34 +44,45 @@ applyLayout rule task=:(Task evala) = Task eval
//On Reset events, we (re-)apply the layout
eval ResetEvent evalOpts (TCLayout _ tt) iworld = case evala ResetEvent evalOpts tt iworld of
(ValueResult value info (ReplaceUI ui) tt,iworld)
# (mbUI,state) = extractUIWithEffects (rule ruleNo (initLUI ui, initLUIMoves))
# ui = fromMaybe (UI UIEmpty 'DM'.newMap []) mbUI
# (change,state) = extractResetChange (rule ruleNo (initLUI ui, initLUIMoves))
//| not (trace_tn ("STATE AFTER RESET: \n"+++toString (toJSON state))) = undef
= (ValueResult value info (ReplaceUI ui) (TCLayout (toJSON state) tt), iworld)
= (ValueResult value info change (TCLayout (toJSON state) tt), iworld)
(res,iworld) = (res,iworld)
eval event evalOpts (TCLayout json tt) iworld = case evala event evalOpts tt iworld of
(ValueResult value info change tt,iworld)
= case fromJSON json of
(Just state)
(Just state1)
//| not (trace_tn ("UPSTREAM CHANGE: \n"+++toString (toJSON change))) = undef
//| not (trace_tn ("STATE BEFORE CHANGE: \n"+++toString (toJSON state))) = undef
# state = applyUpstreamChange change state
//| not (trace_tn ("STATE AFTER CHANGE: \n"+++toString (toJSON state))) = undef
# state = rule ruleNo state
//| not (trace_tn ("STATE AFTER RULES: \n"+++toString (toJSON state))) = undef
# (change,state) = extractDownstreamChange state
//| not (trace_tn ("STATE AFTER EXTRACT: \n"+++toString (toJSON state))) = undef
//| not (trace_tn ("STATE BEFORE CHANGE: \n"+++toString (toJSON state1))) = undef
# state2 = applyUpstreamChange change state1
//| not (trace_tn ("STATE AFTER CHANGE: \n"+++toString (toJSON state2))) = undef
# state3 = rule ruleNo state2
//| not (trace_tn ("STATE AFTER RULES: \n"+++toString (toJSON state3))) = undef
# (change,state4) = extractDownstreamChange state3
//| not (trace_tn ("STATE AFTER EXTRACT: \n"+++toString (toJSON state4))) = undef
//| not (trace_tn ("DOWNSTREAM CHANGE: \n"+++toString (toJSON change))) = undef
//| not (trace_tn "=====") = undef
= (ValueResult value info change (TCLayout (toJSON state) tt), iworld)
| not (fullyApplied_ state4)
# iworld = traceState "state-before-change.txt" state1 iworld
# iworld = traceState "state-after-change.txt" state2 iworld
# iworld = traceState "state-after-rules.txt" state3 iworld
# iworld = traceState "state-after-extract.txt" state4 iworld
= (ExceptionResult (exception ("Corrupt layout state")), iworld)
= (ValueResult value info change (TCLayout (toJSON state4) tt), iworld)
Nothing
= (ExceptionResult (exception ("Corrupt layout state:" +++ toString json)), iworld)
(res,iworld) = (res,iworld)
eval event evalOpts state iworld = evala event evalOpts state iworld //Catchall
import StdDebug, StdMisc
traceState filename state iworld
# {IWorld|world} = iworld
# (_,world) = writeFile filename (jsonPrettyPrint (toJSON state)) world
= {IWorld|iworld & world = world}
import StdDebug, StdMisc, System.File, StdFile
import iTasks.Internal.IWorld
class toAttribute a where toAttribute :: a -> JSONNode
instance toAttribute String where toAttribute s = JSONString s
......
......@@ -149,4 +149,4 @@ where
applyLayoutRule :: LayoutRule UI -> UI
applyLayoutRule rule ui = fromMaybe (UI UIEmpty 'DM'.newMap [])
(fst (extractUIWithEffects (rule (LUINo [0]) (initLUI ui,initLUIMoves))))
(extractUIWithEffects_ (rule (LUINo [0]) (initLUI ui,initLUIMoves)))
......@@ -315,6 +315,8 @@ extractDownstreamChangeTests =
,extractDownstreamChangeTest_RemovingUnwrappedContainer
,extractDownstreamChangeTest_ShiftingInUnwrappedContainer
,extractDownstreamChangeTest_MovingIntoAdditionalContainer
,extractDownstreamChangeTest_MovingIntoInsertedContainer
,extractDownstreamChangeTest_MovingIntoMovedContainer
]
extractDownstreamChangeTest_TopLevelReplace =
......@@ -1029,7 +1031,63 @@ extractDownstreamChangeTest_MovingIntoAdditionalContainer =
] noChanges noEffects
,'DM'.fromList [(1,LUINode UIStep 'DM'.newMap [] noChanges {LUIEffects|noEffects & moved = ESToBeApplied (LUINo [3])})]))
extractUIWithEffectsTests =
extractDownstreamChangeTest_MovingIntoInsertedContainer =
assertEqual "Moving items to an upstream inserted container"
(ChangeUI [] [(1,InsertChild (UI UIParallel 'DM'.newMap [UI UIStep 'DM'.newMap []])), (2,RemoveChild)]
,(LUINode UIPanel ('DM'.fromList [("title",JSONString "A")])
[LUINode UIInteract 'DM'.newMap [] noChanges noEffects
,LUINode UIParallel 'DM'.newMap [
LUIMoveDestination 1 (LUINo [2])
] noChanges noEffects
,LUIMoveSource 1
] noChanges noEffects
,'DM'.fromList [(1,LUINode UIStep 'DM'.newMap [] noChanges {LUIEffects|noEffects & moved = ESApplied (LUINo [2])})])
)
(extractDownstreamChange (
LUINode UIPanel ('DM'.fromList [("title",JSONString "A")])
[LUINode UIInteract 'DM'.newMap [] noChanges noEffects
,LUINode UIParallel 'DM'.newMap [
LUIMoveDestination 1 (LUINo [2])
] {noChanges & toBeInserted = True} noEffects
,LUIMoveSource 1
] noChanges noEffects
,'DM'.fromList [(1,LUINode UIStep 'DM'.newMap [] noChanges {LUIEffects|noEffects & moved = ESToBeApplied (LUINo [2])})]))
extractDownstreamChangeTest_MovingIntoMovedContainer =
assertEqual "Moving items to into a container that was moved itself"
(ChangeUI [] [(1,InsertChild (UI UIParallel 'DM'.newMap [UI UIStep 'DM'.newMap [UI UIEmpty 'DM'.newMap []]])), (2,RemoveChild),(2,RemoveChild)],
(LUINode UIPanel 'DM'.newMap
[LUINode UIInteract 'DM'.newMap [] noChanges noEffects
,LUINode UIParallel 'DM'.newMap [
LUIMoveDestination 1 (LUINo [2])
] noChanges noEffects
,LUIMoveSource 1
,LUIMoveSource 2
] noChanges noEffects
,'DM'.fromList
[(1,LUINode UIStep 'DM'.newMap [
LUIMoveDestination 2 (LUINo [3])
] noChanges {LUIEffects|noEffects & moved = ESApplied (LUINo [2])})
,(2,LUINode UIEmpty 'DM'.newMap [] noChanges {LUIEffects|noEffects & moved = ESApplied (LUINo [3])})
])
)
(extractDownstreamChange (
LUINode UIPanel 'DM'.newMap
[LUINode UIInteract 'DM'.newMap [] noChanges noEffects
,LUINode UIParallel 'DM'.newMap [
LUIMoveDestination 1 (LUINo [2])
] {noChanges & toBeInserted = True} noEffects
,LUIMoveSource 1
,LUIMoveSource 2
] noChanges noEffects
,'DM'.fromList
[(1,LUINode UIStep 'DM'.newMap [
LUIMoveDestination 2 (LUINo [3])
] noChanges {LUIEffects|noEffects & moved = ESToBeApplied (LUINo [2])})
,(2,LUINode UIEmpty 'DM'.newMap [] noChanges {LUIEffects|noEffects & moved = ESToBeApplied (LUINo [3])})
]))
extractUIWithEffects_Tests =
[assertEqual "Extract UI with newly moved items"
(Just (UI UIPanel ('DM'.fromList [("title",JSONString "Parent panel")])
[UI UIStep 'DM'.newMap
......@@ -1037,17 +1095,8 @@ extractUIWithEffectsTests =
,UI UIParallel 'DM'.newMap []
]
])
,(LUINode UIPanel ('DM'.fromList [("title",JSONString "Parent panel")])
[LUIMoveSource 1
,LUINode UIStep 'DM'.newMap [LUIMoveDestination 1 (LUINo [0]),LUIMoveDestination 2 (LUINo [0])] noChanges noEffects
,LUIMoveSource 2
] noChanges noEffects
,'DM'.fromList
[(1,LUINode UIInteract 'DM'.newMap [] noChanges {LUIEffects|noEffects & moved = ESApplied (LUINo [0])})
,(2,LUINode UIParallel 'DM'.newMap [] noChanges {LUIEffects|noEffects & moved = ESApplied (LUINo [0])})
])
)
(extractUIWithEffects (
(extractUIWithEffects_ (
LUINode UIPanel ('DM'.fromList [("title",JSONString "Parent panel")])
[LUIMoveSource 1
,LUINode UIStep 'DM'.newMap [LUIMoveDestination 1 (LUINo [0]),LUIMoveDestination 2 (LUINo [0])] noChanges noEffects
......@@ -1064,18 +1113,8 @@ extractUIWithEffectsTests =
[UI UIInteract 'DM'.newMap []
]
])
,(LUINode UIPanel ('DM'.fromList [("title",JSONString "Parent panel")])
[LUIMoveSource 1
,LUIMoveDestination 2 (LUINo [1])
,LUINode UIStep 'DM'.newMap [LUIMoveDestination 1 (LUINo [0])] noChanges noEffects
,LUIMoveSource 2
] noChanges noEffects
,'DM'.fromList
[(1,LUINode UIInteract 'DM'.newMap [] noChanges {LUIEffects|noEffects & moved = ESApplied (LUINo [0])})
,(2,LUINode UIParallel 'DM'.newMap [] noChanges {LUIEffects|noEffects & moved = ESApplied (LUINo [1])})
])
)
(extractUIWithEffects (
(extractUIWithEffects_ (
LUINode UIPanel ('DM'.fromList [("title",JSONString "Parent panel")])
[LUIMoveSource 1
,LUIMoveDestination 2 (LUINo [1])
......@@ -1088,11 +1127,8 @@ extractUIWithEffectsTests =
]))
,assertEqual "Extract UI with new wrapped"
(Just (UI UIContainer 'DM'.newMap [UI UIStep 'DM'.newMap []])
,(LUINode UIContainer 'DM'.newMap
[LUINode UIStep 'DM'.newMap [] noChanges noEffects
] noChanges {noEffects & wrapper = ESApplied (LUINo [2])}
,initLUIMoves))
(extractUIWithEffects (
)
(extractUIWithEffects_ (
LUINode UIContainer 'DM'.newMap
[LUINode UIStep 'DM'.newMap [] noChanges noEffects
] noChanges {noEffects & wrapper = ESToBeApplied (LUINo [2])}
......@@ -1516,16 +1552,8 @@ combinationTests =
)
//Extract the initial ui
,assertEqual "Combination rule: wrapping after unwrapping -> initial ui"
(Just (UI UIDebug 'DM'.newMap [UI UIInteract 'DM'.newMap []])
,(LUINode UIStep 'DM'.newMap
[LUINode UIDebug 'DM'.newMap [
LUINode UIInteract 'DM'.newMap [
] noChanges noEffects
] noChanges {noEffects & wrapper = ESApplied (LUINo [0,1])}
] noChanges {noEffects & unwrapped = ESApplied (LUINo [0,0])}
,'DM'.newMap))
(extractUIWithEffects
(Just (UI UIDebug 'DM'.newMap [UI UIInteract 'DM'.newMap []]))
(extractUIWithEffects_
(LUINode UIStep 'DM'.newMap
[LUINode UIDebug 'DM'.newMap [
LUINode UIInteract 'DM'.newMap [
......@@ -1585,7 +1613,7 @@ combinationTests =
tests = applyUpstreamChangeTests
++ extractDownstreamChangeTests
++ extractUIWithEffectsTests
++ extractUIWithEffects_Tests
++ updateChildNodes_Tests
++ selectSubNode_Tests
++ updateSubNode_Tests
......
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