model

package module
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: MIT Imports: 4 Imported by: 40

README

Estructuras que utilizo con frecuencia en proyectos escritos en Go

ejemplo de uso en un objeto

func MedicalHistory() model.Object {
	return model.Object{
		Name:           "medicalhistory",
		TextFieldNames: []string{"service_name"},
		Fields: []model.Field{
			{Name: "id_medicalhistory", Legend: "id", Input: input.Pk()},
			{Name: "id_patient", Legend: "paciente", Input: input.Pk()},

			{Name: "staff_id", Legend: "Id", Input: input.Pk()},
			{Name: "staff_name", Legend: "Atendido por", Input: input.Text()},
			{Name: "staff_ocupation", Legend: "Especialidad", Input: input.Text()},
			{Name: "staff_area", Legend: "Area", Input: input.Check(Area{})},

			{Name: "service_id", Legend: "Prestación", Input: input.Pk()},

			{Name: "day_attention", Legend: "Dia Atención", Input: input.Date()},
			{Name: "hour_attention", Legend: "Hora", Input: input.Hour(`min="08:15"`, `max="20:15"`)},

			{Name: "reason", Legend: "Motivo Consulta, Servicio o Procedimiento", Input: input.TextArea()},
			{Name: "diagnostic", Legend: "Diagnostico (Descripción)", Input: input.TextArea()},
			{Name: "prescription", Legend: "Prescripción (Conclusion)", Input: input.TextArea()},

			{Name: "last_print_file", Legend: "Ultima Impresión en Archivo", Input: input.Text()},
		},
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiHandler added in v0.0.31

type ApiHandler struct {
	// nombre del componente u objeto ej: client, search_footer,datalist,form
	Name string

	CreateApi

	ReadFileApi
	ReadOneApi
	ReadAllApi

	UpdateApi
	DeleteApi
}

type CreateApi added in v0.0.31

type CreateApi interface {
	Create(params *[]map[string]string) error
}

type Css added in v0.0.31

type Css interface {
	Css() string
}

type CutData added in v0.0.19

type CutData struct {

	// ej Modelo Objeto: usuario := Object{Name: "Usuario",Fields: []Field{
	// 		{Name: "name"}, //0
	// 		{Name: "email"},//1
	// 		{Name: "phone"},//2
	// 	},}
	// ej data normal con todos los campos: {"name":"John Doe","email":"johndoe@example.com","phone":"555"}
	// version recortada Data: {"John Doe","johndoe@example.com","555"}
	// Index al codificar = {"0:0","1:1","2:2"}
	// ej no mail: {"marcel", "777"}
	// Index al codificar = {"0:0","1:2"}
	Index map[uint8]uint8 `json:"i"`
	//Data ej en mapa: "Data":[{"id":"222","name":"manzana","valor":"1200"}]
	// ahora: "Data":["222","manzana","1200"]
	Data []string `json:"d"`
}

type CutResponse added in v0.0.19

type CutResponse struct {
	//Action,Object,Module,Message
	//ej: ["create","user","ModuleUsers","ok"]
	CutOptions []string  `json:"o"`
	CutData    []CutData `json:"d"`
}

func (*CutResponse) CutResponseDecode added in v0.0.21

func (cr *CutResponse) CutResponseDecode(data []map[string]string) (out Response)

type DeleteApi added in v0.0.31

type DeleteApi interface {
	Delete(params *[]map[string]string) error
}

type Field

type Field struct {
	// si el campo comienza com id_ se considera como único y perteneciente a una tabla específica ej: id_user su tabla es user
	// otros ej: id_usuario, apellido, address, city etc
	Name        string
	Unique      bool   //campo único en db
	Inalterable bool   //la data en el campo sera inalterable después de la creación (¡no se puede modificar!)
	Legend      string //como se mostrara al usuario el campo en el encabezado ej: "name" por "Nombre Usuario"
	Input
	SkipValidation        bool //sin validar
	SkipCompletionAllowed bool //si el campo es requerido obligatoriamente o no

	NotRenderHtml bool // si no se necesita en formulario html

}

type FrontEnd added in v0.0.31

type FrontEnd struct {
}

type Icon added in v0.0.28

type Icon struct {
	Id      string   //ej: icon-search, icon-btn-save, icon-btn-new
	ViewBox string   //ej: "0 0 16 16", "0 0 448 512"
	Paths   []string //ej: m11.51 11..,m7.051..,m3.267 15...
}

type Input added in v0.0.5

type Input struct {
	Object

	Tag
	Validate

	TestData
}

type JsFunctions added in v0.0.31

type JsFunctions interface {
	JsFunctions() string
}

type JsGlobal added in v0.0.5

type JsGlobal interface {
	JsGlobal() string
}

type JsListeners added in v0.0.5

type JsListeners interface {
	JsListeners() string
}

type Module

type Module struct {
	Theme
	//nombre modulo ej: chat,patient,user
	MainName string
	//Titulo que vera el usuario ej: "Modulo Fotografía"
	Title string
	// icono para utilizar en sprite svg
	Icon
	//interfaz usuario modulo
	UI
	//areas soportadas por el modulo ej: 'a','t','x'
	Areas []byte
	// objetos o componentes que contiene el modulo ej: patient,user,datalist,search....
	Objects []*Object

	Path
}

func (*Module) AddObjects added in v0.0.31

func (m *Module) AddObjects(objects ...*Object)

func (Module) BuildHtmlModule added in v0.0.29

func (m Module) BuildHtmlModule(options ...string) (out string)

func (Module) BuildMenuButton added in v0.0.29

func (m Module) BuildMenuButton(index int) (out string)

func (Module) BuildModuleJS added in v0.0.29

func (m Module) BuildModuleJS(functions, listener_add, listener_rem string) (out string)

func (Module) BuildSpriteIcon added in v0.0.31

func (m Module) BuildSpriteIcon() (out string)

func (Module) ContainsTypeAreas added in v0.0.30

func (m Module) ContainsTypeAreas() (public, private bool)

type Object

type Object struct {
	ApiHandler

	TextFieldNames []string //nombre de campos mas representativos del objeto o tabla ej: name, address, phone
	Fields         []Field  //campos del objeto

	*Module // módulo origen del objeto
	// Css() string ej: .mi-style{background:black;}
	Css

	JsGlobal
	// JsFunctions() string | ej: MyFunction(e){console.log("hello ",e)};
	JsFunctions
	// JsListeners() string | ej: btn.addEventListener('click', MyFunction);
	JsListeners

	// FolderPath() string ej: func (Object) FolderPath() string {
	// _, filename, _, _ := runtime.Caller(0)
	// dir := filepath.Dir(filename)
	// return filepath.ToSlash(dir)
	// }
	Path
}

func (*Object) BuildHtmlForm added in v0.0.31

func (o *Object) BuildHtmlForm() string

func (*Object) BuildJSInputFormModule added in v0.0.31

func (o *Object) BuildJSInputFormModule() string

func (Object) Columns

func (o Object) Columns() (columns []string)

func (Object) DataDecode added in v0.0.19

func (o Object) DataDecode(cut_data ...CutData) ([]map[string]string, error)

func (Object) DataEncode added in v0.0.19

func (o Object) DataEncode(data map[string]string) CutData

DataEncode quita los nombres de los campos de la data según modelo del objeto

func (Object) FieldExist added in v0.0.16

func (o Object) FieldExist(field_name string) (Field, bool)

func (Object) FilterFields

func (o Object) FilterFields(namesRequired ...string) (fielsOut []Field)

func (Object) FilterRemoveFields

func (o Object) FilterRemoveFields(namesToRemove ...string) (fielsOut []Field)

func (Object) GetFieldByName

func (o Object) GetFieldByName(nameRq string) (fielOut Field)

func (Object) GetID

func (o Object) GetID(data_search map[string]string) string

func (Object) GetRepresentativeTextField

func (o Object) GetRepresentativeTextField(data_element map[string]string) (values string)

func (Object) IsExternalComponent added in v0.0.32

func (o Object) IsExternalComponent() bool

func (Object) MainName

func (o Object) MainName() string

func (Object) PrimaryKeyName

func (o Object) PrimaryKeyName() string

func (Object) RenderFields

func (o Object) RenderFields() (fielsOut []Field)

func (Object) RequiredFields

func (o Object) RequiredFields() (fielsOut []Field)

func (Object) ValidateData added in v0.0.16

func (o Object) ValidateData(validate_all_fields bool, all_data ...*map[string]string) error

validar objeto

type Path added in v0.0.27

type Path interface {
	FolderPath() string
}

type Permission

type Permission struct {
	Create bool
	Update bool
	Delete bool
}

type ReadAllApi added in v0.0.32

type ReadAllApi interface {
	ReadAll(params *map[string]string) (*[]map[string]string, error)
}

type ReadFileApi added in v0.0.32

type ReadFileApi interface {
	ReadFile(params *map[string]string) (file_path string, err error)
}

type ReadOneApi added in v0.0.32

type ReadOneApi interface {
	ReadOne(params *map[string]string) (*map[string]string, error)
}

type Request

type Request struct {
	//usuario que ejecuta la solicitud
	*User
	// paquetes de solicitud y respuesta
	Packages []Response
}

type Response

type Response struct {
	Action  string              `json:"a,omitempty"` //acción a realizar con la solicitud: create, read, update, delete o error
	Object  string              `json:"o,omitempty"` //nombre de la tabla u objeto controlador hacia donde va la solicitud
	Module  string              `json:"m,omitempty"` //nombre del module controlador hacia donde va la solicitud
	Message string              `json:"g,omitempty"` //mensaje para el usuario de la solicitud
	Data    []map[string]string `json:"d,omitempty"` //data entrada y respuesta json

	SkipMeInResponse bool     `json:"-"` //  saltarme al difundir
	Recipients       []string `json:"-"` // lista de ip, token o ids según app para el reenvió al finalizar solicitud
	TargetArea       bool     `json:"-"` // si es falso el destino por defecto es publico de lo contrario sera para todos quines tengan la misma area del usuario solicitante
}

type Tag added in v0.0.26

type Tag interface {
	HtmlName() string
	HtmlTag(id, field_name string, allow_skip_completed bool) string
}

type TestData added in v0.0.10

type TestData interface {
	GoodTestData() (out []string)
	WrongTestData() (out []string)
}

type Theme added in v0.0.29

type Theme interface {
	// index.html ej in Root Folder Path with:
	// {{.StyleSheet}} {{.AppName}} {{.AppVersion}} {{.SpriteIcons}} {{.Menu}}
	// {{.Message}} {{.UserName}} {{.UserArea}} {{.Modules}} {{.Script}}
	FolderPath() string
	// ModuleHtmlTemplate ej: nombre del modulo html y el contenido
	//<div id="` + module_name + `" class="slider_panel">` + content + `</div>
	ModuleHtmlTemplate(module_name, content string) string
	// MenuButtonTemplate ej: <li class="navbar-item"><a href="#` + module_name + `" tabindex="` + index + `" class="navbar-link" name="` + module_name + `">
	// <svg aria-hidden="true" focusable="false" class="fa-primary"><use xlink:href="#` + icon_id + `" /></svg>
	// <span class="link-text">` + title + `</span></a></li>
	MenuButtonTemplate(module_name, index, icon_id, title string) string
	//SpriteIconTemplate ej: <symbol id="icon-btn-save" viewBox="0 0 16 16"><path fill="currentColor" d="M14 0h-2z" /></symbol>
	SpriteIconTemplate(id, view_box string, paths ...string) string
	//ModuleJsTemplate ej: MODULES['` + module_name + `'] = (function () {	let crud = new Object(); const module = document.getElementById('` + module_name + `');
	// crud.ListenerModuleON = function () {` + listener_add + `};
	// crud.ListenerModuleOFF = function () {` + listener_rem + `};
	// return crud;})();
	ModuleJsTemplate(module_name, functions, listener_add, listener_rem string) string

	FormTemplate(object_name, input_tags string) string
	InputTemplate(object_name, field_name, legend, html_name, input_tag string, index int) string
	InputIdTemplate(object_name, field_name, index string) string
	JsFormVariablesTemplate(object_name string) string
	JsInputVariableTemplate(field_name, html_name string) string
}

type UI added in v0.0.26

type UI interface {
	UserInterface(options ...string) string
}

type UpdateApi added in v0.0.31

type UpdateApi interface {
	Update(params *[]map[string]string) error
}

type User

type User struct {
	Token          string // token de sesión solicitante
	Ip             string
	Name           string
	Area           byte  //0 sin area.. un que byte y uint8 son lo mismo en go la idea que aca sea un valor de carácter ej: a,s,p...
	AccessLevel    uint8 // aquí valor numérico 0 a 255
	Packages       chan []Response
	LastConnection time.Time
}

type Validate added in v0.0.5

type Validate interface {
	ValidateField(data_in string, skip_validation bool) bool
}

Jump to

Keyboard shortcuts

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