'use strict';
|
|
define(['app', 'htmlDiff', 'angular'],
|
function (app, htmlDiff, angular) {
|
app.directive('jsHtmlDiff', ['$log', '$rootScope',
|
function ($log, $rootScope) {
|
return {
|
scope : {
|
issueVersion : "="
|
},
|
restrict : 'AE',
|
templateUrl : '/custom_components/js-html-diff/js-html-diff.html',
|
controller : function ($scope, $element, $attrs) {
|
|
$scope.fn = {
|
compareIssue : compareIssue, // 변경 정보를 비교한다.
|
detectModifyAttr : detectModifyAttr, // 변경 사항 감지
|
setFormByIssueTypeCustomFields : setFormByIssueTypeCustomFields, // 사용자 정의 필드 가공
|
setUseValueByIssueTypeCustomFields : setUseValueByIssueTypeCustomFields, // 이슈에서 사용자가 선택한 사용자 정의 필드 값을 입력 폼에 셋팅한다.
|
getTargetIssueVersion : getTargetIssueVersion,
|
init : init // 데이터 초기화
|
};
|
|
$scope.vm = {
|
title : {
|
modify : false,
|
target : "", // 이전 정보
|
result : "", // 비교 정보
|
},
|
description : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
priority : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
severity : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
issueStatus : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
issueType : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
period : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
userVos : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
attachedFileVos : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
customFieldVos : [],
|
};
|
|
$scope.$watch("issueVersion", function (newValue) {
|
if ($rootScope.isDefined(newValue.targetIssueVersionVo)) {
|
var checkList = ["title", "description", "priority", "severity", "issueStatus", "issueType", "period", "userVos", "attachedFileVos", "customFieldVos"];
|
// 데이터 초기화
|
$scope.fn.init();
|
|
angular.forEach(checkList, function (check) {
|
$scope.fn.compareIssue(check);
|
});
|
}
|
});
|
|
// 데이터 초기화
|
function init() {
|
$scope.vm = {
|
title : {
|
modify : false,
|
target : "", // 이전 정보
|
result : "", // 비교 정보
|
},
|
description : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
priority : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
severity : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
issueStatus : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
issueType : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
period : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
userVos : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
attachedFileVos : {
|
modify : false,
|
target : "",
|
result : ""
|
},
|
customFieldVos : [],
|
};
|
}
|
|
// 변경 정보를 비교한다.
|
function compareIssue(attr) {
|
var result = "";
|
var target = "";
|
var next = "";
|
|
switch (attr) {
|
case "title":
|
target = "<span>" + $scope.issueVersion.targetIssueVersionVo.versionHistory.title + "</span>";
|
next = "<span>" + $scope.issueVersion.nextIssueVersionVo.versionHistory.title + "</span>";
|
|
result = htmlDiff(target, next);
|
|
// 변경 사항이 있는지 감지한다.
|
if ($scope.fn.detectModifyAttr(result)) {
|
$scope.vm.title.modify = true;
|
$scope.vm.title.target = target;
|
$scope.vm.title.result = result;
|
}
|
|
break;
|
|
case "description":
|
target = $scope.issueVersion.targetIssueVersionVo.versionHistory.description;
|
next = $scope.issueVersion.nextIssueVersionVo.versionHistory.description;
|
|
// 이미지 추출해서 없애기
|
var imageList = [];
|
|
$($scope.issueVersion.nextIssueVersionVo.versionHistory.description).find("img").each(function () {
|
imageList.push($(this).attr("src"));
|
});
|
|
result = htmlDiff(target, next);
|
|
$(result).find("img").each(function () {
|
var imageCheck = false;
|
var imageFindCount = 0;
|
|
for (var count in imageList) {
|
var imageSrc = imageList[count];
|
|
if (imageSrc === $(this).attr("src") ) {
|
imageCheck = true;
|
imageFindCount = count;
|
break;
|
}
|
}
|
|
if (!imageCheck) {
|
result = result.replace($(this)[0].outerHTML, "");
|
}
|
else {
|
imageList.splice(imageFindCount, 1);
|
}
|
});
|
|
// 변경 사항이 있는지 감지한다.
|
if ($scope.fn.detectModifyAttr(result) || !(target === next)) {
|
$scope.vm.description.modify = true;
|
$scope.vm.description.target = target;
|
$scope.vm.description.result = result;
|
}
|
|
break;
|
|
case "priority":
|
target = "<span>" + $scope.issueVersion.targetIssueVersionVo.versionHistory.priorityVo.name + "</span>";
|
next = "<span>" + $scope.issueVersion.nextIssueVersionVo.versionHistory.priorityVo.name + "</span>";
|
|
result = htmlDiff(target, next);
|
|
// 변경 사항이 있는지 감지한다.
|
if ($scope.fn.detectModifyAttr(result)) {
|
$scope.vm.priority.modify = true;
|
$scope.vm.priority.target = target;
|
$scope.vm.priority.result = result;
|
}
|
|
break;
|
|
case "severity":
|
target = "<span>" + $scope.issueVersion.targetIssueVersionVo.versionHistory.severityVo.name + "</span>";
|
next = "<span>" + $scope.issueVersion.nextIssueVersionVo.versionHistory.severityVo.name + "</span>";
|
|
result = htmlDiff(target, next);
|
|
// 변경 사항이 있는지 감지한다.
|
if ($scope.fn.detectModifyAttr(result)) {
|
$scope.vm.severity.modify = true;
|
$scope.vm.severity.target = target;
|
$scope.vm.severity.result = result;
|
}
|
|
break;
|
|
case "issueStatus":
|
target = "<span>" + $scope.issueVersion.targetIssueVersionVo.versionHistory.issueStatusVo.name + "</span>";
|
next = "<span>" + $scope.issueVersion.nextIssueVersionVo.versionHistory.issueStatusVo.name + "</span>";
|
|
result = htmlDiff(target, next);
|
|
// 변경 사항이 있는지 감지한다.
|
if ($scope.fn.detectModifyAttr(result)) {
|
$scope.vm.issueStatus.modify = true;
|
$scope.vm.issueStatus.target = target;
|
$scope.vm.issueStatus.result = result;
|
}
|
|
break;
|
|
case "issueType":
|
target = "<span>" + $scope.issueVersion.targetIssueVersionVo.versionHistory.issueTypeVo.name + "</span>";
|
next = "<span>" + $scope.issueVersion.nextIssueVersionVo.versionHistory.issueTypeVo.name + "</span>";
|
|
result = htmlDiff(target, next);
|
|
// 변경 사항이 있는지 감지한다.
|
if ($scope.fn.detectModifyAttr(result)) {
|
$scope.vm.issueType.modify = true;
|
$scope.vm.issueType.target = target;
|
$scope.vm.issueType.result = result;
|
}
|
|
break;
|
|
case "period":
|
if ($rootScope.isDefined($scope.issueVersion.targetIssueVersionVo.versionHistory.completeDate)) {
|
target = "<span>" + $scope.issueVersion.targetIssueVersionVo.versionHistory.startDate + " ~ ";
|
target += $scope.issueVersion.targetIssueVersionVo.versionHistory.completeDate + "</span>";
|
}
|
|
if ($rootScope.isDefined($scope.issueVersion.nextIssueVersionVo.versionHistory.completeDate)) {
|
next = "<span>" + $scope.issueVersion.nextIssueVersionVo.versionHistory.startDate + " ~ ";
|
next += $scope.issueVersion.nextIssueVersionVo.versionHistory.completeDate + "</span>";
|
}
|
|
result = htmlDiff(target, next);
|
|
// 변경 사항이 있는지 감지한다.
|
if ($scope.fn.detectModifyAttr(result)) {
|
$scope.vm.period.modify = true;
|
$scope.vm.period.target = target;
|
$scope.vm.period.result = result;
|
}
|
|
break;
|
|
case "userVos":
|
// 이름 순으로 정렬
|
$scope.issueVersion.targetIssueVersionVo.versionHistory.userVos.sort(function (a, b) {
|
return a.name < b.name ? -1 : (a.name > b.name) ? 1: 0;
|
});
|
|
angular.forEach($scope.issueVersion.targetIssueVersionVo.versionHistory.userVos, function (userVo, index) {
|
if (index > 0) {
|
target += "<br>";
|
}
|
|
/*target += "<span>" + userVo.name + "</span>";*/
|
|
target += "<span>" + userVo.name + "(" + userVo.account + ")</span>";
|
});
|
|
// 이름 순으로 정렬
|
$scope.issueVersion.nextIssueVersionVo.versionHistory.userVos = $scope.issueVersion.nextIssueVersionVo.versionHistory.userVos.sort(function (a, b) {
|
return a.name < b.name ? -1 : (a.name > b.name) ? 1: 0;
|
});
|
|
angular.forEach($scope.issueVersion.nextIssueVersionVo.versionHistory.userVos, function (userVo, index) {
|
if (index > 0) {
|
next += "<br>";
|
}
|
|
/*next += "<span>" + userVo.name + "</span>";*/
|
next += "<span>" + userVo.name + "(" + userVo.account + ")</span>";
|
});
|
|
result = htmlDiff(target, next);
|
|
// 변경 사항이 있는지 감지한다.
|
if ($scope.fn.detectModifyAttr(result)) {
|
$scope.vm.userVos.modify = true;
|
$scope.vm.userVos.target = target;
|
$scope.vm.userVos.result = result;
|
}
|
|
break;
|
|
case "attachedFileVos" :
|
angular.forEach($scope.issueVersion.targetIssueVersionVo.versionHistory.attachedFileVos, function (attachedFileVo, index) {
|
if (index > 0) {
|
target += "<br>";
|
}
|
|
target += "<span>" + attachedFileVo.name + "</span>";
|
});
|
|
angular.forEach($scope.issueVersion.nextIssueVersionVo.versionHistory.attachedFileVos, function (attachedFileVo, index) {
|
if (index > 0) {
|
next += "<br>";
|
}
|
|
next += "<span>" + attachedFileVo.name + "</span>";
|
});
|
|
result = htmlDiff(target, next);
|
|
// 변경 사항이 있는지 감지한다.
|
if ($scope.fn.detectModifyAttr(result)) {
|
$scope.vm.attachedFileVos.modify = true;
|
$scope.vm.attachedFileVos.target = target;
|
$scope.vm.attachedFileVos.result = result;
|
}
|
|
break;
|
|
case "customFieldVos":
|
var totalCustomFieldObjects = $scope.issueVersion.targetIssueVersionVo.versionHistory.issueTypeCustomFieldVos.concat($scope.issueVersion.nextIssueVersionVo.versionHistory.issueTypeCustomFieldVos);
|
var customFieldObjects = [];
|
|
for (var totalCustomFieldCount in totalCustomFieldObjects) {
|
var totalCustomFieldObject = totalCustomFieldObjects[totalCustomFieldCount];
|
|
var exist = false;
|
|
for (var customFieldCount in customFieldObjects) {
|
var customFieldObject = customFieldObjects[customFieldCount];
|
|
if (customFieldObject.customFieldVo.id === totalCustomFieldObject.customFieldVo.id) {
|
exist = true;
|
break;
|
}
|
}
|
|
if (!exist) {
|
customFieldObjects.push(totalCustomFieldObject);
|
}
|
}
|
|
// 사용자 정의 필드 가공
|
$scope.fn.setFormByIssueTypeCustomFields(customFieldObjects);
|
// 이슈에서 사용자가 선택한 사용자 정의 필드 값을 입력 폼에 셋팅한다. - 이전
|
$scope.fn.setUseValueByIssueTypeCustomFields($scope.issueVersion.targetIssueVersionVo.versionHistory.issueCustomFieldValueVos, "target");
|
// 이슈에서 사용자가 선택한 사용자 정의 필드 값을 입력 폼에 셋팅한다. - 현재
|
$scope.fn.setUseValueByIssueTypeCustomFields($scope.issueVersion.nextIssueVersionVo.versionHistory.issueCustomFieldValueVos, "next");
|
|
angular.forEach($scope.vm.customFieldVos, function (customFieldVo) {
|
result = htmlDiff(customFieldVo.target, customFieldVo.next);
|
|
// 변경 사항이 있는지 감지한다.
|
if ($scope.fn.detectModifyAttr(result)) {
|
customFieldVo.modify = true;
|
customFieldVo.result = result;
|
}
|
});
|
|
|
break;
|
}
|
}
|
|
// 변경 사항이 있는지 감지한다.
|
function detectModifyAttr(result) {
|
// del, ins
|
return (result.match(/del/g) || result.match(/ins/g));
|
}
|
|
// 사용자 정의 필드 가공
|
function setFormByIssueTypeCustomFields(issueTypeCustomFields) {
|
$scope.vm.customFieldVos = [];
|
|
angular.forEach(issueTypeCustomFields, function (issueTypeCustomField) {
|
// 표시 여부 결정
|
issueTypeCustomField.modify = false;
|
|
switch (issueTypeCustomField.customFieldVo.customFieldType) {
|
case "INPUT" :
|
case "SINGLE_SELECT" :
|
issueTypeCustomField.target = "";
|
issueTypeCustomField.next = "";
|
break;
|
|
case "MULTI_SELECT" :
|
issueTypeCustomField.target = [];
|
issueTypeCustomField.next = [];
|
break;
|
}
|
|
$scope.vm.customFieldVos.push(issueTypeCustomField);
|
});
|
}
|
|
// 이슈에서 사용자가 선택한 사용자 정의 필드 값을 입력 폼에 셋팅한다. - 이전/현재
|
function setUseValueByIssueTypeCustomFields(issueCustomFieldValues, setType) {
|
|
angular.forEach(issueCustomFieldValues, function (issueCustomFieldValue) {
|
for (var count in $scope.vm.customFieldVos) {
|
var issueCustomField = $scope.vm.customFieldVos[count];
|
|
if (issueCustomField.customFieldVo.id === issueCustomFieldValue.customFieldVo.id) {
|
switch (setType) {
|
case "target" :
|
// 멀티셀렉트 일때
|
if (angular.isArray(issueCustomField.target)) {
|
issueCustomField.target += "<span>" + issueCustomFieldValue.useValue + "</span>";
|
}
|
else {
|
issueCustomField.target = "<span>" + issueCustomFieldValue.useValue + "</span>";
|
}
|
break;
|
case "next" :
|
// 멀티셀렉트 일때
|
if (angular.isArray(issueCustomField.next)) {
|
issueCustomField.next += "<span>" + issueCustomFieldValue.useValue + "</span>";
|
}
|
else {
|
issueCustomField.next = "<span>" + issueCustomFieldValue.useValue + "</span>";
|
}
|
break;
|
}
|
|
break;
|
}
|
}
|
});
|
}
|
|
function getTargetIssueVersion(id) {
|
$rootScope.$broadcast("getIssueVersion", {id : id});
|
}
|
},
|
link : function (scope, element, attrs) {
|
|
}
|
};
|
}])
|
});
|