Commit cadbea27296a35bbc862eb41174e3e3edc59e6c9
1 parent
a8a12768
Exists in
master
and in
111 other branches
Improve granuleGrid rendering
Showing
2 changed files
with
95 additions
and
89 deletions
Show diff stats
js/app/views/EpnTapUI.js
... | ... | @@ -503,101 +503,96 @@ Ext.define('amdaUI.EpnTapUI', { |
503 | 503 | TODO: infinite scroll! http://docs.sencha.com/extjs/4.2.3/extjs-build/examples/grid/infinite-scroll-with-filter.html |
504 | 504 | */ |
505 | 505 | createGranulesGrid: function() { |
506 | - var txtRender = function(val) { | |
507 | - return '<p style="white-space: normal;">' + val + '</p>'; | |
508 | - }; | |
509 | - var linkRender = function(val) { | |
510 | - return '<a href="' + val + '">data</a>'; | |
511 | - }; | |
512 | - var imgRender = function(val) { | |
513 | - return '<img width="40px height="40px" src="' + val + '">'; | |
514 | - }; | |
515 | - var dptRender = function(val) { | |
516 | - var productTypeDict = Ext.data.StoreManager.lookup('productTypesStore').data.map; | |
517 | - return productTypeDict[val].data.name; | |
518 | - }; | |
519 | - var formatRender = function(val) { | |
520 | - // A dictionnary used to associate the mimetype (i.e "application/fits") to a pretty printed word (i.e "fits"). | |
521 | - mimetypeDict = { | |
522 | - 'application/fits': 'fits', | |
523 | - 'application/x-pds': 'pds', | |
524 | - 'image/x-pds': 'pds', | |
525 | - 'application/gml+xml': 'gml', | |
526 | - 'application/json': 'json', | |
527 | - 'application/octet-stream': 'bin, idl, envi or matlab', | |
528 | - 'application/pdf': 'pdf', | |
529 | - 'application/postscript': 'ps', | |
530 | - 'application/vnd.geo+json': 'geojson', | |
531 | - 'application/vnd.google-earth.kml+xml': 'kml', | |
532 | - 'application/vnd.google-earth.kmz': 'kmz', | |
533 | - 'application/vnd.ms-excel': 'xls', | |
534 | - 'application/x-asdm': 'asdm', | |
535 | - 'application/x-cdf': 'cdf', | |
536 | - 'application/x-cdf-istp': 'cdf', | |
537 | - 'application/x-cdf-pds4': 'cdf', | |
538 | - 'application/x-cef1': 'cef1', | |
539 | - 'application/x-cef2': 'cef2', | |
540 | - 'application/x-directory': 'dir', | |
541 | - 'application/x-fits-bintable': 'bintable', | |
542 | - 'application/x-fits-euro3d': 'euro3d', | |
543 | - 'application/x-fits-mef': 'mef', | |
544 | - 'application/x-geotiff': 'geotiff', | |
545 | - 'application/x-hdf': 'hdf', | |
546 | - 'application/x-netcdf': 'nc', | |
547 | - 'application/x-netcdf4': 'nc', | |
548 | - 'application/x-tar': 'tar', | |
549 | - 'application/x-tar-gzip': 'gtar', | |
550 | - 'application/x-votable+xml': 'votable', | |
551 | - 'application/x-votable+xml;content=datalink': 'votable', | |
552 | - 'application/zip': 'zip', | |
553 | - 'image/fits': 'fits', | |
554 | - 'image/gif': 'gif', | |
555 | - 'image/jpeg': 'jpeg', | |
556 | - 'image/png': 'png', | |
557 | - 'image/tiff': 'tiff', | |
558 | - 'image/x-fits-gzip': 'fits', | |
559 | - 'image/x-fits-hcompress': 'fits', | |
560 | - 'text/csv': 'csv', | |
561 | - 'text/html': 'html', | |
562 | - 'text/plain': 'txt', | |
563 | - 'text/tab-separated-values': 'tsv', | |
564 | - 'text/xml': 'xml', | |
565 | - 'video/mpeg': 'mpeg', | |
566 | - 'video/quicktime': 'mov', | |
567 | - 'video/x-msvideo': 'avi' | |
568 | - }; | |
569 | - return (val in mimetypeDict) ? mimetypeDict[val] : '<em style="white-space: normal;">' + val + '</em>'; | |
570 | - }; | |
571 | - var sizeRender = function(val) { | |
572 | - var size = parseInt(val); | |
573 | - if (isNaN(size)) { | |
574 | - return ''; | |
575 | - } else if (size >= 1024*1024) { | |
576 | - return (size/(1024*1024)).toPrecision(3) + 'Go'; | |
577 | - } else if (size >= 1024) { | |
578 | - return (size/1024).toPrecision(3) + 'Mo'; | |
579 | - } else { | |
580 | - return size + 'Ko'; | |
506 | + Ext.define('App.util.Format', { | |
507 | + override: 'Ext.util.Format', | |
508 | + 'text': function(data) { | |
509 | + return '<p style="white-space: normal;">' + data + '</p>'; | |
510 | + }, | |
511 | + 'link': function(data) { | |
512 | + return '<a href="' + data + '">data</a>'; | |
513 | + }, | |
514 | + 'img': function(data) { | |
515 | + return '<img width="40px height="40px" src="' + data + '">'; | |
516 | + }, | |
517 | + 'type': function(data) { | |
518 | + var productTypeDict = Ext.data.StoreManager.lookup('productTypesStore').data.map; | |
519 | + return '<p>' + productTypeDict[data].data.name + '</p>'; | |
520 | + }, | |
521 | + 'format': function(data) { | |
522 | + var mimetypeDict = { | |
523 | + 'application/fits': 'fits', | |
524 | + 'application/x-pds': 'pds', | |
525 | + 'image/x-pds': 'pds', | |
526 | + 'application/gml+xml': 'gml', | |
527 | + 'application/json': 'json', | |
528 | + 'application/octet-stream': 'bin, idl, envi or matlab', | |
529 | + 'application/pdf': 'pdf', | |
530 | + 'application/postscript': 'ps', | |
531 | + 'application/vnd.geo+json': 'geojson', | |
532 | + 'application/vnd.google-earth.kml+xml': 'kml', | |
533 | + 'application/vnd.google-earth.kmz': 'kmz', | |
534 | + 'application/vnd.ms-excel': 'xls', | |
535 | + 'application/x-asdm': 'asdm', | |
536 | + 'application/x-cdf': 'cdf', | |
537 | + 'application/x-cdf-istp': 'cdf', | |
538 | + 'application/x-cdf-pds4': 'cdf', | |
539 | + 'application/x-cef1': 'cef1', | |
540 | + 'application/x-cef2': 'cef2', | |
541 | + 'application/x-directory': 'dir', | |
542 | + 'application/x-fits-bintable': 'bintable', | |
543 | + 'application/x-fits-euro3d': 'euro3d', | |
544 | + 'application/x-fits-mef': 'mef', | |
545 | + 'application/x-geotiff': 'geotiff', | |
546 | + 'application/x-hdf': 'hdf', | |
547 | + 'application/x-netcdf': 'nc', | |
548 | + 'application/x-netcdf4': 'nc', | |
549 | + 'application/x-tar': 'tar', | |
550 | + 'application/x-tar-gzip': 'gtar', | |
551 | + 'application/x-votable+xml': 'votable', | |
552 | + 'application/x-votable+xml;content=datalink': 'votable', | |
553 | + 'application/zip': 'zip', | |
554 | + 'image/fits': 'fits', | |
555 | + 'image/gif': 'gif', | |
556 | + 'image/jpeg': 'jpeg', | |
557 | + 'image/png': 'png', | |
558 | + 'image/tiff': 'tiff', | |
559 | + 'image/x-fits-gzip': 'fits', | |
560 | + 'image/x-fits-hcompress': 'fits', | |
561 | + 'text/csv': 'csv', | |
562 | + 'text/html': 'html', | |
563 | + 'text/plain': 'txt', | |
564 | + 'text/tab-separated-values': 'tsv', | |
565 | + 'text/xml': 'xml', | |
566 | + 'video/mpeg': 'mpeg', | |
567 | + 'video/quicktime': 'mov', | |
568 | + 'video/x-msvideo': 'avi' | |
569 | + }; | |
570 | + return (data in mimetypeDict) ? '<p>' + mimetypeDict[data] + '</p>' : '<em>' + data + '</em>'; | |
571 | + }, | |
572 | + 'size': function(data) { | |
573 | + var size = parseInt(data); | |
574 | + var txt = ''; | |
575 | + if (isNaN(size)) { | |
576 | + } else if (size >= 1024*1024) { | |
577 | + txt = (size/(1024*1024)).toPrecision(3) + 'Go'; | |
578 | + } else if (size >= 1024) { | |
579 | + txt = (size/1024).toPrecision(3) + 'Mo'; | |
580 | + } else { | |
581 | + txt = size + 'Ko'; | |
582 | + } | |
583 | + return '<p>' + txt + '</p>' | |
584 | + }, | |
585 | + 'date': function(data) { | |
586 | + | |
581 | 587 | } |
582 | - }; | |
588 | + }); | |
583 | 589 | |
584 | 590 | var epnTapGranulesGrid = new Ext.grid.Panel({ |
585 | 591 | id: 'epnTapGranulesGrid', |
586 | 592 | title: 'Granules', |
587 | 593 | store: Ext.data.StoreManager.lookup('granulesStore'), |
588 | 594 | flex: 4, |
589 | - columns: [ | |
590 | - // { text: 'Num', dataIndex: 'num', flex: 1, renderer: txtRender, hidden: true }, | |
591 | - // { text: 'Type', dataIndex: 'dataproduct_type', flex: 2, renderer: dptRender }, | |
592 | - // { text: 'Target', dataIndex: 'target_name', flex: 2, renderer: txtRender, hidden: true }, | |
593 | - // { text: 'Time min', dataIndex: 'time_min', flex: 2, renderer: txtRender }, | |
594 | - // { text: 'Time max', dataIndex: 'time_max', flex: 2, renderer: txtRender }, | |
595 | - // { text: 'Format', dataIndex: 'access_format', flex: 2, renderer: formatRender }, | |
596 | - // { text: 'uid', dataIndex: 'granule_uid', flex: 2, renderer: txtRender }, | |
597 | - // { text: 'Size', dataIndex: 'access_estsize', flex: 1, renderer: sizeRender }, | |
598 | - // { text: 'URL', dataIndex: 'access_url', flex: 1, renderer: linkRender }, | |
599 | - // { text: 'Thumb.', dataIndex: 'thumbnail_url', flex: 1, renderer: imgRender} | |
600 | - ], | |
595 | + columns: [], | |
601 | 596 | dockedItems: [{ |
602 | 597 | xtype: 'pagingtoolbar', |
603 | 598 | id: 'epnTapPagingTB', | ... | ... |
php/epntap.php
... | ... | @@ -118,11 +118,22 @@ function getGranules() { |
118 | 118 | // error_log('getGranules query: ' . $query); |
119 | 119 | $rows = request($url, $query); |
120 | 120 | |
121 | + $visibleColumns = ['granule_uid', 'dataproduct_type', 'time_min', 'time_max', 'access_estsize', 'thumbnail_url', 'access_url']; | |
122 | + $names = ['dataproduct_type' => 'Type', 'access_estsize' => 'Size']; | |
123 | + $renderers = ['dataproduct_type' => 'type', 'access_estsize' => 'size', 'access_format' => 'format', 'access_url' => 'link', 'thumbnail_url' => 'img']; | |
124 | + $flexs = ['granule_uid' => 2]; | |
125 | + | |
121 | 126 | $fields = array(); |
122 | 127 | $columns = array(); |
123 | 128 | foreach($rows[0] as $key => $value) { |
124 | 129 | $fields[] = ['name' => $key, 'type' => 'string']; |
125 | - $columns[] = ['text' => ucfirst(str_replace('_', ' ', $key)), 'dataIndex' => $key]; | |
130 | + $columns[] = [ | |
131 | + 'dataIndex' => $key, | |
132 | + 'text' => array_key_exists($key, $names) ? $names[$key] : ucfirst(str_replace('_', ' ', $key)), | |
133 | + 'flex' => array_key_exists($key, $flexs) ? $flexs[$key] : 1, | |
134 | + 'hidden' => !in_array($key, $visibleColumns), | |
135 | + 'renderer' => array_key_exists($key, $renderers) ? $renderers[$key] : 'text' | |
136 | + ]; | |
126 | 137 | } |
127 | 138 | |
128 | 139 | $metadata = ['fields' => $fields, 'columns' => $columns, 'root' => 'data']; | ... | ... |