{{/*
This file is part of SystemTestPortal.
Copyright (C) 2017  Institute of Software Technology, University of Stuttgart

SystemTestPortal is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

SystemTestPortal is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with SystemTestPortal.  If not, see <http://www.gnu.org/licenses/>.
*/}}

{{define "tab-content"}}
<div class="modal fade" id="helpModal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Tools</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span>&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <table class="help-table">
                    <tr>
                        <td>
                            <button class="btn btn-secondary mr-2 help-modal-button">
                                <i class="fa fa-long-arrow-left" aria-hidden="true"></i>
                            </button>
                        </td>
                        <td>Get back to the test case details.</td>
                    </tr>
                    <tr>
                        <td>
                            <button class="btn btn-success mr-2 help-modal-button">
                                <i class="fa fa-play" aria-hidden="true"></i>
                            </button>
                        </td>
                        <td>Start test execution with the first step.</td>
                    </tr>
                    <tr>
                        <td><strong>SUT-Version</strong></td>
                        <td>Choose the tested SUT-Version.</td>
                    </tr>
                    <tr>
                        <td><strong>Environment</strong></td>
                        <td>Choose the tested Environment.</td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<div class="tab-card card" id="tabTestCases">
    <nav class="navbar navbar-light action-bar p-3">

            <button class="btn btn-danger mr-2" id="buttonAbort" >
                <i class="fa fa-times" aria-hidden="true"></i>
                <span class="d-none d-sm-inline"> Abort</span>
            </button>
            {{ if and .isInSequence (not .isSequence) }}
            <button class="btn btn-secondary mr-2" id="buttonBackward">
                <i class="fa fa-step-backward" aria-hidden="true"></i>
                <span class="d-none d-sm-inline"> Previous</span>
            </button>
            {{end}}
            <button class="btn btn-success mr-4" id="buttonExecuteFirstTestStep" >
                <i class="fa fa-step-forward" aria-hidden="true"></i>
                <span class="d-none d-sm-inline"> Next</span>
            </button>
            <div class="progress mr-4" style="flex-grow: 100;">
                <div class="progress-bar" role="progressbar" style="width: {{ .ProgressBarPercent }}%;"
                aria-valuenow="{{ .ProgressBarPercent }}" aria-valuemin="0" aria-valuemax="100">
                    {{if ne .ProgressBarPercent 0}}{{ .ProgressBarCurrent }}/{{ .ProgressBarTotal }}{{end}}
                </div>
            </div>
            <span class="navbar-text" id="timeTracker">
            <span id="timeHours">{{ .hours }}</span>:<span id="timeMinutes">{{ .minutes }}</span>:<span id="timeSeconds">{{ .seconds }}</span>
            </span>
            <button class="btn btn-sm btn-secondary ml-2" id="buttonPause">
                <i class="fa fa-pause" aria-hidden="true" id="buttonPauseIcon"></i>
            </button>
        </nav>
    <div class="row tab-side-bar-row">
        <div class="col-md-9 p-3">
            <h4 class="mb-3"> {{ .TestObject.Name }} </h4>
            <div class="form-group">
                <label><strong>Description</strong></label>
                <p class="text-muted">
                    {{ with .TestObjectVersion.Description }}
                        {{ . }}
                    {{ else }}
                        No Description
                    {{ end }}
                </p>
            </div>
            <div class="form-group">
                <label><strong>Preconditions</strong></label>
                <p class="text-muted">
                    {{ with .TestObjectVersion.Preconditions }}
                    {{ . }}
                    {{ else }}
                    No Conditions
                    {{ end }}
                </p>
            </div>
            <div class="form-group">
                <div class="form-group">
                    <label><strong>Conditions</strong></label>
                    {{ if .isSequence }}
                        {{ if .TestObjectVersion.SequenceInfo.Variants }}
                    <div class="form-group">
                        <div class="form-group">
                            <div class="col-2 col-sm-1 col-md-12 col-lg-12">
                                <label for="inputTestCaseSUTVariants">
                                    <strong>Variants</strong>
                                </label>
                            </div>
                            <div class="col-10 col-sm-11 col-md-12 col-lg-12">
                                <select class="custom-select mb-2" id="inputTestObjectSUTVariants"></select>
                            </div>
                            <div class="col-2 col-sm-1 col-md-12 col-lg-12">
                                <label for="inputTestCaseSUTVersions">
                                    <strong>Versions</strong>
                                </label>
                            </div>
                            <div class="form-group col-10 col-sm-11 col-md-12 col-lg-12">
                                <select class="custom-select mb-2" id="inputTestObjectSUTVersions"></select>
                            </div>
                        </div>
                        <input type="hidden" class="" id="inputTestCaseNumber" value="{{ .case }}">
                    </div>
                        {{ else }}
                            <div class="alert alert-warning alert-dismissible">
                                <a class="close" data-dismiss="alert" aria-label="close">&times;</a>
                                <strong>Warning!</strong> This test is not applicable to any system-under-test versions!
                            </div>
                        {{ end }}
                    {{ else  if .TestObjectVersion.Variants }}
                        <div class="form-group">
                            <div class="form-group">
                                <div class="col-2 col-sm-1 col-md-12 col-lg-12">
                                    <label for="inputTestCaseSUTVariants">
                                        <strong>Variants</strong>
                                    </label>
                                </div>
                                <div class="col-10 col-sm-11 col-md-12 col-lg-12">
                                    <select class="custom-select mb-2" id="inputTestObjectSUTVariants"></select>
                                </div>
                                <div class="col-2 col-sm-1 col-md-12 col-lg-12">
                                    <label for="inputTestCaseSUTVersions">
                                        <strong>Versions</strong>
                                    </label>
                                </div>
                                <div class="form-group col-10 col-sm-11 col-md-12 col-lg-12">
                                    <select class="custom-select mb-2" id="inputTestObjectSUTVersions"></select>
                                </div>
                            </div>
                            <input type="hidden" class="" id="inputTestCaseNumber" value="{{ .case }}">
                        </div>
                    {{ else }}
                        <div class="alert alert-warning alert-dismissible">
                            <a class="close" data-dismiss="alert" aria-label="close">&times;</a>
                            <strong>Warning!</strong> This test is not applicable to any system-under-test versions!
                        </div>
                    {{ end }}
                </div>
            </div>
        </div>
        <div class="col-md-3 p-3 tab-side-bar">
            <div class="form-group">
                <label><strong>Estimated Test Duration</strong></label>
                <p class="text-muted">
                    {{ if and (eq .EstimatedHours 0) (eq .EstimatedMin 0) }}
                    No Test Duration
                    {{ else }}
                    {{ if gt .EstimatedHours 0 }}
                    {{ .EstimatedHours }}
                    {{ if eq .EstimatedHours 1 }} Hour {{ else }} Hours {{ end }}
                    {{ end }}
                    {{ if gt .EstimatedMin 0 }}
                    {{ .EstimatedMin }}
                    {{ if eq .EstimatedMin 1 }}
                    Minute
                    {{ else }}
                    Minutes
                    {{ end }}
                    {{ end }}
                    {{ end }}
                </p>
            </div>
            <div class="form-group">
                <label><strong>Number of Test {{ if .isSequence }}Cases{{ else }}Steps{{ end }}</strong></label>
                <p class="text-muted">
                    {{ if .isSequence }}
                    {{ len .TestObjectVersion.Cases }}
                    {{ else }}
                    {{ len .TestObjectVersion.Steps }}
                    {{ end }}
                </p>
            </div>
            {{ with .TestObject }}
            <div class="form-group">
                <label><strong>Labels</strong></label>
                <p>
                    {{ range .Labels }}
                    <span class="badge badge-pill" style="background-color: {{ .Labelcolor }};">
                            {{ .Labelname}}
                        </span>
                    {{ else }}
                    <span class="text-muted">No Labels</span>
                    {{ end }}
                </p>
            </div>
            {{ end }}
        </div>
    </div>
    <script src="/static/js/execute.js"></script>
    <script src="/static/js/sut-versions-show.js"></script>
    <script>
        // Listen to changes in the drop down menu of the variants
        setVariantDropdownOnChangeListener({{ if .isSequence }}true{{ else }} false{{ end }});

        $.getScript("/static/js/util/common.js");

        // Send a request to get the sut variants and versions
        var urlSeg = window.location.pathname.split("/");
        var url = urlSeg[0] + "/" + urlSeg[1] + "/" + urlSeg[2] + "/" + urlSeg[3] + "/" + urlSeg[4] + "/" + "json";

        // Request test case to get the sut versions from it
        xmlhttp = new XMLHttpRequest();
        xmlhttp.open("GET", url, true);
        xmlhttp.send();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState === 4 && this.status === 200) {
                testObject = JSON.parse(this.responseText);
                tovn = ({{ .TestObjectVersion.VersionNr }});
                {{ if .isSequence }}
                tolength = (testObject.SequenceVersions).length;
                testObjectVersionIndex = tovn - tolength;
                testObjectVersionData = testObject.SequenceVersions[testObjectVersionIndex].SequenceInfo.Variants;
                {{ else }}
                tolength = (testObject.TestCaseVersions).length;
                testObjectVersionIndex = tovn - tolength;
                testObjectVersionData = testObject.TestCaseVersions[testObjectVersionIndex].Variants;
                {{ end }}

                // Fill the drop down menu with the variants
                fillVariants(testObjectVersionData, "#inputTestObjectSUTVariants");
                // Update the version list with the versions of the selected variant
                updateVersionDropdown(testObjectVersionData, "#inputTestObjectSUTVariants", {{ if .isSequence }}true{{ else }} false{{ end }});
            }
        };
        </script>
</div>
{{ end }}