redmineup 1.1.3 → 1.1.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f706adbd36e4dfd53da2d24224e5669c4cdc88ecedd1d7b0e9f3b1ae485b8a06
4
- data.tar.gz: e6c3373d8a37c501d32f87251fe045ba69e0b576a39862835b0c3a4f4aee2479
3
+ metadata.gz: 6f8f8df6b0546cd2b666a238c013c600b54d1fca8c9b68261673bc2256079c93
4
+ data.tar.gz: 5901b81ca53254bf78eab4de85be957647219886d6814b5dbb57ff0a30455aff
5
5
  SHA512:
6
- metadata.gz: f4aeb84bd22c370ca7cae5e938516aae0c75dcbfbd1c69139a27a2029d67578dafde73577ec1e43039a60dec34a2c7e11866924985b9862f6d8774e0ddf3e9c7
7
- data.tar.gz: 3883402ff5a4310e6d423ce618dda88489bb762fbeb7bf7960350484d327bc7ee5a8dc0eb8b9b531ee9cce3ddf4e686eea44b6d8d8e9adad2aedb986912d5a8d
6
+ metadata.gz: f10631319aab3f2ed797cbdb0d9c91f6f9f079cb9f7215c769b5e8416951b2d127ae2173209e2ec098d409a211ac255551e1b5b31fa9ea7c7fdc6fe40ce6dff1
7
+ data.tar.gz: af16c6904f761b0db76bbc6b3d5ee6a4e4488ca492fbec79fe6f60fc9ea0ef651e61c25845f23ae79e64c312a319adddb3f30c41e2d60ccf74bf12f7733c9c40
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
+ /.obsidian
3
4
  /Gemfile.lock
4
5
  /_yardoc/
5
6
  /coverage/
data/README.md CHANGED
@@ -1,204 +1,125 @@
1
- # Redmineup
2
-
3
- This gem is used at RedmineUP as a general place for shared functionality and
4
- assets. It contains **Chart.js** and **select2** JS libraries, various mixins
5
- for ActiveRecord models and other things you might find useful.
6
-
7
- Among mixins there are:
8
-
9
- * up_acts_as_draftable
10
- * up_acts_as_taggable
11
- * up_acts_as_viewable
12
- * up_acts_as_votable
13
-
1
+ # redmineup
2
+
3
+ `redmineup` is a shared gem used by RedmineUP plugins. It provides common
4
+ ActiveRecord mixins, view helpers, assets, settings, and compatibility patches
5
+ so plugin code stays focused on domain logic.
6
+
7
+ The gem is used in production plugins such as `redmine_contacts`,
8
+ `redmine_people`, `redmine_products`, `redmine_questions`, `redmine_drive`,
9
+ `redmineup_tags`, `redmine_agile`, and others.
10
+
11
+ ## What is included
12
+
13
+ - ActiveRecord mixins: `up_acts_as_taggable`, `up_acts_as_draftable`,
14
+ `up_acts_as_viewed`, `up_acts_as_votable`, `up_acts_as_voter`,
15
+ `up_acts_as_priceable`
16
+ - Tag helpers and tag UI helpers: `tag_link`, `tag_links`, `tag_cloud_links`,
17
+ `tag_list_field_tag`, `FormBuilder#tag_list_field`
18
+ - Select2 and chart integration helpers: `select2_tag`, `transform_to_select2`,
19
+ `redmineup_assets`, `chartjs_assets`
20
+ - Shared endpoint for tag autocompletion:
21
+ `auto_complete_taggable_tags_path`
22
+ - Money and currency formatting (`Redmineup::MoneyHelper`,
23
+ `Redmineup::Currency`, `Redmineup::Settings::Money`)
24
+ - Liquid filters and drops used across RedmineUP plugins
14
25
 
15
26
  ## Installation
16
27
 
17
- Add it to your plugin's Gemfile:
28
+ Add to your Redmine or plugin `Gemfile`:
29
+
18
30
  ```ruby
19
31
  gem 'redmineup'
20
32
  ```
21
33
 
22
- Then invoke the following command in your plugin's or Redmine directory:
23
- ```
24
- $ bundle install
25
- ```
26
-
27
- And now you can start using it.
28
-
34
+ Install dependencies:
29
35
 
30
- ## Usage
31
- ### Drafts
32
- This module allows saving and restoring drafts for different models. To be
33
- saved as a draft, an instance does not need to pass the validations. Drafts
34
- store not only model attributes, but also associations and virtual attributes.
35
- A draft could be linked to a given user, so every user can manage his/her own
36
- drafts independent of others. A draft might have a parent instance.
37
-
38
- First of all, drafts need to be saved somewhere, so let's create a migration:
39
- ```ruby
40
- class CreateDrafts < Rails.version > '5' ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
41
- def change
42
- ActiveRecord::Base.create_drafts_table
43
- end
44
- end
36
+ ```bash
37
+ bundle install
45
38
  ```
46
39
 
47
- Then in the Redmine directory run:
48
- ```
49
- $ rake redmine:plugins:migrate
50
- ```
40
+ In plugin `init.rb`, guard the minimum supported version:
51
41
 
52
- Next, add `up_acts_as_draftable` to a model for which you want to save drafts:
53
42
  ```ruby
54
- class Message < ActiveRecord::Base
55
- up_acts_as_draftable
56
- end
43
+ requires_redmineup version_or_higher: '1.1.5'
57
44
  ```
58
45
 
59
- And that's it for the preparation, now you're ready to make use of drafts:
60
- ```ruby
61
- # You can save message as a draft.
62
- Message.new(subject: 'foo').save_draft
63
-
64
- # And later restore message from the draft.
65
- draft = Message.drafts(nil).last
66
- message = draft.restore
67
- puts message.subject
68
- # => foo
69
-
70
- # Draft can be overwritten.
71
- message.content = 'bar'
72
- puts message.save_draft
73
- # => true
74
-
75
- # You can also save draft linked to a particular user.
76
- Message.new(subject: 'baz').save_draft(user: current_user)
77
-
78
- # And restore message from some user's draft.
79
- user_draft = Message.drafts(current_user).last
80
- user_message = user_draft.restore
81
- puts user_message.subject
82
- # => baz
83
-
84
- # It's also possible to restore a bunch of messages at once.
85
- messages = Message.drafts(current_user).restore_all
86
- p messages.map(&:subject)
87
- # => ["baz"]
88
-
89
- # When a model instance is saved, corresponding draft is removed.
90
- puts Message.drafts(current_user).count
91
- # => 1
92
- user_message.board_id = Board.first.id
93
- user_message.save!
94
- puts Message.drafts(current_user).count
95
- # => 0
96
-
97
- # Drafts will be saved only for new (not persisted) or changed instances.
98
- puts Message.new.save_draft
99
- # => true
100
- persisted = Message.last
101
- puts persisted.save_draft
102
- # => false
103
- persisted.subject = 'other subject'
104
- puts persisted.save_draft
105
- # => true
106
- ```
46
+ ## Quick start
107
47
 
108
- ### Tags
109
- This module makes it possible to tag objects.
48
+ ### 1) Add taggable behavior to a model
110
49
 
111
- First, create a migration:
112
50
  ```ruby
113
- class CreateTags < Rails.version > '5' ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
51
+ # db/migrate/XXXXXXXXXXXX_create_tags.rb
52
+ class CreateTags < ActiveRecord::Migration[6.1]
114
53
  def change
115
54
  ActiveRecord::Base.create_taggable_table
116
55
  end
117
56
  end
118
57
  ```
119
58
 
120
- Then in the Redmine directory run:
121
- ```
122
- $ rake redmine:plugins:migrate
123
- ```
124
-
125
- Next, add `up_acts_as_taggable` to a model for which you want to provide tags:
126
59
  ```ruby
127
- class Contact < ActiveRecord::Base
60
+ class Contact < ApplicationRecord
128
61
  up_acts_as_taggable
129
62
  end
130
63
  ```
131
64
 
132
- TODO: Add examples of usage.
133
-
134
- ### Viewings
135
- This module allows you to count views for some ActiveRecord model instances.
65
+ ### 2) Render tags using shared helpers
136
66
 
137
- To count views you'll need to create a migration:
138
67
  ```ruby
139
- class CreateViewings < Rails.version > '5' ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
140
- def change
141
- ActiveRecord::Base.create_viewings_table
142
- end
68
+ # helper
69
+ def contact_tag_url(tag_name, options = {})
70
+ {
71
+ controller: 'contacts',
72
+ action: 'index',
73
+ set_filter: 1,
74
+ fields: [:tags],
75
+ values: { tags: [tag_name] },
76
+ operators: { tags: '=' }
77
+ }.merge(options)
143
78
  end
144
79
  ```
145
80
 
146
- To apply it, run the following in the Redmine directory:
147
- ```
148
- $ rake redmine:plugins:migrate
81
+ ```erb
82
+ <%= tag_cloud_links(Contact.available_tags(project: @project), :contact) %>
149
83
  ```
150
84
 
151
- Then add `up_acts_as_viewed` to a model for which you want to count views.
152
- ```ruby
153
- class Question < ActiveRecord::Base
154
- up_acts_as_viewed
155
- end
156
- ```
85
+ `tag_cloud_links(tags, :contact)` resolves links via `contact_tag_url(name)`.
157
86
 
158
- TODO: Provide some usage examples.
87
+ ### 3) Add Select2 tag editor to forms
159
88
 
160
- ### Votes
161
- With this module you can make your models votable and allow users to vote.
162
-
163
- As always, create a migration first:
164
- ```ruby
165
- class CreateVotes < Rails.version > '5' ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
166
- def change
167
- ActiveRecord::Base.create_votable_table
168
- end
169
- end
89
+ ```erb
90
+ <%= f.tag_list_field :tag_list, width: '95%' %>
170
91
  ```
171
92
 
172
- Then apply it by running the following command in the Redmine directory:
173
- ```
174
- $ rake redmine:plugins:migrate
175
- ```
93
+ or standalone:
176
94
 
177
- To make a model votable, add `up_acts_as_votable` to it:
178
- ```ruby
179
- class Question < ActiveRecord::Base
180
- up_acts_as_votable
181
- end
95
+ ```erb
96
+ <%= tag_list_field_tag 'contact[tag_list]', @contact.tag_list, taggable_type: 'Contact' %>
182
97
  ```
183
98
 
184
- TODO: Write about `up_acts_as_voter` and add usage examples.
99
+ ## Documentation
185
100
 
101
+ - [ActiveRecord mixins](doc/active-record-mixins.md)
102
+ - [Tagging and Select2 helpers](doc/tagging-and-select2.md)
103
+ - [Assets, money, and shared utilities](doc/assets-money-and-utilities.md)
186
104
 
187
105
  ## Development
188
106
 
189
- If you're planning to extend this gem, you will need to install development
190
- dependencies. To do this, execute the following command in the project's
191
- directory:
192
- ```
193
- $ bundle install
194
- ```
107
+ Install dependencies:
195
108
 
196
- After that you'll be able to run tests:
197
- ```
198
- $ bundle exec rake test
109
+ ```bash
110
+ bundle install
199
111
  ```
200
112
 
201
- SQLite in-memory database will be used by default, which is the fastest way to run tests. To run them using different database adapters, set `DB` environment variable to one of the available values — `mysql`, `postgresql`, `sqlite`. For example, to use PostgreSQL, invoke tests like so:
113
+ Run tests:
114
+
115
+ ```bash
116
+ bundle exec rake test
202
117
  ```
203
- $ bundle exec rake test DB=postgresql
118
+
119
+ Run tests against another DB adapter:
120
+
121
+ ```bash
122
+ bundle exec rake test DB=postgresql
204
123
  ```
124
+
125
+ Available `DB` values: `sqlite`, `mysql`, `postgresql`.