Skip to content

Commit

Permalink
Dashboard: Add ?fullscreen=force GET parameter for tablet mode (#1883)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles authored Sep 28, 2023
1 parent e223e3f commit 3760147
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 28 deletions.
12 changes: 12 additions & 0 deletions front/src/actions/dashboard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function createActions(store) {
const actions = {
setFullScreen(state, fullScreen) {
store.setState({
fullScreen
});
}
};
return actions;
}

export default createActions;
24 changes: 13 additions & 11 deletions front/src/routes/dashboard/DashboardPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ const DashboardPage = ({ children, ...props }) => (
</div>

<div class="page-options d-flex align-content-between flex-wrap">
{!props.dashboardNotConfigured && props.browserFullScreenCompatible && (
<button onClick={props.toggleFullScreen} class={cx('btn btn-outline-secondary ml-2 btn-sm')}>
<span>
{!props.fullScreen && <Text id="dashboard.enableFullScreen" />}
{props.fullScreen && <Text id="dashboard.disableFullScreen" />}{' '}
{!props.fullScreen && <i class="fe fe-maximize-2" />}
{props.fullScreen && <i class="fe fe-minimize-2" />}
</span>
</button>
)}
{props.currentDashboard && (
{!props.dashboardNotConfigured &&
props.browserFullScreenCompatible &&
!props.hideExitFullScreenButton && (
<button onClick={props.toggleFullScreen} class={cx('btn btn-outline-secondary ml-2 btn-sm')}>
<span>
{!props.fullScreen && <Text id="dashboard.enableFullScreen" />}
{props.fullScreen && <Text id="dashboard.disableFullScreen" />}{' '}
{!props.fullScreen && <i class="fe fe-maximize-2" />}
{props.fullScreen && <i class="fe fe-minimize-2" />}
</span>
</button>
)}
{props.currentDashboard && !props.hideExitFullScreenButton && (
<button onClick={props.editDashboard} class={cx('btn btn-outline-primary ml-2')}>
<span class={style.editDashboardText}>
<Text id="dashboard.editDashboardButton" />
Expand Down
55 changes: 38 additions & 17 deletions front/src/routes/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { route } from 'preact-router';

import DashboardPage from './DashboardPage';
import GatewayAccountExpired from '../../components/gateway/GatewayAccountExpired';
import actions from '../../actions/dashboard';
import get from 'get-value';

class Dashboard extends Component {
Expand Down Expand Up @@ -76,6 +77,16 @@ class Dashboard extends Component {
}
};

checkIfFullScreenParameterIsHere = () => {
if (this.props.fullscreen === 'force') {
try {
this.switchToFullScreen();
} catch (e) {
console.error(e);
}
}
};

init = async () => {
await this.getDashboards();
if (this.state.currentDashboardSelector) {
Expand All @@ -101,26 +112,34 @@ class Dashboard extends Component {
return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement;
};

switchToFullScreen = () => {
if (document.documentElement.requestFullscreen) {
// chrome & firefox
document.documentElement.requestFullscreen();
} else if (document.documentElement.webkitRequestFullscreen) {
// safari
document.documentElement.webkitRequestFullscreen();
}
this.props.setFullScreen(true);
};

exitFullScreen = () => {
if (document.exitFullscreen) {
// chrome & firefox
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
// safari
document.webkitExitFullscreen();
}
this.props.setFullScreen(false);
};

toggleFullScreen = () => {
const isFullScreen = this.isFullScreen();
if (!isFullScreen) {
if (document.documentElement.requestFullscreen) {
// chrome & firefox
document.documentElement.requestFullscreen();
} else if (document.documentElement.webkitRequestFullscreen) {
// safari
document.documentElement.webkitRequestFullscreen();
}
this.props.setFullScreen(true);
this.switchToFullScreen();
} else {
if (document.exitFullscreen) {
// chrome & firefox
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
// safari
document.webkitExitFullscreen();
}
this.props.setFullScreen(false);
this.exitFullScreen();
}
};

Expand Down Expand Up @@ -149,6 +168,7 @@ class Dashboard extends Component {
document.addEventListener('webkitfullscreenchange', this.onFullScreenChange, false);
document.addEventListener('mozfullscreenchange', this.onFullScreenChange, false);
document.addEventListener('click', this.closeDashboardDropdown, true);
this.checkIfFullScreenParameterIsHere();
}

componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -204,9 +224,10 @@ class Dashboard extends Component {
editDashboard={this.editDashboard}
toggleFullScreen={this.toggleFullScreen}
fullScreen={props.fullScreen}
hideExitFullScreenButton={props.fullscreen === 'force'}
/>
);
}
}

export default connect('user,fullScreen,currentUrl,httpClient,gatewayAccountExpired', {})(Dashboard);
export default connect('user,fullScreen,currentUrl,httpClient,gatewayAccountExpired', actions)(Dashboard);

0 comments on commit 3760147

Please sign in to comment.