reportable_rails 0.1.0
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 +7 -0
- data/README.md +97 -0
- data/lib/reportable_rails/models/report.rb +53 -0
- data/lib/reportable_rails/version.rb +3 -0
- data/lib/reportable_rails.rb +42 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7e5ec2f4a9c2f8a9cdcbfeb33e8644619d50ea228b41406b6f9722a696139969
|
4
|
+
data.tar.gz: 607c06c8e2f02dcb465bbc3f22da9c0bbdf4516e67aed9191f437dc3eb38d901
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a26f5731f97be20f52a7e887a38dbe80037681e0c759fef6df9a5d79f3bdd31b0de1e7aa7f8b45d70e7039a8ba86b32d3843e7545112d44c8cc6f8a0a5ea3e09
|
7
|
+
data.tar.gz: 951dd89ad30271c6c0a9ebaae267a9dd78017277f858b52d3795cae394cc52f067e2440189482c00e5e6b7dd66fbb8e78362074cc33c6c63f00ce4fb13070319
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# ReportableRails
|
2
|
+
|
3
|
+
ReportableRails is a Ruby on Rails gem that provides a flexible reporting system for tracking and managing time-based reports with period management.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'reportable_rails'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
## Configuration
|
20
|
+
|
21
|
+
ReportableRails can be configured in an initializer:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# config/initializers/reportable_rails.rb
|
25
|
+
ReportableRails.configure do |config|
|
26
|
+
# Set the user class for report ownership (default: 'User')
|
27
|
+
config.user_class = 'User'
|
28
|
+
|
29
|
+
# Configure a callback for when reports are submitted
|
30
|
+
config.report_submitted_callback = ->(report) {
|
31
|
+
# Your custom logic here
|
32
|
+
# For example: NotificationMailer.report_submitted(report).deliver_later
|
33
|
+
}
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
### Setting Up Models
|
40
|
+
|
41
|
+
Include the Report module in your model:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class TimeReport < ApplicationRecord
|
45
|
+
include ReportableRails::Models::Report
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
This will add the following associations and functionality to your model:
|
50
|
+
- `belongs_to :owner` (user who owns the report)
|
51
|
+
- `belongs_to :report_category` (optional categorization)
|
52
|
+
- `has_many :hours_logs` (time entries for the report)
|
53
|
+
|
54
|
+
### Managing Hours Logs
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# Add hours to a report
|
58
|
+
report.add_hours_log({
|
59
|
+
hours: 8,
|
60
|
+
date: Date.current,
|
61
|
+
description: 'Project work'
|
62
|
+
})
|
63
|
+
|
64
|
+
# Remove hours from a report
|
65
|
+
report.remove_hours_log(hours_log_id)
|
66
|
+
```
|
67
|
+
|
68
|
+
### Period Management
|
69
|
+
|
70
|
+
The gem includes built-in period management with bi-monthly periods (1st-15th and 16th-end of month):
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
# Get current period dates
|
74
|
+
start_date = report.current_period_start_date
|
75
|
+
end_date = report.current_period_end_date
|
76
|
+
|
77
|
+
# Get hours for current period
|
78
|
+
current_hours = report.current_period_hours
|
79
|
+
|
80
|
+
# Submit current period report
|
81
|
+
report.submit_current_period_report!
|
82
|
+
```
|
83
|
+
|
84
|
+
### Report Categories
|
85
|
+
|
86
|
+
Reports can be optionally categorized:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
report = TimeReport.create!(
|
90
|
+
owner: current_user,
|
91
|
+
report_category: ReportableRails::ReportCategory.find_by(name: 'Project Work')
|
92
|
+
)
|
93
|
+
```
|
94
|
+
|
95
|
+
## License
|
96
|
+
|
97
|
+
The gem is available as open source under the terms of the MIT License.
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module ReportableRails
|
2
|
+
module Models
|
3
|
+
module Report
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
belongs_to :owner, class_name: ReportableRails.configuration.user_class
|
8
|
+
belongs_to :report_category, class_name: 'ReportableRails::ReportCategory', optional: true
|
9
|
+
has_many :hours_logs, class_name: 'ReportableRails::HoursLog', dependent: :destroy
|
10
|
+
|
11
|
+
validates :owner, presence: true
|
12
|
+
|
13
|
+
def add_hours_log(hours_log_params)
|
14
|
+
hours_logs.create(hours_log_params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def remove_hours_log(hours_log_id)
|
18
|
+
hours_logs.find_by(id: hours_log_id)&.destroy
|
19
|
+
end
|
20
|
+
|
21
|
+
def current_period_start_date
|
22
|
+
if Date.current.day <= 15
|
23
|
+
Date.current.beginning_of_month
|
24
|
+
else
|
25
|
+
Date.current.beginning_of_month + 15.days
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def current_period_end_date
|
30
|
+
if Date.current.day <= 15
|
31
|
+
Date.current.beginning_of_month + 15.days
|
32
|
+
else
|
33
|
+
Date.current.end_of_month
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def submit_current_period_report!
|
38
|
+
return false if current_period_hours.empty?
|
39
|
+
|
40
|
+
ReportableRails.configuration.report_submitted_callback&.call(self)
|
41
|
+
true
|
42
|
+
rescue StandardError => e
|
43
|
+
Rails.logger.error("Failed to submit current period report: #{e.message}")
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
def current_period_hours
|
48
|
+
hours_logs.select(&:current_period?)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/engine'
|
4
|
+
require 'active_model_serializers'
|
5
|
+
require 'reportable_rails/version'
|
6
|
+
|
7
|
+
module ReportableRails
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
class Engine < ::Rails::Engine
|
11
|
+
isolate_namespace ReportableRails
|
12
|
+
|
13
|
+
initializer 'reportable_rails.initialize' do |app|
|
14
|
+
# Add any initialization code here
|
15
|
+
end
|
16
|
+
|
17
|
+
config.generators do |g|
|
18
|
+
g.test_framework :rspec
|
19
|
+
g.fixture_replacement :factory_bot
|
20
|
+
g.factory_bot dir: 'spec/factories'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Configuration
|
25
|
+
class << self
|
26
|
+
attr_accessor :configuration
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.configure
|
30
|
+
self.configuration ||= Configuration.new
|
31
|
+
yield(configuration)
|
32
|
+
end
|
33
|
+
|
34
|
+
class Configuration
|
35
|
+
attr_accessor :user_class, :default_category_name
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
@user_class = 'User'
|
39
|
+
@default_category_name = 'Uncategorized'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reportable_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicu Listana
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: rails
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '6.1'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '6.1'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: active_model_serializers
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: sqlite3
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rspec-rails
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: factory_bot_rails
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: faker
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
description: ReportableRails provides a complete solution for managing user reports,
|
97
|
+
hours logging, and report categories in Ruby on Rails applications
|
98
|
+
email:
|
99
|
+
- nicu@adoboenterprisesus.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- README.md
|
105
|
+
- lib/reportable_rails.rb
|
106
|
+
- lib/reportable_rails/models/report.rb
|
107
|
+
- lib/reportable_rails/version.rb
|
108
|
+
homepage: https://github.com/adobocorp/reportable_rails
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubygems_version: 3.6.9
|
127
|
+
specification_version: 4
|
128
|
+
summary: A Rails engine for handling user reports and hours logging
|
129
|
+
test_files: []
|