Module: Workarea::Admin::ReleasesHelper

Defined in:
app/helpers/workarea/admin/releases_helper.rb

Instance Method Summary collapse

Instance Method Details

#calendar_day_classes(day) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
# File 'app/helpers/workarea/admin/releases_helper.rb', line 172

def calendar_day_classes(day)
  date = Date.parse(day)
  today = Time.zone.now.to_date

  classes = ['calendar__day']
  classes << 'calendar__day--odd-month'     if date.month.odd?
  classes << 'calendar__day--today'         if date == today
  classes << 'calendar__day--start-of-week' if date == date.beginning_of_week(start_day = :sunday)
  classes << 'calendar__day--end-of-week'   if date == date.end_of_week(start_day = :sunday)

  classes
end

#calendar_day_number(day) ⇒ Object



168
169
170
# File 'app/helpers/workarea/admin/releases_helper.rb', line 168

def calendar_day_number(day)
  Date.parse(day).day
end

#calendar_release_classes(day, release) ⇒ Object



185
186
187
188
189
190
191
192
193
194
# File 'app/helpers/workarea/admin/releases_helper.rb', line 185

def calendar_release_classes(day, release)
  date = Date.parse(day)

  classes = ['calendar__release']
  classes << 'calendar__release--start'   if release.published_on_date?(date)
  classes << 'calendar__release--end'     if release.ended_on_date?(date)
  classes << 'calendar__release--content' if release.content_release?

  classes
end

#calendar_release_styles(release) ⇒ Object



196
197
198
199
200
201
202
203
# File 'app/helpers/workarea/admin/releases_helper.rb', line 196

def calendar_release_styles(release)
  return if release.undo_at.blank?

  color = Digest::MD5.hexdigest(release.name)[0, 6]
  text_color = release_text_color(color)

  "background-color: ##{color}; color: ##{text_color};"
end


94
95
96
# File 'app/helpers/workarea/admin/releases_helper.rb', line 94

def category_links(ids)
  model_links(Catalog::Category, ids)
end

#change_display_value(value) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/workarea/admin/releases_helper.rb', line 69

def change_display_value(value)
  case value
  when FalseClass then t('workarea.admin.false')
  when TrueClass then t('workarea.admin.true')
  when DateTime, Time then value.to_s(:long)
  when Array then value.map { |v| change_display_value(v) }.join(', ')
  when Money then number_to_currency(value)
  else
    if UrlValidator.valid_url?(value)
      link_to truncate(value, length: 35), value, target: '_blank', rel: 'noopener'
    else
    value.to_s
    end
  end
end

#content_block_data_changes_from(old_data, new_data) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# File 'app/helpers/workarea/admin/releases_helper.rb', line 109

def content_block_data_changes_from(old_data, new_data)
  return {} if new_data.blank?
  locale = I18n.locale.to_s

  old_data = old_data[locale] if old_data.keys.include?(locale)
  new_data = new_data[locale] if new_data.keys.include?(locale)

  new_data.select do |key, value|
    old_data[key] != new_data[key]
  end
end


98
99
100
# File 'app/helpers/workarea/admin/releases_helper.rb', line 98

def discount_links(ids)
  model_links(Pricing::Discount, ids)
end

#for_each_content_block_from_changeset(content, change_hash) ⇒ Object



102
103
104
105
106
107
# File 'app/helpers/workarea/admin/releases_helper.rb', line 102

def for_each_content_block_from_changeset(content, change_hash)
  change_hash.each do |id, changes|
    block = content.blocks.detect { |b| b.id.to_s == id.to_s }
    yield(block, changes) if block.present?
  end
end

#month_and_year_from_date(date) ⇒ Object

Calendar classes



159
160
161
# File 'app/helpers/workarea/admin/releases_helper.rb', line 159

def month_and_year_from_date(date)
  "#{Date::MONTHNAMES[date.month]} #{date.year}"
end

#month_name_needed?(day, days) ⇒ Boolean

Returns:

  • (Boolean)


163
164
165
166
# File 'app/helpers/workarea/admin/releases_helper.rb', line 163

def month_name_needed?(day, days)
  return true if day == days.first.first
  return true if day.split('-').last == '01'
end

Custom change field helpers



90
91
92
# File 'app/helpers/workarea/admin/releases_helper.rb', line 90

def product_links(ids)
  model_links(Catalog::Product, ids)
end

#publishing_options_for_select(selected = current_release.try(:id)) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/workarea/admin/releases_helper.rb', line 18

def publishing_options_for_select(selected = current_release.try(:id))
  results = release_options.map do |release|
    [
      sanitize(
        t(
          'workarea.admin.releases.select.publish_with',
          release: release.name
        )
      ),
      release.id
    ]
  end

  now_option = [t('workarea.admin.releases.select.publishing_now'), :now]
  now_option << { data: { disable_publish_now: '' } } unless allow_publishing?
  results.unshift(now_option)

  options_for_select(results, selected)
end

#release_optionsObject



3
4
5
6
7
8
# File 'app/helpers/workarea/admin/releases_helper.rb', line 3

def release_options
  @release_options ||= ([current_release] + Release.upcoming.to_a)
                            .reject(&:blank?)
                            .uniq(&:id)
                            .map { |r| Admin::ReleaseViewModel.wrap(r) }
end

#release_options_for_select(selected = current_release.try(:id)) ⇒ Object



38
39
40
41
42
# File 'app/helpers/workarea/admin/releases_helper.rb', line 38

def release_options_for_select(selected = current_release.try(:id))
  results = release_options.map { |r| [r.name, r.id] }
  results.unshift([t('workarea.admin.releases.select.live_site'), nil])
  options_for_select(results, selected)
end

#release_select_attributesObject



10
11
12
13
14
15
16
# File 'app/helpers/workarea/admin/releases_helper.rb', line 10

def release_select_attributes
  css_class = ''
  css_class << 'release-select--active' if current_release.present?
  css_class << ' release-select--emphasize' if current_release_session.remind?

  { class: css_class, data: { release_reminder: '' } }
end

#render_changeset_field(changeset, field) ⇒ Object

Change helpers



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/workarea/admin/releases_helper.rb', line 49

def render_changeset_field(changeset, field)
  custom_partial = "workarea/admin/changesets/fields/_#{field}"

  partial = if lookup_context.find_all(custom_partial).present?
              "workarea/admin/changesets/fields/#{field}"
            else
              'workarea/admin/changesets/fields/generic'
            end

  options = {
    release: changeset.release,
    model: changeset.releasable,
    field: field,
    old_value: changeset.old_value_for(field),
    new_value: changeset.new_value_for(field)
  }

  render(partial, options)
end

#render_content_block_changes(old_data, new_data, prefixes = []) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'app/helpers/workarea/admin/releases_helper.rb', line 121

def render_content_block_changes(old_data, new_data, prefixes = [])
  new_data = content_block_data_changes_from(old_data, new_data)

  new_data.map do |field, value|
    if !value.present?
      nil
    elsif value.is_a?(Hash)
      render_content_block_changes(
        old_data[field],
        new_data[field],
        prefixes + [field],
        &block
      )
    else
      custom_partial = "workarea/admin/changesets/fields/data/_#{field}"

      partial = if lookup_context.find_all(custom_partial).present?
                  "workarea/admin/changesets/fields/data/#{field}"
                else
                  'workarea/admin/changesets/fields/data/generic'
                end

      options = {
        field: (prefixes + [field]).join(' '),
        old_value: old_data[field],
        new_value: new_data[field]
      }

      render(partial, options)
    end
  end.compact.join.html_safe
end