Module: ResourceViewHelper

Included in:
Kuppayam::BaseController
Defined in:
app/helpers/resource_view_helper.rb

Instance Method Summary collapse

Instance Method Details



7
8
9
# File 'app/helpers/resource_view_helper.rb', line 7

def delete_link(object)
  url_for(action: 'destroy', controller: object.class.to_s.tableize, id: object.id)
end

#display_featurable_buttons(object, **options) ⇒ Object



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'app/helpers/resource_view_helper.rb', line 333

def display_featurable_buttons(object, **options)
  
  begin
    object_feature_url = url_for(action: 'mark_as_featured', controller: object.class.to_s.tableize, id: object.id)
    object_unfeature_url = url_for(action: 'remove_from_featured', controller: object.class.to_s.tableize, id: object.id)
  rescue
    object_feature_url = ""
    object_unfeature_url = ""
  end

  options.reverse_merge!(
    feature_icon: 'fa fa-star',
    unfeature_icon: 'fa fa-star-o',
    
    feature_link: object_feature_url,
    unfeature_link: object_unfeature_url,
    
    feature_text: "Mark as Featured",
    unfeature_text: "Remove from Featured",
    
    feature_class: "btn btn-block btn-success btn-only-hover",
    unfeature_class: "btn btn-block btn-danger btn-only-hover",

    has_permission_to_edit: true
  )

  if @current_permission
    options[:has_permission_to_edit] = @current_permission.can_update?
  end

  links = []
  links << link_to(raw("<i class=\"#{options[:feature_icon]} mr-5\"></i> #{options[:feature_text]}"), options[:feature_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:feature_class]) unless object.featured? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:unfeature_icon]} mr-5\"></i> #{options[:unfeature_text]}"), options[:unfeature_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:unfeature_class]) if object.featured? && options[:has_permission_to_edit]
  raw(links.join(""))
end


159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'app/helpers/resource_view_helper.rb', line 159

def display_featurable_links(object, **options)

  begin
    object_feature_url = url_for(action: 'mark_as_featured', controller: object.class.to_s.tableize, id: object.id)
    object_unfeature_url = url_for(action: 'remove_from_featured', controller: object.class.to_s.tableize, id: object.id)
  rescue
    object_feature_url = ""
    object_unfeature_url = ""
  end

  options.reverse_merge!(
      feature_icon: 'fa fa-star',
      unfeature_icon: 'fa fa-star-o',
      
      feature_link: object_feature_url,
      unfeature_link: object_unfeature_url,
      
      feature_text: "Mark as Featured",
      unfeature_text: "Remove from Featured",
      
      feature_class: "edit",
      unfeature_class: "delete",

      has_permission_to_edit: true
  )
  
  if @current_permission
    options[:has_permission_to_edit] = @current_permission.can_update?
  end

  links = []
  links << link_to(raw("<i class=\"#{options[:feature_icon]} mr-5\"></i> #{options[:feature_text]}"), options[:feature_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:feature_class]) unless object.featured? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:unfeature_icon]} mr-5\"></i> #{options[:unfeature_text]}"), options[:unfeature_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:unfeature_class]) if object.featured? && options[:has_permission_to_edit]
  raw(links.join(""))
end


32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/resource_view_helper.rb', line 32

def display_featured(object, **options)
  options.reverse_merge!(
    span_class: 'mr-5 mt-5 label',
  )
  if object.featured?
    (:span, "Featured", class: "#{options[:span_class]} label-warning")
  else
    (:span, "Not Featured", class: "#{options[:span_class]} label-default")
  end
end

#display_manage_buttons(object, **options) ⇒ Object



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'app/helpers/resource_view_helper.rb', line 369

def display_manage_buttons(object, **options)

  begin
    object_edit_url = url_for(action: "edit", controller: object.class.to_s.tableize, id: object.id)
    object_delete_url = url_for(action: "destroy", controller: object.class.to_s.tableize, id: object.id)
  rescue
    object_edit_url = ""
    object_delete_url = ""
  end

  options.reverse_merge!(
    edit_icon: 'fa fa-edit',
    delete_icon: 'fa fa-trash',
    
    edit_link: object_edit_url,
    delete_link: object_delete_url,
    
    edit_text: "Edit",
    delete_text: "Delete",
    
    edit_class: "btn btn-block btn-success",
    delete_class: "btn btn-block btn-danger btn-only-hover"
  )
  links = []
  links << link_to(raw("<i class=\"#{options[:edit_icon]} mr-5\"></i> #{options[:edit_text]}"), options[:edit_link], remote: true, role: "menuitem", tabindex: "-1", class: options[:edit_class]) if object.can_be_edited?
  links << link_to(raw("<i class=\"#{options[:delete_icon]} mr-5\"></i> #{options[:delete_text]}"), options[:delete_link], method: 'DELETE', remote: true, role: "menuitem", tabindex: "-1", class: options[:delete_class]) if object.can_be_deleted?
  raw(links.join(""))
end


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'app/helpers/resource_view_helper.rb', line 195

def display_manage_links(object, current_user, **options)

  begin
    object_edit_url = url_for(action: "edit", controller: object.class.to_s.tableize, id: object.id)
    object_delete_url = url_for(action: "destroy", controller: object.class.to_s.tableize, id: object.id)
  rescue
    object_edit_url = ""
    object_delete_url = ""
  end

  options.reverse_merge!(
    edit_icon: 'fa fa-edit',
    delete_icon: 'fa fa-trash',
    
    edit_link: object_edit_url,
    delete_link: object_delete_url,
    
    edit_text: "Edit",
    delete_text: "Delete",
    
    edit_class: "edit",
    delete_class: "",

    has_permission_to_edit: true,
    has_permission_to_delete: true
  )

  if @current_permission
    options[:has_permission_to_edit] = @current_permission.can_update?
    options[:has_permission_to_delete] = @current_permission.can_delete?
  end

links = []
  links << link_to(raw("<i class=\"#{options[:edit_icon]} mr-5\"></i> #{options[:edit_text]}"), options[:edit_link], remote: true, role: "menuitem", tabindex: "-1", class: options[:edit_class]) if object.can_be_edited? && options[:has_permission_to_edit] 
  links << link_to(raw("<i class=\"#{options[:delete_icon]} mr-5\"></i> #{options[:delete_text]}"), options[:delete_link], method: 'DELETE', remote: true, role: "menuitem", tabindex: "-1", class: options[:delete_class]) if object.can_be_deleted? && options[:has_permission_to_delete]
  raw(links.join(""))
end

#display_publishable_buttons(object, **options) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'app/helpers/resource_view_helper.rb', line 233

def display_publishable_buttons(object, **options)

  begin
    object_publish_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "published")
    object_unpublish_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "unpublished")
    object_remove_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "removed")
    object_archive_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "archived")
  rescue
    object_publish_url = ""
    object_unpublish_url = ""
    object_remove_url = ""
    object_archive_url = ""
  end

  options.reverse_merge!(
    publish_icon: 'fa fa-check-square',
    unpublish_icon: 'fa fa-square',
    remove_icon: 'fa fa-close',
    archive_icon: 'fa fa-archive',
    
    publish_link: object_publish_url,
    unpublish_link: object_unpublish_url,
    remove_link: object_remove_url,
    archive_link: object_archive_url,
    
    publish_text: "Publish",
    unpublish_text: "UnPublish",
    remove_text: "Remove",
    archive_text: "Archive",
    
    publish_class: "btn btn-block btn-success btn-only-hover",
    unpublish_class: "btn btn-block btn-gray btn-only-hover",
    remove_class: "btn btn-block btn-danger btn-only-hover",
    archive_class: "btn btn-block btn-gray btn-only-hover",

    has_permission_to_edit: true
  )

  if @current_permission
    options[:has_permission_to_edit] = @current_permission.can_update?
  end

  links = []
  links << link_to(raw("<i class=\"#{options[:publish_icon]} mr-5\"></i> #{options[:publish_text]}"), options[:publish_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:publish_class]) if object.can_publish? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:unpublish_icon]} mr-5\"></i> #{options[:unpublish_text]}"), options[:unpublish_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:unpublish_class]) if object.can_unpublish? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:remove_icon]} mr-5\"></i> #{options[:remove_text]}"), options[:remove_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:remove_class]) if object.can_remove? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:archive_icon]} mr-5\"></i> #{options[:archive_text]}"), options[:archive_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:archive_class]) if object.can_archive? && options[:has_permission_to_edit]
  raw(links.join(""))
end


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/helpers/resource_view_helper.rb', line 59

def display_publishable_links(object, **options)

  begin
    object_publish_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "published")
    object_unpublish_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "unpublished")
    object_remove_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "removed")
    object_archive_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "archived")
  rescue
    object_publish_url = ""
    object_unpublish_url = ""
    object_remove_url = ""
    object_archive_url = ""
  end

  options.reverse_merge!(
      publish_icon: 'fa fa-check-square',
      unpublish_icon: 'fa fa-square',
      remove_icon: 'fa fa-close',
      archive_icon: 'fa fa-archive',
      
      publish_link: object_publish_url,
      unpublish_link: object_unpublish_url,
      remove_link: object_remove_url,
      archive_link: object_archive_url,
      
      publish_text: "Publish",
      unpublish_text: "UnPublish",
      remove_text: "Remove",
      archive_text: "Archive",
      
      publish_class: "edit",
      unpublish_class: "",
      remove_class: "delete",
      archive_class: "",

      has_permission_to_edit: true
  )
  
  if @current_permission
    options[:has_permission_to_edit] = @current_permission.can_update?
  end

links = []
  links << link_to(raw("<i class=\"#{options[:publish_icon]} mr-5\"></i> #{options[:publish_text]}"), options[:publish_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:publish_class]) if object.can_publish? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:unpublish_icon]} mr-5\"></i> #{options[:unpublish_text]}"), options[:unpublish_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:unpublish_class]) if object.can_unpublish? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:remove_icon]} mr-5\"></i> #{options[:remove_text]}"), options[:remove_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:remove_class]) if object.can_remove? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:archive_icon]} mr-5\"></i> #{options[:archive_text]}"), options[:archive_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:archive_class]) if object.can_archive? && options[:has_permission_to_edit]
  raw(links.join(""))
end

#display_publishable_status(object, **options) ⇒ Object



43
44
45
46
47
48
49
# File 'app/helpers/resource_view_helper.rb', line 43

def display_publishable_status(object, **options)
  options.reverse_merge!(
     span_class: 'mr-5 mt-5 label',
   )
   label_class = Publishable::STATUS_UI_CLASS[object.status]
  (:span, object.display_status, class: "#{options[:span_class]} label-#{label_class}")
end

#display_readable_buttons(object, **options) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'app/helpers/resource_view_helper.rb', line 283

def display_readable_buttons(object, **options)

  begin
    object_read_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "read")
    object_unread_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "unread")
    object_remove_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "removed")
    object_archive_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "archived")
  rescue
    object_read_url = ""
    object_unread_url = ""
    object_remove_url = ""
    object_archive_url = ""
  end

  options.reverse_merge!(
      read_icon: 'fa fa-check-square-o',
      unread_icon: 'fa fa-square-o',
      remove_icon: 'fa fa-trash',
      archive_icon: 'fa fa-archive',
      
      read_link: object_read_url,
      unread_link: object_unread_url,
      remove_link: object_remove_url,
      archive_link: object_archive_url,
      
      read_text: "Mark as Read",
      unread_text: "Mark as Unread",
      remove_text: "Remove",
      archive_text: "Archive",
      
      read_class: "btn btn-block btn-success btn-only-hover",
      unread_class: "btn btn-block btn-gray btn-only-hover",
      remove_class: "btn btn-block btn-danger btn-only-hover",
      archive_class: "btn btn-block btn-gray btn-only-hover",

      has_permission_to_edit: true
  )
  
  if @current_permission
    options[:has_permission_to_edit] = @current_permission.can_update?
  end

  links = []
  links << link_to(raw("<i class=\"#{options[:read_icon]} mr-5\"></i> #{options[:read_text]}"), options[:read_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:read_class]) if object.can_read? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:unread_icon]} mr-5\"></i> #{options[:unread_text]}"), options[:unread_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:unread_class]) if object.can_unread? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:remove_icon]} mr-5\"></i> #{options[:remove_text]}"), options[:remove_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:remove_class]) if object.can_remove? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:archive_icon]} mr-5\"></i> #{options[:archive_text]}"), options[:archive_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:archive_class]) if object.can_archive? && options[:has_permission_to_edit]
  raw(links.join(""))
end


109
110
111
112
113
114
115
116
117
118
119
120
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
153
154
155
156
157
# File 'app/helpers/resource_view_helper.rb', line 109

def display_readable_links(object, **options)

  begin
    object_read_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "read")
    object_unread_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "unread")
    object_remove_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "removed")
    object_archive_url = url_for(action: 'update_status', controller: object.class.to_s.tableize, id: object.id, status: "archived")
  rescue
    object_read_url = ""
    object_unread_url = ""
    object_remove_url = ""
    object_archive_url = ""
  end
  
  options.reverse_merge!(
      read_icon: 'fa fa-check-square-o',
      unread_icon: 'fa fa-square-o',
      remove_icon: 'fa fa-trash',
      archive_icon: 'fa fa-archive',
      
      read_link: object_read_url,
      unread_link: object_unread_url,
      remove_link: object_remove_url,
      archive_link: object_archive_url,
      
      read_text: "Read",
      unread_text: "Unread",
      remove_text: "Remove",
      archive_text: "Archive",
      
      read_class: "",
      unread_class: "",
      remove_class: "delete",
      archive_class: "",

      has_permission_to_edit: true
  )
  
  if @current_permission
    options[:has_permission_to_edit] = @current_permission.can_update?
  end

  links = []
  links << link_to(raw("<i class=\"#{options[:read_icon]} mr-5\"></i> #{options[:read_text]}"), options[:read_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:read_class]) if object.can_read? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:unread_icon]} mr-5\"></i> #{options[:unread_text]}"), options[:unread_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:unread_class]) if object.can_unread? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:remove_icon]} mr-5\"></i> #{options[:remove_text]}"), options[:remove_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:remove_class]) if object.can_remove? && options[:has_permission_to_edit]
  links << link_to(raw("<i class=\"#{options[:archive_icon]} mr-5\"></i> #{options[:archive_text]}"), options[:archive_link], method: 'PUT', remote: true, role: "menuitem", tabindex: "-1", class: options[:archive_class]) if object.can_archive? && options[:has_permission_to_edit]
  raw(links.join(""))
end

#display_readable_status(object, **options) ⇒ Object



51
52
53
54
55
56
57
# File 'app/helpers/resource_view_helper.rb', line 51

def display_readable_status(object, **options)
  options.reverse_merge!(
    span_class: 'mr-5 mt-5 label',
  )
  label_class = Readable::STATUS_UI_CLASS[object.status]
  (:span, object.display_status, class: "#{options[:span_class]} label-#{label_class}")
end

#display_thumbnail(object, **options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/resource_view_helper.rb', line 19

def display_thumbnail(object, **options)
  options.reverse_merge!(
    method_name: "cover_image.image.small.url",
    image_class: "img-rectangle",
    image_width: "120",
    image_height: "auto",
  )
  url = url_for(action: 'show', controller: object.class.to_s.tableize, id: object.id)
  link_to(url, remote: true) do
    raw(display_image(object, options[:method_name], width: options[:image_width], height: options[:image_height], class: options[:image_class], alt: object.display_name))
  end
end


3
4
5
# File 'app/helpers/resource_view_helper.rb', line 3

def edit_link(object)
  url_for(action: 'edit', controller: object.class.to_s.tableize, id: object.id)
end

#serial_number(i) ⇒ Object



11
12
13
14
15
16
17
# File 'app/helpers/resource_view_helper.rb', line 11

def serial_number(i)
  if i < 0
    raw((:i, "", class: "fa fa-check text-success"))
  else
    raw(i + 1 + (@per_page.to_i * (@current_page.to_i - 1)))
  end
end