From c88104169bc4fe457f98f33a91574c4dd33da573 Mon Sep 17 00:00:00 2001
From: jhjang <jhjang@maprex.co.kr>
Date: 금, 03 12월 2021 20:08:01 +0900
Subject: [PATCH] - api 입력 오류 수정 - api 기본값 및 중복 설정 적용 수정

---
 src/main/webapp/scripts/app/api/apiSetting.controller.js |  317 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 306 insertions(+), 11 deletions(-)

diff --git a/src/main/webapp/scripts/app/api/apiSetting.controller.js b/src/main/webapp/scripts/app/api/apiSetting.controller.js
index db6427d..9031cce 100644
--- a/src/main/webapp/scripts/app/api/apiSetting.controller.js
+++ b/src/main/webapp/scripts/app/api/apiSetting.controller.js
@@ -7,30 +7,316 @@
         'app', 'angular'
     ],
     function (app, angular) {
-        app.controller('apiSettingController', ['$scope', '$rootScope', '$log', '$resourceProvider','$uibModal', 'SweetAlert', '$timeout', '$filter',
-            function ($scope, $rootScope, $log, $resourceProvider, $uibModal, SweetAlert, $timeout, $filter) {
+        app.controller('apiSettingController', ['$scope', '$rootScope', '$log', '$resourceProvider','$uibModal', 'SweetAlert', '$timeout', '$filter', '$injector', '$controller', 'Api', 'Priority', 'Severity', 'IssueType', 'IssueTypeCustomField',
+            function ($scope, $rootScope, $log, $resourceProvider, $uibModal, SweetAlert, $timeout, $filter, $injector, $controller, Api, Priority, Severity, IssueType, IssueTypeCustomField) {
 
                 $scope.fn = {
                     changeTab : changeTab,
-                    add : add,
+                    getIssueTypeCallback : getIssueTypeCallback,
+                    getProjectListCallback : getProjectListCallback,
+                    formSubmit : formSubmit,
+                    formCheck : formCheck,
+                    initForm : initForm,
+                    getPriorities : getPriorities,
+                    getSeverities : getSeverities,
+                    start : start,
+                    getIssueTypes : getIssueTypes,
+                    onChangeIssueType : onChangeIssueType,
+                    reset : reset,
+                    resetOverlap : resetOverlap,
+                    formSubmitOverlap : formSubmitOverlap,
+                    removeCustomField : removeCustomField,
+                    getOverlapList : getOverlapList,
+                    onChangeIssueTypeOverlap : onChangeIssueTypeOverlap,
+                    getIssueTypeCustomFields : getIssueTypeCustomFields,
+                    getCurrentIssueTypeVo : getCurrentIssueTypeVo
                 };
 
                 $scope.vm = {
                     tab : "API_COL_SETTING",
+                    issueTypes : [],
+                    severities : [],
+                    priorities : [],
+                    // projects : [],
                     form : {
+                        issueCustomFields : [],
+                        issueApiDefault : {
+                            title : "",
+                            description : "",
+                            priorityId : "",
+                            severityId : "",
+                            customFields : [],
+                            // projectName : "",
+                        },
+                        customFieldId : "",
+                    },
 
-                    }
+                    autoCompletePage : {
+                        issueType : {
+                            page : 0,
+                            totalPage : 0
+                        },
+                        // project : {
+                        //     page : 0,
+                        //     totalPage : 0
+                        // }
+                    },
+                    issueTypeId : "",
+                    issueTypeName : "",
+                    customFieldName : "",
                 };
 
-                //  �깮�꽦 �뙘�뾽
-                function add() {
-                    $uibModal.open({
-                        templateUrl : 'views/api/apiOverlapAdd.html',
-                        size : "sm",
-                        // controller : 'apiOverlapAddController',
-                        backdrop : 'static'
+                angular.extend(this, $controller('autoCompleteController', {$scope : $scope, $injector : $injector}));
+
+                function initForm() {
+                    $scope.vm.form.issueApiDefault.title = "";
+                    $scope.vm.form.issueApiDefault.description = "";
+                    $scope.vm.form.issueApiDefault.priorityId = "";
+                    $scope.vm.form.issueApiDefault.severityId = "";
+                }
+
+                function reset() {
+                    $scope.fn.initForm();
+                    $scope.fn.formSubmit();
+                }
+
+                function resetOverlap() {
+                    $scope.vm.form.customFieldIds = [];
+                    $scope.fn.form.formSubmitOverlap();
+                }
+
+                function  getOverlapList() {
+                    let conditions = {
+                        issueTypeId: $scope.vm.issueTypeId
+                    }
+
+                    Api.findApiOverlap($resourceProvider.getContent(
+                        conditions, $resourceProvider.getPageContent(0, 1000))).then(function (result) {
+                        if (result.data.message.status === "success") {
+
+                            let customFieldApiOverlaps = result.data.data;
+                            $scope.vm.form.customFields = [];
+
+                            if (customFieldApiOverlaps != null) {
+                                customFieldApiOverlaps.forEach(function (customFieldApiOverlap) {
+                                    $scope.vm.form.customFields.push(customFieldApiOverlap.customFieldVo);
+                                });
+                            }
+                        }
+                        else {
+                            SweetAlert.swal($filter("translate")("issue.failedToIssueTypeListLookup"), result.data.message.message, "error"); // "�씠�뒋 �쑀�삎 紐⑸줉 議고쉶 �떎�뙣"
+                        }
                     });
                 }
+
+                function getIssueTypes() {
+                    var conditions = {
+                    };
+
+                    IssueType.find($resourceProvider.getContent(
+                        conditions, $resourceProvider.getPageContent(0, 1000))).then(function (result) {
+                        if (result.data.message.status === "success") {
+                            $scope.vm.issueTypes = result.data.data;
+                            if ($scope.vm.issueTypes != null && $scope.vm.issueTypes.length > 0) {
+                                $scope.vm.issueTypeId = $scope.vm.issueTypes[0].id.toString();
+                                $scope.fn.onChangeIssueType();
+                            }
+                        }
+                        else {
+                            SweetAlert.swal($filter("translate")("issue.failedToIssueTypeListLookup"), result.data.message.message, "error"); // "�씠�뒋 �쑀�삎 紐⑸줉 議고쉶 �떎�뙣"
+                        }
+                    });
+                }
+
+                function getCurrentIssueTypeVo() {
+                    var issueTypeId = $scope.vm.issueTypeId;
+
+                    var issueTypeVo = null;
+                    $scope.vm.issueTypes.forEach(function (issueType) {
+                       if (issueType.id == issueTypeId) {
+                           issueTypeVo = issueType;
+                       }
+                    });
+                    return issueTypeVo;
+                }
+
+                function onChangeIssueTypeOverlap() {
+                    $scope.fn.getOverlapList();
+                }
+
+                function onChangeIssueType() {
+                    if ($scope.vm.issueTypeId != null) {
+                        let conditions = {
+                            issueTypeId: $scope.vm.issueTypeId
+                        }
+
+                        Api.findApiDefault($resourceProvider.getContent(
+                            conditions, $resourceProvider.getPageContent(0, 1000))).then(function (result) {
+                            $scope.fn.initForm();
+                            $scope.fn.getIssueTypeCustomFields();
+
+                            if (result.data.message.status === "success") {
+                                if (angular.isDefined(result.data.data)) {
+                                    $scope.vm.form.issueApiDefault = result.data.data;
+                                    $scope.vm.form.issueApiDefault.priorityId = result.data.data.priorityId != null ? result.data.data.priorityId.toString() : "";
+                                    $scope.vm.form.issueApiDefault.severityId = result.data.data.severityId != null ? result.data.data.severityId.toString() : "";
+
+
+                                    // if (angular.isDefined(result.data.data.projectVo)) {
+                                    //     $scope.vm.projects = [];
+                                    //     $scope.vm.projects.push(result.data.data.projectVo);
+                                    // }
+                                }
+                            } else {
+                                SweetAlert.swal($filter("translate")("common.failedToIssueTypeDefault"), result.data.message.message, "error"); // "�봽濡쒖젥�듃 紐⑸줉 議고쉶 �떎�뙣"
+                            }
+                        });
+                    }
+
+                }
+
+                //  �뤌 泥댄겕
+                function formCheck(formInvalid) {
+                    if (formInvalid) {
+                        return true;
+                    }
+
+                    return false;
+                }
+
+                function formSubmit() {
+                    if ($scope.vm.issueTypeId == null)
+                        return;
+
+                    let condition = {
+                        issueTypeId : $scope.vm.issueTypeId,
+                        title : $scope.vm.form.issueApiDefault.title,
+                        // projectId : $scope.vm.projects != null && $scope.vm.projects.length > 0 ? $scope.vm.projects[0].id : null,
+                        priorityId : $scope.vm.form.issueApiDefault.priorityId,
+                        severityId : $scope.vm.form.issueApiDefault.severityId,
+                        description : $scope.vm.form.issueApiDefault.description,
+                    }
+
+                    Api.modifyApiDefault($resourceProvider.getContent(condition,
+                        $resourceProvider.getPageContent(0, 1))).then(function (result) {
+
+                        if (result.data.message.status === "success") {
+                            SweetAlert.swal($filter("translate")("api.successToApiIssueDefault"), result.data.message.message, "success"); // "api 湲곕낯媛� �꽕�젙 �꽦怨�"
+                        }
+                        else {
+                            SweetAlert.swal($filter("translate")("api.failedToApiIssueDefault"), result.data.message.message, "error"); // "api 湲곕낯媛� �꽕�젙 �떎�뙣"
+                        }
+                    });
+                }
+
+                // �궗�슜�옄 �젙�쓽 �븘�뱶 �꽑�깮 �빆紐� �궘�젣
+                function removeCustomField(index) {
+                    $scope.vm.form.customFields.splice(index, 1);
+                }
+
+                // 以묐났 �빆紐� �쟾�넚
+                function formSubmitOverlap() {
+                    if ($scope.vm.issueTypeId === null)
+                        return;
+
+                    let condition = {
+                        issueTypeId : $scope.vm.issueTypeId,
+                        customFieldIds : (function () {
+                            var ids = [];
+
+                            angular.forEach($scope.vm.form.customFields, function (customField) {
+                                ids.push(customField.id);
+                            });
+
+                            return ids;
+                        })(),
+                    }
+
+                    Api.modifyApiOverlap($resourceProvider.getContent(condition,
+                        $resourceProvider.getPageContent(0, 1))).then(function (result) {
+
+                        if (result.data.message.status === "success") {
+                            SweetAlert.swal($filter("translate")("api.successToApiIssueOverlap"), result.data.message.message, "success"); // "api 以묐났媛� �꽕�젙 �꽦怨�"
+                        }
+                        else {
+                            SweetAlert.swal($filter("translate")("api.failedToApiIssueOverlap"), result.data.message.message, "error"); // "api 以묐났媛� �꽕�젙 �떎�뙣"
+                        }
+                    });
+                }
+
+                function getIssueTypeCallback(result) {
+                    $scope.vm.autoCompletePage.issueType.totalPage = result.data.page.totalPage;
+                }
+
+                function getProjectListCallback(result) {
+                    $scope.vm.autoCompletePage.project.totalPage = result.data.page.totalPage;
+                }
+
+                //  �슦�꽑�닚�쐞 紐⑸줉
+                function getPriorities() {
+                    Priority.find($resourceProvider.getContent({},
+                        $resourceProvider.getPageContent(0, 1000))).then(function (result) {
+
+                        if (result.data.message.status === "success") {
+                            $scope.vm.priorities = result.data.data;
+                        }
+                        else {
+                            SweetAlert.swal($filter("translate")("issue.failedToPriorityListLookup"), result.data.message.message, "error"); // �슦�꽑�닚�쐞 紐⑸줉 議고쉶 �떎�뙣
+                        }
+                    });
+                }
+
+                //  �씠�뒋 �쑀�삎�뿉 �뿰寃곕맂 �궗�슜�옄 �젙�쓽 �븘�뱶
+                function getIssueTypeCustomFields() {
+
+                    $scope.vm.form.issueCustomFields = [];
+
+                    var issueTypeVo = $scope.fn.getCurrentIssueTypeVo();
+                    if (issueTypeVo.projectVo == null) return;
+
+                    IssueTypeCustomField.find($resourceProvider.getContent({
+                            projectId : issueTypeVo.projectVo.id,
+                            IssueTypeId : issueTypeVo.id },
+                        $resourceProvider.getPageContent(0, 1000))).then(function (result) {
+
+                        if (result.data.message.status === "success") {
+
+                            $scope.vm.form.issueCustomFields = [];
+                            angular.forEach(result.data.data, function (issueTypeCustomField) {
+                                $scope.vm.form.issueCustomFields.push(issueTypeCustomField);
+                            });
+                        }
+                        else {
+                            SweetAlert.swal($filter("translate")("issue.failedToUserDefinedFieldListAssociatedLookup"), result.data.message.message, "error"); // �씠�뒋 �쑀�삎�뿉 �뿰寃곕맂 �궗�슜�옄 �젙�쓽 �븘�뱶 紐⑸줉 議고쉶 �떎�뙣
+                        }
+
+                    });
+                }
+
+
+                //  以묒슂�룄 紐⑸줉
+                function getSeverities() {
+                    Severity.find($resourceProvider.getContent({},
+                        $resourceProvider.getPageContent(0, 1000))).then(function (result) {
+
+                        if (result.data.message.status === "success") {
+                            $scope.vm.severities = result.data.data;
+                        }
+                        else {
+                            SweetAlert.swal($filter("translate")("issue.failedToCriticalListLookup"), result.data.message.message, "error"); // 以묒슂�룄 紐⑸줉 議고쉶 �떎�뙣
+                        }
+                    });
+                }
+
+                $rootScope.$on("changeColumnSettingTab", function (event, args){
+                    $scope.fn.start();
+                });
+
+
+                $rootScope.$on("changeOverlapSettingTab", function (event, args){
+                    $scope.fn.getOverlapList();
+                });
+
 
                 function changeTab(tab) {
                     $scope.vm.tab = tab;
@@ -42,5 +328,14 @@
                     }
                 }
 
+                function start() {
+                    $scope.fn.initForm();
+                    $scope.fn.getSeverities();
+                    $scope.fn.getPriorities();
+                    $scope.fn.getIssueTypes();
+
+                }
+                $scope.fn.start();
+
             }]);
     });

--
Gitblit v1.8.0