@@ -109,32 +109,40 @@ qx.Class.define("osparc.desktop.credits.RentalsTableModel", {
109109 const lastRow = Math . min ( qxLastRow , this . _rowCount - 1 )
110110 // Returns a request promise with given offset and limit
111111 const getFetchPromise = ( offset , limit = this . self ( ) . SERVER_MAX_LIMIT ) => {
112- return osparc . data . Resources . fetch ( "wallets" , "purchases" , {
113- url : {
114- walletId : this . getWalletId ( ) ,
115- limit,
116- offset,
117- filters : this . getFilters ( ) ?
118- JSON . stringify ( {
119- "started_at" : this . getFilters ( )
120- } ) :
121- null ,
122- orderBy : JSON . stringify ( this . getOrderBy ( ) )
123- }
124- } )
125- . then ( rawData => {
126- const data = [ ]
112+ return Promise . all ( [
113+ osparc . data . Resources . get ( "licensedItems" ) ,
114+ osparc . data . Resources . fetch ( "wallets" , "purchases" , {
115+ url : {
116+ walletId : this . getWalletId ( ) ,
117+ limit,
118+ offset,
119+ filters : this . getFilters ( ) ?
120+ JSON . stringify ( {
121+ "started_at" : this . getFilters ( )
122+ } ) :
123+ null ,
124+ orderBy : JSON . stringify ( this . getOrderBy ( ) )
125+ }
126+ } ) ,
127+ ] )
128+ . then ( values => {
129+ const licensedItems = values [ 0 ] ;
130+ const purchasesItems = values [ 1 ] ;
131+
132+ const data = [ ] ;
127133 const rentalsCols = osparc . desktop . credits . RentalsTable . COLS ;
128- rawData . forEach ( rawRow => {
134+ purchasesItems . forEach ( purchasesItem => {
135+ const licensedItemId = purchasesItem [ "licensedItemId" ] ;
136+ const licensedItem = licensedItems . find ( licItem => licItem [ "licensedItemId" ] === licensedItemId ) ;
129137 data . push ( {
130- [ rentalsCols . PURCHASE_ID . id ] : rawRow [ "licensedItemPurchaseId" ] ,
131- [ rentalsCols . ITEM_ID . id ] : rawRow [ " licensedItemId" ] ,
132- [ rentalsCols . ITEM_LABEL . id ] : "Hello ",
133- [ rentalsCols . START . id ] : osparc . utils . Utils . formatDateAndTime ( new Date ( rawRow [ "startAt" ] ) ) ,
134- [ rentalsCols . END . id ] : osparc . utils . Utils . formatDateAndTime ( new Date ( rawRow [ "expireAt" ] ) ) ,
135- [ rentalsCols . SEATS . id ] : rawRow [ "numOfSeats" ] ,
136- [ rentalsCols . COST . id ] : rawRow [ "pricingUnitCost" ] ? parseFloat ( rawRow [ "pricingUnitCost" ] ) . toFixed ( 2 ) : "" ,
137- [ rentalsCols . USER . id ] : rawRow [ "purchasedByUser" ] ,
138+ [ rentalsCols . PURCHASE_ID . id ] : purchasesItem [ "licensedItemPurchaseId" ] ,
139+ [ rentalsCols . ITEM_ID . id ] : licensedItemId ,
140+ [ rentalsCols . ITEM_LABEL . id ] : licensedItem ? licensedItem [ "name" ] : "unknown model ",
141+ [ rentalsCols . START . id ] : osparc . utils . Utils . formatDateAndTime ( new Date ( purchasesItem [ "startAt" ] ) ) ,
142+ [ rentalsCols . END . id ] : osparc . utils . Utils . formatDateAndTime ( new Date ( purchasesItem [ "expireAt" ] ) ) ,
143+ [ rentalsCols . SEATS . id ] : purchasesItem [ "numOfSeats" ] ,
144+ [ rentalsCols . COST . id ] : purchasesItem [ "pricingUnitCost" ] ? parseFloat ( purchasesItem [ "pricingUnitCost" ] ) . toFixed ( 2 ) : "" ,
145+ [ rentalsCols . USER . id ] : purchasesItem [ "purchasedByUser" ] ,
138146 } )
139147 } )
140148 return data ;
0 commit comments