{% extends base %}

{% block head %}
<style>
.code-analyze-name a {
    /*color: #FF5000;*/
    color: blue;
}
.code-analyze-line {
    color: green;
    padding-left: 10px;
    white-space: pre;
    cursor: pointer;
}
.code-analyze-line:hover {
    background-color: #ccf;
}
</style>
{% end %}

{% block body %}

<div class="col-md-12 card">
    <h3 class="card-title btn-line-height">
        <span>内容搜索</span>
        <div class="float-right">
            <a class="btn btn-default" href="javascript:history.back();">返回</a>
        </div>
    </h3>

    {% include mod_fs_path.html %}
    
    <form action="">
        <table class="no-border-table">
        <tr>
            <td>路径</td>
            <td><textarea name="path" cols=60>{{?path}}</textarea></td>
        </tr>
        <tr>
            <td>包含关键字<br/>(同一行)</td>
            <td><textarea name="key" cols=60>{{?key}}</textarea></td>
        </tr>
        <tr>
            <td>排除关键字</td>
            <td><textarea name="blacklist" cols=60>{{blacklist}}</textarea></td>
        </tr>
        <tr>
            <td>文件名</td>
            <td><textarea name="filename" cols=60>{{?filename}}</textarea></td>
        </tr>
        <tr>
            <td>排除文件夹</td>
            <td><textarea name="blacklist_dir" cols=60>{{blacklist_dir}}</textarea>
        </tr>
        <tr>
            <td>忽略大小写</td>
            <td><input type="checkbox" name="ignore_case" {% if ignore_case == "on" %} checked {% end %}/></td>
        </tr>
        <tr>
            <td>递归搜索</td>
            <td><input type="checkbox" name="recursive" {% if recursive == "on" %} checked {% end %}/></td>
        </tr>
        <tr>
            <td>正则表达式</td>
            <td><input type="checkbox" name="regexp" {% if regexp == "on" %} checked {% end %}/></td>
        </tr>
        </table>
        <div>
            <button>搜索</button>
        </div>
    </form>
</div>


{{?error}}

{% if len(files) > 0 %}
<div class="col-md-12 card">
    匹配文件数: {{len(files)}}<br/>
    匹配行数: {{total_lines}}
</div>
{% end %}

{% for index1, file in enumerate(files) %}

<div class="row card">
    <div style="float:right;">匹配数: {{len(file.result)}}</div>
    <div class="code-analyze-name">
        <a href="{{_server_home}}/code/edit?path={{xutils.quote(file.name)}}&key={{key}}" target="_blank">{{file.name}}</a>
    </div>
    <div>

        {% for line in file.result %}
            {% set around_id = "%s-%s" % (index1, line.lineno) %}
            <div>
                <code class="code-analyze-line" onclick="toggle('#{{around_id}}')">{{"%4d " % line.lineno}}{{line.text}}</code>
                <pre id="{{around_id}}" class="hide marked-pre">{{line.around_text}}</pre>
            </div>
        {% end %}

    </div>
    <br/>
</div>

<script type="text/javascript">
    function toggle(id) {
        $(id).toggle();
    }

    function toggle1(id) {
        if ($(id+"-prev").hasClass("hide")) {
            $(id+"-prev").removeClass("hide");
            $(id+"-next").removeClass("hide");
        } else {
            $(id+"-prev").addClass("hide");
            $(id+"-next").addClass("hide");
        }
    }
</script>

{% end %}
{% end %}

{% block body_right %}
    {% include fs/component/fs_sidebar.html %}
{% end %}