Skip to content

Commit

Permalink
Add Bookmark switch to Moments and Strategies (ifmeorg#1727)
Browse files Browse the repository at this point in the history
* Display contributors as a table

* Use grids.scss to display contributors as  table

* Update grids.scss

* Update contribute.html.erb

* Update gridThreeItemAlways()

* Add bookmark switch

* Resolve conflict

* Update grids.scss

* Remove trailing spaces

* Add translation

* Modified tests

* Update moments_form_helper.rb

* Update strategies_form_helper.rb

* Hide bookmarks in production

* Update strategies_helper.rb

* Remove bookmark tests

* Remove bookmark tests

* Update moments_form_helper.rb

* Update strategies_helper.rb

* Replace nil with empty braces

* Replace nil with {}

Co-authored-by: Manasa2850 <[email protected]>
  • Loading branch information
GayathriVenkatesh and Manasa2850 committed Apr 25, 2020
1 parent 9dc29d8 commit 4552312
Show file tree
Hide file tree
Showing 22 changed files with 81 additions and 38 deletions.
4 changes: 2 additions & 2 deletions app/controllers/concerns/strategies_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def premade_strategy

def strategy_params
params.require(:strategy).permit(
:name, :description, :published_at, :draft,
:comment, { category: [] }, { viewers: [] }, :visible,
:name, :description, :published_at, :draft, :comment,
{ category: [] }, { viewers: [] }, :visible, :bookmarked,
perform_strategy_reminder_attributes: %i[active id]
)
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/moments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def set_moment

def moment_params
params.require(:moment).permit(:name, :why, :fix, :comment, :draft,
:bookmarked,
category: [], mood: [], viewers: [],
strategy: [])
end
Expand Down
28 changes: 17 additions & 11 deletions app/helpers/moments_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,36 @@ def moment_strategy
def moment_comment
moment_input_props('comment', 'switch', 'comment.allow_comments')
.merge(value: true,
uncheckedValue: false,
checked: @moment.comment,
info: t('comment.hint'),
dark: true)
uncheckedValue: false, checked: @moment.comment,
info: t('comment.hint'), dark: true)
end

def moment_publishing
{ id: 'moment_publishing',
type: 'switch',
{ id: 'moment_publishing', type: 'switch',
label: t('moments.form.draft_question'),
dark: true,
name: 'publishing',
value: '0',
uncheckedValue: '1',
dark: true, name: 'publishing',
value: '0', uncheckedValue: '1',
checked: !@moment.published? }
end

def moment_bookmarked
moment_input_props('bookmarked', 'switch', 'moments.bookmark')
.merge(
value: true,
uncheckedValue: false,
checked: @moment.bookmarked,
dark: true
)
end

def moment_form_inputs
[
moment_name, moment_why, moment_fix, moment_category, moment_mood,
moment_strategy, get_viewers_input(
@viewers, 'moment', 'moments', @moment
),
moment_comment, moment_publishing
moment_comment, moment_publishing,
Rails.env.development? ? moment_bookmarked : {}
]
end

Expand Down
44 changes: 20 additions & 24 deletions app/helpers/strategies_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,27 @@ module StrategiesFormHelper

def build_strategy_name(strategy)
{
id: 'strategy_name',
type: 'text',
name: 'strategy[name]',
label: t('common.name'),
id: 'strategy_name', type: 'text',
name: 'strategy[name]', label: t('common.name'),
value: strategy.name || nil,
placeholder: t('strategies.form.name_hint'),
required: true,
dark: true
required: true, dark: true
}
end

def build_strategy_description(strategy)
{
id: 'strategy_description',
type: 'textarea',
id: 'strategy_description', type: 'textarea',
name: 'strategy[description]',
label: t('strategies.form.describe'),
value: strategy.description || nil,
required: true,
dark: true
required: true, dark: true
}
end

def build_strategy_category
{
id: 'strategy_category',
type: 'quickCreate',
id: 'strategy_category', type: 'quickCreate',
name: 'strategy[category][]',
label: t('categories.plural'),
placeholder: t('common.form.search_by_keywords'),
Expand All @@ -46,8 +40,7 @@ def build_strategy_reminder(strategy)
name: 'strategy[perform_strategy_reminder_attributes][active]',
label: t('common.daily_reminder'),
info: t('strategies.form.daily_reminder_hint'),
value: true,
uncheckedValue: false,
value: true, uncheckedValue: false,
checked: strategy&.perform_strategy_reminder&.active,
dark: true
}
Expand All @@ -64,25 +57,29 @@ def build_strategy_reminder_attributes(strategy)

def build_strategy_comment(strategy)
build_switch_input(true, strategy.comment, false).merge(
id: 'strategy_comment',
name: 'strategy[comment]',
label: t('comment.allow_comments'),
info: t('comment.hint')
id: 'strategy_comment', name: 'strategy[comment]',
label: t('comment.allow_comments'), info: t('comment.hint')
)
end

def build_strategy_publishing(strategy)
build_switch_input('0', !strategy.published?, '1').merge(
id: 'strategy_publishing',
name: 'publishing',
id: 'strategy_publishing', name: 'publishing',
label: t('strategies.form.draft_question')
)
end

def build_strategy_bookmarked(strategy)
build_switch_input(true, strategy.bookmarked, false)
.merge(
id: 'strategy_bookmarked', name: 'strategy[bookmarked]',
label: t('strategies.bookmark')
)
end

def build_strategy_visible(strategy)
build_switch_input(true, strategy.visible, false).merge(
id: 'strategy_visible',
name: 'strategy[visible]',
id: 'strategy_visible', name: 'strategy[visible]',
label: t('shared.stats.visible_in_stats')
)
end
Expand All @@ -91,8 +88,7 @@ def build_strategy_visible(strategy)

def build_switch_input(value, checked, unchecked_value)
{
type: 'switch',
value: value,
type: 'switch', value: value,
uncheckedValue: unchecked_value,
checked: checked,
dark: true
Expand Down
1 change: 1 addition & 0 deletions app/helpers/strategies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def strategy_form_inputs(strategy, viewers)
get_viewers_input(viewers, 'strategy', 'strategies', strategy),
build_strategy_comment(strategy), build_strategy_publishing(strategy),
build_strategy_visible(strategy),
Rails.env.development? ? build_strategy_bookmarked(strategy) : {},
build_strategy_reminder(strategy).merge(type: 'checkbox'),
build_strategy_reminder_attributes(strategy)]
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/moment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# secret_share_identifier :uuid
# secret_share_expires_at :datetime
# published_at :datetime
# bookmarked :boolean
#

class Moment < ApplicationRecord
Expand All @@ -42,6 +43,7 @@ class Moment < ApplicationRecord
has_many :strategies, through: :moments_strategies

validates :comment, inclusion: [true, false]
validates :bookmarked, inclusion: [true, false]
validates :user_id, :name, :why, presence: true
validates :why, length: { minimum: 1 }
validates :secret_share_expires_at,
Expand Down
1 change: 1 addition & 0 deletions app/models/strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# slug :string
# published_at :datetime
# visible :boolean
# bookmarked :boolean
#

class Strategy < ApplicationRecord
Expand Down
2 changes: 2 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ de:
edit_moment: 'Moment bearbeiten'
tagged_moments: 'Getaggte Momente'
new: 'Neuer Moment'
bookmark: 'Lesezeichen'
secret_share:
singular: 'Geheimnis teilen'
expires_at: 'Läuft ab am'
Expand Down Expand Up @@ -993,6 +994,7 @@ de:
edit_strategy: 'Strategie bearbeiten'
tagged_strategies: 'Gekennzeichnete Strategien'
new: 'Neue Strategie'
bookmark: 'Lesezeichen'
form:
describe: 'Beschreibe deine Strategie.'
strategies_label: >-
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ en:
edit_moment: 'Edit Moment'
tagged_moments: 'Tagged Moments'
new: 'New Moment'
bookmark: 'Bookmark this moment?'
secret_share:
singular: 'Secret Share'
expires_at: 'Expire at'
Expand Down Expand Up @@ -924,6 +925,7 @@ en:
edit_strategy: 'Edit Strategy'
tagged_strategies: 'Tagged Strategies'
new: 'New Strategy'
bookmark: 'Bookmark this strategy?'
form:
describe: 'Describe the strategy.'
strategies_label: 'What strategies would help achieve these thoughts?'
Expand Down
2 changes: 2 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ es:
edit_moment: 'Editar Momento'
tagged_moments: 'Etiquetar Momento'
new: 'Nuevo Momento'
bookmark: 'Marcador'
secret_share:
singular: 'Compartir en Secreto'
expires_at: 'Caduca en'
Expand Down Expand Up @@ -823,6 +824,7 @@ es:
edit_strategy: 'Editar estrategia'
tagged_strategies: 'Estrategias etiquetadas'
new: 'Nueva estrategia'
bookmark: 'Marcador'
form:
describe: 'Describir estrategia'
strategies_label: '¿Qué estrategias ayudarían a conseguir estos
Expand Down
2 changes: 2 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ fr:
edit_moment: 'Modifier le moment'
tagged_moments: 'Moments étiquetés'
new: 'Nouveau moment'
bookmark: 'Signet'
secret_share:
singular: 'Partage de secret'
expires_at: 'Expire le'
Expand Down Expand Up @@ -966,6 +967,7 @@ fr:
edit_strategy: 'Modifier la stratégie'
tagged_strategies: 'Stratégies étiquetées'
new: 'Nouvelle stratégie'
bookmark: 'Signet'
form:
describe: 'Décrire la stratégie.'
strategies_label: >-
Expand Down
2 changes: 2 additions & 0 deletions config/locales/hi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ hi:
edit_moment: 'क्षण संपादित करें'
tagged_moments: 'टैग किए गए लम्हें'
new: 'नया पल'
bookmark: 'बुकमार्क'
secret_share:
singular: 'गुप्त हिस्सा'
expires_at: 'पर समाप्त'
Expand Down Expand Up @@ -760,6 +761,7 @@ hi:
edit_strategy: 'रणनीति संपादित करें'
tagged_strategies: 'टैग की गईं रणनीतियाँ'
new: 'नई रणनीति'
bookmark: 'बुकमार्क'
form:
describe: 'रणनीति का वर्णन करें।'
strategies_label: 'क्या रणनीति इन विचारों को प्राप्त करने में मदद करेगी?'
Expand Down
2 changes: 2 additions & 0 deletions config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ it:
edit_moment: 'Modifica Momento'
tagged_moments: 'Momenti taggati'
new: 'Nuovo Momento'
bookmark: 'Segnalibro'
secret_share:
singular: 'Condivisione Segreta'
expires_at: Scadenza
Expand Down Expand Up @@ -818,6 +819,7 @@ it:
edit_strategy: 'Modifica Strategia'
tagged_strategies: 'Strategie Taggate'
new: 'Nuova Strategia'
bookmark: 'Segnalibro'
form:
describe: 'Descrivi la Strategia.'
strategies_label: 'Quali strategie ti aiuterebbero a porti in questo modo?'
Expand Down
2 changes: 2 additions & 0 deletions config/locales/nb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ nb:
edit_moment: 'Rediger øyeblikk'
tagged_moments: 'tag øyeblikk'
new: 'Nytt øyeblikk'
bookmark: 'Bookmark'
secret_share:
singular: 'Hemmelig deling'
expires_at: Utløper
Expand Down Expand Up @@ -811,6 +812,7 @@ nb:
edit_strategy: 'Rediger strategi'
tagged_strategies: 'Taggede strategier'
new: 'Ny strategi'
bookmark: 'Bookmark'
form:
describe: 'Beskriv strategien.'
strategies_label: 'Hvilke strategier kan hjelpe deg oppnå disse tankene?'
Expand Down
2 changes: 2 additions & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ nl:
edit_moment: 'Bewerk Moment'
tagged_moments: 'Getagde Momenten'
new: 'Nieuw Moment'
bookmark: 'Bladwijzer'
secret_share:
singular: 'Geheim Delen'
expires_at: 'Verloopt op'
Expand Down Expand Up @@ -826,6 +827,7 @@ nl:
edit_strategy: 'Bewerk Strategie'
tagged_strategies: 'Getagde Strategieën'
new: 'Nieuwe Strategie'
bookmark: 'Bladwijzer'
form:
describe: 'Omschrijf de Strategie.'
strategies_label: 'Welke Strategieën zouden helpen deze gedachten te
Expand Down
2 changes: 2 additions & 0 deletions config/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ pt-BR:
edit_moment: 'Editar momento'
tagged_moments: 'Momentos com tags'
new: 'Novo momento'
bookmark: 'Marca páginas'
secret_share:
singular: 'Compartilhar segredo'
expires_at: 'Expirar em'
Expand Down Expand Up @@ -848,6 +849,7 @@ pt-BR:
edit_strategy: 'Editar Estratégia'
tagged_strategies: 'Estratégias marcadas'
new: 'Nova Estratégia'
bookmark: 'Marca páginas'
form:
describe: 'Descreva a estratégia'
strategies_label: 'Quais estratégias poderiam te ajudar a alcançar suas
Expand Down
2 changes: 2 additions & 0 deletions config/locales/sv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ sv:
edit_moment: 'Redigera Ögonblick'
tagged_moments: 'Taggade Ögonblick'
new: 'Nya Ögonblick'
bookmark: 'Bokmärke'
secret_share:
singular: 'Hemlig Andel'
expires_at: 'Förfaller vid'
Expand Down Expand Up @@ -805,6 +806,7 @@ sv:
edit_strategy: 'Redigera Strategi'
tagged_strategies: 'Taggade Strategier'
new: 'Ny Strategi'
bookmark: 'Bokmärke'
form:
describe: 'Beskriv strategin.'
strategies_label: 'Vilka strategier skulle hjälpa till att uppnå dessa
Expand Down
2 changes: 2 additions & 0 deletions config/locales/vi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ vi:
edit_moment: 'Hiệu chỉnh khoản khắc'
tagged_moments: 'Những khoản khắc đã được ghi'
new: 'Khoản khắc mới'
bookmark: 'Đánh dấu trang'
secret_share:
singular: 'Chia sẻ bí mật'
expires_at: 'Hết hạn lúc'
Expand Down Expand Up @@ -819,6 +820,7 @@ vi:
edit_strategy: 'Chỉnh sửa chiến lược '
tagged_strategies: 'Gắn nhãn cho chiến lược'
new: 'Chiến lược mới'
bookmark: 'Đánh dấu trang'
form:
describe: 'Miêu tả chiến lược.'
strategies_label: 'Chiến lược nào sẽ giúp ban đạt được suy nghĩ này?'
Expand Down
2 changes: 2 additions & 0 deletions config/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ zh-CN:
edit_moment: '编辑片刻'
tagged_moments: '标记的时刻'
new: '新时刻'
bookmark: '书签'
secret_share:
singular: '秘密分享'
expires_at: '于到期'
Expand Down Expand Up @@ -714,6 +715,7 @@ zh-CN:
edit_strategy: '修改策略'
tagged_strategies: '标记策略'
new: '新策略'
bookmark: '书签'
form:
describe: '描述策略。'
strategies_label: '哪些策略可以帮助实现这些想法?'
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20200419063429_add_bookmarked_to_moments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddBookmarkedToMoments < ActiveRecord::Migration[5.2]
def change
add_column :moments, :bookmarked, :boolean, default: false
end
end
Loading

0 comments on commit 4552312

Please sign in to comment.