cmor_files 0.0.44.pre → 0.0.45.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: 80e5b0f66d42596ab3cbeb65a2234620c2eb9687a393a8643a87c6c7dfbdbbef
4
- data.tar.gz: f2d6d035c17968608701c28042bd3f4b7e7cf1b519a0b55619d736841b50b854
3
+ metadata.gz: b08c90107f4559820ba2de578b1dc456dbb1c0042918320783b67ba09fff0150
4
+ data.tar.gz: adf30c1245020a09e6b7b2522270e50c4885a6b92394dab9731c5edf9ca6facf
5
5
  SHA512:
6
- metadata.gz: 9d90e43c2f7b2dd77e9bbd1626099eb08093f054cb73f2402af03d3c56f7a5b61848e6c47c94b34334f3bd750658e24634dd10e1cf8eaf245920ce135b1dd6f2
7
- data.tar.gz: 44f21849068752cc5d98c7f86299c95a5219ad930393119a103a244dab3ef8c25b563f271c3d6a59566fb1f89d3cb5e63e93ae1ccd99a812301be0781197476f
6
+ metadata.gz: 49d230e14bb39f86c71a78682d80bd02d8d00ded2dfe79c71a6d20aa8830f70477214dea559ebf2765250ec570b0ab1dcd18fa6b23f2072bfbb7db00892b1955
7
+ data.tar.gz: 664eb643669118ecb906216ef0819cf071e5607bcadf6ad1685674d6133931e70aab5379747385fa9d1462e740b42b3ee3f20586e119b2d8ba22234f121ee5c8
@@ -0,0 +1,21 @@
1
+ module Cmor::Files
2
+ class FileDetailsController < ApplicationResourcesController
3
+ include Rao::ResourcesController::FriendlyIdConcern
4
+
5
+ helper Rao::Component::ApplicationHelper
6
+
7
+ def self.resource_class
8
+ Cmor::Files::FileDetail
9
+ end
10
+
11
+ private
12
+
13
+ def load_collection_scope
14
+ super.published
15
+ end
16
+
17
+ def load_resource_scope
18
+ super.published
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,7 @@
1
1
  module Cmor::Files
2
2
  class FoldersController < ApplicationResourcesController
3
+ include Rao::ResourcesController::FriendlyIdConcern
4
+
3
5
  helper Rao::Component::ApplicationHelper
4
6
 
5
7
  def self.resource_class
@@ -2,5 +2,19 @@ module Cmor::Files
2
2
  class FileDetail < ApplicationRecord
3
3
  belongs_to :folder
4
4
  belongs_to :asset, class_name: 'ActiveStorage::Attachment', dependent: :destroy
5
+
6
+ # acts as published
7
+ include ActsAsPublished::ActiveRecord
8
+ acts_as_published
9
+
10
+ # acts as list
11
+ acts_as_list scope: :folder
12
+ default_scope { order(folder_id: :desc, position: :asc) }
13
+
14
+ # slugs
15
+ extend FriendlyId
16
+ friendly_id :title, use: :slugged
17
+
18
+ validates :identifier, uniqueness: { scope: [ :folder_id ] }, allow_blank: true, allow_nil: true
5
19
  end
6
20
  end
@@ -1,71 +1,85 @@
1
- module Cmor::Files
2
- class Folder < ApplicationRecord
3
- include ActsAsPublished::ActiveRecord
1
+ module Cmor
2
+ module Files
3
+ class Folder < ApplicationRecord
4
+ include Cmor::Core::Model::LocalizationConcern
4
5
 
5
- has_many_attached :assets
6
+ has_many_attached :assets
6
7
 
7
- acts_as_published
8
+ # acts as published
9
+ include ActsAsPublished::ActiveRecord
10
+ acts_as_published
8
11
 
9
- validates :name, presence: true, uniqueness: true
12
+ # acts as list
13
+ acts_as_list
14
+ default_scope { order(position: :asc) }
10
15
 
11
- def human
12
- "#{self.class.model_name.human}: #{I18n.l(created_at)}"
13
- end
16
+ # slugs
17
+ extend FriendlyId
18
+ friendly_id :name, use: :slugged
14
19
 
15
- def assets_count
16
- assets.count
17
- end
18
20
 
19
- module FileDetailsConcern
20
- extend ActiveSupport::Concern
21
+ validates :name, presence: true, uniqueness: { scope: [ :locale ] }
22
+ validates :identifier, uniqueness: { scope: [ :locale ] }, allow_nil: true, allow_blank: true
21
23
 
22
- included do
23
- has_many :file_details, inverse_of: :folder, dependent: :destroy, autosave: true
24
- before_validation :cleanup_orphaned_file_details
25
- before_validation :ensure_file_details
24
+ def human
25
+ "#{self.class.model_name.human}: #{self.name}"
26
26
  end
27
27
 
28
- def append_assets
29
- assets
28
+ def assets_count
29
+ assets.count
30
30
  end
31
31
 
32
- def append_assets=(assets)
33
- if Rails.version < '6.0.0'
34
- self.assets = assets
35
- else
36
- self.assets.attach(assets)
32
+ module FileDetailsConcern
33
+ extend ActiveSupport::Concern
34
+
35
+ included do
36
+ has_many :file_details, inverse_of: :folder, dependent: :destroy, autosave: true
37
+ before_validation :cleanup_orphaned_file_details
38
+ before_validation :ensure_file_details
39
+ end
40
+
41
+ def append_assets
42
+ assets
43
+ end
44
+
45
+ def append_assets=(assets)
46
+ if Rails.version < '6.0.0'
47
+ self.assets = assets
48
+ else
49
+ self.assets.attach(assets)
50
+ end
37
51
  end
52
+
53
+ def overwrite_assets
54
+ assets
38
55
  end
39
56
 
40
- def overwrite_assets
41
- assets
42
- end
57
+ def overwrite_assets=(assets)
58
+ return if assets.nil? || assets.empty?
59
+ self.file_details.map { |fd| fd.mark_for_destruction }
60
+ self.assets = assets
61
+ end
43
62
 
44
- def overwrite_assets=(assets)
45
- return if assets.nil? || assets.empty?
46
- self.file_details.map { |fd| fd.mark_for_destruction }
47
- self.assets = assets
48
- end
63
+ private
49
64
 
50
- private
65
+ def cleanup_orphaned_file_details
66
+ file_details.each do |file_detail|
67
+ file_detail.destroy if file_detail.asset.nil?
68
+ end
69
+ end
51
70
 
52
- def cleanup_orphaned_file_details
53
- file_details.each do |file_detail|
54
- file_detail.destroy if file_detail.asset.nil?
71
+ def ensure_file_details
72
+ (assets - file_details.all.map(&:asset)).map do |asset|
73
+ build_file_detail_for_asset(asset)
74
+ end
55
75
  end
56
- end
57
76
 
58
- def ensure_file_details
59
- (assets - file_details.all.map(&:asset)).map do |asset|
60
- build_file_detail_for_asset(asset)
77
+ def build_file_detail_for_asset(asset)
78
+ file_details.build(asset: asset)
61
79
  end
62
80
  end
63
81
 
64
- def build_file_detail_for_asset(asset)
65
- file_details.build(asset: asset)
66
- end
82
+ include FileDetailsConcern
67
83
  end
68
-
69
- include FileDetailsConcern
70
84
  end
71
85
  end
@@ -0,0 +1,22 @@
1
+ module Cmor
2
+ module Files
3
+ # Example:
4
+ #
5
+ # # app/controllers/application_controller.rb
6
+ # class ApplicationController < ActionController::Base
7
+ # view_helper Cmor::Files::ApplicationViewHelper, as: :files_helper
8
+ # end
9
+ #
10
+ class ApplicationViewHelper < Rao::ViewHelper::Base
11
+ # Example:
12
+ #
13
+ # # app/views/layouts/application.html.haml
14
+ # = files_helper(self).render_download(name: 'Quick reference manual')
15
+ #
16
+ def render_file(identifier:)
17
+ resource = Cmor::Files::FileDetail.where(identifier: identifier).first
18
+ render resource: resource
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ .cmor-files-file_detail
2
+ %h4.title= resource.title
3
+
4
+ %p.description= resource.description
5
+
6
+ .resource-actions
7
+ = link_to(main_app.url_for(resource.asset), class: 'btn btn-primary') do
8
+ = "#{t('.download')} (#{resource.asset.content_type.split('/').last}, #{number_to_human_size(resource.asset.blob.byte_size)})"
@@ -0,0 +1,12 @@
1
+ %h1= resource_class.model_name.human(count: :other)
2
+
3
+ .row
4
+ .col-12
5
+ = collection_table(collection: @collection, resource_class: resource_class) do |table|
6
+ = table.column :filename do |resource|
7
+ - resource.asset.blob.filename
8
+ = table.column :blob_byte_size do |resource|
9
+ - number_to_human_size(resource.asset.blob.byte_size)
10
+ = table.column :actions do |resource|
11
+ - capture_haml do
12
+ = link_to(t('.download'), main_app.url_for(resource.asset), class: 'btn btn-primary')
@@ -0,0 +1,17 @@
1
+ %h1= @resource.title
2
+
3
+ .row
4
+ .col-12
5
+ = resource_table(resource: @resource, resource_class: Cmor::Files::FileDetail, header: false) do |table|
6
+ = table.row :filename do |resource|
7
+ - resource.asset.blob.filename
8
+ = table.row :blob_byte_size do |resource|
9
+ - number_to_human_size(resource.asset.blob.byte_size)
10
+ = table.row :actions do |resource|
11
+ - capture_haml do
12
+ = link_to(t('.download'), main_app.url_for(resource.asset), class: 'btn btn-primary')
13
+
14
+
15
+ .row.mt-4
16
+ .col-12
17
+ = link_to(t('.back'), last_location, class: 'btn btn-primary')
@@ -2,14 +2,14 @@
2
2
 
3
3
  .row
4
4
  .col-12
5
- = collection_table(collection: @resource.assets, resource_class: ActiveStorage::Attachment, header: false) do |table|
5
+ = collection_table(collection: @resource.file_details, resource_class: Cmor::Files::FileDetail, header: false) do |table|
6
6
  = table.column :filename do |resource|
7
- - resource.blob.filename
7
+ - resource.asset.blob.filename
8
8
  = table.column :blob_byte_size do |resource|
9
- - number_to_human_size(resource.blob.byte_size)
9
+ - number_to_human_size(resource.asset.blob.byte_size)
10
10
  = table.column :actions do |resource|
11
11
  - capture_haml do
12
- = link_to(t('.download'), main_app.url_for(resource), class: 'btn btn-primary')
12
+ = link_to(t('.download'), main_app.url_for(resource.asset), class: 'btn btn-primary')
13
13
 
14
14
 
15
15
  .row.mt-4
@@ -3,6 +3,7 @@ de:
3
3
  cmor/files/engine: Dateien
4
4
  routes:
5
5
  cmor_files_engine: dateien
6
+ file_details: dateien
6
7
  folders: ordner
7
8
  activerecord:
8
9
  models:
@@ -15,30 +16,44 @@ de:
15
16
  attributes:
16
17
  cmor/files/file_detail:
17
18
  id: ID
19
+ asset: Datei
20
+ asset_id: Datei
18
21
  blob_byte_size: Dateigröße
19
22
  blob_checksum: Checksumme
20
23
  blob_filename: Dateiname
24
+ description: Beschreibung
21
25
  folder: Ordner
22
26
  folder_id: Ordner
23
- asset: Datei
24
- asset_id: Datei
25
- title: Titel
26
- description: Beschreibung
27
+ identifier: Bezeichner
27
28
  position: Position
29
+ published: Veröffentlicht
30
+ published_at: Veröffentlicht am
31
+ slug: Freundliche ID
32
+ title: Titel
28
33
  created_at: Erstellt am
29
34
  updated_at: Aktualisiert am
30
35
  cmor/files/folder:
31
36
  id: ID
32
- name: Name
33
- description: Beschreibung
34
37
  assets: Dateien
35
38
  assets_count: Dateien
36
- published_at: Veröffentlicht am
39
+ description: Beschreibung
40
+ identifier: Bezeichner
41
+ locale: Sprache
42
+ name: Name
43
+ position: Position
37
44
  published: Veröffentlicht
45
+ published_at: Veröffentlicht am
46
+ slug: Freundliche ID
38
47
  created_at: Erstellt am
39
48
  updated_at: Aktualisiert am
40
49
  cmor:
41
50
  files:
51
+ application_view_helper:
52
+ render_file:
53
+ download: Herunterladen
54
+ file_details:
55
+ show:
56
+ back: Zurück
42
57
  folders:
43
58
  index:
44
59
  show: Anzeigen
@@ -3,6 +3,7 @@ en:
3
3
  cmor/files/engine: Files
4
4
  routes:
5
5
  cmor_files_engine: files
6
+ file_details: files
6
7
  folders: folders
7
8
  activerecord:
8
9
  models:
@@ -15,30 +16,44 @@ en:
15
16
  attributes:
16
17
  cmor/files/file_detail:
17
18
  id: ID
19
+ asset: Asset
20
+ asset_id: Asset
18
21
  blob_byte_size: Filesize
19
22
  blob_checksum: Checksum
20
23
  blob_filename: Filename
24
+ description: Description
21
25
  folder: Folder
22
26
  folder_id: Folder
23
- asset: Asset
24
- asset_id: Asset
25
- title: Title
26
- description: Description
27
+ identifier: Identifier
27
28
  position: Position
29
+ published: Published
30
+ published_at: Published at
31
+ slug: Friendly ID
32
+ title: Title
28
33
  created_at: Created at
29
34
  updated_at: Updated at
30
35
  cmor/files/folder:
31
36
  id: ID
32
- name: Name
33
- description: Description
34
37
  assets: Files
35
38
  assets_count: Files
36
- published_at: Published at
39
+ description: Description
40
+ identifier: Identifier
41
+ locale: Locale
42
+ name: Name
43
+ position: Position
37
44
  published: Published
45
+ published_at: Published at
46
+ slug: Friendly ID
38
47
  created_at: Created at
39
48
  updated_at: Updated at
40
49
  cmor:
41
50
  files:
51
+ application_view_helper:
52
+ render_file:
53
+ download: Download
54
+ file_details:
55
+ show:
56
+ back: Back
42
57
  folders:
43
58
  index:
44
59
  show: Show
@@ -1,7 +1,8 @@
1
1
  Cmor::Files::Engine.routes.draw do
2
2
  localized do
3
3
  scope :cmor_files_engine do
4
- resources :folders
4
+ resources :folders, only: [ :index, :show ]
5
+ resources :file_details, only: [ :index, :show ]
5
6
 
6
7
  root to: 'folders#index'
7
8
  end
@@ -0,0 +1,5 @@
1
+ class AddIdentifierToCmorFilesFolders < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :cmor_files_folders, :identifier, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddSlugToCmorFilesFolders < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :cmor_files_folders, :slug, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddPositionToCmorFilesFolders < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :cmor_files_folders, :position, :integer
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddLocaleToCmorFilesFolders < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :cmor_files_folders, :locale, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddIdentifierToCmorFilesFileDetails < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :cmor_files_file_details, :identifier, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddSlugToCmorFilesFileDetails < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :cmor_files_file_details, :slug, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddPublishedAtToCmorFilesFileDetails < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :cmor_files_file_details, :published_at, :timestamp
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ class SetAllCmorFilesPublishableToPublished < ActiveRecord::Migration[5.2]
2
+ def self.up
3
+ ActiveRecord::Base.transaction do
4
+ [
5
+ Cmor::Files::FileDetail
6
+ ].each do |klass|
7
+ klass.update_all(published_at: Time.zone.now)
8
+ end
9
+ end
10
+ end
11
+
12
+ def down.up
13
+ ActiveRecord::Base.transaction do
14
+ [
15
+ Cmor::Files::FileDetail
16
+ ].each do |klass|
17
+ klass.update_all(published_at: nil)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,9 @@
1
1
  require 'cmor_core_frontend'
2
2
  require 'acts_as_published'
3
+ require 'acts_as_list'
4
+ require 'friendly_id'
3
5
  require 'rao-resources_controller'
4
6
  require 'rao-component'
5
7
 
8
+ require 'cmor/core/model/localization_concern'
6
9
  require "cmor/files"
@@ -1,5 +1,6 @@
1
1
  FactoryBot.define do
2
2
  factory :cmor_files_folder, class: 'Cmor::Files::Folder' do
3
3
  sequence(:name) { |i| "Folder ##{i}" }
4
+ sequence(:identifier) { |i| "folder-#{i}" }
4
5
  end
5
6
  end
@@ -7,6 +7,6 @@ module Cmor::Files
7
7
  it { expect(subject).to respond_to(:assets_count) }
8
8
 
9
9
  it { expect(subject).to validate_presence_of(:name) }
10
- it { expect(subject).to validate_uniqueness_of(:name) }
10
+ it { expect(subject).to validate_uniqueness_of(:name).scoped_to([:locale]) }
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmor_files
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.44.pre
4
+ version: 0.0.45.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: 2020-01-29 00:00:00.000000000 Z
11
+ date: 2020-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.0
19
+ version: 5.2.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.2.0
26
+ version: 5.2.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: cmor_core
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.44.pre
33
+ version: 0.0.45.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.44.pre
40
+ version: 0.0.45.pre
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: cmor_core_frontend
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.44.pre
47
+ version: 0.0.45.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.44.pre
54
+ version: 0.0.45.pre
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -318,6 +318,34 @@ dependencies:
318
318
  - - ">="
319
319
  - !ruby/object:Gem::Version
320
320
  version: '0'
321
+ - !ruby/object:Gem::Dependency
322
+ name: acts_as_list
323
+ requirement: !ruby/object:Gem::Requirement
324
+ requirements:
325
+ - - ">="
326
+ - !ruby/object:Gem::Version
327
+ version: '0'
328
+ type: :runtime
329
+ prerelease: false
330
+ version_requirements: !ruby/object:Gem::Requirement
331
+ requirements:
332
+ - - ">="
333
+ - !ruby/object:Gem::Version
334
+ version: '0'
335
+ - !ruby/object:Gem::Dependency
336
+ name: friendly_id
337
+ requirement: !ruby/object:Gem::Requirement
338
+ requirements:
339
+ - - ">="
340
+ - !ruby/object:Gem::Version
341
+ version: '0'
342
+ type: :runtime
343
+ prerelease: false
344
+ version_requirements: !ruby/object:Gem::Requirement
345
+ requirements:
346
+ - - ">="
347
+ - !ruby/object:Gem::Version
348
+ version: '0'
321
349
  - !ruby/object:Gem::Dependency
322
350
  name: rao-resources_controller
323
351
  requirement: !ruby/object:Gem::Requirement
@@ -363,6 +391,7 @@ files:
363
391
  - app/assets/stylesheets/cmor/files/application/keep.css
364
392
  - app/controllers/cmor/files/application_controller.rb~
365
393
  - app/controllers/cmor/files/application_resources_controller.rb
394
+ - app/controllers/cmor/files/file_details_controller.rb
366
395
  - app/controllers/cmor/files/folders_controller.rb
367
396
  - app/helpers/cmor/files/application_helper.rb
368
397
  - app/jobs/cmor/files/application_job.rb
@@ -370,16 +399,27 @@ files:
370
399
  - app/models/cmor/files/application_record.rb
371
400
  - app/models/cmor/files/file_detail.rb
372
401
  - app/models/cmor/files/folder.rb
402
+ - app/view_helpers/cmor/files/application_view_helper.rb
403
+ - app/views/cmor/files/application_view_helper/_render_file.html.haml
404
+ - app/views/cmor/files/file_details/index.html.haml
405
+ - app/views/cmor/files/file_details/show.html.haml
373
406
  - app/views/cmor/files/folders/index.html.haml
374
407
  - app/views/cmor/files/folders/show.html.haml
375
408
  - app/views/layouts/cmor/files/application.html.erb
376
409
  - config/initializers/assets.rb
377
- - config/initializers/i18n.rb
378
410
  - config/locales/de.yml
379
411
  - config/locales/en.yml
380
412
  - config/routes.rb
381
413
  - db/migrate/20180301094240_create_cmor_files_folders.rb
382
414
  - db/migrate/20180302082402_create_cmor_files_file_details.rb
415
+ - db/migrate/20200216141542_add_identifier_to_cmor_files_folders.rb
416
+ - db/migrate/20200216141614_add_slug_to_cmor_files_folders.rb
417
+ - db/migrate/20200216141650_add_position_to_cmor_files_folders.rb
418
+ - db/migrate/20200216142054_add_locale_to_cmor_files_folders.rb
419
+ - db/migrate/20200216164748_add_identifier_to_cmor_files_file_details.rb
420
+ - db/migrate/20200217133512_add_slug_to_cmor_files_file_details.rb
421
+ - db/migrate/20200217141730_add_published_at_to_cmor_files_file_details.rb
422
+ - db/migrate/20200301154948_set_all_cmor_files_publishable_to_published.rb
383
423
  - lib/cmor/files.rb
384
424
  - lib/cmor/files/configuration.rb
385
425
  - lib/cmor/files/engine.rb
@@ -1,2 +0,0 @@
1
- Rails.application.config.i18n.available_locales = [:en, :de]
2
- Rails.application.config.i18n.default_locale = :de