2018-10-12 04:26:42 -05:00
|
|
|
package hooks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/grafana/grafana/pkg/api/dtos"
|
2023-01-27 01:50:36 -06:00
|
|
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
2018-10-12 04:26:42 -05:00
|
|
|
)
|
|
|
|
|
2023-01-27 01:50:36 -06:00
|
|
|
type IndexDataHook func(indexData *dtos.IndexViewData, req *contextmodel.ReqContext)
|
2018-10-12 04:26:42 -05:00
|
|
|
|
|
|
|
type HooksService struct {
|
|
|
|
indexDataHooks []IndexDataHook
|
|
|
|
}
|
|
|
|
|
2021-08-25 08:11:22 -05:00
|
|
|
func ProvideService() *HooksService {
|
|
|
|
return &HooksService{}
|
2018-10-12 04:26:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (srv *HooksService) AddIndexDataHook(hook IndexDataHook) {
|
|
|
|
srv.indexDataHooks = append(srv.indexDataHooks, hook)
|
|
|
|
}
|
|
|
|
|
2023-01-27 01:50:36 -06:00
|
|
|
func (srv *HooksService) RunIndexDataHooks(indexData *dtos.IndexViewData, req *contextmodel.ReqContext) {
|
2018-10-12 04:26:42 -05:00
|
|
|
for _, hook := range srv.indexDataHooks {
|
2020-01-27 02:24:44 -06:00
|
|
|
hook(indexData, req)
|
2018-10-12 04:26:42 -05:00
|
|
|
}
|
|
|
|
}
|