@@ -87,7 +87,7 @@ qx.Class.define("osparc.vipMarket.Market", {
8787 } ,
8888
8989 events : {
90- "importMessageSent" : "qx.event.type.Data " ,
90+ "importMessageSent" : "qx.event.type.Event " ,
9191 } ,
9292
9393 properties : {
@@ -100,21 +100,50 @@ qx.Class.define("osparc.vipMarket.Market", {
100100 } ,
101101
102102 members : {
103+ __purchasedCategoryButton : null ,
104+ __purchasedCategoryMarket : null ,
105+
103106 __buildViPMarketPage : function ( marketTabInfo , licensedItems = [ ] ) {
104107 const vipMarketView = new osparc . vipMarket . VipMarket ( licensedItems ) ;
105108 vipMarketView . set ( {
106109 category : marketTabInfo [ "categoryId" ] ,
107110 } ) ;
108111 this . bind ( "openBy" , vipMarketView , "openBy" ) ;
112+ vipMarketView . addListener ( "modelPurchased" , ( ) => this . __repopulatePurchasedCategory ( ) ) ;
109113 vipMarketView . addListener ( "importMessageSent" , ( ) => this . fireEvent ( "importMessageSent" ) ) ;
110114 const page = this . addTab ( marketTabInfo [ "label" ] , marketTabInfo [ "icon" ] , vipMarketView ) ;
111115 page . category = marketTabInfo [ "categoryId" ] ;
112116 if ( page . category === "purchasedModels" ) {
113- page . getChildControl ( "button" ) . setVisibility ( licensedItems . length ? "visible" : "excluded" ) ;
117+ this . __purchasedCategoryMarket = vipMarketView ;
118+ this . __purchasedCategoryButton = page . getChildControl ( "button" ) ;
119+ this . __purchasedCategoryButton . setVisibility ( licensedItems . length ? "visible" : "excluded" ) ;
114120 }
115121 return page ;
116122 } ,
117123
124+ __repopulatePurchasedCategory : function ( ) {
125+ const store = osparc . store . Store . getInstance ( ) ;
126+ const contextWallet = store . getContextWallet ( ) ;
127+ const walletId = contextWallet . getWalletId ( ) ;
128+ const licensedItemsStore = osparc . store . LicensedItems . getInstance ( ) ;
129+ Promise . all ( [
130+ licensedItemsStore . getLicensedItems ( ) ,
131+ licensedItemsStore . getPurchasedLicensedItems ( walletId ) ,
132+ ] )
133+ . then ( values => {
134+ const licensedItems = values [ 0 ] ;
135+ const purchasedItems = values [ 1 ] ;
136+ let items = [ ] ;
137+ licensedItems . forEach ( licensedItem => {
138+ if ( purchasedItems . find ( purchasedItem => purchasedItem [ "licensedItemId" ] === licensedItem [ "licensedItemId" ] ) ) {
139+ items . push ( licensedItem ) ;
140+ }
141+ } ) ;
142+ this . __purchasedCategoryButton . setVisibility ( items . length ? "visible" : "excluded" ) ;
143+ this . __purchasedCategoryMarket . setLicensedItems ( items ) ;
144+ } ) ;
145+ } ,
146+
118147 __openCategory : function ( category ) {
119148 const viewFound = this . getChildControl ( "tabs-view" ) . getChildren ( ) . find ( view => view . category === category ) ;
120149 if ( viewFound ) {
0 commit comments