<%@ page language="java" pageEncoding="UTF-8"
         contentType="text/html; charset=UTF-8"%>
<%@ page import="org.apache.commons.lang.StringEscapeUtils"%>
<%@ page isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
    String basePath = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>兰亭集智知识管理系统-索引服务管理</title>
    <jsp:include page="../../common/head.jsp"></jsp:include>
</head>
<body>
<div  class="easyui-layout"  data-options="fit:true">
    <div data-options="region:'west',split:true,title:'服务器列表'" style="width:230px;padding:0px 0px;">
        <table id="dgSolrServer"  class="easyui-datagrid" style="width:100%;height:100%;"
               data-options="emptyMsg:'没有队列服务器',toolbar:'#tbSolrServer',loadMsg:'正在加载请稍后...',singleSelect:true,pagination:false,fitColumns:true,url:'<%=basePath%>/solr/json/server.action',method:'get'">
            <thead>
            <tr>
                <th data-options="field:'solrname',width:100">服务名称</th>
                <th data-options="field:'solrip',width:100">服务器IP</th>
            </tr>
            </thead>
        </table>
    </div>
    <div data-options="region:'center',title:'Solr Core'" style="padding:0px 0px;">
        <table id="dgSolrCore"  class="easyui-datagrid" style="height:100%;"
               data-options="emptyMsg:'没有符合检索条件的结果',loadMsg:'正在检索请稍后...',singleSelect:true,pagination:false,fitColumns:true,url:'<%=basePath%>/solr/json/admin/cores.action',method:'get'">
            <thead>
            <tr>
                <th data-options="field:'name',width:100">Core名称</th>
                <th data-options="field:'defaultCore',width:200,formatter:function(core){
                if(core==true)
                    return '是';
                else
                    return '否';
            }">默认Core</th>
                <th data-options="field:'numDocs',width:100">索引数目</th>
                <th data-options="field:'maxDoc',width:100">最大索引</th>
                <th data-options="field:'deletedDocs',width:100">删除索引</th>
                <th data-options="field:'segmentCount',width:100">分词数目</th>
                <th data-options="field:'lastModified',width:200,formatter:function(date){
                return datetimeformat('Y-m-d H:i:s',date);
            }">更新时间</th>
                <th data-options="field:'startTime',width:200,formatter:function(date){
                return datetimeformat('Y-m-d H:i:s',date);
            }">启动时间</th>
                <th data-options="field:'instanceDir',width:300">安装目录</th>
                <th data-options="field:'dataDir',width:300">数据目录</th>
                <th data-options="field:'_operation',width:180,formatter:optFormatter">操作</th>
            </tr>
            </thead>
        </table>
    </div>
</div>

<div id="tbSolrServer" style="padding-left: 10px;">
    <input class="easyui-searchbox" id="searchkeyword" style="width: 145px;" data-options="prompt:'请输入检索关键词'">
    <a href="javascript:void(0);" onclick="loadSolrServer()" class="easyui-linkbutton" data-options="iconCls:'fa fa-search-plus',plain:true">检索</a>
</div>

<div id="dgSolrEdit" class="easyui-window" title="Solr数据导入"
     data-options="modal:true,closed:true,collapsible:false,resizable:false,minimizable:false,maximizable:false,iconCls:'icon-save'"
     style="width:400px;height:400px;padding:10px;">
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'center'" style="padding:10px;">
            <form>
                <div style="margin-bottom:20px">
                    <select class="easyui-combobox" data-options="valueField:'text', textField:'text'" id="solrentities" label="<span style='color:red;'>*</span>Solr对象:"
                            style="width:100%">
                        <%--<option>请选择对象</option>--%>
                        <%--<option>collection</option>--%>
                    </select>
                </div>
                <div style="margin-bottom:20px">
                    注：带<span style="color:red;">*</span>的为必填项！
                </div>
                <p id="dataimportresult"></p>
            </form>
        </div>
        <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
            <a id="btnSave" href="javascript:void(0)" class="easyui-linkbutton" iconCls="fa fa-floppy-o" onclick="saveSubmit()"
               style="width:80px">提交</a>
            <a id="btnRefresh" href="javascript:void(0)" class="easyui-linkbutton" iconCls="fa fa-refresh" onclick="refreshSubmit()"
               style="width:80px">刷新</a>
            <a id="btnCancle" href="javascript:void(0)" class="easyui-linkbutton" iconCls="fa fa-times" onclick="cancleSubmit()"
               style="width:80px">取消</a>
        </div>
    </div>
</div>
<input type="hidden" id="current-host" value="">
<input type="hidden" id="current-core-entity" value="">
<input type="hidden" id="current-core" value="">
<script type="text/javascript">
    function optFormatter(value, row, index) {
        var optStr="<a href='javascript:void(0);' style='text-decoration:none' onclick='return showDataImport(" + index + ");'>导入</a>";
        return optStr;
    }

    $(document).ready(function(){
        $('#dgSolrServer').datagrid({
            onClickRow: function(index,row){
                $("#current-host").val(row.solrservice);
                $("#current-core-entity").val(row.solrentities);
                $('#dgSolrCore').datagrid('load',{service:row.solrservice});
            }
        });
        var pager = $('#dgSolrServer').datagrid().datagrid('getPager');
        pager.pagination({
            showPageList:false
        });
    });
    function showDataImport(index){
        $("#dataimportresult").html("暂未结果");
        var row = $('#dgSolrCore').datagrid('getRows')[index];
        $("#current-core").val(row.name);
        var entitis=$("#current-core-entity").val();
        var comboxData=new Array();
        comboxData.push({"text":"请选择对象","id":"-1"});
        if(entitis!=undefined && entitis!=null){
          var arrayEntitys=entitis.split(";");
            for(var i=0;i<arrayEntitys.length;i++){
                var item=arrayEntitys[i];
                if(item!=undefined && item!=null){
                    var info=item.split(":");
                    if(info[0]!=undefined && info[0]!=null && info[0]==row.name){
                        comboxData.push({"text":info[1],"id":info[1]});
                    }
                }
            }
        }
        $("#solrentities").combobox("loadData", comboxData);
        $("#current-core").val(row.name);
        $('#dgSolrEdit').window('open');
    }
    function refreshSubmit(){
        var entity=$("#solrentities").combobox("getValue");
        var service=$("#current-host").val();
        var core=$("#current-core").val();
        if(entity.length<=0 || entity=="-1" || service.length<=0 || core.length<=0){
            $.messager.alert('温馨提示','参数错误！','error');
            return;
        }
        $.ajax({
            type: "GET",
            url: "<%=basePath%>/solr/json/admin/core/dataimport.action",
            data: {service:service, core:core, entity:entity},
            dataType: "json",
            beforeSend:function(XMLHttpRequest){
            },
            success: function(data){
                $("#dataimportresult").html(data.message);
            },
            complete:function(XMLHttpRequest, textStatus){
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
            }
        });
    }

    function saveSubmit(){
        $.messager.confirm('温馨提示', '您确定要重新导入?', function(r){
            if (r){
                var entity=$("#solrentities").combobox("getValue");
                var service=$("#current-host").val();
                var core=$("#current-core").val();
                if(entity.length<=0 || entity=="-1" || service.length<=0 || core.length<=0){
                    $.messager.alert('温馨提示','参数错误！','error');
                    return;
                }
                $.ajax({
                    type: "GET",
                    url: "<%=basePath%>/solr/json/admin/core/dataimport.action",
                    data: {service:service, core:core, entity:entity},
                    dataType: "json",
                    beforeSend:function(XMLHttpRequest){
                    },
                    success: function(data){
                        $("#dataimportresult").html(data.message);
                    },
                    complete:function(XMLHttpRequest, textStatus){
                    },
                    error:function(XMLHttpRequest, textStatus, errorThrown){
                    }
                });
            }
        });
    }
    function loadSolrServer(){
        $('#dgSolrServer').datagrid('load',{keyword:$("#searchkeyword").textbox("getValue")});
    }
    function cancleSubmit(){
        $("#solrentities").combobox("setValue","-1");
        $("#dataimportresult").html("暂未结果");
        $('#dgSolrEdit').window('close');
    }
</script>
</body>
</html>