Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
706efcc
move srcript to right file
armandfardeau Sep 10, 2018
ac5e1be
import js
armandfardeau Sep 10, 2018
f0a2102
import style
armandfardeau Sep 10, 2018
046a6b2
import helper
armandfardeau Sep 10, 2018
e12c4a6
import model
armandfardeau Sep 10, 2018
c677336
Import views
armandfardeau Sep 10, 2018
8910de2
Import extends
armandfardeau Sep 10, 2018
e303270
import translation
armandfardeau Sep 10, 2018
adfb439
import component settings
armandfardeau Sep 10, 2018
ccd8ba4
import migration
armandfardeau Sep 10, 2018
93edda9
Import extends
armandfardeau Sep 10, 2018
326572b
move project file to right folder
armandfardeau Sep 10, 2018
79e6d82
Fix typo
armandfardeau Sep 10, 2018
d75cf5d
Fix migration
armandfardeau Sep 10, 2018
cefbd96
fix rubocop offenses
armandfardeau Sep 11, 2018
3e9e3d4
Fix lint offenses
armandfardeau Sep 11, 2018
6f37c0c
Fix erblint offesense
armandfardeau Sep 11, 2018
17eb74f
Build bundle.js
armandfardeau Sep 11, 2018
ea2164e
Fix commands and form tests
armandfardeau Sep 11, 2018
a76931f
Fix method name
armandfardeau Sep 11, 2018
9a25d4d
Fix linter issue
armandfardeau Sep 11, 2018
8a04085
Fix css test
armandfardeau Sep 11, 2018
1626327
Fix test
armandfardeau Sep 12, 2018
2c95f65
Fix lint offense
armandfardeau Sep 13, 2018
ffbc539
Fix missing translation
armandfardeau Sep 17, 2018
c5b1014
Merge branch '0.12-stable' into 0.12-stable-budget
armandfardeau Sep 17, 2018
329c4b3
Fix rubocop offense
armandfardeau Sep 17, 2018
e395008
remove TODO
armandfardeau Sep 17, 2018
614534f
use proper breakpoint
armandfardeau Sep 17, 2018
0c19e5b
Add readme entry
armandfardeau Sep 17, 2018
1a53403
change fr translation
armandfardeau Sep 20, 2018
24a71d4
Merge remote-tracking branch 'origin/0.12-stable' into 0.12-stable-bu…
armandfardeau Sep 21, 2018
ed02c2d
Fix incorrect translation
armandfardeau Sep 26, 2018
c0c81e3
Fix typo in trad
juliesimon Sep 27, 2018
863743c
Update trad
juliesimon Sep 27, 2018
9af35e5
Fix vote module checkbox in proposals
juliesimon Sep 27, 2018
cb876a3
Merge pull request #288 from OpenSourcePolitics/fix-vote-checkbox
armandfardeau Sep 27, 2018
f59534a
Merge branch '0.12-stable-budget' of https://github.com/OpenSourcePol…
moustachu Oct 2, 2018
ccd3f80
Merge branch '0.12-stable' into 0.12-stable-budget
moustachu Oct 2, 2018
101c577
Merge branch '0.12-stable' into 0.12-stable-budget
moustachu Oct 2, 2018
a7f26a4
Backport fix
armandfardeau Nov 5, 2018
1798b23
Ad test for project model
armandfardeau Nov 6, 2018
4af7866
Add tests for order model
armandfardeau Nov 6, 2018
e42f225
Refactor test
armandfardeau Nov 6, 2018
3e957df
Use examples for greater clarity
armandfardeau Nov 6, 2018
3e1e805
Fix translations issue
armandfardeau Nov 7, 2018
10e81e7
Fix rubocop offense
armandfardeau Nov 7, 2018
4c31cc7
Add tests for budget commands
armandfardeau Nov 8, 2018
8e117f7
Move test to the right folder
armandfardeau Nov 8, 2018
f41e039
Separate test with examples
armandfardeau Nov 8, 2018
78ef023
Add system tests for budget
armandfardeau Nov 9, 2018
c2eedd5
Keep test dry
armandfardeau Nov 9, 2018
30a064c
Merge branch '0.12-stable' into 0.12-stable-budget-with-tests
armandfardeau Nov 9, 2018
f1a2492
Update changelog
armandfardeau Nov 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

**Upgrade notes**:

- **decidim-budgets**: Re-introduce vote on budget by number of project. This feature has not been fully tested. See [\#265](https://github.com/OpenSourcePolitics/decidim/pull/265)
- **Banner uploader**: banner uploader has been changed in [\#150](https://github.com/OpenSourcePolitics/decidim/pull/150)
you should update existing image if you don't want to reupload them.
use the following command in your rails console : `Decidim::ParticipatoryProcess.find_each { |process| process.banner_image.recreate_versions! if process.banner_image? }`
Expand All @@ -14,6 +15,8 @@ use the following command in your rails console : `Decidim::User.find_each { |us

**Added**:

- **decidim-budgets**: Re-introduce vote on budget by number of project.[\#330](https://github.com/OpenSourcePolitics/decidim/pull/330)
- **decidim-debates**: Allow debates to be reported [\#199](https://github.com/OpenSourcePolitics/decidim/pull/199)
- **decidim-proposals**: Allow proposals location to be changed on a map [\#296](https://github.com/OpenSourcePolitics/decidim/pull/296)
- **decidim-participatory_processes**: Ability to order processes in the back-office [#189](https://github.com/OpenSourcePolitics/decidim/pull/189)
- **decidim-debates**: add export feature to debates [#270](https://github.com/OpenSourcePolitics/decidim/pull/270)
Expand Down
81 changes: 81 additions & 0 deletions decidim-admin/app/views/decidim/admin/components/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,84 @@
</div>
</div>
</div>

<script type="text/javascript">
function disableClick(check1, check2, field1, field2) {
if (check1.is(":checked")) {
check2.prop("disabled", true);
// When the checkbox is followed by an input
if (field2) {
disableField(field2)
}
} else if (check2.is(":checked")) {
check1.prop("disabled", true);
// When the checkbox is followed by an input
if (field1) {
disableField(field1)
}
}
}

function switchDisabling(check1, check2, field1, field2) {
check1.change(function () {
if ($(this).is(":checked")) {
check2.prop("disabled", true);
// When the checkbox is followed by an input
if (field2) {
disableField(field2)
}
} else {
$(this).prop("disabled", false);
check2.prop("disabled", false);
if (field2 && field1) {
enableField(field2)
enableField(field1)
}
}
})
}

function disableOtherField(field, actionCheck) {
if (actionCheck.is(":checked")) {
disableField(field)
} else {
enableField(field)
}
actionCheck.change(function () {
if (actionCheck.is(":checked")) {
disableField(field)
} else {
enableField(field)
}
});
}

function disableField(field) {
field.prop("disabled", true);
}

function enableField(field) {
field.prop("disabled", false);
}

$(document).ready(function () {
// PROPOSAL
var participatory_space_id = <%= current_participatory_space.id %>;
var $supports = $('input[name="component[step_settings][' + participatory_space_id + '][votes_enabled]"]')
var $votes = $('input[name="component[step_settings][' + participatory_space_id + '][votes_weight_enabled]"]')
disableClick($supports, $votes, false, false)
switchDisabling($supports, $votes, false, false)
switchDisabling($votes, $supports, false, false)
// BUDGET
var $perBudget = $('input[name="component[settings][vote_per_budget]"]')
var $perProject = $('input[name="component[settings][vote_per_project]"]')
var $BudgetSumField = $('input[name="component[settings][total_budget]"]')
var $projectNumberField = $('input[name="component[settings][total_projects]"]')
var $voteTreshold = $('input[name="component[settings][vote_threshold_percent]"]')
switchDisabling($perBudget, $perProject, $BudgetSumField, $projectNumberField)
switchDisabling($perProject, $perBudget, $projectNumberField, $BudgetSumField)
disableClick($perBudget, $perProject, $BudgetSumField, $projectNumberField)
disableClick($perProject, $perBudget, $projectNumberField, $BudgetSumField)
disableOtherField($voteTreshold, $perProject)
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
$(() => {
const $projects = $("#projects, #project");
const $budgetSummaryTotal = $(".budget-summary__total");
const $budgetExceedModal = $("#budget-excess");
const $budgetExceedModal = $("#limit-excess");

const totalBudget = parseInt($budgetSummaryTotal.attr("data-total-budget"), 10);
const totalProjects = parseInt($budgetSummaryTotal.attr("data-total-projects"), 10);

const cancelEvent = (event) => {
event.stopPropagation();
Expand All @@ -15,13 +16,16 @@ $(() => {

$projects.on("click", ".budget--list__action", (event) => {
const currentBudget = parseInt($(".budget-summary__progressbox").attr("data-current-budget"), 10);
const currentProjects = parseInt($(".budget-summary__progressbox").attr("data-current-projects"), 10);
const perProject = $budgetSummaryTotal.attr("data_per_project");
const $currentTarget = $(event.currentTarget);
const projectBudget = parseInt($currentTarget.attr("data-budget"), 10);

if ($currentTarget.attr("disabled")) {
if ($currentTarget.attr("data-add") && (currentProjects === totalProjects) && perProject) {
$budgetExceedModal.foundation("toggle");
cancelEvent(event);

} else if ($currentTarget.attr("data-add") && ((currentBudget + projectBudget) > totalBudget)) {
} else if ($currentTarget.attr("disabled")) {
cancelEvent(event);
} else if ($currentTarget.attr("data-add") && ((currentBudget + projectBudget) > totalBudget) && perProject === "false") {
$budgetExceedModal.foundation("toggle");
cancelEvent(event);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.card__content{
.hidden{
display: none !important;
}
}

.card__support_votes{
margin-left: 0 !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ class ProjectsController < Decidim::Budgets::ApplicationController
include FilterResource
include NeedsCurrentOrder

helper_method :projects, :random_seed, :project

private
helper_method :projects, :random_seed, :project, :geocoded_projects

def projects
@projects ||= search.results.page(params[:page]).per(current_component.settings.projects_per_page)
Expand Down Expand Up @@ -39,6 +37,12 @@ def default_filter_params
def context_params
{ component: current_component, organization: current_organization }
end

private

def geocoded_projects
@geocoded_projects ||= search.results.select(&:geocoded?)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module ApplicationHelper
include PaginateHelper
include Decidim::Comments::CommentsHelper
include ProjectsHelper
include Decidim::MapHelper
include Decidim::Budgets::MapHelper
end
end
end
21 changes: 21 additions & 0 deletions decidim-budgets/app/helpers/decidim/budgets/map_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Decidim
module Budgets
# This helper include some methods for rendering projects dynamic maps.
module MapHelper
# Serialize a collection of geocoded projects to be used by the dynamic map component
#
# geocoded_projects - A collection of geocoded projects
def projects_data_for_map(geocoded_projects)
geocoded_projects.map do |project|
project.slice(:latitude, :longitude, :address)
.merge(title: translated_attribute(project.title),
description: translated_attribute(project.description),
icon: icon("proposals", width: 40, height: 70, remove_icon_class: true),
link: project_path(project))
end
end
end
end
end
60 changes: 46 additions & 14 deletions decidim-budgets/app/models/decidim/budgets/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ class Order < Budgets::ApplicationRecord
validates :user, uniqueness: { scope: :component }
validate :user_belongs_to_organization

validates :total_budget, numericality: {
greater_than_or_equal_to: :minimum_budget
}, if: :checked_out?
validates :total_budget, numericality: { greater_than_or_equal_to: :minimum_budget }, if: :checked_out_and_not_project?
validates :total_budget, numericality: { less_than_or_equal_to: :maximum_budget }, unless: :per_project

validates :total_budget, numericality: {
less_than_or_equal_to: :maximum_budget
}
validates :total_projects, numericality: { less_than_or_equal_to: :number_of_projects }, if: :per_project
# i18n-tasks-use t('activerecord.errors.messages.equal_to')
validates :total_projects, numericality: { equal_to: :number_of_projects }, if: :checked_out_and_per_project?

scope :finished, -> { where.not(checked_out_at: nil) }
scope :pending, -> { where(checked_out_at: nil) }
Expand All @@ -38,11 +37,6 @@ def checked_out?
checked_out_at.present?
end

# Public: Check if the order total budget is enough to checkout
def can_checkout?
total_budget.to_f >= minimum_budget
end

# Public: Returns the order budget percent from the settings total budget
def budget_percent
(total_budget.to_f / component.settings.total_budget.to_f) * 100
Expand All @@ -54,10 +48,48 @@ def minimum_budget
component.settings.total_budget.to_f * (component.settings.vote_threshold_percent.to_f / 100)
end

# Public: Returns the required maximum budget to checkout
# Public: Returns true if the order has been checked out and is budget type
def checked_out_and_not_project?
checked_out? && !per_project
end

# Public: Returns true if the order has been checked out and is project type
def checked_out_and_per_project?
checked_out? && per_project
end

def per_project
component&.settings&.vote_per_project?
end

def limit_project_reached?
return false unless per_project
total_projects == number_of_projects
end

def total_projects
projects.count
end

def remaining_projects
number_of_projects - projects.count
end

def can_checkout?
if per_project
limit_project_reached?
else
total_budget.to_f >= minimum_budget
end
end

def number_of_projects
component.settings.total_projects
end

def maximum_budget
return 0 unless component
component.settings.total_budget.to_f
return 0 unless component || !per_project
component&.settings&.total_budget.to_f
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<%= form.number_field :budget %>
</div>

<% if component_settings.geocoding_enabled? %>
<div class="row column">
<%= form.text_field :address, label: t(".fields.address") %>
</div>
<% end %>

<% if current_participatory_space.has_subscopes? %>
<div class="row column">
<%= scopes_picker_field form, :decidim_scope_id %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<tr>
<th><%= t("models.project.fields.title", scope: "decidim.budgets") %></th>
<th class="center"><%= t("index.confirmed_orders_count") %></th>
<% if component_settings.geocoding_enabled? %>
<th><%= t("models.project.fields.map", scope: "decidim.budgets") %></th>
<% end %>
<th class="actions"><%= t("actions.title", scope: "decidim.budgets") %></th>
</tr>
</thead>
Expand All @@ -25,6 +28,11 @@
<td class='center'>
<%= project.confirmed_orders_count %>
</td>
<% if component_settings.geocoding_enabled? %>
<td>
<%= static_map_link(project) %>
</td>
<% end %>
<td class="table-list__actions">
<%= icon_link_to "eye", resource_locator(project).path, t("actions.preview", scope: "decidim.budgets"), target: :blank, class: "action-icon--preview" %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,30 @@
</p>
<% else %>
<h3 class="heading3"><%= t(".title") %></h3>
<p><%= t(".description", minimum_budget: budget_to_currency(current_order&.minimum_budget)) %></p>
<p>
<% if component_settings.vote_per_project? %>
<%= t(".description_per_project", minimum_project: component_settings.total_projects) %>
<% else %>
<%= t(".description_per_budget", minimum_budget: budget_to_currency(current_order&.minimum_budget)) %>
<% end %>
</p>
<% end %>
<% end %>

<div class="budget-summary__total" data-total-budget="<%= component_settings.total_budget %>">
<span class="mini-title"><%= t("total_budget") %>
<strong class="mini-title__strong mini-title__strong--highlight">
<%= budget_to_currency(component_settings.total_budget) %>
</strong>
</span>
<div class="budget-summary__total" data-total-budget="<%= component_settings.total_budget %>" data-total-projects="<%= component_settings.total_projects %>" data_per_project="<%= component_settings.vote_per_project %>">
<% unless component_settings.vote_per_project? %>
<span class="mini-title"><%= t("total_budget") %>
<strong class="mini-title__strong mini-title__strong--highlight">
<%= budget_to_currency(component_settings.total_budget) %>
</strong>
</span>
<% end %>
</div>

<%= render partial: "order_progress" %>

<div>
<span class="mini-title">
<span class="mini-title <%= "hidden" if component_settings.vote_per_project? %>">
<%= t(".assigned") %>
<%= render partial: "order_total_budget" %>
</span>
Expand All @@ -33,5 +41,5 @@
<%= render partial: "order_selected_projects" %>
</div>

<%= render partial: "budget_excess" %>
<%= render partial: "limit_excess" %>
<%= render partial: "budget_confirm" %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="reveal" data-reveal id="limit-excess">
<div class="reveal__header">
<h3 class="reveal__title">
<% if component_settings.vote_per_project? %>
<%= t(".title_per_project") %>
<% else %>
<%= t(".title_per_budget") %>
<% end %>
</h3>
<button class="close-button" data-close aria-label="<%= t(".close") %>" type="button">
<span aria-hidden="true">&times;</span>
</button>
</div>
<p>
<% if component_settings.vote_per_project? %>
<%= t(".description_per_project") %>
<% else %>
<%= t(".description_per_budget") %>
<% end %>
</p>
<div class="row">
<div class="columns medium-8 medium-offset-2">
<button data-close class="button expanded"><%= t(".ok") %></button>
</div>
</div>
</div>
Loading