btn_modules.go 2.4 KB

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