demo

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Component demo application

1. 💻 Ensure that you have Golang installed on your system. If not, please follow the https://golang.org/doc/install.

2. 📦 Clone the repository:

git clone https://github.com/nervatura/component.git

3. 📂 Change into the project directory:

cd component

4. 🔨 Build the demo project:

go build -ldflags="-w -s -X main.version=demo" -o ./component main.go

5. 🌍 Run the demo application:

./component 5000

The demo application can store session data in memory and as session files:

Index

Constants

View Source
const (
	DemoEventChange   = "change"
	DemoEventTheme    = "theme"
	DemoEventViewSize = "view_size"

	ComponentGroupAtom     = "atom"
	ComponentGroupMolecule = "molecule"
	ComponentGroupTemplate = "template"
	ComponentGroupPage     = "page"

	ViewSizeCentered = "centered"
	ViewSizeFull     = "full"
)

Demo constants

Variables

Component ComponentGroup values

View Source
var DemoMap map[string][]DemoView = map[string][]DemoView{
	ComponentGroupAtom: {
		{ComponentType: ct.ComponentTypeButton, TestData: ct.TestButton},
		{ComponentType: ct.ComponentTypeDateTime, TestData: ct.TestDateTime},
		{ComponentType: ct.ComponentTypeIcon, TestData: ct.TestIcon},
		{ComponentType: ct.ComponentTypeInput, TestData: ct.TestInput},
		{ComponentType: ct.ComponentTypeLabel, TestData: ct.TestLabel},
		{ComponentType: ct.ComponentTypeNumberInput, TestData: ct.TestNumberInput},
		{ComponentType: ct.ComponentTypeSelect, TestData: ct.TestSelect},
		{ComponentType: ct.ComponentTypeToast, TestData: ct.TestToast},
	},
	ComponentGroupMolecule: {
		{ComponentType: ct.ComponentTypeTable, TestData: ct.TestTable},
		{ComponentType: ct.ComponentTypeList, TestData: ct.TestList},
		{ComponentType: ct.ComponentTypeMenuBar, TestData: ct.TestMenuBar},
		{ComponentType: ct.ComponentTypePagination, TestData: ct.TestPagination},
	},
	ComponentGroupTemplate: {
		{ComponentType: ct.ComponentTypeLogin, TestData: ct.TestLogin},
		{ComponentType: ct.ComponentTypeLocale, TestData: ct.TestLocale},
	},
}

Component map with example data

View Source
var Public embed.FS

Component ViewSize values

Functions

func New

func New(version string, httpPort int64)

It creates a new application and starts an http server.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

Demo application

func (*App) AppEvent

func (app *App) AppEvent(w http.ResponseWriter, r *http.Request)

Receive the component event request. Loads the Demo component based on the X-Session-Token identifier.

func (*App) HomeRoute

func (app *App) HomeRoute(w http.ResponseWriter, r *http.Request)

Creates and returns an Application/Demo component. It stores the state of the component in memory or in a session file

func (*App) LoadDbSession added in v1.1.0

func (app *App) LoadDbSession(sessionID string, data any) (err error)

Loading the state of a component from a database.

func (*App) LoadFileSession added in v1.1.0

func (app *App) LoadFileSession(fileName string, data any) (err error)

Loading the state of a component from a session json file.

func (*App) SaveDbSession added in v1.1.0

func (app *App) SaveDbSession(sessionID string, data any) (err error)

Saving component state in a database.

func (*App) SaveFileSession added in v1.1.0

func (app *App) SaveFileSession(fileName string, data any) (err error)

Saving component state in a session json file.

type Demo

type Demo struct {
	ct.BaseComponent
	// Application title
	Title string `json:"title"`
	/*
		The theme of the application.
		[Theme] variable constants: [ThemeLight], [ThemeDark].
		Default value: [ThemeLight]
	*/
	Theme string `json:"theme"`
	/*
		[ViewSize] variable constants: [ViewSizeCentered], [ViewSizeFull].
		Default value: [ViewSizeCentered]
	*/
	ViewSize string `json:"view_size"`
	/*
		[ComponentGroup] variable constants: [ComponentGroupAtom], [ComponentGroupMolecule], [ComponentGroupTemplate].
		Default value: [ComponentGroupAtom]
	*/
	SelectedGroup string `json:"selected_group"`
	// Selected [DemoView] ComponentType
	SelectedType int64 `json:"selected_type"`
	// Selected component with example data
	SelectedDemo int64 `json:"selected_demo"`
	// Component map with example data
	DemoMap map[string][]DemoView `json:"-"`
}

func NewDemo

func NewDemo(eventURL, title string) *Demo

Creates and loads a new demo application with component example data

func (*Demo) GetProperty

func (sto *Demo) GetProperty(propName string) interface{}

Returns the value of the property of the Demo with the specified name.

func (*Demo) InitDemoMap

func (sto *Demo) InitDemoMap()

func (*Demo) OnRequest

func (sto *Demo) OnRequest(te ct.TriggerEvent) (re ct.ResponseEvent)

The [TriggerEvent] event of the user interface is forwarded to the child component registered in the RequestMap based on the component id. If there is no component associated with the received component ID, or the processing of the component returns an error, it returns the error message by creating a [Toast] component.

func (*Demo) Properties

func (sto *Demo) Properties() ut.IM

Returns all properties of the Demo

func (*Demo) Render

func (sto *Demo) Render() (res string, err error)

Based on the values, it will generate the html code of the Demo or return with an error message.

func (*Demo) SetProperty

func (sto *Demo) SetProperty(propName string, propValue interface{}) interface{}

Setting a property of the Demo value safely. Checks the entered value. In case of an invalid value, the default value will be set.

func (*Demo) Validation

func (sto *Demo) Validation(propName string, propValue interface{}) interface{}

It checks the value given to the property of the Demo and always returns a valid value

type DemoSession

type DemoSession struct {
	Label     string             `json:"label"`
	Component ct.ClientComponent `json:"component"`
}

DemoView Session data

type DemoView

type DemoView struct {
	ComponentType string                                           `json:"component_type"`
	Session       []DemoSession                                    `json:"session"`
	TestData      func(demo ct.ClientComponent) []ct.TestComponent `json:"-"`
}

DemoMap data item

Directories

Path Synopsis
Go database/sql test driver
Go database/sql test driver

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL