Color Picker
Last updated
Last updated
Prepare the basic application containing advanced table loading data from the inMemory database, where any single record can be deleted.
For this task, we will use a color picker to send color codes into the inMemory database, in combination with advanced table gathering data.
The sidebar layout looks to fit our needs. Let's start with the basic layout preparation.
Create a new View and name it colorTable
.
Place in a Sidebar Layout, set up its ID -> sidebarLayout
, and Item Flex -> Stretch
Into the Content of the sidebarLayout
put a Container, name it contTable
, and set Padding -> Wide
Into the Sidebar of the sidebarLayout
put a new Box and configure its property as follows: ID -> sidebarBox
; Background -> WHITE
; Padding -> Wide
; Spacing -> Medium
; Item Flex -> Stretch
The sidebar panel contains a color picker where each picked color has its name. Submit button will send the configuration to our inMemory database, if both values are set up; we will assign submit action later.
A Color component will be placed first, carrying ID -> fldColor
, and Label Value -> "Choose color
"; Label Text Style -> Bold
Put under a Text Input, name it fldName
, and set up as follows: Placeholder -> "name...
"; Label Value -> "Name
"; Label Text Style -> Bold
; Validation Required -> true
A Submit Button will follow, with set up properties: ID -> btnSubmit
; Value -> "Save color
"
State Enabled -> ƒx(fldName.value != "" && fldColor.value != ""
)
Let's prepare an advanced table as an essential part of our layout. Binding its dynamical values will be done later.
Place an Advanced Table into contTable
, name it colorTable
, Spacing-> Narrow
, and set up the following properties.
Add a Name column call its Title text -> "Name
"
Add a Color column call its Title text -> "Color
"; Horizontal Alignment -> Left
; Width -> 50px
Add a Code column call its Title text -> "Code
"; Horizontal Alignment -> Left
; Width -> 25%
Add a fourth column and leave its Title text blank
; Horizontal Alignment -> Left
; Width -> 100px
Add a fifth column and leave its Title text blank
; Horizontal Alignment -> Right
; Width -> 100px
Into the Name
column put a Text component call it tblName
, make it Bold
, and its Value *keeps empty for a moment.
The Color
column will contain an Icon, name it tblIcon
, select from the material library Name -> "mdi/checkbox-blank
", and Size -> Large
; Foreground -> *will be mapped dynamically later
Into the third Code
column put a Property Item component with copyable items, which is handy in our color case. Name it tblProperty
, and add an#1
item with following set up:
Value -> *we will bind it later; Text Style -> Bold
; Enable copy button -> true
Highlighting Icon of the latest added color has ID -> tblHighlight
, and its place in the fifth column; Name -> "mdi/palette
"; Size -> Medium
; Render -> *will be set up later
The last column belongs to a Button, named btnDelete
. Its empty Value -> ""; Icon Name -> "mdi/trash-can-outline
"; Size -> Small
.
Button Style -> Custom
; Background -> White
; Foreground -> Text
; Border Color -> Light_Gray
; Border Width -> 1px
; Border Radius -> 18px
*Binding with a delete action we will make it later.
Using of inMemory database is the best option for saving temporary values. For our case, saving color codes in incremental order.
Create a new Integration by selecting the inMemory DB option. Name it DB.Colors
and set up Primary Key -> color_id
; Auto Generate -> Increment
Saving the integration allows immediate use of internal memory.
Let's prepare an action by sending the required color data to the in-memory database by submitting btnSubmit.
Create an Action and name it UpsertColor
.
Add two Required Strings, name it inpColor
, and inpName
.
Place an Insert function from DB.Colors
Integration panel to your flow canvas and wire it together; ID -> insertDB
There are two ways how to set up Outgoing parameters of insertDB
;
Add two Key parameters, name them color
, name
, and its Values map dynamically as ƒx(params.inpColor)
, ƒx(params.inpName)
Bind all parameters as a function map ƒx{"color" : params.inpColor, "name" : params.inpName}
The submitting button must trigger the action of sending data into the in-memory database.
Open the Click
Event Editor on the btnSubmit
and wire together with the following functions:
Call Action will be bound together with UpsertColor
Action, and it's input parameters are as follows:
inpColor -> ƒx(fldColor.value)
; inpName -> ƒx(fldName.value)
Update State forcing the View to clear the Input Value after submitting by a Method -> fldName.clearValue
Loading all data from the in-memory database to colors
Variable serving as the primary source for Advanced Table.
Create an Action and call it GetColors
.
Wire together InMemory DB / Get All function and set up its ID -> data
.
Place in a Transform function returning data
from the GetColors
Action as follows:
Create a new Action Variable and name it colors
.
Bind the colors
with the GetColors
Action.
Let's prepare to delete action from in-memory in advance. We will bind it with the delete button in the advanced table later.
Create a new Action and name it DeleteColor
.
Add a new Parameter, call it color_id
, and set up it as a Number.
Wire together inMemory DB / Delete function, where the Key value is referencing parameters as follows: params.color_id
Finally, we have to bind our actions with colorTable
.
Select tblName
Text component and bind its Value -> item.name
.
Same do for the tblIcon and set up Foreground -> item.color
.
Bind the #1
item of the tblProperty
Value -> item.color
.
tblHighlight
Visibility Render -> ƒx(item.color == fldColor.value)
btnDelete
on Click Event set up as follows:
Place in a Call Action, bind it with DeleteColor
, and wire it together; as a Parameter color_id set up -> item.color_id
.
As a second component put in Update State with Method -> colors.reload
Update State of thecolors.reload
has to be also added with btnSubmit
Event.
Open the btnSubmit
Event, add and wire together Update State with Method -> colors.reload
.
We are done! Our advanced table with a bound in-memory database has to be working.