{{/*
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 "assignment"}}

<li id="5">

    <!-------------------------------------------------- BADGE ----------------------------------------------->
    <div class="timeline-badge info cursor-clickable" onclick="DataTree.onUserClickedBadge(5)">
        <i class="fa fa-info fa-lg"></i>
    </div>

    <!-------------------------------------------------- TIMELINE PANEL ----------------------------------------------->
    <div class="timeline-panel">
        <div class="timeline-heading">

            <!-- Image -->
            {{if .Author}}
                <a href="/users/{{.Author.Name}}" class="pull-left mr-3">
                    <img src="{{.Author.Image}}" alt="" class="rounded-circle profile-picture" height="42" width="42">
                </a>
            {{ else }}
            {{ end }}


            <!-- Top Left -->
            <div class="media-body w-100">

                {{if .Author}}
                    <strong class=""> {{ .Author.DisplayName }} </strong>
                {{ else }}
                {{end}}


                {{T "assigned" . }}

                {{ if .ActivityItem.IsCase}}

                    {{if .ActivityItem.TestCase}}
                        <a href="#"
                           onclick="DataTree.onUserClickedTest({{ .ActivityItem.TestCase.Name}}, false);return false;">
                        {{ .ActivityItem.TestCase.Name}}
                        </a>
                    {{ else }}
                        <em class="text-muted activity-tooltip" data-toggle="tooltip" data-placement="bottom" title="The assigned test case has been deleted"> an unknown test case</em>
                    {{ end }}

                {{ else }}

                    {{if .ActivityItem.TestSequence}}
                        <a href="#"
                           onclick="DataTree.onUserClickedTest({{ .ActivityItem.TestSequence.Name}}, true);return false;">
                        {{ .ActivityItem.TestSequence.Name}}
                        </a>
                    {{ else }}
                        <em class="text-muted activity-tooltip" data-toggle="tooltip" data-placement="bottom" title="The assigned test sequence has been deleted"> an unknown test sequence</em>
                    {{ end }}

                {{ end }}


                {{ $length := len .ActivityItem.Assignees}}

                {{if eq $length 0}}
                {{else}}

                    {{ if eq $length 1}}

                        {{T "to" .}

                    {{ range .ActivityItem.Assignees}}
                        {{if . }}
                            <a href="#"
                               onclick="DataTree.onUserClickedUserName({{ .DisplayName}});return false;">
                            {{ .DisplayName}}
                            </a>
                        {{ else }}
                        {{ end}}

                    {{end}}

                    {{ else }}

                        {{T "to multiple users" .}

                    {{ end }}

                {{end}}

                <div >
                    <div class="col-sm-8 activity-tooltip" data-toggle="tooltip" data-placement="bottom" title="{{ .ActivityItem.UpdatedAt }}">
                        <small class="text-muted"><i class="fa fa-clock-o fa-lg"></i></small>
                        <time class="timeago text-muted small align-middle " datetime="{{ provideTimeago .ActivityItem.UpdatedAt }}"></time>
                    </div>
                </div>
            </div>
        </div>

    <!-------------------------------------------------- TIMELINE BODY- ----------------------------------------------->
        {{if eq $length 0}}
        {{else}}
            {{ if eq $length 1}}
            {{ else }}
                <div class="timeline-body">
                    <div class="card" style="margin-top: 1rem;">
                        <div class="card-header d-flex flex-row" id="heading-{{.Id}}">

                            <div class="pl-2">
                                <p class="m-0">Assigned Users</p>
                            </div>

                            <div style="flex: 1;">
                                <button class="btn btn-link pull-right p-0 collapseElementButton mouse-hover-pointer collapsed" data-toggle="collapse" data-target="#collapse-{{.Id}}" aria-expanded="false" aria-controls="collapse-{{.Id}}">
                                    <i class="fa" aria-hidden="true"></i>
                                </button>
                            </div>
                        </div>

                        <div id="collapse-{{.Id}}" class="panel-collapse collapse" aria-labelledby="heading-{{.Id}}" style="">
                            <div class="card-body">
                            {{range .ActivityItem.Assignees }}
                                <div class="row mb-3">
                                    <a href="/users/{{.Name}}" class="pull-left mr-3">
                                        <img src="{{.Image}}" alt="" class="rounded-circle profile-picture" height="42" width="42">
                                    </a>
                                    <a href="#"
                                       onclick="DataTree.onUserClickedUserName({{ .DisplayName}});return false;">
                                    {{ .DisplayName}}
                                    </a>
                                </div>
                            {{end}}

                            </div>
                        </div>
                    </div>
                </div>
            {{end }}
        {{end}}
    </div>
</li>
{{ end }}