@@ -25,130 +25,62 @@ qx.Class.define("osparc.study.Conversations", {
2525 construct : function ( studyData ) {
2626 this . base ( arguments ) ;
2727
28- this . __studyData = studyData ;
28+ this . _setLayout ( new qx . ui . layout . VBox ( ) ) ;
2929
30- this . _setLayout ( new qx . ui . layout . VBox ( 10 ) ) ;
31-
32- this . __buildLayout ( ) ;
33-
34- // this.fetchConversations();
35- this . fetchComments ( ) ;
36- } ,
37-
38- statics : {
39- popUpInWindow : function ( studyData ) {
40- const conversations = new osparc . study . Conversations ( studyData ) ;
41- const title = qx . locale . Manager . tr ( "Conversations" ) ;
42- const viewWidth = 600 ;
43- const viewHeight = 700 ;
44- const win = osparc . ui . window . Window . popUpInWindow ( conversations , title , viewWidth , viewHeight ) ;
45- return win ;
46- } ,
30+ this . fetchConversations ( studyData ) ;
4731 } ,
4832
4933 members : {
50- __studyData : null ,
51- __nextRequestParams : null ,
52-
5334 _createChildControlImpl : function ( id ) {
5435 let control ;
5536 switch ( id ) {
56- case "title" :
57- control = new qx . ui . basic . Label ( ) . set ( {
58- value : this . tr ( "0 Comments" )
59- } ) ;
37+ case "loading-button" :
38+ control = new osparc . ui . form . FetchButton ( ) ;
6039 this . _add ( control ) ;
6140 break ;
62- case "comments-list" :
63- control = new qx . ui . container . Composite ( new qx . ui . layout . VBox ( 5 ) ) . set ( {
64- alignY : "middle"
65- } ) ;
41+ case "conversations-layout" :
42+ control = new qx . ui . tabview . TabView ( ) ;
6643 this . _add ( control , {
6744 flex : 1
6845 } ) ;
6946 break ;
70- case "load-more-button" :
71- control = new osparc . ui . form . FetchButton ( this . tr ( "Load more comments..." ) ) ;
72- control . addListener ( "execute" , ( ) => this . fetchComments ( false ) ) ;
73- this . _add ( control ) ;
74- break ;
75- case "add-comment" :
76- if ( osparc . data . model . Study . canIWrite ( this . __studyData [ "accessRights" ] ) ) {
77- control = new osparc . info . CommentAdd ( this . __studyData [ "uuid" ] ) ;
78- control . setPaddingLeft ( 10 ) ;
79- control . addListener ( "commentAdded" , ( ) => this . fetchComments ( ) ) ;
80- this . _add ( control ) ;
81- }
82- break ;
8347 }
8448
8549 return control || this . base ( arguments , id ) ;
8650 } ,
8751
88- __buildLayout : function ( ) {
89- this . getChildControl ( "title" ) ;
90- this . getChildControl ( "comments-list" ) ;
91- this . getChildControl ( "load-more-button" ) ;
92- this . getChildControl ( "add-comment" ) ;
93- } ,
94-
95- fetchConversations : function ( ) {
96- } ,
97-
98- fetchComments : function ( removeComments = true ) {
99- const loadMoreButton = this . getChildControl ( "load-more-button" ) ;
100- loadMoreButton . show ( ) ;
52+ fetchConversations : function ( studyData ) {
53+ const loadMoreButton = this . getChildControl ( "loading-button" ) ;
10154 loadMoreButton . setFetching ( true ) ;
10255
103- if ( removeComments ) {
104- this . getChildControl ( "comments-list" ) . removeAll ( ) ;
105- }
106-
107- this . __getNextRequest ( )
108- . then ( resp => {
109- const comments = resp [ "data" ] ;
110- this . __addComments ( comments ) ;
111- this . __nextRequestParams = resp [ "_links" ] [ "next" ] ;
112- if ( this . __nextRequestParams === null ) {
113- loadMoreButton . exclude ( ) ;
114- }
115- } )
116- . finally ( ( ) => loadMoreButton . setFetching ( false ) ) ;
117- } ,
118-
119- __getNextRequest : function ( ) {
12056 const params = {
12157 url : {
122- studyId : this . __studyData [ "uuid" ] ,
123- conversationId : this . __studyData [ "uuid" ] ,
58+ studyId : studyData [ "uuid" ] ,
12459 offset : 0 ,
125- limit : 40
60+ limit : 42 ,
12661 }
12762 } ;
128- const nextRequestParams = this . __nextRequestParams ;
129- if ( nextRequestParams ) {
130- params . url . offset = nextRequestParams . offset ;
131- params . url . limit = nextRequestParams . limit ;
132- }
133- const options = {
134- resolveWResponse : true
135- } ;
136- return osparc . data . Resources . fetch ( "studyComments" , "getPage" , params , options ) ;
63+ osparc . data . Resources . fetch ( "conversations" , "get" , params )
64+ . then ( conversations => {
65+ const conversationsLayout = this . getChildControl ( "conversations-layout" ) ;
66+ console . log ( "Conversations fetched" , conversations ) ;
67+ if ( conversations . length === 0 ) {
68+ const noConversationTab = new osparc . info . Conversation ( studyData ) ;
69+ noConversationTab . setLabel ( this . tr ( "new 1" ) ) ;
70+ conversationsLayout . add ( noConversationTab ) ;
71+ } else {
72+ conversations . forEach ( conversation => {
73+ const conversationId = conversation [ "id" ] ;
74+ const conversationTab = new osparc . info . Conversation ( studyData , conversationId ) ;
75+ conversationTab . setLabel ( conversation [ "name" ] ) ;
76+ conversationsLayout . add ( conversationTab ) ;
77+ } ) ;
78+ }
79+ } )
80+ . finally ( ( ) => {
81+ loadMoreButton . setFetching ( false ) ;
82+ loadMoreButton . exclude ( ) ;
83+ } ) ;
13784 } ,
138-
139- __addComments : function ( comments ) {
140- const commentsTitle = this . getChildControl ( "title" ) ;
141- if ( comments . length === 1 ) {
142- commentsTitle . setValue ( this . tr ( "1 Comment" ) ) ;
143- } else if ( comments . length > 1 ) {
144- commentsTitle . setValue ( comments . length + this . tr ( " Comments" ) ) ;
145- }
146-
147- const commentsList = this . getChildControl ( "comments-list" ) ;
148- comments . forEach ( comment => {
149- const commentUi = new osparc . info . CommentUI ( comment ) ;
150- commentsList . add ( commentUi ) ;
151- } ) ;
152- }
15385 }
15486} ) ;
0 commit comments