<form id="releaseModal" class="modal fade form-horizontal" name="releaseForm" valdr-type="Release"
      ng-submit="release()">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header panel-primary">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" ng-show="!toReleaseNamespace.isBranch">发布
                    <small>(只有发布过的配置才会被客户端获取到，此次发布只会作用于当前环境:{{env}})</small>
                </h4>
                <h4 class="modal-title" ng-show="toReleaseNamespace.isBranch && !toReleaseNamespace.mergeAndPublish">
                    灰度发布
                    <small>(灰度发布的配置只会作用于在灰度规则中配置的实例)</small>
                </h4>
                <h4 class="modal-title" ng-show="toReleaseNamespace.isBranch && toReleaseNamespace.mergeAndPublish">
                    全量发布
                    <small>(全量发布的配置会作用于全部的实例)</small>
                </h4>

            </div>

            <div class="release modal-body">

                <div class="form-group">
                    <div class="col-sm-2 control-label" ng-if="!toReleaseNamespace.isPropertiesFormat">
                        <div class="row">
                            <div class="btn-group btn-group-xs" style="padding-right: 10px" role="group">
                                <button type="button" class="btn btn-default"
                                        ng-class="{active:releaseChangeViewType=='change'}"
                                        ng-click="switchReleaseChangeViewType('change')">查看变更
                                </button>
                                <button type="button" class="btn btn-default"
                                        ng-class="{active:releaseChangeViewType=='release'}"
                                        ng-click="switchReleaseChangeViewType('release')">发布的值
                                </button>
                            </div>
                        </div>
                    </div>
                    <label class="col-sm-2 control-label" ng-if="toReleaseNamespace.isPropertiesFormat">Changes</label>

                    <div class="col-sm-10"
                         ng-if="(!toReleaseNamespace.isBranch && toReleaseNamespace.itemModifiedCnt)
                                    || (toReleaseNamespace.isBranch && toReleaseNamespace.itemModifiedCnt)
                                    || (toReleaseNamespace.isBranch && toReleaseNamespace.mergeAndPublish && toReleaseNamespace.branchItems.length)"
                         valdr-form-group>

                        <!--properties format-->
                        <!--normal release-->
                        <table class="table table-bordered table-striped text-center table-hover"
                               ng-if="toReleaseNamespace.isPropertiesFormat && !toReleaseNamespace.isBranch">
                            <thead>
                            <tr>
                                <th>
                                    Key
                                </th>
                                <th>
                                    发布的值
                                </th>
                                <th>
                                    未发布的值
                                </th>
                                <th>
                                    修改人
                                </th>
                                <th>
                                    修改时间
                                </th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr ng-repeat="config in toReleaseNamespace.items"
                                ng-if="config.item.key && config.isModified">
                                <td width="20%" title="{{config.item.key}}">
                                    <span ng-bind="config.item.key"></span>
                                     <span class="label label-success" ng-if="config.isModified && !config.oldValue"
                                           data-tooltip="tooltip" data-placement="bottom" title="新增的配置">新</span>
                                    <span class="label label-info"
                                          ng-if="config.isModified && config.oldValue && !config.isDeleted"
                                          data-tooltip="tooltip" data-placement="bottom" title="修改的配置">改</span>
                                    <span class="label label-danger" ng-if="config.isDeleted"
                                          data-tooltip="tooltip" data-placement="bottom" title="删除的配置">删</span>
                                </td>
                                <td width="25%" title="{{config.oldValue}}">
                                    <span ng-bind="config.oldValue"></span>
                                </td>
                                <td width="25%" title="{{config.newValue}}">
                                    <span ng-bind="config.newValue"></span>
                                </td>
                                <td width="15%" ng-bind="config.item.dataChangeLastModifiedBy">
                                </td>
                                <td width="15%"
                                    ng-bind="config.item.dataChangeLastModifiedTime | date: 'yyyy-MM-dd HH:mm:ss'">
                                </td>
                            </tr>
                            </tbody>
                        </table>

                        <!--branch gray release-->
                        <table class="table table-bordered table-striped text-center table-hover"
                               ng-if="toReleaseNamespace.isPropertiesFormat &&
                               toReleaseNamespace.isBranch && !toReleaseNamespace.mergeAndPublish">
                            <thead>
                            <tr>
                                <th>
                                    Key
                                </th>
                                <th>
                                    主版本值
                                </th>
                                <th>
                                    灰度版本发布的值
                                </th>
                                <th>
                                    灰度版本未发布的值
                                </th>
                                <th>
                                    修改人
                                </th>
                                <th>
                                    修改时间
                                </th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr ng-repeat="config in toReleaseNamespace.branchItems"
                                ng-if="config.isModified || config.isDeleted">
                                <td width="15%" title="{{config.item.key}}">
                                    <span ng-bind="config.item.key"></span>
                                        <span class="label label-danger"
                                              ng-show="config.isDeleted">删</span>
                                </td>
                                <td width="20%" title="{{config.masterReleaseValue}}">
                                    <span ng-bind="config.masterReleaseValue"></span>
                                </td>
                                <td width="20%" title="{{config.oldValue}}">
                                    <span ng-bind="config.oldValue"></span>
                                </td>
                                <td width="20%" title="{{config.newValue}}">
                                    <span ng-bind="config.newValue"></span>
                                </td>
                                <td width="10%" ng-bind="config.item.dataChangeLastModifiedBy">
                                </td>
                                <td width="15%"
                                    ng-bind="config.item.dataChangeLastModifiedTime | date: 'yyyy-MM-dd HH:mm:ss'">
                                </td>
                            </tr>
                            </tbody>
                        </table>

                        <!--branch updateAndPublish and publish-->
                        <table class="table table-bordered table-striped text-center table-hover"
                               ng-if="toReleaseNamespace.isPropertiesFormat &&
                               toReleaseNamespace.isBranch && toReleaseNamespace.mergeAndPublish">
                            <thead>
                            <tr>
                                <th>
                                    Key
                                </th>
                                <th ng-if="toReleaseNamespace.isBranch">
                                    主版本值
                                </th>
                                <th ng-if="toReleaseNamespace.isBranch && toReleaseNamespace.mergeAndPublish">
                                    灰度版本的值
                                </th>
                                <th ng-if="!toReleaseNamespace.isBranch || !toReleaseNamespace.mergeAndPublish">
                                    发布的值
                                </th>
                                <th ng-if="!toReleaseNamespace.isBranch || !toReleaseNamespace.mergeAndPublish">
                                    未发布的值
                                </th>
                                <th>
                                    修改人
                                </th>
                                <th>
                                    修改时间
                                </th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr ng-repeat="config in toReleaseNamespace.branchItems"
                                ng-if="!config.isDeleted">
                                <td width="20%" title="{{config.item.key}}">
                                    <span ng-bind="config.item.key"></span>
                                </td>
                                <td width="25%" title="{{config.masterReleaseValue}}">
                                    <span ng-bind="config.masterReleaseValue"></span>
                                </td>
                                <td width="25%" title="{{config.item.value}}">
                                    <span ng-bind="config.item.value"></span>
                                </td>
                                <td width="15%" ng-bind="config.item.dataChangeLastModifiedBy">
                                </td>
                                <td width="15%"
                                    ng-bind="config.item.dataChangeLastModifiedTime | date: 'yyyy-MM-dd HH:mm:ss'">
                                </td>
                            </tr>
                            </tbody>
                        </table>

                        <!--file format -->
                        <div ng-repeat="item in toReleaseNamespace.items"
                             ng-if="!toReleaseNamespace.isPropertiesFormat"
                             ng-show="releaseChangeViewType=='change'">
                            <apollodiff old-str="item.oldValue" new-str="item.newValue"
                                        apollo-id="'releaseStrDiff'"></apollodiff>
                        </div>
                        <div ng-repeat="item in toReleaseNamespace.items"
                             ng-if="!toReleaseNamespace.isPropertiesFormat"
                             ng-show="releaseChangeViewType=='release'">
                                        <textarea class="form-control no-radius" rows="20"
                                                  ng-disabled="true" ng-show="item.newValue" ng-bind="item.newValue">
                                        </textarea>
                        </div>

                    </div>
                    <div class="col-sm-5"
                         ng-show="(!toReleaseNamespace.isBranch && !toReleaseNamespace.itemModifiedCnt)"
                         valdr-form-group>
                        <label class="form-control-static">
                            配置没有变化
                        </label>
                    </div>
                    <div class="col-sm-5"
                         ng-show="(toReleaseNamespace.isBranch && !toReleaseNamespace.mergeAndPublish && !toReleaseNamespace.itemModifiedCnt)"
                         valdr-form-group>
                        <label class="form-control-static">
                            灰度配置没有变化
                        </label>
                    </div>
                    <div class="col-sm-5"
                         ng-show="(toReleaseNamespace.isBranch && toReleaseNamespace.mergeAndPublish && toReleaseNamespace.branchItems.length == 0)"
                         valdr-form-group>
                        <label class="form-control-static">
                            没有灰度的配置项
                        </label>
                    </div>

                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        <apollorequiredfield></apollorequiredfield>
                        Release Name</label>
                    <div class="col-sm-5" valdr-form-group>
                        <input type="text" name="releaseName" class="form-control"
                               placeholder="input release name"
                               ng-model="toReleaseNamespace.releaseTitle" ng-required="true">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">Comment</label>
                    <div class="col-sm-10" valdr-form-group>
                                            <textarea rows="4" name="comment" class="form-control"
                                                      style="margin-top: 15px;"
                                                      ng-model="releaseComment"
                                                      placeholder="Add an optional extended description..."></textarea>
                    </div>
                </div>


            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="submit" class="btn btn-primary"
                        ng-disabled="releaseForm.$invalid || releaseBtnDisabled
                        || (toReleaseNamespace.isBranch && toReleaseNamespace.mergeAndPublish && toReleaseNamespace.branchItems.length == 0)">
                    发布
                </button>
            </div>
        </div>
    </div>
</form>



