<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="base/resource"/>
    <title>集群管理 - Big Whale</title>
    <link href="../../css/common.css" rel="stylesheet"/>
</head>
<body ng-app="content-app" ng-controller="content-controller">
<div class="modal fade" id="editDlg" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">{{editItem.id ? "编辑" : "新增"}}</h4>
            </div>
            <form class="form-horizontal" ng-submit="onSaveItem()">
                <div class="modal-body">
                    <div class="form-group">
                        <label for="modal_input_name" class="col-sm-4 control-label">
                            名称&nbsp;<B>*</B>
                        </label>
                        <div class="col-sm-5">
                            <input id="modal_input_name" class="form-control" ng-model="editItem.name" required autocomplete="off"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="modal_input_url" class="col-sm-4 control-label">
                            yarn管理地址&nbsp;<B>*</B>
                        </label>
                        <div class="col-sm-5">
                            <input id="modal_input_url" class="form-control" type="url" ng-model="editItem.yarnUrl" placeholder="http://resourcemanager:8088" required />
                        </div>
                        <div class="col-sm-3">
                            <p class="help-block">HA集群只需填写其中一个，会自动负载</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="modal_input_defaultFs" class="col-sm-4 control-label">
                            fs.defaultFS&nbsp;<B>*</B>
                        </label>
                        <div class="col-sm-5">
                            <input id="modal_input_defaultFs" class="form-control" ng-model="editItem.fsDefaultFs" placeholder="hdfs://namenode:8020" required />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="modal_input_webhdfs" class="col-sm-4 control-label">
                            fs.webhdfs&nbsp;<B>*</B>
                        </label>
                        <div class="col-sm-5">
                            <input id="modal_input_webhdfs" class="form-control" ng-model="editItem.fsWebhdfs" placeholder="hdfs://namenode:50070" required/>
                        </div>
                        <div class="col-sm-3">
                            <p class="help-block">HA集群用“,”分隔</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="modal_input_user" class="col-sm-4 control-label">
                            操作用户&nbsp;<B>*</B>
                        </label>
                        <div class="col-sm-5">
                            <input id="modal_input_user" class="form-control" ng-model="editItem.fsUser" required />
                        </div>
                        <div class="col-sm-3">
                            <p class="help-block">具有程序包存储目录操作权限的用户</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="modal_input_dir" class="col-sm-4 control-label">
                            程序包存储目录&nbsp;<B>*</B>
                        </label>
                        <div class="col-sm-5">
                            <input id="modal_input_dir" class="form-control" ng-model="editItem.fsDir" required />
                        </div>
                        <div class="col-sm-3">
                            <p class="help-block">绝对路径</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-5 col-md-offset-4">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" ng-model="editItem.defaultFileCluster"> 默认文件存储集群
                                </label>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <p class="help-block">勾选后，所有程序包都将上传至此集群</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-5 col-md-offset-4">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" ng-model="editItem.flinkProxyUserEnabled"> 支持Flink任务代理用户
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="modal_input_streamingBlackNodeList" class="col-sm-4 control-label">
                            流处理任务黑名单
                        </label>
                        <div class="col-sm-5">
                            <input id="modal_input_streamingBlackNodeList" class="form-control" ng-model="editItem.streamingBlackNodeList" autocomplete="off" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="modal_input_batchBlackNodeList" class="col-sm-4 control-label">
                            批处理任务黑名单
                        </label>
                        <div class="col-sm-5">
                            <input id="modal_input_batchBlackNodeList" class="form-control" ng-model="editItem.batchBlackNodeList" autocomplete="off" />
                        </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" id="btn_submit">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="container-fluid animated fadeInDown">
    <div class="bw-nav">
        <div class="row">
            <ol class="breadcrumb">
                <li>集群管理</li>
                <li class="active">集群管理</li>
            </ol>
            <a class="bw-refresh" onclick="location.reload()" title="刷新">
                <i class="fa fa-refresh" style="font-size: 18px"></i>
            </a>
        </div>
    </div>
    <div class="bw-body">
        <div class="row">
            <div class="col-md-12 ">
                <div class="col-md-12 search-form">
                    <form class="form-inline" ng-submit="options.mypage.toFirst()">
                        <div class="form-group">
                            <button type="button" class="btn btn-primary" ng-click="onNewItem()">新增</button>
                        </div>
                    </form>
                </div>
                <div class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>
                                        操作
                                    </th>
                                    <th>
                                        名称
                                    </th>
                                    <th>
                                        yarn管理地址
                                    </th>
                                    <th>
                                        默认文件存储集群
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr ng-repeat="item in options.items">
                                    <td>
                                        <p class="operate">
                                            <span ng-click="onEditItem(item)">
                                                <i class="glyphicon glyphicon-pencil" aria-hidden="true" title="编辑"></i>
                                            </span><br/>
                                            <span class="remove" id="{{item.id}}_removeBtn" ng-click="onRemoveItem(item)">
                                                <i class="glyphicon glyphicon-trash" aria-hidden="true" title="删除"></i>
                                            </span>
                                        </p>
                                    </td>
                                    <td>
                                        {{item.name}}
                                    </td>
                                    <td>
                                        <a href="{{item.yarnUrl}}" target="_blank">YARN</a>
                                    </td>
                                    <td>
                                        <label ng-if="booleanTypeMap[item.defaultFileCluster]" class="label label-{{booleanTypeMap[item.defaultFileCluster].style}}">
                                            {{booleanTypeMap[item.defaultFileCluster].name}}
                                        </label>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <mypage ng-model="options"></mypage>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>
<script src="../../libs/angular-1.3.9/angular.min.js" type="text/javascript"></script>
<script src="../../libs/angular-1.3.9/myangular.js" type="text/javascript"></script>
<script src="../../js/common.js" type="text/javascript"></script>
<script type="text/javascript">
    var app = angular.module('content-app', []);
    registerHttpInterceptor(app);
    registerPage(app);
    app.controller('content-controller', function ($scope, $http) {
        appendBooleanType($scope);

        $scope.onNewItem = function () {
            $scope.editItem = {
                defaultFileCluster: false,
                flinkProxyUserEnabled: false,
                fsUser: 'hdfs',
                fsDir: "/data/big-whale/storage"
            };
            $('#editDlg').modal();
        };

        $scope.onEditItem = function(item) {
            $scope.editItem = angular.copy(item);
            $('#editDlg').modal();
        };

        $scope.onSaveItem = function() {
            $('#btn_submit').attr('disabled', 'true');
            $http.post('./save.api', $scope.editItem)
                .success(function(data) {
                    $('#btn_submit').removeAttr('disabled');
                    $('#editDlg').modal('hide');
                    $scope.reload();
                    swal({
                        title: '保存成功',
                        type: 'success',
                        showConfirmButton: false,
                        timer: 1500
                    });
                })
                .error(function (data) {
                    $('#btn_submit').removeAttr('disabled');
                    $('#editDlg').modal('hide');
                });
        };

        $scope.onRemoveItem = function(item) {
            removeItem('./delete.api', item, $http, $scope.reload);
        };

        // 获取数据列表
        $scope.options = {
            query: {},
            listUrl: './getpage.api'
        };

        // 刷新
        $scope.reload = function () {
            $scope.options.mypage.reload();
        };
    });
</script>
</body>
</html>