package modules import ( "fmt" "html" "os" "path/filepath" "strings" "golang-fave/engine/assets" "golang-fave/engine/builder" "golang-fave/engine/utils" "golang-fave/engine/wrapper" ) func (this *Modules) RegisterAction_FilesList() *Action { return this.newAction(AInfo{ Mount: "files-list", WantAdmin: true, }, func(wrap *wrapper.Wrapper) { pf_path := utils.SafeFilePath(utils.Trim(wrap.R.FormValue("path"))) // Set path wrap.Write(`fave.FilesManagerSetPath('` + pf_path + `');`) // Render table start_dir := strings.Join([]string{wrap.DHtdocs, "public"}, string(os.PathSeparator)) + pf_path + "*" str_dirs := "" str_files := "" nothing := true if files, err := filepath.Glob(start_dir); err == nil { for _, file := range files { file_name := file i := strings.LastIndex(file_name, string(os.PathSeparator)) if i != -1 { file_name = file_name[i+1:] } if utils.IsDir(file) { if nothing { nothing = false } actions := builder.DataTableAction(&[]builder.DataTableActionRow{ { Icon: assets.SysSvgIconView, Href: "/public" + pf_path + file_name + "/", Hint: "View", Target: "_blank", }, { Icon: assets.SysSvgIconRemove, Href: "javascript:fave.FilesManagerRemoveFolder(\\'" + pf_path + file_name + "\\',\\'Are you sure want to delete folder?\\');", Hint: "Delete", Classes: "delete", }, }) str_dirs += `` + html.EscapeString(file_name) + `DIR` + actions + `` } else { if nothing { nothing = false } actions := builder.DataTableAction(&[]builder.DataTableActionRow{ { Icon: assets.SysSvgIconView, Href: "/public" + pf_path + file_name, Hint: "View", Target: "_blank", }, { Icon: assets.SysSvgIconRemove, Href: "javascript:fave.FilesManagerRemoveFile(\\'" + pf_path + file_name + "\\',\\'Are you sure want to delete file?\\');", Hint: "Delete", Classes: "delete", }, }) size_value := float64(utils.GetFileSize(file)) size_text := "Bytes" if size_value > 1024 { size_value = size_value / 1024 size_text = "Kb" } if size_value > 1024 { size_value = size_value / 1024 size_text = "Mb" } if size_value > 1024 { size_value = size_value / 1024 size_text = "Gb" } str_size := fmt.Sprintf("%5.2f %s", size_value, size_text) str_files += `` + html.EscapeString(file_name) + `` + str_size + `` + actions + `` } } } if pf_path != "/" { str_dirs = `..  ` + str_dirs } str_nothing := `` if nothing { str_nothing = `No data` } table := `` + str_dirs + str_files + str_nothing + `
File nameSizeAction
` wrap.Write(`$('#sys-modal-files-manager .dialog-data').html('` + table + `');`) // Enable buttons wrap.Write(`fave.FilesManagerEnableDisableButtons(false);`) }) }