cmor_showcase 0.0.36.pre → 0.0.37.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5844e4b3ac6e9d5610f5b37b1351f200d224229989fd7f1275085d145beb94d4
4
- data.tar.gz: 3fd56fc8c7ef6c6817725d2a93dd48bb247ddc087193e0576d54ba971943a09d
3
+ metadata.gz: 973f667581372f211b2336ddc93f0e68ae71f06fa0f392cbfb3d0d97c1fe8126
4
+ data.tar.gz: 588b26d8a98887506ea7d660a1f9e1761f4927f806a1664fd0fe68e8c7d8a2b2
5
5
  SHA512:
6
- metadata.gz: 9115c59d2ae913904237b24f734b0d821aa1c339f176f745afd841a2217e14d74dd4c8bac31843b63e5ba1e3616e0816ee422af2ff41d26fe1d604d2009aaa7f
7
- data.tar.gz: b9c6cac32e8173a0978bc90d3bf4328d992ff8b357128d6a67c606ef626f8eed8493605f423fecb748e0973cfc7eb15cb75738fb5d1e44276a84b3d6b40dcb29
6
+ metadata.gz: fe0c975b96df6c6848ece2484fdf6cce92e3a51c5d6e694bea6df4018c206f6bdfd1067ec0528326ff1fefeed49fb1b0e28dfd155ed82ee890614a1cabd7a1c8
7
+ data.tar.gz: be4744898f605192ce5f422cd6425a8e194eead1e50354b35cab7c9b63bb2a888695d9badf119afca9cb22060ad93ba34c5313cd2b9e64b0a6607bd3fdc48f7d
@@ -2,6 +2,7 @@ module Cmor::Showcase
2
2
  class CategoriesController < Cmor::Core::Backend::ResourcesController::Base
3
3
  include Rao::ResourcesController::ActsAsListConcern
4
4
  include Rao::ResourcesController::ActsAsPublishedConcern
5
+ include Rao::ResourcesController::FriendlyIdConcern
5
6
 
6
7
  def self.resource_class
7
8
  Cmor::Showcase::Category
@@ -0,0 +1,29 @@
1
+ module Cmor::Showcase
2
+ class FileDetailsController < Cmor::Core::Backend::ResourcesController::Base
3
+ include Rao::ResourcesController::ActsAsListConcern
4
+ include Rao::ResourcesController::SortingConcern
5
+ include Rao::ResourcesController::BatchActionsConcern
6
+
7
+ def self.resource_class
8
+ Cmor::Showcase::FileDetail
9
+ end
10
+
11
+ def self.available_rest_actions
12
+ super - %i(new)
13
+ end
14
+
15
+ private
16
+
17
+ def after_reposition_location
18
+ last_location
19
+ end
20
+
21
+ def after_destroy_many_location
22
+ last_location
23
+ end
24
+
25
+ def permitted_params
26
+ params.require(:file_detail).permit(:title, :description)
27
+ end
28
+ end
29
+ end
@@ -2,6 +2,7 @@ module Cmor::Showcase
2
2
  class ItemsController < Cmor::Core::Backend::ResourcesController::Base
3
3
  include Rao::ResourcesController::ActsAsListConcern
4
4
  include Rao::ResourcesController::ActsAsPublishedConcern
5
+ include Rao::ResourcesController::FriendlyIdConcern
5
6
 
6
7
  def self.resource_class
7
8
  Cmor::Showcase::Item
@@ -9,8 +10,16 @@ module Cmor::Showcase
9
10
 
10
11
  private
11
12
 
13
+ def after_reposition_location
14
+ last_location # collection_path
15
+ end
16
+
17
+ def load_collection_scope
18
+ super.includes(:category)
19
+ end
20
+
12
21
  def permitted_params
13
- params.require(:item).permit(:category_id, :identifier, :name, :body, :published, assets: [])
22
+ params.require(:item).permit(:category_id, :identifier, :name, :body, :published, assets: [], append_assets: [], overwrite_assets: [])
14
23
  end
15
24
  end
16
25
  end
@@ -8,6 +8,10 @@ module Cmor::Showcase
8
8
  acts_as_list
9
9
  acts_as_published
10
10
 
11
+ # slugs
12
+ extend FriendlyId
13
+ friendly_id :name, use: :slugged
14
+
11
15
  validates :locale, presence: true
12
16
  validates :identifier, presence: true, uniqueness: true
13
17
  validates :name, presence: true, uniqueness: true
@@ -0,0 +1,9 @@
1
+ module Cmor::Showcase
2
+ class FileDetail < ApplicationRecord
3
+ belongs_to :item
4
+ belongs_to :asset, class_name: 'ActiveStorage::Attachment', dependent: :destroy
5
+
6
+ acts_as_list scope: :item
7
+ default_scope { order(position: :asc) }
8
+ end
9
+ end
@@ -9,6 +9,11 @@ module Cmor::Showcase
9
9
 
10
10
  acts_as_list scope: :category
11
11
  acts_as_published
12
+
13
+ # slugs
14
+ extend FriendlyId
15
+ friendly_id :name, use: :slugged
16
+
12
17
  acts_as_markup :body, Cmor::Core::Configuration.default_markup_options
13
18
 
14
19
  validates :name, presence: true, uniqueness: { scope: [ :category_id ] }
@@ -16,19 +21,71 @@ module Cmor::Showcase
16
21
  module PreviewPictureConcern
17
22
  extend ActiveSupport::Concern
18
23
 
19
- def images
20
- assets.joins(:blob).where("active_storage_blobs.content_type LIKE '%image/%'")
24
+ def preview_picture
25
+ file_details.images.first
21
26
  end
27
+ end
28
+
29
+ include PreviewPictureConcern
22
30
 
23
- def non_images
24
- assets.joins(:blob).where("active_storage_blobs.content_type NOT LIKE '%image/%'")
31
+ module FileDetailsConcern
32
+ extend ActiveSupport::Concern
33
+
34
+ included do
35
+ has_many :file_details, inverse_of: :item, dependent: :destroy, autosave: true do
36
+ def images
37
+ joins(asset: :blob).where("active_storage_blobs.content_type LIKE '%image/%'")
38
+ end
39
+
40
+ def non_images
41
+ joins(asset: :blob).where("active_storage_blobs.content_type NOT LIKE '%image/%'")
42
+ end
43
+ end
44
+ before_validation :cleanup_orphaned_file_details
45
+ before_validation :ensure_file_details
25
46
  end
26
47
 
27
- def preview_picture
28
- images.first
48
+ def append_assets
49
+ assets
50
+ end
51
+
52
+ def append_assets=(assets)
53
+ if Rails.version < '6.0.0'
54
+ self.assets = assets
55
+ else
56
+ self.assets.attach(assets)
57
+ end
58
+ end
59
+
60
+ def overwrite_assets
61
+ assets
62
+ end
63
+
64
+ def overwrite_assets=(assets)
65
+ return if assets.nil? || assets.empty?
66
+ self.file_details.map { |fd| fd.mark_for_destruction }
67
+ self.assets = assets
68
+ end
69
+
70
+ private
71
+
72
+ def cleanup_orphaned_file_details
73
+ file_details.each do |file_detail|
74
+ file_detail.destroy if file_detail.asset.nil?
75
+ end
76
+ end
77
+
78
+ def ensure_file_details
79
+ (assets - file_details.all.map(&:asset)).map do |asset|
80
+ build_file_detail_for_asset(asset)
81
+ end
82
+ end
83
+
84
+ def build_file_detail_for_asset(asset)
85
+ file_details.build(asset: asset)
29
86
  end
30
87
  end
31
88
 
32
- include PreviewPictureConcern
89
+ include FileDetailsConcern
33
90
  end
34
91
  end
@@ -0,0 +1,13 @@
1
+ = table.batch_actions( actions: { destroy: destroy_many_file_details_path })
2
+ = table.id
3
+ = table.column :filename do |resource|
4
+ - resource.asset.blob.filename
5
+ = table.column :blob_content_type do |resource|
6
+ - resource.asset.blob.content_type
7
+ = table.column :blob_byte_size do |resource|
8
+ - resource.asset.blob.byte_size
9
+ = table.column :blob_checksum do |resource|
10
+ - resource.asset.blob.checksum
11
+ = table.column :blob_created_at do |resource|
12
+ - I18n.l(resource.asset.blob.created_at, format: :short)
13
+ = table.timestamp :created_at
@@ -0,0 +1,2 @@
1
+ = form.input :title_cont
2
+ = form.input :name_cont, association: :item
@@ -0,0 +1,22 @@
1
+ %h2= Cmor::Showcase::FileDetail.model_name.human(count: :other)
2
+
3
+ = collection_table(collection: @resource.file_details, resource_class: Cmor::Showcase::FileDetail) do |table|
4
+ = table.acts_as_list_actions
5
+ = table.id
6
+ = table.thumbnail :asset
7
+ = table.column :title
8
+ = table.column :blob_filename do |resource|
9
+ - resource.asset.blob.filename
10
+ = table.column :blob_byte_size do |resource|
11
+ - number_to_human_size(resource.asset.blob.byte_size)
12
+ = table.column :blob_checksum do |resource|
13
+ - resource.asset.blob.checksum
14
+ = table.timestamps format: :short
15
+ = table.column :actions do |resource|
16
+ - capture_haml do
17
+ = link_to(main_app.url_for(resource.asset), class: 'btn btn-xs btn-responsive btn-primary') do
18
+ %i.fas.fa-download
19
+ %span.btn-text= t('.download')
20
+ = link_to([resource], id: "#{dom_id(resource)}-destroy", class: 'btn btn-xs btn-responsive btn-danger', method: :delete, data: { confirm: I18n.t('.confirmations.delete') }) do
21
+ %i.fas.fa-fire
22
+ %span.btn-text= t('.destroy')
@@ -3,4 +3,13 @@
3
3
  = form.input :name
4
4
  = form.input :body
5
5
  = form.input :published, as: :boolean
6
- = form.input :assets, as: :file, input_html: { multiple: true }
6
+ - if form.object.assets.empty?
7
+ = form.input :assets, as: :file, input_html: { multiple: true }
8
+ - else
9
+ .row.mb-4
10
+ .col-md-6
11
+ .bg-success.p-4
12
+ = form.input :append_assets, as: :file, input_html: { multiple: true }
13
+ .col-md-6
14
+ .bg-danger.p-4
15
+ = form.input :overwrite_assets, as: :file, input_html: { multiple: true }
@@ -1,7 +1,7 @@
1
1
  = table.acts_as_list_actions
2
2
  = table.thumbnail :preview_picture
3
- = table.association :category
4
- = table.column :identifier
5
- = table.column :name
6
- = table.timestamps
3
+ = table.column :category, as: :association, label_method: :human, sort: { column_name: 'cmor_showcase_categories.name' }
4
+ = table.column :identifier, sort: true
5
+ = table.column :name, sort: true
6
+ = table.timestamps sort: true
7
7
  = table.acts_as_published_actions
@@ -0,0 +1,6 @@
1
+ = table.association :category, label_method: :name, url: ->(r) { url_for(r) }
2
+ = table.row :identifier
3
+ = table.row :name
4
+ = table.row :description
5
+ = table.row :published
6
+ = table.timestamps
@@ -1,4 +1,4 @@
1
- = table.association :category
1
+ = table.association :category, label_method: :name, link_to: ->(r) { url_for(r.category) }
2
2
  = table.row :identifier
3
3
  = table.row :name
4
4
  = table.row :body
@@ -6,6 +6,9 @@ de:
6
6
  cmor/showcase/category:
7
7
  one: Kategorie
8
8
  other: Kategorien
9
+ cmor/showcase/file_detail:
10
+ one: Anhang
11
+ other: Anhänge
9
12
  cmor/showcase/item:
10
13
  one: Eintrag
11
14
  other: Einträge
@@ -18,11 +21,20 @@ de:
18
21
  position: Position
19
22
  published_at: Veröffentlicht am
20
23
  published: Veröffentlicht
24
+ slug: Slug
21
25
  updated_at: Aktualisiert am
22
26
  attributes:
23
27
  cmor/showcase/category:
24
28
  <<: *shared_attributes
25
29
  locale: Sprache
30
+ cmor/showcase/file_detail:
31
+ <<: *shared_attributes
32
+ description: Beschreibung
33
+ asset: Datei
34
+ asset_id: Datei
35
+ item: Eintrag
36
+ item_id: Eintrag
37
+ title: Titel
26
38
  cmor/showcase/item:
27
39
  <<: *shared_attributes
28
40
  category: Kategorie
@@ -6,6 +6,9 @@ en:
6
6
  cmor/showcase/category:
7
7
  one: Category
8
8
  other: Categories
9
+ cmor/showcase/file_detail:
10
+ one: File
11
+ other: Files
9
12
  cmor/showcase/item:
10
13
  one: Item
11
14
  other: Items
@@ -18,11 +21,20 @@ en:
18
21
  position: Position
19
22
  published_at: Published at
20
23
  published: Published
24
+ slug: Slug
21
25
  updated_at: Updated at
22
26
  attributes:
23
27
  cmor/showcase/category:
24
28
  <<: *shared_attributes
25
29
  locale: Locale
30
+ cmor/showcase/file_detail:
31
+ <<: *shared_attributes
32
+ description: Description
33
+ asset: Asset
34
+ asset_id: Asset
35
+ item: Item
36
+ item_id: Item
37
+ title: Title
26
38
  cmor/showcase/item:
27
39
  <<: *shared_attributes
28
40
  category: Category
data/config/routes.rb CHANGED
@@ -9,5 +9,10 @@ Cmor::Showcase::Engine.routes.draw do
9
9
  acts_as_list
10
10
  end
11
11
 
12
+ resources :file_details do
13
+ post :destroy_many, on: :collection
14
+ acts_as_list
15
+ end
16
+
12
17
  root to: 'home#index'
13
18
  end
@@ -7,8 +7,11 @@ class CreateCmorShowcaseCategories < ActiveRecord::Migration[5.2]
7
7
  t.text :body
8
8
  t.integer :position
9
9
  t.timestamp :published_at
10
+ t.string :slug
10
11
 
11
12
  t.timestamps
13
+
14
+ t.index :slug, unique: true
12
15
  end
13
16
  end
14
17
  end
@@ -7,8 +7,11 @@ class CreateCmorShowcaseItems < ActiveRecord::Migration[5.2]
7
7
  t.text :body
8
8
  t.integer :position
9
9
  t.timestamp :published_at
10
+ t.string :slug
10
11
 
11
12
  t.timestamps
13
+
14
+ t.index :slug, unique: true
12
15
  end
13
16
  end
14
17
  end
@@ -0,0 +1,13 @@
1
+ class CreateCmorShowcaseFileDetails < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :cmor_showcase_file_details do |t|
4
+ t.references :item, foreign_key: false
5
+ t.references :asset, foreign_key: false
6
+ t.string :title
7
+ t.text :description
8
+ t.integer :position
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
data/lib/cmor_showcase.rb CHANGED
@@ -2,6 +2,7 @@ require "cmor_core"
2
2
  require "cmor_core_backend"
3
3
  require "acts_as_published"
4
4
  require "acts_as_list"
5
+ require "friendly_id"
5
6
  require "markup-rails"
6
7
 
7
8
  require "cmor/showcase/version"
@@ -3,12 +3,14 @@ Cmor::Showcase.configure do |config|
3
3
  #
4
4
  # Default: config.resources_controllers = -> {[
5
5
  # Cmor::Showcase::CategoriesController,
6
- # Cmor::Showcase::ItemsController
6
+ # Cmor::Showcase::ItemsController,
7
+ # Cmor::Showcase::FileDetailsController
7
8
  # ]}
8
9
  #
9
10
  config.resources_controllers = -> {[
10
11
  Cmor::Showcase::CategoriesController,
11
- Cmor::Showcase::ItemsController
12
+ Cmor::Showcase::ItemsController,
13
+ Cmor::Showcase::FileDetailsController
12
14
  ]}
13
15
 
14
16
  # Set the resources, that will be shown in the backend menu.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmor_showcase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.36.pre
4
+ version: 0.0.37.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Vasquez Angel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-10 00:00:00.000000000 Z
11
+ date: 2019-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.36.pre
33
+ version: 0.0.37.pre
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.36.pre
40
+ version: 0.0.37.pre
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: cmor_core_backend
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.36.pre
47
+ version: 0.0.37.pre
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.36.pre
54
+ version: 0.0.37.pre
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -346,6 +346,20 @@ dependencies:
346
346
  - - ">="
347
347
  - !ruby/object:Gem::Version
348
348
  version: 0.0.2
349
+ - !ruby/object:Gem::Dependency
350
+ name: friendly_id
351
+ requirement: !ruby/object:Gem::Requirement
352
+ requirements:
353
+ - - ">="
354
+ - !ruby/object:Gem::Version
355
+ version: '0'
356
+ type: :runtime
357
+ prerelease: false
358
+ version_requirements: !ruby/object:Gem::Requirement
359
+ requirements:
360
+ - - ">="
361
+ - !ruby/object:Gem::Version
362
+ version: '0'
349
363
  - !ruby/object:Gem::Dependency
350
364
  name: bootsnap
351
365
  requirement: !ruby/object:Gem::Requirement
@@ -393,16 +407,22 @@ files:
393
407
  - app/assets/stylesheets/cmor_showcase.css
394
408
  - app/controllers/cmor/showcase/application_controller.rb
395
409
  - app/controllers/cmor/showcase/categories_controller.rb
410
+ - app/controllers/cmor/showcase/file_details_controller.rb
396
411
  - app/controllers/cmor/showcase/home_controller.rb
397
412
  - app/controllers/cmor/showcase/items_controller.rb
398
413
  - app/models/cmor/showcase/category.rb
414
+ - app/models/cmor/showcase/file_detail.rb
399
415
  - app/models/cmor/showcase/item.rb
400
416
  - app/view_helpers/cmor/showcase/application_view_helper.rb
401
417
  - app/views/cmor/showcase/categories/_form.html.haml
402
418
  - app/views/cmor/showcase/categories/_index_table.html.haml
403
419
  - app/views/cmor/showcase/categories/_show_table.html.haml
420
+ - app/views/cmor/showcase/file_details/_index_table.html.haml
421
+ - app/views/cmor/showcase/file_details/_query_form.html.haml
422
+ - app/views/cmor/showcase/items/_after_show_table.html.haml
404
423
  - app/views/cmor/showcase/items/_form.html.haml
405
424
  - app/views/cmor/showcase/items/_index_table.html.haml
425
+ - app/views/cmor/showcase/items/_show.html.haml
406
426
  - app/views/cmor/showcase/items/_show_table.html.haml
407
427
  - config/initializers/assets.rb
408
428
  - config/initializers/cmor.rb
@@ -411,6 +431,7 @@ files:
411
431
  - config/routes.rb
412
432
  - db/migrate/20190728095810_create_cmor_showcase_categories.rb
413
433
  - db/migrate/20190728100031_create_cmor_showcase_items.rb
434
+ - db/migrate/20190815224535_create_cmor_showcase_file_details.rb
414
435
  - lib/cmor/showcase/configuration.rb
415
436
  - lib/cmor/showcase/engine.rb
416
437
  - lib/cmor/showcase/version.rb
@@ -439,7 +460,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
439
460
  - !ruby/object:Gem::Version
440
461
  version: 1.3.1
441
462
  requirements: []
442
- rubygems_version: 3.0.4
463
+ rubygems_version: 3.0.6
443
464
  signing_key:
444
465
  specification_version: 4
445
466
  summary: Cmor::Showcase Module.