data-sevc-controllet.html 6.78 KB
<script src="../shared_js/perfect-scrollbar/js/min/perfect-scrollbar.jquery.min.js"></script>
<link rel="stylesheet" href="../shared_js/perfect-scrollbar/css/perfect-scrollbar.min.css">

<script src="../../locales/controllet_ln.js"></script>

<link rel="import" href="../../bower_components/polymer/polymer.html">

<link rel="import" href="../page-slider-controllet/page-slider-controllet.html">
<link rel="import" href="../dataset-selection-controllet/dataset-selection-controllet.html">
<link rel="import" href="../select-data-controllet/select-data-controllet.html" />
<link rel="import" href="../datalet-selection-controllet/datalet-selection-controllet.html">

<dom-module id="data-sevc-controllet">

    <template>

        <page-slider-controllet id="slider">

            <neon-animatable>

                <template is="dom-if" if={{!modify}}>
                    <dataset-selection-controllet id="select_dataset" data={{data}} datasets={{datasets}} suggested-datasets={{suggestedDatasets}}></dataset-selection-controllet>
                </template>

            </neon-animatable>

            <neon-animatable>

                <select-data-controllet id="select_data" data-url={{dataUrl}} preselected-fields={{selectedFields}} datalet-preset="{{dataletPreset}}"></select-data-controllet>

            </neon-animatable>

            <neon-animatable>

                <datalet-selection-controllet id="select_visualization" deep-url={{deepUrl}} datalets-list-url={{dataletsListUrl}} data-url={{dataUrl}} preselected-datalet={{selectedDatalet}} datalet-preset={{dataletPreset}}></datalet-selection-controllet>

            </neon-animatable>

        </page-slider-controllet>

    </template>

    <script>

        Polymer({

            is : 'data-sevc-controllet',

            listeners : {
                'page-slider-controllet_selected' : '_updateSlider',
                'dataset-selection-controllet_data-url' : '_allowSecondStep',
                'tree-view-controllet_selected-fields' : '_allowThirdStep'
            },

            properties : {

                deepUrl : {
                    type : String,
                    value : undefined
                },

                dataletsListUrl : {
                    type : String ,
                    value : undefined
                },

                datasets : {
                    type : Array,
                    value : undefined
                },

                suggestedDatasets : {
                    type : Array,
                    value : undefined
                },

                dataUrl : {
                    type  : String,
                    value : undefined
                },

                jsonData : {
                    type  : Object,
                    value : undefined
                },

                modify : {
                    type  : Boolean,
                    value : false
                },

                selectedDatalet : {
                    type  : String,
                    value : undefined
                },

                selectedFields : {
                    type  : Array,
                    value : []
                },

                dataletPreset : {
                    type  : Object,
                    value : []
                },

                localization : {
                    type : String,
                    value : "en"
                }

            },

            ready : function(){
                if(this.selectedDatalet){
                    this.modify = true;
                    this.$.slider.selected = 1;
                    this.dataUrl = this.dataletPreset["data-url"];
                }
                ln["localization"] = this.localization;
            },

            _updateSlider : function(e){
                switch (e.detail.selected) {
                    case 0:
                        slider.setTitle(ln["slide1Title_" + this.localization], ln["slide1Subtitle_" + this.localization]);
                        slider.chevronLeft("invisible");
                        slider.chevronRight(false);
                        if(slider.getPrevSelected() == 1)
                            slider.chevronRight(true);
                        break;
                    case 1:
                        slider.setTitle(ln["slide2Title_" + this.localization], ln["slide2Subtitle_" + this.localization]);
                        if(this.modify){
                            slider.chevronLeft("invisible");
                        }
                        else{
                            slider.chevronLeft(true);
                        }
                        slider.chevronRight(false);
                        this.$.select_data.ready();
//                        this.async(function () {this.dataletPreset["filters"] = undefined;}, 1000);
                        this._allowThirdStep({detail: {fields: select_data.getFlatFields()}});
                        this._allowThirdStep({detail: {fields: select_data.getFlatFields()}});
                        break;
                    case 2:
                        slider.setTitle(ln["slide3Title_" + this.localization], ln["slide3Subtitle_" + this.localization]);
                        slider.chevronLeft(true);
                        slider.chevronRight("invisible");
                        this.$.select_visualization.setFields(select_data.getFlatFields());
                        this.$.select_visualization.setFilters(select_data.getFilters());
                        this.$.select_visualization.ready();
                }
            },

            _allowSecondStep : function(e){
                this.dataUrl = e.detail.url;

                $.ajax({
                    url: e.detail.url,
                    dataType: "json",
                    success: function(data){
//                        this.dataUrl = e.detail.url
//                        this.jsonData = JSON.stringify(data);
                        slider.chevronRight(true);
                        select_dataset.$.selected_url.invalid = false;
                    },
                    error: function(){
//                        this.jsonData = undefined;
                        slider.chevronRight(false);
                        select_dataset.$.selected_url.invalid = true;
                    }
                });

                this.$.select_visualization.reset();
            },

            _allowThirdStep : function(e){
                if(e.detail.fields.length > 0)
                    slider.chevronRight(true);
                else
                    slider.chevronRight(false);

                //this.$.select_visualization.reset();
            }

        });

    </script>

</dom-module>