reportable_rails 0.1.0 → 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/models/hours_log.rb +34 -0
- data/lib/reportable_rails/models/report_category.rb +42 -0
- data/lib/reportable_rails/version.rb +1 -1
- data/lib/reportable_rails.rb +5 -1
- metadata +3 -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.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ReportableRails
|
2
|
+
module Models
|
3
|
+
module HoursLog
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
belongs_to :report, class_name: 'ReportableRails::Report'
|
8
|
+
|
9
|
+
validates :hours, presence: true, numericality: { greater_than: 0, less_than_or_equal_to: 24 }
|
10
|
+
validates :date, presence: true
|
11
|
+
validates :description, presence: true, length: { maximum: 1000 }
|
12
|
+
|
13
|
+
validate :date_within_period
|
14
|
+
|
15
|
+
# Check if the hours log belongs to the current reporting period
|
16
|
+
def current_period?
|
17
|
+
return false unless report && date
|
18
|
+
|
19
|
+
date >= report.current_period_start_date && date <= report.current_period_end_date
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def date_within_period
|
25
|
+
return unless date && report
|
26
|
+
|
27
|
+
unless date >= report.current_period_start_date && date <= report.current_period_end_date
|
28
|
+
errors.add(:date, "must be within the current reporting period (#{report.current_period_start_date} to #{report.current_period_end_date})")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ReportableRails
|
2
|
+
module Models
|
3
|
+
module ReportCategory
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
has_many :reports, class_name: 'ReportableRails::Report', dependent: :nullify
|
8
|
+
|
9
|
+
validates :name, presence: true, uniqueness: { case_sensitive: false }
|
10
|
+
validates :description, length: { maximum: 1000 }
|
11
|
+
validates :active, inclusion: { in: [true, false] }
|
12
|
+
|
13
|
+
# Scopes
|
14
|
+
scope :active, -> { where(active: true) }
|
15
|
+
scope :ordered, -> { order(:name) }
|
16
|
+
|
17
|
+
before_validation :set_default_active
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def set_default_active
|
22
|
+
self.active = true if active.nil?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClassMethods
|
27
|
+
# Find or create a category by name
|
28
|
+
def find_or_create_by_name(name, description: nil)
|
29
|
+
find_or_create_by(name: name) do |category|
|
30
|
+
category.description = description if description.present?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Deactivate a category without deleting it
|
35
|
+
def deactivate(name)
|
36
|
+
category = find_by(name: name)
|
37
|
+
category&.update(active: false)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reportable_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicu Listana
|
@@ -103,7 +103,9 @@ extra_rdoc_files: []
|
|
103
103
|
files:
|
104
104
|
- README.md
|
105
105
|
- lib/reportable_rails.rb
|
106
|
+
- lib/reportable_rails/models/hours_log.rb
|
106
107
|
- lib/reportable_rails/models/report.rb
|
108
|
+
- lib/reportable_rails/models/report_category.rb
|
107
109
|
- lib/reportable_rails/version.rb
|
108
110
|
homepage: https://github.com/adobocorp/reportable_rails
|
109
111
|
licenses:
|