| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- // package btn_modules -- кнопка для показа модулей.
- package btn_modules
- import (
- _ "embed"
- "fmt"
- "strings"
- mL0 "gitp78su.ipnodns.ru/svi/kern/v4/lev0"
- mKs "gitp78su.ipnodns.ru/svi/kern/v4/lev0/kspec"
- "gitp78su.ipnodns.ru/svi/kern/v4/lev2/kctx"
- "gitp78su.ipnodns.ru/svi/kern/v4/lev2/wui"
- mWt "gitp78su.ipnodns.ru/svi/kern/v4/lev2/wui/wui_types"
- )
- type BtnModules struct {
- btn mWt.IWuiButton
- kCtx mKs.IKernelCtx
- }
- // NewBtnModules -- возвращает новую кнопку для показа модулей.
- func NewBtnModules() *BtnModules {
- sf := &BtnModules{
- kCtx: kctx.GetKernelCtx(),
- }
- sf.btn = wui.NewWuiButton("Modules", sf.clickMonolit)
- sf.btn.Hx().Target().Set("#modules")
- return sf
- }
- // Html -- возвращает HTML-представление кнопки.
- func (sf *BtnModules) Html() string {
- return sf.btn.Html()
- }
- //go:embed block_modules.html
- var strBlockModules string
- //go:embed block_row.html
- var strBlockRow string
- // Событие клика по кнопке.
- func (sf *BtnModules) clickMonolit(dict map[string]string) mL0.IResult[string] {
- optMonolit := sf.kCtx.Get("monolit")
- if optMonolit.IsNone() {
- err := fmt.Errorf("clickMonolit(): monolit module not found")
- return mL0.NewErr[string](err)
- }
- mon := optMonolit.Some().Val().(mKs.IKernelMonolit)
- chLst := mon.Ctx().SortedList()
- strOut := ``
- for _, val := range chLst {
- if !strings.Contains(val.Key(), "module_") {
- continue
- }
- lstKey := strings.Split(val.Key(), "_")
- id := lstKey[1]
- strRow := strBlockRow
- strRow = strings.ReplaceAll(strRow, "{.id}", id)
- strRow = strings.ReplaceAll(strRow, "{.key}", val.Key())
- moduleName := val.Val().(mKs.IKernelModule).Name().Get()
- strRow = strings.ReplaceAll(strRow, "{.name}", moduleName)
- type_ := fmt.Sprintf("%#T", val.Val())
- type_ = strings.ReplaceAll(type_, ".", ".<br>")
- strRow = strings.ReplaceAll(strRow, "{.type}", type_)
- strRow = strings.ReplaceAll(strRow, "{.createAt}", val.CreateAt().String())
- strRow = strings.ReplaceAll(strRow, "{.updateAt}", val.UpdateAt().String())
- strRow = strings.ReplaceAll(strRow, "{.comment}", val.Comment())
- strOut += strRow
- }
- strOut = strings.ReplaceAll(strBlockModules, "{.mod_block}", strOut)
- return mL0.NewRes(strOut)
- }
|