ds_media_library 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +9 -0
- data/app/assets/javascripts/ds_media_library.coffee +45 -0
- data/app/assets/javascripts/toggle_all_checkboxes.coffee +6 -0
- data/app/controllers/ds_media_library/folders_controller.rb +37 -0
- data/app/controllers/ds_media_library/resources_controller.rb +71 -0
- data/app/models/ds_media_library/folder.rb +43 -0
- data/app/views/ds_media_library/_folder.html.slim +11 -0
- data/app/views/ds_media_library/_form_helper.html.slim +30 -0
- data/app/views/ds_media_library/_image_preview.html.slim +17 -0
- data/app/views/ds_media_library/_resource.html.slim +27 -0
- data/app/views/ds_media_library/resources/_folder.html.slim +14 -0
- data/app/views/ds_media_library/resources/_resource.html.slim +12 -0
- data/app/views/ds_media_library/resources/folder_form.html.slim +19 -0
- data/app/views/ds_media_library/resources/form.html.slim +31 -0
- data/app/views/ds_media_library/resources/index.html.slim +28 -0
- data/app/views/shared/_image_preview.html.slim +17 -0
- data/app/views/shared/_submit.html.slim +6 -0
- data/bin/console +14 -0
- data/bin/server +5 -0
- data/bin/setup +5 -0
- data/config/routes.rb +8 -0
- data/ds_media_library.gemspec +44 -0
- data/dummy/app.rb +53 -0
- data/dummy/database.rb +55 -0
- data/dummy/views.rb +114 -0
- data/lib/ds_media_library/engine.rb +32 -0
- data/lib/ds_media_library/form_helper.rb +86 -0
- data/lib/ds_media_library/version.rb +3 -0
- data/lib/ds_media_library.rb +10 -0
- data/tmp/.keep +0 -0
- metadata +348 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4545cb01d7748469b1a56e318ac1e9b486572cbe
|
4
|
+
data.tar.gz: bcc20e72bf15ec51768b1f9b761423f477f51952
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e3ca176c347d840facdc99787dc619ec086054576448f1546f52a8568aac563c7f19f37461b6fbe1baddc04744f20da03e263a2ca9c6285b624e2f1da13abf2c
|
7
|
+
data.tar.gz: 6502f1776c07ed4845c535c4818b13a71c237c0f509a7f7d3198303a2721eea967f0342353376697ed64b9b2b2867908a82d3997f59fd4c25ee388465e6bf474
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ds_media_library
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.6
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Micah Geisel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# DSMediaLibrary
|
2
|
+
[![Build Status](https://travis-ci.org/botandrose/ds_media_library.svg?branch=master)](https://travis-ci.org/botandrose/ds_media_library)
|
3
|
+
|
4
|
+
A reusable Media Library for Downstream projects built as a Rails Engine.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'ds_media_library'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
1. Mount the engine at the path of your choosing in your routes:
|
21
|
+
```ruby
|
22
|
+
# config/routes.rb
|
23
|
+
Rails.application.routes.draw do
|
24
|
+
# ...
|
25
|
+
mount DSMediaLibrary::Engine => "/media_library"
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
2. Require the app's JavaScript and CSS assets:
|
30
|
+
```sass
|
31
|
+
// application.sass
|
32
|
+
@import ds_media_library
|
33
|
+
```
|
34
|
+
```coffeescript
|
35
|
+
# application.coffee
|
36
|
+
#= require ds_media_library
|
37
|
+
```
|
38
|
+
|
39
|
+
3. Add ds_node columns to your models:
|
40
|
+
```ruby
|
41
|
+
# app/models/widget.rb
|
42
|
+
class Widget < ActiveRecord::Base
|
43
|
+
ds_resource :cat_picture
|
44
|
+
belongs_to_many_ds_resources :dog_pictures
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
4. Use the `#media_library` form helper where you would normally use the `#file_field` form helper:
|
49
|
+
```slim
|
50
|
+
/ app/views/widgets/form.html.slim
|
51
|
+
= form_for @widget do |form|
|
52
|
+
= form.label :cat_picture
|
53
|
+
= form.media_library :cat_picture
|
54
|
+
|
55
|
+
= form.label :dog_pictures
|
56
|
+
= form.media_library :dog_pictures, multiple: true
|
57
|
+
```
|
58
|
+
|
59
|
+
5. Profit!
|
60
|
+
|
61
|
+
## Development
|
62
|
+
|
63
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests.
|
64
|
+
|
65
|
+
You can also run `bin/server` to start a dummy app at http://localhost:8080 that will allow you to experiment. Note that the state of the app is destroyed on exit.
|
66
|
+
|
67
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). You can then run `bundle update ds_media_library` in projects that use it to update them to the newly-released version.
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/botandrose/ds_media_library.
|
72
|
+
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
77
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#= require jquery
|
2
|
+
#= require jquery_ujs
|
3
|
+
#= require jquery-ui/widgets/sortable
|
4
|
+
#= require toggle_all_checkboxes
|
5
|
+
|
6
|
+
$ ->
|
7
|
+
$("[data-media-library]").each ->
|
8
|
+
new MediaLibrary $(this)
|
9
|
+
|
10
|
+
class MediaLibrary
|
11
|
+
constructor: (@$el) ->
|
12
|
+
baseId = @$el.attr("data-media-library")
|
13
|
+
@ids = JSON.parse(@$el.attr("data-media-library-ids"))
|
14
|
+
@$el.find(".media-choice:radio").change => @closeModal()
|
15
|
+
@$target = $("#selected_media_" + baseId)
|
16
|
+
@$modalToggle = $("#" + baseId)
|
17
|
+
@$modalToggle.change (event) =>
|
18
|
+
@showPreviews() unless event.target.checked
|
19
|
+
@showPreviews()
|
20
|
+
|
21
|
+
closeModal: ->
|
22
|
+
@$modalToggle.prop(checked: false).change()
|
23
|
+
|
24
|
+
showPreviews: ->
|
25
|
+
@$target.empty()
|
26
|
+
previews = @$el.find(".media-choice:checked ~ .media-preview-template").map (index, template) =>
|
27
|
+
template.innerHTML.replace(/{{index}}/g, index + 1)
|
28
|
+
previews = previews.toArray().sort (a,b) => @sortPreviews(a,b)
|
29
|
+
@$target.append previews.join("\n")
|
30
|
+
@$target.sortable()
|
31
|
+
|
32
|
+
isMultiple: ->
|
33
|
+
@$el.find(".media-choice").is(":checkbox")
|
34
|
+
|
35
|
+
sortPreviews: (a, b) ->
|
36
|
+
aId = @extractId(a)
|
37
|
+
bId = @extractId(b)
|
38
|
+
if @ids.indexOf(aId) < @ids.indexOf(bId)
|
39
|
+
-1
|
40
|
+
else
|
41
|
+
1
|
42
|
+
|
43
|
+
extractId: (html) ->
|
44
|
+
parseInt(html.match(/value="(\d+)"/)[1])
|
45
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module DSMediaLibrary
|
2
|
+
class FoldersController < ApplicationController
|
3
|
+
expose :folder
|
4
|
+
|
5
|
+
def new
|
6
|
+
@folder = DSMediaLibrary::Folder.new
|
7
|
+
render "ds_media_library/resources/folder_form"
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
DSMediaLibrary::Folder.create! folder_params
|
12
|
+
redirect_to :resources, notice: "Folder created"
|
13
|
+
end
|
14
|
+
|
15
|
+
def edit
|
16
|
+
@folder = DSMediaLibrary::Folder.find(params[:id])
|
17
|
+
render "ds_media_library/resources/folder_form"
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
DSMediaLibrary::Folder.update params[:id], folder_params
|
22
|
+
redirect_to :resources, notice: "Folder updated"
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
DSMediaLibrary::Folder.destroy params[:id]
|
27
|
+
redirect_to :resources, notice: "Folder deleted"
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def folder_params
|
33
|
+
params.require(:folder).permit(:parent_id, :name)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module DSMediaLibrary
|
2
|
+
class ResourcesController < ApplicationController
|
3
|
+
expose :root, :resource, :folders
|
4
|
+
|
5
|
+
def index
|
6
|
+
@root = DSMediaLibrary::Folder.root
|
7
|
+
@folders = folders_with_children
|
8
|
+
end
|
9
|
+
|
10
|
+
def new
|
11
|
+
@resource = DSNode::Resource.new
|
12
|
+
render :form
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
resources_params.each do |resource_params|
|
17
|
+
DSNode::Resource.create! resource_params
|
18
|
+
end
|
19
|
+
redirect_to :resources, notice: "Media created"
|
20
|
+
end
|
21
|
+
|
22
|
+
def edit
|
23
|
+
render :form
|
24
|
+
end
|
25
|
+
|
26
|
+
def update
|
27
|
+
resource.update! resource_params
|
28
|
+
redirect_to :resources, notice: "Media updated"
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy
|
32
|
+
resource.update! hidden: true
|
33
|
+
redirect_to :resources, notice: "Media deleted"
|
34
|
+
end
|
35
|
+
|
36
|
+
def move_many
|
37
|
+
DSNode::Resource.where(resourcesid: params[:resource_ids]).update folder_id: params[:folder_id]
|
38
|
+
redirect_to :resources, notice: "Media updated"
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def resource
|
44
|
+
@resource ||= DSNode::Resource.find(params[:id])
|
45
|
+
end
|
46
|
+
|
47
|
+
def folders_with_children
|
48
|
+
recurse_folders(DSMediaLibrary::Folder.roots.sort_by(&:name))
|
49
|
+
end
|
50
|
+
|
51
|
+
def recurse_folders folders
|
52
|
+
folders.flat_map do |folder|
|
53
|
+
[folder] + recurse_folders(folder.children)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def resource_params
|
58
|
+
resource_params = params.require(:ds_node_resource).permit(:folder_id, :file)
|
59
|
+
# FIXME extract to DSNode gem
|
60
|
+
resource_params.merge!(original_file_name: params[:ds_node_resource][:file].original_filename) if params[:ds_node_resource][:file]
|
61
|
+
resource_params
|
62
|
+
end
|
63
|
+
|
64
|
+
def resources_params
|
65
|
+
params[:ds_node_resource][:file].map do |file|
|
66
|
+
params.require(:ds_node_resource).permit(:folder_id).merge(file: file)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "awesome_nested_set"
|
2
|
+
require "ds_node"
|
3
|
+
|
4
|
+
module DSMediaLibrary
|
5
|
+
class Folder < ActiveRecord::Base
|
6
|
+
self.table_name = :folders
|
7
|
+
|
8
|
+
def self.root
|
9
|
+
klass = Struct.new(:children, :resources)
|
10
|
+
children = Folder.roots.to_a.sort_by(&:name)
|
11
|
+
resources = DSNode::Resource.where(folder_id: nil).order(:original_file_name)
|
12
|
+
klass.new(children, resources)
|
13
|
+
end
|
14
|
+
|
15
|
+
acts_as_nested_set
|
16
|
+
|
17
|
+
has_many :resources, -> { order(:original_file_name) }, class_name: "DSNode::Resource"
|
18
|
+
|
19
|
+
def children
|
20
|
+
super.order(:name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def all_folders
|
24
|
+
self.class.all
|
25
|
+
end
|
26
|
+
|
27
|
+
before_destroy :move_all_contents_to_parent!
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def move_all_contents_to_parent!
|
32
|
+
transaction do
|
33
|
+
resources.each do |resource|
|
34
|
+
resource.update! folder: parent
|
35
|
+
end
|
36
|
+
children.each do |resource|
|
37
|
+
resource.update! parent: parent
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
li
|
2
|
+
input.expand-input type="checkbox" id="#{helper.field}-folder-#{folder.id}"
|
3
|
+
.media-container
|
4
|
+
label.expand-label.folder-link for="#{helper.field}-folder-#{folder.id}" = folder.name
|
5
|
+
|
6
|
+
- if folder.children.any? || folder.resources.any?
|
7
|
+
ul.media-nest
|
8
|
+
- with_options locals: { form: form, helper: helper } do |options|
|
9
|
+
= options.render collection: folder.children, partial: "ds_media_library/folder", as: :folder
|
10
|
+
= options.render collection: folder.resources, partial: "ds_media_library/resource", as: :resource
|
11
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
.media-library data-media-library=helper.html_id data-media-library-ids=helper.ids required=helper.required
|
2
|
+
= form.label helper.file_field_name, helper.label, class: helper.label_css_class
|
3
|
+
|
4
|
+
- if helper.helptext
|
5
|
+
.ratio-text = helper.helptext
|
6
|
+
|
7
|
+
label.media-button for=helper.html_id Media library
|
8
|
+
em or
|
9
|
+
= form.file_field helper.file_field_name, multiple: helper.multiple
|
10
|
+
|
11
|
+
input.modal-input type="checkbox" id=helper.html_id
|
12
|
+
.modal-wrapper
|
13
|
+
.modal-bg
|
14
|
+
.modal-content
|
15
|
+
label.modal-close for=helper.html_id
|
16
|
+
.borders
|
17
|
+
.media-wrapper
|
18
|
+
.info-text Choose a media file below to associate with this field. You can manage media in the <a href="/media_library">Media Library</a>. <br />Note that changing a file in the library will update it across all associated media fields in this app.
|
19
|
+
|
20
|
+
= link_to "Open all folders", "#", class: "open-all-label", data: { "toggle-all-checkboxes" => ".expand-input" }
|
21
|
+
|
22
|
+
input.text#search_media type="text" placeholder="Type keywords to search media (case sensitive)"
|
23
|
+
|
24
|
+
ul.media-nav
|
25
|
+
- with_options locals: { form: form, helper: helper } do |options|
|
26
|
+
= options.render collection: helper.root_folders, partial: "ds_media_library/folder", as: :folder
|
27
|
+
= options.render collection: helper.root_resources, partial: "ds_media_library/resource", as: :resource
|
28
|
+
|
29
|
+
dl.playlist-media id="selected_media_#{helper.html_id}"
|
30
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
- if !defined?(preview) then preview = true
|
2
|
+
|
3
|
+
- if image.present?
|
4
|
+
dfn.preview-form
|
5
|
+
.preview-wrapper
|
6
|
+
- if preview
|
7
|
+
- if image.video?
|
8
|
+
= video_tag image.url, controls: true
|
9
|
+
- else
|
10
|
+
= image_tag image.url
|
11
|
+
|
12
|
+
= yield
|
13
|
+
|
14
|
+
- unless defined?(hide_file_name) && hide_file_name
|
15
|
+
dt
|
16
|
+
figcaption = image.original_file_name
|
17
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
li.resource class=("hidden" if resource.hidden?)
|
2
|
+
.media-container
|
3
|
+
label.expand-label
|
4
|
+
- if helper.multiple
|
5
|
+
input.modal-input.media-choice type="checkbox" value=resource.id checked=form.object.send(helper.field_id_name).include?(resource.id)
|
6
|
+
- else
|
7
|
+
= form.radio_button helper.field_id_name, resource.id, class: "modal-input media-choice"
|
8
|
+
|
9
|
+
span.media-link alt=resource.original_file_name
|
10
|
+
= resource.original_file_name
|
11
|
+
|
12
|
+
script.media-preview-template type="text/x-html-template"
|
13
|
+
= render "ds_media_library/image_preview", image: resource, preview: helper.preview do
|
14
|
+
- if helper.multiple
|
15
|
+
= form.check_box helper.field_id_name, { multiple: true, checked: true }, resource.id, nil
|
16
|
+
= form.check_box helper.remove_field_name, { multiple: true }, resource.id, nil
|
17
|
+
= form.label :"#{helper.remove_field_name}_#{resource.id}" do
|
18
|
+
span Remove #{helper.label.downcase.singularize} {{index}}
|
19
|
+
|
20
|
+
- else
|
21
|
+
- if helper.optional
|
22
|
+
= form.check_box helper.remove_field_name
|
23
|
+
= form.label helper.remove_field_name do
|
24
|
+
span Remove #{helper.label.downcase}
|
25
|
+
|
26
|
+
- helper.block.call(resource) if helper.block
|
27
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
li
|
2
|
+
input type="checkbox" class="expand-input" id="folder-#{folder.id}"
|
3
|
+
.media-container
|
4
|
+
label.expand-label.folder-link for="folder-#{folder.id}" = folder.name
|
5
|
+
.media-links
|
6
|
+
= link_to "Edit folder", [:edit, folder], class: "edit-icon", title: "Edit folder"
|
7
|
+
= link_to "Delete folder", folder, method: :delete, class: "delete-icon", title: "Delete folder",
|
8
|
+
data: { confirm: "Are you sure you want to delete this folder? This will move any folders and resources it may contain up into its parent folder." }
|
9
|
+
|
10
|
+
- if folder.children.any? || folder.resources.any?
|
11
|
+
ul.media-nest
|
12
|
+
= render collection: folder.children, partial: "ds_media_library/resources/folder"
|
13
|
+
= render collection: folder.resources, partial: "ds_media_library/resources/resource"
|
14
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
li.resource class=("hidden" if resource.hidden?)
|
2
|
+
.media-container
|
3
|
+
input.move-input type="checkbox" name="resource_ids[]" id="media-#{resource.id}" value=resource.id
|
4
|
+
label.expand-label for="media-#{resource.id}"
|
5
|
+
= link_to resource.original_file_name, edit_resource_path(resource), class: resource.css_class, alt: resource.original_file_name
|
6
|
+
/ span.move-span.media-link alt=resource.original_file_name = resource.original_file_name
|
7
|
+
|
8
|
+
.media-links
|
9
|
+
= link_to "Edit media", edit_resource_path(resource), class: "edit-icon", title: "Edit media"
|
10
|
+
= link_to "Delete media", resource_path(resource), method: :delete, class: "delete-icon", title: "Delete media",
|
11
|
+
data: { confirm: "Are you sure you want to delete this media item? Note that this will just remove it from the media library." }
|
12
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
= content_for :breadcrumbs do
|
2
|
+
ul.breadcrumb-nav
|
3
|
+
li = link_to "Media Library", :root
|
4
|
+
li
|
5
|
+
= folder.new_record? ? "New" : "Edit"
|
6
|
+
| folder
|
7
|
+
|
8
|
+
|
9
|
+
= form_for folder do |form|
|
10
|
+
fieldset
|
11
|
+
.field
|
12
|
+
= form.label :parent_id, "Parent folder", class: "optional"
|
13
|
+
= form.collection_select :parent_id, form.object.all_folders, :id, :name, include_blank: " -- none -- "
|
14
|
+
.field
|
15
|
+
= form.label :name, "Folder name"
|
16
|
+
= form.text_field :name, class: "name-input"
|
17
|
+
|
18
|
+
= render "shared/submit", name: "folder"
|
19
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
= content_for :breadcrumbs do
|
2
|
+
ul.breadcrumb-nav
|
3
|
+
li = link_to "Media Library", :root
|
4
|
+
li
|
5
|
+
= resource.new_record? ? "New" : "Edit"
|
6
|
+
| media
|
7
|
+
|
8
|
+
|
9
|
+
= form_for resource, url: resource.new_record? ? resources_path : resource_path(resource) do |form|
|
10
|
+
fieldset
|
11
|
+
.flex
|
12
|
+
.field
|
13
|
+
.field
|
14
|
+
= form.label :folder_id, "Parent folder", class: "optional"
|
15
|
+
= form.collection_select :folder_id, DSMediaLibrary::Folder.all, :id, :name, include_blank: " -- none -- "
|
16
|
+
|
17
|
+
-# FIXME extract to super project
|
18
|
+
- if form.object.respond_to?(:expires_at)
|
19
|
+
.field
|
20
|
+
= form.label :expires_at, "Expiration date", class: "optional"
|
21
|
+
= form.date_field :expires_at
|
22
|
+
.warning-text Expired media items will appear with a <i class="fa fa-exclamation-triangle"></i> icon in the media library and an email will be sent upon expiration as a reminder to update it.
|
23
|
+
|
24
|
+
.field
|
25
|
+
= form.label :file, "Upload media"
|
26
|
+
= form.file_field :file, multiple: resource.new_record?
|
27
|
+
- unless form.object.new_record?
|
28
|
+
= render "shared/image_preview", image: form.object
|
29
|
+
|
30
|
+
= render "shared/submit", name: "media"
|
31
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
= content_for :breadcrumbs do
|
2
|
+
ul.breadcrumb-nav
|
3
|
+
li Media Library
|
4
|
+
|
5
|
+
= form_tag nil, method: :put do
|
6
|
+
input type="checkbox" id="select-media"
|
7
|
+
.table-buttons-flex
|
8
|
+
.buttons-left
|
9
|
+
= link_to "Open all folders", "#", class: "open-all-label", data: { "toggle-all-checkboxes" => ".expand-input" }
|
10
|
+
label.select-media-button for="select-media" Select multiple media
|
11
|
+
.field.move-selected
|
12
|
+
label.move-selected-label for="folder_id" Move selected to:
|
13
|
+
select#folder_id name="folder_id"
|
14
|
+
- folders.each do |folder|
|
15
|
+
option value=folder.id
|
16
|
+
= "- " * folder.depth
|
17
|
+
= folder.name
|
18
|
+
button.move-button Move
|
19
|
+
|
20
|
+
.buttons-right
|
21
|
+
= link_to "Add new folder", [:new, :folder], class: "add-button"
|
22
|
+
= link_to "Add new media", [:new, :resource], class: "add-button"
|
23
|
+
|
24
|
+
input.text#search_media type="text" placeholder="Type keywords to search media (case sensitive)"
|
25
|
+
ul.media-nav
|
26
|
+
= render collection: root.children, partial: "ds_media_library/resources/folder"
|
27
|
+
= render collection: root.resources, partial: "ds_media_library/resources/resource"
|
28
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
- if !defined?(preview) then preview = true
|
2
|
+
|
3
|
+
- if image.present?
|
4
|
+
dfn.preview-form
|
5
|
+
.preview-wrapper
|
6
|
+
- if preview
|
7
|
+
- if image.video?
|
8
|
+
= video_tag image.url, controls: true
|
9
|
+
- else
|
10
|
+
= image_tag image.url
|
11
|
+
|
12
|
+
= yield
|
13
|
+
|
14
|
+
- unless defined?(hide_file_name) && hide_file_name
|
15
|
+
dt
|
16
|
+
figcaption = image.original_file_name
|
17
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ds_media_library"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/server
ADDED
data/bin/setup
ADDED