doctype html html(lang=“en”)

head
  meta(charset="utf-8")
  meta(name="viewport" content="width=device-width, initial-scale=0.5, shrink-to-fit=no")
  meta(name="description" content="")
  meta(name="author" content="")
  //- link(rel="icon" href="../../../../favicon.ico")
  title Repository Spot Check Report

  / Bootstrap
  script(src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous")
  script(src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous")
  script(src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous")

  // Bootstrap core CSS
  link(href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet")
  link(href="https://blackrockdigital.github.io/startbootstrap-clean-blog/css/clean-blog.min.css" rel="stylesheet")
  / script(src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js")

  / DataTables support: https://datatables.net/examples/styling/bootstrap4
  / link(href="//cdn.datatables.net/1.10.16/css/dataTables.bootstrap4.min.css" rel="stylesheet")
  link(href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet")
  / script(href="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js")
  script(src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js")

  css:
      .card-columns {
        column-count: 2;
        column-gap: 30px;
        padding-left: 30px;
        padding-right: 30px;
      }

      .card {
        position: relative;
        display: inline-block;
        width: 100%;
      }

      body {
        font-size: 12px;
      }
  javascript:
    $(document).ready(function() {
      $('#identifiers').DataTable();
      $('#resources').DataTable();
      $('#publishers').DataTable();
      $('#contributors').DataTable();
      $('#supportingEvidence').DataTable();
      $('#eventHistory').DataTable();
      $('#applicability').DataTable();
      $('#validations').DataTable();
    } );

body
  .container-fluid
    .jumbotron
      h1 Generated Spot Check Report
      p.lead
        | Summary information extracted from KNART XML documents.
      h4 Table of Contents
      h5 Composites
      ol
        - composites.each do |file, result|
          li
            a(href="##{file}") = result[:title]

      h5 KNARTs
      ol
        - knarts.each do |file, result|
          li
            a(href="##{file}") = result[:title]
      h5
        a(href="#validations") Validations
      h5 Cross-Document Consistency
      ol
        li
          a(href="#identifiers") Identifiers
        li
          a(href="#resources") Resources
        li
          a(href="#publishers") Publishers
        li
          a(href="#contributors") Contributors
        li
          a(href="#supportingEvidence") Supporting Evidence
        li
          a(href="#eventHistory") Event History
        li
          a(href="#applicability") Applicability
        li
          a(href="#validations") Validations

    section
      h1 Composites
      .card-columns
        - composites.each do |file, result|
          .card(id="#{file}")
            .card-body
              h2.card-title = result[:title]
              .card-subtitle = result[:artifactType]
              small.text-muted = file

              section
                == render_partial('metadata.slim', {result: result})

              section
                h4
                  | Artifacts (
                  = result[:artifacts].length
                  | )
                table.table.table-sm.table-striped
                  thead
                    tr
                      th Name
                      th Trigger
                  tbody
                    - result[:artifacts].each do |a|
                      tr
                        td
                          = a.dig(:name, :value)
                          |  (
                          = a.dig(:artifactType, :value)
                          | )
                          br
                          = a.dig(:reference, :url, :address)
                          - if name = a.dig(:reference, :identifiers, :identifier, :identifierName)
                            |  (
                            small = name
                            | )
                          = a[:knowledgeDocument] ? '(embedded)' : nil
                        td
                          = a.dig(:eventBinding, :triggers, :trigger, :onEventName)
                          / - a.dig(:eventBinding, :triggers)&.each do |t|
                          /   = a.dig(:trigger, :onEventName)
                section
                  / - svg = root + '/' + file + '.svg'
                  - svg = file + '.svg'
                  / - if File.exist?(File.dirname(__FILE__) + '/' + svg)
                  h4 Flow Diagram
                  small = svg
                  br
                  a(href="#{svg}" target="_blank")
                    img(src="#{svg}" alt="Composite KNART Flow Diagram")

    section
      h1 KNARTs
      .card-columns
        - knarts.each do |file, result|
          .card(id="#{file}")
            .card-body
              h4.card-title = result[:title]
              .card-subtitle = result[:artifactType]
              small.text-muted = file
              hr
              == render_partial('metadata.slim', {result: result})

    section
      h1 XML Validation
      hr
      table#validations.table.table-sm.table-striped
        thead
          tr
            th File
            th Result
            th Errors
            th Run At
        tbody
          - manifest['groups'].each do |group|
            - group['items'].select{|n| n['validation']}.each do |item|
              tr
                td = item['path']
                / item.dig('validation', 'passed')
                td
                  = item.dig('validation', 'display')
                  / | (
                  / = item.dig('validation', 'code')
                  / | )
                td = item.dig('validation', 'errors')
                td = item.dig('validation', 'run_at')

    section
      h1 KNART Consistency
      hr

      h2 Identifiers
      table#identifiers.table.table-sm.table-striped
        thead
          tr
            th Root
            th Extension
            th Name
            th Version
            th File
        tbody
          - knarts.each do |file, result|
            - result[:doc].xpath('//xmlns:identifiers/xmlns:identifier').each do |c|
              tr
                td = c.xpath('./@root')
                td = c.xpath('./@extension')
                td = c.xpath('./@identifierName')
                td = c.xpath('./@version')
                td = file

      h2 Resources
      table#resources.table.table-sm.table-striped
        thead
          tr
            th Title
            th Identifiers
            th Description
            th File
        tbody
          - knarts.each do |file, result|
            - result[:doc].xpath('//xmlns:relatedResources//xmlns:resource').each do |c|
              tr
                td = c.xpath('./xmlns:title/@value')
                td 
                  - c.xpath('.//xmlns:identifier/@extension').collect{|n|n.to_s}.each do |n|
                    = n
                    br
                td = c.xpath('./xmlns:description/@value').to_s
                td = file

      h2 Publishers
      table#publishers.table.table-sm.table-striped
        thead
          tr
            th Type
            th Name
            th File
        tbody
          - knarts.each do |file, result|
            - result[:doc].xpath('//xmlns:publishers/xmlns:publisher').each do |n|
              tr
                td = n.xpath('./@xsi:type')
                td = n.xpath('./xmlns:name/@value')
                td = file

      h2 Contributors
      table#contributors.table.table-sm.table-striped
        thead
          tr
            th Given
            th Family
            th Title
            th Affiliation
            th File
        tbody
          - knarts.each do |file, result|
            - result[:doc].xpath('//xmlns:contributions//xmlns:contributor').each do |c|
              tr
                td = c.xpath('./xmlns:name/dt:part[@type="GIV"]/@value')
                td = c.xpath('./xmlns:name/dt:part[@type="FAM"]/@value')
                td
                  - c.xpath('./xmlns:name/dt:part[@type="TITLE"]/@value').collect{|n|n.to_s}.each do |n|
                    = n
                    br
                td = c.xpath('./xmlns:affiliation/xmlns:name/@value')
                td = file

      h2 Supporting Evidence
      table#supportingEvidence.table.table-sm.table-striped
        thead
          tr
            th Title
            th Identifiers
            th Description
            th Location
            th File
        tbody
          - knarts.each do |file, result|
            - result[:doc].xpath('//xmlns:metadata/xmlns:supportingEvidence//xmlns:resource').each do |n|
              tr
                td = n.xpath('./xmlns:title/@value')
                td
                  - n.xpath('.//xmlns:identifier/@extension').collect{|n|n.to_s}.each do |n|
                    = n
                    br
                td = n.xpath('./xmlns:description/@value')
                td = n.xpath('./xmlns:location/@value')
                td = file

      h2 Event History
      table#eventHistory.table.table-sm.table-striped
        thead
          tr
            th Type
            th Date/Time
            th File
        tbody
          - knarts.each do |file, result|
            - result[:doc].xpath('//xmlns:eventHistory/xmlns:artifactLifeCycleEvent').each do |n|
              tr
                td = n.xpath('./xmlns:eventType/@value')
                td = n.xpath('./xmlns:eventDateTime/@value')
                td = file

      h2 Applicability
      table#applicability.table.table-sm.table-striped
        thead
          tr
            th Focus
            th Description
            th Code
            th System
            th File
        tbody
          - knarts.each do |file, result|
            - result[:doc].xpath('//xmlns:applicability/xmlns:coverage').each do |n|
              tr
                td = n.xpath('./xmlns:focus/@value')
                td = n.xpath('./xmlns:description/@value')
                td = n.xpath('./xmlns:value/@code')
                td = n.xpath('./xmlns:value/@codeSystem')
                td = file