From add0cdefd56c50c5427945c895574f71202e7ed6 Mon Sep 17 00:00:00 2001
From: minhee <alsdldlfrl@gmail.com>
Date: 수, 16 3월 2022 18:12:51 +0900
Subject: [PATCH] - api로 이슈 추가 시 사용자정의필드 타입으로 체크 => 정규식표현검사로 체크로 변경

---
 src/main/webapp/scripts/app/companyField/companyFieldAdd.controller.js |  223 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 203 insertions(+), 20 deletions(-)

diff --git a/src/main/webapp/scripts/app/companyField/companyFieldAdd.controller.js b/src/main/webapp/scripts/app/companyField/companyFieldAdd.controller.js
index 0c14335..5465d18 100644
--- a/src/main/webapp/scripts/app/companyField/companyFieldAdd.controller.js
+++ b/src/main/webapp/scripts/app/companyField/companyFieldAdd.controller.js
@@ -23,8 +23,10 @@
                     getStatusListCallBack : getStatusListCallBack,
                     addTel : addTel,
                     addMail : addMail,
+                    addIpRange : addIpRange,
                     removeTelInput : removeTelInput,
-                    removeMailInput : removeMailInput
+                    removeMailInput : removeMailInput,
+                    removeIpRangeInput : removeIpRangeInput
                 };
 
                 $scope.vm = {
@@ -38,6 +40,8 @@
                         tel : "",  //�쟾�솕踰덊샇
                         email : "",  //�씠硫붿씪
                         url : "", // url
+                        ipStart : "", //ip�떆�옉二쇱냼
+                        ipEnd : "", //ip醫낅즺二쇱냼
                         memo : "",  //鍮꾧퀬
                         companyTypeId : "",
                         companyType : "", //湲곗뾽援щ텇
@@ -50,9 +54,13 @@
                         statusId : "",
                         status : "", //�긽�깭
                         inputTels : [0], //�뿰�씫泥�
-                        tels : {},
+                        tels : [],
                         inputMails : [0], //�씠硫붿씪
-                        emails : {}
+                        emails : [],
+                        inputIpStarts : [0], //ip �떆�옉�젏
+                        ipStarts : [],
+                        inputIpEnds : [0], //ip 醫낅즺�젏
+                        ipEnds : []
                     },
                     typeCategory : {
                         companyType : "COMPANYTYPE",
@@ -112,7 +120,16 @@
                 }
 
                 // �뾽醫�(��遺꾨쪟) autocomplete page �뾽�뜲�씠�듃
-                function getParentSectorListCallBack(result) {
+                function getParentSectorListCallBack(result, value) {
+                    if (value === "") {
+                        $scope.vm.form.parentSectorId = "";
+                        if ($rootScope.isDefined($scope.vm.form.parentSectors) && $rootScope.isDefined($scope.vm.form.parentSectors[0])) {
+                            $scope.vm.form.parentSectors[0].id = "";
+                        }
+                        $scope.vm.form.childSectorId = "";
+                        $scope.vm.form.childSector = "";
+                        $scope.vm.form.childSectors = [];
+                    }
                     $scope.vm.autoCompletePage.parentSector.totalPage = result.data.page.totalPage;
                 }
 
@@ -140,11 +157,49 @@
                 }
 
                 $scope.$on("ispFieldEvent", function (event, result) {
-                    $scope.vm.form.ispId = result[0].id;
+                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
+                        $scope.vm.form.ispId = result[0].id;
+                    }
                 });
 
                 $scope.$on("hostingFieldEvent", function (event, result) {
-                    $scope.vm.form.hostingId = result[0].id;
+                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
+                        $scope.vm.form.hostingId = result[0].id;
+                    }
+                });
+
+                $scope.$on("companyTypeEvent", function (event, result) {
+                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
+                        $scope.vm.form.companyTypeId = result[0].id;
+                    }
+                });
+                $scope.$on("parentSectorEvent", function (event, result) {
+                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
+                        $scope.vm.form.parentSectorId = result[0].id;
+                    } else {
+                        $scope.vm.form.parentSectorId = "";
+                        if ($rootScope.isDefined($scope.vm.form.parentSectors) && $rootScope.isDefined($scope.vm.form.parentSectors[0])) {
+                            $scope.vm.form.parentSectors[0].id = "";
+                        }
+                    }
+                    $scope.vm.form.childSectorId = "";
+                    $scope.vm.form.childSector = "";
+                    $scope.vm.form.childSectors = [];
+                });
+                $scope.$on("childSectorEvent", function (event, result) {
+                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
+                        $scope.vm.form.childSectorId = result[0].id;
+                    }
+                });
+                $scope.$on("regionEvent", function (event, result) {
+                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
+                        $scope.vm.form.regionId = result[0].id;
+                    }
+                });
+                $scope.$on("statusEvent", function (event, result) {
+                    if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) {
+                        $scope.vm.form.statusId = result[0].id;
+                    }
                 });
 
                 //  �뤌 �쟾�넚
@@ -154,14 +209,14 @@
                     var content = {
                         name : $rootScope.preventXss($scope.vm.form.name),    //  �뾽泥대챸
                         ispId : (function () {  // ISP �븘�씠�뵒
-                            var ispId = -1;
+                            var ispId = null;
                             if ($scope.vm.form.issueIspFields != null) {
                                 ispId = $scope.vm.form.ispId;
                             }
                             return ispId;
                         })(),
                         hostingId : (function () {  // Hosting �븘�씠�뵒
-                            var hostingId = -1;
+                            var hostingId = null;
                             if ($scope.vm.form.issueHostingFields != null) {
                                 hostingId = $scope.vm.form.hostingId;
                             }
@@ -202,39 +257,71 @@
                             }
                             return emailList;
                         })(),
-                        url : $scope.vm.form.url, // url
+                        url : (function () {
+                            //  紐⑤뱺 怨듬갚 �젣嫄�
+                            var regex = / /gi;
+                            let url = $scope.vm.form.url;
+                            if ($rootScope.isDefined(url) && url.indexOf(" ") !== -1) {
+                                url = url.replace(regex, "");
+                            }
+                            return url;
+                        })(),
+                        ipStarts : (function () {
+                            var ipStarts = [];
+                            if ($scope.vm.form.ipStarts != null) {
+                                angular.forEach($scope.vm.form.ipStarts, function (ipS) {
+                                    ipStarts.push(ipS);
+                                });
+                                ipStarts  = ipStarts.filter(function(item) { //�벐�젅湲� �뜲�씠�꽣 �븘�꽣留�
+                                    return item !== null && item !== undefined && item !== '';
+                                });
+                            }
+                            return ipStarts;
+                        })(),
+                        ipEnds : (function () {
+                            var ipEnds = [];
+                            if ($scope.vm.form.ipEnds != null) {
+                                angular.forEach($scope.vm.form.ipEnds, function (ipE) {
+                                    ipEnds.push(ipE);
+                                });
+                                ipEnds  = ipEnds.filter(function(item) { //�벐�젅湲� �뜲�씠�꽣 �븘�꽣留�
+                                    return item !== null && item !== undefined && item !== '';
+                                });
+                            }
+                            return ipEnds;
+                        })(),
                         memo : $scope.vm.form.memo,  //鍮꾧퀬
                         companyTypeId : (function () {
-                            var companyTypeId = -1;
-                            if ($scope.vm.form.companyTypes != null) {
+                            var companyTypeId = null;
+                            if ($scope.vm.form.companyTypes != null && $scope.vm.form.companyTypes.length > 0) {
                                 companyTypeId = $scope.vm.form.companyTypes[0].id;
                             }
                             return companyTypeId;
                         })(),
                         parentSectorId : (function () {
-                            var parentSectorId = -1;
-                            if ($scope.vm.form.parentSectors != null) {
+                            var parentSectorId = null;
+                            if ($scope.vm.form.parentSectors != null && $scope.vm.form.parentSectors.length > 0) {
                                 parentSectorId = $scope.vm.form.parentSectors[0].id;
                             }
                             return parentSectorId;
                         })(),
                         childSectorId : (function () {
-                            var childSectorId = -1;
-                            if ($scope.vm.form.childSectors != null) {
+                            var childSectorId = null;
+                            if ($scope.vm.form.childSectors != null && $scope.vm.form.childSectors.length > 0) {
                                 childSectorId = $scope.vm.form.childSectors[0].id;
                             }
                             return childSectorId;
                         })(),
                         regionId : (function () {
-                            var regionId = -1;
-                            if ($scope.vm.form.regions != null) {
+                            var regionId = null;
+                            if ($scope.vm.form.regions != null && $scope.vm.form.regions.length > 0) {
                                 regionId = $scope.vm.form.regions[0].id;
                             }
                             return regionId;
                         })(),
                         statusId : (function () {
-                            var statusId = -1;
-                            if ($scope.vm.form.statuses != null) {
+                            var statusId = null;
+                            if ($scope.vm.form.statuses != null && $scope.vm.form.statuses.length > 0) {
                                 statusId = $scope.vm.form.statuses[0].id;
                             } else if ($scope.vm.form.status !== ""){
                                 statusId = 120; //吏곸젒�엯�젰 �씪 寃쎌슦
@@ -244,6 +331,13 @@
                         statusName : $scope.vm.form.status
                     };
 
+                    //  ip ���뿭�� �쑀�슚�꽦 泥댄겕
+                    let result = ipRangeChk(content.ipStarts, content.ipEnds);
+                    if (!result) {
+                        $rootScope.spinner = false;
+                        return;
+                    }
+                    
                     CompanyField.add($resourceProvider.getContent(content,
                         $resourceProvider.getPageContent(0, 10))).then(function (result) {
 
@@ -253,12 +347,62 @@
                             $rootScope.$broadcast("getPageList", {});
                         }
                         else {
-                            SweetAlert.error($filter("translate")("companyField.failedCompanyFieldRegistration"), result.data.message.message);
+                            SweetAlert.warning($filter("translate")("companyField.failedCompanyFieldRegistration"), result.data.message.message);
                         }
 
                         $rootScope.spinner = false;
                     });
+                }
+                
+                //  ip ���뿭�� �쑀�슚�꽦 寃��궗
+                function ipRangeChk(ipStarts, ipEnds) {
+                    let result = true;
 
+                    if ($rootScope.isDefined(ipStarts) && $rootScope.isDefined(ipEnds)) {
+                        if (ipStarts.length !== ipEnds.length) {
+                            SweetAlert.warning($filter("translate")("companyField.ipRangeError"), $filter("translate")("companyField.ipRangeNotEnter"));
+                            result = false;
+                            return;
+                        }
+
+                        let ipStartArr = [];
+                        let ipEndArr = [];
+
+                        for (let i=0; i<ipStarts.length; i++) {
+                            let ipStart = ipToLong(ipStarts[i]);
+                            let ipEnd = ipToLong(ipEnds[i]);
+                            if (ipEnd < ipStart) {
+                                SweetAlert.warning($filter("translate")("companyField.ipRangeError"), $filter("translate")("companyField.ipStartNotLargerThanEnd"));
+                                result = false;
+                                return;
+                            }
+                            ipStartArr.push(ipStart);
+                            ipEndArr.push(ipEnd);
+                        }
+
+                        for (let i=0; i<ipStartArr.length; i++) {
+                            if ($rootScope.isDefined(ipStartArr[i+1])) {
+                                if((ipStartArr[i] >= ipStartArr[i+1] && ipStartArr[i] <= ipEndArr[i+1])
+                                    || (ipEndArr[i] >= ipStartArr[i+1] && ipEndArr[i] <= ipEndArr[i+1])) {
+                                    SweetAlert.warning($filter("translate")("companyField.ipRangeError"), $filter("translate")("companyField.ipRangeNotOverlap"));
+                                    result = false;
+                                    return;
+                                }
+                            }
+                        }
+                    }
+                    return result;
+                }
+                
+                //  ip 二쇱냼 �닽�옄濡� 蹂��솚
+                function ipToLong(ip) {
+                    let result = 0;
+                    let ipArr = ip.split(".");
+
+                    for (let i=0; i<ipArr.length; i++) {
+                        result += parseInt(ipArr[i]) * Math.pow(256, 3-i);
+                    }
+                    return result;
                 }
 
                 // �뿰�씫泥� input 李� 異붽� 踰꾪듉
@@ -299,14 +443,53 @@
                     }
                 }
 
+                // IPRange input 李� 異붽� 踰꾪듉
+                function addIpRange() {
+                    var arrayFull = true;      // 諛곗뿴�씠 媛��뱷 李� �엳�뒗吏� �뿬遺�
+                    var startIdx = 0;
+                    var endIdx = 0;
+                    $scope.vm.form.inputIpStarts.forEach(function (start) {
+                        if (!$rootScope.isDefined($scope.vm.form.ipStarts[startIdx])) {
+                            arrayFull = false;
+                        }
+                        startIdx++;
+                    });
+
+                    $scope.vm.form.inputIpEnds.forEach(function (start) {
+                        if (!$rootScope.isDefined($scope.vm.form.ipEnds[endIdx])) {
+                            arrayFull = false;
+                        }
+                        endIdx++;
+                    });
+
+                    if (arrayFull) {
+                        $scope.vm.form.inputIpStarts.push(startIdx);
+                        $scope.vm.form.ipStarts[startIdx] = "";
+                        $scope.vm.form.inputIpEnds.push(endIdx);
+                        $scope.vm.form.ipEnds[endIdx] = "";
+                    } else {
+                        SweetAlert.warning($filter("translate")("companyField.writeCompanyIpRange"), $filter("translate")("companyField.writeIpRange")); // 異붽�踰꾪듉 寃쎄퀬
+                    }
+                }
+
                 // �뿰�씫泥� input �궘�젣
                 function removeTelInput(index) {
                     $scope.vm.form.inputTels.splice(index, 1);
+                    $scope.vm.form.tels.splice(index, 1);
                 }
 
                 // �씠硫붿씪 二쇱냼 input �궘�젣
                 function removeMailInput(index) {
                     $scope.vm.form.inputMails.splice(index, 1);
+                    $scope.vm.form.emails.splice(index, 1);
+                }
+
+                // ipRange input �궘�젣
+                function removeIpRangeInput(index) {
+                    $scope.vm.form.inputIpStarts.splice(index, 1);
+                    $scope.vm.form.ipStarts.splice(index, 1);
+                    $scope.vm.form.inputIpEnds.splice(index, 1);
+                    $scope.vm.form.ipEnds.splice(index, 1);
                 }
 
                 //  �뙘�뾽 李� �떕湲�

--
Gitblit v1.8.0