@@ -25,9 +25,12 @@ class CoNETConnect {
2525 this . connetcError = ko . observable ( - 1 ) ;
2626 this . connectedCoNET = ko . observable ( false ) ;
2727 this . maynotConnectConet = ko . observable ( false ) ;
28- this . mayNotMakeImapConnect = ko . observable ( false ) ;
2928 this . Loading = ko . observable ( false ) ;
3029 this . listenFun = null ;
30+ this . showTryAgain = ko . observable ( false ) ;
31+ this . showSendConnectMail = ko . observable ( false ) ;
32+ this . showNetworkError = ko . observable ( false ) ;
33+ this . infoTextArray = ko . observableArray ( [ ] ) ;
3134 this . keyPairSign = ko . observable ( null ) ;
3235 const self = this ;
3336 if ( ! confirmRisk ) {
@@ -37,52 +40,191 @@ class CoNETConnect {
3740 this . imapConform ( ) ;
3841 this . Loading ( true ) ;
3942 }
40- this . listenFun = ( err , stage ) => {
41- return self . listingConnectStage ( err , stage ) ;
42- } ;
43- _view . connectInformationMessage . socketIo . on ( 'tryConnectCoNETStage' , this . listenFun ) ;
4443 }
4544 listingConnectStage ( err , stage ) {
4645 const self = this ;
4746 this . showConnectCoNETProcess ( true ) ;
48- let processBarCount = 0 ;
49- if ( typeof err === 'number' && err > - 1 ) {
50- this . connectStage ( - 1 ) ;
51- this . ready ( err ) ;
52- return this . connetcError ( err ) ;
47+ /*
48+ if ( typeof err === 'number' && err > -1 ) {
49+ this.connectStage ( -1 )
50+ this.ready ( err )
51+ _view.connectInformationMessage.socketIo.removeListener ( 'tryConnectCoNETStage', this.listenFun )
52+ return this.connetcError ( err )
5353 }
54- if ( stage === 4 ) {
55- this . showConnectCoNETProcess ( false ) ;
56- this . connectedCoNET ( true ) ;
57- processBarCount = 67 ;
58- if ( ! this . isKeypairBeSign ) {
59- if ( ! this . keyPairSign ( ) ) {
60- let u = null ;
61- return this . keyPairSign ( u = new keyPairSign ( ( function ( ) {
62- self . keyPairSign ( u = null ) ;
63- self . ready ( null ) ;
64- } ) ) ) ;
54+ */
55+ switch ( stage ) {
56+ case 1 : {
57+ const index = this . infoTextArray ( ) [ this . infoTextArray ( ) . length - 1 ] ;
58+ if ( ! index ) {
59+ return ;
6560 }
66- return ;
61+ index . text ( 'connectedMailServer' ) ;
62+ return index . err ( false ) ;
63+ }
64+ /**
65+ * waiting pong
66+ */
67+ case 2 : {
68+ return this . infoTextArray . push ( { text : ko . observable ( 'waitingPong' ) , err : ko . observable ( null ) } ) ;
69+ }
70+ /**
71+ * sendConnectRequestMail
72+ */
73+ case 3 : {
74+ return this . infoTextArray . push ( { text : ko . observable ( 'sendConnectRequestMail' ) , err : ko . observable ( null ) } ) ;
75+ }
76+ /**
77+ * timeOut error!
78+ */
79+ case 0 : {
80+ self . Loading ( false ) ;
81+ self . showSendConnectMail ( true ) ;
82+ return self . infoTextArray . push ( { text : ko . observable ( 'timeOut' ) , err : ko . observable ( true ) } ) ;
83+ }
84+ /**
85+ * connected node
86+ */
87+ case 4 : {
88+ this . Loading ( false ) ;
89+ this . showConnectCoNETProcess ( false ) ;
90+ this . connectedCoNET ( true ) ;
91+ _view . connectInformationMessage . socketIo . removeListener ( 'tryConnectCoNETStage' , this . listenFun ) ;
92+ if ( ! this . isKeypairBeSign ) {
93+ if ( ! this . keyPairSign ( ) ) {
94+ let u = null ;
95+ return this . keyPairSign ( u = new keyPairSign ( ( function ( ) {
96+ self . keyPairSign ( u = null ) ;
97+ self . ready ( null ) ;
98+ } ) ) ) ;
99+ }
100+ return ;
101+ }
102+ _view . showIconBar ( true ) ;
103+ return this . ready ( null ) ;
104+ }
105+ /**
106+ * connectToMailServer
107+ */
108+ case 5 : {
109+ return this . infoTextArray . push ( { text : ko . observable ( 'connectToMailServer' ) , err : ko . observable ( null ) } ) ;
110+ }
111+ /**
112+ * Client error!
113+ */
114+ case - 1 : {
115+ this . Loading ( false ) ;
116+ _view . connectInformationMessage . socketIo . removeListener ( 'tryConnectCoNETStage' , this . listenFun ) ;
117+ return this . infoTextArray . push ( { text : ko . observable ( 'systemError' ) , err : ko . observable ( true ) } ) ;
118+ }
119+ /**
120+ * network error!
121+ */
122+ case - 2 : {
123+ this . Loading ( false ) ;
124+ this . showNetworkError ( true ) ;
125+ return this . infoTextArray . push ( { text : ko . observable ( 'offline' ) , err : ko . observable ( true ) } ) ;
67126 }
68- _view . showIconBar ( true ) ;
69- return this . ready ( null ) ;
70- }
71- $ ( '.keyPairProcessBar' ) . progress ( {
72- percent : processBarCount += 33
73- } ) ;
74- if ( this . connectStage ( ) === 3 ) {
75- return ;
76127 }
77- return this . connectStage ( stage ) ;
78128 }
79129 returnToImapSetup ( ) {
80130 return this . ready ( 0 ) ;
81131 }
132+ sendConnectMail ( ) {
133+ this . Loading ( true ) ;
134+ this . showTryAgain ( false ) ;
135+ _view . connectInformationMessage . sockEmit ( 'sendRequestMail' , err => {
136+ if ( err ) {
137+ return this . listingConnectStage ( null , - 1 ) ;
138+ }
139+ } ) ;
140+ }
141+ tryAgain ( ) {
142+ this . resetAll ( ) ;
143+ this . infoTextArray ( [ ] ) ;
144+ return this . imapConform ( ) ;
145+ }
146+ resetAll ( ) {
147+ this . showNetworkError ( false ) ;
148+ this . showSendConnectMail ( false ) ;
149+ this . showSendImapDataWarning ( false ) ;
150+ this . showTryAgain ( false ) ;
151+ }
82152 imapConform ( ) {
153+ const self = this ;
83154 this . showSendImapDataWarning ( false ) ;
84155 this . connetcError ( - 1 ) ;
85156 this . Loading ( true ) ;
86- return _view . connectInformationMessage . sockEmit ( 'tryConnectCoNET' ) ;
157+ //return this.test ()
158+ this . listenFun = ( err , stage ) => {
159+ return self . listingConnectStage ( err , stage ) ;
160+ } ;
161+ _view . connectInformationMessage . socketIo . on ( 'tryConnectCoNETStage' , this . listenFun ) ;
162+ _view . connectInformationMessage . sockEmit ( 'tryConnectCoNET' , err => {
163+ if ( err ) {
164+ return this . listingConnectStage ( null , - 1 ) ;
165+ }
166+ } ) ;
167+ }
168+ /**
169+ * test unit
170+ */
171+ test ( ) {
172+ /**
173+ * localServerError
174+ */
175+ /*
176+ this.listingConnectStage ( null, 5 )
177+ setTimeout (() => {
178+ this.listingConnectStage ( null, -1 )
179+ }, 3000 )
180+ /** */
181+ /**
182+ * connect to mail server error
183+ */
184+ /*
185+ this.listingConnectStage ( null, 5 )
186+ setTimeout (() => {
187+ this.listingConnectStage ( null, -2 )
188+ }, 3000 )
189+ /** */
190+ /**
191+ * waiting pong
192+ */
193+ /*
194+ this.listingConnectStage ( null, 5 )
195+ setTimeout (() => {
196+ this.listingConnectStage ( null, 1 )
197+ this.listingConnectStage ( null, 2 )
198+ }, 3000 )
199+ /** */
200+ /**
201+ * waiting pong error automatic send request mail
202+ */
203+ /*
204+ this.listingConnectStage ( null, 5 )
205+ setTimeout (() => {
206+ this.listingConnectStage ( null, 1 )
207+ this.listingConnectStage ( null, 2 )
208+ setTimeout (() => {
209+ this.listingConnectStage ( null, 3 )
210+ })
211+ }, 3000 )
212+ /** */
213+ /**
214+ * waiting pong error automatic send request mail and timeout error
215+ */
216+ /*
217+ this.listingConnectStage ( null, 5 )
218+ setTimeout (() => {
219+ this.listingConnectStage ( null, 1 )
220+ this.listingConnectStage ( null, 2 )
221+ setTimeout (() => {
222+ this.listingConnectStage ( null, 3 )
223+ setTimeout (() => {
224+ this.listingConnectStage ( null, 0 )
225+ }, 2000 )
226+ })
227+ }, 3000 )
228+ /** */
87229 }
88230}
0 commit comments