-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update streaming * Refactor total cost to service * Lint
- Loading branch information
Showing
16 changed files
with
203 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stream | ||
include DashboardBuilder | ||
include TaxedIncome | ||
|
||
def render_respond_to(turbo_replace) | ||
respond_to do |format| | ||
format.turbo_stream do | ||
render turbo_stream: turbo_replace | ||
end | ||
end | ||
end | ||
|
||
def switch_to_hourly | ||
[ | ||
turbo_stream.replace("salary_budget", | ||
partial: "budget/hourly_budget", | ||
locals: build_locals(tax_on_hourly)) | ||
] | ||
end | ||
|
||
def switch_to_salary | ||
[ | ||
turbo_stream.replace("hourly_budget", | ||
partial: "budget/salary_budget", | ||
locals: build_locals(tax_on_salary)) | ||
] | ||
end | ||
|
||
def render_dashboard | ||
[ | ||
turbo_stream.replace("hourly_budget", | ||
partial: "budget/salary_budget", | ||
locals: build_locals(tax_on_salary)), | ||
turbo_stream.replace("salary_budget", | ||
partial: "budget/hourly_budget", | ||
locals: build_locals(tax_on_hourly)), | ||
turbo_stream.replace("total_costs", | ||
partial: "shared/total_costs", | ||
locals: { | ||
total_annual_cost: @total_annual_cost, | ||
total_monthly_cost: @total_monthly_cost, | ||
total_bi_weekly_cost: @total_bi_weekly_cost | ||
}), | ||
turbo_stream.replace("taxed_incomes", | ||
partial: "shared/taxed_incomes", | ||
locals: { | ||
salary_taxed: @salary_taxed, | ||
hourly_taxed: @hourly_taxed | ||
}) | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
class TotalCostCalculator | ||
attr_reader :annual_cost, | ||
:biannual_cost, | ||
:quarterly_cost, | ||
:monthly_cost, | ||
:bi_weekly_cost, | ||
:weekly_cost, | ||
:daily_cost | ||
|
||
def initialize(cost:) | ||
@annual_cost = cost | ||
@biannual_cost = calculate_biannual_cost | ||
@quarterly_cost = calculate_quarterly_cost | ||
@monthly_cost = calculate_monthly_cost | ||
@bi_weekly_cost = calculate_bi_weekly_cost | ||
@weekly_cost = calculate_weekly_cost | ||
@daily_cost = calculate_daily_cost | ||
end | ||
|
||
def calculate_biannual_cost | ||
@annual_cost / 2 | ||
end | ||
|
||
def calculate_quarterly_cost | ||
@annual_cost / 4 | ||
end | ||
|
||
def calculate_monthly_cost | ||
@annual_cost / 12 | ||
end | ||
|
||
def calculate_bi_weekly_cost | ||
@annual_cost / 26 | ||
end | ||
|
||
def calculate_weekly_cost | ||
@annual_cost / 52 | ||
end | ||
|
||
def calculate_daily_cost | ||
@annual_cost / 365 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
<%= turbo_stream.remove @fixed_expense %> | ||
|
||
<%= turbo_stream.replace "total_costs" do %> | ||
<%= render partial: "shared/total_costs", locals: { total_annual_cost: @total_annual_cost, total_monthly_cost: @total_monthly_cost, total_bi_weekly_cost: @total_bi_weekly_cost } %> | ||
<%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %> | ||
<% end %> | ||
|
||
<%= turbo_stream.replace "salary_budget" do %> | ||
<%= render partial: "budget/salary_budget", locals: {total_annual_cost: @total_annual_cost, total_monthly_cost: @total_monthly_cost, total_bi_weekly_cost: @total_bi_weekly_cost, income: @salary_taxed} %> | ||
<%= render partial: "budget/salary_budget", | ||
locals: { | ||
income: @salary_taxed, | ||
total_cost: @total_cost, | ||
investing_amount: @salary_invest, | ||
savings_amount: @salary_saving, | ||
guilt_free: @guilt_free_salary | ||
} | ||
%> | ||
<% end %> | ||
|
||
<%= turbo_stream.replace "hourly_budget" do %> | ||
<%= render partial: "budget/hourly_budget", locals: {total_annual_cost: @total_annual_cost, total_monthly_cost: @total_monthly_cost, total_bi_weekly_cost: @total_bi_weekly_cost, income: @hourly_taxed} %> | ||
<%= render partial: "budget/hourly_budget", | ||
locals: { | ||
income: @hourly_taxed, | ||
total_cost: @total_cost, | ||
investing_amount: @hourly_invest, | ||
savings_amount: @hourly_saving, | ||
guilt_free: @guilt_free_hourly | ||
} | ||
%> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.