reportable_rails 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +81 -2
- data/lib/reportable_rails/version.rb +1 -1
- data/lib/reportable_rails.rb +5 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2599e880a8d9608af3f17d210f19e6b17ffab9dddad24572c55fdca8187e7a7e
|
4
|
+
data.tar.gz: 3c19a1cfba98ccdfc4279e48b9f9f4c3006b360fbdfc50279c259a3d1d2e7192
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9cc252b5b6fb17a348cd610944724768c89ed91b3dc0be469b9f8683fdf0e85d1342acda5ee71aca5bfcc2c5fd92bc5bc90b26afe6c2292bfa9f67e24272de5
|
7
|
+
data.tar.gz: 19bb2d807d7c4c968093ebfc4d46098906e0920b87f467bbb01937495f5feb6faf70dfe56eb7b001879f6d06ddf53592ed938977834f2e7e50b5fd336acf305a
|
data/README.md
CHANGED
@@ -38,18 +38,47 @@ end
|
|
38
38
|
|
39
39
|
### Setting Up Models
|
40
40
|
|
41
|
-
|
41
|
+
ReportableRails provides three main models that can be included in your application:
|
42
42
|
|
43
43
|
```ruby
|
44
|
+
# app/models/time_report.rb
|
44
45
|
class TimeReport < ApplicationRecord
|
45
46
|
include ReportableRails::Models::Report
|
46
47
|
end
|
48
|
+
|
49
|
+
# app/models/report_category.rb
|
50
|
+
class ReportCategory < ApplicationRecord
|
51
|
+
include ReportableRails::Models::ReportCategory
|
52
|
+
end
|
53
|
+
|
54
|
+
# app/models/hours_log.rb
|
55
|
+
class HoursLog < ApplicationRecord
|
56
|
+
include ReportableRails::Models::HoursLog
|
57
|
+
end
|
47
58
|
```
|
48
59
|
|
49
|
-
|
60
|
+
Each model provides the following functionality:
|
61
|
+
|
62
|
+
#### Report Model
|
50
63
|
- `belongs_to :owner` (user who owns the report)
|
51
64
|
- `belongs_to :report_category` (optional categorization)
|
52
65
|
- `has_many :hours_logs` (time entries for the report)
|
66
|
+
- Period management methods
|
67
|
+
- Report submission handling
|
68
|
+
|
69
|
+
#### Report Category Model
|
70
|
+
- `has_many :reports`
|
71
|
+
- Name and description tracking
|
72
|
+
- Active/inactive status management
|
73
|
+
- Scopes for filtering active categories
|
74
|
+
- Helper methods for finding and managing categories
|
75
|
+
|
76
|
+
#### Hours Log Model
|
77
|
+
- `belongs_to :report`
|
78
|
+
- Hours and date tracking
|
79
|
+
- Period validation
|
80
|
+
- Description management
|
81
|
+
- Methods for checking if hours are in current period
|
53
82
|
|
54
83
|
### Managing Hours Logs
|
55
84
|
|
@@ -92,6 +121,56 @@ report = TimeReport.create!(
|
|
92
121
|
)
|
93
122
|
```
|
94
123
|
|
124
|
+
### Database Setup
|
125
|
+
|
126
|
+
You'll need to create the necessary database tables. Here are the recommended migrations:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
# Create Reports Table
|
130
|
+
class CreateReports < ActiveRecord::Migration[6.1]
|
131
|
+
def change
|
132
|
+
create_table :reports do |t|
|
133
|
+
t.references :owner, null: false, foreign_key: { to_table: :users }
|
134
|
+
t.references :report_category, foreign_key: true
|
135
|
+
t.timestamps
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# Create Report Categories Table
|
141
|
+
class CreateReportCategories < ActiveRecord::Migration[6.1]
|
142
|
+
def change
|
143
|
+
create_table :report_categories do |t|
|
144
|
+
t.string :name, null: false
|
145
|
+
t.text :description
|
146
|
+
t.boolean :active, default: true
|
147
|
+
t.timestamps
|
148
|
+
t.index :name, unique: true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# Create Hours Logs Table
|
154
|
+
class CreateHoursLogs < ActiveRecord::Migration[6.1]
|
155
|
+
def change
|
156
|
+
create_table :hours_logs do |t|
|
157
|
+
t.references :report, null: false, foreign_key: true
|
158
|
+
t.decimal :hours, null: false, precision: 4, scale: 2
|
159
|
+
t.date :date, null: false
|
160
|
+
t.text :description, null: false
|
161
|
+
t.timestamps
|
162
|
+
t.index [:report_id, :date]
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
```
|
167
|
+
|
168
|
+
Run the migrations with:
|
169
|
+
|
170
|
+
```bash
|
171
|
+
$ rails db:migrate
|
172
|
+
```
|
173
|
+
|
95
174
|
## License
|
96
175
|
|
97
176
|
The gem is available as open source under the terms of the MIT License.
|
data/lib/reportable_rails.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
require 'rails/engine'
|
4
4
|
require 'active_model_serializers'
|
5
5
|
require 'reportable_rails/version'
|
6
|
+
require 'reportable_rails/models/report'
|
7
|
+
require 'reportable_rails/models/report_category'
|
8
|
+
require 'reportable_rails/models/hours_log'
|
6
9
|
|
7
10
|
module ReportableRails
|
8
11
|
class Error < StandardError; end
|
@@ -32,11 +35,12 @@ module ReportableRails
|
|
32
35
|
end
|
33
36
|
|
34
37
|
class Configuration
|
35
|
-
attr_accessor :user_class, :default_category_name
|
38
|
+
attr_accessor :user_class, :default_category_name, :report_submitted_callback
|
36
39
|
|
37
40
|
def initialize
|
38
41
|
@user_class = 'User'
|
39
42
|
@default_category_name = 'Uncategorized'
|
43
|
+
@report_submitted_callback = nil
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|