github.com/simpleiot/simpleiot@v0.18.3/frontend/src/Components/NodeCondition.elm (about) 1 module Components.NodeCondition exposing (view) 2 3 import Api.Node as Node 4 import Api.Point as Point 5 import Components.NodeOptions exposing (CopyMove(..), NodeOptions, findNode, oToInputO) 6 import Element exposing (..) 7 import Element.Background as Background 8 import Element.Border as Border 9 import Element.Font as Font 10 import UI.Icon as Icon 11 import UI.NodeInputs as NodeInputs 12 import UI.Style as Style 13 14 15 view : NodeOptions msg -> Element msg 16 view o = 17 let 18 active = 19 Point.getBool o.node.points Point.typeActive "" 20 21 descBackgroundColor = 22 if active then 23 Style.colors.blue 24 25 else 26 Style.colors.none 27 28 descTextColor = 29 if active then 30 Style.colors.white 31 32 else 33 Style.colors.black 34 35 error = 36 Point.getText o.node.points Point.typeError "" 37 38 disabled = 39 Point.getBool o.node.points Point.typeDisabled "" 40 41 titleBackground = 42 if disabled then 43 Style.colors.ltgray 44 45 else if error /= "" then 46 Style.colors.red 47 48 else 49 Style.colors.none 50 in 51 column 52 [ width fill 53 , Border.widthEach { top = 2, bottom = 0, left = 0, right = 0 } 54 , Border.color Style.colors.black 55 , spacing 6 56 ] 57 <| 58 wrappedRow 59 [ spacing 10 60 , paddingEach { top = 0, right = 10, bottom = 0, left = 0 } 61 , Background.color titleBackground 62 , width fill 63 ] 64 [ Icon.check 65 , el [ Background.color descBackgroundColor, Font.color descTextColor ] <| 66 text <| 67 Point.getText o.node.points Point.typeDescription "" 68 , if Point.getBool o.node.points Point.typeDisabled "" then 69 text "(disabled)" 70 71 else 72 text "" 73 ] 74 :: (if o.expDetail then 75 let 76 labelWidth = 77 150 78 79 opts = 80 oToInputO o labelWidth 81 82 textInput = 83 NodeInputs.nodeTextInput opts "0" 84 85 optionInput = 86 NodeInputs.nodeOptionInput opts "0" 87 88 conditionType = 89 Point.getText o.node.points Point.typeConditionType "" 90 91 checkboxInput = 92 NodeInputs.nodeCheckboxInput opts "0" 93 in 94 [ textInput Point.typeDescription "Description" "" 95 , optionInput Point.typeConditionType 96 "Type" 97 [ ( Point.valuePointValue, "point value" ) 98 , ( Point.valueSchedule, "schedule" ) 99 ] 100 , case conditionType of 101 "pointValue" -> 102 pointValue o labelWidth 103 104 "schedule" -> 105 schedule o labelWidth 106 107 _ -> 108 el [ Font.color Style.colors.red ] <| text "Please select condition type" 109 , checkboxInput Point.typeDisabled "Disabled" 110 , NodeInputs.nodeKeyValueInput opts Point.typeTag "Tags" "Add Tag" 111 , el [ Font.color Style.colors.red ] <| text error 112 ] 113 114 else 115 [] 116 ) 117 118 119 schedule : NodeOptions msg -> Int -> Element msg 120 schedule o labelWidth = 121 let 122 opts = 123 oToInputO o labelWidth 124 in 125 NodeInputs.nodeTimeDateInput opts labelWidth 126 127 128 pointValue : NodeOptions msg -> Int -> Element msg 129 pointValue o labelWidth = 130 let 131 opts = 132 oToInputO o labelWidth 133 134 textInput = 135 NodeInputs.nodeTextInput opts "0" 136 137 numberInput = 138 NodeInputs.nodeNumberInput opts "0" 139 140 optionInput = 141 NodeInputs.nodeOptionInput opts "0" 142 143 conditionValueType = 144 Point.getText o.node.points Point.typeValueType "0" 145 146 nodeId = 147 Point.getText o.node.points Point.typeNodeID "0" 148 in 149 column 150 [ width fill 151 , spacing 6 152 ] 153 [ textInput Point.typeNodeID "Node ID" "" 154 , if nodeId /= "" then 155 let 156 nodeDesc = 157 case findNode o.nodes nodeId of 158 Just node -> 159 el [ Background.color Style.colors.ltblue ] <| 160 text <| 161 "(" 162 ++ Node.getBestDesc node 163 ++ ")" 164 165 Nothing -> 166 el [ Background.color Style.colors.orange ] <| text "(node not found)" 167 in 168 el [ Font.italic, paddingEach { top = 0, right = 0, left = 170, bottom = 0 } ] <| 169 nodeDesc 170 171 else 172 Element.none 173 , case o.copy of 174 CopyMoveNone -> 175 Element.none 176 177 Copy id _ desc -> 178 if nodeId /= id then 179 let 180 label = 181 row [ spacing 10 ] 182 [ text <| "paste ID for node: " 183 , el 184 [ Font.italic 185 , Background.color Style.colors.ltblue 186 ] 187 <| 188 text desc 189 ] 190 in 191 NodeInputs.nodePasteButton opts label Point.typeNodeID id 192 193 else 194 Element.none 195 , optionInput Point.typePointType 196 "Point Type" 197 [ ( Point.typeValue, "value" ) 198 , ( Point.typeValueSet, "set value" ) 199 , ( Point.typeErrorCount, "error count" ) 200 , ( Point.typeSysState, "system state" ) 201 , ( Point.typeActive, "active" ) 202 ] 203 , textInput Point.typePointKey "Point Key" "" 204 , optionInput Point.typeValueType 205 "Point Value Type" 206 [ ( Point.valueNumber, "number" ) 207 , ( Point.valueOnOff, "on/off" ) 208 , ( Point.valueText, "text" ) 209 ] 210 , if conditionValueType /= Point.valueOnOff then 211 let 212 operators = 213 case conditionValueType of 214 "number" -> 215 [ ( Point.valueGreaterThan, ">" ) 216 , ( Point.valueLessThan, "<" ) 217 , ( Point.valueEqual, "=" ) 218 , ( Point.valueNotEqual, "!=" ) 219 ] 220 221 "text" -> 222 [ ( Point.valueEqual, "=" ) 223 , ( Point.valueNotEqual, "!=" ) 224 , ( Point.valueContains, "contains" ) 225 ] 226 227 _ -> 228 [] 229 in 230 optionInput Point.typeOperator "Operator" operators 231 232 else 233 Element.none 234 , case conditionValueType of 235 "number" -> 236 numberInput Point.typeValue "Point Value" 237 238 "onOff" -> 239 let 240 onOffInput = 241 NodeInputs.nodeOnOffInput opts "" 242 in 243 onOffInput Point.typeValue Point.typeValue "Point Value" 244 245 "text" -> 246 textInput Point.typeValueText "Point Value" "" 247 248 _ -> 249 Element.none 250 , numberInput Point.typeMinActive "Min active time (m)" 251 ]