Skip to content

Commit

Permalink
remove photo button in attachments (#76)
Browse files Browse the repository at this point in the history
* remove photo button in attachments

* fix device test

* fix tests. Add documentation
  • Loading branch information
microstudi authored Jul 10, 2023
1 parent fba63bc commit 0c14c5f
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
decidim-reporting_proposals (0.4.1)
decidim-reporting_proposals (0.4.2)
decidim-admin (>= 0.25.0, < 0.27)
decidim-core (>= 0.25.0, < 0.27)
decidim-participatory_processes (>= 0.25.0, < 0.27)
Expand Down
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

This module creates a new component to be used in participatory spaces that allows to create proposals orientated to manage geolocated issues in a city. For instance Damages or new ideas of improving a particular street or public good.

[👉 See features & screenshots](#features)

## Installation

Add this line to your application's Gemfile:
Expand All @@ -34,7 +36,7 @@ bundle exec rails decidim_reporting_proposals:install:migrations
> **IMPORTANT:**
>
> This module makes use of the [Deface](https://github.com/spree/deface) gem.
> In conjuntion with other modules (we know [Term Customizer](https://github.com/mainio/decidim-module-term_customizer/) is one of them) it might cause errors when precompiling assets for production sites. But only if during this process the compiling machine does not have access to the database.
> In conjunction with other modules (we know [Term Customizer](https://github.com/mainio/decidim-module-term_customizer/) is one of them) it might cause errors when precompiling assets for production sites. But only if during this process the compiling machine does not have access to the database.
>
> It is easy to overcome this problem. Just add the following line to your `config/environments/production.rb` file:
>
Expand All @@ -50,6 +52,13 @@ bundle exec rails decidim_reporting_proposals:install:migrations
>
> Alternatively, use any other ENV var to set up the `config.deface.enabled` to `false` during the precompilation phase.
Depending on your Decidim version, you can choose the corresponding version to ensure compatibility:
| Version | Compatible Decidim versions |
|---|---|
| 0.5.x | 0.27.x |
| 0.4.x | 0.26.x |
## Usage
This module works very similarly as the Proposals module, in fact, it extends it to provide additional features and some different defaults.
Expand All @@ -58,11 +67,34 @@ It provides a new component called "Reporting Proposals" that can be added in ad
### Features
TODO...
This module provides the following features:
1. **Reporting Proposals Component**: A new component that can be added to any participatory space. It allows to create proposals in one-step form with some optimization for mobile devices. Users can add photos using the phone's camera directly and also use the device's GPS to establish a precise a geolocated address with one click. Some of the options can be used in the normal proposal's component too (but in this case they 2 steps behavior is maintained).
![Reporting proposal creationg](features/proposal.png)
2. **Comparison by proximity**: By default, reporting proposals are compared by proximity before publishing (as they are geolocated by default). This can be disabled in the component's settings.
![Compare by proximity](features/proximity.png)
3. **Automatic assignation of valuators**: When a proposal is created, admins usually have to assign valuators manually to it. This module allows admins to assign valuators to a category directly. This will automatically assign all valuators in that category to any proposal/reporting proposal created under it (and also existing proposals). This avoids the need of manually assign proposals to valuators. This behavior can be disabled in the component's settings.
![Valuators in categories](features/categories.png)
4. **Valuators empowerment**: A number of features allow valuators to have more control over the proposals they are evaluating. They can assign other valuators (instead of themselves) and they can change or add photos to a proposal. All of it is configurable. Also, valuators can be assigned directly in the proposal's answering page instead of using the bulk assignation feature. Additionally, privates note can be edited and links in it are clickable.
![Valuators empowerment](features/answering1.png)
5. **Overdue proposals**: This module allows to set a number of days after which a proposal is considered overdue. This is configurable and can be disabled. This feature affects the admin list of proposals, adding visual notes, color coded, to facilitate the identification of overdue proposals and preventing admins to leave unanswered proposals for a long time.
![Overdue proposals](features/overdues.png)
6. **Improved notifications**: Some notifications are added, and some existing ones are improved. For instance, valuators and admins can receive notifications after a proposal has been added and it's content includes a direct link to the proposal and its answering page.
7. **Hide proposals without reporting**: Administrators can hide proposals directly, without using the reporting process. Also, authors who's content has been hidden receive a notification.
8. **Proposal answers templates**: Administrators can create templates for the answers to proposals. This is useful to provide a standard answer to proposals that are similar. This feature requires to enable the `decidim-templates` official module.
![Templates for proposals answers](features/templates1.png)
![Applying a template](features/templates2.png)
### Customization
Almost all the features of this module can be customized through an initializer.
Almost all the features of this module can be customized/disabled through an initializer.
For instance, you can create an initializer an change some of the available options as follows (**This is optional, you don't need to do this, by default all options are enabled**):
Expand All @@ -89,9 +121,6 @@ Decidim::ReportingProposals.configure do |config|
# Public Setting that adds a button next to the "add image" input[type=file] to open the camera directly
config.use_camera_button = [:proposals, :reporting_proposals]
# Public Setting to prevent adding the camera button on not photo/image input[type=file]
config.camera_button_on_attachments = false
# Public setting to prevent valuators or admins to modify the photos attached to a proposal
# otherwise can be configured at the component level
config.allow_proposal_photo_editing = true
Expand All @@ -101,6 +130,8 @@ Decidim::ReportingProposals.configure do |config|
end
```
Find all the available options in the [config.rb](lib/decidim/reporting_proposals/config.rb) file.

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/openpoke/decidim-module-reporting_proposals.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def use_camera_button?(object_name)

return unless Decidim::ReportingProposals.use_camera_button.include?(@template.current_component.manifest_name.to_sym)

return object_name == :add_photos unless Decidim::ReportingProposals.camera_button_on_attachments

true
object_name == :add_photos
end
end
end
Expand Down
76 changes: 37 additions & 39 deletions app/packs/src/decidim/reporting_proposals/user_camera_inputs.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
$(() => {
$('input[type="file"]').each((_i, el) => {
const $input = $(el);
const $inputField = $input.closest(".row.column");
const $button = $inputField.find("button:first");
const $checkbox = $inputField.find("input:checkbox[name$='[has_no_image]']");
const $formError = $inputField.find("span.form-error")
const $labelInput = $("label[for='proposal_add_photos']")
const $input = $("#proposal_add_photos");
const $inputField = $input.closest(".row.column");
const $button = $inputField.find("button:first");
const $checkbox = $inputField.find("input:checkbox[name$='[has_no_image]']");
const $formError = $inputField.find("span.form-error")
const $labelInput = $("label[for='proposal_add_photos']")

const removeErrors = () => {
$input.removeClass("is-invalid-input");
$formError.removeClass("is-visible");
$labelInput.removeClass("is-invalid-label");
};
const removeErrors = () => {
$input.removeClass("is-invalid-input");
$formError.removeClass("is-visible");
$labelInput.removeClass("is-invalid-label");
};

const toggleInput = () => {
if ($checkbox[0].checked) {
removeErrors();
$input.prop("disabled", true);
$button.prop("disabled", true);
} else {
$input.prop("disabled", false);
$button.prop("disabled", false);
}
const toggleInput = () => {
if ($checkbox[0].checked) {
removeErrors();
$input.prop("disabled", true);
$button.prop("disabled", true);
} else {
$input.prop("disabled", false);
$button.prop("disabled", false);
}
}

$input.attr("accept", "image/*");
$input.attr("accept", "image/*");

$button.on("click", () => {
console.log("click button")
$input.attr("capture", "camera");
$input.click();
$input.removeAttr("capture", "camera");
});
$button.on("click", () => {
console.log("click button")
$input.attr("capture", "camera");
$input.click();
$input.removeAttr("capture", "camera");
});

$input.on("click", () => {
console.log("click", $input);
$input.one("blur", () => {
console.log("blur", $input);
removeErrors();
});
$input.on("click", () => {
console.log("click", $input);
$input.one("blur", () => {
console.log("blur", $input);
removeErrors();
});

if ($checkbox.length > 0) {
$checkbox.on("change", toggleInput);
toggleInput();
}
});

if ($checkbox.length > 0) {
$checkbox.on("change", toggleInput);
toggleInput();
}
});
Binary file added features/answering1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added features/categories.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added features/overdues.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added features/proposal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added features/proximity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added features/templates1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added features/templates2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 0 additions & 5 deletions lib/decidim/reporting_proposals/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ module ReportingProposals
[:proposals, :reporting_proposals]
end

# Public Setting to prevent adding the camera button on not photo/image input[type=file]
config_accessor :camera_button_on_attachments do
false
end

# Public setting to prevent valuators or admins to modify the photos attached to a proposal
# otherwise can be configured at the component level
config_accessor :allow_proposal_photo_editing do
Expand Down
2 changes: 1 addition & 1 deletion lib/decidim/reporting_proposals/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Decidim
module ReportingProposals
VERSION = "0.4.1"
VERSION = "0.4.2"
DECIDIM_VERSION = "0.26.5"

COMPAT_DECIDIM_VERSION = [">= 0.25.0", "< 0.27"].freeze
Expand Down
14 changes: 2 additions & 12 deletions spec/system/device_camera_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,16 @@
let(:proposal) { Decidim::Proposals::Proposal.last }
let(:all_manifests) { [:proposals, :reporting_proposals] }
let(:manifests) { all_manifests }
let(:camera_on_attachments) { true }

before do
allow(Decidim::ReportingProposals).to receive(:use_camera_button).and_return(manifests)
allow(Decidim::ReportingProposals).to receive(:camera_button_on_attachments).and_return(camera_on_attachments)
switch_to_host(organization.host)
login_as user, scope: :user
end

shared_examples "uses device camera" do
it "has two cameras button" do
expect(page).to have_button("Use my camera", count: 2)
end

context "when no camera on attachments" do
let(:camera_on_attachments) { false }

it "has one camera button" do
expect(page).to have_button("Use my camera", count: 1)
end
it "has one camera button" do
expect(page).to have_button("Use my camera", count: 1)
end

context "when option disabled" do
Expand Down

0 comments on commit 0c14c5f

Please sign in to comment.