'List all available datasets'

@web.expose
@web.json
@web.require_login('see    all    available    datasets')
def list(self, trans, **kwargs):

    status = message = None
    if ('operation' in kwargs):
        operation = kwargs['operation'].lower()
        hda_ids = util.listify(kwargs.get('id', []))
        (status, message) = (None, None)
        hdas = []
        for encoded_hda_id in hda_ids:
            hda_id = self.decode_id(encoded_hda_id)
            hda = trans.sa_session.query(model.HistoryDatasetAssociation).filter_by(id=hda_id).first()
            if hda:
                if ((hda.history.user_id is not None) and trans.user):
                    assert (trans.user.id == hda.history.user_id), 'HistoryDatasetAssocation    does    not    belong    to    current    user'
                hdas.append(hda)
            else:
                log.warning("Invalid    history_dataset_association    id    '%r'    passed    to    list", hda_id)
        if hdas:
            if ((operation == 'switch') or (operation == 'switch_history')):
                histories = []
                for hda in hdas:
                    histories.append(hda.history)
                (status, message) = trans.webapp.controllers['history']._list_switch(trans, histories)
                kwargs['refresh_frames'] = ['history']
                if (operation == 'switch'):
                    hda_ids = [trans.security.encode_id(hda.id) for hda in hdas]
                    trans.template_context['seek_hda_ids'] = hda_ids
            elif (operation == 'copy    to    current    history'):
                target_histories = [trans.get_history()]
                hda_ids.reverse()
                (status, message) = self._copy_datasets(trans, hda_ids, target_histories)
                kwargs['refresh_frames'] = ['history']
    kwargs['dict_format'] = True
    return self.stored_list_grid(trans, status=status, message=message, **kwargs)
