Dodano wyszukiwarke na stronie glownej. Refs #75.
authorŁukasz Rekucki <lrekucki@gmail.com>
Fri, 4 Sep 2009 20:43:27 +0000 (22:43 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Fri, 4 Sep 2009 20:43:27 +0000 (22:43 +0200)
apps/explorer/views.py
lib/hg.py
project/static/css/filelist.css [new file with mode: 0755]
project/static/js/editor.js
project/static/js/jquery.hpanel.js
project/static/js/jquery.lazyload.js [changed mode: 0644->0755]
project/static/js/jquery.paginate.js [new file with mode: 0644]
project/templates/explorer/file_list.html

index 7d18688..d6118ac 100644 (file)
@@ -5,7 +5,7 @@ from librarian import html, parser, dcparser, ParseError, ValidationError
 
 from django.conf import settings
 from django.contrib.auth.decorators import login_required, permission_required
-from django.core.paginator import Paginator, InvalidPage, EmptyPage
+
 from django.core.urlresolvers import reverse
 from django.http import HttpResponseRedirect, HttpResponse
 from django.utils import simplejson as json
@@ -40,21 +40,12 @@ def ajax_login_required(view):
 #
 @with_repo
 def file_list(request, repo):
-    paginator = Paginator( repo.file_list('default'), 100);
+    latest_default = repo.repo.branchtags()['default']
+    files = list( repo.repo[latest_default] )
     bookform = forms.BookUploadForm()
 
-    try:
-        page = int(request.GET.get('page', '1'))
-    except ValueError:
-        page = 1
-
-    try:
-        files = paginator.page(page)
-    except (EmptyPage, InvalidPage):
-        files = paginator.page(paginator.num_pages)
-
     return direct_to_template(request, 'explorer/file_list.html', extra_context={
-        'files': files, 'page': page, 'bookform': bookform,
+        'files': files, 'bookform': bookform,
     })
 
 @permission_required('explorer.can_add_files')
@@ -186,7 +177,7 @@ def file_dc(request, path, repo):
 @login_required
 @with_repo
 def display_editor(request, path, repo):
-    path = unicode(path).encode("utf-8")
+    
     if not repo.file_exists(path, models.user_branch(request.user)):
         try:
             data = repo.get_file(path, 'default')
@@ -199,7 +190,7 @@ def display_editor(request, path, repo):
                 
             repo.in_branch(new_file, models.user_branch(request.user) )
         except hg.RepositoryException, e:
-            return direct_to_templace(request, 'explorer/file_unavailble.html',\
+            return direct_to_template(request, 'explorer/file_unavailble.html',\
                 extra_context = { 'path': path, 'error': e })
 
     return direct_to_template(request, 'explorer/editor.html', extra_context={
@@ -215,7 +206,6 @@ def display_editor(request, path, repo):
 @ajax_login_required
 @with_repo
 def xmleditor_panel(request, path, repo):
-    form = forms.BookForm()
     text = repo.get_file(path, models.user_branch(request.user))
     
     return direct_to_template(request, 'explorer/panels/xmleditor.html', extra_context={
index 18a8d18..07ec9a7 100644 (file)
--- a/lib/hg.py
+++ b/lib/hg.py
@@ -1,7 +1,6 @@
 # -*- coding: utf-8 -*-
 import os
-import codecs
-from mercurial import localrepo, ui, match, node, encoding, util
+from mercurial import localrepo, ui, encoding, util
 import mercurial.merge, mercurial.error
 
 encoding.encoding = 'utf-8'
diff --git a/project/static/css/filelist.css b/project/static/css/filelist.css
new file mode 100755 (executable)
index 0000000..f5b8ce0
--- /dev/null
@@ -0,0 +1,33 @@
+/* 
+    Document   : filelist
+    Created on : 2009-09-04, 20:44:44
+    Author     : lreqc
+    Description:
+        Dodatkowe style dla listy plików na stronie głównej.
+*/
+
+#main-page-widgets > div {
+    float: left;
+    border: 1px solid black;
+    padding: 0.5em 2em;
+    margin: 1em;    
+}
+
+.file-list-widget {
+    background: #DDF;
+    max-width: 60%;
+}
+
+.file-list-widget .page-nav-wrap button {
+    width: 2.5em;
+}
+
+.upload-file-widget {
+    min-width: 20%;
+    width: 25%;
+}
+
+
+
+
+
index e615b79..879762c 100644 (file)
@@ -151,10 +151,10 @@ Panel.prototype.connectToolbar = function()
     action_buttons.each(function() {
         var button = $(this);
         var hk = button.attr('ui:hotkey');
+        var params = $.evalJSON(button.attr('ui:action-params'));
 
         var callback = function() {
-           editor.callScriptlet(button.attr('ui:action'),
-                self, eval(button.attr('ui:action-params')) );
+           editor.callScriptlet(button.attr('ui:action'), self, params);
         };
 
         // connect button
index bec82e0..1ad0d17 100644 (file)
@@ -11,7 +11,7 @@
                        $('.panel-overlay', mydata.root).css('display', 'block');
                        return false;
                },
-               resize_changed: function(event) {
+       resize_changed: function(event) {
                        var old_width = parseInt(event.data.overlay.css('width'));
                        var delta = event.pageX + event.data.hotspot_x - old_width;
                        event.data.overlay.css({'width': old_width + delta});
old mode 100644 (file)
new mode 100755 (executable)
diff --git a/project/static/js/jquery.paginate.js b/project/static/js/jquery.paginate.js
new file mode 100644 (file)
index 0000000..710b184
--- /dev/null
@@ -0,0 +1,66 @@
+(function($) {
+    
+    var settings = {
+            items: [],
+            itemsPerPage: 20,
+            page: 0
+    };
+
+    $.fn.filterItems = function(condition)
+    {
+        settings.items = $('p', this);
+
+        if(condition) settings.items = settings.items.filter(function() {
+            return condition( $(this).attr('title') );
+        });
+
+        var pageCount = Math.ceil(settings.items.length / settings.itemsPerPage);
+        var buttons =  $('.page-nav-wrap button', this.parent());
+        buttons.show().filter(function(i) { return i >= pageCount; }).hide();
+        this.switchToPage();
+    };
+
+    $.fn.switchToPage = function(index)
+    {
+        index = index || settings.page;
+        var start = index * settings.itemsPerPage;
+        var end = start + settings.itemsPerPage;
+        $('p', this).hide();
+        
+        var visibleItems = settings.items.filter(function(i) { return i >= start && i < end; });
+        visibleItems.show();        
+    }
+
+    $.fn.paginate = function(options)
+    {
+        var list = this;                 
+
+        // apply defaults
+        if (options) $.extend(settings, options);
+        settings.items = $('p', list);       
+
+        var nav = $('<p class="page-nav-wrap"></p>');
+        list.before(nav);
+        var pageCount = Math.floor(settings.items.length / settings.itemsPerPage);
+        var orphanCount = settings.items.length - (pageCount * settings.itemsPerPage);
+        var button = null;
+
+        for(var i=0; i < pageCount; i++)
+        {
+            button = $("<button type='button'>"+(i+1)+"</button>");
+            button.bind('click', i, function(event) { list.switchToPage(event.data); });
+            nav.append(button);            
+        }        
+
+        if(orphanCount > 0)
+        {
+            i = pageCount;
+            button = $("<button type='button'>"+(i+1)+"</button>");
+            button.bind('click', i, function(event) { list.switchToPage(event.data); });
+            nav.append(button);            
+        }
+
+        list.filterItems(function(){return true;});
+        list.switchToPage(0);
+    };
+})(jQuery);
index 2513637..a36d353 100644 (file)
@@ -1,43 +1,58 @@
 {% extends "base.html" %}
 
+{% block extrahead %}
+<link rel="stylesheet" href="{{ STATIC_URL }}css/filelist.css" type="text/css" />
+<script type="text/javascript" charset="utf-8" src="{{ STATIC_URL }}js/jquery.paginate.js"></script>
+<script type="text/javascript" charset="utf-8">
+$(function() {
+    $('#file-list').paginate({itemsPerPage: 15});
+
+    $('#file-list-find-button').click(function(event)
+    {
+        var expr = new RegExp( $('#file-list-filter').val() );
+
+        $('#file-list').filterItems( function(filename) {
+            return expr.test(filename);
+        });
+
+        event.preventDefault();
+    });
+
+    $('#file-list-reset-button').click(function(event)
+    {
+        $('#file-list').filterItems();
+        event.preventDefault();
+    });
+});
+</script>
+{% endblock extrahead %}
+
 {% block maincontent %}
+<div id="main-page-widgets">
+
+<div class="file-list-widget">
+    <form action="#" method="GET">
+    <p><input name="filter" id="file-list-filter" type="text" size="60" />
+        <input type="submit" value="Znajdź" id="file-list-find-button"/>
+        <input type="reset" value="Wyczyść" id="file-list-reset-button"/>
+    </p>
+    </form>
+    <div id="file-list">
+    {% for file in files %}
+    <p title="{{file}}"><a href="{% url editor_view file %}">{{ file }}</a></p>
+    {% endfor %}
+    </div>
+</div>
 
 {% if perms.explorer.can_add_files %}
+<div class="upload-file-widget">
 <h2>Dodaj nowy utwór</h2>
-
 <form action="{% url file_upload %}" method="POST" enctype="multipart/form-data">
     {{ bookform.as_p }}
     <p><button type="submit">Dodaj książkę</button></p>
 </form>
+</div>
 {% endif %}
 
-<h2>Wszystkie utwory:</h2>
-<table class="object-list" cellspacing="0">
-    <tr><th>Lp.</th><th>Nazwa utworu</th><th>Wersje</th></tr>
-    <tr><td colspan="3" class="page-navigation">
-        {% if files.has_previous %}
-        <span class="prev-page-marker">
-            <a href="?page={{ files.previous_page_number }}">Poprzednia</a>
-        </span>
-        {% endif %}
-
-        <span>Strona {{files.number}} z {{files.paginator.num_pages}}</span>
-
-        {% if files.has_next %}
-        <span class="next-page-marker">
-            <a href="?page={{ files.next_page_number }}">Następna</a>
-        </span>
-        {% endif %}
-    </td>
-    </tr>
-    {% for file in files.object_list %}
-    <tr>
-        <td>{{forloop.counter0|add:files.start_index}}.</td>
-        <td><a href="{% url editor_view file %}">{{ file }}</a></td>
-        <td> &nbsp; </td>
-    </tr>
-    {% endfor %}
-</table>
-
-
+</div>
 {% endblock maincontent %}