decidim-admin 0.0.1.alpha9 → 0.0.1

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.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -8
  3. data/Rakefile +0 -25
  4. data/app/assets/javascripts/decidim/admin/application.js.es6 +17 -10
  5. data/app/assets/javascripts/decidim/admin/sort_steps.js.es6 +20 -11
  6. data/app/assets/javascripts/decidim/admin/tab_focus.js.es6 +22 -0
  7. data/app/assets/stylesheets/decidim/admin/_forms.scss +10 -0
  8. data/app/assets/stylesheets/decidim/admin/_layout.scss +11 -0
  9. data/app/assets/stylesheets/decidim/admin/_tables.scss +4 -0
  10. data/app/assets/stylesheets/decidim/admin/application.scss +8 -2
  11. data/app/commands/decidim/admin/activate_participatory_process_step.rb +1 -1
  12. data/app/commands/decidim/admin/create_category.rb +44 -0
  13. data/app/commands/decidim/admin/create_feature.rb +48 -0
  14. data/app/commands/decidim/admin/create_participatory_process.rb +3 -6
  15. data/app/commands/decidim/admin/create_participatory_process_admin.rb +51 -0
  16. data/app/commands/decidim/admin/create_participatory_process_attachment.rb +44 -0
  17. data/app/commands/decidim/admin/create_participatory_process_step.rb +3 -3
  18. data/app/commands/decidim/admin/create_scope.rb +38 -0
  19. data/app/commands/decidim/admin/create_static_page.rb +40 -0
  20. data/app/commands/decidim/admin/destroy_category.rb +36 -0
  21. data/app/commands/decidim/admin/destroy_feature.rb +39 -0
  22. data/app/commands/decidim/admin/publish_participatory_process.rb +1 -1
  23. data/app/commands/decidim/admin/reorder_participatory_process_steps.rb +5 -2
  24. data/app/commands/decidim/admin/unpublish_participatory_process.rb +1 -1
  25. data/app/commands/decidim/admin/update_category.rb +48 -0
  26. data/app/commands/decidim/admin/update_organization.rb +49 -0
  27. data/app/commands/decidim/admin/update_participatory_process.rb +2 -2
  28. data/app/commands/decidim/admin/update_participatory_process_attachment.rb +49 -0
  29. data/app/commands/decidim/admin/update_participatory_process_step.rb +1 -1
  30. data/app/commands/decidim/admin/update_scope.rb +43 -0
  31. data/app/commands/decidim/admin/update_static_page.rb +45 -0
  32. data/app/constraints/decidim/admin/organization_dashboard_constraint.rb +5 -1
  33. data/app/controllers/decidim/admin/application_controller.rb +8 -0
  34. data/app/controllers/decidim/admin/categories_controller.rb +90 -0
  35. data/app/controllers/decidim/admin/concerns/participatory_process_admin.rb +31 -0
  36. data/app/controllers/decidim/admin/features_controller.rb +74 -0
  37. data/app/controllers/decidim/admin/organization_controller.rb +40 -0
  38. data/app/controllers/decidim/admin/participatory_process_attachments_controller.rb +84 -0
  39. data/app/controllers/decidim/admin/participatory_process_publications_controller.rb +2 -7
  40. data/app/controllers/decidim/admin/participatory_process_step_activations_controller.rb +6 -8
  41. data/app/controllers/decidim/admin/participatory_process_step_ordering_controller.rb +2 -4
  42. data/app/controllers/decidim/admin/participatory_process_steps_controller.rb +13 -11
  43. data/app/controllers/decidim/admin/participatory_process_user_roles_controller.rb +54 -0
  44. data/app/controllers/decidim/admin/participatory_processes_controller.rb +11 -6
  45. data/app/controllers/decidim/admin/scopes_controller.rb +79 -0
  46. data/app/controllers/decidim/admin/static_pages_controller.rb +94 -0
  47. data/app/forms/decidim/admin/category_form.rb +37 -0
  48. data/app/forms/decidim/admin/feature_form.rb +16 -0
  49. data/app/forms/decidim/admin/organization_form.rb +31 -0
  50. data/app/forms/decidim/admin/participatory_process_attachment_form.rb +19 -0
  51. data/app/forms/decidim/admin/participatory_process_form.rb +4 -7
  52. data/app/forms/decidim/admin/participatory_process_step_form.rb +12 -2
  53. data/app/forms/decidim/admin/participatory_process_user_role_form.rb +15 -0
  54. data/app/forms/decidim/admin/scope_form.rb +24 -0
  55. data/app/forms/decidim/admin/static_page_form.rb +30 -0
  56. data/app/helpers/decidim/admin/application_helper.rb +1 -0
  57. data/app/helpers/decidim/admin/aria_selected_link_to_helper.rb +28 -0
  58. data/app/helpers/decidim/admin/attributes_display_helper.rb +13 -5
  59. data/app/models/decidim/admin/abilities/admin_user.rb +34 -0
  60. data/app/models/decidim/admin/abilities/base.rb +19 -0
  61. data/app/models/decidim/admin/abilities/participatory_process_admin.rb +51 -0
  62. data/app/models/decidim/admin/participatory_process_user_role.rb +14 -0
  63. data/app/queries/decidim/admin/manageable_participatory_processes_for_user.rb +41 -0
  64. data/app/queries/decidim/admin/process_admin_roles_for_process.rb +35 -0
  65. data/app/views/decidim/admin/categories/_form.html.erb +12 -0
  66. data/app/views/decidim/admin/categories/edit.html.erb +9 -0
  67. data/app/views/decidim/admin/categories/index.html.erb +44 -0
  68. data/app/views/decidim/admin/categories/new.html.erb +9 -0
  69. data/app/views/decidim/admin/categories/show.html.erb +14 -0
  70. data/app/views/decidim/admin/features/_feature.html.erb +20 -0
  71. data/app/views/decidim/admin/features/_form.html.erb +3 -0
  72. data/app/views/decidim/admin/features/index.html.erb +23 -0
  73. data/app/views/decidim/admin/features/new.html.erb +9 -0
  74. data/app/views/decidim/admin/organization/_form.html.erb +23 -0
  75. data/app/views/decidim/admin/organization/edit.html.erb +11 -0
  76. data/app/views/decidim/admin/participatory_process_attachments/_form.html.erb +11 -0
  77. data/app/views/decidim/admin/participatory_process_attachments/edit.html.erb +9 -0
  78. data/app/views/decidim/admin/participatory_process_attachments/index.html.erb +37 -0
  79. data/app/views/decidim/admin/participatory_process_attachments/new.html.erb +9 -0
  80. data/app/views/decidim/admin/participatory_process_attachments/show.html.erb +25 -0
  81. data/app/views/decidim/admin/participatory_process_steps/_form.html.erb +2 -2
  82. data/app/views/decidim/admin/participatory_process_steps/edit.html.erb +1 -3
  83. data/app/views/decidim/admin/participatory_process_steps/{_table.html.erb → index.html.erb} +15 -11
  84. data/app/views/decidim/admin/participatory_process_steps/new.html.erb +1 -3
  85. data/app/views/decidim/admin/participatory_process_steps/show.html.erb +1 -4
  86. data/app/views/decidim/admin/participatory_process_user_roles/index.html.erb +34 -0
  87. data/app/views/decidim/admin/participatory_processes/_form.html.erb +2 -2
  88. data/app/views/decidim/admin/participatory_processes/edit.html.erb +13 -3
  89. data/app/views/decidim/admin/participatory_processes/index.html.erb +5 -14
  90. data/app/views/decidim/admin/participatory_processes/show.html.erb +19 -36
  91. data/app/views/decidim/admin/scopes/_form.html.erb +3 -0
  92. data/app/views/decidim/admin/scopes/edit.html.erb +11 -0
  93. data/app/views/decidim/admin/scopes/index.html.erb +38 -0
  94. data/app/views/decidim/admin/scopes/new.html.erb +11 -0
  95. data/app/views/decidim/admin/static_pages/_form.html.erb +13 -0
  96. data/app/views/decidim/admin/static_pages/edit.html.erb +11 -0
  97. data/app/views/decidim/admin/static_pages/index.html.erb +40 -0
  98. data/app/views/decidim/admin/static_pages/new.html.erb +11 -0
  99. data/app/views/decidim/admin/static_pages/show.html.erb +22 -0
  100. data/app/views/layouts/decidim/admin/_application.html.erb +40 -0
  101. data/app/views/layouts/decidim/admin/_sidebar.html.erb +5 -2
  102. data/app/views/layouts/decidim/admin/application.html.erb +3 -40
  103. data/app/views/layouts/decidim/admin/participatory_process.html.erb +54 -0
  104. data/config/i18n-tasks.yml +3 -2
  105. data/config/locales/ca.yml +138 -6
  106. data/config/locales/en.yml +191 -13
  107. data/config/locales/es.yml +139 -7
  108. data/config/routes.rb +23 -1
  109. data/db/migrate/20161102144648_add_admin_participatory_process_user_roles.rb +15 -0
  110. data/db/seeds.rb +21 -0
  111. data/lib/decidim/admin/engine.rb +10 -3
  112. data/lib/decidim/admin/features/base_controller.rb +33 -0
  113. data/lib/decidim/admin/features.rb +10 -0
  114. data/lib/decidim/admin.rb +1 -0
  115. data/vendor/assets/javascripts/html.sortable.js +691 -0
  116. metadata +98 -33
  117. data/LICENSE.txt +0 -619
  118. data/app/models/decidim/admin/abilities/admin.rb +0 -21
  119. data/vendor/assets/javascripts/html.sortable.min.js +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d142764afb04ce2249b4458d4b8b2974c5c067f
4
- data.tar.gz: 1ca7e8e1d797aa607e9d3dee8d2acc53992604a3
3
+ metadata.gz: 46d6185dd125a2294268f3ecd81a04bda650cd19
4
+ data.tar.gz: 7285fb73b6dc707318b4aa7e6521361bc3324e8a
5
5
  SHA512:
6
- metadata.gz: dba8739599a660f86a627009888cb6f661d98caf8a6291ced478f8eb55eab1950edca6004de9d5c104f1d30105310d343a51b3752559ca5b9ed715453bcb9da2
7
- data.tar.gz: 86acfe10d775b3c56e88f8b853e072ff07f9e6b392eef8c2c8537769c55b43033182f42c67d1dd2693ccece9ffe7ba02eb9818264788cc4717f30a3f8cbc9072
6
+ metadata.gz: 3ea15149f26cb7988fd7493bd77f194b7a2eb7b2b52dfa8b1d77f68e9390a5a601ef37301d5694827fa90f93ef77b66161e245c6c7568209dbb9016053647213
7
+ data.tar.gz: 3b828b9ce5ba8de78d7340c1272f7fddace5f5221a2ce0c4f99369ba9338a7e12d9ff21dde3fc6300abc06b41e4a8b73b73fa3a45f4f64f4222a1c279e50c7c7
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Decidim::Admin
2
- Short description and motivation.
2
+
3
+ This library adds and administration dashboard so users can manage their
4
+ organization, participatory processes and all other entities.
3
5
 
4
6
  ## Usage
5
- How to use my plugin.
7
+ This will add an admin dashboard to manage an organization an all its entities.
8
+ It's included by default with Decidim.
6
9
 
7
10
  ## Installation
8
11
  Add this line to your application's Gemfile:
@@ -16,13 +19,35 @@ And then execute:
16
19
  $ bundle
17
20
  ```
18
21
 
19
- Or install it yourself as:
20
- ```bash
21
- $ gem install decidim-admin
22
- ```
22
+ ## Features
23
+
24
+ ### Participatory process
25
+
26
+ Here you can manage participatory processes.
27
+
28
+ TODO: Elaborate on this.
29
+
30
+
31
+ ### Static pages
32
+
33
+ This feature allows an admin to create pages to serve static content. Some
34
+ example of this kind of pages could be:
35
+
36
+ * Terms and Conditions
37
+ * FAQ
38
+ * Accessibility guidelines
39
+ * About the project
40
+
41
+ All the pages can be created with I18n support and will be accessible as
42
+ `/pages/:page-slug`. You can link them at your website the same way you link
43
+ other Rails models: `pages_path("terms-and-conditions")`.
44
+
45
+ There are some pages that exist by default and cannot be deleted since there
46
+ are links to them inside the Decidim framework, see `Decidim::StaticPage` for
47
+ the default list.
23
48
 
24
49
  ## Contributing
25
- Contribution directions go here.
50
+ See [Decidim](https://github.com/AjuntamentdeBarcelona/decidim).
26
51
 
27
52
  ## License
28
- The gem is available as open source under the terms of the [AGPLv3 License](https://opensource.org/licenses/AGPL-3.0).
53
+ See [Decidim](https://github.com/AjuntamentdeBarcelona/decidim).
data/Rakefile CHANGED
@@ -1,27 +1,2 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  require "decidim/common_rake"
4
- require "rdoc/task"
5
-
6
- RDoc::Task.new(:rdoc) do |rdoc|
7
- rdoc.rdoc_dir = "rdoc"
8
- rdoc.title = "Decidim::Admin"
9
- rdoc.options << "--line-numbers"
10
- rdoc.rdoc_files.include("README.md")
11
- rdoc.rdoc_files.include("lib/**/*.rb")
12
- end
13
-
14
- load "rails/tasks/statistics.rake"
15
-
16
- require "bundler/gem_tasks"
17
-
18
- begin
19
- require "rspec/core/rake_task"
20
- RSpec::Core::RakeTask.new(:spec)
21
- ENV["ENGINE_PATH"] = File.dirname(__FILE__)
22
-
23
- task default: :spec
24
-
25
- Rake::Task["spec"].enhance ["common:test_app"]
26
- rescue LoadError
27
- end
@@ -1,12 +1,19 @@
1
- //= require jquery
2
- //= require jquery_ujs
3
- //= require foundation
4
- //= require turbolinks
5
- //= require html.sortable.min
6
- //= require ./sort_steps
7
- //= require_self
1
+ /* global sortSteps */
8
2
 
9
- $(document).on('turbolinks:load', () => {
10
- $(() => { $(document).foundation(); });
11
- });
3
+ // = require jquery
4
+ // = require jquery_ujs
5
+ // = require foundation
6
+ // = require turbolinks
7
+ // = require html.sortable
8
+ // = require ./sort_steps
9
+ // = require ./tab_focus
10
+ // = require decidim/editor
11
+ // = require_self
12
12
 
13
+ const pageLoad = () => {
14
+ $(document).foundation();
15
+ sortSteps();
16
+ };
17
+
18
+ $(document).on('turbolinks:load', pageLoad);
19
+ $(pageLoad);
@@ -1,21 +1,30 @@
1
+ /* eslint-disable camelcase */
1
2
  /* global sortable */
2
3
 
3
- // consider removing from application.js file
4
- //
5
4
  // Needs a `tbody` element inside a `#steps` section. The `tbody` element
6
5
  // should have a `data-sort-url` attribute with the URL where the data should
7
6
  // be posted to.
8
- $(() => {
9
- const sortableElement = $('#steps tbody');
7
+ const sortSteps = () => {
8
+ const $sortableElement = $('#steps tbody');
10
9
 
11
- if (sortableElement) {
12
- const sortUrl = sortableElement.data('sort-url');
10
+ if ($sortableElement.length > 0) {
11
+ const sortUrl = $sortableElement.data('sort-url');
13
12
 
14
13
  sortable('#steps tbody', {
15
- placeholder: $('<tr style="border-style: dashed; border-color: #000"><td colspan="4">&nbsp;</td></tr>')[0],
16
- })[0].addEventListener('sortupdate', (e) => {
17
- const order = $(e.target).children().map(() => $(this).data('id')).toArray();
18
- $.ajax({ method: 'POST', url: sortUrl, data: { items_ids: order } });
14
+ placeholder: $('<tr style="border-style: dashed; border-color: #000"><td colspan="4">&nbsp;</td></tr>')[0]
15
+ })[0].addEventListener('sortupdate', (event) => {
16
+ const order = $(event.target).children()
17
+ .map((index, child) => $(child).data('id'))
18
+ .toArray();
19
+
20
+ $.ajax({
21
+ method: 'POST',
22
+ url: sortUrl,
23
+ contentType: 'application/json',
24
+ data: JSON.stringify({ items_ids: order }) },
25
+ );
19
26
  });
20
27
  }
21
- });
28
+ };
29
+
30
+ window.sortSteps = sortSteps;
@@ -0,0 +1,22 @@
1
+ // = require_self
2
+
3
+ /**
4
+ * When switching tabs in i18n fields, autofocus on the input to save clicks #212
5
+ */
6
+ $(document).on('turbolinks:load', () => {
7
+ // Event launched by foundation
8
+ $('[data-tabs]').on('change.zf.tabs', (event) => {
9
+ const $container = $(event.target).next('.tabs-content .tabs-panel.is-active');
10
+ // Detect quilljs editor inside the tabs-panel
11
+ let $content = $container.find('.editor .ql-editor');
12
+ if ($content.length > 0) {
13
+ $content.focus();
14
+ // Detect if inside the tabs-panel have an input
15
+ } else {
16
+ $content = $container.find('input:first');
17
+ if ($content.length > 0) {
18
+ $content.focus();
19
+ }
20
+ }
21
+ });
22
+ });
@@ -0,0 +1,10 @@
1
+ form {
2
+ ul.tabs {
3
+ a.alert {
4
+ color: map-get($foundation-palette, alert);
5
+ }
6
+ }
7
+ .tabs-content {
8
+ margin-bottom: 1rem;
9
+ }
10
+ }
@@ -13,4 +13,15 @@
13
13
 
14
14
  .page-title{
15
15
  margin-bottom: $global-margin;
16
+ }
17
+
18
+ dd {
19
+ margin-bottom: 1rem;
20
+ }
21
+
22
+ tr.subcategory {
23
+ td:first-child a:before {
24
+ content: "•";
25
+ margin-right: 1rem;
26
+ }
16
27
  }
@@ -11,4 +11,8 @@ tbody.sortable tr {
11
11
  border-left-style: dotted;
12
12
  border-left-color: #ccc;
13
13
  }
14
+ }
15
+
16
+ #process_admins td input {
17
+ margin: 0;
14
18
  }
@@ -1,8 +1,14 @@
1
- @import 'https://fonts.googleapis.com/css?family=Montserrat:400,700';
2
-
3
1
  @import "foundation_and_overrides";
4
2
  @import "layout";
5
3
  @import "login";
6
4
  @import "sidebar";
7
5
  @import "tables";
8
6
  @import "actions";
7
+ @import "forms";
8
+
9
+ @import "decidim/editor";
10
+ @import "decidim/utils/fontface";
11
+
12
+ body {
13
+ font-family: 'Source Sans Pro', sans-serif;
14
+ }
@@ -11,7 +11,7 @@ module Decidim
11
11
  @step = step
12
12
  end
13
13
 
14
- # Executes the command. Braodcasts these events:
14
+ # Executes the command. Broadcasts these events:
15
15
  #
16
16
  # - :ok when everything is valid.
17
17
  # - :invalid if the data wasn't valid and we couldn't proceed.
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Admin
4
+ # A command with all the business logic to create a new category in the
5
+ # system.
6
+ class CreateCategory < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # form - A form object with the params.
10
+ # participatory_process - The ParticipatoryProcess that will hold the
11
+ # category
12
+ def initialize(form, participatory_process)
13
+ @form = form
14
+ @participatory_process = participatory_process
15
+ end
16
+
17
+ # Executes the command. Broadcasts these events:
18
+ #
19
+ # - :ok when everything is valid.
20
+ # - :invalid if the form wasn't valid and we couldn't proceed.
21
+ #
22
+ # Returns nothing.
23
+ def call
24
+ return broadcast(:invalid) if form.invalid?
25
+
26
+ create_category
27
+ broadcast(:ok)
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :form
33
+
34
+ def create_category
35
+ Category.create!(
36
+ name: form.name,
37
+ description: form.description,
38
+ parent_id: form.parent_id,
39
+ participatory_process: @participatory_process
40
+ )
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Admin
4
+ # This command gets called when a feature is created from the admin panel.
5
+ class CreateFeature < Rectify::Command
6
+ attr_reader :form, :manifest, :participatory_process
7
+
8
+ # Public: Initializes the command.
9
+ #
10
+ # manifest - The feature's manifest to create a feature from.
11
+ # form - The form from which the data in this feature comes from.
12
+ # participatory_process - The participatory process that will hold this feature.
13
+ def initialize(manifest, form, participatory_process)
14
+ @manifest = manifest
15
+ @form = form
16
+ @participatory_process = participatory_process
17
+ end
18
+
19
+ # Public: Creates the Feature.
20
+ #
21
+ # Broadcasts :ok if created, :invalid otherwise.
22
+ def call
23
+ return broadcast(:invalid) if form.invalid?
24
+
25
+ transaction do
26
+ create_feature
27
+ run_hooks
28
+ end
29
+
30
+ broadcast(:ok)
31
+ end
32
+
33
+ private
34
+
35
+ def create_feature
36
+ @feature = Feature.create!(
37
+ manifest_name: manifest.name,
38
+ name: form.name,
39
+ participatory_process: participatory_process
40
+ )
41
+ end
42
+
43
+ def run_hooks
44
+ manifest.run_hooks(:create, @feature)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -7,14 +7,11 @@ module Decidim
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
10
- # organization - The Organization of the user that created the
11
- # participatory process
12
- def initialize(form, organization)
10
+ def initialize(form)
13
11
  @form = form
14
- @organization = organization
15
12
  end
16
13
 
17
- # Executes the command. Braodcasts these events:
14
+ # Executes the command. Broadcasts these events:
18
15
  #
19
16
  # - :ok when everything is valid.
20
17
  # - :invalid if the form wasn't valid and we couldn't proceed.
@@ -42,7 +39,7 @@ module Decidim
42
39
  hero_image: form.hero_image,
43
40
  banner_image: form.banner_image,
44
41
  promoted: form.promoted,
45
- organization: @organization
42
+ organization: form.current_organization
46
43
  )
47
44
  end
48
45
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Admin
4
+ # A command with all the business logic when creating a new participatory
5
+ # process admin in the system.
6
+ class CreateParticipatoryProcessAdmin < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # form - A form object with the params.
10
+ # participatory_process - The ParticipatoryProcess that will hold the
11
+ # user role
12
+ def initialize(form, participatory_process)
13
+ @form = form
14
+ @participatory_process = participatory_process
15
+ end
16
+
17
+ # Executes the command. Broadcasts these events:
18
+ #
19
+ # - :ok when everything is valid.
20
+ # - :invalid if the form wasn't valid and we couldn't proceed.
21
+ #
22
+ # Returns nothing.
23
+ def call
24
+ return broadcast(:invalid) if form.invalid?
25
+ return broadcast(:invalid) unless user
26
+
27
+ create_participatory_process_admin
28
+ broadcast(:ok)
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :form, :participatory_process
34
+
35
+ def create_participatory_process_admin
36
+ ParticipatoryProcessUserRole.create!(
37
+ role: :admin,
38
+ user: user,
39
+ participatory_process: @participatory_process
40
+ )
41
+ end
42
+
43
+ def user
44
+ User.where(
45
+ email: form.email,
46
+ organization: participatory_process.organization
47
+ ).first
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Admin
4
+ # A command with all the business logic to add an attachment to a
5
+ # participatory process.
6
+ class CreateParticipatoryProcessAttachment < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # form - A form object with the params.
10
+ # participatory_process - The ParticipatoryProcess that will hold the
11
+ # attachment
12
+ def initialize(form, participatory_process)
13
+ @form = form
14
+ @participatory_process = participatory_process
15
+ end
16
+
17
+ # Executes the command. Broadcasts these events:
18
+ #
19
+ # - :ok when everything is valid.
20
+ # - :invalid if the form wasn't valid and we couldn't proceed.
21
+ #
22
+ # Returns nothing.
23
+ def call
24
+ return broadcast(:invalid) if form.invalid?
25
+
26
+ create_attachment
27
+ broadcast(:ok)
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :form
33
+
34
+ def create_attachment
35
+ ParticipatoryProcessAttachment.create!(
36
+ title: form.title,
37
+ description: form.description,
38
+ file: form.file,
39
+ participatory_process: @participatory_process
40
+ )
41
+ end
42
+ end
43
+ end
44
+ end
@@ -14,7 +14,7 @@ module Decidim
14
14
  @participatory_process = participatory_process
15
15
  end
16
16
 
17
- # Executes the command. Braodcasts these events:
17
+ # Executes the command. Broadcasts these events:
18
18
  #
19
19
  # - :ok when everything is valid.
20
20
  # - :invalid if the form wasn't valid and we couldn't proceed.
@@ -36,8 +36,8 @@ module Decidim
36
36
  title: form.title,
37
37
  description: form.description,
38
38
  short_description: form.short_description,
39
- start_date: form.start_date.at_midnight,
40
- end_date: form.end_date.at_midnight,
39
+ start_date: form.start_date,
40
+ end_date: form.end_date,
41
41
  participatory_process: @participatory_process
42
42
  )
43
43
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Admin
4
+ # A command with all the business logic when creating a static scope.
5
+ class CreateScope < Rectify::Command
6
+ # Public: Initializes the command.
7
+ #
8
+ # form - A form object with the params.
9
+ def initialize(form)
10
+ @form = form
11
+ end
12
+
13
+ # Executes the command. Broadcasts these events:
14
+ #
15
+ # - :ok when everything is valid.
16
+ # - :invalid if the form wasn't valid and we couldn't proceed.
17
+ #
18
+ # Returns nothing.
19
+ def call
20
+ return broadcast(:invalid) if form.invalid?
21
+
22
+ create_scope
23
+ broadcast(:ok)
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :form
29
+
30
+ def create_scope
31
+ Scope.create!(
32
+ name: form.name,
33
+ organization: form.organization
34
+ )
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Admin
4
+ # A command with all the business logic when creating a static page.
5
+ class CreateStaticPage < Rectify::Command
6
+ # Public: Initializes the command.
7
+ #
8
+ # form - A form object with the params.
9
+ def initialize(form)
10
+ @form = form
11
+ end
12
+
13
+ # Executes the command. Broadcasts these events:
14
+ #
15
+ # - :ok when everything is valid.
16
+ # - :invalid if the form wasn't valid and we couldn't proceed.
17
+ #
18
+ # Returns nothing.
19
+ def call
20
+ return broadcast(:invalid) if form.invalid?
21
+
22
+ create_page
23
+ broadcast(:ok)
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :form
29
+
30
+ def create_page
31
+ StaticPage.create!(
32
+ title: form.title,
33
+ slug: form.slug,
34
+ content: form.content,
35
+ organization: form.organization
36
+ )
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Admin
4
+ # A command with all the business logic to destroy a category in the
5
+ # system.
6
+ class DestroyCategory < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # category - A Category that will be destroyed
10
+ def initialize(category)
11
+ @category = category
12
+ end
13
+
14
+ # Executes the command. Broadcasts these events:
15
+ #
16
+ # - :ok when everything is valid.
17
+ # - :invalid if the data wasn't valid and we couldn't proceed.
18
+ #
19
+ # Returns nothing.
20
+ def call
21
+ return broadcast(:invalid) if category.nil? || category.subcategories.any?
22
+
23
+ destroy_category
24
+ broadcast(:ok)
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :category
30
+
31
+ def destroy_category
32
+ category.destroy!
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Admin
4
+ # This command deals with destroying a Feature from the admin panel.
5
+ class DestroyFeature < Rectify::Command
6
+ # Public: Initializes the command.
7
+ #
8
+ # feature - The Feature to be destroyed.
9
+ def initialize(feature)
10
+ @feature = feature
11
+ end
12
+
13
+ # Public: Executes the command.
14
+ #
15
+ # Broadcasts :ok if it got destroyed, raises an exception otherwise.
16
+ def call
17
+ begin
18
+ destroy_feature
19
+ rescue StandardError
20
+ return broadcast(:invalid)
21
+ end
22
+ broadcast(:ok)
23
+ end
24
+
25
+ private
26
+
27
+ def destroy_feature
28
+ transaction do
29
+ @feature.destroy!
30
+ run_hooks
31
+ end
32
+ end
33
+
34
+ def run_hooks
35
+ @feature.manifest.run_hooks(:destroy, @feature)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -10,7 +10,7 @@ module Decidim
10
10
  @process = process
11
11
  end
12
12
 
13
- # Executes the command. Braodcasts these events:
13
+ # Executes the command. Broadcasts these events:
14
14
  #
15
15
  # - :ok when everything is valid.
16
16
  # - :invalid if the data wasn't valid and we couldn't proceed.