Changeset - cd2ee462fc2c
[Not reviewed]
default
0 6 0
Marcin Kuzminski - 15 years ago 2010-06-13 23:14:04
marcin@python-works.com
implemented yui tooltip, and added it into annotation and main page.
6 files changed with 143 insertions and 29 deletions:
0 comments (0 inline, 0 general)
pylons_app/lib/helpers.py
Show inline comments
 
"""Helper functions
 

	
 
Consists of functions to typically be used within templates, but also
 
available to Controllers. This module is available to both as 'h'.
 
"""
 
from pygments.formatters import HtmlFormatter
 
from pygments import highlight as code_highlight
 
from pylons import url, app_globals as g
 
from pylons.i18n.translation import _, ungettext
 
from vcs.utils.annotate import annotate_highlight
 
from webhelpers.html import literal, HTML, escape
 
from webhelpers.html.tools import *
 
from webhelpers.html.builder import make_tag
 
from webhelpers.html.tags import auto_discovery_link, checkbox, css_classes, \
 
    end_form, file, form, hidden, image, javascript_link, link_to, link_to_if, \
 
    link_to_unless, ol, required_legend, select, stylesheet_link, submit, text, \
 
    password, textarea, title, ul, xml_declaration
 
    password, textarea, title, ul, xml_declaration, radio
 
from webhelpers.html.tools import auto_link, button_to, highlight, js_obfuscate, \
 
    mail_to, strip_links, strip_tags, tag_re
 
from webhelpers.number import format_byte_size, format_bit_size
 
from webhelpers.pylonslib import Flash as _Flash
 
from webhelpers.pylonslib.secure_form import secure_form
 
from webhelpers.text import chop_at, collapse, convert_accented_entities, \
 
    convert_misc_entities, lchop, plural, rchop, remove_formatting, \
 
    replace_whitespace, urlify, truncate
 
    replace_whitespace, urlify, truncate, wrap_paragraphs
 

	
 

	
 
#Custom helper here :)
 
#Custom helpers here :)
 
class _Link(object):
 
    '''
 
    Make a url based on label and url with help of url_for
 
    @param label:name of link    if not defined url is used
 
    @param url: the url for link
 
    '''
 

	
 
    def __call__(self, label='', *url_, **urlargs):
 
        if label is None or '':
 
            label = url
 
        link_fn = link_to(label, url(*url_, **urlargs))
 
        return link_fn
 

	
 
link = _Link()
 

	
 
class _GetError(object):
 

	
 
    def __call__(self, field_name, form_errors):
 
        tmpl = """<span class="error_msg">%s</span>"""
 
        if form_errors and form_errors.has_key(field_name):
 
            return literal(tmpl % form_errors.get(field_name))
 

	
 
get_error = _GetError()
 

	
 
def recursive_replace(str, replace=' '):
 
    """
 
    Recursive replace of given sign to just one instance
 
    @param str: given string
 
    @param replace:char to find and replace multiple instances
 
        
 
    Examples::
 
    >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-')
 
    'Mighty-Mighty-Bo-sstones'
 
    """
 

	
 
    if str.find(replace * 2) == -1:
 
        return str
 
    else:
 
        str = str.replace(replace * 2, replace)
 
        return recursive_replace(str, replace)  
 

	
 
class _ToolTip(object):
 
    
 
    def __call__(self, tooltip_title, trim_at=50):
 
        """
 
        Special function just to wrap our text into nice formatted autowrapped
 
        text
 
        @param tooltip_title:
 
        """
 
        
 
        return literal(wrap_paragraphs(tooltip_title, trim_at)\
 
                       .replace('\n', '<br/>')) 
 
    
 
    def activate(self):
 
        """
 
        Adds tooltip mechanism to the given Html all tooltips have to have 
 
        set class tooltip and set attribute tooltip_title.
 
        Then a tooltip will be generated based on that
 
        All with yui js tooltip
 
        """
 
        
 
        js = '''
 
        YAHOO.util.Event.onDOMReady(function(){
 
            function toolTipsId(){
 
                var ids = [];
 
                var tts = YAHOO.util.Dom.getElementsByClassName('tooltip');
 
                
 
                for (var i = 0; i < tts.length; i++) {
 
                    //if element doesn not have and id autgenerate one for tooltip
 
                    
 
                    if (!tts[i].id){
 
                        tts[i].id='tt'+i*100;
 
                    }
 
                    ids.push(tts[i].id);
 
                }
 
                return ids        
 
            };
 
            var myToolTips = new YAHOO.widget.Tooltip("tooltip", { 
 
                context: toolTipsId(),
 
                monitorresize:false,
 
                xyoffset :[0,0],
 
                autodismissdelay:300000,
 
                hidedelay:5,
 
                showdelay:20,
 
            });
 
            
 
            //Mouse subscribe optional arguments
 
            myToolTips.contextMouseOverEvent.subscribe(
 
                function(type, args) {
 
                    var context = args[0];
 
                    return true;
 
                });
 
            
 
            // Set the text for the tooltip just before we display it. Lazy method
 
            myToolTips.contextTriggerEvent.subscribe( 
 
                 function(type, args) { 
 
                        var context = args[0]; 
 
                        var txt = context.getAttribute('tooltip_title');
 
                        this.cfg.setProperty("text", txt);                     
 
                  });
 
        });
 
        '''         
 
        return literal(js)
 

	
 
tooltip = _ToolTip()
 

	
 
class _FilesBreadCrumbs(object):
 
    
 
    def __call__(self, repo_name, rev, paths):
 
        url_l = [link_to(repo_name, url('files_home', repo_name=repo_name, revision=rev, f_path=''))]
 
        paths_l = paths.split('/')
 
        
 
        for cnt, p in enumerate(paths_l, 1):
 
            if p != '':
 
                url_l.append(link_to(p, url('files_home', repo_name=repo_name, revision=rev, f_path='/'.join(paths_l[:cnt]))))
 

	
 
        return literal(' / '.join(url_l))
 

	
 
files_breadcrumbs = _FilesBreadCrumbs()
 

	
 
def pygmentize(filenode, **kwargs):
 
    """
 
    pygmentize function using pygments
 
    @param filenode:
 
    """
 
    return literal(code_highlight(filenode.content, filenode.lexer, HtmlFormatter(**kwargs)))
 

	
 
def pygmentize_annotation(filenode, **kwargs):
 
    """
 
    pygmentize function for annotation
 
    @param filenode:
 
    """
 
@@ -75,50 +163,43 @@ def pygmentize_annotation(filenode, **kw
 
    def gen_color():
 
        import random
 
        return [str(random.randrange(10, 235)) for _ in xrange(3)]
 
    def get_color_string(cs):
 
        if color_dict.has_key(cs):
 
            col = color_dict[cs]
 
        else:
 
            color_dict[cs] = gen_color()
 
            col = color_dict[cs]
 
        return "color: rgb(%s) ! important;" % (','.join(col))
 
        
 
    def url_func(changeset):
 
        return '%s\n' % (link_to('r%s:%s' % (changeset.revision, changeset.raw_id),
 
        url('changeset_home', repo_name='test', revision=changeset.raw_id),
 
        title=_('author') + ':%s - %s' % (changeset.author, changeset.message,),
 
        style=get_color_string(changeset.raw_id)))
 
           
 
    return literal(annotate_highlight(filenode, url_func, **kwargs))
 
        tooltip_html = "<div style='font-size:0.8em'><b>Author:</b> %s<br/><b>Date:</b> %s</b><br/><b>Message:</b> %s<br/></div>" 
 

	
 
def recursive_replace(str, replace=' '):
 
    """
 
    Recursive replace of given sign to just one instance
 
    @param str: given string
 
    @param replace:char to find and replace multiple instances
 
        tooltip_html = tooltip_html % (changeset.author,
 
                                               changeset.date,
 
                                               tooltip(changeset.message))
 
        lnk_format = 'r%s:%s' % (changeset.revision,
 
                                 changeset.raw_id)
 
        uri = link_to(
 
                lnk_format,
 
                url('changeset_home', repo_name='test',
 
                    revision=changeset.raw_id),
 
                style=get_color_string(changeset.raw_id),
 
                class_='tooltip',
 
                tooltip_title=tooltip_html
 
              )
 
        
 
    Examples::
 
    >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-')
 
    'Mighty-Mighty-Bo-sstones'
 
    """
 

	
 
    if str.find(replace * 2) == -1:
 
        return str
 
    else:
 
        str = str.replace(replace * 2, replace)
 
        return recursive_replace(str, replace)  
 
        uri += '\n'
 
        return uri   
 
    return literal(annotate_highlight(filenode, url_func, **kwargs))
 
      
 
def repo_name_slug(value):
 
    """
 
    Return slug of name of repository
 
    """
 
    slug = urlify(value)
 
    for c in """=[]\;'"<>,/~!@#$%^&*()+{}|:""":
 
        slug = slug.replace(c, '-')
 
    slug = recursive_replace(slug, '-')
 
    return slug
 
    
 
files_breadcrumbs = _FilesBreadCrumbs()
 
link = _Link()
 
flash = _Flash()
 
get_error = _GetError()
pylons_app/lib/utils.py
Show inline comments
 
@@ -134,24 +134,25 @@ def invalidate_cache(name, *args):
 
        from pylons_app.model.hg_model import _get_repos_cached
 
        region_invalidate(_get_repos_cached, None, *args)
 
        
 
    if name == 'full_changelog':
 
        from pylons_app.model.hg_model import _full_changelog_cached
 
        region_invalidate(_full_changelog_cached, None, *args)
 
        
 
from vcs.backends.base import BaseChangeset
 
from vcs.utils.lazy import LazyProperty
 
class EmptyChangeset(BaseChangeset):
 
    
 
    revision = -1
 
    message = ''
 

	
 
    @LazyProperty
 
    def raw_id(self):
 
        """
 
        Returns raw string identifing this changeset, useful for web
 
        representation.
 
        """
 
        return '0' * 12
 

	
 

	
 
def repo2db_mapper(initial_repo_list):
 
    """
pylons_app/model/hg_model.py
Show inline comments
 
@@ -139,17 +139,18 @@ class HgModel(object):
 
            tmp_d['name'] = repo.name
 
            tmp_d['name_sort'] = tmp_d['name'].lower()
 
            tmp_d['description'] = repo.description
 
            tmp_d['description_sort'] = tmp_d['description']
 
            tmp_d['last_change'] = last_change
 
            tmp_d['last_change_sort'] = last_change[1] - last_change[0]
 
            tmp_d['tip'] = tip.raw_id
 
            tmp_d['tip_sort'] = tip.revision 
 
            tmp_d['rev'] = tip.revision
 
            tmp_d['contact'] = repo.contact
 
            tmp_d['contact_sort'] = tmp_d['contact']
 
            tmp_d['repo_archives'] = list(repo._get_archives())
 
            tmp_d['last_msg'] = tip.message
 
            
 
            yield tmp_d
 

	
 
    def get_repo(self, repo_name):
 
        return _get_repos_cached()[repo_name]
pylons_app/public/css/monoblue_custom.css
Show inline comments
 
@@ -147,24 +147,49 @@ table tr.parity1 {
 
	background:transparent url("icons/cross_grey_small.png")	no-repeat scroll 0 0;
 
	cursor:pointer;
 
	height:16px;
 
	position:absolute;
 
	right:5px;
 
	top:5px;
 
	width:16px;
 
}
 

	
 
.error-message{
 
	color:#CC3300;
 
}
 
/**** Tooltip ****/
 
.yui-overlay,
 
.yui-panel-container {
 
    visibility:hidden;
 
    position:absolute;
 
    z-index: 2;
 
}
 

	
 
.yui-tt {
 
    visibility:hidden;
 
    position:absolute;
 
    color:#666666;
 
    background-color:#FFFFFF;
 
    font-family:arial,helvetica,verdana,sans-serif;
 
    padding:8px;
 
    border:2px solid #556CB5;
 
    font:100% sans-serif;
 
    width:auto;
 
}
 

	
 
.yui-tt-shadow {
 
    display: none;
 
}
 
/** end of Tooltip **/ 
 

	
 

	
 
div#main {
 
	padding: 5px;
 
}
 

	
 
div#container {
 
	background: #FFFFFF;
 
	position: relative;
 
	color: #666;
 
}
 

	
 
div.page-header {
pylons_app/templates/base/base.html
Show inline comments
 
@@ -19,24 +19,25 @@
 
    <div class="flash_msg">
 
    <% messages = h.flash.pop_messages() %>
 
		% if messages:
 
		<ul id="flash-messages">
 
		    % for message in messages:
 
		    <li class="${message.category}_msg">${message}</li>
 
		    % endfor
 
		</ul>
 
		% endif
 
    </div>        
 
    <div id="main"> 
 
    	${next.main()}
 
    	<script>${h.tooltip.activate()}</script>    	
 
    </div>
 
    <div class="page-footer">
 
        Hg App ${c.hg_app_version} &copy; 2010 by Marcin Kuzminski
 
    </div>   
 

	
 
    <div id="powered-by">
 
        <p>
 
        <a href="http://mercurial.selenic.com/" title="Mercurial">
 
            <img src="/images/hglogo.png" width="75" height="90" alt="mercurial"/></a>
 
        </p>
 
    </div>
 

	
 
@@ -131,24 +132,25 @@ def is_current(selected):
 
    </ul>
 
    </div>
 
    %endif
 
</%def>
 

	
 

	
 
<%def name="css()">
 
<link rel="stylesheet" href="/css/monoblue_custom.css" type="text/css" />
 
</%def>
 

	
 
<%def name="js()">
 
<script type="text/javascript" src="/js/yui/utilities/utilities.js"></script>
 
<script type="text/javascript" src="/js/yui/container/container-min.js"></script>
 
</%def>
 

	
 
<!-- DEFINITION OF FORM ERROR FETCHER -->
 
<%def name="get_form_error(element)">
 
	%if hasattr(c,'form_errors') and type(c.form_errors) == dict:
 
        %if c.form_errors.get(element,False):
 
            <span class="error-message">
 
                ${c.form_errors.get(element,'')}
 
            </span>
 
        %endif
 
	%endif           
 
</%def>
 
\ No newline at end of file
pylons_app/templates/index.html
Show inline comments
 
@@ -26,27 +26,31 @@ from pylons_app.lib import filters
 
	<table class="table_disp">
 
	  <tr class="header">
 
	    <td>${get_sort(_('Name'))}</td>
 
	    <td>${get_sort(_('Description'))}</td>
 
	    <td>${get_sort(_('Last change'))}</td>
 
	    <td>${get_sort(_('Tip'))}</td>
 
	    <td>${get_sort(_('Contact'))}</td>
 
	    <td>${_('RSS')}</td>
 
	    <td>${_('Atom')}</td>
 
	  </tr>	
 
	%for cnt,repo in enumerate(c.repos_list):
 
 		<tr class="parity${cnt%2}">
 
		    <td>${h.link(repo['name'],h.url('summary_home',repo_name=repo['name']))}</td>
 
		    <td>${h.link_to(repo['name'],
 
		    	h.url('summary_home',repo_name=repo['name']))}</td>
 
		    <td title="${repo['description']}">${h.truncate(repo['description'],60)}</td>
 
	        <td>${repo['last_change']|n,filters.age}</td>
 
	        <td>${h.link_to('r%s:%s' % (repo['rev'],repo['tip']),h.url('changeset_home',repo_name=repo['name'],revision=repo['tip']))}</td>
 
	        <td>${h.link_to('r%s:%s' % (repo['rev'],repo['tip']),
 
		        h.url('changeset_home',repo_name=repo['name'],revision=repo['tip']),
 
	        	class_="tooltip",
 
		    	tooltip_title=h.tooltip(repo['last_msg']))}</td>
 
	        <td title="${repo['contact']}">${repo['contact']|n,filters.person}</td>
 
			<td>
 
				<a title="${_('Subscribe to %s rss feed')%repo['name']}" class="rss_logo"  href="${h.url('rss_feed_home',repo_name=repo['name'])}"></a>
 
			</td>        
 
			<td>
 
				<a title="${_('Subscribe to %s atom feed')%repo['name']}"  class="atom_logo" href="${h.url('atom_feed_home',repo_name=repo['name'])}"></a>
 
			</td>
 
		</tr>
 
	%endfor
 
	</table>
 
</%def>    
0 comments (0 inline, 0 general)