/**
|
* Created by wisestone on 2018-01-17.
|
*/
|
'use strict';
|
|
define([
|
'app',
|
'angular'
|
],
|
function (app, angular) {
|
app.controller('issueImportExcelController', ['$scope', '$rootScope', '$log', '$resourceProvider', '$uibModalInstance', '$injector', '$controller', '$tableProvider', 'Issue', 'IssueType', 'SweetAlert', '$filter', '$timeout',
|
function ($scope, $rootScope, $log, $resourceProvider, $uibModalInstance, $injector, $controller, $tableProvider, Issue, IssueType, SweetAlert, $filter, $timeout) {
|
|
$scope.fn = {
|
cancel : cancel, // 팝업 창 닫기
|
formSubmit : formSubmit, // 폼 전송
|
formCheck : formCheck, // 폼 체크
|
getIssueTypes : getIssueTypes, // 이슈 타입 목록 가져오기
|
makeSearchConditions : makeSearchConditions, // 선택한 조건을 json 으로 만든다.
|
onFileSelect : onFileSelect, // 파일 업로드
|
getIssueListCallBack : getIssueListCallBack, // 이슈 autocomplete page 업데이트
|
startExecute : startExecute, // 컨트롤 로딩시 처음으로 시작되는 함수
|
};
|
|
$scope.vm = {
|
form : {
|
projects : [], // 선택한 프로젝트
|
issueTypeId : "", // 이슈 타입 아이디
|
issueTypes : [], // 이슈 유형 전체 목록
|
file : "", // 업로드하는 Excel File
|
fileName : ""
|
},
|
projectName : "",
|
autoCompletePage : {
|
issue : {
|
page : 0,
|
totalPage : 0
|
},
|
project : {
|
page : 0,
|
totalPage : 0
|
}
|
},
|
tab : "VIDEO"
|
};
|
|
angular.extend(this, $controller('autoCompleteController', {$scope : $scope, $injector : $injector}));
|
|
// 이슈 autocomplete page 업데이트
|
function getIssueListCallBack(result) {
|
$scope.vm.autoCompletePage.issue.totalPage = result.data.page.totalPage;
|
}
|
|
$scope.$on("projectListEvent", function (event, result) {
|
$scope.vm.form.projects = result;
|
$scope.vm.form.issues = "";
|
$scope.fn.getIssueTypes();
|
});
|
|
// 이슈 유형 목록
|
function getIssueTypes() {
|
if (!$rootScope.isDefined($scope.vm.form.projects[0])) {
|
return;
|
}
|
IssueType.find($resourceProvider.getContent({projectId : $scope.vm.form.projects[0].id},
|
$resourceProvider.getPageContent(0, 1000))).then(function (result) {
|
|
if (result.data.message.status === "success") {
|
$scope.vm.issueTypes = result.data.data;
|
|
// 현재 이슈타입 유형 설정
|
let currentIssueTypeId = $rootScope.getCurrentIssueTypeId();
|
if (currentIssueTypeId != null) {
|
$scope.vm.form.issueTypeId = currentIssueTypeId.toString();
|
}
|
|
// option 빈값 방지
|
if ($rootScope.isDefined($scope.vm.issueTypes) && $scope.vm.issueTypes.length > 0) {
|
let chk = 0;
|
angular.forEach($scope.vm.issueTypes, function (issueType) {
|
if (issueType.id.toString() === $scope.vm.form.issueTypeId.toString()) {
|
chk ++;
|
}
|
});
|
if (chk === 0) {
|
$scope.vm.form.issueTypeId = null;
|
}
|
}
|
}
|
else {
|
SweetAlert.error($filter("translate")("issue.failedToIssueTypeListLookup"), result.data.message.message); // "이슈 타입 목록 조회 실패"
|
}
|
});
|
}
|
|
// 선택한 조건을 json 으로 만든다.
|
function makeSearchConditions() {
|
return {
|
projectId : (function () {
|
var projectId = "";
|
|
angular.forEach($scope.vm.form.projects, function (project) {
|
projectId = project.id;
|
});
|
|
return projectId;
|
})(),
|
issueTypeId : $scope.vm.form.issueTypeId
|
};
|
}
|
|
// 파일 업로드
|
function onFileSelect($files) {
|
$scope.vm.form.file = $files;
|
|
if ($files.length > 0) {
|
$scope.vm.form.fileName = $files[0].name;
|
}
|
else {
|
$scope.vm.form.fileName = "";
|
}
|
}
|
|
// 폼 체크
|
function formCheck() {
|
if ($scope.vm.form.projects == null || $scope.vm.form.projects.length === 0) {
|
return false;
|
}
|
|
/*if ($scope.vm.form.issues == null || $scope.vm.form.issues.length === 0) {
|
return false;
|
}*/
|
|
if ($scope.vm.form.file.length < 1) {
|
return true;
|
}
|
|
return false;
|
}
|
|
// 폼 전송
|
function formSubmit() {
|
$rootScope.spinner = true;
|
|
let inheritYn = false;
|
// 하위이슈 등록 & 파트너 정보 상속 일 경우 알림 창
|
if ($rootScope.isDefined($scope.vm.form.issues) && $rootScope.isDefined($scope.vm.form.issues[0])
|
&& $scope.vm.form.issues[0].inheritPartners != null && $scope.vm.form.issues[0].inheritPartners === true) {
|
|
SweetAlert.swal({
|
title : $filter("translate")("issue.addDownIssue"), // 하위 이슈 추가
|
text : $filter("translate")("issue.wantToInheritPartnersOfParentIssue"), // 상위이슈의 파트너 정보(업체/ISP/호스팅)를 적용시키겠습니까?
|
type : "warning",
|
showCancelButton : true,
|
confirmButtonColor : "#DD6B55",
|
confirmButtonText : $filter("translate")("common.ok"), // 네
|
cancelButtonText : $filter("translate")("common.no"), // 아니오
|
closeOnConfirm : false,
|
closeOnCancel : false
|
},
|
function (isConfirm) {
|
if (isConfirm) {
|
inheritYn = true;
|
}
|
SweetAlert.close();
|
|
Issue.importExcel({
|
method : "POST",
|
file : $scope.vm.form.file,
|
// data 속성으로 별도의 데이터 전송
|
fields : {
|
content : {
|
projectId : $scope.vm.form.projects[0].id,
|
issueTypeId : $scope.vm.form.issueTypeId,
|
parentIssueId : (function () {
|
let id = null;
|
if ($rootScope.isDefined($scope.vm.form.issues)) {
|
if ($rootScope.isDefined($scope.vm.form.issues[0])) {
|
id = $scope.vm.form.issues[0].id;
|
}
|
}
|
return id;
|
})(),
|
inheritYn : inheritYn
|
}
|
},
|
fileFormDataName : "file",
|
}).then(function (result) {
|
if (result.data.message.status === "success") {
|
$timeout(function () {
|
SweetAlert.success($filter("translate")("issue.succeededIssueRegistration"), result.data.message.message); // 이슈 등록 성공
|
$scope.fn.cancel();
|
$rootScope.$broadcast("getIssueList");
|
$rootScope.spinner = false;
|
}, 1000);
|
}
|
else {
|
SweetAlert.error($filter("translate")("issue.failedIssueRegistration"), result.data.message.message); // 이슈 등록 실패
|
$rootScope.spinner = false;
|
}
|
});
|
});
|
} else {
|
Issue.importExcel({
|
method : "POST",
|
file : $scope.vm.form.file,
|
// data 속성으로 별도의 데이터 전송
|
fields : {
|
content : {
|
projectId : $scope.vm.form.projects[0].id,
|
issueTypeId : $scope.vm.form.issueTypeId,
|
parentIssueId : (function () {
|
let id = null;
|
if ($rootScope.isDefined($scope.vm.form.issues)) {
|
if ($rootScope.isDefined($scope.vm.form.issues[0])) {
|
id = $scope.vm.form.issues[0].id;
|
}
|
}
|
return id;
|
})(),
|
inheritYn : inheritYn
|
}
|
},
|
fileFormDataName : "file",
|
}).then(function (result) {
|
if (result.data.message.status === "success") {
|
$timeout(function () {
|
SweetAlert.success($filter("translate")("issue.succeededIssueRegistration"), result.data.message.message); // 이슈 등록 성공
|
$scope.fn.cancel();
|
$rootScope.$broadcast("getIssueList");
|
$rootScope.spinner = false;
|
}, 1000);
|
}
|
else {
|
SweetAlert.error($filter("translate")("issue.failedIssueRegistration"), result.data.message.message); // 이슈 등록 실패
|
$rootScope.spinner = false;
|
}
|
});
|
}
|
|
}
|
|
function cancel() {
|
$rootScope.$broadcast("closeLayer"); // 팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정
|
$uibModalInstance.dismiss('cancel');
|
}
|
|
// 최초 실행
|
function startExecute() {
|
// 현재 프로젝트 설정
|
if ($rootScope.workProject != null && $rootScope.workProject.id > -1) {
|
$scope.vm.projectName = $rootScope.workProject.name;
|
$scope.vm.form.projects = [];
|
$scope.vm.form.projects.push($rootScope.workProject);
|
}
|
$scope.fn.getIssueTypes();
|
}
|
|
$scope.fn.startExecute();
|
}]);
|
});
|