{$layout}
{$template "menu"}

<form class="ui form" action="/ns/clusters/cluster" v-show="countAll > 0">
	<input type="hidden" name="clusterId" :value="clusterId"/>
	<div class="ui fields inline">
		<div class="ui field">
			<b-select
				name="installedState"
				v-model="installState"
				:options="[
					{label: '[安装状态]', value: '0'},
					{label: '已安装', value: '1'},
					{label: '未安装', value: '2'},
				]"
			></b-select>

			<!-- <select class="ui dropdown" name="installedState" v-model="installState">
				<option value="0">[安装状态]</option>
				<option value="1">已安装</option>
				<option value="2">未安装</option>
			</select> -->
		</div>
		<div class="ui field">
			<b-select
				name="activeState"
				v-model="activeState"
				:options="[
					{label: '[在线状态]', value: '0'},
					{label: '在线', value: '1'},
					{label: '不在线', value: '2'},
				]"
			></b-select>

			<!-- <select class="ui dropdown" name="activeState" v-model="activeState">
				<option value="0">[在线状态]</option>
				<option value="1">在线</option>
				<option value="2">不在线</option>
			</select> -->
		</div>
		<div class="ui field">
			<input type="text" name="keyword" placeholder="关键词" v-model="keyword" style="width:10em"/>
		</div>
		<div class="ui field">
			<button class="ui button" type="submit">搜索</button>
		</div>
	</div>
</form>

<div v-if="countAll == 0">
	<b-empty large>
		当前集群下还没有节点，至少添加一个节点后才能提供服务。
		<a :href="'/ns/clusters/cluster/createNode?clusterId=' + clusterId">
			<i class="pi pi-pen-to-square"></i>
			创建节点
		 </a>
	</b-empty>
   <!-- <not-found-box message="当前集群下还没有节点，至少添加一个节点后才能提供服务。">
       <div style="margin-top: 0.5em">
           <a :href="'/ns/clusters/cluster/createNode?clusterId=' + clusterId">
						<i class="pi pi-pen-to-square"></i>
						创建节点
					 </a>
       </div>
   </not-found-box> -->
</div>
<div v-if="countAll > 0">
	<b-empty v-if="nodes.length == 0">暂时还没有节点。</b-empty>
</div>

<table class="ui table selectable celled" v-if="nodes.length > 0">
	<thead>
	<tr>
		<th>节点名称</th>
		<th class="four wide">IP</th>
		<th class="value-column center" v-if="windowWidth < miniWidth || windowWidth > columnWidth1">CPU</th>
		<th class="value-column center" v-if="windowWidth < miniWidth || windowWidth > columnWidth2">内存</th>
        <th class="value-column center" v-if="windowWidth < miniWidth || windowWidth > columnWidth3">负载</th>
		<th class="two wide center">状态</th>
		<th class="two op">操作</th>
	</tr>
	</thead>
	<tr v-for="node in nodes">
        <td class="node-name-td"><a :href="'/ns/clusters/cluster/node?clusterId=' + clusterId + '&nodeId=' + node.id"><keyword :v-word="keyword">{{node.name}}</keyword></a>
            <div v-if="node.status != null && node.status.version.length > 0 && node.status.version != latestVersion">
                <span class="small red">v{{node.status.version}} -&gt; v{{latestVersion}}</span>
            </div>

            <a :href="'/ns/clusters/cluster/node/update?clusterId=' + clusterId + '&nodeId=' + node.id" title="设置"><i class="icon setting grey"></i></a>
        </td>
		<td>
			<span v-if="node.ipAddresses.length == 0" class="disabled">-</span>
			<div v-else class="address-box">
				<div v-for="addr in node.ipAddresses" style="margin-bottom:0.3em">
					<div class="ui label tiny basic">{{addr.ip}}
						<span class="small" v-if="addr.name.length > 0">（{{addr.name}}<span v-if="!addr.canAccess">，不公开访问</span>）</span>
						<span class="small" v-if="addr.name.length == 0 && !addr.canAccess">（不公开访问）</span>
                        <span v-if="addr.hasError"> &nbsp;<a href="" @click.prevent="showPortError(addr)"><span class="small red">异常</span></a></span>
					</div>
				</div>
			</div>
		</td>
		<td class="center" v-if="windowWidth < miniWidth || windowWidth > columnWidth1">
			<span v-if="node.status.isActive" :class="{red:node.status.cpuUsage > 0.80}">{{node.status.cpuUsageText}}</span>
			<span v-else class="disabled">-</span>
		</td>
		<td class="center" v-if="windowWidth < miniWidth || windowWidth > columnWidth2">
			<span v-if="node.status.isActive" :class="{red:node.status.memUsage > 0.80}">{{node.status.memUsageText}}</span>
			<span v-else class="disabled">-</span>
		</td>
        <td class="center" v-if="windowWidth < miniWidth || windowWidth > columnWidth3">
            <span v-if="node.status.isActive && node.status.load1m > 0">{{node.status.load1m}}</span>
            <span v-else class="disabled">-</span>
        </td>
		<td class="center">
			<div v-if="!node.isUp">
				<span class="red">健康问题下线</span>
                <div>
                    <a href="" @click.prevent="upNode(node.id)">[上线]</a>
                </div>
			</div>
			<div v-else-if="!node.isOn">
				<label-on :v-is-on="node.isOn"></label-on>
			</div>
			<div v-else-if="node.isInstalled">
				<div v-if="node.status.isActive">
					<span class="green">运行中</span>
				</div>
				<span v-else-if="node.status.updatedAt > 0" class="red">已断开</span>
				<span v-else-if="node.status.updatedAt == 0" class="red">未连接</span>
			</div>
			<div v-else>
				<span v-if="node.installStatus.isRunning" class="red">安装中</span>
				<a v-if="node.installStatus.isFinished && !node.installStatus.isOk" :href="'/ns/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + node.id" title="点击看安装错误"><span class="red">安装出错</span></a>
				<a v-else class="red" :href="'/ns/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + node.id" title="点击进安装界面"><span class="red">未安装</span></a>
			</div>
		</td>
		<td>
			<a :href="'/ns/clusters/cluster/node?clusterId=' + clusterId + '&nodeId=' + node.id">详情</a> &nbsp; <a href="" @click.prevent="deleteNode(node.id)">删除</a>
		</td>
	</tr>
</table>


<div class="page" v-html="filterPageContent(page)"></div>