Source

galaxy-central / templates / root / alternate_history.mako

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
<%inherit file="/base.mako"/>

<%def name="title()">
    ${_('Galaxy History')}
</%def>

## ---------------------------------------------------------------------------------------------------------------------
<%def name="create_localization_json( strings_to_localize )">
    ## converts strings_to_localize (a list of strings) into a JSON dictionary of { string : localized string }
${ h.to_json_string( dict([ ( string, _(string) ) for string in strings_to_localize ]) ) }
## ?? add: if string != _(string)
</%def>

<%def name="get_page_localized_strings()">
    ## a list of localized strings used in the backbone views, etc. (to be loaded and cached)
    ##! change on per page basis
    <%
        ## havent been localized
        ##[
        ##    "anonymous user",
        ##    "Click to rename history",
        ##    "Click to see more actions",
        ##    "Edit history tags",
        ##    "Edit history annotation",
        ##    "Tags",
        ##    "Annotation",
        ##    "Click to edit annotation",
        ##    "You are over your disk ...w your allocated quota.",
        ##    "Show deleted",
        ##    "Show hidden",
        ##    "Display data in browser",
        ##    "Edit Attributes",
        ##    "Download",
        ##    "View details",
        ##    "Run this job again",
        ##    "Visualize",
        ##    "Edit dataset tags",
        ##    "Edit dataset annotation",
        ##    "Trackster",
        ##    "Circster",
        ##    "Scatterplot",
        ##    "GeneTrack",
        ##    "Local",
        ##    "Web",
        ##    "Current",
        ##    "main",
        ##    "Using"
        ##]
        strings_to_localize = [
            
            # from history.mako
            # not needed?: "Galaxy History",
            'refresh',
            'collapse all',
            'hide deleted',
            'hide hidden',
            'You are currently viewing a deleted history!',
            "Your history is empty. Click 'Get Data' on the left pane to start",
            
            # from history_common.mako
            'Download',
            'Display Data',
            'Display data in browser',
            'Edit attributes',
            'Delete',
            'Job is waiting to run',
            'View Details',
            'Run this job again',
            'Job is currently running',
            'View Details',
            'Run this job again',
            'Metadata is being Auto-Detected.',
            'No data: ',
            'format: ',
            'database: ',
            #TODO localized data.dbkey??
            'Info: ',
            #TODO localized display_app.display_name??
            # _( link_app.name )
            # localized peek...ugh
            'Error: unknown dataset state',
        ]
        return strings_to_localize
    %>
</%def>

## ---------------------------------------------------------------------------------------------------------------------
## all the possible history urls (primarily from web controllers at this point)
<%def name="get_history_url_templates()">
<%
    from urllib import unquote_plus

    history_class_name      = history.__class__.__name__
    encoded_id_template     = '<%= id %>'

    url_dict = {
        ##TODO: into their own MVs
        'rename'        : h.url_for( controller="/history", action="rename_async",
                            id=encoded_id_template ),
        'tag'           : h.url_for( controller='tag', action='get_tagging_elt_async',
                            item_class=history_class_name, item_id=encoded_id_template ),
        'annotate'      : h.url_for( controller="/history", action="annotate_async",
                            id=encoded_id_template )
    }
%>
${ unquote_plus( h.to_json_string( url_dict ) ) }
</%def>

## ---------------------------------------------------------------------------------------------------------------------
## all the possible hda urls (primarily from web controllers at this point) - whether they should have them or not
##TODO: unify url_for btwn web, api
<%def name="get_hda_url_templates()">
<%
    from urllib import unquote_plus

    hda_class_name      = 'HistoryDatasetAssociation'
    encoded_id_template = '<%= id %>'
    #username_template   = '<%= username %>'
    hda_ext_template    = '<%= file_ext %>'
    meta_type_template  = '<%= file_type %>'

    display_app_name_template = '<%= name %>'
    display_app_link_template = '<%= link %>'

    url_dict = {
        # ................................................................ warning message links
        'purge' : h.url_for( controller='dataset', action='purge',
            dataset_id=encoded_id_template ),
        #TODO: hide (via api)
        'unhide' : h.url_for( controller='dataset', action='unhide',
            dataset_id=encoded_id_template ),
        #TODO: via api
        'undelete' : h.url_for( controller='dataset', action='undelete',
            dataset_id=encoded_id_template ),

        # ................................................................ title actions (display, edit, delete),
        'display' : h.url_for( controller='dataset', action='display',
            dataset_id=encoded_id_template, preview=True, filename='' ),
        #TODO:
        #'user_display_url' : h.url_for( controller='dataset', action='display_by_username_and_slug',
        #    username=username_template, slug=encoded_id_template, filename='' ),
        'edit' : h.url_for( controller='dataset', action='edit',
            dataset_id=encoded_id_template ),

        #TODO: via api
        #TODO: show deleted handled by history
        'delete' : h.url_for( controller='dataset', action='delete',
            dataset_id=encoded_id_template, show_deleted_on_refresh=show_deleted ),

        # ................................................................ download links (and associated meta files),
        'download' : h.url_for( controller='/dataset', action='display',
            dataset_id=encoded_id_template, to_ext=hda_ext_template ),
        'meta_download' : h.url_for( controller='/dataset', action='get_metadata_file',
            hda_id=encoded_id_template, metadata_name=meta_type_template ),

        # ................................................................ primary actions (errors, params, rerun),
        'report_error' : h.url_for( controller='dataset', action='errors',
            id=encoded_id_template ),
        'show_params' : h.url_for( controller='dataset', action='show_params',
            dataset_id=encoded_id_template ),
        'rerun' : h.url_for( controller='tool_runner', action='rerun',
            id=encoded_id_template ),
        'visualization' : h.url_for( controller='visualization' ),

        # ................................................................ secondary actions (tagging, annotation),
        'tags' : {
            'get' : h.url_for( controller='tag', action='get_tagging_elt_async',
                item_class=hda_class_name, item_id=encoded_id_template ),
            'set' : h.url_for( controller='tag', action='retag',
                item_class=hda_class_name, item_id=encoded_id_template ),
        },
        'annotation' : {
            #TODO: needed? doesn't look like this is used (unless graceful degradation)
            #'annotate_url' : h.url_for( controller='dataset', action='annotate',
            #    id=encoded_id_template ),
            'get' : h.url_for( controller='dataset', action='get_annotation_async',
                id=encoded_id_template ),
            'set' : h.url_for( controller='/dataset', action='annotate_async',
                id=encoded_id_template ),
        },
    }
%>
${ unquote_plus( h.to_json_string( url_dict ) ) }
</%def>

## -----------------------------------------------------------------------------
## get the history, hda, user data from the api (as opposed to the web controllers/mako)

## I'd rather do without these (esp. the get_hdas which hits the db twice)
##   but we'd need a common map producer (something like get_api_value but more complete)
##TODO: api/web controllers should use common code, and this section should call that code
<%def name="get_history( id )">
<%
    return trans.webapp.api_controllers[ 'histories' ].show( trans, trans.security.encode_id( id ) )
%>
</%def>

<%def name="get_current_user()">
<%
    return trans.webapp.api_controllers[ 'users' ].show( trans, 'current' )
%>
</%def>

<%def name="get_hdas( history_id, hdas )">
<%
    #BUG: one inaccessible dataset will error entire list

    if not hdas:
        return '[]'
    # rather just use the history.id (wo the datasets), but...
    return trans.webapp.api_controllers[ 'history_contents' ].index(
        #trans, trans.security.encode_id( history_id ),
        trans, trans.security.encode_id( history_id ),
        ids=( ','.join([ trans.security.encode_id( hda.id ) for hda in hdas ]) ) )
%>
</%def>


## -----------------------------------------------------------------------------
<%def name="javascripts()">
${parent.javascripts()}

${h.js(
    "libs/jquery/jstorage",
    "libs/jquery/jquery.autocomplete", "galaxy.autocom_tagging",
    ##"libs/json2",
    ##"libs/bootstrap",
    ## I think we can remove some of these
    ##"libs/backbone/backbone-relational",
    "mvc/base-mvc",
    ##"mvc/ui"
)}

${h.templates(
    "helpers-common-templates",
    "template-warningmessagesmall",
    
    "template-history-historyPanel",

    "template-hda-warning-messages",
    "template-hda-titleLink",
    "template-hda-failedMetadata",
    "template-hda-hdaSummary",
    "template-hda-downloadLinks",
    "template-hda-tagArea",
    "template-hda-annotationArea",
    "template-hda-displayApps",
    
    "template-user-quotaMeter-quota",
    "template-user-quotaMeter-usage"
)}

##TODO: fix: curr hasta be _after_ h.templates bc these use those templates - move somehow
${h.js(
    "mvc/user/user-model", "mvc/user/user-quotameter",

    "mvc/dataset/hda-model",
    "mvc/dataset/hda-base",
    "mvc/dataset/hda-edit",
    ##"mvc/dataset/hda-readonly",

    ##"mvc/tags", "mvc/annotations"

    "mvc/history/history-model", "mvc/history/history-panel"
)}
    
<script type="text/javascript">
function galaxyPageSetUp(){
    // moving global functions, objects into Galaxy namespace
    top.Galaxy                  = top.Galaxy || {};
    
    // bad idea from memleak standpoint?
    top.Galaxy.mainWindow       = top.Galaxy.mainWindow     || top.frames.galaxy_main;
    top.Galaxy.toolWindow       = top.Galaxy.toolWindow     || top.frames.galaxy_tools;
    top.Galaxy.historyWindow    = top.Galaxy.historyWindow  || top.frames.galaxy_history;
    
    top.Galaxy.$masthead        = top.Galaxy.$masthead      || $( top.document ).find( 'div#masthead' );
    top.Galaxy.$messagebox      = top.Galaxy.$messagebox    || $( top.document ).find( 'div#messagebox' );
    top.Galaxy.$leftPanel       = top.Galaxy.$leftPanel     || $( top.document ).find( 'div#left' );
    top.Galaxy.$centerPanel     = top.Galaxy.$centerPanel   || $( top.document ).find( 'div#center' );
    top.Galaxy.$rightPanel      = top.Galaxy.$rightPanel    || $( top.document ).find( 'div#right' );

    //modals
    // other base functions

    // global backbone models
    top.Galaxy.currUser         = top.Galaxy.currUser;
    top.Galaxy.currHistoryPanel = top.Galaxy.currHistoryPanel;

    //top.Galaxy.paths            = galaxy_paths;

    top.Galaxy.localization     = GalaxyLocalization;
    window.Galaxy = top.Galaxy;
}

// set js localizable strings
GalaxyLocalization.setLocalizedString( ${ create_localization_json( get_page_localized_strings() ) } );

// add needed controller urls to GalaxyPaths
if( !galaxy_paths ){ galaxy_paths = top.galaxy_paths || new GalaxyPaths(); }
galaxy_paths.set( 'hda', ${get_hda_url_templates()} );
galaxy_paths.set( 'history', ${get_history_url_templates()} );

$(function(){
    galaxyPageSetUp();
    //Galaxy.historyFrame = window;

    var debugging = ( new PersistantStorage( '__history_panel' ).get( 'debugging' ) || false );

    // ostensibly, this is the App
    // LOAD INITIAL DATA IN THIS PAGE - since we're already sending it...
    //  ...use mako to 'bootstrap' the models
    var page_show_deleted = ${ 'true' if show_deleted == True else ( 'null' if show_deleted == None else 'false' ) },
        page_show_hidden  = ${ 'true' if show_hidden  == True else ( 'null' if show_hidden  == None else 'false' ) },

        user    = ${ get_current_user() },
        history = ${ get_history( history.id ) },
        hdas    = ${ get_hdas( history.id, datasets ) };

    // add user data to history
    // i don't like this history+user relationship, but user authentication changes views/behaviour
    history.user = user;

    // create the history panel
    var historyPanel = new HistoryPanel({
        model           : new History( history, hdas ),
        urlTemplates    : galaxy_paths.attributes,
        logger          : ( debugging )?( console ):( null ),
        // is page sending in show settings? if so override history's
        show_deleted    : page_show_deleted,
        show_hidden     : page_show_hidden
    });
    historyPanel.render();

    // ...or LOAD FROM THE API
    //historyPanel = new HistoryPanel({
    //    model: new History(),
    //    urlTemplates    : galaxy_paths.attributes,
    //    logger          : ( debugging )?( console ):( null ),
    //    // is page sending in show settings? if so override history's
    //    show_deleted    : page_show_deleted,
    //    show_hidden     : page_show_hidden
    //});
    //historyPanel.model.loadFromApi( history.id );

    // set it up to be accessible across iframes
    //TODO:?? mem leak
    top.Galaxy.currHistoryPanel = historyPanel;
    var currUser = new User( user );
    if( !Galaxy.currUser ){ Galaxy.currUser = currUser; }

    // QUOTA METER is a cross-frame ui element (meter in masthead, over quota message in history)
    //  create it and join them here for now (via events)
    //TODO: this really belongs in the masthead
    //TODO: and the quota message (curr. in the history panel) belongs somewhere else

    //window.currUser.logger = console;
    var quotaMeter = new UserQuotaMeter({
        model   : currUser,
        //logger  : ( debugging )?( console ):( null ),
        el      : $( top.document ).find( '.quota-meter-container' )
    });
    //quotaMeter.logger = console; window.quotaMeter = quotaMeter
    quotaMeter.render();

    // show/hide the 'over quota message' in the history when the meter tells it to
    quotaMeter.bind( 'quota:over',  historyPanel.showQuotaMessage, historyPanel );
    quotaMeter.bind( 'quota:under', historyPanel.hideQuotaMessage, historyPanel );
    // having to add this to handle re-render of hview while overquota (the above do not fire)
    historyPanel.on( 'rendered rendered:initial', function(){
        if( quotaMeter.isOverQuota() ){
            historyPanel.showQuotaMessage();
        }
    });
    //TODO: this _is_ sent to the page (over_quota)...

    // update the quota meter when current history changes size
    historyPanel.model.bind( 'change:nice_size', function(){
        quotaMeter.update()
    }, quotaMeter );


    //ANOTHER cross-frame element is the history-options-button...
    // in this case, we need to change the popupmenu options listed to include some functions for this history
    // these include: current (1 & 2) 'show/hide' delete and hidden functions, and (3) the collapse all option
    (function(){
        // don't try this if the history panel is in it's own window
        if( top.document === window.document ){
            return;
        }

        // lots of wtf here...due to infernalframes
        //TODO: this is way tooo acrobatic
        var $historyButtonWindow = $( top.document ),
            HISTORY_MENU_BUTTON_ID = 'history-options-button',
            $historyMenuButton = $historyButtonWindow.find( '#' + HISTORY_MENU_BUTTON_ID ),
            // jq data in another frame can only be accessed by the jQuery in that frame,
            //  get the jQuery from the top frame (that contains the history-options-button)
            START_INSERTING_AT_INDEX = 11,
            COLLAPSE_OPTION_TEXT = _l("Collapse Expanded Datasets"),
            DELETED_OPTION_TEXT  = _l("Include Deleted Datasets"),
            HIDDEN_OPTION_TEXT   = _l("Include Hidden Datasets");
            windowJQ = $( top )[0].jQuery,
            popupMenu = ( windowJQ && $historyMenuButton[0] )?( windowJQ.data( $historyMenuButton[0], 'PopupMenu' ) )
                                                             :( null );

        //console.debug(
        //    '$historyButtonWindow:', $historyButtonWindow,
        //    '$historyMenuButton:', $historyMenuButton,
        //    'windowJQ:', windowJQ,
        //    'popupmenu:', popupMenu
        //);
        if( !popupMenu ){ return; }

        // since the history frame reloads so often (compared to the main window),
        //  we need to check whether these options are there already before we add them again
        // In IE, however, NOT re-adding them creates a 'cant execute from freed script' error:
        //  so...we need to re-add the function in either case (just not the option itself)
        //NOTE: we use the global Galaxy.currHistoryPanel here
        //  because these remain bound in the main window even if panel refreshes
        //TODO: too much boilerplate
        //TODO: ugh...(in general)
        var collapseOption = popupMenu.findItemByHtml( COLLAPSE_OPTION_TEXT );
        if( !collapseOption ){
            collapseOption = {
                html    : COLLAPSE_OPTION_TEXT
            };
            popupMenu.addItem( collapseOption, START_INSERTING_AT_INDEX )
        }
        collapseOption.func = function() {
            Galaxy.currHistoryPanel.collapseAllHdaBodies();
        };

        var deletedOption = popupMenu.findItemByHtml( DELETED_OPTION_TEXT );
        if( !deletedOption ){
            deletedOption = {
                html    : DELETED_OPTION_TEXT
            };
            popupMenu.addItem( deletedOption, START_INSERTING_AT_INDEX + 1 )
        }
        deletedOption.func = function( clickEvent, thisMenuOption ){
            var show_deleted = Galaxy.currHistoryPanel.toggleShowDeleted();
            thisMenuOption.checked = show_deleted;
        };
        // whether was there or added, update the checked option to reflect the panel's settings on the panel render
        deletedOption.checked = Galaxy.currHistoryPanel.storage.get( 'show_deleted' );

        var hiddenOption = popupMenu.findItemByHtml( HIDDEN_OPTION_TEXT );
        if( !hiddenOption ){
            hiddenOption = {
                html    : HIDDEN_OPTION_TEXT
            };
            popupMenu.addItem( hiddenOption, START_INSERTING_AT_INDEX + 2 )
        }
        hiddenOption.func = function( clickEvent, thisMenuOption ){
            var show_hidden = Galaxy.currHistoryPanel.toggleShowHidden();
            thisMenuOption.checked = show_hidden;
        };
        // whether was there or added, update the checked option to reflect the panel's settings on the panel render
        hiddenOption.checked = Galaxy.currHistoryPanel.storage.get( 'show_hidden' );
    })();

    //TODO: both the quota meter and the options-menu stuff need to be moved out when iframes are removed

    return;
});
</script>
    
</%def>

<%def name="stylesheets()">
    ${parent.stylesheets()}
    ${h.css(
        "base",
        "history",
        "autocomplete_tagging"
    )}
    <style>
        ## TODO: move to base.less
        .historyItemBody {
            display: none;
        }

        #history-controls {
            /*border: 1px solid white;*/
            margin-bottom: 5px;
            padding: 5px;
        }

        #history-title-area {
            margin: 0px 0px 5px 0px;
            /*border: 1px solid red;*/
        }
        #history-name {
            word-wrap: break-word;
            font-weight: bold;
            /*color: gray;*/
        }
        .editable-text {
            border: solid transparent 1px;
        }
        #history-name-container input {
            width: 90%;
            margin: -2px 0px -3px -4px;
            font-weight: bold;
            /*color: gray;*/
        }

        #quota-message-container {
            margin: 8px 0px 5px 0px;
        }
        #quota-message {
            margin: 0px;
        }

        #history-subtitle-area {
            /*border: 1px solid green;*/
        }
        #history-size {
        }
        #history-secondary-links {
        }

        /*why this is getting underlined is beyond me*/
        #history-secondary-links #history-refresh {
            text-decoration: none;
        }
        /*too tweaky*/
        #history-annotate {
            margin-right: 3px;
        }

        #history-tag-area, #history-annotation-area {
            margin: 10px 0px 10px 0px;
        }

        .historyItemTitle {
            text-decoration: underline;
            cursor: pointer;
        }
        .historyItemTitle:hover {
            text-decoration: underline;
        }

    </style>
    
    <noscript>
        ## js disabled: degrade gracefully
        <style>
        .historyItemBody {
            display: block;
        }
        </style>
    </noscript>
</%def>

<body class="historyPage"></body>