from mako import runtime, filters, cache
UNDEFINED = runtime.UNDEFINED
__M_dict_builtin = dict
__M_locals_builtin = locals
_magic_number = 5
_modified_time = 1287725327.4199979
_template_filename=u'templates/root/history_common.mako'
_template_uri=u'root/history_common.mako'
_template_cache=cache.Cache(__name__, _modified_time)
_source_encoding=None
_exports = ['render_dataset']


def render_body(context,**pageargs):
    context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        n_ = context.get('n_', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 1
        _=n_ 
        
        __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin()[__M_key]) for __M_key in ['_'] if __M_key in __M_locals_builtin()]))
        __M_writer(u'\n')
        # SOURCE LINE 208
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_render_dataset(context,data,hid,show_deleted_on_refresh=False,for_editing=True):
    context.caller_stack._push_frame()
    try:
        h = context.get('h', UNDEFINED)
        app = context.get('app', UNDEFINED)
        def render_dataset(data,hid,show_deleted_on_refresh=False,for_editing=True):
            return render_render_dataset(context,data,hid,show_deleted_on_refresh,for_editing)
        request = context.get('request', UNDEFINED)
        len = context.get('len', UNDEFINED)
        enumerate = context.get('enumerate', UNDEFINED)
        trans = context.get('trans', UNDEFINED)
        _ = context.get('_', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 3
        __M_writer(u'\n    <a name="')
        # SOURCE LINE 4
        __M_writer(unicode(trans.security.encode_id( data.id )))
        __M_writer(u'"></a>\n    ')
        # SOURCE LINE 5

        if data.state in ['no state','',None]:
            data_state = "queued"
        else:
            data_state = data.state
        current_user_roles = trans.get_current_user_roles()
            
        
        # SOURCE LINE 11
        __M_writer(u'\n')
        # SOURCE LINE 12
        if not trans.user_is_admin() and not trans.app.security_agent.can_access_dataset( current_user_roles, data.dataset ):
            # SOURCE LINE 13
            __M_writer(u'        <div class="historyItemWrapper historyItem historyItem-')
            __M_writer(unicode(data_state))
            __M_writer(u' historyItem-noPermission" id="historyItem-')
            __M_writer(unicode(data.id))
            __M_writer(u'">\n')
            # SOURCE LINE 14
        else:
            # SOURCE LINE 15
            __M_writer(u'        <div class="historyItemWrapper historyItem historyItem-')
            __M_writer(unicode(data_state))
            __M_writer(u'" id="historyItem-')
            __M_writer(unicode(data.id))
            __M_writer(u'">\n')
        # SOURCE LINE 17
        __M_writer(u'        \n')
        # SOURCE LINE 18
        if data.deleted:
            # SOURCE LINE 19
            __M_writer(u'        <div class="warningmessagesmall">\n            <strong>This dataset has been deleted. Click <a href="')
            # SOURCE LINE 20
            __M_writer(unicode(h.url_for( controller='dataset', action='undelete', id=data.id )))
            __M_writer(u'" class="historyItemUndelete" id="historyItemUndeleter-')
            __M_writer(unicode(data.id))
            __M_writer(u'" target="galaxy_history">here</a> to undelete.</strong>\n        </div>\n')
        # SOURCE LINE 23
        __M_writer(u'\n')
        # SOURCE LINE 24
        if data.visible is False:
            # SOURCE LINE 25
            __M_writer(u'        <div class="warningmessagesmall">\n            <strong>This dataset has been hidden. Click <a href="')
            # SOURCE LINE 26
            __M_writer(unicode(h.url_for( controller='dataset', action='unhide', id=data.id )))
            __M_writer(u'" class="historyItemUnhide" id="historyItemUnhider-')
            __M_writer(unicode(data.id))
            __M_writer(u'" target="galaxy_history">here</a> to unhide.</strong>\n        </div>\n')
        # SOURCE LINE 29
        __M_writer(u'\n\n')
        # SOURCE LINE 32
        __M_writer(u'    <div style="overflow: hidden;" class="historyItemTitleBar">     \n        <div class="historyItemButtons">\n')
        # SOURCE LINE 34
        if data_state == "upload":
            # SOURCE LINE 38
            __M_writer(u"                <img title='Display Data' class='icon-button display_disabled' />\n")
            # SOURCE LINE 39
            if for_editing:
                # SOURCE LINE 40
                __M_writer(u"                    <img title='Edit Attributes' class='icon-button edit_disabled' />\n")
            # SOURCE LINE 42
        else:
            # SOURCE LINE 43
            __M_writer(u'                ')
 
            dataset_id = trans.security.encode_id( data.id )
            if for_editing:
                display_url = h.url_for( controller='dataset', action='display', dataset_id=dataset_id, preview=True, filename='' )
            else:
                # Get URL for display only.
                if data.history.user and data.history.user.username:
                    display_url = h.url_for( controller='dataset', action='display_by_username_and_slug',
                                             username=data.history.user.username, slug=dataset_id )
                else:
                    # HACK: revert to for_editing display URL when there is no user/username. This should only happen when
                    # there's no user/username because dataset is being displayed by history/view after error reported.
                    # There are no security concerns here because both dataset/display and dataset/display_by_username_and_slug
                    # check user permissions (to the same degree) before displaying.
                    display_url = h.url_for( controller='dataset', action='display', dataset_id=dataset_id, preview=True, filename='' )
                            
            
            # SOURCE LINE 58
            __M_writer(u'\n                <a class="icon-button display tooltip" title="Display data in browser" href="')
            # SOURCE LINE 59
            __M_writer(unicode(display_url))
            __M_writer(u'"\n')
            # SOURCE LINE 60
            if for_editing:
                # SOURCE LINE 61
                __M_writer(u'                    target="galaxy_main"\n')
            # SOURCE LINE 63
            __M_writer(u'                ></a>\n')
            # SOURCE LINE 64
            if for_editing:
                # SOURCE LINE 65
                __M_writer(u'                    <a class="icon-button edit tooltip" title="Edit attributes" href="')
                __M_writer(unicode(h.url_for( controller='root', action='edit', id=data.id )))
                __M_writer(u'" target="galaxy_main"></a>\n')
        # SOURCE LINE 68
        if for_editing:
            # SOURCE LINE 69
            __M_writer(u'                <a class="icon-button delete tooltip" title="Delete" href="')
            __M_writer(unicode(h.url_for( action='delete', id=data.id, show_deleted_on_refresh=show_deleted_on_refresh )))
            __M_writer(u'" id="historyItemDeleter-')
            __M_writer(unicode(data.id))
            __M_writer(u'"></a>\n')
        # SOURCE LINE 71
        __M_writer(u'        </div>\n        <span class="state-icon"></span>\n        <span class="historyItemTitle">')
        # SOURCE LINE 73
        __M_writer(unicode(hid))
        __M_writer(u': ')
        __M_writer(unicode(data.display_name()))
        __M_writer(u'</span>\n    </div>\n        \n')
        # SOURCE LINE 77
        __M_writer(u'    \n    <div id="info')
        # SOURCE LINE 78
        __M_writer(unicode(data.id))
        __M_writer(u'" class="historyItemBody">\n')
        # SOURCE LINE 79
        if not trans.user_is_admin() and not trans.app.security_agent.can_access_dataset( current_user_roles, data.dataset ):
            # SOURCE LINE 80
            __M_writer(u'            <div>You do not have permission to view this dataset.</div>\n')
            # SOURCE LINE 81
        elif data_state == "upload":
            # SOURCE LINE 82
            __M_writer(u'            <div>Dataset is uploading</div>\n')
            # SOURCE LINE 83
        elif data_state == "queued":
            # SOURCE LINE 84
            __M_writer(u'            <div>')
            __M_writer(unicode(_('Job is waiting to run')))
            __M_writer(u'</div>\n')
            # SOURCE LINE 85
        elif data_state == "running":
            # SOURCE LINE 86
            __M_writer(u'            <div>')
            __M_writer(unicode(_('Job is currently running')))
            __M_writer(u'</div>\n')
            # SOURCE LINE 87
        elif data_state == "error":
            # SOURCE LINE 88
            __M_writer(u'            <div>\n                An error occurred running this job: <i>')
            # SOURCE LINE 89
            __M_writer(unicode(data.display_info().strip()))
            __M_writer(u'</i>\n            </div>\n            <div>\n                <a href="')
            # SOURCE LINE 92
            __M_writer(unicode(h.url_for( controller='dataset', action='errors', id=data.id )))
            __M_writer(u'" target="galaxy_main" title="View or report this error" class="icon-button bug tooltip"></a>\n                <a href="')
            # SOURCE LINE 93
            __M_writer(unicode(h.url_for( controller='tool_runner', action='rerun', id=data.id )))
            __M_writer(u'" target="galaxy_main" title="Run this job again" class="icon-button arrow-circle tooltip"></a>\n            </div>\n')
            # SOURCE LINE 95
        elif data_state == "discarded":
            # SOURCE LINE 96
            __M_writer(u'            <div>\n                The job creating this dataset was cancelled before completion.\n            </div>\n')
            # SOURCE LINE 99
        elif data_state == 'setting_metadata':
            # SOURCE LINE 100
            __M_writer(u'            <div>')
            __M_writer(unicode(_('Metadata is being Auto-Detected.')))
            __M_writer(u'</div>\n')
            # SOURCE LINE 101
        elif data_state == "empty":
            # SOURCE LINE 102
            __M_writer(u'            <div>')
            __M_writer(unicode(_('No data: ')))
            __M_writer(u'<i>')
            __M_writer(unicode(data.display_info()))
            __M_writer(u'</i></div>\n')
            # SOURCE LINE 103
        elif data_state in [ "ok", "failed_metadata" ]:
            # SOURCE LINE 104
            if data_state == "failed_metadata":
                # SOURCE LINE 105
                __M_writer(u'                <div class="warningmessagesmall" style="margin: 4px 0 4px 0">\n                    An error occurred setting the metadata for this dataset.  You may be able to <a href="')
                # SOURCE LINE 106
                __M_writer(unicode(h.url_for( controller='root', action='edit', id=data.id )))
                __M_writer(u'" target="galaxy_main">set it manually or retry auto-detection</a>.\n                </div>\n')
            # SOURCE LINE 109
            __M_writer(u'            <div>\n                ')
            # SOURCE LINE 110
            __M_writer(unicode(data.blurb))
            __M_writer(u',\n                format: <span class="')
            # SOURCE LINE 111
            __M_writer(unicode(data.ext))
            __M_writer(u'">')
            __M_writer(unicode(data.ext))
            __M_writer(u'</span>, \n                database:\n')
            # SOURCE LINE 113
            if data.dbkey == '?':
                # SOURCE LINE 114
                __M_writer(u'                    <a href="')
                __M_writer(unicode(h.url_for( controller='root', action='edit', id=data.id )))
                __M_writer(u'" target="galaxy_main">')
                __M_writer(unicode(_(data.dbkey)))
                __M_writer(u'</a>\n')
                # SOURCE LINE 115
            else:
                # SOURCE LINE 116
                __M_writer(u'                    <span class="')
                __M_writer(unicode(data.dbkey))
                __M_writer(u'">')
                __M_writer(unicode(_(data.dbkey)))
                __M_writer(u'</span>\n')
            # SOURCE LINE 118
            __M_writer(u'            </div>\n            <div class="info">')
            # SOURCE LINE 119
            __M_writer(unicode(_('Info: ')))
            __M_writer(unicode(data.display_info()))
            __M_writer(u'</div>\n            <div> \n                ')
            # SOURCE LINE 121
            dataset_id=trans.security.encode_id( data.id ) 
            
            __M_writer(u'\n')
            # SOURCE LINE 122
            if data.has_data():
                # SOURCE LINE 123
                __M_writer(u'                    <a href="')
                __M_writer(unicode(h.url_for( controller='dataset', action='display', dataset_id=dataset_id, to_ext=data.ext )))
                __M_writer(u'" title="Save" class="icon-button disk tooltip"></a>\n')
                # SOURCE LINE 124
                if for_editing:
                    # SOURCE LINE 125
                    __M_writer(u'                        <a href="')
                    __M_writer(unicode(h.url_for( controller='tool_runner', action='rerun', id=data.id )))
                    __M_writer(u'" target="galaxy_main" title="Run this job again" class="icon-button arrow-circle tooltip"></a>\n')
                    # SOURCE LINE 126
                    if app.config.get_bool( 'enable_tracks', False ) and data.ext in app.datatypes_registry.get_available_tracks():
                        # SOURCE LINE 127
                        __M_writer(u'                            <a data-url="')
                        __M_writer(unicode(h.url_for( controller='tracks', action='list_tracks' )))
                        __M_writer(u'" class="icon-button vis-chart tooltip trackster-add"\n                                action-url="')
                        # SOURCE LINE 128
                        __M_writer(unicode(h.url_for( controller='tracks', action='browser', dataset_id=dataset_id)))
                        __M_writer(u'"\n                                new-url="')
                        # SOURCE LINE 129
                        __M_writer(unicode(h.url_for( controller='tracks', action='index', dataset_id=dataset_id, default_dbkey=data.dbkey)))
                        __M_writer(u'" title="Visualize in Trackster"></a>\n')
                    # SOURCE LINE 131
                    if trans.user:
                        # SOURCE LINE 132
                        __M_writer(u'                            <div style="float: right">\n                                <a href="')
                        # SOURCE LINE 133
                        __M_writer(unicode(h.url_for( controller='tag', action='retag', item_class=data.__class__.__name__, item_id=dataset_id )))
                        __M_writer(u'" target="galaxy_main" title="Edit dataset tags" class="icon-button tags tooltip"></a>\n                                <a href="')
                        # SOURCE LINE 134
                        __M_writer(unicode(h.url_for( controller='dataset', action='annotate', id=dataset_id )))
                        __M_writer(u'" target="galaxy_main" title="Edit dataset annotation" class="icon-button annotate tooltip"></a>\n                            </div>\n                            <div style="clear: both"></div>\n                            <div class="tag-area" style="display: none">\n                                <strong>Tags:</strong>\n                                <div class="tag-elt"></div>\n                            </div>\n                            <div id="')
                        # SOURCE LINE 141
                        __M_writer(unicode(dataset_id))
                        __M_writer(u'-annotation-area" class="annotation-area" style="display: none">\n                                <strong>Annotation:</strong>\n                                <div id="')
                        # SOURCE LINE 143
                        __M_writer(unicode(dataset_id))
                        __M_writer(u'-annotation-elt" style="margin: 1px 0px 1px 0px" class="annotation-elt tooltip editable-text" title="Edit dataset annotation"></div>\n                            </div>\n                            \n')
                    # SOURCE LINE 147
                else:
                    # SOURCE LINE 150
                    __M_writer(u'                        <div style="clear: both"></div>\n')
                # SOURCE LINE 152
                __M_writer(u'    \t\t        <div style="clear: both"></div>\n')
                # SOURCE LINE 153
                for display_app in data.datatype.get_display_types():
                    # SOURCE LINE 154
                    __M_writer(u'                        ')
                    target_frame, display_links = data.datatype.get_display_links( data, display_app, app, request.base ) 
                    
                    __M_writer(u'\n')
                    # SOURCE LINE 155
                    if len( display_links ) > 0:
                        # SOURCE LINE 156
                        __M_writer(u'                            | ')
                        __M_writer(unicode(data.datatype.get_display_label(display_app)))
                        __M_writer(u'\n')
                        # SOURCE LINE 157
                        for display_name, display_link in display_links:
                            # SOURCE LINE 158
                            __M_writer(u'                                <a target="')
                            __M_writer(unicode(target_frame))
                            __M_writer(u'" href="')
                            __M_writer(unicode(display_link))
                            __M_writer(u'">')
                            __M_writer(unicode(_(display_name)))
                            __M_writer(u'</a> \n')
                # SOURCE LINE 162
                for display_app in data.get_display_applications( trans ).itervalues():
                    # SOURCE LINE 163
                    __M_writer(u'                        | ')
                    __M_writer(unicode(display_app.name))
                    __M_writer(u' \n')
                    # SOURCE LINE 164
                    for link_app in display_app.links.itervalues():
                        # SOURCE LINE 165
                        __M_writer(u'                            <a target="')
                        __M_writer(unicode(link_app.url.get( 'target_frame', '_blank' )))
                        __M_writer(u'" href="')
                        __M_writer(unicode(link_app.get_display_url( data, trans )))
                        __M_writer(u'">')
                        __M_writer(unicode(_(link_app.name)))
                        __M_writer(u'</a> \n')
                # SOURCE LINE 168
            elif for_editing:
                # SOURCE LINE 169
                __M_writer(u'                    <a href="')
                __M_writer(unicode(h.url_for( controller='tool_runner', action='rerun', id=data.id )))
                __M_writer(u'" target="galaxy_main" title="Run this job again" class="icon-button arrow-circle tooltip"></a>\n')
            # SOURCE LINE 171
            __M_writer(u'    \n                </div>\n')
            # SOURCE LINE 173
            if data.peek != "no peek":
                # SOURCE LINE 174
                __M_writer(u'                    <div><pre id="peek')
                __M_writer(unicode(data.id))
                __M_writer(u'" class="peek">')
                __M_writer(unicode(_(data.display_peek())))
                __M_writer(u'</pre></div>\n')
            # SOURCE LINE 176
        else:
            # SOURCE LINE 177
            __M_writer(u'            <div>')
            __M_writer(unicode(_('Error: unknown dataset state "%s".') % data_state))
            __M_writer(u'</div>\n')
        # SOURCE LINE 179
        __M_writer(u'           \n')
        # SOURCE LINE 181
        __M_writer(u'                          \n')
        # SOURCE LINE 182
        if len( data.children ) > 0:
            # SOURCE LINE 185
            __M_writer(u'            ')

            children = []
            for child in data.children:
                if child.visible:
                    children.append( child )
            
            
            # SOURCE LINE 190
            __M_writer(u'\n')
            # SOURCE LINE 191
            if len( children ) > 0:
                # SOURCE LINE 192
                __M_writer(u'                <div>\n                    There are ')
                # SOURCE LINE 193
                __M_writer(unicode(len( children )))
                __M_writer(u' secondary datasets.\n')
                # SOURCE LINE 194
                for idx, child in enumerate(children):
                    # SOURCE LINE 195
                    __M_writer(u'                        ')
                    __M_writer(unicode(render_dataset( child, idx + 1, show_deleted_on_refresh = show_deleted_on_refresh )))
                    __M_writer(u'\n')
                # SOURCE LINE 197
                __M_writer(u'                </div>\n')
        # SOURCE LINE 200
        __M_writer(u'\n    <div style="clear: both;"></div>\n\n    </div>\n        \n        \n    </div>\n\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


