{{/*
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 .Activity.Author }}
                {{ if and (not .Activity.Author) .SystemSettings.IsDeleteUsers }}
                <a href="#" class="pull-left mr-3">
                <img src="{{getImagePath .Activity.Author.Image "user"}}" alt="" class="rounded-circle profile-picture" height="42" width="42">
                </a>
                {{ else }}
                <a href="/users/{{.Activity.Author.Name}}" class="pull-left mr-3">
                    <img src="{{getImagePath .Activity.Author.Image "user"}}" alt="" class="rounded-circle profile-picture" height="42" width="42">
                </a>
                {{ end }}
            {{ end }}

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

                {{if .Activity.Author}}
                    {{ if and (not .Activity.Author) .SystemSettings.IsDeleteUsers }}
                    <strong class=""> {{T "Anonymous" .}} </strong>
                    {{ else }} 
                    <strong class=""> {{ .Activity.Author.DisplayName }} </strong>
                    {{ end }}
                {{ else }}
                {{end}}


                {{T "assigned" . }}

                {{ if .Activity.ActivityItem.IsCase}}

                    {{if .Activity.ActivityItem.TestCase}}
                        <a href="#"
                           onclick="DataTree.onUserClickedTest({{ .Activity.ActivityItem.TestCase.Name}}, false);return false;">
                        {{ .Activity.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 .Activity.ActivityItem.TestSequence}}
                        <a href="#"
                           onclick="DataTree.onUserClickedTest({{ .Activity.ActivityItem.TestSequence.Name}}, true);return false;">
                        {{ .Activity.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 .Activity.ActivityItem.Assignees}}

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

                    {{ if eq $length 1}}

                        {{T "to" .}}

                    {{ range .Activity.ActivityItem.Assignees}}
                        {{if and (not .IsDeactivated) $.SystemSettings.IsDeleteUsers  }}
                            <a href="#"
                               onclick="DataTree.onUserClickedUserName({{ .DisplayName}});return false;">
                            {{ .DisplayName}}
                            </a>
                        {{ else }}
                            {{T "anonymous" .}}
                        {{ end}}

                    {{end}}

                    {{ else }}

                        {{T "to multiple users" .}}

                    {{ end }}

                {{end}}

                <div >
                    <div class="col-sm-8 activity-tooltip" data-toggle="tooltip" data-placement="bottom" title="{{ .Activity.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 .Activity.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-{{.Activity.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-{{.Activity.Id}}" aria-expanded="false" aria-controls="collapse-{{.Activity.Id}}">
                                    <i class="fa" aria-hidden="true"></i>
                                </button>
                            </div>
                        </div>

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

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