# -*- coding: utf-8 -*- # # @file # @brief # @author ongaeshi # @date 2011/07/18 require 'milkode/cdweb/lib/query' require 'milkode/cdweb/lib/mkurl' require 'milkode/cdweb/lib/command' module Milkode class SearchFiles attr_reader :total_records DISP_NUM = 100 # 1ページの表示数 def initialize(path, params, query) @params = params @q = query @offset = params[:offset].to_i fpaths = @q.fpaths fpaths << path unless path == "" if (fpaths.include?("*")) @records, @total_records = Database.instance.selectAll(@offset, DISP_NUM) else @records, @total_records = Database.instance.search(@q.keywords, @q.packages, fpaths, @q.suffixs, @offset, DISP_NUM) end end def query @q.query_string end def next_offset @offset + @records.size end def data_range @offset..(next_offset - 1) end def html_contents @records.map {|record| result_record(record)}.join end def html_pagination return "" if @q.empty? return "" if next_offset >= @total_records return < #{pagination_link(next_offset, "next >>")} EOF end private def pagination_link(offset, label) tmpp = @params tmpp[:offset] = offset.to_s href = Mkurl.new("", tmpp).inherit_query_shead_offset pagination_span("#{label}") end def pagination_span(content) "#{content}\n" end def result_record(record) <#{file_or_dirimg(true)}#{record.shortpath} EOS end def record_link(record) Mkurl.new(record.shortpath, @params).inherit_query_shead end end end