2022-10-08 06:52:39 +02:00
|
|
|
/*
|
|
|
|
* Copyright [2021] [wisemapping]
|
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2022-10-22 02:23:32 +02:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2022-10-05 23:54:23 +02:00
|
|
|
import MaterialToolbar from '@mui/material/Toolbar';
|
2022-10-07 07:30:46 +02:00
|
|
|
import MaterialAppBar from '@mui/material/AppBar';
|
2022-10-08 23:52:40 +02:00
|
|
|
import { ToolbarMenuItem } from '../toolbar';
|
2022-10-08 19:12:07 +02:00
|
|
|
import ActionConfig from '../../classes/action/action-config';
|
2022-10-10 06:33:26 +02:00
|
|
|
import Editor from '../../classes/model/editor';
|
|
|
|
import Capability from '../../classes/action/capability';
|
|
|
|
import Tooltip from '@mui/material/Tooltip';
|
|
|
|
import UndoOutlinedIcon from '@mui/icons-material/UndoOutlined';
|
|
|
|
import RedoOutlinedIcon from '@mui/icons-material/RedoOutlined';
|
|
|
|
import RestoreOutlinedIcon from '@mui/icons-material/RestoreOutlined';
|
|
|
|
import SaveOutlinedIcon from '@mui/icons-material/SaveOutlined';
|
|
|
|
import PrintOutlinedIcon from '@mui/icons-material/PrintOutlined';
|
|
|
|
import FileDownloadOutlinedIcon from '@mui/icons-material/FileDownloadOutlined';
|
2022-10-12 06:09:02 +02:00
|
|
|
import StarRateRoundedIcon from '@mui/icons-material/StarRateRounded';
|
2022-10-10 06:33:26 +02:00
|
|
|
import CloudUploadOutlinedIcon from '@mui/icons-material/CloudUploadOutlined';
|
|
|
|
import HelpOutlineOutlinedIcon from '@mui/icons-material/InfoOutlined';
|
|
|
|
import ArrowBackIosNewOutlinedIcon from '@mui/icons-material/ArrowBackIosNewOutlined';
|
|
|
|
import Typography from '@mui/material/Typography';
|
|
|
|
import UndoAndRedo from '../action-widget/button/undo-and-redo';
|
|
|
|
import Button from '@mui/material/Button';
|
|
|
|
import LogoTextBlackSvg from '../../../images/logo-text-black.svg';
|
2022-10-12 06:09:02 +02:00
|
|
|
import IconButton from '@mui/material/IconButton';
|
2022-10-12 06:49:24 +02:00
|
|
|
import { ToolbarActionType } from '../toolbar/ToolbarActionType';
|
2022-10-22 02:23:32 +02:00
|
|
|
import MapInfo from '../../classes/model/map-info';
|
2022-10-23 02:49:46 +02:00
|
|
|
import { useIntl } from 'react-intl';
|
2022-10-05 23:54:23 +02:00
|
|
|
|
2022-10-12 06:09:02 +02:00
|
|
|
interface AppBarProps {
|
2022-10-10 06:33:26 +02:00
|
|
|
model: Editor;
|
2022-10-22 02:23:32 +02:00
|
|
|
mapInfo: MapInfo;
|
2022-10-10 06:33:26 +02:00
|
|
|
capability: Capability;
|
|
|
|
onAction?: (type: ToolbarActionType) => void;
|
|
|
|
accountConfig?;
|
2022-10-12 06:09:02 +02:00
|
|
|
}
|
2022-10-22 02:23:32 +02:00
|
|
|
const appBarDivisor = {
|
|
|
|
render: () => <Typography component="div" sx={{ flexGrow: 1 }} />,
|
|
|
|
};
|
|
|
|
|
2022-10-23 02:49:46 +02:00
|
|
|
const keyTooltip = (msg: string, key: string): string => {
|
|
|
|
const isMac = window.navigator.platform.toUpperCase().indexOf('MAC') >= 0;
|
|
|
|
return `${msg} (${isMac ? '⌘' : 'Ctrl'} + ${key})`;
|
|
|
|
};
|
|
|
|
|
2022-10-22 02:23:32 +02:00
|
|
|
const AppBar = ({ model, mapInfo, capability, onAction, accountConfig }: AppBarProps) => {
|
|
|
|
const [isStarred, setStarred] = useState<undefined | boolean>(undefined);
|
2022-10-23 02:49:46 +02:00
|
|
|
const intl = useIntl();
|
2022-10-12 06:09:02 +02:00
|
|
|
|
2022-10-22 02:23:32 +02:00
|
|
|
const handleStarredOnClick = () => {
|
|
|
|
const newStatus = !isStarred;
|
|
|
|
mapInfo.updateStarred(newStatus).then(() => setStarred(newStatus));
|
2022-10-10 06:33:26 +02:00
|
|
|
};
|
|
|
|
|
2022-10-22 02:23:32 +02:00
|
|
|
useEffect(() => {
|
|
|
|
mapInfo
|
|
|
|
.isStarred()
|
|
|
|
.then((value) => setStarred(value))
|
|
|
|
.catch((e) => {
|
|
|
|
console.error(`Unexpected error loading starred status-> ${e}`);
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const config: ActionConfig[] = [
|
|
|
|
{
|
|
|
|
icon: <ArrowBackIosNewOutlinedIcon />,
|
2022-10-23 02:49:46 +02:00
|
|
|
tooltip: intl.formatMessage({
|
|
|
|
id: 'appbar.back-to-map-list',
|
|
|
|
defaultMessage: 'Back to maps list',
|
|
|
|
}),
|
2022-10-22 02:23:32 +02:00
|
|
|
onClick: () => history.back(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
render: () => <img src={LogoTextBlackSvg} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
render: () => (
|
|
|
|
<Tooltip title={mapInfo.getTitle()}>
|
|
|
|
<Typography
|
|
|
|
className="truncated"
|
|
|
|
variant="body1"
|
|
|
|
component="div"
|
|
|
|
sx={{ marginX: '1.5rem' }}
|
|
|
|
>
|
|
|
|
{mapInfo.getTitle()}
|
|
|
|
</Typography>
|
|
|
|
</Tooltip>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
render: () => (
|
|
|
|
<UndoAndRedo
|
|
|
|
configuration={{
|
|
|
|
icon: <UndoOutlinedIcon />,
|
2022-10-23 02:49:46 +02:00
|
|
|
tooltip: keyTooltip(
|
|
|
|
intl.formatMessage({ id: 'appbar.tooltip-undo', defaultMessage: 'Undo' }),
|
|
|
|
'Z',
|
|
|
|
),
|
2022-10-22 02:23:32 +02:00
|
|
|
onClick: () => designer.undo(),
|
|
|
|
}}
|
|
|
|
disabledCondition={(event) => event.undoSteps > 0}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
visible: !capability.isHidden('undo-changes'),
|
|
|
|
disabled: () => !model?.isMapLoadded(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
render: () => (
|
|
|
|
<UndoAndRedo
|
|
|
|
configuration={{
|
|
|
|
icon: <RedoOutlinedIcon />,
|
2022-10-23 02:49:46 +02:00
|
|
|
tooltip: keyTooltip(
|
|
|
|
intl.formatMessage({ id: 'appbar.tooltip-redo', defaultMessage: 'Redo' }),
|
|
|
|
'Shift + Z',
|
|
|
|
),
|
2022-10-22 02:23:32 +02:00
|
|
|
onClick: () => designer.redo(),
|
|
|
|
}}
|
|
|
|
disabledCondition={(event) => event.redoSteps > 0}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
visible: !capability.isHidden('redo-changes'),
|
|
|
|
disabled: () => !model?.isMapLoadded(),
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
icon: <SaveOutlinedIcon />,
|
|
|
|
onClick: () => {
|
|
|
|
model.save(true);
|
2022-10-10 06:33:26 +02:00
|
|
|
},
|
2022-10-23 02:49:46 +02:00
|
|
|
tooltip: keyTooltip(
|
|
|
|
intl.formatMessage({ id: 'appbar.tooltip-save', defaultMessage: 'Save' }),
|
|
|
|
'S',
|
|
|
|
),
|
2022-10-22 02:23:32 +02:00
|
|
|
visible: !capability.isHidden('save'),
|
|
|
|
disabled: () => !model?.isMapLoadded(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: <RestoreOutlinedIcon />,
|
|
|
|
onClick: () => onAction('history'),
|
2022-10-23 02:49:46 +02:00
|
|
|
tooltip: intl.formatMessage({
|
|
|
|
id: 'appbar.tooltip-history',
|
|
|
|
defaultMessage: 'Changes History',
|
|
|
|
}),
|
2022-10-22 02:23:32 +02:00
|
|
|
visible: !capability.isHidden('history'),
|
|
|
|
},
|
|
|
|
appBarDivisor,
|
|
|
|
{
|
|
|
|
render: () => (
|
2022-10-23 02:49:46 +02:00
|
|
|
<Tooltip
|
|
|
|
title={intl.formatMessage({ id: 'appbar.tooltip-starred', defaultMessage: 'Starred' })}
|
|
|
|
>
|
|
|
|
<IconButton size="small" onClick={handleStarredOnClick}>
|
|
|
|
<StarRateRoundedIcon
|
|
|
|
color="action"
|
|
|
|
style={{
|
|
|
|
color: isStarred ? 'yellow' : 'gray',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
2022-10-22 02:23:32 +02:00
|
|
|
),
|
|
|
|
visible: !capability.isHidden('starred'),
|
|
|
|
disabled: () => isStarred !== undefined,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: <FileDownloadOutlinedIcon />,
|
|
|
|
onClick: () => onAction('export'),
|
2022-10-23 02:49:46 +02:00
|
|
|
tooltip: intl.formatMessage({ id: 'appbar.tooltip-export', defaultMessage: 'Export' }),
|
2022-10-22 02:23:32 +02:00
|
|
|
visible: !capability.isHidden('export'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: <PrintOutlinedIcon />,
|
|
|
|
onClick: () => onAction('print'),
|
2022-10-23 02:49:46 +02:00
|
|
|
tooltip: intl.formatMessage({ id: 'appbar.tooltip-print', defaultMessage: 'Print' }),
|
2022-10-22 02:23:32 +02:00
|
|
|
visible: !capability.isHidden('print'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: <HelpOutlineOutlinedIcon />,
|
|
|
|
onClick: () => onAction('info'),
|
2022-10-23 02:49:46 +02:00
|
|
|
tooltip: intl.formatMessage({ id: 'appbar.tooltip-info', defaultMessage: 'Information' }),
|
2022-10-22 02:23:32 +02:00
|
|
|
visible: !capability.isHidden('info'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: <CloudUploadOutlinedIcon />,
|
|
|
|
onClick: () => onAction('publish'),
|
2022-10-23 02:49:46 +02:00
|
|
|
tooltip: intl.formatMessage({ id: 'appbar.tooltip-publish', defaultMessage: 'Publish' }),
|
2022-10-22 02:23:32 +02:00
|
|
|
visible: !capability.isHidden('publish'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
render: () => (
|
2022-10-23 02:49:46 +02:00
|
|
|
<Tooltip
|
|
|
|
title={intl.formatMessage({
|
|
|
|
id: 'appbar.tooltip-shared',
|
|
|
|
defaultMessage: 'Share for Collaboration',
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<Button variant="contained" onClick={() => onAction('share')}>
|
|
|
|
{intl.formatMessage({ id: 'appbar.shared-button', defaultMessage: 'Share' })}
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
2022-10-22 02:23:32 +02:00
|
|
|
),
|
|
|
|
visible: !capability.isHidden('share'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
render: () => accountConfig,
|
|
|
|
visible: !capability.isHidden('account'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
render: () => (
|
2022-10-23 02:49:46 +02:00
|
|
|
<Tooltip
|
|
|
|
title={intl.formatMessage({ id: 'appbar.tooltip-signup', defaultMessage: 'Sign Up' })}
|
|
|
|
>
|
|
|
|
<Button variant="contained" onClick={() => (window.location.href = '/c/registration')}>
|
|
|
|
{intl.formatMessage({ id: 'appbar.button-signup', defaultMessage: 'Sign Up' })}
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
2022-10-22 02:23:32 +02:00
|
|
|
),
|
|
|
|
visible: !capability.isHidden('sign-up'),
|
|
|
|
},
|
|
|
|
];
|
2022-10-10 06:33:26 +02:00
|
|
|
|
2022-10-05 23:54:23 +02:00
|
|
|
return (
|
2022-10-07 07:30:46 +02:00
|
|
|
<MaterialAppBar
|
2022-10-05 23:54:23 +02:00
|
|
|
role="menubar"
|
|
|
|
position="absolute"
|
|
|
|
color="default"
|
|
|
|
className="material-menubar"
|
|
|
|
sx={{
|
|
|
|
'& MuiButtonBase-root': {
|
|
|
|
marginX: '1rem',
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<MaterialToolbar>
|
2022-10-10 06:33:26 +02:00
|
|
|
{config.map((c, i) => {
|
2022-10-05 23:54:23 +02:00
|
|
|
return <ToolbarMenuItem key={i} configuration={c} />;
|
|
|
|
})}
|
|
|
|
</MaterialToolbar>
|
2022-10-07 07:30:46 +02:00
|
|
|
</MaterialAppBar>
|
2022-10-05 23:54:23 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-10-07 07:30:46 +02:00
|
|
|
export default AppBar;
|