Автогенерация полей в клиенте
This commit is contained in:
parent
ad98c6eff1
commit
30f88f8a28
51
example.yml
51
example.yml
|
@ -20,6 +20,30 @@ db:
|
|||
- id: e14d5504-fc3b-4ea1-9b5d-22bfa77fce94
|
||||
name: F1
|
||||
type: text
|
||||
- id: 2d0437e5-5350-420c-874c-44516a47dbba
|
||||
name: F2
|
||||
type: string
|
||||
- id: c5856020-da93-49be-8b62-3954b3da9b76
|
||||
name: F3
|
||||
type: int
|
||||
- id: 263f27c4-d533-4005-8427-707592acdadf
|
||||
name: F4
|
||||
type: bigint
|
||||
- id: 551acad6-c2a6-487f-b02b-de190b46aa10
|
||||
name: F5
|
||||
type: float
|
||||
- id: 4abf39c6-7ea0-4651-8b4c-d4aaf4171ede
|
||||
name: F6
|
||||
type: double
|
||||
- id: 31a8c7d1-e288-4f54-9a93-e7536440080a
|
||||
name: F7
|
||||
type: date
|
||||
- id: aa793a81-c799-414a-8bb9-3c019a975d40
|
||||
name: F8
|
||||
type: time
|
||||
- id: 5a9b7ba4-7ce4-40f7-ba84-c156ba44470f
|
||||
name: F9
|
||||
type: bool
|
||||
- id: 5fb86d34-aada-409a-ac9d-29fd1f7c2d1b
|
||||
name: test___test_1
|
||||
pk: uuid
|
||||
|
@ -85,7 +109,32 @@ backend:
|
|||
- APP_ADMIN
|
||||
PUT:
|
||||
- APP_ADMIN
|
||||
/reference/test2:
|
||||
name: test2
|
||||
groupName: nogroup
|
||||
summary: Общее описание
|
||||
comment: Описание
|
||||
data:
|
||||
id: 181418d3-8d28-45de-b2a7-d1df72d556b3
|
||||
name: db.test2
|
||||
filter:
|
||||
- id: f919a13e-1454-4872-b7e0-d62ded372661
|
||||
name: f1
|
||||
fieldId:
|
||||
id: 00000000-0000-0000-0000-000000000000
|
||||
name: id
|
||||
roles:
|
||||
DELETE:
|
||||
- APP_ADMIN
|
||||
GET:
|
||||
- APP_ADMIN
|
||||
LIST:
|
||||
- APP_ADMIN
|
||||
POST:
|
||||
- APP_ADMIN
|
||||
PUT:
|
||||
- APP_ADMIN
|
||||
frontend:
|
||||
lang: angular
|
||||
theme: primeng/resources/themes/mdc-light-indigo/theme.css
|
||||
defaultAfterLogin: /default/path
|
||||
defaultPathAfterLogin: /
|
||||
|
|
|
@ -34,7 +34,8 @@ func prepareRest(project *structs.Project) *structs.Project {
|
|||
// Есть интерфейс
|
||||
switch strings.ToLower(dataArr[0]) {
|
||||
case "db":
|
||||
project.Backend.Rest[i].Data.ID = findSourceDataInDBByName(project, dataArr[1])
|
||||
tmpSrc := templ.FindSourceDataInDBByName(project, dataArr[1])
|
||||
project.Backend.Rest[i].Data.ID = tmpSrc.ID
|
||||
// Обработаем поля для Edit
|
||||
if len(project.Backend.Rest[i].Edit) > 0 {
|
||||
for j := range project.Backend.Rest[i].Edit {
|
||||
|
@ -42,7 +43,7 @@ func prepareRest(project *structs.Project) *structs.Project {
|
|||
project.Backend.Rest[i].Edit[j].Name = templ.FieldDBName(&structs.Field{
|
||||
Name: project.Backend.Rest[i].Edit[j].Name,
|
||||
})
|
||||
project.Backend.Rest[i].Edit[j].ID = findFieldIdInDBByName(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Edit[j].Name)
|
||||
project.Backend.Rest[i].Edit[j].ID = templ.FindFieldIdInDBByName(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Edit[j].Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,17 +54,19 @@ func prepareRest(project *structs.Project) *structs.Project {
|
|||
project.Backend.Rest[i].Filter[j].Name = templ.FieldDBName(&structs.Field{
|
||||
Name: project.Backend.Rest[i].Filter[j].Name,
|
||||
})
|
||||
project.Backend.Rest[i].Filter[j].ID = findFieldIdInDBByName(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Filter[j].Name)
|
||||
project.Backend.Rest[i].Filter[j].ID = templ.FindFieldIdInDBByName(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Filter[j].Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
case "interface":
|
||||
project.Backend.Rest[i].Data.ID = findSourceDataInInterfaceByName(project, dataArr[1])
|
||||
tmpInterface := templ.FindSourceDataInInterfaceByName(project, dataArr[1])
|
||||
project.Backend.Rest[i].Data.ID = tmpInterface.ID
|
||||
// Обработаем поля для Edit
|
||||
if len(project.Backend.Rest[i].Edit) > 0 {
|
||||
for j := range project.Backend.Rest[i].Edit {
|
||||
if project.Backend.Rest[i].Edit[j].ID == uuid.Nil {
|
||||
project.Backend.Rest[i].Edit[j].ID = findFieldIdInInterfaceByName(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Edit[j].Name)
|
||||
tmp := templ.FindFieldIdInInterfaceByName(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Edit[j].Name)
|
||||
project.Backend.Rest[i].Edit[j].ID = tmp.ID //templ.FindFieldIdInInterfaceByName(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Edit[j].Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +74,8 @@ func prepareRest(project *structs.Project) *structs.Project {
|
|||
if len(project.Backend.Rest[i].Filter) > 0 {
|
||||
for j := range project.Backend.Rest[i].Filter {
|
||||
if project.Backend.Rest[i].Filter[j].ID == uuid.Nil {
|
||||
project.Backend.Rest[i].Filter[j].ID = findFieldIdInInterfaceByName(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Filter[j].Name)
|
||||
tmp := templ.FindFieldIdInInterfaceByName(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Filter[j].Name)
|
||||
project.Backend.Rest[i].Filter[j].ID = tmp.ID //templ.FindFieldIdInInterfaceByName(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Filter[j].Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,11 +86,13 @@ func prepareRest(project *structs.Project) *structs.Project {
|
|||
}
|
||||
if len(dataArr) == 1 {
|
||||
// Нет интерфейса, по этому ищем где первым попадется
|
||||
project.Backend.Rest[i].Data.ID = findSourceDataInDBByName(project, dataArr[1])
|
||||
tmpSrc := templ.FindSourceDataInDBByName(project, dataArr[1])
|
||||
project.Backend.Rest[i].Data.ID = tmpSrc.ID
|
||||
if project.Backend.Rest[i].Data.ID != uuid.Nil {
|
||||
continue
|
||||
}
|
||||
project.Backend.Rest[i].Data.ID = findSourceDataInInterfaceByName(project, dataArr[1])
|
||||
tmpSrc1 := templ.FindSourceDataInInterfaceByName(project, dataArr[1])
|
||||
project.Backend.Rest[i].Data.ID = tmpSrc1.ID //templ.FindSourceDataInInterfaceByName(project, dataArr[1])
|
||||
if project.Backend.Rest[i].Data.ID == uuid.Nil {
|
||||
log.Fatal("Не найдена структура данных для REST")
|
||||
}
|
||||
|
@ -95,28 +101,29 @@ func prepareRest(project *structs.Project) *structs.Project {
|
|||
}
|
||||
if project.Backend.Rest[i].Data.Name == "" && project.Backend.Rest[i].Data.ID != uuid.Nil {
|
||||
// Есть имя, но нет ID. Найдем
|
||||
|
||||
project.Backend.Rest[i].Data.Name = findSourceDataInDBByID(project, project.Backend.Rest[i].Data.ID)
|
||||
tmpSrc := templ.FindSourceDataInDBByID(project, project.Backend.Rest[i].Data.ID)
|
||||
project.Backend.Rest[i].Data.Name = tmpSrc.Name // findSourceDataInDBByID(project, project.Backend.Rest[i].Data.ID)
|
||||
if project.Backend.Rest[i].Data.ID != uuid.Nil {
|
||||
for j := range project.Backend.Rest[i].Edit {
|
||||
project.Backend.Rest[i].Data.Name = findFieldNameInDBById(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Edit[j].ID)
|
||||
project.Backend.Rest[i].Data.Name = templ.FindFieldNameInDBById(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Edit[j].ID)
|
||||
}
|
||||
for j := range project.Backend.Rest[i].Filter {
|
||||
project.Backend.Rest[i].Data.Name = findFieldNameInDBById(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Filter[j].ID)
|
||||
project.Backend.Rest[i].Data.Name = templ.FindFieldNameInDBById(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Filter[j].ID)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
project.Backend.Rest[i].Data.Name = findSourceDataInInterfaceByID(project, project.Backend.Rest[i].Data.ID)
|
||||
tmpSrc1 := templ.FindSourceDataInInterfaceByID(project, project.Backend.Rest[i].Data.ID)
|
||||
project.Backend.Rest[i].Data.Name = tmpSrc1.Name //templ.FindSourceDataInInterfaceByID(project, project.Backend.Rest[i].Data.ID)
|
||||
if project.Backend.Rest[i].Data.ID == uuid.Nil {
|
||||
log.Fatal("Не найдена структура данных для REST")
|
||||
}
|
||||
|
||||
for j := range project.Backend.Rest[i].Edit {
|
||||
project.Backend.Rest[i].Edit[j].Name = findFieldNameInInterfaceById(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Edit[j].ID)
|
||||
project.Backend.Rest[i].Edit[j].Name = templ.FindFieldNameInInterfaceById(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Edit[j].ID)
|
||||
}
|
||||
for j := range project.Backend.Rest[i].Filter {
|
||||
project.Backend.Rest[i].Edit[j].Name = findFieldNameInInterfaceById(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Filter[j].ID)
|
||||
project.Backend.Rest[i].Edit[j].Name = templ.FindFieldNameInInterfaceById(project, project.Backend.Rest[i].Data.ID, project.Backend.Rest[i].Filter[j].ID)
|
||||
}
|
||||
}
|
||||
// Собираем группы, чтобы они были уникальными
|
||||
|
@ -138,99 +145,3 @@ func prepareRest(project *structs.Project) *structs.Project {
|
|||
}
|
||||
return project
|
||||
}
|
||||
|
||||
// Найти ID таблицы по имени
|
||||
func findSourceDataInDBByName(project *structs.Project, name string) uuid.UUID {
|
||||
if len(project.DB.Tables) == 0 {
|
||||
return uuid.Nil
|
||||
}
|
||||
for i := range project.DB.Tables {
|
||||
if project.DB.Tables[i].Name == name {
|
||||
return project.DB.Tables[i].ID
|
||||
}
|
||||
}
|
||||
return uuid.Nil
|
||||
}
|
||||
|
||||
// Найти ID поля по имени
|
||||
func findFieldIdInDBByName(project *structs.Project, tblID uuid.UUID, fldName string) uuid.UUID {
|
||||
if len(project.DB.Tables) == 0 {
|
||||
return uuid.Nil
|
||||
}
|
||||
for i := range project.DB.Tables {
|
||||
if project.DB.Tables[i].ID == tblID {
|
||||
for j := range project.DB.Tables[i].Fields {
|
||||
if project.DB.Tables[i].Fields[j].Name == strings.ToLower(fldName) {
|
||||
return project.DB.Tables[i].Fields[j].ID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return uuid.Nil
|
||||
}
|
||||
|
||||
// Найти имя таблицы по ID
|
||||
func findSourceDataInDBByID(project *structs.Project, id uuid.UUID) string {
|
||||
if len(project.DB.Tables) == 0 {
|
||||
return ""
|
||||
}
|
||||
for i := range project.DB.Tables {
|
||||
if project.DB.Tables[i].ID == id {
|
||||
return project.DB.Tables[i].Name
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Найти имя поля в таблице по ID
|
||||
func findFieldNameInDBById(project *structs.Project, tblID uuid.UUID, fldId uuid.UUID) string {
|
||||
if len(project.DB.Tables) == 0 {
|
||||
return ""
|
||||
}
|
||||
for i := range project.DB.Tables {
|
||||
if project.DB.Tables[i].ID == tblID {
|
||||
for j := range project.DB.Tables[i].Fields {
|
||||
if project.DB.Tables[i].Fields[j].ID == fldId {
|
||||
return project.DB.Tables[i].Fields[j].Name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func findSourceDataInInterfaceByName(project *structs.Project, name string) uuid.UUID {
|
||||
// TODO
|
||||
log.Fatal("Функция в разработки")
|
||||
return uuid.Nil
|
||||
}
|
||||
|
||||
func findSourceDataInInterfaceByID(project *structs.Project, id uuid.UUID) string {
|
||||
// TODO
|
||||
log.Fatal("Функция в разработки")
|
||||
return ""
|
||||
}
|
||||
|
||||
// Найти ID поля по имени
|
||||
func findFieldIdInInterfaceByName(project *structs.Project, tblID uuid.UUID, fldName string) uuid.UUID {
|
||||
// TODO
|
||||
log.Fatal("Функция в разработки")
|
||||
return uuid.Nil
|
||||
}
|
||||
|
||||
// Найти имя поля в интерфейсе по ID
|
||||
func findFieldNameInInterfaceById(project *structs.Project, tblID uuid.UUID, fldId uuid.UUID) string {
|
||||
if len(project.DB.Tables) == 0 {
|
||||
return ""
|
||||
}
|
||||
for i := range project.DB.Tables {
|
||||
if project.DB.Tables[i].ID == tblID {
|
||||
for j := range project.DB.Tables[i].Fields {
|
||||
if project.DB.Tables[i].Fields[j].ID == fldId {
|
||||
return project.DB.Tables[i].Fields[j].Name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -11,7 +11,19 @@ func FieldJsonName(field *structs.Field) string {
|
|||
if field == nil {
|
||||
log.Fatal("переданное поле не должно быть пустым")
|
||||
}
|
||||
str := FieldNamePrepare(field.Name)
|
||||
//str := FieldNamePrepare(field.Name)
|
||||
str := FieldJsonNameStr(field.Name)
|
||||
|
||||
str = strings.ToLower(string([]rune(str)[0])) + string([]rune(str)[1:])
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
func FieldJsonNameStr(field string) string {
|
||||
if field == "" {
|
||||
log.Fatal("переданное поле не должно быть пустым")
|
||||
}
|
||||
str := FieldNamePrepare(field)
|
||||
|
||||
str = strings.ToLower(string([]rune(str)[0])) + string([]rune(str)[1:])
|
||||
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
package templ
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"git.ymnuktech.ru/ymnuk/yt-gen-app/structs"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
// Найти таблицу по имени
|
||||
func FindSourceDataInDBByName(project *structs.Project, name string) *structs.Table /*uuid.UUID*/ {
|
||||
if len(project.DB.Tables) == 0 {
|
||||
//return uuid.Nil
|
||||
return nil
|
||||
}
|
||||
for i := range project.DB.Tables {
|
||||
if project.DB.Tables[i].Name == name {
|
||||
//return project.DB.Tables[i].ID
|
||||
return &project.DB.Tables[i]
|
||||
}
|
||||
}
|
||||
//return uuid.Nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// Найти ID поля по имени
|
||||
func FindFieldIdInDBByName(project *structs.Project, tblID uuid.UUID, fldName string) uuid.UUID {
|
||||
if len(project.DB.Tables) == 0 {
|
||||
return uuid.Nil
|
||||
}
|
||||
for i := range project.DB.Tables {
|
||||
if project.DB.Tables[i].ID == tblID {
|
||||
for j := range project.DB.Tables[i].Fields {
|
||||
if project.DB.Tables[i].Fields[j].Name == strings.ToLower(fldName) {
|
||||
return project.DB.Tables[i].Fields[j].ID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return uuid.Nil
|
||||
}
|
||||
|
||||
// Найти таблицу по ID
|
||||
func FindSourceDataInDBByID(project *structs.Project, id uuid.UUID) *structs.Table {
|
||||
if len(project.DB.Tables) == 0 {
|
||||
return nil
|
||||
}
|
||||
for i := range project.DB.Tables {
|
||||
if project.DB.Tables[i].ID == id {
|
||||
//return project.DB.Tables[i].Name
|
||||
return &project.DB.Tables[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Найти имя поля в таблице по ID
|
||||
func FindFieldNameInDBById(project *structs.Project, tblID uuid.UUID, fldId uuid.UUID) string {
|
||||
if len(project.DB.Tables) == 0 {
|
||||
return ""
|
||||
}
|
||||
for i := range project.DB.Tables {
|
||||
if project.DB.Tables[i].ID == tblID {
|
||||
for j := range project.DB.Tables[i].Fields {
|
||||
if project.DB.Tables[i].Fields[j].ID == fldId {
|
||||
return project.DB.Tables[i].Fields[j].Name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func FindSourceDataInInterfaceByName(project *structs.Project, name string) *structs.Interface {
|
||||
// TODO
|
||||
log.Fatal("Функция в разработки")
|
||||
return nil
|
||||
}
|
||||
|
||||
func FindSourceDataInInterfaceByID(project *structs.Project, id uuid.UUID) *structs.Interface {
|
||||
// TODO
|
||||
log.Fatal("Функция в разработки")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Найти ID поля по имени
|
||||
func FindFieldIdInInterfaceByName(project *structs.Project, tblID uuid.UUID, fldName string) *structs.Field {
|
||||
// TODO
|
||||
log.Fatal("Функция в разработки")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Найти имя поля в интерфейсе по ID
|
||||
func FindFieldNameInInterfaceById(project *structs.Project, tblID uuid.UUID, fldId uuid.UUID) string {
|
||||
if len(project.DB.Tables) == 0 {
|
||||
return ""
|
||||
}
|
||||
for i := range project.DB.Tables {
|
||||
if project.DB.Tables[i].ID == tblID {
|
||||
for j := range project.DB.Tables[i].Fields {
|
||||
if project.DB.Tables[i].Fields[j].ID == fldId {
|
||||
return project.DB.Tables[i].Fields[j].Name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
|
@ -32,6 +32,19 @@ func GetModelName(project *structs.Project, value structs.VisField) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func GetModelNameAngular(project *structs.Project, value structs.VisField) string {
|
||||
if project == nil {
|
||||
log.Fatal("project is null")
|
||||
}
|
||||
for _, tbl := range project.DB.Tables {
|
||||
if tbl.ID == value.ID {
|
||||
return fmt.Sprintf("Model%s", FieldNamePrepare(tbl.Name))
|
||||
}
|
||||
}
|
||||
log.Fatal("model not found")
|
||||
return ""
|
||||
}
|
||||
|
||||
func DisplayMethodNamePost(value string) string {
|
||||
// TODO
|
||||
//log.Fatal("not released")
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"text/template"
|
||||
|
||||
"git.ymnuktech.ru/ymnuk/yt-gen-app/structs"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
//go:embed tmpl/*
|
||||
|
@ -24,6 +25,7 @@ var funcMap = template.FuncMap{
|
|||
"fieldChildName": FieldChildName,
|
||||
"fieldNamePrepare": FieldNamePrepare,
|
||||
"fieldNameLowerPrepare": FieldNameLowerPrepare,
|
||||
"fieldJsonNameStr": FieldJsonNameStr,
|
||||
"fieldType": FieldType,
|
||||
//"fieldDbTableType": FieldDbTableType,
|
||||
"fieldTypeParentTable": FieldTypeParentTable,
|
||||
|
@ -39,6 +41,7 @@ var funcMap = template.FuncMap{
|
|||
"methodSummary": MethodSummary,
|
||||
"methodComment": MethodComment,
|
||||
"getModelName": GetModelName,
|
||||
"getModelNameAngular": GetModelNameAngular,
|
||||
"displayMethodNamePost": DisplayMethodNamePost,
|
||||
"methodNamePost": MethodNamePost,
|
||||
"displayMethodNameGet": DisplayMethodNameGet,
|
||||
|
@ -51,6 +54,9 @@ var funcMap = template.FuncMap{
|
|||
|
||||
"angularRestName": AngularRestName,
|
||||
"angularFilename": AngularFilename,
|
||||
|
||||
"getFieldsByModelID": GetFieldsByModelID,
|
||||
"getFksByModelID": GetFksByModelID,
|
||||
}
|
||||
|
||||
func IsMethod(arr map[string][]string, method string) bool {
|
||||
|
@ -409,6 +415,43 @@ func RemoveFirstChar(value string) string {
|
|||
if value == "" {
|
||||
return ""
|
||||
}
|
||||
value = string([]rune(value)[1:])
|
||||
runes := []rune(value)
|
||||
if runes[0] == '-' || runes[0] == '/' || runes[0] == '\\' || runes[0] == '_' {
|
||||
value = string(runes[1:])
|
||||
} else {
|
||||
value = string(runes)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func GetFieldsByModelID(project *structs.Project, id uuid.UUID) []structs.Field {
|
||||
tmpSrc := FindSourceDataInDBByID(project, id)
|
||||
if tmpSrc != nil {
|
||||
return tmpSrc.Fields
|
||||
}
|
||||
tmpInterface := FindSourceDataInInterfaceByID(project, id)
|
||||
if tmpInterface != nil {
|
||||
return tmpInterface.Fields
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetFksByModelID(project *structs.Project, id uuid.UUID) []structs.Field {
|
||||
tmpSrc := FindSourceDataInDBByID(project, id)
|
||||
if tmpSrc != nil {
|
||||
return tmpSrc.FkFields
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetFieldsByModelName(project *structs.Project, name string) []structs.Field {
|
||||
tmpSrc := FindSourceDataInDBByName(project, name)
|
||||
if tmpSrc != nil {
|
||||
return tmpSrc.Fields
|
||||
}
|
||||
tmpInterface := FindSourceDataInInterfaceByName(project, name)
|
||||
if tmpInterface != nil {
|
||||
return tmpInterface.Fields
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,6 +1,31 @@
|
|||
<div class="center">
|
||||
<p-card header="{{ .Summary }}">
|
||||
<p-card header="{{ .Rest.Summary }}">
|
||||
<form [formGroup]="form">
|
||||
{{ range $index, $field := getFieldsByModelID .Project .Rest.Data.ID }}
|
||||
<div class="card flex justify-content-center">
|
||||
<span class="p-float-label">
|
||||
{{ if eq $field.Type "string" }}<input pInputText id="{{ fieldJsonNameStr $field.Name }}" formControlName="{{ fieldJsonNameStr $field.Name }}" />{{ end }}
|
||||
{{ if eq $field.Type "text" }}<input pInputText id="{{ fieldJsonNameStr $field.Name }}" formControlName="{{ fieldJsonNameStr $field.Name }}" />{{ end }}
|
||||
{{ if eq $field.Type "uuid" }}<input pInputText id="{{ fieldJsonNameStr $field.Name }}" formControlName="{{ fieldJsonNameStr $field.Name }}" />{{ end }}
|
||||
{{ if eq $field.Type "int" }}<p-inputNumber id="{{ fieldJsonNameStr $field.Name }}" formControlName="{{ fieldJsonNameStr $field.Name }}" />{{ end }}
|
||||
{{ if eq $field.Type "bigint" }}<p-inputNumber id="{{ fieldJsonNameStr $field.Name }}" formControlName="{{ fieldJsonNameStr $field.Name }}" />{{ end }}
|
||||
{{ if eq $field.Type "float" }}<p-inputNumber id="{{ fieldJsonNameStr $field.Name }}" formControlName="{{ fieldJsonNameStr $field.Name }}" />{{ end }}
|
||||
{{ if eq $field.Type "double" }}<p-inputNumber id="{{ fieldJsonNameStr $field.Name }}" formControlName="{{ fieldJsonNameStr $field.Name }}" />{{ end }}
|
||||
{{ if eq $field.Type "date" }}<p-calendar id="{{ fieldJsonNameStr $field.Name }}" formControlName="{{ fieldJsonNameStr $field.Name }}" dateFormat="dd.mm.yy" [showIcon]="true" [showButtonBar]="true" />{{ end }}
|
||||
{{ if eq $field.Type "time" }}<p-calendar id="{{ fieldJsonNameStr $field.Name }}" formControlName="{{ fieldJsonNameStr $field.Name }}" dateFormat="dd.mm.yy" [showIcon]="true" [showButtonBar]="true" [showTime]="true" [showSeconds]="true" />{{ end }}
|
||||
{{ if eq $field.Type "bool" }}<p-triStateCheckbox id="{{ fieldJsonNameStr $field.Name }}" formControlName="{{ fieldJsonNameStr $field.Name }}" />{{ end }}
|
||||
<label htmlFor="{{ fieldJsonNameStr $field.Name }}">{{ if ne $field.Description "" }}{{ $field.Description }}{{ else }}{{ fieldName $field }}{{ end }}</label>
|
||||
</span>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ range $index, $field := getFksByModelID .Project .Rest.Data.ID }}
|
||||
<div class="card flex justify-content-center">
|
||||
<span class="p-float-label">
|
||||
<input pInputText id="{{ fieldJsonNameStr $field.Name }}" formControlName="{{ fieldJsonNameStr $field.Name }}" />
|
||||
<label htmlFor="{{ fieldJsonNameStr $field.Name }}">{{ if ne $field.Description "" }}{{ $field.Description }}{{ else }}{{ fieldName $field }}{{ end }}</label>
|
||||
</span>
|
||||
</div>
|
||||
{{ end }}
|
||||
<div class="button">
|
||||
<button pButton pRipple (click)="onSave()"label="Сохранить" class="p-button-raised"
|
||||
[disabled]="form.invalid || form.disabled"></button>
|
||||
|
|
|
@ -3,6 +3,7 @@ import { UntypedFormGroup, UntypedFormControl, Validators } from '@angular/forms
|
|||
import { Subscription, Observable, firstValueFrom } from 'rxjs';
|
||||
import { Router, ActivatedRoute, Params } from '@angular/router';
|
||||
import { MessageService } from 'primeng/api';
|
||||
import { {{ getModelNameAngular .Project .Rest.Data }}, {{ fieldNamePrepare .Rest.GroupName }}Service } from 'src/app/module/api';
|
||||
|
||||
@Component({
|
||||
selector: 'app-{{ angularFilename .Path }}-form',
|
||||
|
@ -14,27 +15,46 @@ export class {{ angularRestName .Path }}FormComponent implements OnInit, AfterVi
|
|||
private id?: string; // Идентификатор
|
||||
|
||||
public form: UntypedFormGroup = new UntypedFormGroup({
|
||||
// TODO
|
||||
{{ range $index, $field := getFieldsByModelID .Project .Rest.Data.ID }}
|
||||
{{ fieldJsonNameStr $field.Name }}: new UntypedFormControl(),
|
||||
{{ end }}
|
||||
{{ range $index, $field := getFksByModelID .Project .Rest.Data.ID }}
|
||||
{{ fieldJsonNameStr $field.Name }}: new UntypedFormControl(),
|
||||
{{ end }}
|
||||
});
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private toast: MessageService
|
||||
) {
|
||||
private messageService: MessageService,
|
||||
private {{ .Rest.GroupName }}Service: {{ fieldNamePrepare .Rest.GroupName }}Service,
|
||||
|
||||
}
|
||||
) { }
|
||||
ngAfterViewInit(): void {
|
||||
// Получим переданные параметры (id)
|
||||
this.route.params.subscribe((params: Params) => {
|
||||
if (params['id'] != null) {
|
||||
this.id = params['id'];
|
||||
console.log(this.id);
|
||||
// Получаем данные с сервера о выбранном пользователе
|
||||
firstValueFrom(this.{{ fieldNameLowerPrepare .Rest.GroupName }}Service.{{$tmp1 := angularRestName .Path}}{{ fieldJsonNameStr $tmp1 }}IdGet(this.id as string)).then((item: {{ getModelNameAngular .Project .Rest.Data }}) => {
|
||||
if (item) {
|
||||
this.form.patchValue(item)
|
||||
} else {
|
||||
this.id = undefined;
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.id = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
infoForm(): string {
|
||||
return this.id ? "Изменить" : "Добавить";
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
// TODO
|
||||
}
|
||||
|
@ -44,7 +64,25 @@ export class {{ angularRestName .Path }}FormComponent implements OnInit, AfterVi
|
|||
}
|
||||
|
||||
onSave(): void {
|
||||
// TODO
|
||||
let item: {{ getModelNameAngular .Project .Rest.Data }} = this.form.value;
|
||||
if (this.id) {
|
||||
// Обновить
|
||||
firstValueFrom(this.{{ fieldNameLowerPrepare .Rest.GroupName }}Service.{{$tmp1 := angularRestName .Path}}{{ fieldJsonNameStr $tmp1 }}IdPut(this.id, item)).then(() => {
|
||||
this.messageService.add({ severity: "success", summary: "Запись обновлена" });
|
||||
this.router.navigate(['/{{ removeFirstChar .Path }}']);
|
||||
}).catch(() => {
|
||||
this.messageService.add({ severity: "error", summary: "Ошабка", detail: "Не удалось обновить запись" });
|
||||
});
|
||||
} else {
|
||||
// Создать
|
||||
firstValueFrom(this.{{ fieldNameLowerPrepare .Rest.GroupName }}Service.{{$tmp1 := angularRestName .Path}}{{ fieldJsonNameStr $tmp1 }}Post(item)).then(() => {
|
||||
this.messageService.add({ severity: "success", summary: "Запись создана" });
|
||||
this.router.navigate(['/{{ removeFirstChar .Path }}']);
|
||||
}).catch(() => {
|
||||
this.messageService.add({ severity: "error", summary: "Ошабка", detail: "Не удалось создать запись" });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onCancel(): void {
|
||||
|
|
|
@ -1,12 +1,39 @@
|
|||
{{ if .Rest.Editable }}
|
||||
<p-button type="button" (click)="OnNewItem()">Добавить</p-button>
|
||||
{{ end }}
|
||||
|
||||
<p-table [value]="items" responsiveLayout="scroll" [rows]="10" [showCurrentPageReport]="true"
|
||||
[rowsPerPageOptions]="[10,25,50]" [paginator]="true"
|
||||
currentPageReportTemplate="Отображено с {first} по {last} из {totalRecords} записей">
|
||||
<ng-template pTemplate="header">
|
||||
|
||||
<tr>
|
||||
{{ range $index, $field := getFieldsByModelID .Project .Rest.Data.ID }}
|
||||
<td>{{ if ne $field.Description "" }}{{ $field.Description }}{{ else }}{{ fieldName $field }}{{ end }}</td>
|
||||
{{ end }}
|
||||
{{ range $index, $field := getFksByModelID .Project .Rest.Data.ID }}
|
||||
<td>{{ if ne $field.Description "" }}{{ $field.Description }}{{ else }}{{ fieldName $field }}{{ end }}</td>
|
||||
{{ end }}
|
||||
{{ if .Rest.Editable }}
|
||||
<th>Действия</th>
|
||||
{{ end }}
|
||||
</tr>
|
||||
</ng-template>
|
||||
<ng-template pTemplate="body" let-element>
|
||||
|
||||
<tr>
|
||||
{{ range $index, $field := getFieldsByModelID .Project .Rest.Data.ID }}
|
||||
<td>{{ "{{" }} element.{{ fieldJsonNameStr $field.Name }} {{ "}}" }}</td>
|
||||
{{ end }}
|
||||
{{ range $index, $field := getFksByModelID .Project .Rest.Data.ID }}
|
||||
<td>{{ "{{" }} element.{{ fieldJsonNameStr $field.Name }} {{ "}}" }}</td>
|
||||
{{ end }}
|
||||
{{ if .Rest.Editable }}
|
||||
<td>
|
||||
<p-button type="button" (click)="onEdit(element.id)">Изменить</p-button>
|
||||
<p-button type="button" (click)="onDelete(element.id)">Удалить</p-button>
|
||||
</td>
|
||||
{{ end }}
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
|
||||
{{ if .Rest.Editable }}<p-confirmDialog [style]="{width: '50vw'}"></p-confirmDialog>{{ end }}
|
|
@ -1,8 +1,9 @@
|
|||
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||
import { firstValueFrom, Observable, Subscription } from 'rxjs';
|
||||
import { Router } from '@angular/router';
|
||||
import { UntypedFormControl } from '@angular/forms';
|
||||
import { MessageService } from 'primeng/api';
|
||||
import { ConfirmationService, MessageService } from 'primeng/api';
|
||||
import { {{ getModelNameAngular .Project .Rest.Data }}, {{ fieldNamePrepare .Rest.GroupName }}Service } from 'src/app/module/api';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-{{ angularFilename .Path }}',
|
||||
|
@ -11,17 +12,26 @@ import { MessageService } from 'primeng/api';
|
|||
})
|
||||
export class {{ angularRestName .Path }}Component implements OnInit, OnDestroy {
|
||||
|
||||
items: any[] = [];
|
||||
items: {{ getModelNameAngular .Project .Rest.Data }}[] = [];
|
||||
|
||||
constructor(
|
||||
private toast: MessageService,
|
||||
private router: Router
|
||||
private router: Router,
|
||||
private {{ .Rest.GroupName }}Service: {{ fieldNamePrepare .Rest.GroupName }}Service,
|
||||
private confirmationService: ConfirmationService,
|
||||
private messageService: MessageService
|
||||
|
||||
) { }
|
||||
|
||||
ngOnDestroy(): void { }
|
||||
|
||||
private refreshData(): void {
|
||||
// TODO
|
||||
firstValueFrom(this.{{ fieldNameLowerPrepare .Rest.GroupName }}Service.{{$tmp1 := angularRestName .Path}}{{ fieldJsonNameStr $tmp1 }}Get()).then(items => {
|
||||
this.items = items;
|
||||
}).catch(() => {
|
||||
this.messageService.add({ severity: "warn", summary: "Отсутствуют данные" })
|
||||
this.items = [];
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
@ -33,7 +43,25 @@ export class {{ angularRestName .Path }}Component implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
onDelete(id:any): void {
|
||||
// TODO
|
||||
this.confirmationService.confirm({
|
||||
message: 'Вы действительно хотите удалить запись?',
|
||||
header: 'Confirmation',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: "Да",
|
||||
rejectLabel: "Нет",
|
||||
accept: () => {
|
||||
firstValueFrom(this.{{ fieldNameLowerPrepare .Rest.GroupName }}Service.{{$tmp1 := angularRestName .Path}}{{ fieldJsonNameStr $tmp1 }}IdDelete(id)).then(() => {
|
||||
this.messageService.add({ severity: 'success', summary: 'Удалено' });
|
||||
this.refreshData();
|
||||
}).catch(err => {
|
||||
this.messageService.add({ severity: 'error', summary: 'Ошибка', detail: "Не удалось удалить элеменет" });
|
||||
})
|
||||
},
|
||||
reject: () => {
|
||||
this.messageService.add({ severity: 'error', summary: 'Отменено' });
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
OnNewItem(): void {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package structs
|
||||
|
||||
import uuid "github.com/satori/go.uuid"
|
||||
|
||||
type Interface struct {
|
||||
ID uuid.UUID `yaml:"id" json:"id"`
|
||||
Name string `yaml:"name,omitempty" json:"name,omitempty" default:"noname"`
|
||||
Fields []Field `yaml:"fields,omitempty" json:"fields,omitempty"`
|
||||
// TODO
|
||||
}
|
Loading…
Reference in New Issue