<div class="col-sm-9 col-md-10 col-sm-push-3 col-md-push-2">

    <kc-tabs-resource-server></kc-tabs-resource-server>

    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th class="kc-table-actions" colspan="7">
                    <div class="form-inline">
                        Filter by:&nbsp;&nbsp;
                        <div class="form-group">
                            <div class="input-group">
                                <input type="text" placeholder="Name" data-ng-model="search.name" class="form-control search" onkeyup="if(event.keyCode == 13){$(this).next('I').click();}">
                                <div class="input-group-addon">
                                    <i class="fa fa-search" type="submit"></i>
                                </div>
                            </div>
                            <div class="input-group">
                                <input type="text" placeholder="Owner" data-ng-model="search.owner.name" class="form-control search" onkeyup="if(event.keyCode == 13){$(this).next('I').click();}">
                                <div class="input-group-addon">
                                    <i class="fa fa-search" type="submit"></i>
                                </div>
                            </div>
                            <div class="input-group">
                                <select class="form-control search" data-ng-model="search.type"
                                        ng-options="r.type as r.type for r in resources | unique : 'type'">
                                    <option value="" selected ng-click="search.type = ''">All types</option>
                                </select>
                            </div>
                        </div>

                        <div class="pull-right">
                            <a id="createResource" class="btn btn-default" href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/resource/create">Create</a>
                        </div>
                    </div>
                </th>
            </tr>
            <tr data-ng-hide="resources.length == 0">
                <th>Name</th>
                <th>Type</th>
                <th>Uri</th>
                <th>Owner</th>
                <th>Scopes</th>
                <th>Permissions</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="resource in resources | filter:search | orderBy:'name'">
                <td><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/resource/{{resource._id}}">{{resource.name}}</a></td>
                <td>
                    <span data-ng-show="resource.type">{{resource.type}}</span>
                    <span data-ng-show="!resource.type">No type defined.</span>
                </td>
                <td>{{resource.uri}}</td>
                <td>{{resource.owner.name}}</td>
                <td>
                    <span data-ng-show="!resource.scopes.length">No scopes assigned.</span>
                    <span data-ng-show="resource.scopes.length > 0">
                        <span ng-repeat="scope in resource.scopes">
                            <a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/scope/{{scope.id}}">{{scope.name}}</a>{{$last ? '' : ', '}}
                        </span>
                    </span>
                </td>
                <td>
                    <span data-ng-show="!resource.policies.length">No permission assigned.</span>
                    <span data-ng-show="resource.policies.length > 0">
                        <span ng-repeat="policy in resource.policies">
                            <a href="#/realms/{{realm.realm}}/clients/{{client.id}}//authz/resource-server/permission/{{policy.type}}/{{policy.id}}">{{policy.name}}</a>{{$last ? '' : ', '}}
                        </span>
                    </span>
                </td>
                <td class="kc-action-cell" style="vertical-align: middle">
                    <button class="btn btn-default btn-block btn-sm" ng-click="createPolicy(resource);">Create Permission</button>
                </td>
            </tr>
            <tr data-ng-show="(resources | filter:search).length == 0">
                <td class="text-muted" colspan="6" data-ng-show="search.name">No results</td>
                <td class="text-muted" colspan="6" data-ng-hide="search.name">No resources available</td>
            </tr>
        </tbody>
    </table>
</div>

<kc-menu></kc-menu>