-
Notifications
You must be signed in to change notification settings - Fork 756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Track Progress on Strategies #1719
Changes from all commits
36cf917
e1430fb
06a14fd
7b1e9f3
fd45438
671c57c
b2fbf3f
130080c
201cf50
074fa4f
05ea003
b700bdd
e7ce1e1
a40700f
343d750
f793949
69fef40
1b625c5
4839cdd
06aa0fd
a986ce4
d2f9030
6c2a1b4
3d56560
fd883c3
6ee81d5
2ca7062
3cf1569
06bcd2f
1e088d4
719c25e
61c4502
15700e5
96a5301
0ec0bad
4b365c9
1089f6d
a8adbef
b360190
957f671
d001eb8
6d40000
dfa599d
f41b5b8
1656963
9d5c6d5
3b5f6a3
69b38aa
895707e
349021d
b2e87d3
2db2e2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class StrategiesController < ApplicationController | ||
include CollectionPageSetupConcern | ||
include ReminderHelper | ||
include StrategiesConcern | ||
include Shared | ||
include StrategiesConcern | ||
include MomentsHelper | ||
include TagsHelper | ||
|
||
|
@@ -94,12 +93,14 @@ def update | |
end | ||
empty_array_for :viewers, :category | ||
shared_update(@strategy, strategy_params) | ||
create_task(@strategy) | ||
end | ||
|
||
# DELETE /strategies/1 | ||
# DELETE /strategies/1.json | ||
def destroy | ||
shared_destroy(@strategy) | ||
Task.where(id: @strategy.id).destroy_all | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be testing for this new task functionality in the test for destroy. |
||
PerformStrategyReminder.where(strategy_id: @strategy.id).destroy_all | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class TasksController < ApplicationController | ||
Manasa2850 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
before_action :set_task | ||
|
||
def index | ||
@tasks = Task.all | ||
end | ||
|
||
private | ||
|
||
def set_task | ||
@task = Task.find(params[:id]) | ||
end | ||
|
||
def task_params | ||
params.require(:task).permit(:title, :description) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
# | ||
class TodoItemsController < ApplicationController | ||
Manasa2850 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
before_action :set_task | ||
|
||
def create | ||
@todo_item = @task.todo_items.create(todo_item_params) | ||
end | ||
|
||
private | ||
|
||
def set_task | ||
@task = TodoList.find(params[:task_id]) | ||
end | ||
|
||
def todo_item_params | ||
params[:todo_item].permit(:content) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module TasksHelper | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be unit testing this helper. |
||
def present_task(element) | ||
{ | ||
name: element.title, | ||
link: 'strategies/' + element.title.downcase.strip.tr(' ', '-') + '/edit', | ||
date: TimeAgo.created_or_edited(element), | ||
categories: slugs_hash('Followed ': element.no_of_days_followed.to_s + | ||
'/' + element.total_no_of_days.to_s + ' days') | ||
} | ||
end | ||
|
||
def task_props(elements) | ||
elements.map { |element| present_task(element) } | ||
end | ||
|
||
private | ||
|
||
def slugs_hash(data) | ||
data.map { |total_no_of_days| { name: total_no_of_days } } | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
# visible :boolean default(TRUE) | ||
# bookmarked :boolean default(FALSE) | ||
# | ||
|
||
class Strategy < ApplicationRecord | ||
include Viewer | ||
include CommonMethods | ||
|
@@ -70,4 +69,19 @@ def published? | |
def comments | ||
Comment.comments_from(self) | ||
end | ||
|
||
after_save :update_tasks_table | ||
|
||
private | ||
|
||
def update_tasks_table | ||
@task = Task.exists?(id) ? Task.find(id) : Task.new(id: id) | ||
@task.title = name | ||
@task.description = description | ||
@task.finished = finished | ||
@task.date = updated_at | ||
@task.no_of_days_followed = finished ? 1 : 0 | ||
@task.total_no_of_days = (created_at.to_date - Time.zone.today).to_i + 1 | ||
@task.save | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should handle errors in the event that save does not work. |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
# | ||
class Task < ApplicationRecord | ||
has_many :todo_items | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
# | ||
class TodoItem < ApplicationRecord | ||
belongs_to :task | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<% title t('tasks.plural') %> | ||
<%= react_component('BaseContainer', props: { | ||
container: 'StoryContainer', | ||
data: task_props(@tasks), | ||
fetchUrl: tasks_path, | ||
lastPage: true | ||
})%> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= form_for([@task, @task.todo_items.build]) do |f| %> | ||
<%= f.text_field :content, placeholder: "New Todo" %> | ||
<%= f.submit %> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<p><%= todo_item.content %></p> | ||
<%= link_to task_todo_item_path(@task, todo_item.id), method: :delete, data: { confirm: t('common.actions.confirm') } %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,16 @@ | |
lodash "^4.17.13" | ||
source-map "^0.5.0" | ||
|
||
"@babel/generator@^7.9.0": | ||
version "7.9.4" | ||
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.9.4.tgz#12441e90c3b3c4159cdecf312075bf1a8ce2dbce" | ||
integrity sha512-rjP8ahaDy/ouhrvCoU1E5mqaitWrxwuNGU+dy1EpaoK48jZay4MdkskKGIMHLZNewg8sAsqpGSREJwP0zH3YQA== | ||
dependencies: | ||
"@babel/types" "^7.9.0" | ||
jsesc "^2.5.1" | ||
lodash "^4.17.13" | ||
source-map "^0.5.0" | ||
|
||
"@babel/helper-annotate-as-pure@^7.8.3": | ||
version "7.8.3" | ||
resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.8.3.tgz#60bc0bc657f63a0924ff9a4b4a0b24a13cf4deee" | ||
|
@@ -281,6 +291,11 @@ | |
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.9.4.tgz#68a35e6b0319bbc014465be43828300113f2f2e8" | ||
integrity sha512-bC49otXX6N0/VYhgOMh4gnP26E9xnDZK3TmbNpxYzzz9BQLBosQwfyOe9/cXUU3txYhTzLCbcqd5c8y/OmCjHA== | ||
|
||
"@babel/parser@^7.7.5", "@babel/parser@^7.9.0": | ||
version "7.9.4" | ||
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.9.4.tgz#68a35e6b0319bbc014465be43828300113f2f2e8" | ||
integrity sha512-bC49otXX6N0/VYhgOMh4gnP26E9xnDZK3TmbNpxYzzz9BQLBosQwfyOe9/cXUU3txYhTzLCbcqd5c8y/OmCjHA== | ||
|
||
"@babel/plugin-proposal-async-generator-functions@^7.8.3": | ||
version "7.8.3" | ||
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.8.3.tgz#bad329c670b382589721b27540c7d288601c6e6f" | ||
|
@@ -938,6 +953,15 @@ | |
lodash "^4.17.13" | ||
to-fast-properties "^2.0.0" | ||
|
||
"@babel/types@^7.9.0": | ||
version "7.9.0" | ||
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.9.0.tgz#00b064c3df83ad32b2dbf5ff07312b15c7f1efb5" | ||
integrity sha512-BS9JKfXkzzJl8RluW4JGknzpiUV7ZrvTayM6yfqLTVBEnFtyowVIOu6rqxRd5cVO6yGoWf4T8u8dgK9oB+GCng== | ||
dependencies: | ||
"@babel/helper-validator-identifier" "^7.9.0" | ||
lodash "^4.17.13" | ||
to-fast-properties "^2.0.0" | ||
|
||
"@base2/[email protected]": | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/@base2/pretty-print-object/-/pretty-print-object-1.0.0.tgz#860ce718b0b73f4009e153541faff2cb6b85d047" | ||
|
@@ -8401,6 +8425,13 @@ json5@^2.1.1, json5@^2.1.2: | |
dependencies: | ||
minimist "^1.2.5" | ||
|
||
json5@^2.1.2: | ||
version "2.1.3" | ||
resolved "https://registry.yarnpkg.com/json5/-/json5-2.1.3.tgz#c9b0f7fa9233bfe5807fe66fcf3a5617ed597d43" | ||
integrity sha512-KXPvOm8K9IJKFM0bmdn8QXh7udDh1g/giieX0NLCaMnb4hEiVFqnop2ImTXCc5e0/oHz3LTqmHGtExn5hfMkOA== | ||
dependencies: | ||
minimist "^1.2.5" | ||
|
||
jsonfile@^2.1.0: | ||
version "2.4.0" | ||
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be testing for this new task functionality in the test for update.