Newer
Older
piotr.kupczyk@id.ethz.ch
committed
import React from 'react'
import autoBind from 'auto-bind'
import Grid from '@src/js/components/common/grid/Grid.jsx'
piotr.kupczyk@id.ethz.ch
committed
import AppController from '@src/js/components/AppController.js'
piotr.kupczyk@id.ethz.ch
committed
import openbis from '@src/js/services/openbis.js'
import ids from '@src/js/common/consts/ids.js'
import logger from '@src/js/common/logger.js'
piotr.kupczyk@id.ethz.ch
committed
export default class GridWithOpenbis extends React.PureComponent {
piotr.kupczyk@id.ethz.ch
committed
constructor(props) {
super(props)
autoBind(this)
piotr.kupczyk@id.ethz.ch
committed
if (props.id === undefined || props.id === null) {
throw new Error('Grid id cannot be null or undefined!')
}
if (props.settingsId === undefined) {
throw new Error('Grid settingsId cannot be undefined!')
piotr.kupczyk@id.ethz.ch
committed
}
}
render() {
piotr.kupczyk@id.ethz.ch
committed
logger.log(logger.DEBUG, 'GridWithOpenbis.render')
piotr.kupczyk@id.ethz.ch
committed
piotr.kupczyk@id.ethz.ch
committed
return (
<Grid
{...this.props}
loadSettings={this.loadSettings}
onSettingsChange={this.onSettingsChange}
onError={this.onError}
piotr.kupczyk@id.ethz.ch
committed
exportXLS={this.exportXLS}
piotr.kupczyk@id.ethz.ch
committed
/>
)
}
piotr.kupczyk@id.ethz.ch
committed
getSettingsId() {
return this.props.settingsId
}
piotr.kupczyk@id.ethz.ch
committed
async loadSettings() {
piotr.kupczyk@id.ethz.ch
committed
const settingsId = this.getSettingsId()
if (!settingsId) {
return null
}
piotr.kupczyk@id.ethz.ch
committed
return await AppController.getInstance().getSetting(settingsId)
piotr.kupczyk@id.ethz.ch
committed
}
async onSettingsChange(settings) {
piotr.kupczyk@id.ethz.ch
committed
const settingsId = this.getSettingsId()
if (!settingsId) {
return
}
piotr.kupczyk@id.ethz.ch
committed
await AppController.getInstance().setSetting(settingsId, settings)
piotr.kupczyk@id.ethz.ch
committed
}
piotr.kupczyk@id.ethz.ch
committed
async onError(error) {
await AppController.getInstance().errorChange(error)
}
piotr.kupczyk@id.ethz.ch
committed
async exportXLS({
piotr.kupczyk@id.ethz.ch
committed
exportedFilePrefix,
exportedIds,
exportedFields,
piotr.kupczyk@id.ethz.ch
committed
exportedReferredMasterData,
exportedImportCompatible
piotr.kupczyk@id.ethz.ch
committed
}) {
piotr.kupczyk@id.ethz.ch
committed
const serviceId = new openbis.CustomASServiceCode(ids.EXPORT_SERVICE)
piotr.kupczyk@id.ethz.ch
committed
piotr.kupczyk@id.ethz.ch
committed
const serviceOptions = new openbis.CustomASServiceExecutionOptions()
serviceOptions.withParameter('method', 'export')
serviceOptions.withParameter('file_name', exportedFilePrefix)
serviceOptions.withParameter('ids', exportedIds)
serviceOptions.withParameter(
'export_referred_master_data',
exportedReferredMasterData
)
serviceOptions.withParameter('export_fields', exportedFields)
piotr.kupczyk@id.ethz.ch
committed
serviceOptions.withParameter('text_formatting', exportedValues)
piotr.kupczyk@id.ethz.ch
committed
serviceOptions.withParameter('compatible_with_import', exportedImportCompatible)
piotr.kupczyk@id.ethz.ch
committed
const sessionToken = AppController.getInstance().getSessionToken()
const exportResult = await openbis.executeService(serviceId, serviceOptions)
return { sessionToken, exportResult }
piotr.kupczyk@id.ethz.ch
committed
}