btn_modules.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package btn_modules
  2. import (
  3. _ "embed"
  4. "fmt"
  5. "strings"
  6. "gitp78su.ipnodns.ru/svi/kern/krn/kctx"
  7. . "gitp78su.ipnodns.ru/svi/kern/krn/ktypes"
  8. "gitp78su.ipnodns.ru/svi/kern/wui"
  9. . "gitp78su.ipnodns.ru/svi/kern/wui/wtypes"
  10. )
  11. type BtnModules struct {
  12. btn IWuiButton
  13. kCtx IKernelCtx
  14. }
  15. // NewBtnModules -- возвращает новую кнопку модулей
  16. func NewBtnModules() *BtnModules {
  17. sf := &BtnModules{
  18. kCtx: kctx.GetKernelCtx(),
  19. }
  20. sf.btn = wui.NewWuiButton("Modules", sf.clickMonolit)
  21. sf.btn.Hx().Target().Set("#modules")
  22. return sf
  23. }
  24. // Html -- возвращает HTML-представление кнопки
  25. func (sf *BtnModules) Html() string {
  26. return sf.btn.Html()
  27. }
  28. //go:embed block_modules.html
  29. var strBlockModules string
  30. //go:embed block_row.html
  31. var strBlockRow string
  32. // Событие клика по кнопке
  33. func (sf *BtnModules) clickMonolit() string {
  34. mon := sf.kCtx.Get("monolit").Val().(IKernelMonolit)
  35. chLst := mon.Ctx().SortedList()
  36. strOut := ``
  37. for _, val := range chLst {
  38. if !strings.Contains(val.Key(), "module_") {
  39. continue
  40. }
  41. lstKey := strings.Split(val.Key(), "_")
  42. id := lstKey[1]
  43. strRow := strBlockRow
  44. strRow = strings.ReplaceAll(strRow, "{.id}", id)
  45. strRow = strings.ReplaceAll(strRow, "{.key}", val.Key())
  46. moduleName := string(val.Val().(IKernelModule).Name())
  47. strRow = strings.ReplaceAll(strRow, "{.name}", moduleName)
  48. type_ := fmt.Sprintf("%#T", val.Val())
  49. type_ = strings.ReplaceAll(type_, ".", ".<br>")
  50. strRow = strings.ReplaceAll(strRow, "{.type}", type_)
  51. strRow = strings.ReplaceAll(strRow, "{.createAt}", string(val.CreateAt()))
  52. strRow = strings.ReplaceAll(strRow, "{.updateAt}", string(val.UpdateAt()))
  53. strRow = strings.ReplaceAll(strRow, "{.comment}", val.Comment())
  54. strOut += strRow
  55. }
  56. strOut = strings.ReplaceAll(strBlockModules, "{.mod_block}", strOut)
  57. return strOut
  58. }