// package btn_modules -- кнопка для показа модулей. package btn_modules import ( _ "embed" "fmt" "strings" "gitp78su.ipnodns.ru/svi/kern/v4/d0" "gitp78su.ipnodns.ru/svi/kern/v4/d2" "gitp78su.ipnodns.ru/svi/kern/v4/d2/wui" mWt "gitp78su.ipnodns.ru/svi/kern/v4/d2/wui/wui_types" "gitp78su.ipnodns.ru/svi/kern/v4/d3/mod_spec" ) type BtnModules struct { btn mWt.IWuiButton kCtx *d2.KernCtx } // NewBtnModules -- возвращает новую кнопку для показа модулей. func NewBtnModules() *BtnModules { sf := &BtnModules{ kCtx: d2.GetKernCtx(), } sf.btn = wui.NewWuiButton(d0.LetTxt("Modules"), sf.clickMonolit) sf.btn.Hx().Target().Set("#modules") return sf } // Html -- возвращает HTML-представление кнопки. func (sf *BtnModules) Html() *d0.LTxt { 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[d0.Txt]d0.Txt) *d0.Result[*d0.LTxt] { optMonolit := sf.kCtx.Get(d0.LetTxt("monolit")) if optMonolit.IsNone() { err := d0.LetErr("clickMonolit(): monolit module not found") return d0.ResErr[*d0.LTxt](err) } mon := optMonolit.Some().Val().(mod_spec.IKernelMonolit) chLst := mon.Ctx().SortedList() strOut := `` for _, val := range chLst { if !strings.Contains(val.Key().String(), "module_") { continue } lstKey := strings.Split(val.Key().String(), "_") id := lstKey[1] strRow := strBlockRow strRow = strings.ReplaceAll(strRow, "{.id}", id) strRow = strings.ReplaceAll(strRow, "{.key}", val.Key().String()) moduleName := val.Val().(mod_spec.IKernelModule).Name().Get() strRow = strings.ReplaceAll(strRow, "{.name}", string(moduleName)) type_ := fmt.Sprintf("%#T", val.Val()) type_ = strings.ReplaceAll(type_, ".", ".
") 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().String()) strOut += strRow } strOut = strings.ReplaceAll(strBlockModules, "{.mod_block}", strOut) txtOut := d0.LetTxt(strOut) return d0.ResOk(txtOut) }