var _excluded = ["pipelineTaskVOs"],
    _excluded2 = ["list"];

var _dec, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _descriptor13, _descriptor14, _descriptor15, _descriptor16, _descriptor17, _descriptor18, _descriptor19, _descriptor20, _descriptor21;

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }

function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and runs after the decorators transform.'); }

/* eslint-disable no-plusplus */
import { observable, action, computed, set, remove } from 'mobx';
import { axios, store, Choerodon } from '@choerodon/boot';
import _ from 'lodash';
import { handlePromptError } from "../../../utils";
import { STAGE_FLOW_AUTO, TASK_SERIAL, TASK_TYPE_MANUAL, TRIGGER_TYPE_AUTO, TRIGGER_TYPE_MANUAL } from "../components/Constants";
var INIT_INDEX = 0;
var PipelineCreateStore = (_dec = store('PipelineCreateStore'), _dec(_class = (_class2 = /*#__PURE__*/function () {
  function PipelineCreateStore() {
    _classCallCheck(this, PipelineCreateStore);

    _initializerDefineProperty(this, "stageList", _descriptor, this);

    _initializerDefineProperty(this, "isDisabled", _descriptor2, this);

    _initializerDefineProperty(this, "canSubmit", _descriptor3, this);

    _initializerDefineProperty(this, "checkCanSubmit", _descriptor4, this);

    _initializerDefineProperty(this, "trigger", _descriptor5, this);

    _initializerDefineProperty(this, "stageIndex", _descriptor6, this);

    _initializerDefineProperty(this, "taskSettings", _descriptor7, this);

    _initializerDefineProperty(this, "taskIndex", _descriptor8, this);

    _initializerDefineProperty(this, "taskList", _descriptor9, this);

    _initializerDefineProperty(this, "envData", _descriptor10, this);

    _initializerDefineProperty(this, "appData", _descriptor11, this);

    _initializerDefineProperty(this, "loading", _descriptor12, this);

    _initializerDefineProperty(this, "instances", _descriptor13, this);

    _initializerDefineProperty(this, "configList", _descriptor14, this);

    _initializerDefineProperty(this, "user", _descriptor15, this);

    _initializerDefineProperty(this, "detailLoading", _descriptor16, this);

    _initializerDefineProperty(this, "pipeline", _descriptor17, this);

    _initializerDefineProperty(this, "pageInfo", _descriptor18, this);

    this.editConfigValue = function (projectId, data) {
      return axios.put("/devops/v1/projects/".concat(projectId, "/deploy_value"), JSON.stringify(data));
    };

    _initializerDefineProperty(this, "createVisible", _descriptor19, this);

    _initializerDefineProperty(this, "editVisible", _descriptor20, this);

    _initializerDefineProperty(this, "editId", _descriptor21, this);
  }

  _createClass(PipelineCreateStore, [{
    key: "setIsDisabled",
    value: function setIsDisabled(data) {
      this.isDisabled = data;
    }
  }, {
    key: "getIsDisabled",
    get: function get() {
      return this.isDisabled;
    } // 自动触发时，第一个阶段为空，禁止提交表单

  }, {
    key: "setCanSubmit",
    value: function setCanSubmit(flag) {
      this.canSubmit = flag;
    }
  }, {
    key: "getCanSubmit",
    get: function get() {
      return this.canSubmit;
    }
    /**
     * 流水线的触发方式
     */

  }, {
    key: "setTrigger",
    value: function setTrigger(type) {
      // 切换触发方式，对第一个阶段的首个任务的类型校验
      if (type === TRIGGER_TYPE_MANUAL) {
        this.setIsDisabled(false);
      } else {
        var headStageId = (_.head(this.stageList) || {}).tempId;

        var headTask = _.find(this.taskList[headStageId], 'isHead');

        this.setIsDisabled(headTask && headTask.type === TASK_TYPE_MANUAL);
      }

      this.trigger = type;
    }
  }, {
    key: "getTrigger",
    get: function get() {
      return this.trigger;
    }
    /** ****************阶段相关设置****************** */

  }, {
    key: "setStageIndex",
    value: function setStageIndex(index) {
      this.stageIndex = index;
    }
  }, {
    key: "getStageIndex",
    get: function get() {
      return this.stageIndex;
    }
    /**
     * 添加阶段
     * @param id 前一个阶段的id
     * @param data
     */

  }, {
    key: "addStage",
    value: function addStage(id, data) {
      var index = _.findIndex(this.stageList, ['tempId', id]);

      if (index === -1) return;
      this.stageList.splice(index + 1, 0, data);
    }
    /**
     * 修改阶段
     * @param id 当前修改阶段的id
     * @param data
     */

  }, {
    key: "editStage",
    value: function editStage(id, data) {
      var stage = _.find(this.stageList, ['tempId', id]);

      set(stage, _objectSpread({}, data));
    }
  }, {
    key: "setStageList",
    value: function setStageList(id, data) {
      var stage = _.find(this.stageList, ['tempId', id]);

      if (!stage) return;
      set(stage, _objectSpread({}, data));
    }
  }, {
    key: "setTaskSettings",
    value:
    /**
     * 设置任务执行模式：并行和串行
     * @param id
     * @param data
     */
    function setTaskSettings(id, data) {
      var stage = _.find(this.stageList, ['tempId', id]);

      set(stage, {
        isParallel: _.toNumber(data)
      });
      set(this.taskSettings, _defineProperty({}, id, data));
    }
  }, {
    key: "removeStage",
    value: function removeStage(id) {
      var index = _.findIndex(this.stageList, ['tempId', id]);

      if (index === -1) return;
      remove(this.stageList, index);
      set(this.taskList, _defineProperty({}, id, null));
      set(this.taskSettings, _defineProperty({}, id, null));
      /**
       * 自动触发的流水线中
       * 删除第一个阶段，需要判断第二个阶段的第一个任务是不是部署类型
       */

      if (index === 0 && this.stageList.length) {
        var headStageId = this.stageList[0].tempId;
        var tasks = this.taskList[headStageId];

        if (tasks && tasks.length) {
          tasks[0].isHead = true;
          this.setIsDisabled(tasks[0].type === TASK_TYPE_MANUAL && this.trigger === TRIGGER_TYPE_AUTO);
        }
      }
    }
  }, {
    key: "clearStageList",
    value: function clearStageList() {
      this.stageList = [{
        tempId: INIT_INDEX,
        stageName: '阶段一',
        triggerType: TRIGGER_TYPE_AUTO,
        pipelineTaskVOs: null,
        stageUserRels: null,
        isParallel: TASK_SERIAL
      }];
    }
  }, {
    key: "clearTaskSettings",
    value: function clearTaskSettings() {
      this.taskSettings = {};
    }
  }, {
    key: "getTaskSettings",
    get: function get() {
      return this.taskSettings;
    }
  }, {
    key: "getStageList",
    get: function get() {
      return this.stageList.slice();
    }
    /** **********task 相关*************** */
    // 缓存不同阶段的task的序号

  }, {
    key: "setTaskIndex",
    value: function setTaskIndex(stageId, index) {
      set(this.taskIndex, _defineProperty({}, stageId, index));
    }
  }, {
    key: "clearTaskIndex",
    value: function clearTaskIndex() {
      this.taskIndex = {
        0: INIT_INDEX
      };
    }
  }, {
    key: "getTaskIndex",
    get: function get() {
      return this.taskIndex;
    }
  }, {
    key: "setTaskList",
    value:
    /**
     * 设置某阶段的任务列表
     * @param stage 阶段标识
     * @param data
     */
    function setTaskList(stage, data) {
      set(this.taskList, _defineProperty({}, stage, [].concat(_toConsumableArray(this.taskList[stage] || []), [data])));
    }
  }, {
    key: "updateTaskList",
    value: function updateTaskList(stage, id, data) {
      var task = this.taskList[stage];

      var current = _.findIndex(task, ['index', id]);

      if (current || current === 0) {
        task[current] = data;
      }

      if (data.isHead && this.trigger === TRIGGER_TYPE_AUTO) {
        // 修改节点为第一个阶段的第一个任务，触发方式为自动触发时
        this.setIsDisabled(data.type === TASK_TYPE_MANUAL);
      }

      set(this.taskList, _defineProperty({}, stage, task));
    }
    /**
     * 移除阶段内的任务
     * @param stage 阶段的 tempId
     * @param id 任务的 index
     * @param isHead 是否是整个流水线的第一个任务
     */

  }, {
    key: "removeTask",
    value: function removeTask(stage, id, isHead) {
      if (!this.taskList[stage]) return;

      var newTaskList = _.filter(this.taskList[stage], function (item) {
        return item.index !== id;
      });

      if (isHead && newTaskList[0]) {
        newTaskList[0].isHead = true; // 类型错误，禁止创建

        this.setIsDisabled(newTaskList[0].type === TASK_TYPE_MANUAL && this.trigger === TRIGGER_TYPE_AUTO);
      }

      set(this.taskList, _defineProperty({}, stage, newTaskList));
    }
  }, {
    key: "clearTaskList",
    value: function clearTaskList() {
      this.taskList = {};
    }
  }, {
    key: "getTaskList",
    get: function get() {
      return this.taskList;
    }
    /** ***********task相关结束************* */

  }, {
    key: "setEnvData",
    value: function setEnvData(data) {
      this.envData = data;
    }
  }, {
    key: "getEnvData",
    get: function get() {
      return this.envData.slice();
    }
  }, {
    key: "setAppDate",
    value: function setAppDate(data) {
      this.appData = data;
    }
  }, {
    key: "getAppData",
    get: function get() {
      return this.appData.slice();
    }
  }, {
    key: "setLoading",
    value: function setLoading(name, flag) {
      set(this.loading, _defineProperty({}, name, flag));
    }
  }, {
    key: "getLoading",
    get: function get() {
      return this.loading;
    }
  }, {
    key: "setInstances",
    value: function setInstances(data) {
      this.instances = data;
    }
  }, {
    key: "getInstance",
    get: function get() {
      return this.instances.slice();
    }
  }, {
    key: "setConfigList",
    value: function setConfigList(data) {
      this.configList = data;
    }
  }, {
    key: "getConfigList",
    get: function get() {
      return this.configList.slice();
    }
  }, {
    key: "setUser",
    value: function setUser(data) {
      this.user = data;
    }
  }, {
    key: "getUser",
    get: function get() {
      return this.user.slice();
    }
  }, {
    key: "setDetailLoading",
    value: function setDetailLoading(data) {
      this.detailLoading = data;
    }
  }, {
    key: "getDetailLoading",
    get: function get() {
      return this.detailLoading;
    }
  }, {
    key: "setPipeline",
    value: function setPipeline(data) {
      this.pipeline = data;
    }
  }, {
    key: "getPipeline",
    get: function get() {
      return this.pipeline;
    }
  }, {
    key: "initPipeline",
    value: function initPipeline(data) {
      var pipelineStageVOs = data.pipelineStageVOs,
          triggerType = data.triggerType;
      var taskList = {};
      var stageIndex = INIT_INDEX;
      var taskIndex = {
        0: INIT_INDEX
      };

      var stageList = _.map(pipelineStageVOs, function (_ref) {
        var pipelineTaskVOs = _ref.pipelineTaskVOs,
            item = _objectWithoutProperties(_ref, _excluded);

        var index = 1;

        var tasks = _.map(pipelineTaskVOs, function (task) {
          return _objectSpread(_objectSpread({}, task), {}, {
            isHead: stageIndex === INIT_INDEX && index === 1,
            index: index++
          });
        });

        var stage = _objectSpread(_objectSpread({}, item), {}, {
          tempId: ++stageIndex,
          pipelineTaskVOs: tasks
        });

        taskList[stageIndex] = tasks;
        taskIndex[stageIndex] = index;
        return stage;
      });

      this.trigger = triggerType;
      this.taskIndex = taskIndex;
      this.stageIndex = stageIndex;
      this.stageList = stageList;
      this.taskList = taskList;
    }
  }, {
    key: "setPageInfo",
    value: function setPageInfo(pageInfo) {
      this.pageInfo = pageInfo;
    }
  }, {
    key: "getPageInfo",
    get: function get() {
      return this.pageInfo;
    }
    /**
     * 检查流水线名称唯一性
     * @param projectId
     * @param name
     * @returns {*}
     */

  }, {
    key: "checkName",
    value: function checkName(projectId, name) {
      return axios.get("/devops/v1/projects/".concat(projectId, "/pipeline/check_name?name=").concat(name));
    }
    /**
     * 校验实例名称
     * 1. 校验本地所有为上传的任务中的实例
     * 2. 校验已创建的实例
     * @param projectId
     * @param name
     * @param envId
     * @returns {*}
     */

  }, {
    key: "checkInstanceName",
    value: function checkInstanceName(projectId, name, envId) {
      // 正在创建的流水线中是否存在同名实例
      var taskList = _.values(this.taskList).slice();

      var hasName = false;

      for (var i = 0, len = taskList.length; i < len; i++) {
        var task = _.find(taskList[i], function (_ref2) {
          var pipelineAppServiceDeployVO = _ref2.pipelineAppServiceDeployVO;
          return pipelineAppServiceDeployVO && pipelineAppServiceDeployVO.instanceName === name;
        });

        if (task) {
          hasName = true;
          break;
        }
      }

      return hasName ? Promise.resolve({
        failed: true
      }) : axios.get("/devops/v1/projects/".concat(projectId, "/app_service_instances/check_name?instance_name=").concat(name, "&env_id=").concat(envId));
    }
  }, {
    key: "loadEnvData",
    value: function () {
      var _loadEnvData = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(projectId) {
        var _this = this;

        var response;
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                this.setLoading('env', true);
                _context.next = 3;
                return axios.get("/devops/v1/projects/".concat(projectId, "/envs/list_by_active?active=", true))["catch"](function (e) {
                  _this.setLoading('env', false);

                  Choerodon.handleResponseError(e);
                });

              case 3:
                response = _context.sent;
                this.setLoading('env', false);

                if (handlePromptError(response)) {
                  // 让连接的环境排在前面
                  this.setEnvData(_.sortBy(response, function (value) {
                    return Number(!value.connect);
                  }));
                }

              case 6:
              case "end":
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      function loadEnvData(_x) {
        return _loadEnvData.apply(this, arguments);
      }

      return loadEnvData;
    }()
  }, {
    key: "loadAppData",
    value: function () {
      var _loadAppData = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(projectId) {
        var _this2 = this;

        var response;
        return regeneratorRuntime.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                this.setLoading('app', true);
                _context2.next = 3;
                return axios.post("/devops/v1/projects/".concat(projectId, "/app_service/page_by_options?active=true&type=normal&doPage=false&has_version=true&app_market=false"), JSON.stringify({
                  searchParam: {},
                  param: ''
                }))["catch"](function (e) {
                  _this2.setLoading('app', false);

                  Choerodon.handleResponseError(e);
                });

              case 3:
                response = _context2.sent;
                this.setLoading('app', false);

                if (handlePromptError(response)) {
                  this.setAppDate(response.list);
                }

              case 6:
              case "end":
                return _context2.stop();
            }
          }
        }, _callee2, this);
      }));

      function loadAppData(_x2) {
        return _loadAppData.apply(this, arguments);
      }

      return loadAppData;
    }()
  }, {
    key: "loadInstances",
    value: function () {
      var _loadInstances = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(projectId, envId, appId) {
        var _this3 = this;

        var response;
        return regeneratorRuntime.wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                this.setLoading('instance', true);
                _context3.next = 3;
                return axios.get("/devops/v1/projects/".concat(projectId, "/app_service_instances/list_running_and_failed?env_id=").concat(envId, "&app_service_id=").concat(appId))["catch"](function (e) {
                  _this3.setLoading('instance', false);

                  Choerodon.handleResponseError(e);
                });

              case 3:
                response = _context3.sent;
                this.setLoading('instance', false);

                if (handlePromptError(response)) {
                  this.setInstances(response);
                }

              case 6:
              case "end":
                return _context3.stop();
            }
          }
        }, _callee3, this);
      }));

      function loadInstances(_x3, _x4, _x5) {
        return _loadInstances.apply(this, arguments);
      }

      return loadInstances;
    }()
    /**
     * 查询部署配置列表
     * @param projectId
     * @param envId
     * @param appId
     * @returns {Promise<void>}
     */

  }, {
    key: "loadConfig",
    value: function () {
      var _loadConfig = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(projectId, envId, appId) {
        var _this4 = this;

        var response;
        return regeneratorRuntime.wrap(function _callee4$(_context4) {
          while (1) {
            switch (_context4.prev = _context4.next) {
              case 0:
                this.setLoading('config', true);
                _context4.next = 3;
                return axios.get("/devops/v1/projects/".concat(projectId, "/deploy_value/list_by_env_and_app?app_service_id=").concat(appId, "&env_id=").concat(envId))["catch"](function (e) {
                  _this4.setLoading('config', false);

                  Choerodon.handleResponseError(e);
                });

              case 3:
                response = _context4.sent;
                this.setLoading('config', false);

                if (handlePromptError(response)) {
                  this.setConfigList(response);
                }

              case 6:
              case "end":
                return _context4.stop();
            }
          }
        }, _callee4, this);
      }));

      function loadConfig(_x6, _x7, _x8) {
        return _loadConfig.apply(this, arguments);
      }

      return loadConfig;
    }()
    /**
     * 查询部署信息
     * @param projectId
     * @param valueId
     * @returns {Promise<void>}
     */

  }, {
    key: "loadValue",
    value: function () {
      var _loadValue = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(projectId, valueId) {
        var _this5 = this;

        var response;
        return regeneratorRuntime.wrap(function _callee5$(_context5) {
          while (1) {
            switch (_context5.prev = _context5.next) {
              case 0:
                this.setLoading('value', true);
                _context5.next = 3;
                return axios.get("/devops/v1/projects/".concat(projectId, "/deploy_value?value_id=").concat(valueId))["catch"](function (e) {
                  _this5.setLoading('value', false);

                  Choerodon.handleResponseError(e);
                });

              case 3:
                response = _context5.sent;
                this.setLoading('value', false);

                if (!handlePromptError(response)) {
                  _context5.next = 7;
                  break;
                }

                return _context5.abrupt("return", response);

              case 7:
              case "end":
                return _context5.stop();
            }
          }
        }, _callee5, this);
      }));

      function loadValue(_x9, _x10) {
        return _loadValue.apply(this, arguments);
      }

      return loadValue;
    }()
    /**
     * 修改部署信息
     * @param projectId
     * @param data
     * @returns {Promise<void>}
     */

  }, {
    key: "loadUser",
    value:
    /**
     * 项目所有者和项目成员
     * @param projectId
     * @returns {Promise<void>}
     */
    function () {
      var _loadUser = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(projectId) {
        var _this6 = this;

        var page,
            searchValue,
            users,
            data,
            response,
            list,
            rest,
            allList,
            _args6 = arguments;
        return regeneratorRuntime.wrap(function _callee6$(_context6) {
          while (1) {
            switch (_context6.prev = _context6.next) {
              case 0:
                page = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : 1;
                searchValue = _args6.length > 2 ? _args6[2] : undefined;
                users = _args6.length > 3 ? _args6[3] : undefined;
                this.setLoading('user', true);
                data = {
                  params: searchValue ? [searchValue] : [],
                  searchParam: {},
                  ids: users || []
                };
                _context6.next = 7;
                return axios.post("/devops/v1/projects/".concat(projectId, "/users/list_users?page=").concat(page, "&size=20"), data)["catch"](function (e) {
                  _this6.setLoading('user', false);

                  Choerodon.handleResponseError(e);
                });

              case 7:
                response = _context6.sent;
                this.setLoading('user', false);

                if (handlePromptError(response)) {
                  list = response.list, rest = _objectWithoutProperties(response, _excluded2);
                  this.setPageInfo(rest);

                  if (searchValue || searchValue === '') {
                    this.setUser(list);
                  } else {
                    allList = this.getUser.concat(list);
                    this.setUser(allList);
                  }
                }

              case 10:
              case "end":
                return _context6.stop();
            }
          }
        }, _callee6, this);
      }));

      function loadUser(_x11) {
        return _loadUser.apply(this, arguments);
      }

      return loadUser;
    }()
    /**
     * 创建流水线
     * @param projectId
     * @param data
     *
     * data 属性：
     *  - name
     *  - triggerType 触发方式，值为 'auto' 和 'manual'
     *  - pipelineUserRels 触发人员，id的数组格式，如果 triggerType 是 'auto'， 则值为null
     *  - pipelineStageVOs 阶段信息，数组
     */

  }, {
    key: "createPipeline",
    value: function createPipeline(projectId, data) {
      return axios.post("/devops/v1/projects/".concat(projectId, "/pipeline"), JSON.stringify(data));
    }
  }, {
    key: "editPipeline",
    value: function editPipeline(projectId, data) {
      return axios.put("/devops/v1/projects/".concat(projectId, "/pipeline"), JSON.stringify(data));
    }
  }, {
    key: "loadDetail",
    value: function () {
      var _loadDetail = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(projectId, id) {
        var _this7 = this;

        var response;
        return regeneratorRuntime.wrap(function _callee7$(_context7) {
          while (1) {
            switch (_context7.prev = _context7.next) {
              case 0:
                this.setDetailLoading(true);
                _context7.next = 3;
                return axios.get("/devops/v1/projects/".concat(projectId, "/pipeline/").concat(id))["catch"](function (e) {
                  _this7.setPipeline(null);

                  _this7.setDetailLoading(false);

                  Choerodon.handleResponseError(e);
                });

              case 3:
                response = _context7.sent;
                this.setDetailLoading(false);

                if (!handlePromptError(response)) {
                  _context7.next = 11;
                  break;
                }

                this.setPipeline(response);
                this.initPipeline(response);
                this.setTrigger(response.triggerType);
                this.checkCanSubmit();
                return _context7.abrupt("return", response);

              case 11:
                return _context7.abrupt("return", false);

              case 12:
              case "end":
                return _context7.stop();
            }
          }
        }, _callee7, this);
      }));

      function loadDetail(_x12, _x13) {
        return _loadDetail.apply(this, arguments);
      }

      return loadDetail;
    }()
  }, {
    key: "setCreateVisible",
    value: function setCreateVisible(value) {
      this.createVisible = value;
    }
  }, {
    key: "setEditVisible",
    value: function setEditVisible(value) {
      this.editVisible = value;
    }
  }, {
    key: "setEditId",
    value: function setEditId(value) {
      this.editId = value;
    }
  }]);

  return PipelineCreateStore;
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "stageList", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return [{
      tempId: INIT_INDEX,
      stageName: '阶段一',
      triggerType: TRIGGER_TYPE_AUTO,
      pipelineTaskVOs: null,
      stageUserRels: null,
      isParallel: TASK_SERIAL
    }];
  }
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "isDisabled", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return false;
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setIsDisabled", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setIsDisabled"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getIsDisabled", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getIsDisabled"), _class2.prototype), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "canSubmit", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return true;
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setCanSubmit", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setCanSubmit"), _class2.prototype), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "checkCanSubmit", [action], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    var _this8 = this;

    return function () {
      /**
       * 校验时机：
       * 删除任务|添加任务|删除阶段|修改触发方式|修改流水线数据加载完成后
       */
      var tempId = _this8.stageList[0].tempId;
      var tasks = tempId || tempId === 0 ? _this8.getTaskList[tempId] : [];
      _this8.canSubmit = _this8.getTrigger !== TRIGGER_TYPE_AUTO || tasks && tasks.length;
    };
  }
}), _applyDecoratedDescriptor(_class2.prototype, "getCanSubmit", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getCanSubmit"), _class2.prototype), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "trigger", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return TRIGGER_TYPE_AUTO;
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setTrigger", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setTrigger"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getTrigger", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getTrigger"), _class2.prototype), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "stageIndex", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return INIT_INDEX;
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setStageIndex", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setStageIndex"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getStageIndex", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getStageIndex"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "addStage", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "addStage"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "editStage", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "editStage"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setStageList", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setStageList"), _class2.prototype), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "taskSettings", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return {};
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setTaskSettings", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setTaskSettings"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "removeStage", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "removeStage"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "clearStageList", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "clearStageList"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "clearTaskSettings", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "clearTaskSettings"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getTaskSettings", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getTaskSettings"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getStageList", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getStageList"), _class2.prototype), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "taskIndex", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return {
      0: INIT_INDEX
    };
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setTaskIndex", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setTaskIndex"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "clearTaskIndex", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "clearTaskIndex"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getTaskIndex", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getTaskIndex"), _class2.prototype), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "taskList", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return {};
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setTaskList", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setTaskList"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "updateTaskList", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "updateTaskList"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "removeTask", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "removeTask"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "clearTaskList", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "clearTaskList"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getTaskList", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getTaskList"), _class2.prototype), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "envData", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return [];
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setEnvData", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setEnvData"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getEnvData", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getEnvData"), _class2.prototype), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "appData", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return [];
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setAppDate", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setAppDate"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getAppData", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getAppData"), _class2.prototype), _descriptor12 = _applyDecoratedDescriptor(_class2.prototype, "loading", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return {
      instance: false,
      app: false,
      env: false,
      config: false,
      value: false,
      user: false
    };
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setLoading", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setLoading"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getLoading", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getLoading"), _class2.prototype), _descriptor13 = _applyDecoratedDescriptor(_class2.prototype, "instances", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return [];
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setInstances", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setInstances"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getInstance", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getInstance"), _class2.prototype), _descriptor14 = _applyDecoratedDescriptor(_class2.prototype, "configList", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return [];
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setConfigList", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setConfigList"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getConfigList", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getConfigList"), _class2.prototype), _descriptor15 = _applyDecoratedDescriptor(_class2.prototype, "user", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return [];
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setUser", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setUser"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getUser", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getUser"), _class2.prototype), _descriptor16 = _applyDecoratedDescriptor(_class2.prototype, "detailLoading", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return false;
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setDetailLoading", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setDetailLoading"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getDetailLoading", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getDetailLoading"), _class2.prototype), _descriptor17 = _applyDecoratedDescriptor(_class2.prototype, "pipeline", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return {};
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setPipeline", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setPipeline"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getPipeline", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getPipeline"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "initPipeline", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "initPipeline"), _class2.prototype), _descriptor18 = _applyDecoratedDescriptor(_class2.prototype, "pageInfo", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return {};
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setPageInfo", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setPageInfo"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getPageInfo", [computed], Object.getOwnPropertyDescriptor(_class2.prototype, "getPageInfo"), _class2.prototype), _descriptor19 = _applyDecoratedDescriptor(_class2.prototype, "createVisible", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return false;
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setCreateVisible", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setCreateVisible"), _class2.prototype), _descriptor20 = _applyDecoratedDescriptor(_class2.prototype, "editVisible", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return false;
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setEditVisible", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setEditVisible"), _class2.prototype), _descriptor21 = _applyDecoratedDescriptor(_class2.prototype, "editId", [observable], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return null;
  }
}), _applyDecoratedDescriptor(_class2.prototype, "setEditId", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "setEditId"), _class2.prototype)), _class2)) || _class);
var pipelineCreateStore = new PipelineCreateStore();
export default pipelineCreateStore;