2020-09-13 20:37:07 +08:00
|
|
|
package cache
|
|
|
|
|
|
|
|
|
|
import (
|
2020-10-04 14:27:05 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/cache/cacheutils"
|
2020-09-13 20:37:07 +08:00
|
|
|
"github.com/iwind/TeaGo/actions"
|
|
|
|
|
"net/http"
|
2020-10-04 14:27:05 +08:00
|
|
|
"reflect"
|
2020-09-13 20:37:07 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Helper struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewHelper() *Helper {
|
|
|
|
|
return &Helper{}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-04 14:27:05 +08:00
|
|
|
func (this *Helper) BeforeAction(actionPtr actions.ActionWrapper) {
|
|
|
|
|
action := actionPtr.Object()
|
2020-09-13 20:37:07 +08:00
|
|
|
if action.Request.Method != http.MethodGet {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
action.Data["mainTab"] = "component"
|
|
|
|
|
action.Data["secondMenuItem"] = "cache"
|
2020-10-04 14:27:05 +08:00
|
|
|
|
|
|
|
|
cachePolicyId := action.ParamInt64("cachePolicyId")
|
|
|
|
|
action.Data["cachePolicyId"] = cachePolicyId
|
|
|
|
|
|
|
|
|
|
parentActionValue := reflect.ValueOf(actionPtr).Elem().FieldByName("ParentAction")
|
|
|
|
|
if parentActionValue.IsValid() {
|
|
|
|
|
parentAction, isOk := parentActionValue.Interface().(actionutils.ParentAction)
|
|
|
|
|
if isOk {
|
|
|
|
|
action.Data["cachePolicyName"] = cacheutils.FindCachePolicyNameWithoutError(&parentAction, cachePolicyId)
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-13 20:37:07 +08:00
|
|
|
}
|