Browse Source

CP notify module, new svg icon, one more status

Vova Tkach 5 years ago
parent
commit
337de66ba0
5 changed files with 151 additions and 2 deletions
  1. 14 0
      assets/cp.styles.css
  2. 0 0
      assets/cp.styles.css.go
  3. 1 0
      assets/sys.svg.icon.go
  4. 6 2
      engine/builder/builder.go
  5. 130 0
      modules/module_notify_mail.go

+ 14 - 0
assets/cp.styles.css

@@ -725,6 +725,11 @@ body.cp .wrap .sidebar.sidebar-left ul.nav li.nav-item svg.sicon {
 	color: #d9534f;
 }
 
+.svg-yellow svg {
+	fill: currentColor;
+	color: #f0ad4e;
+}
+
 /* Pagination */
 ul.pagination {
 	margin-top: 1rem;
@@ -867,6 +872,15 @@ ul.pagination {
 	text-align: right;
 }
 
+/* Admin table: table_pages */
+.data-table.table_notify_mail .col_datetime {
+	width: 8rem;
+}
+
+.data-table.table_notify_mail .col_status {
+	width: 5rem;
+}
+
 /* Admin data form */
 .data-form label {
 	font-weight: bold;

File diff suppressed because it is too large
+ 0 - 0
assets/cp.styles.css.go


+ 1 - 0
assets/sys.svg.icon.go

@@ -19,3 +19,4 @@ var SysSvgIconRestore = `<svg viewBox="0 0 24 24" width="16" height="16" class="
 var SysSvgIconPagination = `<svg viewBox="0 0 24 24" width="16" height="16" class="sicon" version="1.1"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M10 10.02h5V21h-5zM17 21h3c1.1 0 2-.9 2-2v-9h-5v11zm3-18H5c-1.1 0-2 .9-2 2v3h19V5c0-1.1-.9-2-2-2zM3 19c0 1.1.9 2 2 2h3V10H3v9z"/></svg>`
 var SysSvgIconThumbnails = `<svg viewBox="0 0 24 24" width="16" height="16" class="sicon" version="1.1"><path d="M0 0h24v24H0z" fill="none"/><path d="M23 18V6c0-1.1-.9-2-2-2H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2zM8.5 12.5l2.5 3.01L14.5 11l4.5 6H5l3.5-4.5z"/></svg>`
 var SysSvgIconApi = `<svg viewBox="0 0 24 24" width="16" height="16" class="sicon" version="1.1"><path d="M0 0h24v24H0z" fill="none"/><path d="M5 2c0-.55-.45-1-1-1s-1 .45-1 1v4H1v6h6V6H5V2zm4 14c0 1.3.84 2.4 2 2.82V23h2v-4.18c1.16-.41 2-1.51 2-2.82v-2H9v2zm-8 0c0 1.3.84 2.4 2 2.82V23h2v-4.18C6.16 18.4 7 17.3 7 16v-2H1v2zM21 6V2c0-.55-.45-1-1-1s-1 .45-1 1v4h-2v6h6V6h-2zm-8-4c0-.55-.45-1-1-1s-1 .45-1 1v4H9v6h6V6h-2V2zm4 14c0 1.3.84 2.4 2 2.82V23h2v-4.18c1.16-.41 2-1.51 2-2.82v-2h-6v2z"/></svg>`
+var SysSvgIconEmail = `<svg viewBox="0 0 24 24" width="16" height="16" class="sicon" version="1.1"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M22 6c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6zm-2 0l-8 5-8-5h16zm0 12H4V8l8 5 8-5v10z"/></svg>`

+ 6 - 2
engine/builder/builder.go

@@ -5,8 +5,12 @@ import (
 )
 
 func CheckBox(value int) string {
-	if value > 0 {
+	if value == 0 {
+		return `<span class="svg-red">` + assets.SysSvgIconError + `</span>`
+	} else if value == 1 {
 		return `<span class="svg-green">` + assets.SysSvgIconChecked + `</span>`
+	} else if value == 2 {
+		return `<span class="svg-yellow">` + assets.SysSvgIconRestore + `</span>`
 	}
-	return `<span class="svg-red">` + assets.SysSvgIconError + `</span>`
+	return ""
 }

+ 130 - 0
modules/module_notify_mail.go

@@ -0,0 +1,130 @@
+package modules
+
+import (
+	"html"
+
+	"golang-fave/assets"
+	"golang-fave/consts"
+	"golang-fave/engine/builder"
+	"golang-fave/engine/sqlw"
+	"golang-fave/engine/wrapper"
+	"golang-fave/utils"
+)
+
+func (this *Modules) RegisterModule_NotifyMail() *Module {
+	return this.newModule(MInfo{
+		WantDB: true,
+		Mount:  "notify-mail",
+		Name:   "Mail notifier",
+		Order:  803,
+		System: true,
+		Icon:   assets.SysSvgIconEmail,
+		Sub: &[]MISub{
+			{Mount: "default", Name: "All", Show: true, Icon: assets.SysSvgIconList},
+			{Mount: "success", Name: "Success", Show: true, Icon: assets.SysSvgIconList},
+			{Mount: "in-progress", Name: "In progress", Show: true, Icon: assets.SysSvgIconList},
+			{Mount: "error", Name: "Error", Show: true, Icon: assets.SysSvgIconList},
+		},
+	}, nil, func(wrap *wrapper.Wrapper) (string, string, string) {
+		content := ""
+		sidebar := ""
+		if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" || wrap.CurrSubModule == "success" || wrap.CurrSubModule == "in-progress" || wrap.CurrSubModule == "error" {
+			ModuleName := "All"
+			ModulePagination := "/cp/" + wrap.CurrModule + "/"
+			ModuleSqlWhere := ""
+
+			if wrap.CurrSubModule == "success" {
+				ModuleName = "Success"
+				ModulePagination = "/cp/" + wrap.CurrModule + "/success/"
+				ModuleSqlWhere = " WHERE notify_mail.status = 1"
+			} else if wrap.CurrSubModule == "in-progress" {
+				ModuleName = "In progress"
+				ModulePagination = "/cp/" + wrap.CurrModule + "/in-progress/"
+				ModuleSqlWhere = " WHERE notify_mail.status = 2"
+			} else if wrap.CurrSubModule == "error" {
+				ModuleName = "Error"
+				ModulePagination = "/cp/" + wrap.CurrModule + "/error/"
+				ModuleSqlWhere = " WHERE notify_mail.status = 0"
+			}
+
+			content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
+				{Name: ModuleName},
+			})
+			content += builder.DataTable(
+				wrap,
+				"notify_mail",
+				"id",
+				"DESC",
+				&[]builder.DataTableRow{
+					{
+						DBField: "id",
+					},
+					{
+						DBField:     "email",
+						NameInTable: "Email / Subject",
+						CallBack: func(values *[]string) string {
+							email := `<a href="/cp/` + wrap.CurrModule + `/details/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + `</a>`
+							subject := html.EscapeString((*values)[2])
+							if subject != "" {
+								subject = `<div><small>` + subject + `</small></div>`
+							}
+							return `<div>` + email + `</div>` + subject
+						},
+					},
+					{
+						DBField: "subject",
+					},
+					{
+						DBField:     "datetime",
+						DBExp:       "UNIX_TIMESTAMP(`datetime`)",
+						NameInTable: "Date / Time",
+						Classes:     "d-none d-md-table-cell",
+						CallBack: func(values *[]string) string {
+							t := int64(utils.StrToInt((*values)[3]))
+							return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
+								`<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
+						},
+					},
+					{
+						DBField:     "status",
+						NameInTable: "Status",
+						Classes:     "d-none d-sm-table-cell",
+						CallBack: func(values *[]string) string {
+							return builder.CheckBox(utils.StrToInt((*values)[4]))
+						},
+					},
+				},
+				nil,
+				ModulePagination,
+				func() (int, error) {
+					var count int
+					return count, wrap.DB.QueryRow(
+						"SELECT COUNT(*) FROM `notify_mail`" + ModuleSqlWhere + ";",
+					).Scan(&count)
+				},
+				func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
+					return wrap.DB.Query(
+						`SELECT
+							notify_mail.id,
+							notify_mail.email,
+							notify_mail.subject,
+							UNIX_TIMESTAMP(`+"`notify_mail`.`datetime`"+`) AS datetime,
+							notify_mail.status
+						FROM
+							notify_mail
+						`+ModuleSqlWhere+`
+						ORDER BY
+							notify_mail.id DESC
+						LIMIT ?, ?;`,
+						limit_offset,
+						pear_page,
+					)
+				},
+				true,
+			)
+		} else if wrap.CurrSubModule == "details" {
+			//
+		}
+		return this.getSidebarModules(wrap), content, sidebar
+	})
+}

Some files were not shown because too many files changed in this diff