mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.4 KiB
69 lines
1.4 KiB
4 years ago
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
4 years ago
|
package middleware
|
||
4 years ago
|
|
||
|
import "net/url"
|
||
|
|
||
|
// flashes enumerates all the flash types
|
||
|
const (
|
||
|
SuccessFlash = "SuccessMsg"
|
||
|
ErrorFlash = "ErrorMsg"
|
||
|
WarnFlash = "WarningMsg"
|
||
|
InfoFlash = "InfoMsg"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
// FlashNow FIXME:
|
||
|
FlashNow bool
|
||
|
)
|
||
|
|
||
|
// Flash represents a one time data transfer between two requests.
|
||
|
type Flash struct {
|
||
|
DataStore
|
||
|
url.Values
|
||
|
ErrorMsg, WarningMsg, InfoMsg, SuccessMsg string
|
||
|
}
|
||
|
|
||
|
func (f *Flash) set(name, msg string, current ...bool) {
|
||
4 years ago
|
if f.Values == nil {
|
||
|
f.Values = make(map[string][]string)
|
||
|
}
|
||
4 years ago
|
isShow := false
|
||
|
if (len(current) == 0 && FlashNow) ||
|
||
|
(len(current) > 0 && current[0]) {
|
||
|
isShow = true
|
||
|
}
|
||
|
|
||
|
if isShow {
|
||
|
f.GetData()["Flash"] = f
|
||
|
} else {
|
||
|
f.Set(name, msg)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Error sets error message
|
||
|
func (f *Flash) Error(msg string, current ...bool) {
|
||
|
f.ErrorMsg = msg
|
||
|
f.set("error", msg, current...)
|
||
|
}
|
||
|
|
||
|
// Warning sets warning message
|
||
|
func (f *Flash) Warning(msg string, current ...bool) {
|
||
|
f.WarningMsg = msg
|
||
|
f.set("warning", msg, current...)
|
||
|
}
|
||
|
|
||
|
// Info sets info message
|
||
|
func (f *Flash) Info(msg string, current ...bool) {
|
||
|
f.InfoMsg = msg
|
||
|
f.set("info", msg, current...)
|
||
|
}
|
||
|
|
||
|
// Success sets success message
|
||
|
func (f *Flash) Success(msg string, current ...bool) {
|
||
|
f.SuccessMsg = msg
|
||
|
f.set("success", msg, current...)
|
||
|
}
|