<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="MRIQC" />
<title>MRIQC: individual {{ modality }}
report</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script>
function read_form() {
    var ds = "{{ dataset or 'unknown' }}";
    var sub = "{{ bids_name }}";
    var artifacts = [];
    $('#artifacts-group input:checked').each(function() {
        artifacts.push($(this).attr('name'));
    });

    var rating = $('#ratings-group input:checked').attr('value');
    var payload = {
        'dataset': ds,
        'subject': sub,
        'rating': rating,
        'artifacts': artifacts
    };
    var file = new Blob([JSON.stringify(payload)], {type: 'text/json'});
    $('#btn-download').attr('href', URL.createObjectURL(file));
    $('#btn-download').attr('download', payload['dataset'] + "_" + payload['subject'] + ".json");
    return payload
};

function toggle_rating() {
    if ($('#rating-menu').hasClass('d-none')) {
        $('#rating-menu').removeClass('d-none');
        $('#rating-toggler').addClass('active');
        $('#rating-toggler').removeClass('btn-outline-primary');
        $('#rating-toggler').addClass('btn-primary');
    } else {
        $('#rating-menu').addClass('d-none');
        $('#rating-toggler').removeClass('active');
        $('#rating-toggler').removeClass('btn-primary');
        $('#rating-toggler').addClass('btn-outline-primary');
    }
};

$(window).on('load',function(){
    var authorization = $('#btn-post').val()
    if (authorization.includes("secret_token")) {
        $('#btn-post').addClass('d-none');
    };
});
</script>
<style type="text/css">
body {
  font-family: helvetica;
  padding: 50px 10px 10px;
}

div.warning p.admonition-title, .code .error {
  color: red ;
  font-weight: bold ;
}

span.problematic {
  color: red;
  font-weight: bold ;
}

p.label {
  white-space: nowrap }

span.section-subtitle {
  /* font-size relative to parent (h1..h6 element) */
  font-size: 80% }

div.embeded-report {
  width: 100%;
  page-break-before:always;
  padding-top: 20px;
}

div.embeded-report svg { width: 100%; }

span.qa-fail {
    color: white;
    font-weight: bold;
    background-color: #FF6347;
}

span.qa-pass {
    color: white;
    font-weight: bold;
    background-color: #32CD32;
}

div#accordionOther {
    margin: 0 20px;
}

.add-padding {
    padding-top: 15px;
}

#report-qi2-fitting {
    max-width: 450px;
}

</style>
</head>
<body>
<div class="document">

<nav class="navbar fixed-top navbar-expand-lg navbar-light bg-light">
<div class="collapse navbar-collapse">
    <ul class="navbar-nav">
      <li class="nav-item"><a class="nav-link" href="#summary">Summary</a></li>
      <li class="nav-item"><a class="nav-link" href="#visuals">Visual reports</a></li>
      <li class="nav-item"><a class="nav-link" href="#other">Other</a></li>
    </ul>
</div>
<a id="rating-toggler" href="#" class="btn btn-primary float-right mb-3 mb-md-0 ml-md-3 active">Toggle rating widget</a>
</nav>
<noscript>
    <h1 class="text-danger"> The navigation menu uses Javascript. Without it this report might not work as expected </h1>
</noscript>

<h1 class="mt-5 mb-5">MRIQC: individual {{ modality }}
report</h1>

<div class="card mt-3" style="width: 480pt;">
    <h2 id="summary" class="card-header">Summary</h2>
    <div class="card-body">
        <ul class="simple">
        <li>BIDS filename: {{ bids_name }}.</li>
        {% if pred_qa is not none %}
        <li>MRIQC predicted QA:
        {% if pred_qa > 0 %}<span class="qa-fail">Exclude</span>
        {% else %}<span class="qa-pass">Pass</span>
        {% endif %}
        </li>
        {% endif %}
        <li>Date and time: {{ timestamp }}.</li>
        <li>MRIQC version: {{ version }}.</li>
        {% if workflow_details %}
        <li>Workflow details:
          <ul class="sub-simple">
          {% for detail in workflow_details %}
          <li>{{ detail }}</li>
          {% endfor %}
          </ul>
        </li>
        {% endif %}
        </ul>
    </div>
</div>

<h2 id="visuals" class="mt-5 mb-2">Visual reports</h2>
{% for title, svg_id, svg in svg_files %}
    <div class="card mt-2">
        <div class="card-header">{{ title }}</div>
        <div id="report-{{ svg_id }}" class="card-body">
        {{ svg }}
        </div>
    </div>
{% endfor %}

<h2 id="other" class="mt-5 mb-2">Other</h2>
<div class="accordion" id="accordionOther">
  <div class="card">
    <div class="card-header" id="headingOne">
        <button class="btn btn-link collapsed mb-0 mt-0 pm-0 pt-0" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
          Extracted Image Quality Metrics (IQMs)
        </button>
    </div>

    <div id="collapseOne" class="collapse" aria-labelledby="headingOne" data-parent="#accordionOther">
      <div class="card-body metadata-table">
      {{ imparams }}
      </div>
    </div>
  </div>
{% if metadata %}
  <div class="card">
    <div class="card-header" id="headingTwo">
        <button class="btn btn-link collapsed mb-0 mt-0 pm-0 pt-0" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
          Metadata
        </button>
    </div>
    <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionOther">
      <div class="card-body metadata-table">
      {{ metadata }}
      </div>
    </div>
  </div>
{% endif %}
{% if provenance %}
  <div class="card">
    <div class="card-header" id="headingThree">
        <button class="btn btn-link collapsed mb-0 mt-0 pm-0 pt-0" type="button" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
          Provenance information
        </button>
    </div>
    <div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordionOther">
      <div class="card-body provenance-table">
      {{ provenance }}
      </div>
    </div>
  </div>
{% endif %}
</div>

<div id="rating-menu" class="card position-fixed" style="width: 30%; top: 100px; left: 65%;">
<div class="card-header m-0">Rate Image
    <button type="button" class="close" aria-label="Close" id="close-rating-menu" onclick="toggle_rating()">
        <span aria-hidden="true">&times;</span>
    </button>
</div>
<div class="card-body">
    <div id="ratings-group" class="btn-group btn-group-toggle mb-2 mx-auto" style="width: 100%" data-toggle="buttons">
        <label class="btn btn-outline-danger"><input type="radio" name="qc-rating" id="exclude" value="1">Exclude</label>
        <label class="btn btn-outline-warning"><input type="radio" name="qc-rating" id="poor" value="2">Poor</label>
        <label class="btn btn-outline-info"><input type="radio" name="qc-rating" id="acceptable" value="3">Acceptable</label>
        <label class="btn btn-outline-success"><input type="radio" name="qc-rating" id="excellent" value="4">Excellent</label>
    </div>


<fieldset id="artifacts-group" class="form-group">
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="head-motion" id="art1">
        <label class="form-check-label" for="art1">Head motion artifacts</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="eye-spillover" id="art2">
        <label class="form-check-label" for="art2">Eye spillover through PE axis</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="noneye-spillover" id="art3">
        <label class="form-check-label" for="art3">Non-eye spillover through PE axis</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="coil-failure" id="art4">
        <label class="form-check-label" for="art4">Coil failure</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="noise-global" id="art5">
        <label class="form-check-label" for="art5">Global noise</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="noise-local" id="art6">
        <label class="form-check-label" for="art6">Local noise</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="em-perturbation" id="art7">
        <label class="form-check-label" for="art7">EM interference / perturbation</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="wrap-around" id="art8">
        <label class="form-check-label" for="art8">Problematic FoV prescription / Wrap-around</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="ghost-aliasing" id="art9">
        <label class="form-check-label" for="art9">Aliasing ghosts</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="ghosts-other" id="art10">
        <label class="form-check-label" for="art10">Other ghosts</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="inu" id="art11">
        <label class="form-check-label" for="art11">Intensity non-uniformity</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="field-variation" id="art12">
        <label class="form-check-label" for="art12">Temporal field variation</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="postprocessing" id="art13">
        <label class="form-check-label" for="art13">Reconstruction and postprocessing (e.g. denoising, defacing, resamplings)</label>
    </div>
    <div class="form-check">
        <input class="form-check-input" type="checkbox" name="uncategorized" id="art0">
        <label class="form-check-label" for="art0">Uncategorized artifact</label>
    </div>
</fieldset>
<a class="btn btn-primary disabled" id="btn-download" href="">Download</a>
<button class="btn btn-primary" id="btn-post" value="8sSYVI0XjFqacEMZ8wF4" disabled>Post to WebAPI</button>
<script type="text/javascript">
$('input[name="qc-rating"]').change( function() {
    var payload = read_form();
    $('#btn-download').removeClass('disabled');
    $('#btn-download').removeAttr('aria-disabled');
    $('#btn-post').removeAttr('disabled');
});

$( '#btn-post' ).click( function() {
    var payload = read_form();
    var md5sum = "{{ md5sum }}";
    var params = {
        'rating': payload['rating'],
        'md5sum': md5sum,
        'name': "",
        'comment': JSON.stringify(payload['artifacts'])
    };

    // disable developement releases
    var authorization = $(this).val();
    var ratingReq = new XMLHttpRequest();
    ratingReq.open("POST", "{{ webapi_url }}/rating");
    ratingReq.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
    ratingReq.setRequestHeader("Authorization", authorization);
    ratingReq.onload = function () {
        status = ratingReq.status;
        $('#btn-post').removeClass('btn-primary');
        $('#btn-post').attr('disabled', true);
        $('#btn-post').attr('aria-disabled', true);
        $('#btn-post').prop('disabled');
        $('#btn-post').addClass('disabled');
        $('#btn-post').removeClass('active');
        if (status === "201") {
            $('#btn-post').addClass('btn-success');
            $('#btn-post').html('Posted!');
        } else {
            $('#btn-post').addClass('btn-danger');
            $('#btn-post').html('Failed');
        };
    };
    ratingReq.send(JSON.stringify(params));
});

$( 'body' ).on( 'click', '#artifacts-group input', function(e) {
    var payload = read_form();
});

$( 'body' ).on( 'click', '#rating-toggler', function(e) {
    toggle_rating();
});
</script>
</div>
</div>
</div>

<p>For details on the IQMs (image quality metrics) and further information on
the enclosed plots, please read the
<a class="reference external" href="http://mriqc.readthedocs.io/en/stable/measures.html">documentation</a>.</p>
</body>
</html>
