Module: Card::Set::Self::Trash::HtmlFormat

Extended by:
AbstractFormat
Defined in:
platypus/tmp/set/gem-card/mod001-core/self/trash.rb

Instance Method Summary collapse

Instance Method Details



40
41
42
43
44
45
46
47
48
49
50
# File 'platypus/tmp/set/gem-card/mod001-core/self/trash.rb', line 40

def empty_trash_link
  wrap_with(
    :p,
    button_link("empty trash",
                btn_type: :default,
                path: { mark: :admin, action: :update, task: :empty_trash,
                        success: { mark: "~#{card.id}" } },
                "data-confirm" => "Are you sure you want to delete "\
                                  "all cards in the trash?")
  )
end


52
53
54
55
# File 'platypus/tmp/set/gem-card/mod001-core/self/trash.rb', line 52

def history_link trashed_card
  link_to_card trashed_card, "history",
               path: { view: :history, look_in_trash: true }
end


57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'platypus/tmp/set/gem-card/mod001-core/self/trash.rb', line 57

def restore_link trashed_card
  before_delete = trashed_card.actions[-2]
  link_to "restore", method: :post,
                     rel: "nofollow",
                     remote: true,
                     class: "slotter",
                     path: { id: trashed_card.id,
                             view: :open,
                             look_in_trash: true,
                             action: :update,
                             restore: trashed_card.id,
                             action_ids: [before_delete],
                             success: { mark: "~#{card.id}" } }
end

#restoredObject



31
32
33
34
35
36
37
38
# File 'platypus/tmp/set/gem-card/mod001-core/self/trash.rb', line 31

def restored
  return unless (res_id = Env.params[:restore]) &&
                (res_card = Card[res_id.to_i])

  alert :success, true do
    wrap_with(:h5, "restored") + subformat(res_card).render_bar
  end
end

#trash_table_row(card) ⇒ Object



22
23
24
25
26
27
28
29
# File 'platypus/tmp/set/gem-card/mod001-core/self/trash.rb', line 22

def trash_table_row card
  [
    card.name,
    "#{time_ago_in_words(card.updated_at)} ago",
    card.updater_id.cardname,
    "#{history_link(card)} | #{restore_link(card)}"
  ]
end

#trashed_cardsObject



18
19
20
# File 'platypus/tmp/set/gem-card/mod001-core/self/trash.rb', line 18

def trashed_cards
  Card.where(trash: true).order(updated_at: :desc)
end

#view: coreObject



9
10
11
12
13
14
15
16
# File 'platypus/tmp/set/gem-card/mod001-core/self/trash.rb', line 9

view :core do
  rows = trashed_cards.map { |tc| trash_table_row(tc) }
  output [
    restored,
    (empty_trash_link if rows.present?),
    table(rows, header: ["card", "deleted", "by", ""])
  ]
end