datalet-selection-controllet.html 11.1 KB
<link rel="import" href="../../bower_components/polymer/polymer.html" />

<link rel="import" href="../../bower_components/paper-material/paper-material.html" />

<link rel="import" href="../../bower_components/paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="../../bower_components/paper-menu/paper-menu.html">
<link rel="import" href="../../bower_components/paper-item/paper-item.html">

<link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../../bower_components/iron-icon/iron-icon.html">

<link rel="import" href="../../bower_components/paper-input/paper-textarea.html">

<link rel="import" href="../../bower_components/paper-button/paper-button.html">

<link rel="import" href="../items-vslider-controllet/items-vslider-controllet.html" />

<link rel="import" href="../../datalets/datatable-datalet/datatable-datalet.html" />

<dom-module id="datalet-selection-controllet">

    <template>

        <style is="custom-style">

            #datalet_selection_container {
                display: flex;
                font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
                font-size: 16px;
            }

            #datalet_selection_inputs {
                position: relative;
                height: 100vh;
                margin-left: 32px;
                width: 344px;
            }

            #datalet_selection_labels {
                position: relative;
                height: 100vh;
                margin-left: 32px;
                width: 344px;
            }

            #datalet_selection_column {
                position: relative;
                width: 100%;
                margin-left: 32px;
            }

            #datalet_selection_datalet {
                position: relative;
                height: 100vh;
                width: 100%;
                /*margin-left: 32px;*/
                /*margin-top: 32px;*/
                /*margin-bottom: 32px;*/
            }

            #datalet_selection_comment{
                width: 100%;
                margin-bottom: 32px;
            }

            #datalet_selection_datalet_placeholder {
                padding: 16px;
            }

            .inputs{
                position: relative;
                /*margin-left: 16px;*/
                /*margin-right: 16px;*/
            }

            .input_name{
                height: 16px;
                padding: 16px;
                /*background-color: #B6B6B6;*/

                background-color: #2196F3;
                color: #FFFFFF;
                font-weight: 700;
            }

            .input_header{
                /*height: 16px;*/
                padding: 16px;
                background-color: #B6B6B6;
                text-align: center;
                font-weight: 700;
            }

            .info_button {
                position: absolute;
                top: 4px;
                right: 0px;
            }

            paper-textarea {
                height: 48px;
                padding: 0px 8px;
                --paper-input-container-focus-color: #2196F3;
            }

            paper-dropdown-menu {
                height: 48px;
                padding: 0px 8px;
                --paper-input-container-focus-color: #2196F3;
            }

            paper-item.iron-selected {
                background-color: #2196F3;
                color: #FFFFFF;
            }

            paper-icon-button {
                /*color: #2196F3;*/
                color: #FFFFFF;
                --paper-icon-button-ink-color: #2196F3;
                /*padding: 0px;*/
            }

            paper-button {
                /*display: block;*/
                position: absolute;
                bottom: 16px;
                right: 11px;

                /*float: right;*/
                /*margin-right: 11px;*/




                height: 48px;
                width: 172px;
                background-color: #00BCD4;
                color: white;
                font-weight: 700;
                padding: 16px;
            }

            paper-button:hover {
                background-color: #00AABF;
            }
        </style>

        <iron-ajax id="selectedDatalet_request" on-response="handleSelectedDatalet"></iron-ajax>

        <div id="datalet_selection_container">
            <items-vslider-controllet datalets-list-url={{dataletsListUrl}}></items-vslider-controllet>


            <paper-material id="datalet_selection_inputs" elevation="5">
                <div class="input_header">INPUTS</div>
                <template is="dom-repeat" items="{{inputs}}" index-as="index">
                    <div class="inputs">
                        <div class="input_name">
                            {{item.name}}
                            <div class="info_button">
                                <paper-icon-button id="info_button" on-click="_showInfo" icon="info-outline" title="{{item.name}} info"></paper-icon-button>
                            </div>
                        </div>
                        <paper-dropdown-menu no-label-float label={{item.name}}>
                            <paper-menu class="dropdown-content">
                                <template is="dom-repeat" items={{fields}}>
                                    <paper-item id={{index}} on-tap="_loadDatalet">{{item}}</paper-item>
                                </template>
                            </paper-menu>
                        </paper-dropdown-menu>
                    </div>
                </template>
            </paper-material>

            <paper-material id="datalet_selection_labels" elevation="5">
                <div class="input_header">LABELS</div>
                <template is="dom-repeat" items="{{labels}}" index-as="index">
                    <div class="inputs">
                        <div class="input_name">
                            {{item.name}}
                            <div class="info_button">
                                <paper-icon-button id="info_button" on-click="_showInfo" icon="info-outline" title="{{item.name}} info"></paper-icon-button>
                            </div>
                        </div>
                        <paper-textarea no-label-float label={{item.name}}></paper-textarea>
                    </div>
                </template>
            </paper-material>


            <div id="datalet_selection_column">
                <paper-material id="datalet_selection_comment" elevation="5">
                    <div class="input_header">COMMENT</div>
                    <paper-textarea no-label-float label="comment (max 100 characters)"></paper-textarea>
                </paper-material>

                <paper-material id="datalet_selection_datalet" elevation="5">
                    <div class="input_header">DATALET PREVIEW</div>
                    <div id="datalet_selection_datalet_placeholder"></div>

                </paper-material>

                <paper-button raised>ADD DATALET</paper-button>

            </div>

        </div>

    </template>

    <script>

        Polymer({

            is : 'datalet-selection-controllet',

            properties : {

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

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

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

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

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

                fields : {
                    type : Array,
                    value : ["result,records,Lat","result,records,Lng"]
                },

                dataUrl : {
                    type  : String,
                    value : " http://ckan.routetopa.eu/api/action/datastore_search?resource_id=73e02092-85a1-434e-85fe-0c9a43aa9a52&amp;limit=10000"
                }

            },

            listeners: {
                'items-vslider-controllet_selected-datalet': '_dataletSelected'
            },

            ready : function() {
                this._resize();
                $(this.$.datalet_selection_inputs).perfectScrollbar();
                $(this.$.datalet_selection_labels).perfectScrollbar();
                $(this.$.datalet_selection_datalet).perfectScrollbar();
            },

            attached : function() {
                this._resize();
                var that = this;
                window.addEventListener("resize", function() { that._resize(); });
            },

            _dataletSelected : function(e){
                this.selectedDatalet = e.detail.datalet;
                if(this.selectedDatalet){
                    this.$.selectedDatalet_request.url = this.deepUrl + e.detail.datalet + "-datalet";
                    this.$.selectedDatalet_request.generateRequest();
                }
                else
                    this.inputs = []
            },

            handleSelectedDatalet : function(e){
//                console.log(e.detail.response.idm.inputs.layouts.input);
                var inputs = e.detail.response.idm.inputs.input;
                var labels = e.detail.response.idm.inputs.layouts.input;

                if(inputs.constructor == Object) {//not Array && inputs.input.selection == "*"
                    var name = inputs.name;
                    inputs = [];
                    for(var i in this.fields)
                        inputs.push({name: name + " " + i});

                }

                this.inputs = inputs;
                this.labels = labels;
            },

            _loadDatalet : function(){
//                this.$.datalet_selection_datalet_placeholder.innerHTML = "<datatable-datalet data-url=\""+this.dataUrl+"\" fields='[\"result,records,Lat\",\"result,records,Lng\"]'></datatable-datalet>";
                this.$.datalet_selection_datalet_placeholder.innerHTML = "<datatable-datalet data-url=\"http://ckan.routetopa.eu/api/action/datastore_search?resource_id=73e02092-85a1-434e-85fe-0c9a43aa9a52&amp;limit=10000\" fields='[\"result,records,Lat\",\"result,records,Lng\"]'>we";

//                $("#base_datalet_container").html("");
                $("#base_datalet_container").css('visibility','hidden');
                $("#base_datalet_container").css('padding','0px');
                $("#base_datalet_container").css('height','0px');
//                console.log($("#base_datalet_container"));

            },

            _resize : function(){
                var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0) - 16;
                h = h - 64 - 8; //height with page scroller

                $("#items_vslider_container").height(h);//vslider controllet

                $("#datalet_selection_inputs").height(h);
                $("#datalet_selection_labels").height(h);
                $("#datalet_selection_datalet").height(h-132);
            }

        });

    </script>

</dom-module>