{# NOTICE #}
{# This software was produced for the U.S. Government under contract FA8702-22-C-0001, #}
{# and is subject to the Rights in Data-General Clause 52.227-14, Alt. IV (DEC 2007) #}
{# ©2021 The MITRE Corporation. All Rights Reserved. #}


{% extends "html-multi/base.html" %}


{% block navbar %}
  {% include "html-multi/navbar.html" %}
{% endblock navbar %}




{% block sidebar %}
  {% set thispage=main_entity.qname %}
    {% include "html-multi/sidebar.html" %}
  
{% endblock sidebar %}


{% block bodycontent %}
{% if main_entity_type == "class"  %}
  {% set each = main_entity  %}    {# each is a OntoClass object #}

    {# path to this class #}
    {% set thispage="classinfo" %}
        {% include "html-multi/breadcrumbs.html" %}
    

    {# name of this class, with "leaf node" if it has no children #}
    <h1>
      {{each.title}}
      {% if not each.children()  %}
        <small class="label label-info label-xs">leaf node</small>
      {% endif %}
    </h1>

    <hr>  {# horizontal rule #}

    {# Tree diagram #}
    <div class="tree-container">
      <div class="tree">
        <ul>
          {% if each.parents() %}
            {% for s in each.parents() %}
              <li>
                <a href="{{s.slug}}.html" title="'{{s.bestLabel()}}'{% if s.bestDescription() %} - {{s.bestDescription()|truncatewords(20)}}{% endif %}">{{s.title}}</a>
                  <ul>
                    <li><a style="font-weight: bold;" title="'{{each.bestLabel()}}'{% if each.bestDescription() %} - {{each.bestDescription()|truncatewords(20)}}{% endif %}">{{each.title}}</a>
                    {% if each.children()  %}
                      <ul>
                      {% for s in each.children() %}
                        <li><a href="{{s.slug}}.html" title="'{{s.bestLabel()}}'{% if s.bestDescription() %} - {{s.bestDescription()|truncatewords(20)}}{% endif %}">{{s.title}}</a></li>
                      {% endfor %}
                      </ul>
                    {% endif %}
                  </li>
                </ul>
              </li>
            {% endfor %}
          {% else %}
            <li><a href="entities-tree-classes.html">owl:Thing</a>
              <ul>
                <li><a style="font-weight: bold;" title="'{{each.bestLabel()}}'{% if each.bestDescription() %} - {{each.bestDescription()|truncatewords(20)}}{% endif %}">{{each.title}}</a>
                  {% if each.children()  %}
                    <ul>
                      {% for s in each.children() %}
                        <li><a href="{{s.slug}}.html" title="'{{s.bestLabel()}}'{% if s.bestDescription() %} - {{s.bestDescription()|truncatewords(20)}}{% endif %}">{{s.title}}</a></li>
                      {% endfor %}
                    </ul>
                  {% endif %}
                </li>
              </ul>
            </li>
          {% endif %}
        </ul>
      </div>
    </div>


    {# URI panel #}
    <div class="row">
      <div class="col-md-12">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title">URI</h3>
          </div>
          <div class="panel-body">
            <code>{{each.uri}}</code>
          </div>
        </div>
      </div>
    </div>


    {# Label panel #}
    {% if  each.bestLabel() %}
      <div class="row">
        <div class="col-md-12">
          <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title">Label</h3>
          </div>
          <div class="panel-body">
            {{each.bestLabel()}}
          </div>
          </div>
        </div>
      </div>
    {% endif %}


    {# Description panel #}
    {% if  each.bestDescription() %}
      <div class="row">
        <div class="col-md-12">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3 class="panel-title">Description</h3>
            </div>
            <div class="panel-body">
              {{each.bestDescription()|linebreaks|default("--")}}
            </div>
          </div>
        </div>
      </div>
    {% endif %}


    {# Superclasses panel #}
    {% if each.ancestors() %}
      <div class="row">
        <div class="col-md-12">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3 class="panel-title">Superclasses ({{each.ancestors()|length}})</h3>
            </div>
            <div class="panel-body">
              {% if each.ancestors() %}
                {% for s in each.ancestors() %}
                  <li><a href="{{s.slug}}.html" title="{{s.uri}}">{{s.title}}</a></li>
                {% endfor %}
              {% else %}
                <li>owl:Thing</li>
              {% endif %}
            </div>
          </div>
        </div>
      </div>
    {% endif %}


    {# Shapes panel #}
    {% if each.all_shapes %}
      <div class="row">
        <div class="col-md-12">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3 class="panel-title">Shapes ({{each.all_shapes|length}})</h3>
            </div>
            <div class="panel-body">
              {% for s in each.all_shapes %}
                <li><a href="{{s.slug}}.html" title="{{s.uri}}">{{s.title}}</a></li>
              {% endfor %}
            </div>
          </div>
        </div>
      </div>
    {% endif %}


    {# Instances panel #}
    {% if each.instances%}
    <div class="row"><div class="col-md-12">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h3 class="panel-title">Instances ({{each.instances|length}})</h3>
        </div>
        <div class="panel-body">
          {% for s in each.instances%}
            <li><a href="{{s.slug}}.html" title="{{s.uri}}">{{s.title}}</a></li>
          {% endfor %}
          </div>
        </div>
      </div>
    </div>
   {% endif %}


    {# Usage panel #}
    {% if each.domain_of_inferred %}
      <div class="row">
        <div class="col-md-12">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3 class="panel-title">Usage</h3>
            </div>
            <div class="panel-body" style="overflow: auto;">
              <p>Instances of {{each.title}} can have the following properties:</p>
            </div>
            <table class="table table-bordered" style="overflow: auto;">
              <tr class="table-classproperties">
                <th>PROPERTY</th><th>TYPE</th><th>DESCRIPTION</th><th>RANGE</th>
              </tr>
              {% for group in each.domain_of_inferred  %}
                {% for k,v in group.items()  %}
                  {% if v %}
                      <tr class="table-inheritanceinfo">
                        <th colspan="4" class="treeinfo">
                          <span class="label label-default">From class <a title="{{k.qname}}" href="{{k.slug}}.html" class="fromclass_link">{{k.title}}</a></span>
                        </th>
                      </tr>
                    {% for prop in v %}
                      <tr>
                        <td class="firsttd">
                          <a class="propcolor" title="{{prop.qname}}" href="{{prop.slug}}.html">{{prop.title}}</a>
                        </td>
                        <td class="secondtd">
                          <i>{{prop.rdftype_qname}}<i>
                        </td>
                        <td class="thirdtd">
                          <span>{{prop.bestDescription()|default("--")}}</span>
                        </td>
                        <td class="fourthtd">
                          {% if prop.ranges %}
                            {% for range in prop.ranges  %}
                                {% if not range.ext_model %}
                                  <a title="{{range.qname}}" href="{{range.slug}}.html" class="rdfclass">{{range.title}}</a>
                                {% else %}
                                  <i>{{range.title}}</i>
                                {% endif %}
                            {% endfor %}
                          {% else %}
                              <i>owl:Thing</i>
                          {% endif %}
                        </td>
                      </tr>
                    {% endfor %}
                  {% endif %}
                {% endfor %}
              {% endfor %}
            </table>
          </div>
        </div>
      </div>
    {% endif %}


    {# Property Shapes #}
    {% if each.shacl_constraints %}
      <div class="row">
        <div class="col-md-12">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3 class="panel-title">Property Shapes</h3>
            </div>
            <div class="panel-body" style="overflow: auto;">
              <p>By the associated SHACL property shapes, instances of {{each.title}} can have the following properties:</p>
            </div>
            <table class="table table-bordered" style="overflow: auto;">
              <tr class="table-classproperties">
                <th><p style="text-align:center;">PROPERTY</p></th>
                <th><p style="text-align:center;">PROPERTY TYPE</p></th>
                <th><p style="text-align:center;">DESCRIPTION</p></th>
                <th><p style="text-align:center;">MIN COUNT</p></th>
                <th><p style="text-align:center;">MAX COUNT</p></th>
                <th><p style="text-align:center;">LOCAL RANGE<br><i>(type range for property on this class)</i></p></th>
                <th><p style="text-align:center;">GLOBAL RANGE<br><i>(type range for property globally)</i></p></th>
              </tr>
              {% for constraint in each.shacl_constraints  %}
                <tr>
                  {# LABEL ROW -- for constraint.headers, display the label #}
                  {% if constraint.header %}
                    <td colspan="8">
                      <small class="label label-info label-xs">{{constraint.header}}</small>
                    </td>


                  {# DATA ROW -- for non-headers, display the data in columns #}
                  {% else %}
                    <td>    {# PROPERTY #}
                      {% set prop = constraint.property_obj.onto_property %}
                        <a class="propcolor" title="{{prop.qname}}" href="{{prop.slug}}.html">{{prop.qname}}</a>
                      
                    </td>

                    <td>    {# TYPE (owl:DatatypeProperty or owl:ObjectProperty #}
                      {{constraint.rdftype_qname|join("<br>")|default("--")}}
                    </td>

                    <td>     {# DESCRIPTION #}
                      {{constraint.rdfs_comment|join("<br>")}}
                      <br>
                      {{constraint.sh_description|join("<br>")}}
                    </td>

                    <td>     {# MIN COUNT #}
                      {{constraint.sh_minCount|join(", ")|default("0")}}
                    </td>

                    <td>     {# MAX COUNT #}
                      {{constraint.sh_maxCount|join(", ")|default("*")}}
                    </td>

                    <td>     {# LOCAL TYPE (type defined for property on this classe) #}
                      {% for value in constraint.sh_datatype %}
                        {% if value.onto_class %}
                          <a title="{{value.qname}}" href="{{value.onto_class.slug}}.html" class="rdfclass">{{value.onto_class.qname}}</a>
                        {% else %}
                          <i>{{value.qname}}</i>
                        {% endif %} 
                          <br>
                      {% endfor %}
                      {% for value in constraint.sh_class %}
                        {% if value.onto_class %}
                          <a title="{{value.qname}}" href="{{value.onto_class.slug}}.html" class="rdfclass">{{value.onto_class.qname}}</a>
                        {% else %}
                          <i>{{value.qname}}</i>
                        {% endif %} 
                        <br>
                      {% endfor %}
                    </td>

                    <td>    {# GLOBAL RANGE (type range for property globally) #}
                      {% set values = constraint.rdfs_range %}
                        {% if values %}
                          {% for value in values %}
                            {% if value.onto_class %}
                              <a title="{{value.qname}}" href="{{value.onto_class.slug}}.html" class="rdfclass">{{value.onto_class.qname}}</a>
                            {% else %}
                              <i>{{value.qname}}</i>
                            {% endif %} 
                            <br>
                          {% endfor %}                                     
                        {% else %}
                          <i>owl:Thing</i>
                        {% endif %}
                      
                    </td>
                  {% endif %}
                </tr>
              {% endfor %}
            </table>
          </div>
        </div>
      </div>
    {% endif %}


    {# Implementation panel #}
    <div class="row">
      <div class="col-md-12">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title">Implementation</h3>
          </div>
          <div class="panel-body implementation-panel">
            {% if pygments_code %}
              {{pygments_code|safe}}
            {% else %}
              <div class="implementation">
                <code style="background-color: white;">{{each.rdf_source()|linebreaks}}</code>
              </div>
            {% endif %}
          </div>
        </div>
      </div>
    </div>


        
{% endif %}
{% endblock bodycontent %}
