Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad67b9ba24 | ||
|
|
ddf9a32ea9 | ||
|
|
e01a2eafba | ||
|
|
3b3bff1b6b | ||
|
|
ecc45c7a9e | ||
|
|
3497e09703 | ||
|
|
dfc52191fc | ||
|
|
6268ced4cb | ||
|
|
e7495e0067 | ||
|
|
b8c065e0c8 | ||
|
|
86e4864d1b | ||
|
|
0be598ca9e |
Generated
+31
@@ -17,6 +17,7 @@
|
||||
"js-cookie": "^3.0.1",
|
||||
"lodash": "^4.17.20",
|
||||
"node-sass": "^7.0.1",
|
||||
"photoswipe": "^5.2.7",
|
||||
"prop-types": "^15.8.1",
|
||||
"react": "^17.0.2",
|
||||
"react-beautiful-dnd": "^13.0.0",
|
||||
@@ -26,6 +27,7 @@
|
||||
"react-i18next": "^11.16.6",
|
||||
"react-input-mask": "^2.0.4",
|
||||
"react-markdown": "^8.0.2",
|
||||
"react-photoswipe-gallery": "^2.2.1",
|
||||
"react-redux": "^7.2.8",
|
||||
"react-router-dom": "^5.3.1",
|
||||
"react-scripts": "5.0.1",
|
||||
@@ -16224,6 +16226,14 @@
|
||||
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
||||
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
|
||||
},
|
||||
"node_modules/photoswipe": {
|
||||
"version": "5.2.7",
|
||||
"resolved": "https://registry.npmjs.org/photoswipe/-/photoswipe-5.2.7.tgz",
|
||||
"integrity": "sha512-AogMba7W/O5gOtDIZ8cQuou1ltwxlaLNoZY1qi1s+kbYXpZk9D6rXxnNGAfDppl+bfe+sKLW2w2sx+3uQ8oPzg==",
|
||||
"engines": {
|
||||
"node": ">= 0.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/picocolors": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
|
||||
@@ -18230,6 +18240,16 @@
|
||||
"react-dom": "^15.5.x || ^16.x || ^17.x"
|
||||
}
|
||||
},
|
||||
"node_modules/react-photoswipe-gallery": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/react-photoswipe-gallery/-/react-photoswipe-gallery-2.2.1.tgz",
|
||||
"integrity": "sha512-xaUKKmwRLCpEzB8+bU7yxjXvRBHaInpBcI6YQY0UOeFctHAL3jGRDk9j2YbwmlgN7kRStHTcyrSNxr+zSaOnKg==",
|
||||
"peerDependencies": {
|
||||
"photoswipe": ">= 5.2.2",
|
||||
"prop-types": ">= 15.7.0",
|
||||
"react": ">= 16.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-popper": {
|
||||
"version": "2.2.5",
|
||||
"resolved": "https://registry.npmjs.org/react-popper/-/react-popper-2.2.5.tgz",
|
||||
@@ -35010,6 +35030,11 @@
|
||||
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
||||
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
|
||||
},
|
||||
"photoswipe": {
|
||||
"version": "5.2.7",
|
||||
"resolved": "https://registry.npmjs.org/photoswipe/-/photoswipe-5.2.7.tgz",
|
||||
"integrity": "sha512-AogMba7W/O5gOtDIZ8cQuou1ltwxlaLNoZY1qi1s+kbYXpZk9D6rXxnNGAfDppl+bfe+sKLW2w2sx+3uQ8oPzg=="
|
||||
},
|
||||
"picocolors": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
|
||||
@@ -36319,6 +36344,12 @@
|
||||
"integrity": "sha512-a5Q7CkWznBRUWPmocCvE8b6lEYw1s6+opp/60dCunhO+G6E4tDTO2Sd2jKE+leEnnrLAE2Wj5DlDHNqj5wPv1Q==",
|
||||
"requires": {}
|
||||
},
|
||||
"react-photoswipe-gallery": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/react-photoswipe-gallery/-/react-photoswipe-gallery-2.2.1.tgz",
|
||||
"integrity": "sha512-xaUKKmwRLCpEzB8+bU7yxjXvRBHaInpBcI6YQY0UOeFctHAL3jGRDk9j2YbwmlgN7kRStHTcyrSNxr+zSaOnKg==",
|
||||
"requires": {}
|
||||
},
|
||||
"react-popper": {
|
||||
"version": "2.2.5",
|
||||
"resolved": "https://registry.npmjs.org/react-popper/-/react-popper-2.2.5.tgz",
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
"js-cookie": "^3.0.1",
|
||||
"lodash": "^4.17.20",
|
||||
"node-sass": "^7.0.1",
|
||||
"photoswipe": "^5.2.7",
|
||||
"prop-types": "^15.8.1",
|
||||
"react": "^17.0.2",
|
||||
"react-beautiful-dnd": "^13.0.0",
|
||||
@@ -83,6 +84,7 @@
|
||||
"react-i18next": "^11.16.6",
|
||||
"react-input-mask": "^2.0.4",
|
||||
"react-markdown": "^8.0.2",
|
||||
"react-photoswipe-gallery": "^2.2.1",
|
||||
"react-redux": "^7.2.8",
|
||||
"react-router-dom": "^5.3.1",
|
||||
"react-scripts": "5.0.1",
|
||||
|
||||
@@ -29,6 +29,14 @@ export const handleTaskUpdate = (task) => ({
|
||||
},
|
||||
});
|
||||
|
||||
export const moveTask = (id, index) => ({
|
||||
type: EntryActionTypes.TASK_MOVE,
|
||||
payload: {
|
||||
id,
|
||||
index,
|
||||
},
|
||||
});
|
||||
|
||||
export const deleteTask = (id) => ({
|
||||
type: EntryActionTypes.TASK_DELETE,
|
||||
payload: {
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
}
|
||||
|
||||
.wrapper {
|
||||
cursor: auto;
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import classNames from 'classnames';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Gallery, Item as GalleryItem } from 'react-photoswipe-gallery';
|
||||
import { Button } from 'semantic-ui-react';
|
||||
import { useToggle } from '../../../lib/hooks';
|
||||
|
||||
@@ -8,81 +10,152 @@ import Item from './Item';
|
||||
|
||||
import styles from './Attachments.module.scss';
|
||||
|
||||
const Attachments = React.memo(({ items, onUpdate, onDelete, onCoverUpdate }) => {
|
||||
const [t] = useTranslation();
|
||||
const [isOpened, toggleOpened] = useToggle();
|
||||
const INITIALLY_VISIBLE = 4;
|
||||
|
||||
const handleToggleClick = useCallback(() => {
|
||||
toggleOpened();
|
||||
}, [toggleOpened]);
|
||||
const Attachments = React.memo(
|
||||
({ items, onUpdate, onDelete, onCoverUpdate, onGalleryOpen, onGalleryClose }) => {
|
||||
const [t] = useTranslation();
|
||||
const [isAllVisible, toggleAllVisible] = useToggle();
|
||||
|
||||
const handleCoverSelect = useCallback(
|
||||
(id) => {
|
||||
onCoverUpdate(id);
|
||||
},
|
||||
[onCoverUpdate],
|
||||
);
|
||||
const handleCoverSelect = useCallback(
|
||||
(id) => {
|
||||
onCoverUpdate(id);
|
||||
},
|
||||
[onCoverUpdate],
|
||||
);
|
||||
|
||||
const handleCoverDeselect = useCallback(() => {
|
||||
onCoverUpdate(null);
|
||||
}, [onCoverUpdate]);
|
||||
const handleCoverDeselect = useCallback(() => {
|
||||
onCoverUpdate(null);
|
||||
}, [onCoverUpdate]);
|
||||
|
||||
const handleUpdate = useCallback(
|
||||
(id, data) => {
|
||||
onUpdate(id, data);
|
||||
},
|
||||
[onUpdate],
|
||||
);
|
||||
const handleUpdate = useCallback(
|
||||
(id, data) => {
|
||||
onUpdate(id, data);
|
||||
},
|
||||
[onUpdate],
|
||||
);
|
||||
|
||||
const handleDelete = useCallback(
|
||||
(id) => {
|
||||
onDelete(id);
|
||||
},
|
||||
[onDelete],
|
||||
);
|
||||
const handleDelete = useCallback(
|
||||
(id) => {
|
||||
onDelete(id);
|
||||
},
|
||||
[onDelete],
|
||||
);
|
||||
|
||||
const visibleItems = isOpened ? items : items.slice(0, 4);
|
||||
const handleBeforeGalleryOpen = useCallback(
|
||||
(gallery) => {
|
||||
onGalleryOpen();
|
||||
|
||||
return (
|
||||
<>
|
||||
{visibleItems.map((item) => (
|
||||
<Item
|
||||
gallery.on('destroy', () => {
|
||||
onGalleryClose();
|
||||
});
|
||||
},
|
||||
[onGalleryOpen, onGalleryClose],
|
||||
);
|
||||
|
||||
const handleToggleAllVisibleClick = useCallback(() => {
|
||||
toggleAllVisible();
|
||||
}, [toggleAllVisible]);
|
||||
|
||||
const galleryItemsNode = items.map((item, index) => {
|
||||
const isPdf = item.url && item.url.endsWith('.pdf');
|
||||
|
||||
let props;
|
||||
if (item.image) {
|
||||
props = item.image;
|
||||
} else {
|
||||
props = {
|
||||
content: isPdf ? (
|
||||
// eslint-disable-next-line jsx-a11y/alt-text
|
||||
<object
|
||||
data={item.url}
|
||||
type="application/pdf"
|
||||
className={classNames(styles.content, styles.contentPdf)}
|
||||
/>
|
||||
) : (
|
||||
<span className={classNames(styles.content, styles.contentError)}>
|
||||
{t('common.thereIsNoPreviewAvailableForThisAttachment')}
|
||||
</span>
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
const isVisible = isAllVisible || index < INITIALLY_VISIBLE;
|
||||
|
||||
return (
|
||||
<GalleryItem
|
||||
{...props} // eslint-disable-line react/jsx-props-no-spreading
|
||||
key={item.id}
|
||||
name={item.name}
|
||||
url={item.url}
|
||||
coverUrl={item.coverUrl}
|
||||
createdAt={item.createdAt}
|
||||
isCover={item.isCover}
|
||||
isPersisted={item.isPersisted}
|
||||
onCoverSelect={() => handleCoverSelect(item.id)}
|
||||
onCoverDeselect={handleCoverDeselect}
|
||||
onUpdate={(data) => handleUpdate(item.id, data)}
|
||||
onDelete={() => handleDelete(item.id)}
|
||||
/>
|
||||
))}
|
||||
{items.length > 4 && (
|
||||
<Button
|
||||
fluid
|
||||
content={
|
||||
isOpened
|
||||
? t('action.showFewerAttachments')
|
||||
: t('action.showAllAttachments', {
|
||||
hidden: items.length - visibleItems.length,
|
||||
})
|
||||
original={item.url}
|
||||
caption={item.name}
|
||||
>
|
||||
{({ ref, open }) =>
|
||||
isVisible ? (
|
||||
<Item
|
||||
ref={ref}
|
||||
name={item.name}
|
||||
url={item.url}
|
||||
coverUrl={item.coverUrl}
|
||||
createdAt={item.createdAt}
|
||||
isCover={item.isCover}
|
||||
isPersisted={item.isPersisted}
|
||||
onClick={item.image || isPdf ? open : undefined}
|
||||
onCoverSelect={() => handleCoverSelect(item.id)}
|
||||
onCoverDeselect={handleCoverDeselect}
|
||||
onUpdate={(data) => handleUpdate(item.id, data)}
|
||||
onDelete={() => handleDelete(item.id)}
|
||||
/>
|
||||
) : (
|
||||
<span ref={ref} />
|
||||
)
|
||||
}
|
||||
className={styles.toggleButton}
|
||||
onClick={handleToggleClick}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
});
|
||||
</GalleryItem>
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<Gallery
|
||||
withCaption
|
||||
withDownloadButton
|
||||
options={{
|
||||
showHideAnimationType: 'none',
|
||||
closeTitle: '',
|
||||
zoomTitle: '',
|
||||
arrowPrevTitle: '',
|
||||
arrowNextTitle: '',
|
||||
errorMsg: '',
|
||||
}}
|
||||
onBeforeOpen={handleBeforeGalleryOpen}
|
||||
>
|
||||
{galleryItemsNode}
|
||||
</Gallery>
|
||||
{items.length > INITIALLY_VISIBLE && (
|
||||
<Button
|
||||
fluid
|
||||
content={
|
||||
isAllVisible
|
||||
? t('action.showFewerAttachments')
|
||||
: t('action.showAllAttachments', {
|
||||
hidden: items.length - INITIALLY_VISIBLE,
|
||||
})
|
||||
}
|
||||
className={styles.toggleButton}
|
||||
onClick={handleToggleAllVisibleClick}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Attachments.propTypes = {
|
||||
items: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types
|
||||
onUpdate: PropTypes.func.isRequired,
|
||||
onDelete: PropTypes.func.isRequired,
|
||||
onCoverUpdate: PropTypes.func.isRequired,
|
||||
onGalleryOpen: PropTypes.func.isRequired,
|
||||
onGalleryClose: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export default Attachments;
|
||||
|
||||
@@ -1,4 +1,26 @@
|
||||
:global(#app) {
|
||||
.content {
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
margin: auto;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.contentPdf {
|
||||
height: 100%;
|
||||
width: 1120px;
|
||||
}
|
||||
|
||||
.contentError {
|
||||
color: #fff;
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
height: 20px;
|
||||
width: 470px;
|
||||
}
|
||||
|
||||
.toggleButton {
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
|
||||
@@ -8,24 +8,32 @@ import EditPopup from './EditPopup';
|
||||
|
||||
import styles from './Item.module.scss';
|
||||
|
||||
const Item = React.memo(
|
||||
({
|
||||
name,
|
||||
url,
|
||||
coverUrl,
|
||||
createdAt,
|
||||
isCover,
|
||||
isPersisted,
|
||||
onCoverSelect,
|
||||
onCoverDeselect,
|
||||
onUpdate,
|
||||
onDelete,
|
||||
}) => {
|
||||
const Item = React.forwardRef(
|
||||
(
|
||||
{
|
||||
name,
|
||||
url,
|
||||
coverUrl,
|
||||
createdAt,
|
||||
isCover,
|
||||
isPersisted,
|
||||
onCoverSelect,
|
||||
onCoverDeselect,
|
||||
onClick,
|
||||
onUpdate,
|
||||
onDelete,
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
const [t] = useTranslation();
|
||||
|
||||
const handleClick = useCallback(() => {
|
||||
window.open(url, '_blank');
|
||||
}, [url]);
|
||||
if (onClick) {
|
||||
onClick();
|
||||
} else {
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
}, [url, onClick]);
|
||||
|
||||
const handleToggleCoverClick = useCallback(
|
||||
(event) => {
|
||||
@@ -54,7 +62,7 @@ const Item = React.memo(
|
||||
return (
|
||||
/* eslint-disable jsx-a11y/click-events-have-key-events,
|
||||
jsx-a11y/no-static-element-interactions */
|
||||
<div className={styles.wrapper} onClick={handleClick}>
|
||||
<div ref={ref} className={styles.wrapper} onClick={handleClick}>
|
||||
{/* eslint-enable jsx-a11y/click-events-have-key-events,
|
||||
jsx-a11y/no-static-element-interactions */}
|
||||
<div
|
||||
@@ -133,6 +141,7 @@ Item.propTypes = {
|
||||
createdAt: PropTypes.instanceOf(Date),
|
||||
isCover: PropTypes.bool.isRequired,
|
||||
isPersisted: PropTypes.bool.isRequired,
|
||||
onClick: PropTypes.func,
|
||||
onCoverSelect: PropTypes.func.isRequired,
|
||||
onCoverDeselect: PropTypes.func.isRequired,
|
||||
onUpdate: PropTypes.func.isRequired,
|
||||
@@ -143,6 +152,7 @@ Item.defaultProps = {
|
||||
url: undefined,
|
||||
coverUrl: undefined,
|
||||
createdAt: undefined,
|
||||
onClick: undefined,
|
||||
};
|
||||
|
||||
export default Item;
|
||||
export default React.memo(Item);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import React, { useCallback, useRef } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import classNames from 'classnames';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -61,6 +61,7 @@ const CardModal = React.memo(
|
||||
onLabelDelete,
|
||||
onTaskCreate,
|
||||
onTaskUpdate,
|
||||
onTaskMove,
|
||||
onTaskDelete,
|
||||
onAttachmentCreate,
|
||||
onAttachmentUpdate,
|
||||
@@ -73,6 +74,8 @@ const CardModal = React.memo(
|
||||
}) => {
|
||||
const [t] = useTranslation();
|
||||
|
||||
const isGalleryOpened = useRef(false);
|
||||
|
||||
const handleNameUpdate = useCallback(
|
||||
(newName) => {
|
||||
onUpdate({
|
||||
@@ -124,6 +127,22 @@ const CardModal = React.memo(
|
||||
});
|
||||
}, [isSubscribed, onUpdate]);
|
||||
|
||||
const handleGalleryOpen = useCallback(() => {
|
||||
isGalleryOpened.current = true;
|
||||
}, []);
|
||||
|
||||
const handleGalleryClose = useCallback(() => {
|
||||
isGalleryOpened.current = false;
|
||||
}, []);
|
||||
|
||||
const handleClose = useCallback(() => {
|
||||
if (isGalleryOpened.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
onClose();
|
||||
}, [onClose]);
|
||||
|
||||
const userIds = users.map((user) => user.id);
|
||||
const labelIds = labels.map((label) => label.id);
|
||||
|
||||
@@ -313,6 +332,7 @@ const CardModal = React.memo(
|
||||
canEdit={canEdit}
|
||||
onCreate={onTaskCreate}
|
||||
onUpdate={onTaskUpdate}
|
||||
onMove={onTaskMove}
|
||||
onDelete={onTaskDelete}
|
||||
/>
|
||||
</div>
|
||||
@@ -328,6 +348,8 @@ const CardModal = React.memo(
|
||||
onUpdate={onAttachmentUpdate}
|
||||
onDelete={onAttachmentDelete}
|
||||
onCoverUpdate={handleCoverUpdate}
|
||||
onGalleryOpen={handleGalleryOpen}
|
||||
onGalleryClose={handleGalleryClose}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -445,7 +467,7 @@ const CardModal = React.memo(
|
||||
);
|
||||
|
||||
return (
|
||||
<Modal open closeIcon size="small" centered={false} onClose={onClose}>
|
||||
<Modal open closeIcon size="small" centered={false} onClose={handleClose}>
|
||||
{canEdit ? (
|
||||
<AttachmentAddZone onCreate={onAttachmentCreate}>{contentNode}</AttachmentAddZone>
|
||||
) : (
|
||||
@@ -493,6 +515,7 @@ CardModal.propTypes = {
|
||||
onLabelDelete: PropTypes.func.isRequired,
|
||||
onTaskCreate: PropTypes.func.isRequired,
|
||||
onTaskUpdate: PropTypes.func.isRequired,
|
||||
onTaskMove: PropTypes.func.isRequired,
|
||||
onTaskDelete: PropTypes.func.isRequired,
|
||||
onAttachmentCreate: PropTypes.func.isRequired,
|
||||
onAttachmentUpdate: PropTypes.func.isRequired,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import React, { useCallback, useRef } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import PropTypes from 'prop-types';
|
||||
import classNames from 'classnames';
|
||||
import { Draggable } from 'react-beautiful-dnd';
|
||||
import { Button, Checkbox, Icon } from 'semantic-ui-react';
|
||||
|
||||
import NameEdit from './NameEdit';
|
||||
@@ -8,72 +10,85 @@ import ActionsPopup from './ActionsPopup';
|
||||
|
||||
import styles from './Item.module.scss';
|
||||
|
||||
const Item = React.memo(({ name, isCompleted, isPersisted, canEdit, onUpdate, onDelete }) => {
|
||||
const nameEdit = useRef(null);
|
||||
const Item = React.memo(
|
||||
({ id, index, name, isCompleted, isPersisted, canEdit, onUpdate, onDelete }) => {
|
||||
const nameEdit = useRef(null);
|
||||
|
||||
const handleClick = useCallback(() => {
|
||||
if (isPersisted && canEdit) {
|
||||
nameEdit.current.open();
|
||||
}
|
||||
}, [isPersisted, canEdit]);
|
||||
const handleClick = useCallback(() => {
|
||||
if (isPersisted && canEdit) {
|
||||
nameEdit.current.open();
|
||||
}
|
||||
}, [isPersisted, canEdit]);
|
||||
|
||||
const handleNameUpdate = useCallback(
|
||||
(newName) => {
|
||||
const handleNameUpdate = useCallback(
|
||||
(newName) => {
|
||||
onUpdate({
|
||||
name: newName,
|
||||
});
|
||||
},
|
||||
[onUpdate],
|
||||
);
|
||||
|
||||
const handleToggleChange = useCallback(() => {
|
||||
onUpdate({
|
||||
name: newName,
|
||||
isCompleted: !isCompleted,
|
||||
});
|
||||
},
|
||||
[onUpdate],
|
||||
);
|
||||
}, [isCompleted, onUpdate]);
|
||||
|
||||
const handleToggleChange = useCallback(() => {
|
||||
onUpdate({
|
||||
isCompleted: !isCompleted,
|
||||
});
|
||||
}, [isCompleted, onUpdate]);
|
||||
const handleNameEdit = useCallback(() => {
|
||||
nameEdit.current.open();
|
||||
}, []);
|
||||
|
||||
const handleNameEdit = useCallback(() => {
|
||||
nameEdit.current.open();
|
||||
}, []);
|
||||
return (
|
||||
<Draggable draggableId={id} index={index} isDragDisabled={!isPersisted || !canEdit}>
|
||||
{({ innerRef, draggableProps, dragHandleProps }, { isDragging }) => {
|
||||
const contentNode = (
|
||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||
<div {...draggableProps} {...dragHandleProps} ref={innerRef} className={styles.wrapper}>
|
||||
<span className={styles.checkboxWrapper}>
|
||||
<Checkbox
|
||||
checked={isCompleted}
|
||||
disabled={!isPersisted || !canEdit}
|
||||
className={styles.checkbox}
|
||||
onChange={handleToggleChange}
|
||||
/>
|
||||
</span>
|
||||
<NameEdit ref={nameEdit} defaultValue={name} onUpdate={handleNameUpdate}>
|
||||
<div className={classNames(canEdit && styles.contentHoverable)}>
|
||||
{/* eslint-disable jsx-a11y/click-events-have-key-events,
|
||||
jsx-a11y/no-static-element-interactions */}
|
||||
<span
|
||||
className={classNames(styles.text, canEdit && styles.textEditable)}
|
||||
onClick={handleClick}
|
||||
>
|
||||
{/* eslint-enable jsx-a11y/click-events-have-key-events,
|
||||
jsx-a11y/no-static-element-interactions */}
|
||||
<span className={classNames(styles.task, isCompleted && styles.taskCompleted)}>
|
||||
{name}
|
||||
</span>
|
||||
</span>
|
||||
{isPersisted && canEdit && (
|
||||
<ActionsPopup onNameEdit={handleNameEdit} onDelete={onDelete}>
|
||||
<Button className={classNames(styles.button, styles.target)}>
|
||||
<Icon fitted name="pencil" size="small" />
|
||||
</Button>
|
||||
</ActionsPopup>
|
||||
)}
|
||||
</div>
|
||||
</NameEdit>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={styles.wrapper}>
|
||||
<span className={styles.checkboxWrapper}>
|
||||
<Checkbox
|
||||
checked={isCompleted}
|
||||
disabled={!isPersisted || !canEdit}
|
||||
className={styles.checkbox}
|
||||
onChange={handleToggleChange}
|
||||
/>
|
||||
</span>
|
||||
<NameEdit ref={nameEdit} defaultValue={name} onUpdate={handleNameUpdate}>
|
||||
<div className={classNames(canEdit && styles.contentHoverable)}>
|
||||
{/* eslint-disable jsx-a11y/click-events-have-key-events,
|
||||
jsx-a11y/no-static-element-interactions */}
|
||||
<span
|
||||
className={classNames(styles.text, canEdit && styles.textEditable)}
|
||||
onClick={handleClick}
|
||||
>
|
||||
{/* eslint-enable jsx-a11y/click-events-have-key-events,
|
||||
jsx-a11y/no-static-element-interactions */}
|
||||
<span className={classNames(styles.task, isCompleted && styles.taskCompleted)}>
|
||||
{name}
|
||||
</span>
|
||||
</span>
|
||||
{isPersisted && canEdit && (
|
||||
<ActionsPopup onNameEdit={handleNameEdit} onDelete={onDelete}>
|
||||
<Button className={classNames(styles.button, styles.target)}>
|
||||
<Icon fitted name="pencil" size="small" />
|
||||
</Button>
|
||||
</ActionsPopup>
|
||||
)}
|
||||
</div>
|
||||
</NameEdit>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
return isDragging ? ReactDOM.createPortal(contentNode, document.body) : contentNode;
|
||||
}}
|
||||
</Draggable>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Item.propTypes = {
|
||||
id: PropTypes.string.isRequired,
|
||||
index: PropTypes.number.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
isCompleted: PropTypes.bool.isRequired,
|
||||
isPersisted: PropTypes.bool.isRequired,
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
vertical-align: top;
|
||||
z-index: 2000;
|
||||
line-height: 1;
|
||||
height: 32px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.contentHoverable:hover {
|
||||
@@ -69,10 +69,10 @@
|
||||
|
||||
.wrapper {
|
||||
border-radius: 3px;
|
||||
cursor: auto;
|
||||
margin-left: -40px;
|
||||
min-height: 32px;
|
||||
position: relative;
|
||||
transition: all 0.14s ease-in;
|
||||
width: calc(100% + 40px);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,34 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { DragDropContext, Droppable } from 'react-beautiful-dnd';
|
||||
import { Progress } from 'semantic-ui-react';
|
||||
import { closePopup } from '../../../lib/popup';
|
||||
|
||||
import DroppableTypes from '../../../constants/DroppableTypes';
|
||||
import Item from './Item';
|
||||
import Add from './Add';
|
||||
|
||||
import styles from './Tasks.module.scss';
|
||||
|
||||
const Tasks = React.memo(({ items, canEdit, onCreate, onUpdate, onDelete }) => {
|
||||
const Tasks = React.memo(({ items, canEdit, onCreate, onUpdate, onMove, onDelete }) => {
|
||||
const [t] = useTranslation();
|
||||
|
||||
const handleDragStart = useCallback(() => {
|
||||
closePopup();
|
||||
}, []);
|
||||
|
||||
const handleDragEnd = useCallback(
|
||||
({ draggableId, source, destination }) => {
|
||||
if (!destination || source.index === destination.index) {
|
||||
return;
|
||||
}
|
||||
|
||||
onMove(draggableId, destination.index);
|
||||
},
|
||||
[onMove],
|
||||
);
|
||||
|
||||
const handleUpdate = useCallback(
|
||||
(id, data) => {
|
||||
onUpdate(id, data);
|
||||
@@ -39,26 +57,38 @@ const Tasks = React.memo(({ items, canEdit, onCreate, onUpdate, onDelete }) => {
|
||||
className={styles.progress}
|
||||
/>
|
||||
)}
|
||||
{items.map((item) => (
|
||||
<Item
|
||||
key={item.id}
|
||||
name={item.name}
|
||||
isCompleted={item.isCompleted}
|
||||
isPersisted={item.isPersisted}
|
||||
canEdit={canEdit}
|
||||
onUpdate={(data) => handleUpdate(item.id, data)}
|
||||
onDelete={() => handleDelete(item.id)}
|
||||
/>
|
||||
))}
|
||||
{canEdit && (
|
||||
<Add onCreate={onCreate}>
|
||||
<button type="button" className={styles.taskButton}>
|
||||
<span className={styles.taskButtonText}>
|
||||
{items.length > 0 ? t('action.addAnotherTask') : t('action.addTask')}
|
||||
</span>
|
||||
</button>
|
||||
</Add>
|
||||
)}
|
||||
<DragDropContext onDragStart={handleDragStart} onDragEnd={handleDragEnd}>
|
||||
<Droppable droppableId="tasks" type={DroppableTypes.TASK}>
|
||||
{({ innerRef, droppableProps, placeholder }) => (
|
||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||
<div {...droppableProps} ref={innerRef}>
|
||||
{items.map((item, index) => (
|
||||
<Item
|
||||
key={item.id}
|
||||
id={item.id}
|
||||
index={index}
|
||||
name={item.name}
|
||||
isCompleted={item.isCompleted}
|
||||
isPersisted={item.isPersisted}
|
||||
canEdit={canEdit}
|
||||
onUpdate={(data) => handleUpdate(item.id, data)}
|
||||
onDelete={() => handleDelete(item.id)}
|
||||
/>
|
||||
))}
|
||||
{placeholder}
|
||||
{canEdit && (
|
||||
<Add onCreate={onCreate}>
|
||||
<button type="button" className={styles.taskButton}>
|
||||
<span className={styles.taskButtonText}>
|
||||
{items.length > 0 ? t('action.addAnotherTask') : t('action.addTask')}
|
||||
</span>
|
||||
</button>
|
||||
</Add>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Droppable>
|
||||
</DragDropContext>
|
||||
</>
|
||||
);
|
||||
});
|
||||
@@ -68,6 +98,7 @@ Tasks.propTypes = {
|
||||
canEdit: PropTypes.bool.isRequired,
|
||||
onCreate: PropTypes.func.isRequired,
|
||||
onUpdate: PropTypes.func.isRequired,
|
||||
onMove: PropTypes.func.isRequired,
|
||||
onDelete: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import CoreWrapperContainer from '../containers/CoreWrapperContainer';
|
||||
import NotFound from './NotFound';
|
||||
|
||||
import 'react-datepicker/dist/react-datepicker.css';
|
||||
import 'photoswipe/dist/photoswipe.css';
|
||||
import '../lib/custom-ui/styles.css';
|
||||
|
||||
import '../styles.module.scss';
|
||||
|
||||
@@ -32,7 +32,7 @@ const createData = (timer) => {
|
||||
const TimerEditStep = React.memo(({ defaultValue, onUpdate, onBack, onClose }) => {
|
||||
const [t] = useTranslation();
|
||||
const [data, handleFieldChange, setData] = useForm(() => createData(defaultValue));
|
||||
const [isEditing, toggleEdit] = useToggle();
|
||||
const [isEditing, toggleEditing] = useToggle();
|
||||
|
||||
const hoursField = useRef(null);
|
||||
const minutesField = useRef(null);
|
||||
@@ -55,10 +55,10 @@ const TimerEditStep = React.memo(({ defaultValue, onUpdate, onBack, onClose }) =
|
||||
onClose();
|
||||
}, [defaultValue, onUpdate, onClose]);
|
||||
|
||||
const handleToggleEditClick = useCallback(() => {
|
||||
const handleToggleEditingClick = useCallback(() => {
|
||||
setData(createData(defaultValue));
|
||||
toggleEdit();
|
||||
}, [defaultValue, setData, toggleEdit]);
|
||||
toggleEditing();
|
||||
}, [defaultValue, setData, toggleEditing]);
|
||||
|
||||
const handleSubmit = useCallback(() => {
|
||||
const parts = {
|
||||
@@ -149,7 +149,7 @@ const TimerEditStep = React.memo(({ defaultValue, onUpdate, onBack, onClose }) =
|
||||
type="button"
|
||||
icon={isEditing ? 'close' : 'edit'}
|
||||
className={styles.iconButton}
|
||||
onClick={handleToggleEditClick}
|
||||
onClick={handleToggleEditingClick}
|
||||
/>
|
||||
</div>
|
||||
{isEditing && <Button positive content={t('action.save')} />}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
const BOARD = 'BOARD';
|
||||
const LIST = 'LIST';
|
||||
const CARD = 'CARD';
|
||||
const TASK = 'TASK';
|
||||
|
||||
export default {
|
||||
BOARD,
|
||||
LIST,
|
||||
CARD,
|
||||
TASK,
|
||||
};
|
||||
|
||||
@@ -138,6 +138,7 @@ export default {
|
||||
TASK_CREATE_HANDLE: `${PREFIX}/TASK_CREATE_HANDLE`,
|
||||
TASK_UPDATE: `${PREFIX}/TASK_UPDATE`,
|
||||
TASK_UPDATE_HANDLE: `${PREFIX}/TASK_UPDATE_HANDLE`,
|
||||
TASK_MOVE: `${PREFIX}/TASK_MOVE`,
|
||||
TASK_DELETE: `${PREFIX}/TASK_DELETE`,
|
||||
TASK_DELETE_HANDLE: `${PREFIX}/TASK_DELETE_HANDLE`,
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
fetchActionsInCurrentCard,
|
||||
fetchBoard,
|
||||
moveCurrentCard,
|
||||
moveTask,
|
||||
removeLabelFromCurrentCard,
|
||||
removeUserFromCurrentCard,
|
||||
transferCurrentCard,
|
||||
@@ -111,6 +112,7 @@ const mapDispatchToProps = (dispatch) =>
|
||||
onLabelDelete: deleteLabel,
|
||||
onTaskCreate: createTaskInCurrentCard,
|
||||
onTaskUpdate: updateTask,
|
||||
onTaskMove: moveTask,
|
||||
onTaskDelete: deleteTask,
|
||||
onAttachmentCreate: createAttachmentInCurrentCard,
|
||||
onAttachmentUpdate: updateAttachment,
|
||||
|
||||
@@ -32,14 +32,12 @@ const Markdown = React.memo(({ linkStopPropagation, ...props }) => {
|
||||
}
|
||||
|
||||
return (
|
||||
/* eslint-disable react/jsx-props-no-spreading */
|
||||
<ReactMarkdown
|
||||
{...props}
|
||||
{...props} // eslint-disable-line react/jsx-props-no-spreading
|
||||
components={components}
|
||||
remarkPlugins={[remarkGfm, remarkBreaks]}
|
||||
className="markdown-body"
|
||||
/>
|
||||
/* eslint-enable react/jsx-props-no-spreading */
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -134,6 +134,7 @@ export default {
|
||||
subscribeToMyOwnCardsByDefault: 'Standardmäßig meine eigenen Karten abonnieren',
|
||||
taskActions_title: 'Aufgabenaktionen',
|
||||
tasks: 'Aufgaben',
|
||||
thereIsNoPreviewAvailableForThisAttachment: 'Für diesen Anhang ist keine Vorschau verfügbar',
|
||||
time: 'Zeit',
|
||||
timer: 'Timer',
|
||||
title: 'Titel',
|
||||
|
||||
@@ -127,6 +127,8 @@ export default {
|
||||
subscribeToMyOwnCardsByDefault: 'Subscribe to my own cards by default',
|
||||
taskActions_title: 'Task Actions',
|
||||
tasks: 'Tasks',
|
||||
thereIsNoPreviewAvailableForThisAttachment:
|
||||
'There is no preview available for this attachment',
|
||||
time: 'Time',
|
||||
timer: 'Timer',
|
||||
title: 'Title',
|
||||
|
||||
@@ -122,6 +122,7 @@ export default {
|
||||
subscribeToMyOwnCardsByDefault: 'По умолчанию подписаться на мои собственные карточки',
|
||||
taskActions: 'Действия с задачей',
|
||||
tasks: 'Задачи',
|
||||
thereIsNoPreviewAvailableForThisAttachment: 'Предпросмотр для этого вложения недоступен',
|
||||
time: 'Время',
|
||||
timer: 'Таймер',
|
||||
title: 'Название',
|
||||
|
||||
@@ -9,6 +9,7 @@ export default class extends Model {
|
||||
id: attr(),
|
||||
url: attr(),
|
||||
coverUrl: attr(),
|
||||
image: attr(),
|
||||
name: attr(),
|
||||
cardId: fk({
|
||||
to: 'Card',
|
||||
|
||||
@@ -206,7 +206,7 @@ export default class extends Model {
|
||||
}
|
||||
|
||||
getOrderedTasksQuerySet() {
|
||||
return this.tasks.orderBy('id');
|
||||
return this.tasks.orderBy('position');
|
||||
}
|
||||
|
||||
getOrderedAttachmentsQuerySet() {
|
||||
|
||||
@@ -7,6 +7,7 @@ export default class extends Model {
|
||||
|
||||
static fields = {
|
||||
id: attr(),
|
||||
position: attr(),
|
||||
name: attr(),
|
||||
isCompleted: attr({
|
||||
getDefault: () => false,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { call, put, select } from 'redux-saga/effects';
|
||||
|
||||
import request from '../request';
|
||||
import { pathSelector } from '../../../selectors';
|
||||
import { nextTaskPositionSelector, pathSelector, taskByIdSelector } from '../../../selectors';
|
||||
import {
|
||||
createTask,
|
||||
deleteTask,
|
||||
@@ -14,11 +14,16 @@ import api from '../../../api';
|
||||
import { createLocalId } from '../../../utils/local-id';
|
||||
|
||||
export function* createTaskService(cardId, data) {
|
||||
const nextData = {
|
||||
...data,
|
||||
position: yield select(nextTaskPositionSelector, cardId),
|
||||
};
|
||||
|
||||
const localId = yield call(createLocalId);
|
||||
|
||||
yield put(
|
||||
createTask({
|
||||
...data,
|
||||
...nextData,
|
||||
cardId,
|
||||
id: localId,
|
||||
}),
|
||||
@@ -26,7 +31,7 @@ export function* createTaskService(cardId, data) {
|
||||
|
||||
let task;
|
||||
try {
|
||||
({ item: task } = yield call(request, api.createTask, cardId, data));
|
||||
({ item: task } = yield call(request, api.createTask, cardId, nextData));
|
||||
} catch (error) {
|
||||
yield put(createTask.failure(localId, error));
|
||||
return;
|
||||
@@ -63,6 +68,15 @@ export function* handleTaskUpdateService(task) {
|
||||
yield put(handleTaskUpdate(task));
|
||||
}
|
||||
|
||||
export function* moveTaskService(id, index) {
|
||||
const { cardId } = yield select(taskByIdSelector, id);
|
||||
const position = yield select(nextTaskPositionSelector, cardId, index, id);
|
||||
|
||||
yield call(updateTaskService, id, {
|
||||
position,
|
||||
});
|
||||
}
|
||||
|
||||
export function* deleteTaskService(id) {
|
||||
yield put(deleteTask(id));
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
handleTaskCreateService,
|
||||
handleTaskDeleteService,
|
||||
handleTaskUpdateService,
|
||||
moveTaskService,
|
||||
updateTaskService,
|
||||
} from '../services';
|
||||
import EntryActionTypes from '../../../constants/EntryActionTypes';
|
||||
@@ -24,6 +25,9 @@ export default function* taskWatchers() {
|
||||
takeEvery(EntryActionTypes.TASK_UPDATE_HANDLE, ({ payload: { task } }) =>
|
||||
handleTaskUpdateService(task),
|
||||
),
|
||||
takeEvery(EntryActionTypes.TASK_MOVE, ({ payload: { id, index } }) =>
|
||||
moveTaskService(id, index),
|
||||
),
|
||||
takeEvery(EntryActionTypes.TASK_DELETE, ({ payload: { id } }) => deleteTaskService(id)),
|
||||
takeEvery(EntryActionTypes.TASK_DELETE_HANDLE, ({ payload: { task } }) =>
|
||||
handleTaskDeleteService(task),
|
||||
|
||||
@@ -71,7 +71,7 @@ export const makeTasksByCardIdSelector = () =>
|
||||
return cardModel;
|
||||
}
|
||||
|
||||
return cardModel.tasks.toRefArray();
|
||||
return cardModel.getOrderedTasksQuerySet().toRefArray();
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -76,3 +76,19 @@ export const nextCardPositionSelector = createSelector(
|
||||
return nextPosition(listModel.getOrderedFilteredCardsModelArray(), index, excludedId);
|
||||
},
|
||||
);
|
||||
|
||||
export const nextTaskPositionSelector = createSelector(
|
||||
orm,
|
||||
(_, cardId) => cardId,
|
||||
(_, __, index) => index,
|
||||
(_, __, ___, excludedId) => excludedId,
|
||||
({ Card }, cardId, index, excludedId) => {
|
||||
const cardModel = Card.withId(cardId);
|
||||
|
||||
if (!cardModel) {
|
||||
return cardModel;
|
||||
}
|
||||
|
||||
return nextPosition(cardModel.getOrderedTasksQuerySet().toRefArray(), index, excludedId);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -10,4 +10,5 @@ export * from './board';
|
||||
export * from './board-membership';
|
||||
export * from './list';
|
||||
export * from './card';
|
||||
export * from './task';
|
||||
export * from './attachment';
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { createSelector } from 'redux-orm';
|
||||
|
||||
import orm from '../orm';
|
||||
|
||||
export const makeTaskByIdSelector = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
({ Task }, id) => {
|
||||
const taskModel = Task.withId(id);
|
||||
|
||||
if (!taskModel) {
|
||||
return taskModel;
|
||||
}
|
||||
|
||||
return taskModel.ref;
|
||||
},
|
||||
);
|
||||
|
||||
export const taskByIdSelector = makeTaskByIdSelector();
|
||||
@@ -101,6 +101,10 @@
|
||||
border-radius: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.pswp .pswp__img--placeholder {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
#root {
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "planka",
|
||||
"version": "1.1.5",
|
||||
"version": "1.2.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "planka",
|
||||
"version": "1.1.5",
|
||||
"version": "1.2.1",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "planka",
|
||||
"version": "1.1.5",
|
||||
"version": "1.3.2",
|
||||
"private": true,
|
||||
"homepage": "https://plankanban.github.io/planka",
|
||||
"repository": {
|
||||
|
||||
@@ -54,10 +54,8 @@ module.exports = {
|
||||
|
||||
const attachment = await sails.helpers.attachments.createOne(
|
||||
{
|
||||
dirname: file.extra.dirname,
|
||||
...file.extra,
|
||||
filename: file.filename,
|
||||
isImage: file.extra.isImage,
|
||||
name: file.extra.name,
|
||||
},
|
||||
currentUser,
|
||||
card,
|
||||
|
||||
@@ -46,7 +46,7 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
if (!attachment.isImage) {
|
||||
if (!attachment.image) {
|
||||
throw Errors.ATTACHMENT_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
this.res.type(attachment.filename);
|
||||
if (!attachment.isImage && path.extname(attachment.filename) !== '.pdf') {
|
||||
if (!attachment.image && path.extname(attachment.filename) !== '.pdf') {
|
||||
this.res.set('Content-Disposition', 'attachment');
|
||||
}
|
||||
this.res.set('Cache-Control', 'private, max-age=900'); // TODO: move to config
|
||||
|
||||
@@ -33,11 +33,6 @@ module.exports = {
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
// TODO: allow over HTTP without subscription
|
||||
if (!this.req.isSocket) {
|
||||
return this.res.badRequest();
|
||||
}
|
||||
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const project = await Project.findOne(inputs.projectId);
|
||||
@@ -61,7 +56,9 @@ module.exports = {
|
||||
this.req,
|
||||
);
|
||||
|
||||
sails.sockets.join(this.req, `board:${board.id}`); // TODO: only when subscription needed
|
||||
if (this.req.isSocket) {
|
||||
sails.sockets.join(this.req, `board:${board.id}`); // TODO: only when subscription needed
|
||||
}
|
||||
|
||||
return {
|
||||
item: board,
|
||||
|
||||
@@ -20,11 +20,6 @@ module.exports = {
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
// TODO: allow over HTTP without subscription
|
||||
if (!this.req.isSocket) {
|
||||
return this.res.badRequest();
|
||||
}
|
||||
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { board, project } = await sails.helpers.boards
|
||||
@@ -77,7 +72,9 @@ module.exports = {
|
||||
card.isSubscribed = isSubscribedByCardId[card.id] || false; // eslint-disable-line no-param-reassign
|
||||
});
|
||||
|
||||
sails.sockets.join(this.req, `board:${board.id}`); // TODO: only when subscription needed
|
||||
if (this.req.isSocket) {
|
||||
sails.sockets.join(this.req, `board:${board.id}`); // TODO: only when subscription needed
|
||||
}
|
||||
|
||||
return {
|
||||
item: board,
|
||||
|
||||
@@ -11,6 +11,10 @@ module.exports = {
|
||||
regex: /^[0-9]+$/,
|
||||
required: true,
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
@@ -39,7 +43,7 @@ module.exports = {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['name', 'isCompleted']);
|
||||
const values = _.pick(inputs, ['position', 'name', 'isCompleted']);
|
||||
const task = await sails.helpers.tasks.createOne(values, card, this.req);
|
||||
|
||||
return {
|
||||
|
||||
@@ -11,6 +11,9 @@ module.exports = {
|
||||
regex: /^[0-9]+$/,
|
||||
required: true,
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
@@ -42,7 +45,7 @@ module.exports = {
|
||||
throw Errors.TASK_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['name', 'isCompleted']);
|
||||
const values = _.pick(inputs, ['position', 'name', 'isCompleted']);
|
||||
task = await sails.helpers.tasks.updateOne(task, values, board, this.req);
|
||||
|
||||
if (!task) {
|
||||
|
||||
@@ -38,7 +38,7 @@ module.exports = {
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
if (!inputs.card.coverAttachmentId && attachment.isImage) {
|
||||
if (!inputs.card.coverAttachmentId && attachment.image) {
|
||||
await sails.helpers.cards.updateOne(inputs.card, {
|
||||
coverAttachmentId: attachment.id,
|
||||
});
|
||||
|
||||
@@ -5,11 +5,23 @@ module.exports = {
|
||||
custom: (value) => _.isString(value) || _.every(value, _.isString),
|
||||
required: true,
|
||||
},
|
||||
exceptTaskIdOrIds: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isString(value) || _.every(value, _.isString),
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return sails.helpers.tasks.getMany({
|
||||
const criteria = {
|
||||
cardId: inputs.idOrIds,
|
||||
});
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptTaskIdOrIds)) {
|
||||
criteria.id = {
|
||||
'!=': inputs.exceptTaskIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return sails.helpers.tasks.getMany(criteria);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
|
||||
required: true,
|
||||
},
|
||||
card: {
|
||||
@@ -14,8 +15,32 @@ module.exports = {
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const tasks = await sails.helpers.cards.getTasks(inputs.card.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
inputs.values.position,
|
||||
tasks,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Task.update({
|
||||
id,
|
||||
cardId: inputs.card.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.card.boardId}`, 'taskUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const task = await Task.create({
|
||||
...inputs.values,
|
||||
position,
|
||||
cardId: inputs.card.id,
|
||||
}).fetch();
|
||||
|
||||
|
||||
@@ -7,6 +7,6 @@ module.exports = {
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return Task.find(inputs.criteria).sort('id');
|
||||
return Task.find(inputs.criteria).sort('position');
|
||||
},
|
||||
};
|
||||
|
||||
@@ -6,6 +6,17 @@ module.exports = {
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
@@ -18,6 +29,33 @@ module.exports = {
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
if (!_.isUndefined(inputs.values.position)) {
|
||||
const tasks = await sails.helpers.cards.getTasks(inputs.record.cardId, inputs.record.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
inputs.values.position,
|
||||
tasks,
|
||||
);
|
||||
|
||||
inputs.values.position = position; // eslint-disable-line no-param-reassign
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Task.update({
|
||||
id,
|
||||
cardId: inputs.record.cardId,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.board.id}`, 'taskUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const task = await Task.updateOne(inputs.record.id).set(inputs.values);
|
||||
|
||||
if (task) {
|
||||
|
||||
@@ -43,15 +43,20 @@ module.exports = {
|
||||
await writeFile(path.join(rootPath, filename), buffer);
|
||||
|
||||
const image = sharp(buffer);
|
||||
let imageMetadata;
|
||||
let metadata;
|
||||
|
||||
try {
|
||||
imageMetadata = await image.metadata();
|
||||
metadata = await image.metadata();
|
||||
} catch (error) {} // eslint-disable-line no-empty
|
||||
|
||||
if (imageMetadata) {
|
||||
const extra = {
|
||||
dirname,
|
||||
name: file.filename,
|
||||
};
|
||||
|
||||
if (metadata && !['svg', 'pdf'].includes(metadata.format)) {
|
||||
let cover256Buffer;
|
||||
if (imageMetadata.height > imageMetadata.width) {
|
||||
if (metadata.height > metadata.width) {
|
||||
cover256Buffer = await image
|
||||
.resize(256, 320)
|
||||
.jpeg({
|
||||
@@ -75,17 +80,16 @@ module.exports = {
|
||||
fs.mkdirSync(thumbnailsPath);
|
||||
|
||||
await writeFile(path.join(thumbnailsPath, 'cover-256.jpg'), cover256Buffer);
|
||||
|
||||
extra.image = _.pick(metadata, ['width', 'height']);
|
||||
} else {
|
||||
extra.image = null;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
file.extra = {
|
||||
dirname,
|
||||
isImage: !!imageMetadata,
|
||||
name: file.filename,
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
file.filename = filename;
|
||||
Object.assign(file, {
|
||||
filename,
|
||||
extra,
|
||||
});
|
||||
|
||||
return done();
|
||||
} catch (error) {
|
||||
|
||||
@@ -19,10 +19,8 @@ module.exports = {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
isImage: {
|
||||
type: 'boolean',
|
||||
required: true,
|
||||
columnName: 'is_image',
|
||||
image: {
|
||||
type: 'json',
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
@@ -51,9 +49,9 @@ module.exports = {
|
||||
|
||||
customToJSON() {
|
||||
return {
|
||||
..._.omit(this, ['dirname', 'filename', 'isImage']),
|
||||
..._.omit(this, ['dirname', 'filename']),
|
||||
url: `${sails.config.custom.attachmentsUrl}/${this.id}/download/${this.filename}`,
|
||||
coverUrl: this.isImage
|
||||
coverUrl: this.image
|
||||
? `${sails.config.custom.attachmentsUrl}/${this.id}/download/thumbnails/cover-256.jpg`
|
||||
: null,
|
||||
};
|
||||
|
||||
@@ -11,6 +11,10 @@ module.exports = {
|
||||
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
|
||||
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
|
||||
|
||||
position: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
|
||||
+7
-3
@@ -20,20 +20,24 @@
|
||||
* https://sailsjs.com/anatomy/app.js
|
||||
*/
|
||||
|
||||
require('dotenv').config();
|
||||
const dotenv = require('dotenv');
|
||||
|
||||
// Ensure we're in the project directory, so cwd-relative paths work as expected
|
||||
// no matter where we actually lift from.
|
||||
// > Note: This is not required in order to lift, but it is a convenient default.
|
||||
process.chdir(__dirname);
|
||||
|
||||
dotenv.config();
|
||||
|
||||
// Attempt to import `sails` dependency, as well as `rc` (for loading `.sailsrc` files).
|
||||
let sails;
|
||||
let rc;
|
||||
|
||||
try {
|
||||
sails = require('sails'); // eslint-disable-line global-require
|
||||
rc = require('sails/accessible/rc'); // eslint-disable-line global-require
|
||||
/* eslint-disable global-require */
|
||||
sails = require('sails');
|
||||
rc = require('sails/accessible/rc');
|
||||
/* eslint-enable global-require */
|
||||
} catch (error) {
|
||||
/* eslint-disable no-console */
|
||||
console.error("Encountered an error when attempting to require('sails'):");
|
||||
|
||||
+5
-3
@@ -1,10 +1,12 @@
|
||||
const config = require('./knexfile');
|
||||
const initKnex = require('knex');
|
||||
|
||||
const knex = require('knex')(config); // eslint-disable-line import/order
|
||||
const knexfile = require('./knexfile');
|
||||
|
||||
const knex = initKnex(knexfile);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const isExists = await knex.schema.hasTable(config.migrations.tableName);
|
||||
const isExists = await knex.schema.hasTable(knexfile.migrations.tableName);
|
||||
|
||||
await knex.migrate.latest();
|
||||
if (!isExists) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
const path = require('path');
|
||||
const dotenv = require('dotenv');
|
||||
const _ = require('lodash');
|
||||
|
||||
require('dotenv').config({
|
||||
dotenv.config({
|
||||
path: path.resolve(__dirname, '../.env'),
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module.exports.up = (knex) =>
|
||||
knex.schema.createTable('card', (table) => {
|
||||
knex.schema.createTable('card', async (table) => {
|
||||
/* Columns */
|
||||
|
||||
table.bigInteger('id').primary().defaultTo(knex.raw('next_id()'));
|
||||
@@ -12,7 +12,7 @@ module.exports.up = (knex) =>
|
||||
table.specificType('position', 'double precision');
|
||||
table.text('name').notNullable();
|
||||
table.text('description');
|
||||
table.timestamp('dueDate', true);
|
||||
table.timestamp('due_date', true);
|
||||
table.jsonb('timer');
|
||||
|
||||
table.timestamp('created_at', true);
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
const path = require('path');
|
||||
const sharp = require('sharp');
|
||||
const _ = require('lodash');
|
||||
|
||||
const getConfig = require('../../get-config');
|
||||
|
||||
module.exports.up = async (knex) => {
|
||||
await knex.schema.table('attachment', (table) => {
|
||||
/* Columns */
|
||||
|
||||
table.jsonb('image');
|
||||
});
|
||||
|
||||
const config = await getConfig();
|
||||
const attachments = await knex('attachment');
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (attachment of attachments) {
|
||||
if (attachment.is_image) {
|
||||
const image = sharp(
|
||||
path.join(config.custom.attachmentsPath, attachment.dirname, attachment.filename),
|
||||
);
|
||||
|
||||
let metadata;
|
||||
try {
|
||||
metadata = await image.metadata(); // eslint-disable-line no-await-in-loop
|
||||
} catch (error) {
|
||||
continue; // eslint-disable-line no-continue
|
||||
}
|
||||
|
||||
if (!['svg', 'pdf'].includes(metadata.format)) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await knex('attachment')
|
||||
.update({
|
||||
image: _.pick(metadata, ['width', 'height']),
|
||||
})
|
||||
.where('id', attachment.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return knex.schema.table('attachment', (table) => {
|
||||
table.dropColumn('is_image');
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.down = async (knex) => {
|
||||
await knex.schema.table('attachment', (table) => {
|
||||
/* Columns */
|
||||
|
||||
table.boolean('is_image');
|
||||
});
|
||||
|
||||
const attachments = await knex('attachment');
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (attachment of attachments) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await knex('attachment')
|
||||
.update({
|
||||
is_image: !!attachment.image,
|
||||
})
|
||||
.where('id', attachment.id);
|
||||
}
|
||||
|
||||
await knex.schema.table('attachment', (table) => {
|
||||
table.dropColumn('image');
|
||||
});
|
||||
|
||||
return knex.schema.alterTable('attachment', (table) => {
|
||||
table.boolean('is_image').notNullable().alter();
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
const POSITION_GAP = 65535;
|
||||
|
||||
module.exports.up = async (knex) => {
|
||||
await knex.schema.table('task', (table) => {
|
||||
/* Columns */
|
||||
|
||||
table.specificType('position', 'double precision');
|
||||
|
||||
/* Indexes */
|
||||
|
||||
table.index('position');
|
||||
});
|
||||
|
||||
const tasks = await knex('task').orderBy(['card_id', 'id']);
|
||||
|
||||
let prevCardId;
|
||||
let position;
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (task of tasks) {
|
||||
if (task.card_id === prevCardId) {
|
||||
position += POSITION_GAP;
|
||||
} else {
|
||||
prevCardId = task.card_id;
|
||||
position = POSITION_GAP;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await knex('task')
|
||||
.update({
|
||||
position,
|
||||
})
|
||||
.where('id', task.id);
|
||||
}
|
||||
|
||||
return knex.schema.table('task', (table) => {
|
||||
table.dropNullable('position');
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.down = async (knex) =>
|
||||
knex.schema.table('task', (table) => {
|
||||
table.dropColumn('position');
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
const dotenv = require('dotenv');
|
||||
const sails = require('sails');
|
||||
const rc = require('sails/accessible/rc');
|
||||
|
||||
process.chdir(__dirname);
|
||||
dotenv.config();
|
||||
|
||||
const config = rc('sails');
|
||||
|
||||
const getConfigPromise = new Promise((resolve) => {
|
||||
sails.load(
|
||||
{
|
||||
...config,
|
||||
hooks: {
|
||||
...config.hooks,
|
||||
logger: false,
|
||||
request: false,
|
||||
views: false,
|
||||
blueprints: false,
|
||||
responses: false,
|
||||
helpers: false,
|
||||
pubsub: false,
|
||||
policies: false,
|
||||
services: false,
|
||||
security: false,
|
||||
i18n: false,
|
||||
session: false,
|
||||
http: false,
|
||||
userhooks: false,
|
||||
},
|
||||
},
|
||||
() => {
|
||||
resolve(sails.config);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
module.exports = () => getConfigPromise;
|
||||
Reference in New Issue
Block a user