Class: WickedCore

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/pdf/report/generator/wicked_core.rb

Constant Summary collapse

C_CLASS_NAME =
"WickedCore"
C_FIRST_PAGE =
5
C_PER_PAGE =
9

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWickedCore

Returns a new instance of WickedCore.



9
10
11
12
# File 'lib/pdf/report/generator/wicked_core.rb', line 9

def initialize
  @html = ""
  @paper_size = ""
end

Class Method Details

.add_extension(filename, extension) ⇒ Object



18
19
20
# File 'lib/pdf/report/generator/wicked_core.rb', line 18

def self.add_extension(filename, extension)
  filename.to_s.split('.').include?(extension) ? filename : "#{filename}.#{extension}"
end

.custom_body_html(results, cust = nil) ⇒ Object



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
158
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/pdf/report/generator/wicked_core.rb', line 111

def self.custom_body_html(results, cust = nil)
  html = ''
  results.each do |result|
    result.each do |key,value|
      html = '<table class="table table-striped table-bordered table-condensed">
				<tr>
				    <td colspan="2">
				      <h4>BC Demonstration</h4>
				    </td>
				    <td class="bg-info text-white"> BC properties</td>
				</tr>
				<tr>
				  <td colspan="3">
				   <h5>Group</h5>
				  </td>
				</tr>
				<tr>
				  <td colspan="3">
				    <h5>Common Group</h5>
				  </td>
				</tr>
				<tr>
				  <td colspan="3">
				    <h5>EQ-5D-3L Mobility</h5>
				  </td>
				</tr>
				<tr>
				  <td>Date & Time</td>
				  <td></td>
				  <td>
				    <table class="crf-input-field">
				      <tr>'
      if result[key].present?
        html += result[key]["MOBILITY.DATE"].present? ? result[:bc_demo]["MOBILITY.DATE"] : "<td class='bg-success text-white'> Not submitted</td><td>D</td> <td>D</td> <td>/</td> <td>M</td> <td>M</td> <td>M</td> <td>/</td> <td>Y</td> <td>Y</td> <td>Y</td> <td>Y</td> <td></td> <td>H</td> <td>H</td> <td>:</td> <td>M</td> <td>M</td>"
      end
      html +=			      '</tr>
				    </table>
				  </td>
				</tr>
				<tr>
				  <td>Mobility</td>
				  <td></td>
				  <td>
				    <p><input type="radio" name="EQ5D3L.MOBILITY.NONE" value="EQ5D3L.MOBILITY.NONE"></input>No problems</p>
				    <p><input type="radio" name="EQ5D3L.MOBILITY.SOME" value="EQ5D3L.MOBILITY.SOME"></input>Some problems</p>
				    <p><input type="radio" name="EQ5D3L.MOBILITY.CONFINED" value="EQ5D3L.MOBILITY.CONFINED"></input>Confined to bed</p>
				  </td>
				</tr>
				<tr>
				  <td colspan="3">
				    <h5>EQ-5D-3L Self-Care</h5>
				  </td>
				</tr>
				<tr>
				  <td>Date & Time</td>
				  <td></td>
				  <td>
				    <table class="crf-input-field">
				      <tr>
				        <td>D</td>
				        <td>D</td>
				        <td>/</td>
				        <td>M</td>
				        <td>M</td>
				        <td>M</td>
				        <td>/</td>
				        <td>Y</td>
				        <td>Y</td>
				        <td>Y</td>
				        <td>Y</td>
				        <td></td>
				        <td>H</td>
				        <td>H</td>
				        <td>:</td>
				        <td>M</td>
				        <td>M</td>
				      </tr>
				    </table>
				  </td>
				</tr>
				<tr>
				  <td>Self-Care</td>
				  <td></td>
				  <td>
				    <p><input type="radio" name="EQ5D3L.SELFCARE.NONE" value="EQ5D3L.SELFCARE.NONE"></input>No problems</p>
				    <p><input type="radio" name="EQ5D3L.SELFCARE.SOME" value="EQ5D3L.SELFCARE.SOME"></input>Some problems</p>
				    <p><input type="radio" name="EQ5D3L.SELFCARE.UNABLE" value="EQ5D3L.SELFCARE.UNABLE"></input>Unable to wash/dress</p>
				  </td>
				</tr>
				</table>'
    end
  end
  html += "<div id='foo'></div>"
  if cust.present?
    views_dir = WickedCore.root_path.join('.', 'public')
    views_source = WickedCore.add_extension(cust, 'html')
    html = "#{File.read(views_dir.join(views_source))}"
  end
  html = WickedCore.new.replace_image_assets(html)
  return html
end

.report_asset_path(asset) ⇒ Object



280
281
282
# File 'lib/pdf/report/generator/wicked_core.rb', line 280

def self.report_asset_path(asset)
  return WickedCore.root_path.join('.', 'public').to_s+asset
end

.root_pathObject



14
15
16
# File 'lib/pdf/report/generator/wicked_core.rb', line 14

def self.root_path
  String === Rails.root ? Pathname.new(Rails.root) : Rails.root
end

Instance Method Details

#add_page_breakNull

Insert page break

Returns:

  • (Null)


51
52
53
# File 'lib/pdf/report/generator/wicked_core.rb', line 51

def add_page_break
  @html += page_break
end

#add_to_body(html) ⇒ Null

Add to the body

Returns:

  • (Null)


44
45
46
# File 'lib/pdf/report/generator/wicked_core.rb', line 44

def add_to_body(html)
  @html += html
end

#body(results, cls) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/pdf/report/generator/wicked_core.rb', line 85

def body(results, cls)
  # raise cls.inspect
  # @report = WickedCore.new
  @html = ""
  @html += '<div class="sk-circle"> <div class="sk-circle1 sk-child"></div> <div class="sk-circle2 sk-child"></div> <div class="sk-circle3 sk-child"></div> <div class="sk-circle4 sk-child"></div> <div class="sk-circle5 sk-child"></div> <div class="sk-circle6 sk-child"></div> <div class="sk-circle7 sk-child"></div> <div class="sk-circle8 sk-child"></div> <div class="sk-circle9 sk-child"></div> <div class="sk-circle10 sk-child"></div> <div class="sk-circle11 sk-child"></div> <div class="sk-circle12 sk-child"></div> </div>'
  @html += "<h3>Conventions</h3>"
  @html += "<p>In the following table for a code list entry:<ul><li><p>C = Code List was created in the CDISC Terminology</p></li>"
  @html += "<li><p>U = Code List was updated in some way</p></li>"
  @html += "<li><p>'-' = There was no change to the Code List</p></li>"
  @html += "<li><p>X = The Code List was deleted from teh CDISC Terminology</p></li></ul></p>"
  index = 0
  page_count = C_FIRST_PAGE
  @html += '<div class="table-responsive">'
  @html += '<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">'
  @html += '<thead><tr><th>Email</th><th>Status</th><th>Name</th></tr></thead>'
  @html +=  '<tbody>'
  results.each do |user|
    @html +=    '<tr>'
    @html +=      "<td>#{user.email}</td>"
    @html +=      "<td>#{user.first_name}</td>"
    @html +=    '</tr>'
  end
  @html
  # @report.add_to_body(html)
end

#closeNull

Close up the HTML

Returns:

  • (Null)


58
59
60
# File 'lib/pdf/report/generator/wicked_core.rb', line 58

def close
  @html += page_footer
end

#history_page(history) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/pdf/report/generator/wicked_core.rb', line 257

def history_page(history)
  html = ""
  if history.length > 0
    html += "<h3>Item History</h3>"
    html += "<table class=\"table table-striped table-bordered table-condensed\">"
    html += "<thead><tr><th>Date</th><th>Change</th><th>Comment</th><th>References</th></tr></thead><tbody>"
    history.each do |item|
      changed_date = Timestamp.new(item[:last_changed_date]).to_date
      description = MarkdownEngine::render(item[:change_description])
      comment = MarkdownEngine::render(item[:explanatory_comment])
      refs = MarkdownEngine::render(item[:origin])
      html += "<tr><td>#{changed_date}</td><td>#{description}</td><td>#{comment}</td><td>#{refs}</td></tr>"
    end
    html += "</tbody></table>"
    html += page_break
  end
  return html
end

#htmlString

Return the current HTML.

Returns:

  • (String)

    The HTML



81
82
83
# File 'lib/pdf/report/generator/wicked_core.rb', line 81

def html
  return @html
end

#open(results, cls, doc_type, title, history, user, custom_body = nil) ⇒ Null

Open the document

Parameters:

  • doc_type (String)

    The document type, a title string

  • managed_item (Hash)

    Managed item. Can be empty

  • user (Object)

    The user creating the report

Returns:

  • (Null)


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pdf/report/generator/wicked_core.rb', line 28

def open(results, cls,doc_type, title, history, user, custom_body=nil)
  @paper_size = 5 #user.paper_size
  @html = page_header
  if custom_body.present?
    @html += WickedCore.custom_body_html(results, custom_body)
  else
    @html += WickedCore.new.title_page(doc_type, title, user)
    @html += WickedCore.custom_body_html(results)
  end
  # raise @html.inspect
  @html += WickedCore.new.history_page(history) if !history.empty?
end

#page_breakObject



276
277
278
# File 'lib/pdf/report/generator/wicked_core.rb', line 276

def page_break
  return "<div style='page-break-after:always;'></div>"
end


230
231
232
233
# File 'lib/pdf/report/generator/wicked_core.rb', line 230

def page_footer
  html = "</body></html>"
  return html
end

#page_headerObject



221
222
223
224
225
226
227
228
# File 'lib/pdf/report/generator/wicked_core.rb', line 221

def page_header
  css_dir = WickedCore.root_path.join('app/assets', 'stylesheets')
  html = "<html><head>"
  source = WickedCore.add_extension("bootstrap", 'css')
  html += "<style type='text/css'>#{File.read(css_dir.join(source))}</style>"
  html += "</head><body>"
  return html
end

#pdfObject

Get the PDF

Returns:

  • (Object)

    The PDF document



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/pdf/report/generator/wicked_core.rb', line 65

def pdf
  footer =
      {
          :font_size => "8",
          :font_name => "Arial, \"Helvetica Neue\", Helvetica, sans-serif",
          :left => "",
          :center => "",
          :right => "[page] of [topage]"
      }
  pdf = WickedPdf.new.pdf_from_string(@html, :page_size => @paper_size, :footer => footer )
  return pdf
end

#replace_image_assets(html) ⇒ Object



213
214
215
216
217
218
219
# File 'lib/pdf/report/generator/wicked_core.rb', line 213

def replace_image_assets(html)
  doc = Nokogiri::HTML(html)
  doc.xpath("//img").each do |img|
    img.attributes["src"].value = WickedCore.report_asset_path(img.attributes["src"].value)
  end
  doc.to_html
end

#title_page(doc_type, title, user) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/pdf/report/generator/wicked_core.rb', line 235

def title_page(doc_type, title,  user)
  html = ""
  #title = ""
  #name = APP_CONFIG['organization_title']
  #image_file = APP_CONFIG['organization_image_file']
  name = "BCS file" #ENV['organization_title']
  image_file = "favicon.png" # ENV['organization_image_file']
  dir = Rails.root.join("app", "assets", "images")
  file = File.join(dir, image_file)
  time_generated = Time.now
  # Generate HTML
  html = "<div style=\"vertical-align:middle; text-align:center\"><img height=\"75\" src=\"#{file}\"></div>"
  html += "<h3 class=\"text-center col-md-12\">#{name}</h3>"
  html += "<br>" * 10
  html += "<div class=\"text-center col-md-12\"><h1>#{doc_type}<h1><h3>#{title}</h3></div>"
  html += "<br>" * 5
  html += "<div class=\"text-center col-md-12\"><p>Run at: #{time_generated.strftime("%Y-%b-%d, %H:%M:%S")}</p></div>"
  html += "<div class=\"text-center col-md-12\"><p>Run by: #{user.email}</p></div>"
  html += page_break
  return html
end