-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
media list(events): Event media list
Render a list of media for an event. The component can be re-used for posts, comments, or what-have-you
- Loading branch information
Showing
11 changed files
with
183 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Api::V1::EventMediaController < ApplicationController | ||
def create | ||
uploaded_file = params[:file] | ||
|
||
s3_object = Medium.s3_create uploaded_file | ||
@event = Event.find_by_id params[:event_id] | ||
@media = @event.media.create! name: s3_object[:name], url: s3_object[:url] | ||
|
||
render json: {event: @event, media: @media} | ||
end | ||
|
||
def index | ||
@event = Event.find_by_id params[:event_id] | ||
render json: @event.media | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<template> | ||
<div id="editable-media"> | ||
<md-card> | ||
<MediaList :media='media' /> | ||
<md-field v-if='isEditable'> | ||
<label>Add media</label> | ||
<md-file v-model='mediaFile' v-on:md-change='addMedia' /> | ||
</md-field> | ||
</md-card> | ||
</div> | ||
</template> | ||
<script> | ||
import MediaList from './MediaList.vue' | ||
export default { | ||
name: 'EditableMedia', | ||
components: {MediaList}, | ||
props: { | ||
model_id: Number, | ||
model_type: String, | ||
media: {type: Array, required: false}, | ||
isEditable: {type: Boolean, default: false}, | ||
}, | ||
data: function() { | ||
return { | ||
mediaFile: null | ||
} | ||
}, | ||
methods: { | ||
addMedia: function(fileList) { | ||
this.$emit('addMedia', fileList) | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<template> | ||
<div id="media-list"> | ||
<ul class="media"> | ||
<li v-for='m in media' :key='m.id'> | ||
<img :src='m.url' class="media-file" /> | ||
</li> | ||
</ul> | ||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
name: 'Media', | ||
props: { | ||
media: Array, | ||
}, | ||
} | ||
</script> | ||
<style language='scss' scoped> | ||
.media-file { | ||
width: 125px; | ||
height: 125px; | ||
} | ||
ul { | ||
list-style-type: none; | ||
width: 100%; | ||
overflow-x: scroll; | ||
white-space: nowrap; | ||
} | ||
ul > li { | ||
display: inline-block; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
class Medium < ApplicationRecord | ||
belongs_to :mediable, polymorphic: true | ||
belongs_to :mediumable, polymorphic: true | ||
def self.s3_create(uploaded_file) | ||
s3 = Rails.configuration.s3 | ||
bucket = Rails.configuration.media_bucket | ||
key = "#{uploaded_file.original_filename}__#{DateTime.now.to_i}" | ||
|
||
s3.put_object( | ||
key: key, | ||
bucket: bucket, | ||
content_type: uploaded_file.content_type, | ||
body: uploaded_file.tempfile, | ||
) | ||
s3_object = Aws::S3::Object.new bucket_name: bucket, key: key | ||
|
||
puts "Created public URL: #{s3_object.public_url}" | ||
{ | ||
url: s3_object.public_url, | ||
name: key, | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"Version":"2012-10-17", | ||
"Statement":[ | ||
{ | ||
"Sid":"PublicRead", | ||
"Effect":"Allow", | ||
"Principal": "*", | ||
"Action":["s3:GetObject"], | ||
"Resource":["arn:aws:s3:::media/*"] | ||
} | ||
] | ||
} |