Changeset 94c2ba7


Ignore:
Timestamp:
May 13, 2009 5:21:34 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
9df0472
Parents:
a8c9705
Message:
  • SusiDNS:
    • Reduce displayed entries from 300 to 100
    • Add ability to go forward or back
    • Make textareas bigger
    • Clean up file names
    • Clarify messages about filter and search
Location:
apps/susidns/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java

    ra8c9705 r94c2ba7  
    3838{
    3939        private String book, action, serial, lastSerial, filter, search, hostname, destination;
     40        private int beginIndex, endIndex;
    4041        private Properties properties, addressbook;
    4142        private int trClass;
    4243        private LinkedList deletionMarks;
    4344        private static Comparator sorter;
    44        
     45        private static final int DISPLAY_SIZE=100;
     46
    4547        static {
    4648                sorter = new AddressByNameSorter();
     
    7577                properties = new Properties();
    7678                deletionMarks = new LinkedList();
     79                beginIndex = 0;
     80                endIndex = DISPLAY_SIZE - 1;
    7781        }
    7882        private long configLastLoaded = 0;
     
    107111                loadConfig();
    108112                String filename = properties.getProperty( getBook() + "_addressbook" );
     113                if (filename.startsWith("../"))
     114                        return filename.substring(3);
    109115                return ConfigBean.addressbookPrefix + filename;
    110116        }
     
    175181                                list.addLast( new AddressBean( name, destination ) );
    176182                        }
    177                         // Format a message about filtered addressbook size, and the number of displayed entries
    178                         if( filter != null && filter.length() > 0 )
    179                                 message = "Filtered l";
    180                         else
    181                                 message = "L";
    182                         message += "ist contains " + list.size() + " entries";
    183                         if (list.size() > 300) message += ", displaying the first 300."; else message += ".";
    184 
    185183                        Object array[] = list.toArray();
    186184                        Arrays.sort( array, sorter );
    187185                        entries = array;
     186
     187                        // Format a message about filtered addressbook size, and the number of displayed entries
     188                        // addressbook.jsp catches the case where the whole book is empty.
     189                        String filterArg = "";
     190                        if( search != null && search.length() > 0 ) {
     191                                message = "Search ";
     192                        }
     193                        if( filter != null && filter.length() > 0 ) {
     194                                if( search != null && search.length() > 0 )
     195                                        message += "within ";
     196                                message += "Filtered list ";
     197                                filterArg = "&filter=" + filter;
     198                        }
     199                        if (entries.length == 0) {
     200                                message += "- no matches";
     201                        } else if (getBeginInt() == 0 && getEndInt() == entries.length - 1) {
     202                                if (message.length() == 0)
     203                                        message = "Addressbook ";
     204                                message += "contains " + entries.length + " entries";
     205                        } else {
     206                                if (getBeginInt() > 0) {
     207                                        int newBegin = Math.max(0, getBeginInt() - DISPLAY_SIZE);
     208                                        int newEnd = Math.max(0, getBeginInt() - 1);
     209                                        message += "<a href=\"addressbook.jsp?book=" + getBook() + filterArg +
     210                                                   "&begin=" + newBegin + "&end=" + newEnd + "\">" + newBegin +
     211                                                   '-' + newEnd + "</a> | ";
     212                                }
     213                                message += "Showing " + getBegin() + '-' + getEnd() + " of " + entries.length;
     214                                if (getEndInt() < entries.length - 1) {
     215                                        int newBegin = Math.min(entries.length - 1, getEndInt() + 1);
     216                                        int newEnd = Math.min(entries.length, getEndInt() + DISPLAY_SIZE);
     217                                        message += " | <a href=\"addressbook.jsp?book=" + getBook() + filterArg +
     218                                                   "&begin=" + newBegin + "&end=" + newEnd + "\">" + newBegin +
     219                                                   '-' + newEnd + "</a>";
     220                                }
     221                        }
    188222                }
    189223                catch (Exception e) {
     
    303337                this.hostname = hostname;
    304338        }
     339        private int getBeginInt() {
     340                return Math.max(0, Math.min(entries.length - 1, beginIndex));
     341        }
     342        public String getBegin() {
     343                return "" + getBeginInt();
     344        }
     345        public void setBegin(String s) {
     346                try {
     347                        beginIndex = Integer.parseInt(s);
     348                } catch (NumberFormatException nfe) {}
     349        }
     350        private int getEndInt() {
     351                return Math.max(0, Math.max(getBeginInt(), Math.min(entries.length - 1, endIndex)));
     352        }
     353        public String getEnd() {
     354                return "" + getEndInt();
     355        }
     356        public void setEnd(String s) {
     357                try {
     358                        endIndex = Integer.parseInt(s);
     359                } catch (NumberFormatException nfe) {}
     360        }
    305361}
  • apps/susidns/src/jsp/addressbook.jsp

    ra8c9705 r94c2ba7  
    4747<div id="navi">
    4848<p>addressbooks
    49 <a href="addressbook.jsp?book=master">master</a> |
    50 <a href="addressbook.jsp?book=router">router</a> |
    51 <a href="addressbook.jsp?book=published">published</a> |
    52 <a href="addressbook.jsp?book=private">private</a> *
     49<a href="addressbook.jsp?book=master&filter=none&begin=0&end=99">master</a> |
     50<a href="addressbook.jsp?book=router&filter=none&begin=0&end=99">router</a> |
     51<a href="addressbook.jsp?book=published&filter=none&begin=0&end=99">published</a> |
     52<a href="addressbook.jsp?book=private&filter=none&begin=0&end=99">private</a> *
    5353<a href="subscriptions.jsp">subscriptions</a> *
    5454<a href="config.jsp">configuration</a> *
     
    6565<span>${book.loadBookMessages}</span>
    6666
     67<c:if test="${book.notEmpty}">
    6768<div id="filter">
    68 <p>Filter: <a href="addressbook.jsp?filter=a">a</a>
    69 <a href="addressbook.jsp?filter=b">b</a>
    70 <a href="addressbook.jsp?filter=c">c</a>
    71 <a href="addressbook.jsp?filter=d">d</a>
    72 <a href="addressbook.jsp?filter=e">e</a>
    73 <a href="addressbook.jsp?filter=f">f</a>
    74 <a href="addressbook.jsp?filter=g">g</a>
    75 <a href="addressbook.jsp?filter=h">h</a>
    76 <a href="addressbook.jsp?filter=i">i</a>
    77 <a href="addressbook.jsp?filter=j">j</a>
    78 <a href="addressbook.jsp?filter=k">k</a>
    79 <a href="addressbook.jsp?filter=l">l</a>
    80 <a href="addressbook.jsp?filter=m">m</a>
    81 <a href="addressbook.jsp?filter=n">n</a>
    82 <a href="addressbook.jsp?filter=o">o</a>
    83 <a href="addressbook.jsp?filter=p">p</a>
    84 <a href="addressbook.jsp?filter=q">q</a>
    85 <a href="addressbook.jsp?filter=r">r</a>
    86 <a href="addressbook.jsp?filter=s">s</a>
    87 <a href="addressbook.jsp?filter=t">t</a>
    88 <a href="addressbook.jsp?filter=u">u</a>
    89 <a href="addressbook.jsp?filter=v">v</a>
    90 <a href="addressbook.jsp?filter=w">w</a>
    91 <a href="addressbook.jsp?filter=x">x</a>
    92 <a href="addressbook.jsp?filter=y">y</a>
    93 <a href="addressbook.jsp?filter=z">z</a>
    94 <a href="addressbook.jsp?filter=0-9">0-9</a>
    95 <a href="addressbook.jsp?filter=none">all</a></p>
     69<p>Filter:
     70<a href="addressbook.jsp?filter=a&begin=0&end=99">a</a>
     71<a href="addressbook.jsp?filter=b&begin=0&end=99">b</a>
     72<a href="addressbook.jsp?filter=c&begin=0&end=99">c</a>
     73<a href="addressbook.jsp?filter=d&begin=0&end=99">d</a>
     74<a href="addressbook.jsp?filter=e&begin=0&end=99">e</a>
     75<a href="addressbook.jsp?filter=f&begin=0&end=99">f</a>
     76<a href="addressbook.jsp?filter=g&begin=0&end=99">g</a>
     77<a href="addressbook.jsp?filter=h&begin=0&end=99">h</a>
     78<a href="addressbook.jsp?filter=i&begin=0&end=99">i</a>
     79<a href="addressbook.jsp?filter=j&begin=0&end=99">j</a>
     80<a href="addressbook.jsp?filter=k&begin=0&end=99">k</a>
     81<a href="addressbook.jsp?filter=l&begin=0&end=99">l</a>
     82<a href="addressbook.jsp?filter=m&begin=0&end=99">m</a>
     83<a href="addressbook.jsp?filter=n&begin=0&end=99">n</a>
     84<a href="addressbook.jsp?filter=o&begin=0&end=99">o</a>
     85<a href="addressbook.jsp?filter=p&begin=0&end=99">p</a>
     86<a href="addressbook.jsp?filter=q&begin=0&end=99">q</a>
     87<a href="addressbook.jsp?filter=r&begin=0&end=99">r</a>
     88<a href="addressbook.jsp?filter=s&begin=0&end=99">s</a>
     89<a href="addressbook.jsp?filter=t&begin=0&end=99">t</a>
     90<a href="addressbook.jsp?filter=u&begin=0&end=99">u</a>
     91<a href="addressbook.jsp?filter=v&begin=0&end=99">v</a>
     92<a href="addressbook.jsp?filter=w&begin=0&end=99">w</a>
     93<a href="addressbook.jsp?filter=x&begin=0&end=99">x</a>
     94<a href="addressbook.jsp?filter=y&begin=0&end=99">y</a>
     95<a href="addressbook.jsp?filter=z&begin=0&end=99">z</a>
     96<a href="addressbook.jsp?filter=0-9&begin=0&end=99">0-9</a>
     97<a href="addressbook.jsp?filter=none&begin=0&end=99">all</a></p>
    9698<c:if test="${book.hasFilter}">
    9799<p>Current filter: ${book.filter}
    98 (<a href="addressbook.jsp?filter=none">clear filter</a>)</p>
     100(<a href="addressbook.jsp?filter=none&begin=0&end=99">clear filter</a>)</p>
    99101</c:if>
    100102</div>
    101103
    102104<form method="POST" action="addressbook.jsp">
     105<input type="hidden" name="begin" value="0"/>
     106<input type="hidden" name="end" value="99"/>
    103107<div id="search">
    104108<table><tr>
     
    110114
    111115</form>
     116</c:if>
    112117
    113118<form method="POST" action="addressbook.jsp">
    114119<input type="hidden" name="serial" value="${book.serial}"/>
     120<input type="hidden" name="begin" value="0"/>
     121<input type="hidden" name="end" value="99"/>
    115122
    116123<c:if test="${book.notEmpty}">
     
    128135<th>Destination</th>
    129136</tr>
    130 <!-- limit iterator to 300, or "Form too large" may result on submit -->
    131 <c:forEach items="${book.entries}" var="addr" begin="0" end="299">
     137<!-- limit iterator, or "Form too large" may result on submit, and is a huge web page if we don't -->
     138<c:forEach items="${book.entries}" var="addr" begin="${book.begin}" end="${book.end}">
    132139<tr class="list${book.trClass}">
    133140<c:if test="${book.master || book.router || book.published || book.private}">
     
    137144<span class="addrhlpr"><a href="http://${addr.name}/?i2paddresshelper=${addr.destination}">(addrhlpr)</a></span>
    138145</td>
    139 <td class="destinations"><textarea rows="1" cols="20" wrap="off" readonly="readonly" name="dest_${addr.name}" >${addr.destination}</textarea></td>
     146<td class="destinations"><textarea rows="1" cols="40" wrap="off" readonly="readonly" name="dest_${addr.name}" >${addr.destination}</textarea></td>
    140147</tr>
    141148</c:forEach>
     
    161168<p class="add">
    162169<h3>Add new destination:</h3>
    163 Hostname: <input type="text" name="hostname" value="${book.hostname}" size="20">
    164 Destination: <textarea name="destination" rows="1" cols="20" wrap="off" >${book.destination}</textarea><br/>
     170<b>Hostname:</b> <input type="text" name="hostname" value="${book.hostname}" size="20">
     171<b>Destination:</b> <textarea name="destination" rows="1" cols="40" wrap="off" >${book.destination}</textarea><br/>
     172</p><p>
    165173<input type="image" name="action" value="add" src="images/add.png" alt="Add destination" />
    166174</p>
Note: See TracChangeset for help on using the changeset viewer.