OWL ITS + 탐지시스템(인터넷 진흥원)
wyu
2021-12-05 8e535752d798b9ecfe4d8b6f864f1cd4f989a70e
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
475
476
477
478
479
480
481
482
483
484
485
486
487
'use strict';
 
define(['app',
        'angular'
    ],
    function (app, angular) {
 
        app.controller('commonController', ['$scope', '$rootScope', '$log', 'Auth', '$state', 'User', '$resourceProvider', '$uibModal', 'SweetAlert', 'Workspace', '$translate', '$q',
            '$interval', 'IssueSearch', '$filter', 'Notice', 'Project', 'IssueType',
            function ($scope, $rootScope, $log, Auth, $state, User, $resourceProvider, $uibModal, SweetAlert, Workspace, $translate, $q, $interval, IssueSearch, $filter, Notice, Project, IssueType) {
 
                $scope.fn = {
                    logout: logout,    //  로그아웃
                    startWebSock: startWebSock,    //  웹 소켓 시작
                    changeLastWorkspace: changeLastWorkspace,  //  마지막 접근 업무 공간
                    changeLastProject: changeLastProject, // 프로젝트 변경
                    invite: invite,    //  사용자 초대하기
                    findAllWorkproject: findAllWorkproject,  //  사용자가 참여하는 프로젝트 목록 가져오기
                    addIssue: addIssue, //  이슈 만들기 팝업 표시
                    makeIssueSearch: makeIssueSearch,  //  이슈 번호를 저장한 후 이슈 목록으로 이동한다.
                    disconnectSocket: disconnectSocket,    //  웹 소켓 연결 해제
                    sendMessage: sendMessage,
                    moveMenu : moveMenu,
                    findIssueList : findIssueList,   // 사이드바 이슈 목록 가져오기
                    changeIssueListMenu : changeIssueListMenu,
                    setLastIssueType : setLastIssueType
                };
 
                $scope.vm = {
                    workProject : -1,
                    message: "",
                    workProjectId : -1
                };
 
 
 
                //  시스템에서 특정 이슈로 바로 이동할 수 있도록 해준다.
                $scope.$on("makeIssueSearch", function (event, args) {
                    //  이슈 번호를 저장한 후 이슈 목록으로 이동한다.
                    $scope.fn.makeIssueSearch(args.projectKey, args.issueNumber);
                });
 
                // 이슈 유형 변경시
                $scope.$on("modifyIssueType", function (event, args) {
                    findIssueList($rootScope.workProject != null ? $rootScope.workProject.id : null);
                });
 
                //  프로젝트 목록 화면 새로 고침시
                $scope.$on("getProjectList", function () {
                    findAllWorkproject();
                });
 
                $scope.$on("changedLastProject", function () {
                    if ($rootScope.workProject != null) {
                        $scope.fn.findIssueList($rootScope.workProject.id);
                    }
                });
 
                function setLastIssueType() {
                    if (User != null) {
                        User.updateLastIssueType($resourceProvider.getContent(
                            {lastIssueTypeId: $rootScope.getCurrentIssueTypeId()},
                            $resourceProvider.getPageContent(0, 0))).then(function (result) {
 
                            if (result.data.message.status === "success") {
 
                            }
                        });
                    }
                }
 
                function changeIssueListMenu(issueTypeId, changeProject = true) {
                    $rootScope.issueTypeMenu = null;
                    for (var issueType of $rootScope.workIssueTypes) {
                        if (issueType.id === issueTypeId) {
                            $rootScope.issueTypeMenu = issueType;
                            break;
                        }
                    }
 
                    // sidebar 클릭시 프로젝트 아이디 설정
                    if (changeProject) {
                        $rootScope.changeLastProject($rootScope.issueTypeMenu.projectVo.id, false, false);
 
                        if ($rootScope.issueTypeMenu != null) {
                            moveMenu("issues.list");
                        }
                    }
                    //moveMenu("issues.list");
                    //$rootScope.$broadcast("changeIssueListMenu", $rootScope.issueTypeMenu);
 
                    if ($rootScope.user.lastIssueTypeId !== issueTypeId) {
                        $scope.fn.setLastIssueType(issueTypeId);
                    }
 
                }
 
                function moveMenu(stateName) {
                    if ($state.current.name === stateName) {
                        $state.reload();
                    } else {
                        $state.go(stateName);
                    }
                }
 
                //  메세지 발송
                function sendMessage() {
                    var content = {
                        description : $scope.vm.message,
                        userIds : [1]
                    };
 
                    Notice.send($resourceProvider.getContent(content,
                        $resourceProvider.getPageContent(0, 0))).then(function (result) {
                    });
                }
 
                //  이슈 번호를 저장한 후 이슈 목록으로 이동한다.
                function makeIssueSearch(projectKey, issueNumber) {
                    var combinationIssueNumber = projectKey;
                    if (issueNumber != undefined) {
                        combinationIssueNumber += "-" + issueNumber;
                    }
 
                    var content = {
                        conditions: JSON.stringify({
                            search: {
                                combinationIssueNumber: combinationIssueNumber
                            }
                        })
                    };
 
                    IssueSearch.add($resourceProvider.getContent(content,
                        $resourceProvider.getPageContent(0, 0))).then(function (result) {
 
                        if (result.data.message.status === "success") {
                            moveMenu("issues.list");
                        } else {
                            SweetAlert.error($filter("translate")("issue.failedToSaveFieldConditions"), result.data.message.message); // "검색 필드 조건 저장 실패"
                        }
                    });
                }
 
 
                //  이슈 만들기 팝업 표시
                function addIssue() {
                    $uibModal.open({
                        templateUrl: 'views/issue/issueAdd.html',
                        size: "lg",
                        controller: 'issueAddController',
                        backdrop: 'static'
                    });
                }
 
                //  참여하는 프로젝트 목록 가져오기
                function findAllWorkproject() {
                    var deferred = $q.defer();
 
                    var defaultName = $filter("translate")("common.totalProject");
                    var defaultProject = {id:-1, name: defaultName, customName:"[ "+ defaultName + " ]" };
 
                    $rootScope.projects = [];
                    $rootScope.projects.push(defaultProject);
                    $rootScope.workProject = defaultProject;
 
                    Project.findListWork($resourceProvider.getContent({},
                        $resourceProvider.getPageContent(0, 1000))).then(function (result) {
                        if (result.data.message.status === "success") {
                            var projects = result.data.data;
 
                            if (projects != undefined && projects.length > 0) {
                                // 마지막 사용한 프로젝트 조회
                                var datas = [];
                                datas.push(defaultProject);
                                for (var count in projects) {
                                    var project = projects[count];
                                    datas.push(project);
                                    project.depth = 0;
                                    project.customName = project.name;
                                    setChildren(project, datas, project.depth);
 
                                    if ($rootScope.user.lastProjectId === project.id) {
                                        $rootScope.workProject = project;
                                    }
 
                                    var id = $rootScope.workProject.id === -1 ? null : $rootScope.workProject.id;
                                    $scope.fn.findIssueList(id);
                                }
                                $rootScope.projects = datas;
                            }
 
                            if ($rootScope.user.lastProjectId == null) {
                                $rootScope.user.lastProjectId = -1;
                            }
                        }
                        deferred.resolve(result.data.data);
                    });
 
                    return deferred.promise;
                }
 
                function setChildren(row, datas, depth) {
                    depth++;
                    var childProjects = row.childProjects;
                    if (childProjects != undefined && childProjects.length > 0) {
                        for (var child of childProjects) {
                            child.depth = depth;
                            var space = "";
                            for (var i=0;i<depth;i++) {
                                if (i==depth-1) {
                                    space += "┗\u00A0";
                                } else {
                                    space += "\u00A0\u00A0";
                                }
                            }
                            child.customName = space + child.name;
                            datas.push(child);
 
                            if ($rootScope.user.lastProjectId === child.id) {
                                $rootScope.workProject = child;
                            }
 
                            setChildren(child, datas, depth);
                        }
                    }
                    return datas;
                }
 
 
                //  사용자 초대
                function invite() {
                    $uibModal.open({
                        templateUrl: 'views/userInvite/userInvite.html',
                        size: "md",
                        controller: 'userInviteController',
                        backdrop: 'static'
                    });
                }
 
                //  현재 프로젝트 변경시
 
                // 이슈 유형 목록 가져오기
               function findIssueList(projectId) {
                   //  이슈 타입 목록 검색 조건을 만든다.
                   var conditions = {
                       projectId : projectId > -1 ? projectId : null,
                       useProject : true,
                       deep : "01" //  이슈 유형에 연결된 워크플로우 정보를 찾는다.
                   }
                   IssueType.find($resourceProvider.getContent(conditions,
                       $resourceProvider.getPageContent(0, 100))).then(function (result) {
 
                       if (result.data.message.status === "success") {
                           $rootScope.workIssueTypes = result.data.data;
 
                           if ($rootScope.workIssueTypes != null && $rootScope.workIssueTypes.length > 0) {
                               $rootScope.workIssueTypes.forEach(function (issueType) {
 
                                   var selectIssueTypeId = null;
                                   if (issueType.id === $rootScope.user.lastIssueTypeId) {
                                       selectIssueTypeId = issueType.id;
                                       $scope.fn.changeIssueListMenu(issueType.id, false);
                                       $state.go('dashboards.dashboard');
                                   }
 
                                   if (selectIssueTypeId == null) {
                                       $scope.fn.changeIssueListMenu($rootScope.workIssueTypes[0].id, false);
 
                                   }
                               });
                           }
                           // 대쉬보드로 가는데 프로젝트를 생성하거나 수정해도 걸리는 조건이다.
                           // else {
                           //     $state.go('dashboards.dashboard');
                           // }
                       }
                       else {
                           SweetAlert.error($filter("translate")("managementType.failedToIssueTypeList"), result.data.message.message); // "이슈 유형 목록 조회 실패"
                       }
                   });
               }
 
 
 
                // 프로젝트 변경
                function changeLastProject(projectId) {
                   $rootScope.changeLastProject(projectId);
 
 
                }
 
                //  업무 공간 변경
                function changeLastWorkspace(workspaceId) {
                    User.updateLastWorkspace($resourceProvider.getContent(
                        {lastWorkspaceId: workspaceId},
                        $resourceProvider.getPageContent(0, 0))).then(function (result) {
 
                        if (result.data.message.status === "success") {
                            $rootScope.user = result.data.data;
                            $rootScope.setCurrentIssueTypeId()
                            $state.go($state.current, {}, {reload: true});
 
                            if ($state.current.name === "dashboards.dashboard") {
                                $state.go($state.current, {}, {reload: true});
                            } else {
                                $state.go("dashboards.dashboard");
                            }
                        }
                    });
                }
 
                //  로그아웃
                function logout() {
                    // edit by zenith at 20200801
                    // before set socket connection call disconnection, fire error so catch
                    try {
                        //  웹 소켓 연결 해제
                        $scope.fn.disconnectSocket();
                    } catch(e) {
                        $log.debug("Error disconnectSocket  : ", e);
                    }
                    Auth.logout();
                    $state.go('login');
                }
 
                //  최초 실행 - 사용자 세션 조회시, 10초마다 확인하여 끊겨있으면 다시 연결 시도
                function startWebSock() {
                    $rootScope.webSocket.socket = new SockJS("/owl-socket");
                    $rootScope.webSocket.client = Stomp.over($rootScope.webSocket.socket); //Stomp client 구성
 
 
                    $rootScope.webSocket.client.connect('', '', function (frame) {
                        //  사용자 목록
                        $rootScope.webSocket.client.subscribe('/session/user-list', function (userList) {
                            $rootScope.users = JSON.parse(userList.body);
 
                            if ($scope.$root.$$phase !== '$apply' && $scope.$root.$$phase !== '$digest') {
                                $scope.$apply();
                            }
 
                            if ($rootScope.isDefined($rootScope.webSocket.client)) {
                                $rootScope.webSocket.client.send('/app/session/alive', {}, '');
                            }
 
                            $log.debug("소켓 연결 사용자 정보 : ", $rootScope.users);
                        });
 
                        // 사용자에게 메세지 보내기
                        $rootScope.webSocket.client.subscribe('/user/notification/message', function (notification) {
                            SweetAlert.warning("메세지 전달", notification.body);
                        });
 
                        // 업무 공간 사용자 초과 알림
                        $rootScope.webSocket.client.subscribe('/user/notification/workspace-max-user-excess', function (notification) {
                            var body = JSON.parse(notification.body);
                            SweetAlert.warning($filter("translate")("common.exceedsMaximumUsersWorkspace"), body.message); // "업무 공간 최대 사용자 초과"
                        });
 
                        //  참여 업무 공간 삭제 알림 - 해당 업무 공간를 보고 있을 때
                        $rootScope.webSocket.client.subscribe('/user/notification/workspace-remove', function (notification) {
                            var body = JSON.parse(notification.body);
                            SweetAlert.warning($filter("translate")("common.deleteParticipatingWorkspaceReminder"), body.message); // "참여 업무 공간 삭제 알림"
 
                            $scope.fn.findAllWorkspace().then(function () {
                                //  로그인한 사용자 정보를 초기화해서 변경된 업무 공간 정보로 대시보드 재조회
                                User.updateUserSession({}).then(function (result) {
                                    if (result.data.message.status === "success") {
                                        $rootScope.user = result.data.data;  //  전역으로 사용하는 로그인 사용자 정보.
                                    } else {
                                        SweetAlert.error($filter("translate")("common.failedToUpdateParticipatingSessions"), body.message); // "참여 세션 업데이트 실패"
                                    }
 
                                    //  업무 공간 초기화하여 서버에서 다시 목록 가져오게 하기
                                    if ($state.current.name === "dashboards.dashboard") {
                                        $state.go($state.current, {}, {reload: true});
                                    } else {
                                        $state.go("dashboards.dashboard");
                                    }
                                });
                            });
                        });
 
                        //  참여 업무 공간 비활성화 알림 - 해당 업무 공간를 보고 있을 때
                        $rootScope.webSocket.client.subscribe('/user/notification/workspace-disabled', function (notification) {
                            // edit by zenith at 20200801
                            // direct oug out cause stand alone have just one workspace
                            SweetAlert.warning($filter("translate")("common.disableParticipationWorkspace"), $filter("translate")("common.disableParticipationWorkspaceMessage"));
                            $rootScope.$broadcast("logout");
 
                            /*var body = JSON.parse(notification.body);
                            SweetAlert.warning($filter("translate")("common.disableParticipationWorkspace"), body.message); // "참여 업무 공간 비활성화 알림"
 
                            $scope.fn.findAllWorkspace().then(function () {
                                //  로그인한 사용자 정보를 초기화해서 변경된 업무 공간 정보로 대시보드 재조회
                                User.updateUserSession({}).then(function (result) {
                                    if (result.data.message.status == "success") {
                                        $rootScope.user = result.data.data;  //  전역으로 사용하는 로그인 사용자 정보.
                                    }
                                    else {
                                        SweetAlert.error($filter("translate")("common.failedToUpdateParticipatingSessions"), body.message); // "참여 세션 업데이트 실패"
                                    }
 
                                    //  업무 공간 초기화하여 서버에서 다시 목록 가져오게 하기
                                    if ($state.current.name == "dashboards.dashboard") {
                                        $state.go($state.current, {}, {reload : true});
                                    }
                                    else {
                                        $state.go("dashboards.dashboard");
                                    }
                                });
                            });*/
                        });
 
                        //  참여 업무 공간 제외/추가 될때 업무 공간 업데이트
                        $rootScope.webSocket.client.subscribe('/user/notification/workspace-update', function () {
                            $scope.fn.findAllWorkspace();
                        });
 
                        //  시스템 알림 오류 - ModelAndView 에서 Exception 발생시 페이지 이동이 일어나는 현상을 수정
                        $rootScope.webSocket.client.subscribe('/user/notification/system-alert', function (notification) {
                            var body = JSON.parse(notification.body);
                            SweetAlert.warning($filter("translate")("common.alertsAboutSystem"), body.message); // "시스템 알림 정보"
                        });
 
                        //  참여 업무 공간 제외/추가 될때 업무 공간 업데이트
                        $rootScope.webSocket.client.subscribe('/user/notification/file-upload-process', function (notification) {
                            var body = JSON.parse(notification.body);
 
                            $rootScope.$broadcast("displayFileUpload", body);
                        });
 
                        //  참여 프로젝트 목록 업데이트
                        $rootScope.$broadcast("refreshWorkproject");
                    });
                }
 
                //  웹 소켓 연결 해제
                function disconnectSocket() {
                    if ($rootScope.webSocket.client != null) {
                        $rootScope.webSocket.client.disconnect(function () {
                            $log.debug("소켓 종료");
                        });
                    }
                }
 
 
                //  웹 소켓 시작
                $scope.$on("startSocket", function () {
                    $log.debug("소켓 시작");
                    //  웹 소켓 연결
                    $scope.fn.startWebSock();
                });
 
                //  로그아웃
                $scope.$on("logout", function () {
                    $scope.fn.logout();
                });
 
                //  업무 공간 목록 새로고침
                $scope.$on("refreshWorkspace", function () {
                    $scope.fn.findAllWorkspace();
                });
 
                //  업무 프로젝트 목록 새로고침
                $scope.$on("refreshWorkproject", function () {
                    $scope.fn.findAllWorkproject();
                });
 
 
                //  10초마다 웹 소켓 연결을 확인하는 폴링 이벤트
                $interval(function () {
                    //$log.debug("10초마다 소켓 연결을 확인합니다.");
                    //  로그인한 사용자 정보가 있을 경우
                    if (angular.isDefined($rootScope.user)) {
                        if ($rootScope.user.id != null) {
                            //  만약 웹소켓이 연결되어 있지 않으면 재연결 시도
                            if ($rootScope.webSocket.client == null || !$rootScope.webSocket.client.connected) {
                                $log.debug("소켓 연결이 끊겨 있어 소켓을 연결합니다.");
                                $rootScope.$broadcast("startSocket");
                            }
                        }
                    }
                }, 10000);
            }
        ]);
    }
);