-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link collections and improvements to results view and API
- Show category image if image is not defined - Add possibility to define link collections for links - Add link collection management views and API fields - Destroy associated records on result destroy - Order statuses by progress - Disable general attachments display for results - Add possibility to display attachments and links per collection - Add statuses progress bar to the result sidebar - Update timeline styling - Add possibility to fetch the image blobs (main and list image) - Fix issue updating main image or list image through the API - Update locations module - Add missing translations and modify existing translations - Improve API specs
- Loading branch information
Showing
45 changed files
with
1,214 additions
and
65 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
50 changes: 50 additions & 0 deletions
50
app/commands/decidim/accountability/admin/create_link_collection.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,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Accountability | ||
module Admin | ||
# This command is executed when the user creates a ResultLinkCollection | ||
# for a Result from the admin panel. | ||
class CreateLinkCollection < Decidim::Command | ||
def initialize(form) | ||
@form = form | ||
end | ||
|
||
# Creates the link collection if valid. | ||
# | ||
# Broadcasts :ok if successful, :invalid otherwise. | ||
def call | ||
return broadcast(:invalid) if @form.invalid? | ||
|
||
transaction do | ||
create_link_collection | ||
end | ||
|
||
broadcast(:ok, link_collection) | ||
end | ||
|
||
private | ||
|
||
attr_reader :link_collection | ||
|
||
def create_link_collection | ||
@link_collection = Decidim.traceability.create!( | ||
AccountabilitySimple::ResultLinkCollection, | ||
@form.current_user, | ||
params, | ||
visibility: "all" | ||
) | ||
end | ||
|
||
def params | ||
{ | ||
decidim_accountability_result_id: @form.decidim_accountability_result_id, | ||
key: @form.key, | ||
name: @form.name, | ||
position: @form.position | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
49 changes: 49 additions & 0 deletions
49
app/commands/decidim/accountability/admin/update_link_collection.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,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Accountability | ||
module Admin | ||
# This command is executed when the user updates a ResultLinkCollection | ||
# for a Result from the admin panel. | ||
class UpdateLinkCollection < Decidim::Command | ||
def initialize(form, link_collection) | ||
@form = form | ||
@link_collection = link_collection | ||
end | ||
|
||
# Updates the link collection if valid. | ||
# | ||
# Broadcasts :ok if successful, :invalid otherwise. | ||
def call | ||
return broadcast(:invalid) if @form.invalid? | ||
|
||
transaction do | ||
update_link_collection | ||
end | ||
|
||
broadcast(:ok, link_collection) | ||
end | ||
|
||
private | ||
|
||
attr_reader :link_collection | ||
|
||
def update_link_collection | ||
Decidim.traceability.update!( | ||
link_collection, | ||
@form.current_user, | ||
params | ||
) | ||
end | ||
|
||
def params | ||
{ | ||
key: @form.key, | ||
name: @form.name, | ||
position: @form.position | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
...ontrollers/concerns/decidim/accountability_simple/admin/statuses_controller_extensions.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 AccountabilitySimple | ||
module Admin | ||
module StatusesControllerExtensions | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
private | ||
|
||
# Order the statuses based on progress. | ||
def statuses | ||
@statuses ||= Decidim::Accountability::Status.where(component: current_component).order(:progress).page(params[:page]).per(15) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
85 changes: 85 additions & 0 deletions
85
app/controllers/decidim/accountability/admin/link_collections_controller.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,85 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Accountability | ||
module Admin | ||
# Controller that allows managing all the link collections for a result. | ||
class LinkCollectionsController < Admin::ApplicationController | ||
helper_method :result | ||
|
||
def index | ||
enforce_permission_to :create, :result | ||
end | ||
|
||
def new | ||
enforce_permission_to :create, :result | ||
@form = form(AccountabilitySimple::Admin::ResultLinkCollectionForm).from_params({}, result: result) | ||
end | ||
|
||
def create | ||
enforce_permission_to :create, :result | ||
@form = form(AccountabilitySimple::Admin::ResultLinkCollectionForm).from_params(params, result: result) | ||
|
||
CreateLinkCollection.call(@form) do | ||
on(:ok) do | ||
flash[:notice] = I18n.t("link_collections.create.success", scope: "decidim.accountability.admin") | ||
redirect_to action: :index | ||
end | ||
|
||
on(:invalid) do | ||
flash.now[:alert] = I18n.t("link_collections.create.error", scope: "decidim.accountability.admin") | ||
render :new | ||
end | ||
end | ||
end | ||
|
||
def edit | ||
@link_collection = collection.find(params[:id]) | ||
enforce_permission_to :update, :result, result: @link_collection.result | ||
@form = form(AccountabilitySimple::Admin::ResultLinkCollectionForm).from_model(@link_collection, result: result) | ||
end | ||
|
||
def update | ||
@link_collection = collection.find(params[:id]) | ||
enforce_permission_to :update, :result, result: @link_collection.result | ||
@form = form(AccountabilitySimple::Admin::ResultLinkCollectionForm).from_params(params, result: result) | ||
|
||
UpdateLinkCollection.call(@form, @link_collection) do | ||
on(:ok) do | ||
flash[:notice] = I18n.t("link_collections.update.success", scope: "decidim.accountability.admin") | ||
redirect_to action: :index | ||
end | ||
|
||
on(:invalid) do | ||
flash.now[:alert] = I18n.t("link_collections.update.error", scope: "decidim.accountability.admin") | ||
render :edit | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@link_collection = collection.find(params[:id]) | ||
enforce_permission_to :destroy, :result, result: @link_collection.result | ||
|
||
Decidim.traceability.perform_action!("delete", @link_collection, current_user) do | ||
@link_collection.destroy! | ||
end | ||
|
||
flash[:notice] = I18n.t("link_collections.destroy.success", scope: "decidim.accountability.admin") | ||
|
||
redirect_to action: :index | ||
end | ||
|
||
private | ||
|
||
def result | ||
@result ||= Result.where(component: current_component).find(params[:result_id]) | ||
end | ||
|
||
def collection | ||
@collection ||= result.result_link_collections | ||
end | ||
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
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
25 changes: 25 additions & 0 deletions
25
app/forms/decidim/accountability_simple/admin/result_link_collection_form.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,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module AccountabilitySimple | ||
module Admin | ||
# A form object to create or update attachment collections. | ||
class ResultLinkCollectionForm < Form | ||
include TranslatableAttributes | ||
|
||
mimic :result_link_collection | ||
|
||
attribute :key, String | ||
attribute :position, Integer, default: 0 | ||
translatable_attribute :name, String | ||
|
||
validates :name, translatable_presence: true | ||
validates :decidim_accountability_result_id, presence: true | ||
|
||
def decidim_accountability_result_id | ||
context[:result]&.id | ||
end | ||
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
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
Oops, something went wrong.