<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<hr/>
<div>
     <h4 (click)="toggleBoolean('showTopologies')"><span [class]="'clickable inline-glyph glyhpicon glyphicon-' + (this['showTopologies'] ? 'minus' : 'plus')"></span>&nbsp;Topologies</h4>
</div>
<div *ngIf="this['showTopologies']">
<ng-container *ngFor="let topology of topologies">
    <div>
      <span [class]="'clickable inline-glyph
      glyhpicon glyphicon-' + (this['showTopology_' + topology.topology] ? 'minus' : 'plus')"
      (click)="toggleBoolean('showTopology_' + topology.topology)"></span>
      <span (click)="toggleBoolean('showTopology_' + topology.topology)"><strong>{{topology.topology}}</strong></span>
      <span class="inline-glyph glyphicon glyphicon-pushpin btn btn-xs" *ngIf="topology.pinned"
            title="You may unpin this topology in gateway-site.xml by removing it from the list declared in 'knox.homepage.pinned.topologies'"
            data-toggle="tooltip"></span>
      <span class="inline-glyph glyphicon glyphicon-cog btn btn-xs" *ngIf="!topology.pinned"
            title="You may pin this topology in gateway-site.xml using the 'knox.homepage.pinned.topologies' property"
            data-toggle="tooltip"></span>
    </div>

    <div class="table-responsive" *ngIf="this['showTopology_' + topology.topology]">

        <h5 *ngIf="topology.uiServices.service.length > 0">UI Services</h5>

        <!-- UI services -->
        <mat-grid-list cols="4" rowHeight="130px">
            <mat-grid-tile *ngFor="let service of topology.uiServices.service" [colspan]="1" [rowspan]="1">
                 <a href="{{service.serviceUrl}}" target="_blank" *ngIf="!this['enableServiceText_' + service.serviceName.toLowerCase()]">
                    <img src="assets/service-logos/{{service.serviceName.toLowerCase()}}.png" height="50px" (error)="enableServiceText('enableServiceText_' + service.serviceName.toLowerCase())"/>
                </a>
                 <a href="{{service.serviceUrl}}" target="_blank" *ngIf="this['enableServiceText_' + service.serviceName.toLowerCase()]">
                    {{service.shortDesc}}
                </a>
                <mat-grid-tile-footer class="tile-shortDesc">
                    <h3>{{service.shortDesc}} <span class="small" *ngIf="service.version">(v{{service.version}})</span></h3>
                </mat-grid-tile-footer>
                <mat-grid-tile-footer class="tile-longDesc" style="height:100px;">
                    <h3>{{service.description}}</h3>
                </mat-grid-tile-footer>
            </mat-grid-tile>
        </mat-grid-list>

        <h5 *ngIf="topology.apiServices.service.length > 0">API Services</h5>

        <!-- API services -->
        <mat-grid-list cols="4" rowHeight="130px">
            <mat-grid-tile *ngFor="let service of topology.apiServices.service" [colspan]="1" [rowspan]="1">
                <span *ngIf="!this['enableServiceText_' + service.serviceName.toLowerCase()]" (click)="openApiServiceInformationModal(service)">
                    <img src="assets/service-logos/{{service.serviceName.toLowerCase()}}.png" height="50px" (error)="enableServiceText('enableServiceText_' + service.serviceName.toLowerCase())"/>
                </span>
                <span *ngIf="this['enableServiceText_' + service.serviceName.toLowerCase()]" (click)="openApiServiceInformationModal(service)">
                    {{service.shortDesc}}
                </span>
                <mat-grid-tile-footer class="tile-shortDesc">
                    <h3>{{service.shortDesc}} <span class="small" *ngIf="service.version">(v{{service.version}})</span></h3>
                </mat-grid-tile-footer>
                <mat-grid-tile-footer class="tile-longDesc" style="height:100px;">
                    <h3>{{service.description}}</h3>
                </mat-grid-tile-footer>
            </mat-grid-tile>
        </mat-grid-list>
    </div>
</ng-container>
<hr />
</div>

<bs-modal #apiServiceInformationModal>
    <bs-modal-header [showDismiss]="true" *ngIf="selectedApiService">
        <h4 class="modal-title">{{selectedApiService.shortDesc}}</h4>
    </bs-modal-header>
    <bs-modal-body *ngIf="selectedApiService">
        <div class="panel panel-default table-responsive">
            <table class="table table-sm">
                <colgroup>
                   <col width="25%">
                   <col width="75%">
               </colgroup>
               <tr>
                   <td style="font-weight: bold;">Knox Service Name</td>
                   <td>{{selectedApiService.serviceName}} <span class="small" *ngIf="selectedApiService.version">(v{{selectedApiService.version}})</span></td>
               </tr>
               <tr>
                   <td style="font-weight: bold;">Description</td>
                   <td>{{selectedApiService.description}}</td>
               </tr>
               <tr>
                   <td style="font-weight: bold;">Sample(s)</td>
                   <td>
                     <table class="table table-sm">
                       <div *ngIf="selectedApiService.samples && selectedApiService.samples.sample.length > 0">
                         <ng-container *ngFor="let sample of selectedApiService.samples.sample">
                           <tr><td style="font-weight: bold;">{{sample.description}}</td></tr>
                           <tr style="margin-bottom: 15px"><td>&nbsp;&nbsp;{{sample.value}}</tr>
                         </ng-container>
                       </div>
                       <div *ngIf="!selectedApiService.samples || selectedApiService.samples.sample.length < 1">
                         <tr><td style="font-weight: bold;">There is no any sample found in service metadata</td></tr>
                         <tr>
                           <td>&nbsp;You may check out the service's documentation and find out how to use its REST API. The service's URL is <a href="{{selectedApiService.serviceUrl}}" target="_blank">{{selectedApiService.serviceUrl}}</a></td>
                         </tr>
                       </div>
                     </table>
                   </td>
               </tr>
           </table>
       </div>
    </bs-modal-body>
    <bs-modal-footer>
        <button type="button" class="btn btn-primary btn-sm" (click)="apiServiceInformationModal.close()">Close</button>
    </bs-modal-footer>
</bs-modal>
