model

package module
v0.0.45 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 3 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

View Source
const INPUT_PATTERN = `Input: input\.(\w+)\([^)]*\)`
View Source
const PREFIX_ID_NAME = "id_"

Variables

This section is empty.

Functions

func Error added in v0.0.40

func Error(texts ...string) *err

Types

type BackendAuthHandler added in v0.0.44

type BackendAuthHandler interface {
}

type BackendRequest added in v0.0.33

type BackendRequest struct {
	BootResponse

	CreateApi
	ReadApi
	UpdateApi
	DeleteApi

	FileApi
}

type BootActions added in v0.0.44

type BootActions struct {
	JsonBootActions string
}

type BootResponse added in v0.0.45

type BootResponse interface {
	AddBootResponse(u *User) ([]Response, error)
}

type CreateApi added in v0.0.31

type CreateApi interface {
	Create(data ...map[string]string) error
}

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 Objeto 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 DataBaseAdapter added in v0.0.35

type DataBaseAdapter interface {
	CreateObjectsInDB(table_name string, data ...map[string]string) error

	// from_tables ej: "users,products" or: public.reservation, public.patient"
	// data ... map[string]string ej:{
	// LIMIT: 10, 5, 100. note: Postgres y MySQL: "LIMIT 10", SQLite: "LIMIT 10 OFFSET 0" OR "" no limit
	// ORDER_BY: name,phone,address
	// SELECT: "name, phone, address" default *
	// WHERE: "patient.id_patient = reservation.id_patient AND reservation.id_staff = '2'"
	// ARGS: "1,4,33"
	// }
	ReadObjectsInDB(from_tables string, data ...map[string]string) ([]map[string]string, error)
	UpdateObjectsInDB(table_name string, data ...map[string]string) ([]map[string]string, error)
	DeleteObjectsInDB(table_name string, data ...map[string]string) ([]map[string]string, error)

	CreateTablesInDB(...*Object) error
}

type DeleteApi added in v0.0.31

type DeleteApi interface {
	Delete(data ...map[string]string) ([]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
	Legend        string //como se mostrara al usuario el campo en el encabezado ej: "name" por "Nombre Usuario"
	NotRenderHtml bool   // si no se necesita en formulario html

	Input

	SkipCompletionAllowed bool //se permite que el campo no este completado. por defecto siempre sera requerido

	Unique          bool //campo único e inalterable en db
	NotRequiredInDB bool // campo no requerido en base de datos al crear tabla
	Encrypted       bool // si estará encriptado su almacenamiento o no
}

func (Field) IsPrimaryKey added in v0.0.35

func (f Field) IsPrimaryKey(o *Object) bool

type FileApi added in v0.0.33

type FileApi interface {
	MaximumFileSize() int64
	CreateFile(r *http.Request, params map[string]string) ([]map[string]string, error)
	FilePath(params map[string]string) (file_path string, err error)
}

type FrontendBootActions added in v0.0.45

type FrontendBootActions interface {
}

type FrontendResponse added in v0.0.33

type FrontendResponse 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 {
	InputName string

	Minimum int
	Maximum int

	Tag
	Validate

	TestData
}

type Module

type Module struct {
	//nombre modulo ej: chat,patient,user
	ModuleName string
	//Titulo que vera el usuario ej: "Modulo Fotografía"
	Title string
	// id icono para utilizar en sprite svg ej: icon-info
	IconID string

	//interfaz usuario modulo
	UI

	// ej:	`<div class="target-module">
	// 	<select name="select">
	// 		<option value="value1">Value 1</option>
	// 		<option value="value2" selected>Value 2</option>
	// 	</select>
	// </div>`
	HeaderInputTarget string

	//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
}

type Object

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

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

	BackendRequest

	FrontendResponse
	// contains filtered or unexported fields
}

func (*Object) AddModule added in v0.0.33

func (o *Object) AddModule(m *Module, api_name ...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(all_data ...map[string]string) (out []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(required_name string) (Field, error)

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) ID added in v0.0.38

func (o Object) ID() string

func (Object) MainName

func (o Object) MainName() string

func (Object) Module added in v0.0.36

func (o Object) Module() *Module

func (Object) ModuleName added in v0.0.33

func (o Object) ModuleName() 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) Response added in v0.0.35

func (o *Object) Response(action, message string, data ...map[string]string) Response

func (Object) TestData added in v0.0.39

func (o Object) TestData(required_objects int, skip_id, wrong_data bool) ([]map[string]string, error)

func (Object) ValidateData added in v0.0.16

func (o Object) ValidateData(its_new, its_update_or_delete bool, all_data ...map[string]string) error

validar data objeto

type Package added in v0.0.35

type Package struct {
	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
	Response
}

type Page added in v0.0.33

type Page struct {
	StyleSheet string // url ej style.css

	AppName    string
	AppVersion string

	SpriteIcons string

	Menu string

	UserName string
	UserArea string
	Message  string

	Modules string

	Script string // ej main.js

	JsonBootActions string //index ej <meta name="JsonBootActions" content="{{.JsonBootActions}}">
}

index.html ej: {{.StyleSheet}} {{.AppName}} {{.AppVersion}} {{.SpriteIcons}} {{.Menu}} {{.Message}} {{.UserName}} {{.UserArea}} {{.Modules}} {{.Script}} {{.Data}}

type Path added in v0.0.27

type Path interface {
	FolderPath() string
}

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

type Permission

type Permission struct {
	Read  bool
	Write bool
}

type ReadApi added in v0.0.31

type ReadApi interface {
	Read(data ...map[string]string) ([]map[string]string, error)
}

type Request

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

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
	Message string              `json:"g,omitempty"` //mensaje para el usuario de la solicitud
	Data    []map[string]string `json:"d,omitempty"` //data entrada y respuesta json
}

type SourceData added in v0.0.44

type SourceData interface {
	SourceData() map[string]string
}

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 {
	// 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
	MenuClassName() string // ej: .menu-container
	MenuItemClass() string // ej: navbar-item

	ModuleClassName() string //ej: slider_panel
	ModuleTemplate(m *Module, form *Object, options ...string) string

	FunctionMessageName() string // ej: ShowMessageToUser
}

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(data ...map[string]string) ([]map[string]string, error)
}

type User

type User struct {
	Token          string // token de sesión solicitante
	Id             string // id usuario
	Ip             string
	Name           string
	Area           string //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    string // aquí valor numérico 0 a 255
	LastConnection string //time.Time

}

type Validate added in v0.0.5

type Validate interface {
	//options html ej: data-option="ch_doc"
	ValidateField(data_in string, skip_validation bool, options ...string) error
}

Jump to

Keyboard shortcuts

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