function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }

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

function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }

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

function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }

function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }

function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }

function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }

(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["default~functional-functional-module~scenario-scenario-module~scenarios-scenarios-module~welcome-pag~bc6e8da7"], {
  /***/
  "./src/app/pages/scenario/service/scenario-share.service.ts":
  /*!******************************************************************!*\
    !*** ./src/app/pages/scenario/service/scenario-share.service.ts ***!
    \******************************************************************/

  /*! exports provided: ScenarioSharedService */

  /***/
  function _src_app_pages_scenario_service_scenarioShareServiceTs(module, __webpack_exports__, __webpack_require__) {
    "use strict";

    __webpack_require__.r(__webpack_exports__);
    /* harmony export (binding) */


    __webpack_require__.d(__webpack_exports__, "ScenarioSharedService", function () {
      return ScenarioSharedService;
    });
    /* harmony import */


    var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
    /*! tslib */
    "./node_modules/tslib/tslib.es6.js");
    /* harmony import */


    var _angular_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
    /*! @angular/core */
    "./node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js");
    /* harmony import */


    var _constants_scen_schedule_constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(
    /*! ../constants/scen-schedule-constants */
    "./src/app/pages/scenario/constants/scen-schedule-constants.ts");
    /* harmony import */


    var _scenario_http_service__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(
    /*! ./scenario-http.service */
    "./src/app/pages/scenario/service/scenario-http.service.ts");
    /* harmony import */


    var _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(
    /*! ../interface/scenario-state */
    "./src/app/pages/scenario/interface/scenario-state.ts");
    /* harmony import */


    var _angular_common_http__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(
    /*! @angular/common/http */
    "./node_modules/@angular/common/__ivy_ngcc__/fesm2015/http.js");
    /* harmony import */


    var src_app_core_session_session_service__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(
    /*! src/app/core/session/session.service */
    "./src/app/core/session/session.service.ts");
    /* harmony import */


    var _scenario_utils_service__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(
    /*! ./scenario-utils.service */
    "./src/app/pages/scenario/service/scenario-utils.service.ts");
    /* harmony import */


    var src_app_shared_header_work_profile_services_work_profile_active_service__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(
    /*! src/app/shared/header/work-profile/services/work-profile-active.service */
    "./src/app/shared/header/work-profile/services/work-profile-active.service.ts");
    /* harmony import */


    var lodash__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(
    /*! lodash */
    "./node_modules/lodash/lodash.js");
    /* harmony import */


    var lodash__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_9__);

    var ScenarioSharedService = /*#__PURE__*/function () {
      function ScenarioSharedService(sessionService, scenHttpService, scenUtilsService, activeWPService) {
        _classCallCheck(this, ScenarioSharedService);

        this.sessionService = sessionService;
        this.scenHttpService = scenHttpService;
        this.scenUtilsService = scenUtilsService;
        this.activeWPService = activeWPService;
        this.script = "";
        this.privilege = "{}";
        this.projectOptions = [];
        this.subProjectOptions = [];
        this.dataDirOptions = [];
        this.runLogicOptions = [];
        this.userProfileoptions = [];
        this.scriptOptions = [];
        this.grpPrj = "default";
        this.grpSubProj = "default";
        this.showScheduleDialog = false;
        this.isEditSchedule = false;
        this.isScheduler = false;
        this.SCRIPT_DATA = {
          SCRIPT: "script",
          PROJ: "project",
          SUBPROJ: "subproject",
          OWNER: "owner",
          GRP_NAME: "groupName",
          PERM: "Permission",
          MOD_TIME: "modificationTime"
        };
        this.runLogicListPool = {};
      }

      return _createClass(ScenarioSharedService, [{
        key: "getProjSubProjList",
        value: function getProjSubProjList() {
          var _this = this;

          return new Promise(function (onfullfill, onreject) {
            if (_this.totalProjSubProjData && _this.totalProjSubProjData.length > 0) {
              _this.projSubProjData(_this.totalProjSubProjData);

              onfullfill(true);
              return;
            }

            _this.scenHttpService.getProjSubprojList(_this.sessionService.session.cctx.u, _this.privilege).subscribe(function (state) {
              if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["GetProjSubprojListLoadingState"]) {
                _this.scenUtilsService.loadingScen = true;
                return;
              }

              if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["GetProjSubprojListLoadedState"]) {
                _this.onLoadedGetProjSubProjList(state);

                onfullfill(state.data);
                _this.scenUtilsService.loadingScen = false;
                return;
              }
            }, function (state) {
              console.error(state);
              _this.scenUtilsService.loadingScen = false;
            });
          });
        }
      }, {
        key: "onLoadedGetProjSubProjList",
        value: function onLoadedGetProjSubProjList(state) {
          this.projSubProjData(state.data);
        }
      }, {
        key: "projSubProjData",
        value: function projSubProjData(res) {
          this.totalProjSubProjData = res;
          var prjArr = [];
          var tmpPrjArr = [];
          this.projectOptions = [];
          this.projectOptions.push({
            label: "--Select Project--",
            value: ""
          });

          for (var i = 0; i < res.length; i++) {
            if (prjArr.indexOf(res[i].project) == -1 && res[i]["Permission"] != "4") prjArr.push(res[i].project);

            if (tmpPrjArr.indexOf(res[i].project) == -1) {
              if (res[i]["Permission"] != "4") tmpPrjArr.push(res[i].project);
            }
          }

          for (var k = 0; k < tmpPrjArr.length; k++) {
            if (tmpPrjArr[k] == 'samples') continue;
            this.projectOptions.push({
              label: tmpPrjArr[k],
              value: tmpPrjArr[k]
            });
          }
        }
      }, {
        key: "showSubProjList",
        value: function showSubProjList(event) {
          this.grpPrj = event.value;
          this.subProjectOptions = [];
          this.subProjectOptions.push({
            label: ' -- Select Sub Project-- ',
            value: null
          });
          var subPrjArr = [];

          for (var i = 0; i < this.totalProjSubProjData.length; i++) {
            if (this.totalProjSubProjData[i].project == event.value) {
              if (subPrjArr.indexOf(this.totalProjSubProjData[i].subproject) == -1 && this.totalProjSubProjData[i]["Permission"] != "4") subPrjArr.push(this.totalProjSubProjData[i].subproject);
            }
          }

          for (var j = 0; j < subPrjArr.length; j++) {
            this.subProjectOptions.push({
              label: subPrjArr[j],
              value: subPrjArr[j]
            });
          }

          this.grpSubProj = subPrjArr[0];
          return this.grpSubProj;
        }
      }, {
        key: "getProjSubjBasedOnScriptList",
        value: function getProjSubjBasedOnScriptList(flag) {
          var _this2 = this;

          return new Promise(function (onfullfill) {
            _this2.scenHttpService.getScriptList(_this2.sessionService.session.cctx.u, _this2.privilege, flag).subscribe(function (state) {
              if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["GetScriptListLoadingState"]) {
                _this2.scenUtilsService.loadingScen = true;
                return;
              }

              if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["GetScriptListLoadedState"]) {
                _this2.onLoadedGetScriptList(state, flag);

                onfullfill(_this2.script);
                _this2.scenUtilsService.loadingScen = false;
                return;
              }
            }, function (state) {
              _this2.scenUtilsService.loadingScen = false;
            });
          });
        }
      }, {
        key: "onLoadedGetScriptList",
        value: function onLoadedGetScriptList(state, isJmeter) {
          this.scenUtilsService.projSubScriptData = state.data;
          this.script = this.createDDScriptList({
            value: this.grpSubProj
          }, isJmeter);
        }
      }, {
        key: "createDDScriptList",
        value: function createDDScriptList(event, isJmeter, script) {
          if (event.value != undefined) this.grpSubProj = event.value;
          this.scriptOptions = [];
          var tmpScriptArr = [];
          var arrData = this.scenUtilsService.projSubScriptData;

          if (isJmeter) {}

          for (var i = 0; i < arrData.length; i++) {
            var sriptObj = arrData[i];

            if (sriptObj[this.SCRIPT_DATA.PROJ] == this.grpPrj && sriptObj[this.SCRIPT_DATA.SUBPROJ] == this.grpSubProj) {
              if (tmpScriptArr.indexOf(sriptObj[this.SCRIPT_DATA.SCRIPT]) == -1) {
                tmpScriptArr.push(sriptObj[this.SCRIPT_DATA.SCRIPT]);
              }
            }
          } //Handling Edit case


          if (script != null) {
            if (tmpScriptArr.indexOf(script) == -1) {
              tmpScriptArr.push(script);
            }
          }

          tmpScriptArr.sort();
          var scriptName = "";
          this.scriptOptions.push({
            label: 'Select script',
            value: null
          });
          this.scriptOptions = this.createSelectItem(tmpScriptArr);

          if (this.scriptOptions.length != 0) {
            scriptName = this.scriptOptions[0].value;
            this.getRunlogicData(scriptName);
          }

          return scriptName;
        }
      }, {
        key: "createSelectItem",
        value: function createSelectItem(list) {
          var selectItemList;
          selectItemList = [];

          for (var index in list) {
            selectItemList.push({
              label: list[index],
              value: list[index]
            });
          }

          return selectItemList;
        }
      }, {
        key: "getRunlogicData",
        value: function getRunlogicData(scriptName, groupData) {
          var _this3 = this;

          try {
            return new Promise(function (onfullfill, onreject) {
              var username = _this3.sessionService.session.cctx.u;
              if (username == 'cavisson') username = 'admin';
              var keyScriptName = "".concat(_this3.grpPrj, "/").concat(_this3.grpSubProj, "/").concat(scriptName);
              var key = keyScriptName;

              if (_this3.runLogicListPool[key] != undefined && _this3.runLogicListPool[key] != null) {
                _this3.processRunlogicList(_this3.runLogicListPool[key], groupData);

                onfullfill(_this3.selectedrunlogic);
                return _this3.runLogicListPool[key];
              }

              var params = new _angular_common_http__WEBPACK_IMPORTED_MODULE_5__["HttpParams"]();
              params = params.set('productKey', _this3.sessionService.session.cctx.pk);
              params = params.set("workspace", username);
              params = params.set("project", _this3.grpPrj);
              params = params.set("subProject", _this3.grpSubProj);
              params = params.set("scriptName", scriptName);
              params = params.set("profile", _this3.activeWPService.profile);

              _this3.scenHttpService.GetScriptRunlogicList(params).subscribe(function (state) {
                if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["GetScriptRunlogicListLoadingState"]) {
                  _this3.scenUtilsService.loadingScen = true;
                  return;
                }

                if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["GetScriptRunlogicListLoadedState"]) {
                  _this3.scenUtilsService.loadingScen = false;

                  _this3.onLoadedGetScriptRunlogic(state, key, groupData);

                  onfullfill(_this3.selectedrunlogic);
                  return;
                }
              }, function (state) {
                _this3.scenUtilsService.loadingScen = false;
              });
            });
          } catch (e) {
            console.error('Error while getting data ', e);
          }
        }
        /**
         * This method produces result with script type as output.
         * @param groupData selected Group Data
         * @returns
         */

      }, {
        key: "isScriptRBU",
        value: function isScriptRBU(groupData) {
          var _this4 = this;

          var scriptName = groupData.scriptName.split("/");
          var flow;
          var user = this.sessionService.session.cctx.u;
          var payload;
          var cctx = this.sessionService.session.cctx;
          payload = {
            reqData: "-w " + (user == "cavisson" ? "admin" : user) + "/" + this.activeWPService.profile + " -s " + "".concat(this.grpPrj, "/").concat(this.grpSubProj, "/scripts/").concat(scriptName[2]) + " -o info"
          };
          return new Promise(function (onFulfil, onReject) {
            _this4.scenHttpService.doScriptOperation(payload).subscribe(function (state) {
              if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["CreateScriptLoadingState"]) {
                return;
              }

              if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["CreateScriptLoadedState"]) {
                onFulfil(state.data);
                return;
              }
            }, function (state) {
              return;
            });
          });
        }
      }, {
        key: "onLoadedGetScriptRunlogic",
        value: function onLoadedGetScriptRunlogic(state, key, groupData) {
          var res = state.data;
          this.selectedrunlogic = this.processRunlogicList(res, groupData);
          this.runLogicListPool[key] = res;
          return res;
        }
      }, {
        key: "processRunlogicList",
        value: function processRunlogicList(res, groupData) {
          this.runLogicOptions = [];
          this.runLogicOptions.unshift({
            label: 'as per script',
            value: null
          });
          this.selectedrunlogic = res['default'];
          var isMyObjectEmpty = JSON.stringify(res) === "{}";

          if (isMyObjectEmpty) {
            if (groupData) groupData.isRunlogicPresent = false;
            this.selectedrunlogic = 'as per script';
          } else if (res['list'].length == 0) {
            if (groupData) groupData.isRunlogicPresent = false;
            this.selectedrunlogic = 'as per script';
          } else {
            if (groupData) groupData.isRunlogicPresent = true;
            if (!res['default']) this.selectedrunlogic = res['list'][0];else this.selectedrunlogic = res['default'];

            for (var i = 0; i < res['list'].length; i++) {
              this.runLogicOptions.push({
                label: res['list'][i],
                value: res['list'][i]
              });
            }
          }

          return this.selectedrunlogic;
        }
      }, {
        key: "getProfileScriptList",
        value: function getProfileScriptList(locKeyData) {
          var _this5 = this;

          return new Promise(function (onfullfill, onreject) {
            var REST_KEY = {
              SCRIPT: "_S",
              PROFILE: "_P",
              GENERATOR: "_G",
              SCRIPT_TAG: "_ST",
              GENERATOR_LOCATION: "_GL",
              GENERATOR_US_LOCATION: "_UL",
              GENERATOR_LOCATION_SUB: "_GLS"
            };
            var me = _this5;
            var dataServiceObj = {
              getScenMode: function getScenMode() {
                return me.scenUtilsService.ScenMode;
              },
              getScenName: function getScenName() {
                return "".concat(me.scenUtilsService.Project, "/").concat(me.scenUtilsService.subProject, "/").concat(me.scenUtilsService.scenarioName);
              }
            }; //todo~ functionalimpleemntation set to false by default for now

            _this5.scenHttpService.getProfileScriptList(false, dataServiceObj, false).subscribe(function (state) {
              if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["GetProfileScriptListLoadingState"]) {
                return;
              }

              if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["GetProfileScriptListLoadedState"]) {
                _this5.onLoadedGetProfileScriptList(state, REST_KEY, locKeyData);

                onfullfill(true);
                return;
              }
            }, function (state) {
              onreject(false);
            });
          });
        }
      }, {
        key: "onLoadedGetProfileScriptList",
        value: function onLoadedGetProfileScriptList(state, REST_KEY, locKeyData) {
          var data = state.data;

          for (var key in data) {
            if (key == REST_KEY.PROFILE) {
              var profileArr = data[key]; //Getting profile data added from User Profile -> Location, which will not come from server unless it is saved from UI.

              if (locKeyData) {
                var locKeyDataTmp = lodash__WEBPACK_IMPORTED_MODULE_9__["cloneDeep"](locKeyData)[_constants_scen_schedule_constants__WEBPACK_IMPORTED_MODULE_2__["GLOBAL_KEY"]];

                if (locKeyDataTmp) {
                  for (var i = 0; i < locKeyDataTmp.length; i++) {
                    var profile = locKeyDataTmp[i][0];

                    if (profileArr.indexOf(profile) == -1) {
                      profileArr.push(profile);
                    }
                  }
                }
              }

              this.userProfileoptions = this.createSelectItem(profileArr);
            }
          }
        }
      }, {
        key: "fillDataDir",
        value: function fillDataDir() {
          var _this6 = this;

          return new Promise(function (onfullfill, onreject) {
            var username = _this6.sessionService.session.cctx.u;
            if (username == 'cavisson') username = 'admin';
            _this6.defaultPath = "workspace/" + username + "/" + _this6.activeWPService.profile + "/cavisson/data/";
            _this6.dataDirOptions = [];

            _this6.dataDirOptions.push({
              label: '--Select Data Directory--',
              value: ""
            });

            _this6.scenHttpService.getDataDirList(_this6.defaultPath).subscribe(function (state) {
              if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["GetServerDirectoryFilesLoadingState"]) {
                return;
              }

              if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["GetServerDirectoryFilesLoadedState"]) {
                _this6.onLoadedUserGetServerDirectoryFiles(state);

                onfullfill(true);
                return;
              }
            }, function (state) {
              onreject(false);
            });
          });
        }
      }, {
        key: "onLoadedUserGetServerDirectoryFiles",
        value: function onLoadedUserGetServerDirectoryFiles(state) {
          var datadirectorylist = state.data;
          if (datadirectorylist == undefined) return;else {
            for (var i = 0; i < datadirectorylist.length; i++) {
              if (!datadirectorylist[i].name.startsWith(".") && datadirectorylist[i].isDir) this.dataDirOptions.push({
                label: datadirectorylist[i].name,
                value: datadirectorylist[i].name
              });
            }
          }
        }
      }, {
        key: "getPermissions",
        value: function getPermissions() {
          var _this7 = this;

          return new Promise(function (onfullfill, onreject) {
            if (Object.keys(JSON.parse(_this7.privilege)).length > 0) return onfullfill(_this7.privilege);

            _this7.scenHttpService.getPermissions("scenario", "scenario").subscribe(function (state) {
              var _a;

              if (state instanceof _interface_scenario_state__WEBPACK_IMPORTED_MODULE_4__["ScenarioRestLoadedState"]) {
                var res = state.data;
                _this7.privilege = (_a = JSON.stringify(res.data)) !== null && _a !== void 0 ? _a : "{}";
                onfullfill(_this7.privilege);
              }
            }, function (err) {
              onreject(err);
            });
          });
        }
        /**
         * This method is used to get latest group name for scenario.
         * @param groupArray - grp data array.
         */

      }, {
        key: "getLatestGroupName",
        value: function getLatestGroupName(groupArray) {
          var totalGroup = 0;
          var groupNameArr = [];

          var _iterator = _createForOfIteratorHelper(groupArray),
              _step;

          try {
            for (_iterator.s(); !(_step = _iterator.n()).done;) {
              var grpObj = _step.value;
              totalGroup++;
              groupNameArr.push(grpObj.grpName);
            }
          } catch (err) {
            _iterator.e(err);
          } finally {
            _iterator.f();
          }

          return this.getNewGroupName(totalGroup, groupNameArr);
        }
        /**
         * This is recursive method to get new group name.
         * @param totalGroup - number of total groups
         * @param groupNameArr - array of grp Names
         * @returns
         */

      }, {
        key: "getNewGroupName",
        value: function getNewGroupName(totalGroup, groupNameArr) {
          if (groupNameArr.indexOf("Group_".concat(totalGroup + 1)) > -1) return this.getNewGroupName(totalGroup + 1, groupNameArr);else return "Group_".concat(totalGroup + 1);
        }
      }, {
        key: "buildRunlogicOptions",
        value: function buildRunlogicOptions(selectedGroupData) {
          var _this8 = this;

          this.runLogicOptions = [];
          this.runLogicOptions.unshift({
            label: 'as per script',
            value: null
          });
          selectedGroupData.runlogicList.forEach(function (runlogic, index) {
            _this8.runLogicOptions.push({
              label: runlogic.name + (runlogic.isDefault ? ' (Default)' : ''),
              value: runlogic.name
            });
          });
        }
      }]);
    }();

    ScenarioSharedService.ctorParameters = function () {
      return [{
        type: src_app_core_session_session_service__WEBPACK_IMPORTED_MODULE_6__["SessionService"]
      }, {
        type: _scenario_http_service__WEBPACK_IMPORTED_MODULE_3__["ScenarioHttpService"]
      }, {
        type: _scenario_utils_service__WEBPACK_IMPORTED_MODULE_7__["ScenarioUtilsService"]
      }, {
        type: src_app_shared_header_work_profile_services_work_profile_active_service__WEBPACK_IMPORTED_MODULE_8__["WorkProfileActiveService"]
      }];
    };

    ScenarioSharedService = Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"])([Object(_angular_core__WEBPACK_IMPORTED_MODULE_1__["Injectable"])({
      providedIn: 'root'
    })], ScenarioSharedService);
    /***/
  }
}]);