page_modules.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // package page_modules -- страница представления модулей
  2. package page_modules
  3. import (
  4. _ "embed"
  5. "fmt"
  6. "strings"
  7. "github.com/gofiber/fiber/v2"
  8. "gitp78su.ipnodns.ru/svi/kern/krn/kctx"
  9. . "gitp78su.ipnodns.ru/svi/kern/krn/ktypes"
  10. )
  11. // PageModules -- отображает модули модулей
  12. type PageModules struct {
  13. ctx IKernelCtx
  14. }
  15. var page *PageModules
  16. // GetPageModules -- возвращает страницу модулей
  17. func GetPageModules() *PageModules {
  18. if page != nil {
  19. return page
  20. }
  21. kCtx := kctx.GetKernelCtx()
  22. sf := &PageModules{
  23. ctx: kCtx,
  24. }
  25. fiberApp := kCtx.Get("fiberApp").Val().(*fiber.App)
  26. fiberApp.Post("/modules", sf.postModules)
  27. page = sf
  28. return sf
  29. }
  30. //go:embed mod_row_block.html
  31. var strModRowBlock string
  32. //go:embed mod_row_val.html
  33. var strModRowBlank string
  34. // Индексная страница модулей
  35. func (sf *PageModules) postModules(ctx *fiber.Ctx) error {
  36. ctx.Set("Content-type", "text/html; charset=utf8;\n\n")
  37. mon := sf.ctx.Get("monolit").Val().(IKernelMonolit)
  38. chLst := mon.Ctx().SortedList()
  39. strOut := ``
  40. for _, val := range chLst {
  41. if !strings.Contains(val.Key(), "module_") {
  42. continue
  43. }
  44. lstKey := strings.Split(val.Key(), "_")
  45. id := lstKey[1]
  46. strRow := strModRowBlank
  47. strRow = strings.ReplaceAll(strRow, "{.id}", id)
  48. strRow = strings.ReplaceAll(strRow, "{.key}", val.Key())
  49. moduleName := string(val.Val().(IKernelModule).Name())
  50. strRow = strings.ReplaceAll(strRow, "{.name}", moduleName)
  51. type_ := fmt.Sprintf("%#T", val.Val())
  52. type_ = strings.ReplaceAll(type_, ".", ".<br>")
  53. strRow = strings.ReplaceAll(strRow, "{.type}", type_)
  54. strRow = strings.ReplaceAll(strRow, "{.createAt}", string(val.CreateAt()))
  55. strRow = strings.ReplaceAll(strRow, "{.updateAt}", string(val.UpdateAt()))
  56. strRow = strings.ReplaceAll(strRow, "{.comment}", val.Comment())
  57. strOut += strRow
  58. }
  59. strOut = strings.ReplaceAll(strModRowBlock, "{.mod_block}", strOut)
  60. return ctx.SendString(strOut)
  61. }