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

<script type="text/ng-template" id="jobMerge.html">
    <div class="modal-header">
        <h4 tooltip="merge">CUBE MERGE CONFIRM</h4>
    </div>
    <div class="modal-body" style="background-color: white">
        <div ng-if="metaModel.model.partition_desc.partition_date_column" class="row">
            <div class="col-md-2"></div>
            <div class="col-md-8">
                <div ng-if="!!!(cube.segments) || cube.segments.length < 2">
                    <span class="text-info">NO SEGMENT TO MERGE.</span>
                </div>
                <div ng-if="cube.segments.length >= 2" class="row">
                    <table class="table table-striped list" >
                        <tbody>
                        <tr>
                            <td>PARTITION DATE COLUMN</td>
                            <td>{{metaModel.model.partition_desc.partition_date_column}}</td>
                        </tr>
                        <tr>
                            <td>MERGE START SEGMENT</td>
                            <td>
                                <select ng-model="mergeStartSeg"
                                        ng-init="mergeStartSeg=cube.segments[0];mergeStartSelected(mergeStartSeg)"
                                        ng-options="segment as segment.name for segment in cube.segments"
                                        ng-change="mergeStartSelected(mergeStartSeg)">
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>MERGE END SEGMENT</td>
                            <td>
                                <select ng-model="mergeEndSeg"
                                        ng-init="mergeEndSeg=cube.segments[cube.segments.length-1];mergeEndSelected(mergeEndSeg)"
                                        ng-options="segment as segment.name for segment in cube.segments"
                                        ng-change="mergeEndSelected(mergeEndSeg)">
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>START SEGMENT DETAIL</td>
                            <td>
                                <table class="table table-condensed">
                                    <tr>
                                        <td>Start Date (Include)</td>
                                        <td>{{mergeStartSeg.date_range_start | reverseToGMT0}}</td>
                                    </tr>
                                    <tr>
                                        <td>End Date (Exclude)</td>
                                        <td>{{mergeStartSeg.date_range_end | reverseToGMT0}}</td>
                                    </tr>
                                    <tr>
                                        <td>Last build Time</td>
                                        <td>{{mergeStartSeg.last_build_time | utcToConfigTimeZone}}</td>
                                    </tr>
                                    <tr>
                                        <td>Last build ID</td>
                                        <td>{{mergeStartSeg.last_build_job_id}}</td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>END SEGMENT DETAIL</td>
                            <td>
                                <table class="table table-condensed">
                                    <tr>
                                        <td>Start Date (Include)</td>
                                        <td>{{mergeEndSeg.date_range_start |  reverseToGMT0}}</td>
                                    </tr>
                                    <tr>
                                        <td>End Date (Exclude)</td>
                                        <td>{{mergeEndSeg.date_range_end |  reverseToGMT0}}</td>
                                    </tr>
                                    <tr>
                                        <td>Last build Time</td>
                                        <td>{{mergeEndSeg.last_build_time | utcToConfigTimeZone}}</td>
                                    </tr>
                                    <tr>
                                        <td>Last build ID</td>
                                        <td>{{mergeEndSeg.last_build_job_id}}</td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div ng-if="message">
                    <span class="text-warning">{{message}}</span>
                </div>
            </div>
            <div class="col-md-2"></div>
        </div>

        <div ng-if="!metaModel.model.partition_desc.partition_date_column" class="row">
            <div class="col-md-2"></div>
            <div class="col-md-8">
                <span>No partition date column defined.</span>
            </div>
            <div class="col-md-2"></div>
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" ng-click="cancel()">Close</button>
        <button class="btn btn-success" ng-click="rebuild()"
                ng-disabled="!(jobBuildRequest.startTime >= 0 && jobBuildRequest.endTime > 0)">
            Submit
        </button>
    </div>
</script>
