1
1
import {
2
2
IJupyterCadDoc ,
3
- IJupyterCadDocChange ,
3
+ IJupyterCadModel ,
4
4
IJupyterCadTracker
5
5
} from '@jupytercad/schema' ;
6
6
import { ISignal , Signal } from '@lumino/signaling' ;
@@ -12,15 +12,23 @@ import {
12
12
ISessionModel ,
13
13
requestDocSession
14
14
} from '@jupyter/docprovider' ;
15
+ import { ICollaborativeDrive } from '@jupyter/collaborative-drive' ;
15
16
16
17
export class SuggestionModel {
17
18
constructor ( options : SuggestionModel . IOptions ) {
18
- const { tracker, forkManager, filePath, sharedModel } = options ;
19
+ const {
20
+ tracker,
21
+ forkManager,
22
+ filePath,
23
+ jupytercadModel,
24
+ collaborativeDrive
25
+ } = options ;
19
26
this . _tracker = tracker ;
20
27
this . _forkManager = forkManager ;
28
+ this . _drive = collaborativeDrive ;
21
29
this . switchContext ( {
22
30
filePath,
23
- sharedModel
31
+ jupytercadModel
24
32
} ) ;
25
33
this . _tracker ;
26
34
this . _forkManager ;
@@ -31,15 +39,6 @@ export class SuggestionModel {
31
39
return pathComponents . length > 1 ? pathComponents [ 1 ] : pathComponents [ 0 ] ;
32
40
}
33
41
34
- set sharedModel ( newSharedModel : IJupyterCadDoc | undefined ) {
35
- this . _sharedModel ?. changed . disconnect ( this . _onStateChanged , this ) ;
36
- this . _sharedModel = newSharedModel ;
37
- this . _sharedModel ?. changed . connect ( this . _onStateChanged . bind ( this ) , this ) ;
38
- }
39
- get sharedModel ( ) : IJupyterCadDoc | undefined {
40
- return this . _sharedModel ;
41
- }
42
-
43
42
get allForks ( ) : IAllForksResponse {
44
43
return this . _allForks ;
45
44
}
@@ -56,18 +55,16 @@ export class SuggestionModel {
56
55
57
56
async switchContext ( context : {
58
57
filePath : string ;
59
- sharedModel : IJupyterCadDoc | undefined ;
58
+ jupytercadModel : IJupyterCadModel | undefined ;
60
59
} ) : Promise < void > {
61
60
this . _filePath = context . filePath ;
62
- this . sharedModel = context . sharedModel ;
61
+ this . _jupytercadModel = context . jupytercadModel ;
63
62
if ( this . _filePath && this . _filePath . length > 0 ) {
64
63
const session = ( this . _currentSession = await requestDocSession (
65
64
'text' ,
66
65
'jcad' ,
67
66
this . _filePath
68
67
) ) ;
69
- console . log ( 'file path' , this . _filePath , session ) ;
70
-
71
68
this . _forkProvider = this . _forkManager . getProvider ( {
72
69
documentPath : this . _filePath ,
73
70
format : session . format ! ,
@@ -103,9 +100,26 @@ export class SuggestionModel {
103
100
}
104
101
105
102
async backToRoot ( ) : Promise < void > {
106
- console . log ( 'restoring' , this . _forkProvider ) ;
107
- if ( this . _forkProvider ) {
108
- await this . _forkProvider ?. reconnect ( ) ;
103
+ this . _jupytercadModel ?. sharedModel . dispose ( ) ;
104
+ if ( this . _drive && this . _currentSession && this . _filePath ) {
105
+ const currentSharedModel = this . _drive . sharedModelFactory . createNew ( {
106
+ path : this . _filePath ,
107
+ format : this . _currentSession . format ,
108
+ contentType : this . _currentSession . type ,
109
+ collaborative : true
110
+ } ) ;
111
+
112
+ if ( currentSharedModel ) {
113
+ this . _jupytercadModel ?. swapSharedModel (
114
+ currentSharedModel as IJupyterCadDoc
115
+ ) ;
116
+ }
117
+ this . _forkProvider = this . _forkManager . getProvider ( {
118
+ documentPath : this . _filePath ,
119
+ format : this . _currentSession . format ! ,
120
+ type : this . _currentSession . type
121
+ } ) ;
122
+ await ( this . _forkProvider as any ) . ready ;
109
123
this . _toggleSplitScreen ( false ) ;
110
124
}
111
125
}
@@ -138,24 +152,7 @@ export class SuggestionModel {
138
152
}
139
153
}
140
154
141
- private _onStateChanged (
142
- sender : IJupyterCadDoc ,
143
- changes : IJupyterCadDocChange
144
- ) {
145
- if ( changes . stateChange ) {
146
- changes . stateChange . forEach ( value => {
147
- if (
148
- value . name === 'document_id' &&
149
- value . newValue &&
150
- value . newValue !== value . oldValue
151
- ) {
152
- // const documentId = value.newValue;
153
- // const allForks = this._forkManager.getAllForks(documentId);
154
- }
155
- } ) ;
156
- }
157
- }
158
- private _sharedModel : IJupyterCadDoc | undefined ;
155
+ private _jupytercadModel : IJupyterCadModel | undefined ;
159
156
private _allForks : IAllForksResponse = { } ;
160
157
private _forksUpdated : Signal < this, void > = new Signal ( this ) ;
161
158
private _forkSwitched : Signal < this, string > = new Signal ( this ) ;
@@ -166,13 +163,15 @@ export class SuggestionModel {
166
163
private _forkManager : IForkManager ;
167
164
private _forkProvider ?: IForkProvider ;
168
165
private _currentSession ?: ISessionModel ;
166
+ private _drive ?: ICollaborativeDrive ;
169
167
}
170
168
171
169
namespace SuggestionModel {
172
170
export interface IOptions {
173
- sharedModel : IJupyterCadDoc | undefined ;
171
+ jupytercadModel : IJupyterCadModel | undefined ;
174
172
filePath : string ;
175
173
tracker : IJupyterCadTracker ;
176
174
forkManager : IForkManager ;
175
+ collaborativeDrive ?: ICollaborativeDrive ;
177
176
}
178
177
}
0 commit comments