@@ -4,6 +4,7 @@ import { GroupsManagerService, RichGroup } from '@perun-web-apps/perun/openapi';
4
4
import { Urns } from '@perun-web-apps/perun/urns' ;
5
5
import { getAttribute } from '@perun-web-apps/perun/utils' ;
6
6
import { NotificatorService } from '@perun-web-apps/perun/services' ;
7
+ import { formatDate } from '@angular/common' ;
7
8
8
9
export type SyncType = 'BASIC' | 'STRUCTURED' ;
9
10
@@ -21,13 +22,11 @@ export class GroupSyncDetailDialogComponent implements OnInit {
21
22
theme : string ;
22
23
loading = true ;
23
24
group : RichGroup ;
24
- private syncEnabled : string ;
25
- private lastSyncState : string ;
26
- private lastSyncTime : string ;
27
- private structSyncEnabled : boolean ;
28
- private lastStructSyncState : string ;
29
- private lastStructSyncTime : string ;
30
- private type : SyncType ;
25
+ syncInterval = '' ;
26
+ syncState = '' ;
27
+ syncTime = '' ;
28
+ syncType = '' ;
29
+ type : SyncType ;
31
30
32
31
constructor (
33
32
public dialogRef : MatDialogRef < GroupSyncDetailDialogComponent > ,
@@ -41,79 +40,29 @@ export class GroupSyncDetailDialogComponent implements OnInit {
41
40
this . loadGroup ( ) ;
42
41
}
43
42
44
- onForceStructure ( ) : void {
45
- this . loading = true ;
46
- this . groupService . forceGroupStructureSynchronization ( this . data . groupId ) . subscribe (
47
- ( ) => {
48
- this . notificator . showSuccess ( 'DIALOGS.GROUP_SYNC_DETAIL.STRUCT_FORCE_SUCCESS' ) ;
49
- this . loading = false ;
50
- } ,
51
- ( ) => ( this . loading = false )
52
- ) ;
53
- }
54
-
55
43
onCancel ( ) : void {
56
44
this . dialogRef . close ( null ) ;
57
45
}
58
46
59
47
onForce ( ) : void {
60
48
this . loading = true ;
61
- if ( this . isBasic ( ) ) {
62
- this . groupService . forceGroupSynchronization ( this . group . id ) . subscribe (
63
- ( ) => {
49
+ if ( this . type === 'BASIC' ) {
50
+ this . groupService . forceGroupSynchronization ( this . group . id ) . subscribe ( {
51
+ next : ( ) => {
64
52
this . notificator . showSuccess ( 'DIALOGS.GROUP_SYNC_DETAIL.FORCE_SUCCESS' ) ;
65
53
this . refresh ( ) ;
66
54
} ,
67
- ( ) => ( this . loading = false )
68
- ) ;
69
- }
70
- if ( this . isStructured ( ) ) {
71
- this . groupService . forceGroupStructureSynchronization ( this . group . id ) . subscribe (
72
- ( ) => {
55
+ error : ( ) => ( this . loading = false ) ,
56
+ } ) ;
57
+ } else {
58
+ this . groupService . forceGroupStructureSynchronization ( this . group . id ) . subscribe ( {
59
+ next : ( ) => {
73
60
this . notificator . showSuccess ( 'DIALOGS.GROUP_SYNC_DETAIL.FORCE_SUCCESS' ) ;
74
61
this . refresh ( ) ;
75
62
} ,
76
- ( ) => ( this . loading = false )
77
- ) ;
78
- }
79
- }
80
-
81
- getSynchronizationType ( ) : string {
82
- if ( this . isBasic ( ) ) {
83
- return 'DIALOGS.GROUP_SYNC_DETAIL.NORMAL_SYNC' ;
84
- }
85
- if ( this . isStructured ( ) ) {
86
- return 'DIALOGS.GROUP_SYNC_DETAIL.STRUCT_SYNC' ;
87
- }
88
- return 'N/A' ;
89
- }
90
-
91
- isBasic ( ) : boolean {
92
- return this . type === 'BASIC' ;
93
- }
94
-
95
- isStructured ( ) : boolean {
96
- return this . type === 'STRUCTURED' ;
97
- }
98
-
99
- getLastSyncState ( ) : string {
100
- if ( this . isBasic ( ) ) {
101
- return this . lastSyncState !== '' ? this . lastSyncState : 'OK' ;
102
- }
103
- if ( this . isStructured ( ) ) {
104
- return this . lastStructSyncState !== '' ? this . lastStructSyncState : 'OK' ;
105
- }
106
- return 'N/A' ;
107
- }
108
-
109
- getLastSyncTime ( ) : string {
110
- if ( this . isBasic ( ) ) {
111
- return this . lastSyncTime ;
112
- }
113
- if ( this . isStructured ( ) ) {
114
- return this . lastStructSyncTime ;
63
+ error : ( ) => ( this . loading = false ) ,
64
+ } ) ;
115
65
}
116
- return 'N/A' ;
117
66
}
118
67
119
68
refresh ( ) : void {
@@ -130,33 +79,45 @@ export class GroupSyncDetailDialogComponent implements OnInit {
130
79
Urns . GROUP_STRUCTURE_SYNC_ENABLED ,
131
80
Urns . GROUP_LAST_STRUCTURE_SYNC_STATE ,
132
81
Urns . GROUP_LAST_STRUCTURE_SYNC_TIMESTAMP ,
82
+ Urns . GROUP_SYNC_INTERVAL ,
133
83
] )
134
84
. subscribe ( ( richGroup ) => {
135
85
this . group = richGroup ;
136
86
137
- this . syncEnabled = getAttribute ( this . group . attributes , Urns . GROUP_SYNC_ENABLED )
87
+ const syncEnabled = getAttribute ( this . group . attributes , Urns . GROUP_SYNC_ENABLED )
138
88
. value as string ;
139
- this . lastSyncState = getAttribute ( this . group . attributes , Urns . GROUP_LAST_SYNC_STATE )
89
+ const lastSyncState = getAttribute ( this . group . attributes , Urns . GROUP_LAST_SYNC_STATE )
140
90
. value as string ;
141
- this . lastSyncTime = getAttribute ( this . group . attributes , Urns . GROUP_LAST_SYNC_TIMESTAMP )
91
+ const lastSyncTime = getAttribute ( this . group . attributes , Urns . GROUP_LAST_SYNC_TIMESTAMP )
142
92
. value as string ;
143
- this . structSyncEnabled = getAttribute (
93
+ const structSyncEnabled = getAttribute (
144
94
this . group . attributes ,
145
95
Urns . GROUP_STRUCTURE_SYNC_ENABLED
146
96
) . value as boolean ;
147
- this . lastStructSyncState = getAttribute (
97
+ const lastStructSyncState = getAttribute (
148
98
this . group . attributes ,
149
99
Urns . GROUP_LAST_STRUCTURE_SYNC_STATE
150
100
) . value as string ;
151
- this . lastStructSyncTime = getAttribute (
101
+ const lastStructSyncTime = getAttribute (
152
102
this . group . attributes ,
153
103
Urns . GROUP_LAST_STRUCTURE_SYNC_TIMESTAMP
154
104
) . value as string ;
155
- if ( this . syncEnabled !== null && this . syncEnabled === 'true' ) {
105
+ const syncInterval = getAttribute ( this . group . attributes , Urns . GROUP_SYNC_INTERVAL )
106
+ . value as string ;
107
+ // value is in chunks of 5 minutes
108
+ this . syncInterval = syncInterval === null ? 'N/A' : ( + syncInterval * 5 ) . toString ( ) ;
109
+
110
+ if ( syncEnabled !== null && syncEnabled === 'true' ) {
156
111
this . type = 'BASIC' ;
112
+ this . syncType = 'DIALOGS.GROUP_SYNC_DETAIL.NORMAL_SYNC' ;
113
+ this . syncState = lastSyncState !== '' ? lastSyncState : 'OK' ;
114
+ this . syncTime = formatDate ( lastSyncTime , 'YYYY-MM-dd H:mm:ss' , 'en' ) ;
157
115
}
158
- if ( this . structSyncEnabled !== null && this . structSyncEnabled ) {
116
+ if ( structSyncEnabled !== null && structSyncEnabled ) {
159
117
this . type = 'STRUCTURED' ;
118
+ this . syncType = 'DIALOGS.GROUP_SYNC_DETAIL.STRUCT_SYNC' ;
119
+ this . syncState = lastStructSyncState !== '' ? lastStructSyncState : 'OK' ;
120
+ this . syncTime = formatDate ( lastStructSyncTime , 'YYYY-MM-dd H:mm:ss' , 'en' ) ;
160
121
}
161
122
this . loading = false ;
162
123
} ) ;
0 commit comments