l10n_model_with_version.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package models
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. "github.com/qor/oss"
  8. "github.com/qor5/admin/l10n"
  9. "github.com/qor5/admin/publish"
  10. "gorm.io/gorm"
  11. )
  12. type L10nModelWithVersion struct {
  13. gorm.Model
  14. Title string
  15. publish.Status
  16. publish.Version
  17. publish.Schedule
  18. l10n.Locale
  19. }
  20. func (lmv *L10nModelWithVersion) PrimarySlug() string {
  21. return fmt.Sprintf("%v_%v_%v", lmv.ID, lmv.Version.Version, lmv.LocaleCode)
  22. }
  23. func (lmv *L10nModelWithVersion) PrimaryColumnValuesBySlug(slug string) map[string]string {
  24. segs := strings.Split(slug, "_")
  25. if len(segs) != 3 {
  26. panic("wrong slug")
  27. }
  28. return map[string]string{
  29. "id": segs[0],
  30. "version": segs[1],
  31. "locale_code": segs[2],
  32. }
  33. }
  34. func (lmv *L10nModelWithVersion) GetPublishActions(db *gorm.DB, ctx context.Context, storage oss.StorageInterface) (objs []*publish.PublishAction, err error) {
  35. return
  36. }
  37. func (lmv *L10nModelWithVersion) GetUnPublishActions(db *gorm.DB, ctx context.Context, storage oss.StorageInterface) (objs []*publish.PublishAction, err error) {
  38. return
  39. }
  40. func (lmv *L10nModelWithVersion) PermissionRN() []string {
  41. return []string{"l10n_model_with_versions", strconv.Itoa(int(lmv.ID)), lmv.LocaleCode, lmv.Version.Version}
  42. }