// package btn_modules -- кнопка для показа модулей. package btn_modules import ( _ "embed" "fmt" "strings" . "gitp78su.ipnodns.ru/svi/kern/v4/lev0/ktypes" . "gitp78su.ipnodns.ru/svi/kern/v4/lev1/result" "gitp78su.ipnodns.ru/svi/kern/v4/lev2/kctx" "gitp78su.ipnodns.ru/svi/kern/v4/lev2/wui" . "gitp78su.ipnodns.ru/svi/kern/v4/lev2/wui/wtypes" ) type BtnModules struct { btn IWuiButton kCtx IKernelCtx } // NewBtnModules -- возвращает новую кнопку для показа модулей. func NewBtnModules() IResult[*BtnModules] { resKernCtx := kctx.GetKernelCtx() if resKernCtx.IsErr() { err := fmt.Errorf("NewBtnModules(): err=\n\t%w", resKernCtx.Err()) return NewErr[*BtnModules](err) } kCtx := resKernCtx.Val() sf := &BtnModules{ kCtx: kCtx, } resBtn := wui.NewWuiButton("Modules", sf.clickMonolit) if resBtn.IsErr() { err := fmt.Errorf("NewBtnModules(): err=\n\t%w", resBtn.Err()) return NewErr[*BtnModules](err) } sf.btn = resBtn.Val() sf.btn.Hx().Target().Set("#modules") return NewRes(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) IResult[string] { optMonolit := sf.kCtx.Get("monolit") if optMonolit.IsNone() { err := fmt.Errorf("clickMonolit(): monolit module not found") return NewErr[string](err) } mon := optMonolit.Val().Val().(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 := string(val.Val().(IKernelModule).Name()) strRow = strings.ReplaceAll(strRow, "{.name}", moduleName) type_ := fmt.Sprintf("%#T", val.Val()) type_ = strings.ReplaceAll(type_, ".", ".
") strRow = strings.ReplaceAll(strRow, "{.type}", type_) strRow = strings.ReplaceAll(strRow, "{.createAt}", string(val.CreateAt())) strRow = strings.ReplaceAll(strRow, "{.updateAt}", string(val.UpdateAt())) strRow = strings.ReplaceAll(strRow, "{.comment}", val.Comment()) strOut += strRow } strOut = strings.ReplaceAll(strBlockModules, "{.mod_block}", strOut) return NewRes(strOut) }