Skip to content

Commit

Permalink
Merge pull request #1446 from rszwajko/consoleOptions
Browse files Browse the repository at this point in the history
Console options
  • Loading branch information
sgratch authored Jun 22, 2021
2 parents 7655599 + e516986 commit 017b592
Show file tree
Hide file tree
Showing 14 changed files with 386 additions and 58 deletions.
23 changes: 22 additions & 1 deletion src/actions/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,22 @@ export function loadUserOptions (userOptions: RemoteUserOptionsType): LoadUserOp
}
}

export function saveGlobalOptions ({ values: { sshKey, language, showNotifications, notificationSnoozeDuration, refreshInterval, persistLocale } = {} }: Object, { transactionId }: Object): SaveGlobalOptionsActionType {
export function saveGlobalOptions ({
values: {
sshKey,
language,
persistLocale,
showNotifications,
notificationSnoozeDuration,
refreshInterval,
preferredConsole,
fullScreenVnc,
ctrlAltEndVnc,
fullScreenSpice,
ctrlAltEndSpice,
smartcardSpice,
} = {},
}: Object, { transactionId }: Object): SaveGlobalOptionsActionType {
return {
type: C.SAVE_GLOBAL_OPTIONS,
payload: {
Expand All @@ -82,6 +97,12 @@ export function saveGlobalOptions ({ values: { sshKey, language, showNotificatio
showNotifications,
notificationSnoozeDuration,
refreshInterval,
preferredConsole,
fullScreenVnc,
ctrlAltEndVnc,
fullScreenSpice,
ctrlAltEndSpice,
smartcardSpice,
},
meta: {
transactionId,
Expand Down
8 changes: 7 additions & 1 deletion src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ export type SaveGlobalOptionsActionType = {
persistLocale?: boolean,
showNotifications?: boolean,
notificationSnoozeDuration?: number,
sshKey?: string
sshKey?: string,
preferredConsole?: string,
fullScreenVnc?: boolean,
ctrlAltEndVnc?: boolean,
fullScreenSpice?: boolean,
ctrlAltEndSpice?: boolean,
smartcardSpice?: boolean
|},
meta: {|
transactionId: string
Expand Down
13 changes: 8 additions & 5 deletions src/components/Settings/SettingsBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ Section.propTypes = {
}

const SettingsBase = ({ name, section }) => {
const sections = section.sections ? Object.entries(section.sections) : [[name, section]]
return (
<div className={style['search-content-box']}>
<Card key={name} className={style['main-content']}>
<div className={style['main-content-container']}>
<Section name={name} section={section} />
</div>
</Card>
{ sections.map(([name, section]) =>
<Card key={name} className={style['main-content']}>
<div className={style['main-content-container']}>
<Section name={name} section={section} />
</div>
</Card>
)}
</div>
)
}
Expand Down
190 changes: 174 additions & 16 deletions src/components/UserSettings/GlobalSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Settings, SettingsBase } from '../Settings'
import SelectBox from '../SelectBox'
import moment from 'moment'
import AppConfiguration from '_/config'
import { BROWSER_VNC, NATIVE_VNC, SPICE, RDP } from '_/constants/console'

const GENERAL_SECTION = 'general'

Expand Down Expand Up @@ -59,8 +60,30 @@ class GlobalSettings extends Component {
]
}

preferredConsoleList (msg) {
return [
{
id: NATIVE_VNC,
value: msg.vncConsole(),
},
{
id: BROWSER_VNC,
value: msg.vncConsoleBrowser(),
},
{
id: SPICE,
value: msg.spiceConsole(),
},
{
id: RDP,
value: msg.remoteDesktop(),
},
]
}

constructor (props) {
super(props)
const { config } = props
/**
* Typical flow (happy path):
* 1. at the begining:
Expand Down Expand Up @@ -99,6 +122,12 @@ class GlobalSettings extends Component {
refreshInterval: AppConfiguration.schedulerFixedDelayInSeconds,
notificationSnoozeDuration: AppConfiguration.notificationSnoozeDurationInMinutes,
persistLocale: AppConfiguration.persistLocale,
fullScreenVnc: false,
fullScreenSpice: false,
ctrlAltEndVnc: false,
ctrlAltEndSpice: false,
preferredConsole: config.defaultUiConsole,
smartcardSpice: AppConfiguration.smartcardSpice,
},
}
this.handleCancel = this.handleCancel.bind(this)
Expand Down Expand Up @@ -181,22 +210,6 @@ class GlobalSettings extends Component {
</div>
),
}))('language'),
((name) => ({
title: msg.sshKey(),
tooltip: msg.sshKeyTooltip(),
name,
body: (
<div className={style['half-width']}>
<FormControl
id={`${idPrefix}-${name}`}
componentClass='textarea'
onChange={e => onChange(name)(e.target.value)}
value={draftValues[name] || ''}
rows={8}
/>
</div>
),
}))('sshKey'),
],
},
refreshInterval: {
Expand Down Expand Up @@ -255,6 +268,144 @@ class GlobalSettings extends Component {
}))('notificationSnoozeDuration'),
],
},
console: {
title: msg.console(),
fields: [ ],
sections: {
console: {
title: msg.console(),
tooltip: msg.globalSettingsTooltip(),
fields: [],
},
preferredConsole: {
title: '',
fields: [
((name) => ({
title: msg.preferredConsole(),
tooltip: msg.preferredConsoleTooltip(),
name,
body: (
<div className={style['half-width']}>
<SelectBox
id={`${idPrefix}-${name}`}
items={this.preferredConsoleList(msg)
.map(({ id, value }) => ({
id,
value,
isDefault: id === config.defaultUiConsole,
}))
}
selected={draftValues[name]}
onChange={onChange(name)}
/>
</div>
),
}))('preferredConsole'),
],
},
vnc: {
title: msg.vncOptions(),
fields: [
((name) => ({
title: msg.fullScreenMode(),
name,
body: (
<Switch
id={`${idPrefix}-${name}`}
isChecked={draftValues[name]}
onChange={(fullScreen) => {
onChange(name)(fullScreen)
}}
/>
),
}))('fullScreenVnc'),
((name) => ({
title: msg.ctrlAltEnd(),
tooltip: msg.remapCtrlAltDelete(),
name,
body: (
<Switch
id={`${idPrefix}-${name}`}

isChecked={draftValues[name]}
onChange={(ctrlAltEnd) => {
onChange(name)(ctrlAltEnd)
}}
/>
),
}))('ctrlAltEndVnc'),
],
},
spice: {
title: msg.spiceOptions(),
fields: [
((name) => ({
title: msg.fullScreenMode(),
name,
body: (
<Switch
id={`${idPrefix}-${name}`}
isChecked={draftValues[name]}
onChange={(fullScreen) => {
onChange(name)(fullScreen)
}}
/>
),
}))('fullScreenSpice'),
((name) => ({
title: msg.ctrlAltEnd(),
tooltip: msg.remapCtrlAltDelete(),
name,
body: (
<Switch
id={`${idPrefix}-${name}`}
isChecked={draftValues[name]}
onChange={(ctrlAltEnd) => {
onChange(name)(ctrlAltEnd)
}}
/>
),
}))('ctrlAltEndSpice'),
((name) => ({
title: msg.smartcard(),
tooltip: msg.smartcardTooltip(),
name,
body: (
<Switch
id={`${idPrefix}-${name}`}
isChecked={draftValues[name]}
onChange={(smartcard) => {
onChange(name)(smartcard)
}}
/>
),
}))('smartcardSpice'),
],
},
serial: {
title: msg.serialConsoleOptions(),
fields: [
((name) => ({
title: msg.sshKey(),
tooltip: msg.sshKeyTooltip(),
name,
body: (
<div className={style['half-width']}>
<FormControl
id={`${idPrefix}-${name}`}
componentClass='textarea'
onChange={e => onChange(name)(e.target.value)}
value={draftValues[name] || ''}
rows={8}
/>
</div>
),
}))('sshKey'),
],
},
},

},
advancedOptions: {
title: msg.advancedOptions(),
fields: [
Expand Down Expand Up @@ -347,6 +498,7 @@ export default connect(
config: {
userName: config.getIn(['user', 'name']),
email: config.getIn(['user', 'email']),
defaultUiConsole: config.getIn(['defaultUiConsole']),
},
currentValues: {
sshKey: options.getIn(['ssh', 'key']),
Expand All @@ -355,6 +507,12 @@ export default connect(
notificationSnoozeDuration: options.getIn(['localOptions', 'notificationSnoozeDuration']),
refreshInterval: options.getIn(['remoteOptions', 'refreshInterval', 'content']),
persistLocale: options.getIn(['remoteOptions', 'persistLocale', 'content']),
fullScreenVnc: options.getIn(['remoteOptions', 'fullScreenVnc', 'content']),
fullScreenSpice: options.getIn(['remoteOptions', 'fullScreenSpice', 'content']),
ctrlAltEndVnc: options.getIn(['remoteOptions', 'ctrlAltEndVnc', 'content']),
ctrlAltEndSpice: options.getIn(['remoteOptions', 'ctrlAltEndSpice', 'content']),
preferredConsole: options.getIn(['remoteOptions', 'preferredConsole', 'content'], config.getIn(['defaultUiConsole'])),
smartcardSpice: options.getIn(['remoteOptions', 'smartcardSpice', 'content']),
},
lastTransactionId: options.getIn(['lastTransactions', 'global', 'transactionId'], ''),
}),
Expand Down
6 changes: 4 additions & 2 deletions src/components/VmActions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class VmActions extends React.Component {
onSuspend,
onRDP,
msg,
preferredConsole,
} = this.props
const isPoolVm = !!vm.getIn(['pool', 'id'], false)
const isPool = !!pool && !isPoolVm
Expand All @@ -137,7 +138,6 @@ class VmActions extends React.Component {
const vncConsole = vm.get('consoles').find(c => c.get('protocol') === VNC)
const spiceConsole = vm.get('consoles').find(c => c.get('protocol') === SPICE)
const hasRdp = isWindows(vm.getIn(['os', 'type']))
const defaultUiConsole = config.get('defaultUiConsole')
let consoles = []

if (vncConsole) {
Expand Down Expand Up @@ -197,7 +197,7 @@ class VmActions extends React.Component {
}

consoles = consoles
.map(({ uiConsole, ...props }) => ({ ...props, priority: uiConsole === defaultUiConsole ? 1 : 0 }))
.map(({ uiConsole, ...props }) => ({ ...props, priority: uiConsole === preferredConsole ? 1 : 0 }))
.sort((a, b) => b.priority - a.priority)

const actions = [
Expand Down Expand Up @@ -391,13 +391,15 @@ VmActions.propTypes = {
onStartVm: PropTypes.func.isRequired,
onRDP: PropTypes.func.isRequired,
msg: PropTypes.object.isRequired,
preferredConsole: PropTypes.string,
}

export default withRouter(
connect(
(state, { vm }) => ({
isEditable: vm.get('canUserEditVm') && state.clusters.find(cluster => cluster.get('canUserUseCluster')) !== undefined,
config: state.config,
preferredConsole: state.options.getIn(['remoteOptions', 'preferredConsole', 'content'], state.config.get('defaultUiConsole')),
}),
(dispatch, { vm, pool }) => ({
onShutdown: () => dispatch(shutdownVm({ vmId: vm.get('id'), force: false })),
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const AppConfiguration = {
notificationSnoozeDurationInMinutes: 10,
showNotificationsDefault: true,
persistLocale: true,
smartcardSpice: true,

consoleClientResourcesURL: 'https://www.ovirt.org/documentation/admin-guide/virt/console-client-resources/',
cockpitPort: '9090',
Expand All @@ -27,7 +28,7 @@ export const DefaultEngineOptions = Object.seal({
MaxNumOfThreadsPerCpu: 8,
MaxNumOfVmCpusPerArch: `{${DEFAULT_ARCH}=1}`,

SpiceUsbAutoShare: 1,
SpiceUsbAutoShare: true,
getUSBFilter: {},

UserSessionTimeOutInterval: 30,
Expand Down
Loading

0 comments on commit 017b592

Please sign in to comment.