Skip to content

Commit

Permalink
update AddProcessor api
Browse files Browse the repository at this point in the history
  • Loading branch information
binku87 committed Oct 16, 2017
1 parent 1118bc1 commit 7c6ac54
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions media_library.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,37 +271,40 @@ func (mediaBox MediaBox) ConfigureQorMeta(metaor resource.Metaor) {
})
}

config.RemoteDataResource.AddProcessor(func(record interface{}, metaValues *resource.MetaValues, context *qor.Context) error {
if mediaLibrary, ok := record.(MediaLibraryInterface); ok {
var filename string
var mediaOption MediaOption

for _, metaValue := range metaValues.Values {
if fileHeaders, ok := metaValue.Value.([]*multipart.FileHeader); ok {
for _, fileHeader := range fileHeaders {
filename = fileHeader.Filename
config.RemoteDataResource.AddProcessor(&resource.Processor{
Name: "media-meta-processor",
Handler: func(record interface{}, metaValues *resource.MetaValues, context *qor.Context) error {
if mediaLibrary, ok := record.(MediaLibraryInterface); ok {
var filename string
var mediaOption MediaOption

for _, metaValue := range metaValues.Values {
if fileHeaders, ok := metaValue.Value.([]*multipart.FileHeader); ok {
for _, fileHeader := range fileHeaders {
filename = fileHeader.Filename
}
}
}
}

if metaValue := metaValues.Get("MediaOption"); metaValue != nil {
mediaOptionStr := utils.ToString(metaValue.Value)
json.Unmarshal([]byte(mediaOptionStr), &mediaOption)
}
if metaValue := metaValues.Get("MediaOption"); metaValue != nil {
mediaOptionStr := utils.ToString(metaValue.Value)
json.Unmarshal([]byte(mediaOptionStr), &mediaOption)
}

if mediaOption.SelectedType == "video_link" {
mediaLibrary.SetSelectedType("video_link")
} else if filename != "" {
if _, err := getImageFormat(filename); err == nil {
mediaLibrary.SetSelectedType("image")
} else if isVideoFormat(filename) {
mediaLibrary.SetSelectedType("video")
} else {
mediaLibrary.SetSelectedType("file")
if mediaOption.SelectedType == "video_link" {
mediaLibrary.SetSelectedType("video_link")
} else if filename != "" {
if _, err := getImageFormat(filename); err == nil {
mediaLibrary.SetSelectedType("image")
} else if isVideoFormat(filename) {
mediaLibrary.SetSelectedType("video")
} else {
mediaLibrary.SetSelectedType("file")
}
}
}
}
return nil
return nil
},
})

config.RemoteDataResource.UseTheme("grid")
Expand Down

0 comments on commit 7c6ac54

Please sign in to comment.