module_notify_mail.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package modules
  2. import (
  3. "html"
  4. "golang-fave/engine/assets"
  5. "golang-fave/engine/builder"
  6. "golang-fave/engine/consts"
  7. "golang-fave/engine/sqlw"
  8. "golang-fave/engine/utils"
  9. "golang-fave/engine/wrapper"
  10. )
  11. func (this *Modules) RegisterModule_NotifyMail() *Module {
  12. return this.newModule(MInfo{
  13. Mount: "notify-mail",
  14. Name: "Mail notifier",
  15. Order: 803,
  16. System: true,
  17. Icon: assets.SysSvgIconEmail,
  18. Sub: &[]MISub{
  19. {Mount: "default", Name: "All", Show: true, Icon: assets.SysSvgIconList},
  20. {Mount: "success", Name: "Success", Show: true, Icon: assets.SysSvgIconList},
  21. {Mount: "in-progress", Name: "In progress", Show: true, Icon: assets.SysSvgIconList},
  22. {Mount: "error", Name: "Error", Show: true, Icon: assets.SysSvgIconList},
  23. },
  24. }, nil, func(wrap *wrapper.Wrapper) (string, string, string) {
  25. content := ""
  26. sidebar := ""
  27. if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" || wrap.CurrSubModule == "success" || wrap.CurrSubModule == "in-progress" || wrap.CurrSubModule == "error" {
  28. ModuleName := "All"
  29. ModulePagination := "/cp/" + wrap.CurrModule + "/"
  30. ModuleSqlWhere := ""
  31. if wrap.CurrSubModule == "success" {
  32. ModuleName = "Success"
  33. ModulePagination = "/cp/" + wrap.CurrModule + "/success/"
  34. ModuleSqlWhere = " WHERE fave_notify_mail.status = 1"
  35. } else if wrap.CurrSubModule == "in-progress" {
  36. ModuleName = "In progress"
  37. ModulePagination = "/cp/" + wrap.CurrModule + "/in-progress/"
  38. ModuleSqlWhere = " WHERE fave_notify_mail.status = 2 OR fave_notify_mail.status = 3"
  39. } else if wrap.CurrSubModule == "error" {
  40. ModuleName = "Error"
  41. ModulePagination = "/cp/" + wrap.CurrModule + "/error/"
  42. ModuleSqlWhere = " WHERE fave_notify_mail.status = 0"
  43. }
  44. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  45. {Name: ModuleName},
  46. })
  47. content += builder.DataTable(
  48. wrap,
  49. "fave_notify_mail",
  50. "id",
  51. "DESC",
  52. &[]builder.DataTableRow{
  53. {
  54. DBField: "id",
  55. },
  56. {
  57. DBField: "email",
  58. NameInTable: "Email / Subject",
  59. CallBack: func(values *[]string) string {
  60. subject := html.EscapeString((*values)[2])
  61. if subject != "" {
  62. subject = `<div><small>` + subject + `</small></div>`
  63. }
  64. error_message := html.EscapeString((*values)[5])
  65. if error_message != "" {
  66. error_message = `<div><small><b>` + error_message + `</b></small></div>`
  67. }
  68. return `<div>` + html.EscapeString((*values)[1]) + `</div>` + subject + error_message
  69. },
  70. },
  71. {
  72. DBField: "subject",
  73. },
  74. {
  75. DBField: "datetime",
  76. DBExp: "UNIX_TIMESTAMP(`datetime`)",
  77. NameInTable: "Date / Time",
  78. Classes: "d-none d-md-table-cell",
  79. CallBack: func(values *[]string) string {
  80. t := int64(utils.StrToInt((*values)[3]))
  81. return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
  82. `<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
  83. },
  84. },
  85. {
  86. DBField: "status",
  87. NameInTable: "Status",
  88. Classes: "d-none d-sm-table-cell",
  89. CallBack: func(values *[]string) string {
  90. return builder.CheckBox(utils.StrToInt((*values)[4]))
  91. },
  92. },
  93. {
  94. DBField: "error",
  95. },
  96. },
  97. nil,
  98. ModulePagination,
  99. func() (int, error) {
  100. var count int
  101. return count, wrap.DB.QueryRow(
  102. wrap.R.Context(),
  103. "SELECT COUNT(*) FROM `fave_notify_mail`"+ModuleSqlWhere+";",
  104. ).Scan(&count)
  105. },
  106. func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
  107. return wrap.DB.Query(
  108. wrap.R.Context(),
  109. `SELECT
  110. fave_notify_mail.id,
  111. fave_notify_mail.email,
  112. fave_notify_mail.subject,
  113. UNIX_TIMESTAMP(`+"`fave_notify_mail`.`datetime`"+`) AS datetime,
  114. fave_notify_mail.status,
  115. fave_notify_mail.error
  116. FROM
  117. fave_notify_mail
  118. `+ModuleSqlWhere+`
  119. ORDER BY
  120. fave_notify_mail.id DESC
  121. LIMIT ?, ?;`,
  122. limit_offset,
  123. pear_page,
  124. )
  125. },
  126. true,
  127. )
  128. }
  129. return this.getSidebarModules(wrap), content, sidebar
  130. })
  131. }