btn_modules.go 2.3 KB

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