Web UI uses new name calc_reliability_string() rather than old calc_reliability()
[irspy-moved-to-github.git] / web / htdocs / details / found.mc
1 %# $Id: found.mc,v 1.33 2009-04-15 18:16:46 wosch Exp $
2 <%once>
3 sub print_navlink {
4     my($params, $cond, $caption, $skip) = @_;
5
6     if ($cond) {
7         print('     <a href="', navlink($params, $caption, $skip),
8               '"', ">$caption</a>\n");
9     } else {
10         print qq[     <span class="disabled">$caption</span>\n];
11     }
12 }
13
14 sub navlink {
15     my($params, $caption, $skip) = @_;
16     local $params->{_skip} = $skip;
17     my $url = "?" . join("&", map { "$_=" . $params->{$_}  } sort keys %$params);
18     $url = xml_encode($url);
19     return $url;
20 }
21
22 # Just make this once; forge the connection on first use
23 our $conn = undef;
24 </%once>
25 <%perl>
26 my %params = map { ( $_, utf8param($r, $_)) } grep { &utf8param($r, $_) } &utf8param($r);
27 my $query;
28 if ($params{_query}) {
29     $query = $params{_query};
30 } else {
31     $query = "";
32     foreach my $key (keys %params) {
33         next if $key =~ /^_/;
34         my $val = $params{$key};
35         next if $val eq "";
36         $query .= " and " if $query ne "";
37         $query .= "$key = ($val)";
38     }
39 }
40 $query = 'cql.allRecords=1' if $query eq "";
41
42 my $sort = $params{"_sort"};
43 if ($sort) {
44     my $modifiers = "";
45     if ($sort =~ s/(\/.*)//) {
46         $modifiers = $1;
47     }
48     $query .= " or $sort=/sort";
49     $query .= "-desc" if $params{_desc};
50     $query .= $modifiers;
51     $query .= " 0";
52 }
53
54 my $tried_to_open = 0;
55 if (!defined $conn) {
56   OPEN:
57     $conn = new ZOOM::Connection("localhost:8018/IR-Explain---1");
58     $conn->option(elementSetName => "zeerex");
59     $conn->option(count => 20);
60 }
61
62 my $rs;
63 eval { $rs = $conn->search(new ZOOM::Query::CQL($query)) };
64 if ($@ && ref $@ && $@->isa('ZOOM::Exception') &&
65     $@->code() == ZOOM::Error::CONNECTION_LOST && !$tried_to_open) {
66     $tried_to_open = 1;
67     goto OPEN;
68 } elsif ($@) {
69     die $@;
70 }
71
72 my $n = $rs->size();
73
74 my $skip = $params{"_skip"} || 0;
75 my $count = $params{"_count"} || 10;
76
77 my $first = $skip+1;
78 my $last = $first+$count-1;
79 $last = $n if $last > $n;
80 </%perl>
81      <form method="get" action=""><p>
82       <input type="text" name="_query" size="60" value="<% xml_encode($query) %>"/>
83       <input type="submit" name="_search" value="Search"/>
84      </p></form>
85      <p>
86 % if ($n == 0) {
87       No matches
88 % } elsif ($first > $n) {
89 %# "Can't happen"
90       Past end of <% $n %> records
91 % } else {
92       Records <% $first %> to <% $last %> of <% $n %><br/>
93 <%perl>
94 print_navlink(\%params, $skip > 0, "Prev", $count < $skip ? $skip-$count : 0);
95 print_navlink(\%params, $last < $n, "Next", $skip+$count);
96 </%perl>
97 % }
98      </p>
99 % if ($n > 0 && $first <= $n) {
100      <table width="100%">
101       <tr class="thleft">
102        <th>#</th>
103        <th>Title</th>
104        <th>Host Connection Reliability <& /help/link.mc, help => "info/reliability" &>
105        </th>
106        <th>Host</th>
107        <th>Port</th>
108        <th>DB</th>
109        <th></th>
110        <th></th>
111       </tr>
112 % my @ids;
113 % $rs->records($first-1, $last-$first+1); ## Force pre-cache
114 % foreach my $i ($first .. $last) {
115 <%perl>
116 my $xc = irspy_xpath_context($rs->record($i-1));
117 my $title = $xc->find("e:databaseInfo/e:title") || "[UNTITLED]";
118 my $reliability = calc_reliability_string($xc);
119 my $host = $xc->find("e:serverInfo/e:host");
120 my $port = $xc->find("e:serverInfo/e:port");
121 my $db = $xc->find("e:serverInfo/e:database");
122 my $id = irspy_record2identifier($xc);
123 push @ids, $id;
124 </%perl>
125       <tr style="background: <% ($i % 2) ? '#ffffc0' : 'white' %>">
126        <td><% $i %></td>
127        <td><a href="<% xml_encode("/full.html?id=" . uri_escape($id))
128                 %>"><% xml_encode($title) %></a></td>
129        <td><% xml_encode($reliability, "", { nbsp => 1 }) %></td>
130        <td><% xml_encode($host, "") %></td>
131        <td><% xml_encode($port, "") %></td>
132        <td><% xml_encode($db, "") %></td>
133        <td>
134         <a href="<% xml_encode("/admin/check.html?id=" . uri_escape($id))
135                 %>" title="Test this target">Test</a
136         >&nbsp;<a href="<% xml_encode("/admin/edit.html?op=edit&id=" .
137                 uri_escape($id))
138                 %>" title="Edit this target's record">Edit</a
139         >&nbsp;<a href="<% xml_encode("/raw.html?id=" . uri_escape($id))
140                 %>" title="Raw XML record">XML</a>
141        </td>
142       </tr>
143 % }
144      </table>
145 <%perl>
146 print_navlink(\%params, $skip > 0, "Prev", $count < $skip ? $skip-$count : 0);
147 print_navlink(\%params, $last < $n, "Next", $skip+$count);
148 </%perl>
149      <p>
150       <a href="<% "/admin/check.html?" .
151         xml_encode(join("&", map { "id=" . uri_escape($_) } @ids))
152         %>">[Test all targets on this list]</a>
153      </p>
154      <p>
155       <a href="<% "/stats.html?query=" . xml_encode(uri_escape($query))
156         %>">[Statistics for targets on this list]</a>
157      </p>
158 % }