import View from '../view';
import template from '../../templates/widgets/datasetInfoWidget.pug';
import '../../stylesheets/widgets/datasetInfoWidget.styl';
/**
* This widget is used to diplay minerva metadata for a dataset.
*/
const DatasetInfoWidget = View.extend({
    initialize: function (settings) {
        this.dataset = settings.dataset;
        this.normalizeMetaInfo = this.normalizeMetaInfo.bind(this);
    },

    render: function () {
        var modal = this.$el.html(template(this))
            .girderModal(this);

        modal.trigger($.Event('ready.girder.modal', { relatedTarget: modal }));

        return this;
    },
    normalizeMetaInfo() {
        var meta = this.dataset.get('meta').minerva;
        var name = meta.original_files ? meta.original_files[0].name : meta.geojson_file.name;
        var output = {
            Name: name,
            Source: 'file'
        };
        switch (meta.dataset_type) {
            case 'geojson':
                output.Type = 'GeoJSON';
                if (meta.postgresGeojson) {
                    output.Source = 'PostgreSQL';
                }
                break;
            case 'geotiff':
                output.Type = 'GeoTiff';
                break;
        }
        return output;
    }
});
export default DatasetInfoWidget;

import View from '../view';
import template from '../../templates/widgets/datasetInfoWidget.pug';
import '../../stylesheets/widgets/datasetInfoWidget.styl';
/**
* This widget is used to diplay minerva metadata for a dataset.
*/
const DatasetInfoWidget = View.extend({
    initialize: function (settings) {
        this.dataset = settings.dataset;
        this.normalizeMetaInfo = this.normalizeMetaInfo.bind(this);
    },

    render: function () {
        var modal = this.$el.html(template(this))
            .girderModal(this);

        modal.trigger($.Event('ready.girder.modal', { relatedTarget: modal }));

        return this;
    },
    normalizeMetaInfo() {
        var meta = this.dataset.get('meta').minerva;
        var output = {
            Name: this.dataset.get('name'),
            Source: 'file'
        };
        if (meta.original_files && meta.original_files[0] && meta.original_files[0].name) {
            output['Original name'] = meta.original_files[0].name;
        } else if (meta.geojson_file && meta.geojson_file.name) {
            output['Original name'] = meta.geojson_file.name;
        }
        switch (meta.dataset_type) {
            case 'geojson':
                output.Type = 'GeoJSON';
                if (meta.postgresGeojson) {
                    output.Source = 'PostgreSQL';
                }
                break;
            case 'geotiff':
                output.Type = 'GeoTiff';
                break;
        }
        return output;
    }
});
export default DatasetInfoWidget;

Make the query of dataset name more reliable on different kind datasets
Make the query of dataset name more reliable on different kind datasets

Some datasets are created at runtime, so it could be missing fields
Also prepare for dataset rename feature
