<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<div class="modal-body streaming-source" style="height: 360px;">
  <div class="col-xs-5">
    <p class="text-info">
      Need to input streaming source record here, will detect the source schema and create a table schema for
      streaming.
    </p>

    <div style="padding:15px;" class="has-error">
      <small class="help-block" ng-show="streaming.sourceSchema==''&&form.setStreamingSchema.$submitted">Please
        input Streaming source record to generate schema.
      </small>
      <small class="help-block" ng-if="!table.sourceValid&&table.schemaChecked">
        Source json invalid, Please correct your schema and generate again.
      </small>
    </div>
    <div style="margin-bottom: 20px;">
      <span class="label label-info">JSON</span>
    </div>

    <div ng-model="streaming.sourceSchema" ui-ace="{
    useWrapMode : true,
    mode:'json',
    onLoad: streamingOnLoad
  }">
    </div>
  </div>
  <div class="col-xs-1" style="margin-top:300px;text-align:center;">
    <button type="button" class="btn btn-primary" ng-click="streamingOnChange()"><i
      class="fa fa-angle-double-right fa-5" style="font-size:2em;"></i></button>
  </div>
  <div class="col-xs-6" ng-show="table.schemaChecked">
    <ol class="text-info" style="margin-bottom: 30px;">
      <li>Choose 'timestamp' type column for streaming table.</li>
      <li>By default, system will choose 'Default' as database, you can specify database like this 'database.table'</li>
      <li>derived time dimensions are calculated from timestamp field to help analysis against different time granularities.</li>
    </ol>
    <form class="form-horizontal" name="form.setStreamingSchema" novalidate>
      <div class="form-group required">
        <label class="col-xs-4 control-label" style="text-align: left;">Table Name</label>

        <div class="col-xs-8"
             ng-class="{'has-error':form.setStreamingSchema.streamingObject.$invalid && (form.setStreamingSchema.streamingObject.$dirty||form.setStreamingSchema.$submitted)}">
          <input type="text" name="streamingObject" placeholder="database.table" required="" ng-model="table.name" class="form-control"/>
          <small class="help-block"
                 ng-show="form.setStreamingSchema.streamingObject.$error.required&&(form.setStreamingSchema.streamingObject.$dirty||form.setStreamingSchema.$submitted)">
            Table name is required.
          </small>
        </div>
      </div>
    </form>
    <table class="table table-hover table-bordered">
      <tr>
        <th></th>
        <th>Column</th>
        <th>Column Type</th>
        <th>Comment</th>
      </tr>
      <tr ng-repeat="column in columnList">
        <td><label style="width:100%;cursor: pointer;" for="{{column.name}}"><input style="width:1em;height:1em;"
                                                                                    type="checkbox"
                                                                                    id="{{column.name}}"
                                                                                    ng-model="column.checked"
                                                                                    ng-true-value="Y"
                                                                                    ng-false-value="N"/></label>
        </td>
        <td>{{column.name}}</td>
        <td>
          <select chosen ng-model="column.type"
                  ng-options="type as type for type in tableConfig.dataTypes"
                  data-placeholder="select a column type"
                  style="width: 120px !important;"
                  class="chosen-select">
          </select>
        </td>
        <td>
          <label ng-if="column.type=='timestamp'&&column.fromSource=='Y'" class="badge badge-info">timestamp</label>
          <label ng-if="column.fromSource=='N'" class="badge badge-info">derived time dimension</label>
        </td>
      </tr>
    </table>

    <div class="has-error" ng-if="!rule.timestampColumnExist&&form.setStreamingSchema.$submitted">
      <small class="help-block">
        You should choose at least one 'timestamp' type column generated from source schema.
      </small>
    </div>
  </div>
</div>
