udongo 5.3.1 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d86f45348cbaf7e17874b28d0ed6127723114c69
4
- data.tar.gz: 3720785fb4413c8da1e76fa990405c3c4023edc1
3
+ metadata.gz: 75a5407f853e677bc244654a801843f1b9663805
4
+ data.tar.gz: e3a9c0edbb2798d44ad7bd5fe934ee2c2826d5be
5
5
  SHA512:
6
- metadata.gz: c890e82171a21337cf9fb70840042609383a69f3e2b14b4038b4655949ca41eb52d81fc261e7bb570467d3586b25213dac2661f9d685cb258126500f0aec5bc8
7
- data.tar.gz: 9e1499743c8b7692e17fe11fc51d7470319eb86a0f251ea12214a4fea855b0b97707c5e5415e3fceb3287b21cbfcf17eeaf4dc2c91268154cb09b8d92bfffebd
6
+ metadata.gz: 4bc1535a00eded6212d6c39e0d0293ad7c28f99ac6809ec248f4bdf725d97a0d526711a65e2a4d80f5c065b3fcf026cb832e8c02faa4bc4e1c8f79edbf20b1e6
7
+ data.tar.gz: 3266aceac326318a4f86fd648f6b51e9c4f1f445b7e889fae6cb4e0d9c660a40b0202f08e61d89f8cc0b2400bba0fa0eca11d0a47b5d8c951038e308321f0d46
@@ -26,7 +26,7 @@ var sortable = sortable || {
26
26
  },
27
27
 
28
28
  update_position_listener: function(e, ui) {
29
- var new_position = ui.item.index() + 1
29
+ var new_position = ui.item.index() + 1;
30
30
 
31
31
  $.ajax({
32
32
  data: { position: new_position },
@@ -0,0 +1,11 @@
1
+ class Backend::Articles::BaseController < Backend::BaseController
2
+ before_action :find_article
3
+ before_action do
4
+ breadcrumb.add t('b.articles'), backend_articles_path
5
+ breadcrumb.add @article.title
6
+ end
7
+
8
+ def find_article
9
+ @article = Article.find params[:article_id]
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ class Backend::Articles::ImagesController < Backend::Articles::BaseController
2
+ include Concerns::Backend::PositionableController
3
+
4
+ before_action { breadcrumb.add t('b.images') }
5
+
6
+ def index
7
+ @images = @article.images
8
+ end
9
+
10
+ private
11
+
12
+ def find_model
13
+ @model = @article.images.find params[:id]
14
+ end
15
+ end
@@ -0,0 +1,56 @@
1
+ class Backend::ImagesController < Backend::BaseController
2
+ before_action :find_model
3
+ before_action :init_image, only: [:index, :new, :create]
4
+ layout 'backend/lightbox'
5
+
6
+ def index
7
+ @search = Asset.ransack params[:q]
8
+ @assets = @search.result(distinct: true).image.where.not(id: @model.images.pluck(:asset_id)).order('id DESC')
9
+ end
10
+
11
+ def create
12
+ @image.build_asset
13
+ @image.asset.filename = params[:image][:asset][:filename]
14
+ @image.asset.description = params[:image][:asset][:description]
15
+
16
+ if @image.asset.filename && @image.asset.filename.content_type.to_s.include?('image') && @image.save
17
+ redirect_images_overview(:added)
18
+ else
19
+ @image.errors.add :filename, 'Ignore me'
20
+ render :new
21
+ end
22
+ end
23
+
24
+ def link
25
+ @model.images.create(asset: Asset.find(params[:asset_id]))
26
+ redirect_images_overview(:added)
27
+ end
28
+
29
+ def unlink
30
+ @model.images.find_by(asset_id: params[:asset_id]).destroy
31
+ redirect_images_overview(:deleted)
32
+ end
33
+
34
+ private
35
+
36
+ def find_model
37
+ begin
38
+ @model ||= params[:klass].constantize.find params[:id]
39
+ rescue
40
+ redirect_to backend_path
41
+ end
42
+ end
43
+
44
+ def allowed_params
45
+ params[:image].permit(asset_attributes: [:filename, :description])
46
+ end
47
+
48
+ def redirect_images_overview(action)
49
+ redirect_to send("backend_#{@model.class.name.underscore}_images_path", @model),
50
+ notice: translate_notice(action, :image)
51
+ end
52
+
53
+ def init_image
54
+ @image = @model.images.new
55
+ end
56
+ end
@@ -5,6 +5,7 @@ class Article < ApplicationRecord
5
5
  include Concerns::FlexibleContent
6
6
  include Concerns::Searchable
7
7
  include Concerns::Publishable
8
+ include Concerns::Imageable
8
9
 
9
10
  include Concerns::Translatable
10
11
  translatable_fields :title, :summary
data/app/models/asset.rb CHANGED
@@ -5,6 +5,8 @@ class Asset < ApplicationRecord
5
5
 
6
6
  has_many :images, dependent: :destroy
7
7
 
8
+ scope :image, -> { where(content_type: %w(image/gif image/jpeg image/png)) }
9
+
8
10
  before_save :update_filesize, :update_content_type
9
11
 
10
12
  validates :filename, presence: true
@@ -5,8 +5,8 @@ module Concerns
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- scope :visible, ->{ where(visible: true) }
9
- scope :hidden, ->{ where('visible = 0 OR visible IS NULL') }
8
+ scope :visible, -> { where(visible: true) }
9
+ scope :hidden, -> { where('visible = 0 OR visible IS NULL') }
10
10
  end
11
11
 
12
12
  def hidden?
@@ -12,13 +12,13 @@ class ContentColumn < ApplicationRecord
12
12
  belongs_to :row, class_name: 'ContentRow', touch: true
13
13
  belongs_to :content, polymorphic: true, dependent: :destroy
14
14
 
15
+ default_scope -> { order(:position) }
16
+
15
17
  validates :row, presence: true
16
18
  validates :width_xs, :width_sm, :width_md, :width_lg, :width_xl,
17
19
  presence: true,
18
20
  numericality: { greater_than: 0, less_than_or_equal_to: 12, only_integer: true }
19
21
 
20
- default_scope -> { order(:position) }
21
-
22
22
  def linked_to_searchable_parent?
23
23
  parent.present? && parent.searchable?
24
24
  end
data/app/models/image.rb CHANGED
@@ -2,7 +2,7 @@ class Image < ApplicationRecord
2
2
  include Concerns::Visible
3
3
 
4
4
  include Concerns::Sortable
5
- sortable scope: [:asset_id]
5
+ sortable scope: [:imageable_id]
6
6
 
7
7
  belongs_to :asset
8
8
  belongs_to :imageable, polymorphic: true
data/app/models/note.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Note < ApplicationRecord
2
2
  belongs_to :notable, polymorphic: true
3
3
 
4
- validates :content, presence: true
5
-
6
4
  default_scope { order('created_at DESC') }
5
+
6
+ validates :content, presence: true
7
7
  end
@@ -1,11 +1,11 @@
1
1
  class QueuedTask < ApplicationRecord
2
- validates :klass, presence: true
3
-
4
2
  serialize :data, Hash
5
3
 
6
4
  scope :locked, -> { where(locked: true) }
7
5
  scope :not_locked, -> { where('locked = 0 OR locked IS NULL') }
8
6
 
7
+ validates :klass, presence: true
8
+
9
9
  def lock!
10
10
  update_attribute :locked, true
11
11
  end
@@ -1,10 +1,10 @@
1
1
  class Redirect < ApplicationRecord
2
- validates :source_uri, :destination_uri, :status_code, presence: true
3
- validates :source_uri, uniqueness: { case_sensitive: false }
4
-
5
2
  scope :disabled, -> { where(disabled: true) }
6
3
  scope :enabled, -> { where('disabled IS NULL or disabled = 0') }
7
4
 
5
+ validates :source_uri, :destination_uri, :status_code, presence: true
6
+ validates :source_uri, uniqueness: { case_sensitive: false }
7
+
8
8
  def enabled?
9
9
  !disabled?
10
10
  end
@@ -1,8 +1,8 @@
1
1
  class SearchModule < ApplicationRecord
2
- validates :name, presence: true
3
-
4
2
  scope :weighted, -> { order('weight DESC') }
5
3
 
4
+ validates :name, presence: true
5
+
6
6
  def indices
7
7
  SearchIndex.joins('INNER JOIN search_modules ON search_indices.searchable_type = search_modules.name')
8
8
  .where('search_modules.name = ?', name)
@@ -1,5 +1,4 @@
1
1
  class SearchSynonym < ApplicationRecord
2
2
  validates :locale, :term, :synonyms, presence: true
3
-
4
3
  validates :term, uniqueness: { case_sensitive: false, scope: :locale }
5
4
  end
@@ -5,7 +5,7 @@
5
5
  <% klass = %w(nav-link) %>
6
6
  <% klass << 'active' if active == :general %>
7
7
 
8
- <%= link_to t('b.general'), edit_backend_article_path(@model), class: klass %>
8
+ <%= link_to t('b.general'), edit_backend_article_path(model), class: klass %>
9
9
  </li>
10
10
 
11
11
  <% Udongo.config.i18n.app.locales.each do |locale| %>
@@ -13,11 +13,17 @@
13
13
  <% klass = %w(nav-link) %>
14
14
  <% klass << 'active' if active == locale.to_sym %>
15
15
 
16
- <%= link_to locale.upcase, edit_translation_backend_article_path(@model, locale), class: klass %>
16
+ <%= link_to locale.upcase, edit_translation_backend_article_path(model, locale), class: klass %>
17
17
  </li>
18
18
  <% end %>
19
19
 
20
- <!-- TODO show the images tab if Udongo.config.articles.images? -->
20
+ <% if Udongo.config.articles.images? %>
21
+ <li class="nav-item">
22
+ <% klass = %w(nav-link) %>
23
+ <% klass << 'active' if active == :images %>
24
+ <%= link_to icon(:image, t('b.images')), backend_article_images_path(model), class: klass %>
25
+ </li>
26
+ <% end %>
21
27
  </ul>
22
28
  </div>
23
29
  </div>
@@ -2,5 +2,5 @@
2
2
  <% breadcrumb.add t('b.edit') %>
3
3
  <%= render 'backend/breadcrumbs' %>
4
4
 
5
- <%= render 'tabs', active: :general %>
5
+ <%= render 'tabs', model: @model, active: :general %>
6
6
  <%= render 'form', model: @model %>
@@ -2,7 +2,7 @@
2
2
  <% breadcrumb.add t('b.edit') %>
3
3
  <%= render 'backend/breadcrumbs' %>
4
4
 
5
- <%= render 'tabs', active: params[:translation_locale].to_sym %>
5
+ <%= render 'tabs', model: @model, active: params[:translation_locale].to_sym %>
6
6
  <%= render 'backend/general_form_error', object: @translation %>
7
7
 
8
8
  <%= simple_form_for([:backend, @translation], url: edit_translation_backend_article_path, html: { class: 'no-focus' }) do |f| %>
@@ -0,0 +1,43 @@
1
+ <% javascript 'backend/sortable' %>
2
+ <%= render 'backend/breadcrumbs' %>
3
+ <%= render 'backend/articles/tabs', model: @article, active: :images %>
4
+
5
+ <p class="text-xs-right">
6
+ <%= link_to icon(:plus, t('b.add')), backend_images_path(klass: @article.class.name, id: @article.id), class: 'btn btn-primary btn-sm' %>
7
+ </p>
8
+
9
+ <% if @images.any? %>
10
+ <table class="table table-striped table-hover">
11
+ <thead class="thead-inverse">
12
+ <tr>
13
+ <th><%= t 'b.file' %></th>
14
+ <th><%= t 'g.type' %></th>
15
+ <th><%= t 'b.size' %></th>
16
+ <th><%= t 'b.description' %></th>
17
+ <th><%= t 'b.last_changed_at' %></th>
18
+ <th>&nbsp;</th>
19
+ </tr>
20
+ </thead>
21
+
22
+ <tbody>
23
+ <% @images.each do |img| %>
24
+ <% a = img.asset %>
25
+ <tr data-update-position="<%= update_position_backend_article_image_path(@article, img) %>">
26
+ <td>
27
+ <%= image_tag a.image.url(150, 150), alt: '', class: 'img-fluid' %>
28
+ </td>
29
+ <td><%= a.actual_filename.split('.').last.upcase %></td>
30
+ <td><%= number_to_human_size a.filesize %></td>
31
+ <td><%= simple_format a.description %></td>
32
+ <td><%= l a.updated_at %></td>
33
+ <td class="text-xs-right">
34
+ <%= link_to icon(:trash), unlink_backend_images_path(klass: @article.class.name, id: @article.id, asset_id: a.id), data: { confirm: t('b.msg.confirm') }, title: t('b.delete') %>
35
+ </td>
36
+ </tr>
37
+ <% end %>
38
+ </tbody>
39
+ </table>
40
+
41
+ <% else %>
42
+ <p><%= t 'b.msg.no_items' %></p>
43
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <%= search_form_for @search, url: backend_images_path do |f| %>
2
+ <%= hidden_field_tag :klass, @model.class.name %>
3
+ <%= hidden_field_tag :id, @model.id %>
4
+ <div class="row m-b-2">
5
+ <div class="col-md-6">
6
+ <%= f.search_field :description_cont, placeholder: t('b.description'), class: 'form-control' %>
7
+ </div>
8
+ <div class="col-md-6">
9
+ <%= f.submit class: 'btn btn-sn' %>
10
+ </div>
11
+ </div>
12
+ <% end %>
@@ -0,0 +1,38 @@
1
+ <%= simple_form_for @image, url: backend_images_path(klass: @model.class.name, id: @model.id) do |f| %>
2
+ <div class="card">
3
+ <div class="card-header">
4
+ <%= t 'b.upload_a_new_image' %>
5
+ </div>
6
+
7
+ <div class="card-block">
8
+ <%= f.simple_fields_for :asset do |fa| %>
9
+ <%= fa.input :filename, as: :file, label: false, required: false %>
10
+ <%= fa.input :description, as: :text, required: false %>
11
+ <% end %>
12
+
13
+ <div class="form-actions">
14
+ <button type="submit" class="btn btn-primary"><%= t 'b.save' %></button>
15
+ </div>
16
+ </div>
17
+ </div>
18
+ <% end %>
19
+
20
+ <div class="card">
21
+ <div class="card-header">
22
+ <%= t 'b.choose_an_existing_image' %>
23
+ </div>
24
+
25
+ <div class="card-block">
26
+ <%= render 'filter' %>
27
+
28
+ <div class="row">
29
+ <% @assets.each do |a| %>
30
+ <div class="col-sm-6 col-md-4 col-lg-3 col-xl-2">
31
+ <%= link_to link_backend_images_path(klass: @model.class, id: @model.id, asset_id: a.id), style: '' do %>
32
+ <%= image_tag a.image.url(550, 550, action: :resize_and_pad, background: :white), alt: '', class: 'img-fluid' %>
33
+ <% end %>
34
+ </div>
35
+ <% end %>
36
+ </div>
37
+ </div>
38
+ </div>
@@ -0,0 +1,24 @@
1
+ <% if @image.errors.any? %>
2
+ <div class="alert alert-danger" role="alert">
3
+ <strong><%= t 'b.msg.something_went_wrong' %>!</strong>
4
+ <%= t 'b.msg.please_select_a_valid_image' %>
5
+ </div>
6
+ <% end %>
7
+
8
+ <%= simple_form_for @image, url: backend_images_path(klass: @model.class.name, id: @model.id) do |f| %>
9
+ <div class="card">
10
+ <div class="card-header">
11
+ <%= t 'b.image' %>
12
+ </div>
13
+
14
+ <div class="card-block">
15
+ <%= f.simple_fields_for :asset do |fa| %>
16
+ <%= fa.input :filename, as: :file, label: false %>
17
+ <%= fa.input :description, as: :text, required: false %>
18
+ <% end %>
19
+
20
+ <%= render 'backend/form_actions', cancel_url: backend_images_path(klass: @model.class.name, id: @model.id) %>
21
+ </div>
22
+ </div>
23
+
24
+ <% end %>
data/changelog.md CHANGED
@@ -1,3 +1,10 @@
1
+ 5.4.0 - 2017-03-08
2
+ --
3
+ * When enabled, you can add images to articles from the assets module.
4
+ * Bugfix: the sortable scope for the ```Image``` wasn't properly set.
5
+ * Images are now enabled by default for articles.
6
+
7
+
1
8
  5.3.1 - 2017-03-07
2
9
  --
3
10
  * Bugfix: there was an issue with loading the base module for the image
@@ -35,6 +35,7 @@ en:
35
35
  general: General
36
36
  house_number: House number
37
37
  html_content: HTML content
38
+ images: Afbeeldingen
38
39
  last_changed_at: Last changed at
39
40
  last_name: Last name
40
41
  locale: Locale
@@ -10,6 +10,7 @@ nl:
10
10
  articles: Artikels
11
11
  author: Auteur
12
12
  cancel: Annuleren
13
+ choose_an_existing_image: Kies bestaande afbeelding
13
14
  content: Inhoud
14
15
  current_image: Huidige afbeelding
15
16
  custom_title: Aangepaste titel
@@ -35,6 +36,8 @@ nl:
35
36
  general: Algemeen
36
37
  house_number: Huisnummer
37
38
  html_content: HTML inhoud
39
+ image: Afbeelding
40
+ images: Afbeeldingen
38
41
  last_changed_at: Laatst gewijzigd op
39
42
  last_name: Achternaam
40
43
  locale: Taal
@@ -78,6 +81,7 @@ nl:
78
81
  title: Titel
79
82
  to: Naar
80
83
  up: Omhoog
84
+ upload_a_new_image: Upload nieuwe afbeelding
81
85
  used: Gebruikt
82
86
  user: Gebruiker
83
87
  users: Gebruikers
@@ -117,8 +121,10 @@ nl:
117
121
  no_title_set: Dit item heeft nog geen titel.
118
122
  pages:
119
123
  invisible: Deze pagina is niet zichtbaar op de website.
124
+ please_select_a_valid_image: Gelieve een geldige afbeelding te selecteren en opnieuw te proberen.
120
125
  saved: '%{actor} werd bewaard.'
121
126
  seo: SEO
127
+ something_went_wrong: Er liep iets fout!
122
128
  status_codes:
123
129
  '301': 301 (Moved Permanently)
124
130
  '303': 303 (See Other)
data/config/routes.rb CHANGED
@@ -32,6 +32,10 @@ Rails.application.routes.draw do
32
32
 
33
33
  resources :articles, except: [:show] do
34
34
  concerns :translatable
35
+
36
+ resources :images, only: [:index], controller: 'articles/images' do
37
+ concerns :positionable
38
+ end
35
39
  end
36
40
 
37
41
  resources :navigations, only: [:index] do
@@ -82,6 +86,10 @@ Rails.application.routes.draw do
82
86
  end
83
87
  end
84
88
 
89
+ resources :images, only: [:index, :new, :create] do
90
+ collection { get 'link', 'unlink' }
91
+ end
92
+
85
93
  resources :assets
86
94
  end
87
95
 
@@ -6,7 +6,7 @@ module Udongo
6
6
  attribute :allow_html_in_title, Axiom::Types::Boolean, default: false
7
7
  attribute :allow_html_in_summary, Axiom::Types::Boolean, default: false
8
8
  attribute :editor_for_summary, Axiom::Types::Boolean, default: false
9
- attribute :images, Axiom::Types::Boolean, default: false
9
+ attribute :images, Axiom::Types::Boolean, default: true
10
10
 
11
11
  def allow_html_in_title?
12
12
  allow_html_in_title === true
@@ -1,3 +1,3 @@
1
1
  module Udongo
2
- VERSION = '5.3.1'
2
+ VERSION = '5.4.0'
3
3
  end
data/readme.md CHANGED
@@ -90,7 +90,7 @@ Udongo.config.articles.editor_for_summary = false
90
90
 
91
91
  ### images
92
92
  ```ruby
93
- Udongo.config.articles.images = false
93
+ Udongo.config.articles.images = true
94
94
  ```
95
95
 
96
96
  # Concerns
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: udongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.1
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davy Hellemans
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-07 00:00:00.000000000 Z
12
+ date: 2017-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -451,6 +451,8 @@ files:
451
451
  - app/assets/stylesheets/backend/pages/_login.scss
452
452
  - app/assets/stylesheets/backend/udongo.scss
453
453
  - app/controllers/backend/admins_controller.rb
454
+ - app/controllers/backend/articles/base_controller.rb
455
+ - app/controllers/backend/articles/images_controller.rb
454
456
  - app/controllers/backend/articles_controller.rb
455
457
  - app/controllers/backend/assets_controller.rb
456
458
  - app/controllers/backend/base_controller.rb
@@ -461,6 +463,7 @@ files:
461
463
  - app/controllers/backend/dashboard_controller.rb
462
464
  - app/controllers/backend/email_templates_controller.rb
463
465
  - app/controllers/backend/emails_controller.rb
466
+ - app/controllers/backend/images_controller.rb
464
467
  - app/controllers/backend/navigation/items_controller.rb
465
468
  - app/controllers/backend/navigations_controller.rb
466
469
  - app/controllers/backend/pages_controller.rb
@@ -585,6 +588,7 @@ files:
585
588
  - app/views/backend/articles/_tabs.html.erb
586
589
  - app/views/backend/articles/edit.html.erb
587
590
  - app/views/backend/articles/edit_translation.html.erb
591
+ - app/views/backend/articles/images/index.html.erb
588
592
  - app/views/backend/articles/index.html.erb
589
593
  - app/views/backend/articles/new.html.erb
590
594
  - app/views/backend/assets/_filter.html.erb
@@ -609,6 +613,9 @@ files:
609
613
  - app/views/backend/email_templates/new.html.erb
610
614
  - app/views/backend/emails/index.html.erb
611
615
  - app/views/backend/emails/show.html.erb
616
+ - app/views/backend/images/_filter.html.erb
617
+ - app/views/backend/images/index.html.erb
618
+ - app/views/backend/images/new.html.erb
612
619
  - app/views/backend/navigation/items/_form.html.erb
613
620
  - app/views/backend/navigation/items/_tabs.html.erb
614
621
  - app/views/backend/navigation/items/edit.html.erb