forked from decidim/decidim
-
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.
Merge branch 'develop' into feature/admin_answers_close_comments
- Loading branch information
Showing
274 changed files
with
5,608 additions
and
545 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
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
23 changes: 23 additions & 0 deletions
23
decidim-admin/app/commands/decidim/admin/create_taxonomy.rb
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Admin | ||
# A command with all the business logic to create a taxonomy. | ||
# This command is called from the controller. | ||
class CreateTaxonomy < Decidim::Commands::CreateResource | ||
fetch_form_attributes :name, :organization, :parent_id | ||
|
||
protected | ||
|
||
def resource_class = Decidim::Taxonomy | ||
|
||
def extra_params | ||
{ | ||
extra: { | ||
parent_name: form.try(:parent).try(:name) | ||
} | ||
} | ||
end | ||
end | ||
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
18 changes: 18 additions & 0 deletions
18
decidim-admin/app/commands/decidim/admin/destroy_taxonomy.rb
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Admin | ||
# A command with all the business logic to destroy a taxonomy. | ||
class DestroyTaxonomy < Decidim::Commands::DestroyResource | ||
private | ||
|
||
def extra_params | ||
{ | ||
extra: { | ||
parent_name: resource.parent.try(:name) | ||
} | ||
} | ||
end | ||
end | ||
end | ||
end |
76 changes: 76 additions & 0 deletions
76
decidim-admin/app/commands/decidim/admin/reorder_taxonomies.rb
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,76 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Admin | ||
# A command that reorders a collection of taxonomies | ||
# the ones that might be missing. | ||
class ReorderTaxonomies < Decidim::Command | ||
# Public: Initializes the command. | ||
# | ||
# organization - the Organization where the content blocks reside | ||
# order - an Array holding the order of IDs of published content blocks. | ||
def initialize(organization, order, offset = 0) | ||
@organization = organization | ||
@order = order | ||
@offset = offset | ||
end | ||
|
||
# Executes the command. Broadcasts these events: | ||
# | ||
# - :ok when everything is valid. | ||
# - :invalid if the data was not valid and we could not proceed. | ||
# | ||
# Returns nothing. | ||
def call | ||
return broadcast(:invalid) if order.blank? | ||
return broadcast(:invalid) if collection.empty? | ||
|
||
reorder_steps | ||
broadcast(:ok) | ||
end | ||
|
||
private | ||
|
||
attr_reader :organization, :offset | ||
|
||
def reorder_steps | ||
transaction do | ||
reset_weights | ||
collection.reload | ||
set_new_weights | ||
end | ||
end | ||
|
||
def reset_weights | ||
# rubocop:disable Rails/SkipsModelValidations | ||
collection.where.not(weight: nil).where(id: order).update_all(weight: nil) | ||
# rubocop:enable Rails/SkipsModelValidations | ||
end | ||
|
||
def set_new_weights | ||
data = order.each_with_index.inject({}) do |hash, (id, index)| | ||
hash.update(id => index + 1 + offset) | ||
end | ||
|
||
data.each do |id, weight| | ||
item = collection.find_by(id:) | ||
item.update!(weight:) if item.present? | ||
end | ||
end | ||
|
||
def order | ||
return nil unless @order.is_a?(Array) && @order.present? | ||
|
||
@order | ||
end | ||
|
||
def collection | ||
@collection ||= Decidim::Taxonomy.where(organization:, parent_id: first_item.parent_id) | ||
end | ||
|
||
def first_item | ||
@first_item ||= Decidim::Taxonomy.where(organization:).find(order.first) | ||
end | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
decidim-admin/app/commands/decidim/admin/update_taxonomy.rb
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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Admin | ||
# A command to update a taxonomy. | ||
class UpdateTaxonomy < Decidim::Commands::UpdateResource | ||
fetch_form_attributes :name, :parent_id | ||
|
||
protected | ||
|
||
def extra_params | ||
{ | ||
extra: { | ||
parent_name: resource.parent.try(:name) | ||
} | ||
} | ||
end | ||
end | ||
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
20 changes: 0 additions & 20 deletions
20
decidim-admin/app/controllers/concerns/decidim/admin/paginable.rb
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
decidim-admin/app/controllers/concerns/decidim/admin/taxonomies/filterable.rb
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require "active_support/concern" | ||
|
||
module Decidim | ||
module Admin | ||
module Taxonomies | ||
module Filterable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
include Decidim::Admin::Filterable | ||
|
||
private | ||
|
||
def base_query | ||
collection | ||
end | ||
|
||
def search_field_predicate | ||
:name_or_children_name_cont | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
decidim-admin/app/controllers/concerns/decidim/admin/verification_conflicts/filterable.rb
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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require "active_support/concern" | ||
|
||
module Decidim | ||
module Admin | ||
module VerificationConflicts | ||
module Filterable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
include Decidim::Admin::Filterable | ||
|
||
private | ||
|
||
def base_query | ||
collection | ||
end | ||
|
||
def search_field_predicate | ||
:current_user_name_or_current_user_nickname_or_current_user_email_cont | ||
end | ||
|
||
def filters | ||
[] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.