{{/*
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">Test Case Start</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">
                    <!-- Will be generated by js -->
                </table>
                <span class="mt-3 float-left">For more information visit our <a href="http://docs.systemtestportal.org" target="_blank">documentation</a>.</span>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">{{T "Close" .}}</button>
            </div>
        </div>
    </div>
</div>
{{template "execution-abort-modal" .}}
<div class="tab-card card" id="tabTestCases">
    <nav class="navbar navbar-light action-bar p-3">

        <button type="button" class="btn btn-danger mr-2" id="buttonAbort" title="Stop execution and discard protocol." data-shortcut="Esc">
            <i class="fa fa-times" aria-hidden="true"></i>
            <span class="d-none d-sm-inline"> {{T "Abort" .}}</span>
        </button>
    {{ if and .isInSequenceExecution (not .isSequence) }}
        <button type="button" class="btn btn-secondary"
                    id="buttonPreviousStepFromStartPage" title="Go back to previous step" data-shortcut="<- , Backspace">
            <i class="fa fa-step-backward" aria-hidden="true"></i>
            <span class="d-none d-sm-inline"> {{T "Previous" .}}</span>
        </button>
    {{end}}
        <div class="progress ml-4 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 mr-4" id="timeTracker">
            <span id="timeHours">{{ .hours }}</span>:<span id="timeMinutes">{{ .minutes }}</span>:<span
                id="timeSeconds">{{ .seconds }}</span>
            </span>
        <button type="button" class="btn btn-secondary mr-2" id="buttonPause" title="Resume/Pause the execution timer." data-shortcut="Space">
            <i class="fa fa-fw fa-pause buttonPauseIcon" aria-hidden="true"></i>
        </button>
    {{ if and (not .isSequence) }}
        {{if .TestObjectVersion.Versions}}
        <button type="button" class="btn btn-success" id="buttonExecuteFirstTestStep"
                title="Start testcase execution with first teststep." data-shortcut="->">
        {{else}}
        <button class="btn btn-success" id="buttonExecuteFirstTestStep" disabled data-toggle="tooltip" data-placement="bottom"
                title="" data-original-title="{{T "This Test Case is not applicable to any system-under-test-versions" .}}!">
        {{end}}
    {{else}}
        {{if .TestObjectVersion.SequenceInfo.Versions}}
        <button type="button" class="btn btn-success" id="buttonExecuteFirstTestStep"
                title="Start testsequence execution with first testcase." data-shortcut="->">
        {{else}}
        <button class="btn btn-success" id="buttonExecuteFirstTestStep" disabled data-toggle="tooltip" data-placement="bottom"
                title="" data-original-title="{{T "This Test Case is not applicable to any system-under-test-versions" .}}!">
        {{end}}
    {{end}}
            <i class="fa fa-step-forward" aria-hidden="true"></i>
            <span class="d-none d-sm-inline"> {{T "Next" }}</span>
        </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>{{T "Description" .}}</strong></label>
                <div class="text-muted">
                {{ with .TestObjectVersion.Description }}
                    {{printMarkdown . }}
                {{ else }}
                    {{T "No Description" .}}
                {{ end }}
                </div>
            </div>
            <div class="form-group">
                <label><strong>{{T "Please indicate which of the following preconditions are fulfilled/partially fulfilled/not fulfilled" .}}</strong></label>
                <ul class="list-group" id="preconditionsList">
                    {{ if .TestObjectVersion.Preconditions }} 
                        {{ range $index, $precondition := .TestObjectVersion.Preconditions }}
                        <li class="list-group-item preconditionItem">
                            <div style="width: 5%; float:left" class="no-highlight">
                                <input type="checkbox" class="preconditionCheckbox" id="{{ $precondition }}{{ $index }}">
                                <label for="{{ $precondition }}{{ $index }}" data-toggle='tooltip' data-placement='top' data-original-title="not fulfilled"></label>
                            </div>
                            <div style="width: 95%; float:right">
                                <span class="preconditionText">{{ .Content }}</span>
                            </div>
                        </li>
                        {{ end }}
                    {{ else }} 
                        <li class="list-group-item">
                            <span>{{T "No preconditions." .}}</span>
                        </li>
                    {{ end }} 
                    </ul>
            </div>
            <div class="form-group">
                <div class="form-group">
                    <label><strong>{{T "Conditions" .}}</strong></label>
                {{ if .isSequence }}
                {{ if .TestObjectVersion.SequenceInfo.Versions }}
                    <div class="form-group">
                        <div class="form-group">
                            {{ if .isTaskExecution }}
                                <div class="col-2 col-sm-1 col-md-12 col-lg-12">
                                    <label for="sutVersText">
                                        <strong>Selected Version</strong>
                                    </label>
                                </div>
                                <!-- inline to prevent line breaks when reading out the value -->
                                <p id="sutVersText" class="text-muted col-10 col-sm-11 col-md-12 col-lg-12">{{ .inputSUTVersion }}</p>
                                <div class="col-2 col-sm-1 col-md-12 col-lg-12">
                                    <label for="sutVarText">
                                        <strong>Selected Variant</strong>
                                    </label>
                                </div>
                                <!-- inline to prevent line breaks when reading out the value -->
                                <p id="sutVarText" class="text-muted col-10 col-sm-11 col-md-12 col-lg-12">{{ .inputSUTVariant }}</p>
                            {{ else  }}
                            <div>
                                <label for="inputTestCaseSUTVersions">
                                    <strong>Versions</strong>
                                </label>
                            </div>
                            <div class="mb-2">
                                <select class="custom-select col-5 col-lg-2" id="inputTestObjectSUTVersions"
                                        title="Select the version of the system you're testing with.">
                                </select>
                            </div>
                            <div>
                                <label for="inputTestCaseSUTVariants">
                                    <strong>Variants</strong>
                                </label>
                            </div>
                            <div class="mb-2">
                                <select class="custom-select col-5 col-lg-2" id="inputTestObjectSUTVariants"
                                        title="Select the variant of the system you're testing with.">
                                </select>
                            </div>
                            {{ end }}
                        </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>{{T "Warning" .}}!</strong> {{T "This test is not applicable to any system-under-test variants" .}}!
                    </div>
                {{ end }}
                {{ else  if .TestObjectVersion.Versions }}
                    <div class="form-group">
                        <div class="form-group">
                            {{ if or (ge .case 0) .isTaskExecution }}
                                <div class="col-2 col-sm-1 col-md-12 col-lg-12">
                                    <label for="sutVersText">
                                        <strong>{{T "Selected Version" .}}</strong>
                                    </label>
                                </div>
                                <!-- inline to prevent line breaks when reading out the value -->
                                <p id="sutVersText" class="text-muted col-10 col-sm-11 col-md-12 col-lg-12">{{ .inputSUTVersion }}</p>
                                <div class="col-2 col-sm-1 col-md-12 col-lg-12">
                                    <label for="sutVarText">
                                        <strong>{{T "Selected Variant" .}}</strong>
                                    </label>
                                </div>
                                <!-- inline to prevent line breaks when reading out the value -->
                                <p id="sutVarText" class="text-muted col-10 col-sm-11 col-md-12 col-lg-12">{{ .inputSUTVariant }}</p>
                            {{ else }}
                                <div>
                                    <label for="inputTestCaseSUTVersions">
                                        <strong>{{T "Versions" .}}</strong>
                                    </label>
                                </div>
                                <div class="mb-2">
                                    <select class="custom-select col-5 col-lg-2" id="inputTestObjectSUTVersions"
                                            title="Select the variant of the system you're testing with.">
                                    </select>
                                </div>
                                <div>
                                    <label for="inputTestCaseSUTVariants">
                                        <strong>{{T "Variants" .}}</strong>
                                    </label>
                                </div>
                                <div class="mb-2">
                                    <select class="custom-select col-5 col-lg-2" id="inputTestObjectSUTVariants"
                                            title="Select the variant of the system you're testing with.">
                                    </select>
                                </div>
                            {{ end }}
                        </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> {{T "This test is not applicable to any system-under-test variants" .}}!
                    </div>
                {{ end }}
                </div>
            </div>
            <div class="form-group">
                <div class="form-check">
                    <label class="form-check-label" title="Enable or disable the anonymous execution">
                        <input type="checkbox" class="form-check-input" id="optionAnonymous"
                               value="anonymous" {{ if  .caseProtocol}}{{if .isAnonymous }}checked{{ end }}{{end}}>
                        <b>Anonymous execution</b> &mdash; Check if you want your name not to be shown in the protocol
                        of this Test-{{ if .isSequence }}Sequence{{ else }}Case{{ end }}
                    </label>
                </div>
            </div>
        </div>
        <div class="col-md-3 p-3 tab-side-bar">
            <div class="form-group">
                <label><strong>{{T "Estimated Test Duration" .}}</strong></label>
                <p class="text-muted">
                {{ if and (eq .EstimatedHours 0) (eq .EstimatedMin 0) }}
                    {{T "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>{{T "Number of Test" .}}{{ if .isSequence }}{{T " Cases" .}}{{ else }}{{T " 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>{{T "Labels" .}}</strong></label>
                <p>
                {{ range .Labels }}
                    <span class="badge badge-primary" data-toggle="tooltip" title="{{ .Description }}"
                          style="background-color: #{{ .Color }};">
                    {{ .Name }}
                    </span>
                {{ else }}
                    <span class="text-muted">{{T "No Labels" .}}</span>
                {{ end }}
                </p>
            </div>
        {{ end }}
        </div>
    </div>
</div>

<!-- Import Scripts here -->
<script src="/static/js/project/execute.js"></script>
<script src="/static/js/project/sut-versions-show.js"></script>
<script src="/static/js/util/common.js"></script>
<script src="/static/js/util/generate_help.js"></script>

<script>
    isSequence = {{ .isSequence }};
    isInSequenceExecution = {{ .isInSequenceExecution }};
    {{ if .isInSequenceExecution }}
        if (seqProtocol != null) {
            let caseProtocols = seqProtocol.caseProtocols;
            let time = seqProtocol.OtherNeededTime;
            seqProtocol = {{ .seqProtocol }};
            seqProtocol.CurrentCase = {{.case}};
            seqProtocol.caseProtocols = caseProtocols;
            seqProtocol.OtherNeededTime = time;
        }else{
            seqProtocol = {{ .seqProtocol }};
        }
        if (!isSequence) {
            seqProtocol.CurrentCase = {{.case}};
            storeSeqProtocol(seqProtocol);
        }
    {{ end }}

    {{ if not .isSequence}}
        if (caseProtocol == null) {
            caseProtocol = {{ .caseProtocol }};
            storeCaseProtocol(caseProtocol);
        }
    {{end}}

    //Initializes the Execution buttons
    initializeExecutionClickListener();
    initializeAbortListener();

    isTaskExecution = {{ .isTaskExecution }};

    tovn = {{ .TestObjectVersion.VersionNr }}

    {{ if .isSequence }}
        testObjectVersionData = {{ .TestObjectVersion.SequenceInfo.Versions }};
        // Fill the drop down menu with the versions
        fillVersions(testObjectVersionData, "#inputTestObjectSUTVersions");
        // Update the variant list with the variants of the selected version
        updateVariantDropdown(testObjectVersionData, "#inputTestObjectSUTVersions", "#inputTestObjectSUTVariants");
    {{ else }}
        testObjectVersionData = {{ .TestObjectVersion.Versions}}
        {{ if not .isInSequenceExecution}}
            // Fill the drop down menu with the versions
            fillVersions(testObjectVersionData, "#inputTestObjectSUTVersions");
            // Update the variant list with the variants of the selected version
            updateVariantDropdown(testObjectVersionData, "#inputTestObjectSUTVersions", "#inputTestObjectSUTVariants");
        {{ end }}
    {{ end }}

    // Remove print icon
    $("#printerIcon").addClass("d-none");

    // Generate help
    $(function () {
        generateHelp($("#tabTestCases"));
    });
    initHours = {{ .hours }};
    initMinutes = {{ .minutes }};
    initSeconds = {{ .seconds }};

    /**
     * Fills the data if teststep already got executed
     */
    (function () {
        fillStartPageWithData()

    })();
</script>
{{ end }}