OWL ITS + 탐지시스템(인터넷 진흥원)
jhjang
2021-10-14 b74776268dd3eb2bc57744928d6f7150ffcd4ec2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
'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) {
 
                    }
                };
            }])
    });