<!--
* 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.
-->

<!-- Measures Summary -->
<div ng-controller="ModelMeasuresCtrl">
  <ng-form name="forms.model_measure_form" novalidate>
    <div class="dataTables_wrapper form-inline no-footer">
      <b class="col-xs-6" ng-if="state.mode=='view'&&modelsManager.selectedModel.metrics.length==0">No Measures</b>
      <table ng-if="state.mode=='view'&&modelsManager.selectedModel.metrics.length > 0" class="table table-striped table-hover">
        <thead>
            <tr>
                <th>ID</th>
                <th>Column</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="measure in modelsManager.selectedModel.metrics track by $index">
                <td>
                    <!--ID -->
                    <b>{{$index + 1}}</b>
                </td>
                <td>
                    <!--Name -->
                    <span tooltip="measure name..">{{measure}}</span>
                </td>
            </tr>
        </tbody>
      </table>
      <div  ng-if="state.mode=='edit'" class="form-group" style="width: 100%">
        <h4 style="margin-left:42px">Select measure columns</h4>
        <table style="margin-left:42px; width:92%"
               class="table table-hover list">
          <tr class="row">
            <th class="col-xs-1">ID</th>
            <th class="col-xs-2">Table Alias</th>
            <th class="col-xs-9">Columns</th>
          </tr>

          <tr  class="row" ng-repeat="table in availableFactTables ">
            <td class="col-xs-1">
              <!-- ID -->
              <b>{{($index + 1)}}</b>
            </td>
            <td class="col-xs-2">
              {{table}}
            </td>
            <td class="col-xs-9">
              <ui-select
                close-on-select="false"
                ng-if="state.mode=='edit'"
                style="width: 100%" ng-change="changeColumns(table)"
                autofocus="true"
                ng-model="selectedFactTables[table]" multiple>
                <ui-select-match placeholder="Select Column...">{{$item.name}}</ui-select-match>
                <ui-select-choices
                  repeat="table+'.'+measure.name as measure in getColumnsByAlias(table) | filter:$select.search|inDimNotInMea:table:modelsManager.selectedModel.dimensions|notInJoin:table:modelsManager.selectedModel.lookups">
                  {{measure.name}}
                </ui-select-choices>
              </ui-select>
            </td>
          </tr>
        </table>
      </div>
    </div>
  </ng-form>
</div>
