<div class="top-pad"></div>

<div class="content-padding">

	<h1 class="title"><i class="fa fa-database"></i>{{server.name}}</h1>
	<div class="box-content2 box-content-table">
		<table>
			<tr>
				<th>Hostname</th>
				<td>{{server.hostname}}</td>
			</tr>
			<tr>
				<th>IP</th>
				<td>{{server.ip}}</td>
			</tr>
			<tr>
				<th>Script</th>
				<td>{{server.script}}</td>
			</tr>
			<tr>
				<th>Params</th>
				<td>{{server.params}}</td>
			</tr>
			<tr>
				<th>Git Repo</th>
				<td><a href="https://github.com/{{server.repo}}" target="_system">{{server.repo}}</a></td>
			</tr>
			<tr>
				<th>Requires Travis Validation</th>
				<td>{{server.travis == '1' ? 'Yes' : 'No'}}</td>
			</tr>
			<tr>
				<th>Requires Git Tag</th>
				<td>{{server.tag == '1' ? 'Yes' : 'No'}}</td>
			</tr>
			<tr>
				<th>Last Update</th>
				<td><span ng-if="server.version.timestamp">{{server.version.timestamp*1000 | date:'MM/dd @ HH:mm'}}</span></td>
			</tr>
			<tr>
				<th>Last Git Version</th>
				<td><a href="https://github.com/{{server.repo}}/commit/{{server.version.version}}" target="_system">{{server.version.version}}</a></td>
			</tr>
		</table>
	</div>
	
	<div ng-if="account.user.permissions['SERVER-DEPLOY-ADMIN']">
		<h1 class="title"><i class="fa fa-bolt"></i>Deploy a Version</h1>
		<div class="box-content2 box-content-table">
			<table>
				<tr>
					<th>Date</th>
					<td><input type="datetime" ng-model="deploy.date"></td>
				</tr>
				<tr>
					<th>Git&nbsp;Version</th>
					<td>
						<select ng-model="deploy.version" class="deploy-commit-select" ng-disabled="commitLoad">
							<option value="master" ng-disabled="server.travis == '1'">master</option>
							<option ng-repeat="commit in commits" value="{{commit.commit}}" ng-disabled="server.travis == '1' && commit.status != 'passed'">[{{commit.status | uppercase}}] {{commit.commit}} / {{commit.author}} / {{commit.date | date:'MM/dd @ HH:mm'}} / {{commit.note}}</option>
						</select>
						<span ng-if="commitLoad">&nbsp;&nbsp;<i class="fa fa-refresh fa-spin"></i></span>
						<span ng-if="!commitLoad">&nbsp;&nbsp;<a href="" ng-click="updateCommits()">refresh</a></span>
					</td>
				</tr>
				<tr ng-if="server.id_deploy_server && (server.travis != '1' || (server.travis == '1' && deploy.version != 'master'))">
					<td colspan="2">
						<button class="button orange" ng-click="saveDeploy()">Deploy<span ng-if="deploying">&nbsp;&nbsp;&nbsp;<i class="fa fa-cog fa-spin"></i></span></button>
						
					</td>
				</tr>
			</table>
		</div>
	</div>


	<h1 class="title"><i class="fa fa-bookmark"></i>Versions</h1>
	<div class="box-content2 box-content-table">
		<table class="tb-zebra">
			<tr>
				<th>ID</th>
				<th>Server</th>
				<th>Date</th>
				<th>Git Version / Tag</th>
				<th>Status</th>
				<th>Admin</th>
			</tr>
			<tr ng-repeat="version in versions">
				<td><a href="/deploy/version/{{version.id_deploy_version}}">{{version.id_deploy_version}}</td>
				<td>{{version.server.name}}</td>
				<td>{{version.timestamp*1000 | date:'MM/dd @ HH:mm'}}</td>
				<td>
					<span ng-if="version.version">
						<a href="https://github.com/{{version.server.repo}}/commit/{{version.version}}" target="_system">{{version.version}}</a>
					</span>
					<span ng-if="version.version && version.tag">
						&nbsp;/&nbsp;
					</span>				
					<span ng-if="version.tag">
						<a href="https://github.com/{{version.server.repo}}/tree/{{version.tag}}" target="_system">{{version.tag}}</a>
					</span>
				</td>
				<td class="deploy-status-{{version.status}}">
					{{version.status}}
					<span ng-if="version.status=='deploying'">&nbsp;&nbsp;&nbsp;<i class="fa fa-cog fa-spin"></i></span>
					<span ng-if="version.status=='new'">&nbsp;&nbsp;&nbsp;<a href="" ng-click="cancel(version.id_deploy_version)"><i class="fa fa-times-circle"></i></a></span>
				</td>
				<td><a href="/staff/{{version.id_admin}}">{{version.admin.name}}</a></td>
			</tr>
		</table>
	</div>

</div>
