Module: Card::Set::All::HtmlError::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
card/tmpsets/set/mod008-card-mod-format/all/html_error.rb,
card/tmpsets/set/mod007-card-mod-format/all/html_error.rb

Instance Method Summary collapse

Instance Method Details



110
111
112
113
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 110

def backtrace_link cardname, exception
  # TODO: make this a modal link after new modal handling is merged in
  wrap_with(:span, title: error_message(exception)) { cardname }
end

#createableObject



26
27
28
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 26

def createable
  card.ok?(:create) ? yield : ""
end

#error_cardname(exception) ⇒ Object



89
90
91
92
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 89

def error_cardname exception
  cardname = super
  show_all_errors? ? backtrace_link(cardname, exception) : cardname
end

#error_message(exception) ⇒ Object



102
103
104
105
106
107
108
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 102

def error_message exception
  %{
    <h3>Error message (visible to admin only)</h3>
    <p><strong>#{CGI.escapeHTML exception.message}</strong></p>
    <div>#{exception.backtrace * "<br>\n"}</div>
  }
end

#error_modal_idObject



98
99
100
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 98

def error_modal_id
  @error_modal_id ||= unique_id
end

#loud_denialObject



171
172
173
174
175
176
177
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 171

def loud_denial
  voo.hide :menu
  frame do
    [wrap_with(:h1, tr(:sorry)),
     wrap_with(:div, loud_denial_message)]
  end
end

#loud_denial_messageObject



179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 179

def loud_denial_message
  to_task = @denied_task ? tr(:denied_task, denied_task: @denied_task) : tr(:to_do_that)

  case
  when not_denied_task_read?
    tr(:read_only)
  when Auth.signed_in?
    tr(:need_permission_task, task: to_task)
  else
    Env.save_interrupted_action request.env["REQUEST_URI"]
     to_do_unauthorized_task
  end
end

#not_denied_task_read?Boolean

Returns:

  • (Boolean)


193
194
195
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 193

def not_denied_task_read?
  @denied_task != :read && Card.config.read_only
end

#not_found_errorsObject



132
133
134
135
136
137
138
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 132

def not_found_errors
  if card.errors.any?
    standard_errors
  else
    haml :not_found
  end
end

#quiet_denialObject



165
166
167
168
169
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 165

def quiet_denial
  wrap_with :span, class: "denied" do
    "<!-- Sorry, you don't have permission (#{@denied_task}) -->"
  end
end

#rendering_error(exception, view) ⇒ Object



94
95
96
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 94

def rendering_error exception, view
  wrap_with(:span, class: "render-error alert alert-danger") { super }
end

#show_all_errors?Boolean

Returns:

  • (Boolean)


84
85
86
87
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 84

def show_all_errors?
  # make configurable by env
  Auth.always_ok? || Rails.env.development?
end


140
141
142
143
144
145
146
147
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 140

def  to_task
  return if Auth.signed_in?

  links = [, ].compact.join " #{tr :or} "
  wrap_with(:div) do
    [tr(:please), links, to_task].join(" ") + "."
  end
end


149
150
151
152
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 149

def 
  link_to_card :signin, tr(:sign_in),
               class: "signin-link", slotter: true, path: { view: :open }
end


154
155
156
157
158
159
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 154

def 
  return unless 

  link_to_card :signup, tr(:sign_up),
               class: "signup-link", slotter: true, path: { action: :new }
end

#signup_ok?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 161

def 
  Card.new(type_id: Card::SignupID).ok? :create
end

#simple_error_message(message) ⇒ Object



124
125
126
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 124

def simple_error_message message
  h message
end

#standard_error_message(error) ⇒ Object



128
129
130
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 128

def standard_error_message error
  "<p><strong>#{h error.attribute.to_s.upcase}:</strong> #{h error.message}</p>"
end

#standard_errors(heading = nil) ⇒ Object



115
116
117
118
119
120
121
122
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 115

def standard_errors heading=nil
  alert "warning", true do
    [
      (wrap_with(:h4, heading, class: "alert-heading error") if heading),
      error_messages.join("<hr>")
    ]
  end
end

#to_do_unauthorized_taskObject



197
198
199
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 197

def to_do_unauthorized_task
  @denied_task ? tr(:denied_task, denied_task: @denied_task) : tr(:to_do_that)
end

#unknown_iconObject



35
36
37
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 35

def unknown_icon
  fa_icon "plus-square"
end


30
31
32
33
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 30

def unknown_link text
  path_opts = voo.type ? { card: { type: voo.type } } : {}
  link_to_view :new_in_modal, text, path: path_opts, class: classy("unknown-link")
end

#view: compact_missingObject



39
40
41
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 39

view :compact_missing, perms: :none do
  wrap_with :span, h(title_in_context), class: "text-muted"
end

#view: conflictObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 43

view :conflict, cache: :never do
  actor_link = link_to_card card.last_action.act.actor.name
  class_up "card-slot", "error-view"
  wrap do # LOCALIZE
    alert "warning" do
      %(
        <strong>Conflict!</strong>
        <span class="new-current-revision-id">#{card.last_action_id}</span>
        <div>#{actor_link} has also been making changes.</div>
        <div>Please examine below, resolve above, and re-submit.</div>
        #{render_act}
      )
    end
  end
end

#view: debug_server_errorObject



11
12
13
14
15
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 11

view :debug_server_error, wrap: { modal: { size: :full } } do
  error_page = BetterErrors::ErrorPage.new Card::Error.current,
                                           "PATH_INFO" => request.env["REQUEST_URI"]
  haml :debug_server_error, {}, error_page
end

#view: denialObject



76
77
78
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 76

view :denial do
  focal? ? loud_denial : quiet_denial
end

#view: errorsObject



59
60
61
62
63
64
65
66
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 59

view :errors, perms: :none do
  return if card.errors.empty?

  voo.title = card.name.blank? ? "Problems" : tr(:problems_name, cardname: card.name)
  voo.hide! :menu
  class_up "alert", "card-error-msg"
  standard_errors voo.title
end

#view: mini_unknownObject

icon only, no wrap



22
23
24
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 22

view :mini_unknown, unknown: true, cache: :never do
  createable { unknown_link unknown_icon }
end

#view: not_foundObject



68
69
70
71
72
73
74
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 68

view :not_found do
  voo.hide! :menu
  voo.title = "Not Found"
  frame do
    [not_found_errors, ("to create it")]
  end
end

#view: server_errorObject



9
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 9

view :server_error, template: :haml

#view: unknownObject



17
18
19
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 17

view :unknown do
  createable { wrap { unknown_link "#{unknown_icon} #{render_title}" } }
end

#view_for_unknown(view) ⇒ Object



80
81
82
# File 'card/tmpsets/set/mod008-card-mod-format/all/html_error.rb', line 80

def view_for_unknown view
  main? && ok?(:create) ? :new : super
end