Skip to content

Commit

Permalink
RocketChat#752 [NEW] Меню для раздела и пункта, перемещение разделов …
Browse files Browse the repository at this point in the history
…и пунктов
  • Loading branch information
shedoev committed Nov 10, 2020
1 parent a7e578c commit 6977b45
Show file tree
Hide file tree
Showing 11 changed files with 429 additions and 402 deletions.
34 changes: 32 additions & 2 deletions app/models/server/models/Protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ class Protocols extends Base {
sectionData._id = _id;

const data = this.findOne({ _id: protocolId });
data.sections = data.sections ? [...data.sections, sectionData] : [sectionData];

if (data.sections) {
let internalNum = 0;
data.sections.forEach((section) => {
if (section.inum > internalNum) {
internalNum = section.inum;
}
})
internalNum++;
sectionData.inum = internalNum;
data.sections = [...data.sections, sectionData];
} else {
sectionData.inum = 1;
data.sections = [sectionData];
}

data._updatedAt = new Date();
this.update({ _id: protocolId }, { $set: { ...data } });

Expand Down Expand Up @@ -73,7 +88,22 @@ class Protocols extends Base {

data.sections.forEach((section) => {
if (section._id === sectionId) {
section.items = section.items ? [...section.items, item] : [item];

if (section.items) {
let internalNum = 0;
section.items.forEach((item) => {
if (item.inum > internalNum) {
internalNum = item.inum;
}
})
internalNum++;
item.inum = internalNum;
section.items = [...section.items, item];
} else {
item.inum = 1;
section.items = [item];
}

}
});

Expand Down
66 changes: 0 additions & 66 deletions app/protocols/client/views/EditItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import {
Button,
ButtonGroup,
Field,
Icon,
Skeleton,
Throbber,
InputBox,
TextInput,
Modal
} from '@rocket.chat/fuselage';
import DatePicker, { registerLocale } from 'react-datepicker';
import ru from 'date-fns/locale/ru';
Expand All @@ -24,50 +22,10 @@ import { useMethod } from '../../../../client/contexts/ServerContext';
import { useToastMessageDispatch } from '../../../../client/contexts/ToastMessagesContext';
import { useEndpointDataExperimental, ENDPOINT_STATES } from '../../../../client/hooks/useEndpointDataExperimental';
import { validateItemData, createItemData } from './lib';
import { useSetModal } from '../../../../client/contexts/ModalContext';
import VerticalBar from '../../../../client/components/basic/VerticalBar';

require('react-datepicker/dist/react-datepicker.css');

const DeleteWarningModal = ({ onDelete, onCancel, ...props }) => {
const t = useTranslation();
return <Modal {...props}>
<Modal.Header>
<Icon color='danger' name='modal-warning' size={20}/>
<Modal.Title>{t('Are_you_sure')}</Modal.Title>
<Modal.Close onClick={onCancel}/>
</Modal.Header>
<Modal.Content fontScale='p1'>
{t('Item_Delete_Warning')}
</Modal.Content>
<Modal.Footer>
<ButtonGroup align='end'>
<Button ghost onClick={onCancel}>{t('Cancel')}</Button>
<Button primary danger onClick={onDelete}>{t('Delete')}</Button>
</ButtonGroup>
</Modal.Footer>
</Modal>;
};

const SuccessModal = ({ onClose, ...props }) => {
const t = useTranslation();
return <Modal {...props}>
<Modal.Header>
<Icon color='success' name='checkmark-circled' size={20}/>
<Modal.Title>{t('Deleted')}</Modal.Title>
<Modal.Close onClick={onClose}/>
</Modal.Header>
<Modal.Content fontScale='p1'>
{t('Item_Has_Been_Deleted')}
</Modal.Content>
<Modal.Footer>
<ButtonGroup align='end'>
<Button primary onClick={onClose}>{t('Ok')}</Button>
</ButtonGroup>
</Modal.Footer>
</Modal>;
};

export function EditItem({ protocolId, sectionId, _id, cache, onChange, ...props }) {
const query = useMemo(() => ({
query: JSON.stringify({ _id: protocolId }),
Expand All @@ -89,9 +47,6 @@ export function EditItem({ protocolId, sectionId, _id, cache, onChange, ...props
<Button disabled><Throbber inheritColor/></Button>
<Button primary disabled><Throbber inheritColor/></Button>
</ButtonGroup>
<ButtonGroup stretch w='full' mbs='x8'>
<Button primary danger disabled><Throbber inheritColor/></Button>
</ButtonGroup>
</Box>;
}

Expand All @@ -115,7 +70,6 @@ function EditItemWithData({ close, onChange, protocol, sectionId, itemId, ...pro
const [name, setName] = useState('');
const [responsible, setResponsible] = useState('');
const [expireAt, setExpireAt] = useState('');
const setModal = useSetModal();

useEffect(() => {
setNumber(previousNumber || '');
Expand All @@ -124,7 +78,6 @@ function EditItemWithData({ close, onChange, protocol, sectionId, itemId, ...pro
setExpireAt(previousExpireAt ? new Date(previousExpireAt) : '');
}, [previousNumber, previousName, previousResponsible, previousExpireAt, _id]);

const deleteItem = useMethod('deleteItem');
const insertOrUpdateItem = useMethod('insertOrUpdateItem');

const hasUnsavedChanges = useMemo(() => previousNumber !== number || previousName !== name || previousResponsible !== responsible || previousExpireAt !== expireAt,
Expand All @@ -144,18 +97,6 @@ function EditItemWithData({ close, onChange, protocol, sectionId, itemId, ...pro
onChange();
}, [saveAction, onChange]);

const onDeleteConfirm = useCallback(async () => {
try {
await deleteItem(protocol._id, sectionId, _id);
setModal(() => <SuccessModal onClose={() => { setModal(undefined); close(); onChange(); }}/>);
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
onChange();
}
}, [_id, close, deleteItem, dispatchToastMessage, onChange]);

const openConfirmDelete = () => setModal(() => <DeleteWarningModal onDelete={onDeleteConfirm} onCancel={() => setModal(undefined)}/>);

return <VerticalBar.ScrollableContent {...props}>
<Field>
<Field.Label>{t('Item_Number')}</Field.Label>
Expand Down Expand Up @@ -206,12 +147,5 @@ function EditItemWithData({ close, onChange, protocol, sectionId, itemId, ...pro
</ButtonGroup>
</Field.Row>
</Field>
<Field>
<Field.Row>
<ButtonGroup stretch w='full'>
<Button primary danger onClick={openConfirmDelete}><Icon name='trash' mie='x4'/>{t('Delete')}</Button>
</ButtonGroup>
</Field.Row>
</Field>
</VerticalBar.ScrollableContent>;
}
66 changes: 0 additions & 66 deletions app/protocols/client/views/EditSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import {
Button,
ButtonGroup,
Field,
Icon,
Skeleton,
Throbber,
InputBox,
Modal
} from '@rocket.chat/fuselage';
import CKEditor from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
Expand All @@ -19,50 +17,10 @@ import { useMethod } from '../../../../client/contexts/ServerContext';
import { useToastMessageDispatch } from '../../../../client/contexts/ToastMessagesContext';
import { useEndpointDataExperimental, ENDPOINT_STATES } from '../../../../client/hooks/useEndpointDataExperimental';
import { validateSectionData, createSectionData } from './lib';
import { useSetModal } from '../../../../client/contexts/ModalContext';
import VerticalBar from '../../../../client/components/basic/VerticalBar';

require('react-datepicker/dist/react-datepicker.css');

const DeleteWarningModal = ({ onDelete, onCancel, ...props }) => {
const t = useTranslation();
return <Modal {...props}>
<Modal.Header>
<Icon color='danger' name='modal-warning' size={20}/>
<Modal.Title>{t('Are_you_sure')}</Modal.Title>
<Modal.Close onClick={onCancel}/>
</Modal.Header>
<Modal.Content fontScale='p1'>
{t('Section_Delete_Warning')}
</Modal.Content>
<Modal.Footer>
<ButtonGroup align='end'>
<Button ghost onClick={onCancel}>{t('Cancel')}</Button>
<Button primary danger onClick={onDelete}>{t('Delete')}</Button>
</ButtonGroup>
</Modal.Footer>
</Modal>;
};

const SuccessModal = ({ onClose, ...props }) => {
const t = useTranslation();
return <Modal {...props}>
<Modal.Header>
<Icon color='success' name='checkmark-circled' size={20}/>
<Modal.Title>{t('Deleted')}</Modal.Title>
<Modal.Close onClick={onClose}/>
</Modal.Header>
<Modal.Content fontScale='p1'>
{t('Section_Has_Been_Deleted')}
</Modal.Content>
<Modal.Footer>
<ButtonGroup align='end'>
<Button primary onClick={onClose}>{t('Ok')}</Button>
</ButtonGroup>
</Modal.Footer>
</Modal>;
};

export function EditSection({ protocolId, _id, cache, onChange, ...props }) {
const query = useMemo(() => ({
query: JSON.stringify({ _id: protocolId }),
Expand All @@ -80,9 +38,6 @@ export function EditSection({ protocolId, _id, cache, onChange, ...props }) {
<Button disabled><Throbber inheritColor/></Button>
<Button primary disabled><Throbber inheritColor/></Button>
</ButtonGroup>
<ButtonGroup stretch w='full' mbs='x8'>
<Button primary danger disabled><Throbber inheritColor/></Button>
</ButtonGroup>
</Box>;
}

Expand All @@ -104,14 +59,12 @@ function EditSectionWithData({ close, onChange, protocol, sectionId, ...props })

const [number, setNumber] = useState('');
const [name, setName] = useState('');
const setModal = useSetModal();

useEffect(() => {
setNumber(previousNumber || '');
setName(previousName || '');
}, [previousNumber, previousName, _id]);

const deleteSection = useMethod('deleteSection');
const insertOrUpdateSection = useMethod('insertOrUpdateSection');

const hasUnsavedChanges = useMemo(() => previousNumber !== number || previousName !== name,
Expand All @@ -131,18 +84,6 @@ function EditSectionWithData({ close, onChange, protocol, sectionId, ...props })
onChange();
}, [saveAction, onChange]);

const onDeleteConfirm = useCallback(async () => {
try {
await deleteSection(protocol._id, _id);
setModal(() => <SuccessModal onClose={() => { setModal(undefined); close(); onChange(); }}/>);
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
onChange();
}
}, [_id, close, deleteSection, dispatchToastMessage, onChange]);

const openConfirmDelete = () => setModal(() => <DeleteWarningModal onDelete={onDeleteConfirm} onCancel={() => setModal(undefined)}/>);

return <VerticalBar.ScrollableContent {...props}>
<Field>
<Field.Label>{t('Section_Number')}</Field.Label>
Expand Down Expand Up @@ -175,12 +116,5 @@ function EditSectionWithData({ close, onChange, protocol, sectionId, ...props })
</ButtonGroup>
</Field.Row>
</Field>
<Field>
<Field.Row>
<ButtonGroup stretch w='full'>
<Button primary danger onClick={openConfirmDelete}><Icon name='trash' mie='x4'/>{t('Delete')}</Button>
</ButtonGroup>
</Field.Row>
</Field>
</VerticalBar.ScrollableContent>;
}
Loading

0 comments on commit 6977b45

Please sign in to comment.