<link href="css/repositories.css?v=3.4.0-RC3" rel="stylesheet">

<h1>
    {{title}}
    <page-info-tooltip></page-info-tooltip>
</h1>

<div class="alert alert-warning" ng-if="locations.length && !hasActiveLocation()">
    {{getLocationError()}}
</div>

<div id="wb-repositories" class="ot-owlim-ctrl mb-2">
    <div onto-loader size="50" ng-show="loader"></div>
    <!-- Local GraphDB instance -->
    <div ng-if="getLocalLocation(true, RemoteLocationType.GRAPH_DB).length && hasActiveLocation()" class="mb-1">
        <table id="wb-locations-locationInGetLocations" class="table" aria-describedby="Locations repository table">
            <tbody>
            <tr class="location"
                ng-repeat="location in getLocalLocation(true, RemoteLocationType.GRAPH_DB) | orderBy: ['uri']">
                <td>
                    <div>
                        <div class="pull-left">
                            <strong>{{'repos.from' | translate}}</strong>
                            <em ng-if="location.degradedReason" class="ri-alert-line icon-lg text-warning"
                                gdb-tooltip="{{location.degradedReason}}{{'repos.degraded.reason.extra.msg' | translate}}"
                                tooltip-placement="right"></em>
                            <span class="mr-1">{{location.label}}</span>
                        </div>
                        <div ng-if="location.local" class="actions-bar-inline pull-right">
                            <button
                                gdb-tooltip="{{'repos.edit.common.settings' | translate}}"
                                tooltip-placement="top"
                                class="btn btn-link px-0"
                                ng-click="openActiveLocationSettings()">
                                <span class="ri-settings-3-line"></span>
                            </button>
                            <a class="btn btn-link px-0 pull-right" href="license"
                               gdb-tooltip="{{'repos.view.update.licenses' | translate}}"
                               tooltip-placement="top">
                                <span class="ri-key-line"></span>
                            </a>
                        </div>
                        <div ng-if="isAdmin() && !location.local" class="actions-bar-inline pull-right">
                            <button class="btn btn-link p-0"
                                    gdb-tooltip="{{'edit.location' | translate}}" tooltip-placement="top"
                                    ng-click="editLocation(location)">
                                <em class="ri-edit-line"></em>
                            </button>
                            <button class="btn btn-link p-0 secondary"
                                    gdb-tooltip="{{'detach.location' | translate}}" tooltip-placement="top"
                                    ng-click="deleteLocation(location.uri)">
                                <em class="ri-close-line"></em>
                            </button>
                        </div>
                    </div>
                    <div ng-if="hasActiveLocation()" class="pt-2">
                        <div class="alert alert-warning no-repositories-alert"
                             ng-if="!getRepositoriesFromLocation(location.uri).length && !location.errorMsg">
                            {{'no.repos.in.current.location' | translate}}
                        </div>
                        <div class="alert alert-danger" ng-if="location.errorMsg">
                            {{location.errorMsg}}{{'repos.refresh.page.msg' | translate}}
                        </div>
                        <div ng-if="getRepositoriesFromLocation(location.uri).length" class="mb-1">
                            <table id="wb-repositories-repositoryInGetRepositories"
                                   class="table table-hover table-striped" aria-describedby="Repositories table">
                                <tbody>
                                <tr class="repository"
                                    ng-repeat="repository in getRepositoriesFromLocation(location.uri) | orderBy: ['type === \'system\'', 'location', 'id'] track by repository.hash"
                                    ng-class="{'table-info text-secondary active': isRepoActive(repository)}"
                                    data-test="repository-{{repository.id}}"
                                    guide-selector="repository-{{repository.id}}">
                                    <td class="select-repository-button-wrapper" data-test="select-repository-button-wrapper" guide-selector="select-repository-button-wrapper">
                                        <span role="button" class="icon-connection-off icon-1-5x inactive-repo m-0"
                                              gdb-tooltip="{{'connect.repo' | translate}}" tooltip-placement="top"
                                              ng-click="setRepository(repository)"
                                              ng-if="!isRepoActive(repository)"
                                              data-repository-id="{{repository}}"
                                              guide-selector="select-repository-button">
                                        </span>
                                        <span role="button" class="icon-connection-on icon-1-5x active-repo"
                                              gdb-tooltip="{{'connected.tooltip' | translate}}" tooltip-placement="top"
                                              ng-if="isRepoActive(repository)"
                                              guide-selector="select-repository-button">
                                        </span>
                                    </td>
                                    <td>
                                        <div class="lead text-overflow" ng-mouseover="setPopoverRepo(repository)">
                                            <span popover-popup-delay="500"
                                                  popover-trigger="mouseenter" popover-placement="bottom-right"
                                                  uib-popover-template="popoverTemplate"
                                                  popover-title="{{'security.repository.title' | translate}} {{repository.id}}">
                                                <span class="icon-lg" ng-class="'icon-repo-' + repository.type"></span>
                                                <strong class="repository-id">{{repository.id}}</strong></span>
                                            <span class="repository-status"> &middot; <span
                                                class="text-secondary">{{repository.state}}</span></span>
                                            <span ng-if="repository.title"><small> &middot; {{repository.title}}</small></span>
                                        </div>
                                    </td>
                                    <td width="150" class="text-nowrap repository-actions">
                                        <button class="btn btn-link p-0"
                                                ng-click="copyToClipboard(repository.externalUrl)"
                                                gdb-tooltip="{{'copy.repo.url' | translate}}">
                                            <span class="ri-links-line"></span>
                                        </button>
                                        <span ng-if="location.degradedReason">
                                            <em class="ri-alert-line icon-lg text-warning"
                                                gdb-tooltip="{{location.degradedReason}}{{'repo.not.supported.delete.or.edit' | translate}}"
                                                tooltip-placement="top"></em>
                                        </span>
                                        <span ng-if="repository.type !== 'system' && !location.degradedReason">
                                            <a class="btn btn-link p-0 edit-repository-btn"
                                               href="repository/edit/{{repository.id}}?location={{repository.location}}"
                                               gdb-tooltip="{{'repoTooltips.editRepository' | translate}}"
                                               tooltip-placement="top">
                                                <span class="ri-edit-line"></span>
                                            </a>
                                            <a class="btn btn-link p-0 download-turtle-config download-repository-config-btn"
                                               ng-href="{{getRepositoryDownloadLink(repository)}}"
                                               rel="noopener"
                                               target="_blank"
                                               gdb-tooltip="{{'download.repo.config' | translate}}"
                                               tooltip-placement="top">
                                                    <em class="ri-download-2-line"></em>
                                            </a>
                                            <button class="btn btn-link p-0 restart-repository-btn" type="button"
                                                    gdb-tooltip="{{('restart.repo.label' | translate) + ' ' + repository.id}}"
                                                    tooltip-placement="top"
                                                    ng-click="restartRepository(repository)">
                                                    <span class="ri-reset-right-line"></span>
                                            </button>
                                            <button class="btn btn-link p-0 secondary delete-repository-btn"
                                                    type="button"
                                                    gdb-tooltip="{{'delete.repo' | translate}}"
                                                    tooltip-placement="top"
                                                    ng-click="deleteRepository(repository)">
                                                <em class="ri-delete-bin-6-line"></em>
                                            </button>
                                        </span>
                                    </td>
                                    <td width="50">
                                        <button class="btn btn-link p-0 pin-repository-btn"
                                                ng-if="repository.type !== 'system' && location.active"
                                                ng-click="toggleDefaultRepository(repository.id)"
                                                ng-class="getDefaultRepository() === repository.id && location.active ? 'active' : ''"
                                                gdb-tooltip="{{'set.as.default.repo' | translate}}">
                                            <em class="ri-pushpin-line"></em>
                                        </button>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <!-- Remote GraphDB instances -->
    <div ng-if="getLocalLocation(false, RemoteLocationType.GRAPH_DB).length && hasActiveLocation()" class="mb-1">
        <h4 class="location-type-title">{{'repositories.location.remote.graph_db.instances' | translate}}</h4>

        <table id="wb-locations-locationInGetRemoteLocations" class="table" aria-describedby="Locations repository table">
            <tbody>
                <tr class="location"
                    ng-repeat="location in getLocalLocation(false, RemoteLocationType.GRAPH_DB) | orderBy: ['uri']">
                    <td>
                        <div>
                            <div class="pull-left">
                                <strong>{{'repos.from' | translate}}</strong>
                                <em ng-if="location.degradedReason" class="ri-alert-line icon-lg text-warning"
                                    gdb-tooltip="{{location.degradedReason}}{{'repos.degraded.reason.extra.msg' | translate}}"
                                    tooltip-placement="right"></em>
                                <span class="mr-1">{{location.label}}</span>
                            </div>
                            <div ng-if="location.local" class="actions-bar-inline pull-right">
                                <button
                                    gdb-tooltip="{{'repos.edit.common.settings' | translate}}"
                                    tooltip-placement="top"
                                    class="btn btn-link px-0"
                                    ng-click="openActiveLocationSettings()">
                                    <span class="ri-settings-3-line"></span>
                                </button>
                                <a class="btn btn-link px-0 pull-right" href="license"
                                   gdb-tooltip="{{'repos.view.update.licenses' | translate}}"
                                   tooltip-placement="top">
                                    <span class="ri-key-line"></span>
                                </a>
                            </div>
                            <div ng-if="isAdmin() && !location.local" class="actions-bar-inline pull-right">
                                <button class="btn btn-link p-0"
                                        gdb-tooltip="{{'edit.location' | translate}}" tooltip-placement="top"
                                        ng-click="editLocation(location)">
                                    <em class="ri-edit-line"></em>
                                </button>
                                <button class="btn btn-link p-0 secondary"
                                        gdb-tooltip="{{'detach.location' | translate}}" tooltip-placement="top"
                                        ng-click="deleteLocation(location.uri)">
                                    <em class="ri-close-line"></em>
                                </button>
                            </div>
                        </div>
                        <div ng-if="hasActiveLocation()" class="pt-2">
                            <div class="alert alert-warning no-repositories-alert"
                                 ng-if="!getRepositoriesFromLocation(location.uri).length && !location.errorMsg">
                                {{'no.repos.in.current.location' | translate}}
                            </div>
                            <div class="alert alert-danger" ng-if="location.errorMsg">
                                {{location.errorMsg}}{{'repos.refresh.page.msg' | translate}}
                            </div>
                            <div ng-if="getRepositoriesFromLocation(location.uri).length" class="mb-1">
                                <table id="wb-repositories-repositoryInRemoteGetRepositories"
                                       class="table table-hover table-striped" aria-describedby="Repositories table">
                                    <tbody>
                                    <tr class="repository"
                                        ng-repeat="repository in getRepositoriesFromLocation(location.uri) | orderBy: ['type === \'system\'', 'location', 'id'] track by repository.hash"
                                        ng-class="{'table-info text-secondary': isRepoActive(repository)}">
                                        <td width="25">
                                            <span role="button" class="icon-connection-off icon-lg text-secondary m-0"
                                                  gdb-tooltip="{{'connect.repo' | translate}}" tooltip-placement="top"
                                                  ng-click="setRepository(repository)"
                                                  ng-if="!isRepoActive(repository)"
                                                  data-repository-id="{{repository}}"
                                                  guide-selector="repository-{{repository.id}}-plug"></span>
                                            <span role="button" class="icon-connection-on icon-lg text-tertiary"
                                                  gdb-tooltip="{{'connected.tooltip' | translate}}" tooltip-placement="top"
                                                  ng-if="isRepoActive(repository)"></span>
                                        </td>
                                        <td>
                                            <div class="lead text-overflow" ng-mouseover="setPopoverRepo(repository)">
                                                <span popover-popup-delay="500"
                                                      popover-trigger="mouseenter" popover-placement="bottom-right"
                                                      uib-popover-template="popoverTemplate"
                                                      popover-title="{{'security.repository.title' | translate}} {{repository.id}}">
                                                    <span class="icon-lg" ng-class="'icon-repo-' + repository.type"></span>
                                                    <strong class="repository-id">{{repository.id}}</strong></span>
                                                <span class="repository-status"> &middot; <span
                                                    class="text-secondary">{{repository.state}}</span></span>
                                                <span ng-if="repository.title"><small> &middot; {{repository.title}}</small></span>
                                            </div>
                                        </td>
                                        <td width="150" class="text-nowrap repository-actions">
                                            <button class="btn btn-link p-0"
                                                    ng-click="copyToClipboard(repository.externalUrl)"
                                                    gdb-tooltip="{{'copy.repo.url' | translate}}">
                                                <span class="ri-links-line"></span>
                                            </button>
                                            <span ng-if="location.degradedReason">
                                                <em class="ri-alert-line icon-lg text-warning"
                                                    gdb-tooltip="{{location.degradedReason}}{{'repo.not.supported.delete.or.edit' | translate}}"
                                                    tooltip-placement="top"></em>
                                            </span>
                                            <span ng-if="repository.type !== 'system' && !location.degradedReason">
                                                <a class="btn btn-link p-0 edit-repository-btn"
                                                   href="repository/edit/{{repository.id}}?location={{repository.location}}"
                                                   gdb-tooltip="{{'repoTooltips.editRepository' | translate}}"
                                                   tooltip-placement="top">
                                                    <span class="ri-edit-line"></span>
                                                </a>
                                                <a class="btn btn-link p-0 download-turtle-config download-repository-config-btn"
                                                   ng-href="{{getRepositoryDownloadLink(repository)}}"
                                                   rel="noopener"
                                                   target="_blank"
                                                   gdb-tooltip="{{'download.repo.config' | translate}}"
                                                   tooltip-placement="top">
                                                        <em class="ri-download-2-line"></em>
                                                </a>
                                                <button class="btn btn-link p-0 restart-repository-btn" type="button"
                                                        gdb-tooltip="{{'restart.repo.label' | translate}} {{repository.id}}"
                                                        tooltip-placement="top"
                                                        ng-click="restartRepository(repository)">
                                                        <span class="ri-reset-right-line"></span>
                                                </button>
                                                <button class="btn btn-link p-0 secondary delete-repository-btn"
                                                        type="button"
                                                        gdb-tooltip="{{'delete.repo' | translate}}"
                                                        tooltip-placement="top"
                                                        ng-click="deleteRepository(repository)">
                                                    <em class="ri-delete-bin-6-line"></em>
                                                </button>
                                            </span>
                                        </td>
                                        <td width="50">
                                            <button class="btn btn-link p-0 pin-repository-btn"
                                                    ng-if="repository.type !== 'system' && location.active"
                                                    ng-click="toggleDefaultRepository(repository.id)"
                                                    ng-class="getDefaultRepository() === repository.id && location.active ? 'active' : ''"
                                                    gdb-tooltip="{{'set.as.default.repo' | translate}}">
                                                <em class="ri-pushpin-line"></em>
                                            </button>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <!-- Remote Ontopic and SPARQL instances -->
    <div ng-if="hasAnyRemoteLocation(false, [RemoteLocationType.SPARQL, RemoteLocationType.ONTOPIC])" class="mb-1 ontopic-instances">
        <h4 class="remote-location-type-title">{{'repositories.location.sparql.instances' | translate}}</h4>
        <table id="wb-repositories-ontopic-sparql-repositoryInGetRepositories"
               class="table table-hover table-striped" aria-describedby="Repositories table">
            <tbody>
            <tr ng-repeat="location in getLocalLocation(false, RemoteLocationType.ONTOPIC) | orderBy: ['type === \'system\'', 'location', 'id']"
                ng-class="{'table-info text-secondary': isRepoActive(location)}">
                <td class="lead text-overflow">
                    <strong class="location-url">{{location.uri}}</strong>
                    <span class="location-type"> &middot; <span
                        class="text-secondary">{{location.locationType}}</span></span>
                </td>
                <td>
                    <div ng-if="isAdmin()" class="actions-bar-inline pull-right">
                        <button class="btn btn-link p-0 edit-ontopic-location"
                                gdb-tooltip="{{'edit.location' | translate}}" tooltip-placement="top"
                                ng-click="editLocation(location)">
                            <em class="ri-edit-line"></em>
                        </button>
                        <button class="btn btn-link p-0 secondary delete-ontopic-location"
                                gdb-tooltip="{{'detach.location' | translate}}" tooltip-placement="top"
                                ng-click="deleteLocation(location.uri)">
                            <em class="ri-close-line"></em>
                        </button>
                    </div>
                </td>
            </tr>

            <tr ng-if="getLocalLocation(false, RemoteLocationType.SPARQL).length" class="mb-1 sparql-instances"
                ng-repeat="location in getLocalLocation(false, RemoteLocationType.SPARQL) | orderBy: ['type === \'system\'', 'location', 'id']"
                ng-class="{'table-info text-secondary': isRepoActive(location)}">
                <td class="lead text-overflow">
                    <strong class="location-url">{{location.uri}}</strong>
                    <span class="location-type"> &middot; <span
                        class="text-secondary">{{location.locationType}}</span></span>
                </td>
                <td>
                    <div ng-if="isAdmin()" class="actions-bar-inline pull-right">
                        <button class="btn btn-link p-0 edit-sparql-location"
                                gdb-tooltip="{{'edit.location' | translate}}" tooltip-placement="top"
                                ng-click="editLocation(location)">
                            <em class="ri-edit-line"></em>
                        </button>
                        <button class="btn btn-link p-0 secondary delete-sparql-location"
                                gdb-tooltip="{{'detach.location' | translate}}" tooltip-placement="top"
                                ng-click="deleteLocation(location.uri)">
                            <em class="ri-close-line"></em>
                        </button>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>

    <div class="btns-all" ng-if="getLocationError()">
        <div class="btn-group" uib-dropdown>
            <a id="wb-repositories-addRepositoryLink" class="btn btn-primary" ng-href="repository/create" guide-selector="createRepository"><span
                class="ri-add-circle-line"></span> {{'repository.create.btn' | translate}}</a>
            <button type="button" class="btn btn-primary dropdown-toggle-split dropdown-toggle" uib-dropdown-toggle>
                <span class="sr-only">{{'split.btn' | translate}}</span>
            </button>
            <ul class="dropdown-menu" role="menu">
                <li><a class="dropdown-item" href ng-click="fromFile()">{{'create.from.file' | translate}}</a></li>
            </ul>
        </div>
        <button id="addAttachRemoteLocation" ng-click="addLocation()" class="btn btn-primary pull-right"><span
            class="ri-add-circle-line"></span>{{'attach.remote.location' | translate}}
        </button>
    </div>
</div>
