<form class="form-inline float-right">
	<a class="btn btn-sm btn-warning mr-2" data-target="#adminOperationModal" data-toggle="modal">administration</a>
	<button class="btn btn-sm btn-primary" ng-click="refresh()">
		<i class="fas fa-redo"></i> refresh
	</button>
</form>

<fieldset>
	<legend>General</legend>
	<div class="row">
		<div class="col-xs-12 col-md-6 col-lg-4">
			<div class="card card-default">
				<div class="card-header text-white bg-primary text-center">Totals</div>
				<table class="table table-sm small">
					<tr>
						<th class="col-xs-6">n. subscriptions</th>
						<td class="col-xs-6 text-right">
							{{summary.totals.subscriptions}}
						</td>
					</tr>
					<tr>
						<th class="col-xs-6">n. events (total)</th>
						<td class="col-xs-6 text-right">
							{{summary.totals.events_db}}
						</td>
					</tr>
					<tr>
						<th class="col-xs-6">n. events (on ES)</th>
						<td class="col-xs-6 text-right">
							{{summary.totals.events_es}}
						</td>
					</tr>
					<tr>
						<th class="col-xs-6">n. topic types</th>
						<td class="col-xs-6 text-right">
							{{summary.totals.topics}}
						</td>
					</tr>
					<tr>
						<th class="col-xs-6">n. notifications</th>
						<td class="col-xs-6 text-right">
							{{summary.totals.notifications_es}}
						</td>
					</tr>
				</table>
			</div>
		</div>
	</div>
</fieldset>

<fieldset>
	<legend>Internal components</legend>
	
	<div class="row">
		<div class="col-xs-12 col-md-12 col-lg-6">
			<div class="card mb-2">
				<div class="card-header text-white bg-primary text-center">Buffers</div>
				<table class="table table-sm small">
					<thead>
						<tr>
							<th class="col-xs-4 text-right"></th>
							<th class="col-xs-2 text-right">Size</th>
							<th class="col-xs-2 text-right">Lost</th>
							<th class="col-xs-2 text-right">Skipped</th>
							<th class="col-xs-2 text-right">Invalid</th>
						</tr>
					</thead>
					<tbody>
						<tr ng-repeat="b in summary.buffers">
							<th>{{b.name}}</th>
							<td class="text-right">{{b.size}}</td>
							<td class="text-right" ng-class="{ 'text-danger' : b.lost > 0 }">{{b.lost}}</td>
							<td class="text-right" ng-class="{ 'text-danger' : b.skipped > 0 }">{{b.skipped}}</td>
							<td class="text-right" ng-class="{ 'text-danger' : b.invalid > 0 }">{{b.invalid}}</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
		
		<div class="col-xs-12 col-md-6 col-lg-3">
			<div class="card mb-2">
				<div class="card-header text-white bg-primary text-center">Notification dispatchers</div>
				<table class="table table-sm small">
					<thead>
						<tr>
							<th></th>
							<th class="text-right">Sent messages</th>
							<th class="text-right">Errors</th>
						</tr>
					</thead>
					<tbody>
						<tr ng-repeat="b in summary.dispatchers">
							<th>{{b.name}}</th>
							<td class="text-right">{{b.count}}</td>
							<td class="text-right" ng-class="{ 'text-danger' : b.countErrors > 0 }" title="{{b.lastError}}">{{b.countErrors}}</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
		
		<div class="col-xs-12 col-md-6 col-lg-3">
			<div class="card mb-2">
				<div class="card-header text-white bg-primary text-center">Threads</div>
				<table class="table table-sm small">
					<tbody>
						<tr ng-repeat="t in summary.threads">
							<th ng-class="{'text-muted' : !t.alive }">{{t.name}}</th>
							<td class="text-right">
								<span class="badge badge-success" ng-class="{'badge-success' : t.alive, 'badge-danger': !t.alive}">{{t.state}}</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
	</div>

</fieldset>

<fieldset>
	<legend>Configuration</legend>
	
	<div class="row">

		<div class="col-xs-12 col-md-6 col-lg-4">
			<div class="card mb-2">
				<div class="card-header text-white bg-primary text-center">Elasticsearch</div>
				<table class="table table-sm small">
					<tr>
						<th class="col-xs-4">cluster nodes</th>
						<td class="col-xs-8" colspan="3">{{summary.elasticSearch.clusterNodes}}</td>
					</tr>
					<tr>
						<th class="col-xs-4" rowspan="2">indexes</th>
						<td class="col-xs-8">{{summary.elasticSearch.eventsIndexName}}</td>
					<tr>
						<td class="col-xs-8">{{summary.elasticSearch.notificationsIndexName}}</td>
					</tr>
					<tr>
						<th class="col-xs-4">socket timeout</th>
						<td class="col-xs-8" colspan="3">{{summary.elasticSearch.socketTimeout}} ms</td>
					</tr>
					<tr>
						<th class="col-xs-4">connection timeout</th>
						<td class="col-xs-8" colspan="3">{{summary.elasticSearch.connectionTimeout}} ms</td>
					</tr>
				</table>
			</div>
		</div>
	
		<div class="col-xs-12 col-md-6 col-lg-4">
			<div class="card mb-2">
				<div class="card-header text-white bg-primary text-center">Postgres database</div>
				<table class="table table-sm small">
					<tr>
						<th class="col-xs-4">path</th>
						<td class="col-xs-8">{{summary.db.url}}</td>
					</tr>
				</table>
			</div>
		</div>
		
		<div class="col-xs-12 col-md-6 col-lg-4">
			<div class="card mb-2">
				<div class="card-header text-white bg-primary text-center">Email dispatcher</div>
				<table class="table table-sm small">
					<tr>
						<th class="col-xs-2" rowspan="2">smtp</th>
						<th class="col-xs-2">host</th>
						<td class="col-xs-8" colspan="3">{{summary.emails.smtpHost}}:{{summary.emails.smtpPort}}</td>
					</tr>
					<tr>
						<th class="col-xs-2">user</th>
						<td class="col-xs-5">{{summary.emails.smtpUser ? summary.emails.smtpUser : '-'}}</td>
						<th class="col-xs-2">password</th>
						<td class="col-xs-1" title="{{summary.emails.smtpPassword}}">&hellip;</td>
					</tr>
					<tr>
						<th class="col-xs-2" rowspan="2">from</th>
						<th class="col-xs-2">name</th>
						<td class="col-xs-8" colspan="3">{{summary.emails.fromName}}</td>
					</tr>
					<tr>
						<th class="col-xs-2">address</th>
						<td class="col-xs-8" colspan="3">{{summary.emails.from}}</td>
					</tr>
					<tr>
						<th class="col-xs-2">cc</th>
						<th class="col-xs-2">email(s)</th>
						<td class="col-xs-8" colspan="3">{{summary.emails.cc}}</td>
					</tr>
				</table>
			</div>
		</div>

	</div>
	
</fieldset>


<div id="adminOperationModal" class="modal fade" tabindex="-1" role="dialog">
	<div class="modal-dialog modal-lg"">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title">Admin operations</h4>
				<button type="button" class="close" data-dismiss="modal">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<div class="modal-body">
				<table class="table table-bordered">
					<tr admin-operation label="reset counters"
						description="Reset the counters of the internal queues."
						action="resetCounters()"></tr>
				</table>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
			</div>
		</div>
	</div>
</div>