mirror of
https://github.com/plankanban/planka.git
synced 2025-07-29 10:09:44 +02:00
Initial commit
This commit is contained in:
commit
36fe34e8e1
583 changed files with 91539 additions and 0 deletions
9
client/src/api/access-tokens.js
Executable file
9
client/src/api/access-tokens.js
Executable file
|
@ -0,0 +1,9 @@
|
|||
import http from './http';
|
||||
|
||||
/* Actions */
|
||||
|
||||
const createAccessToken = (data, headers) => http.post('/access-tokens', data, headers);
|
||||
|
||||
export default {
|
||||
createAccessToken,
|
||||
};
|
35
client/src/api/actions.js
Executable file
35
client/src/api/actions.js
Executable file
|
@ -0,0 +1,35 @@
|
|||
import socket from './socket';
|
||||
|
||||
/* Transformers */
|
||||
|
||||
export const transformAction = (action) => ({
|
||||
...action,
|
||||
createdAt: new Date(action.createdAt),
|
||||
});
|
||||
|
||||
/* Actions */
|
||||
|
||||
const getActions = (cardId, data, headers) => socket.get(`/cards/${cardId}/actions`, data, headers).then((body) => ({
|
||||
...body,
|
||||
items: body.items.map(transformAction),
|
||||
}));
|
||||
|
||||
/* Event handlers */
|
||||
|
||||
const makeHandleActionCreate = (next) => (body) => {
|
||||
next({
|
||||
...body,
|
||||
item: transformAction(body.item),
|
||||
});
|
||||
};
|
||||
|
||||
const makeHandleActionUpdate = makeHandleActionCreate;
|
||||
|
||||
const makeHandleActionDelete = makeHandleActionCreate;
|
||||
|
||||
export default {
|
||||
getActions,
|
||||
makeHandleActionCreate,
|
||||
makeHandleActionUpdate,
|
||||
makeHandleActionDelete,
|
||||
};
|
25
client/src/api/boards.js
Executable file
25
client/src/api/boards.js
Executable file
|
@ -0,0 +1,25 @@
|
|||
import socket from './socket';
|
||||
import { transformCard } from './cards';
|
||||
|
||||
/* Actions */
|
||||
|
||||
const createBoard = (projectId, data, headers) => socket.post(`/projects/${projectId}/boards`, data, headers);
|
||||
|
||||
const getBoard = (id, headers) => socket.get(`/boards/${id}`, undefined, headers).then((body) => ({
|
||||
...body,
|
||||
included: {
|
||||
...body.included,
|
||||
cards: body.included.cards.map(transformCard),
|
||||
},
|
||||
}));
|
||||
|
||||
const updateBoard = (id, data, headers) => socket.patch(`/boards/${id}`, data, headers);
|
||||
|
||||
const deleteBoard = (id, headers) => socket.delete(`/boards/${id}`, undefined, headers);
|
||||
|
||||
export default {
|
||||
createBoard,
|
||||
getBoard,
|
||||
updateBoard,
|
||||
deleteBoard,
|
||||
};
|
12
client/src/api/card-labels.js
Normal file
12
client/src/api/card-labels.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import socket from './socket';
|
||||
|
||||
/* Actions */
|
||||
|
||||
const createCardLabel = (cardId, data, headers) => socket.post(`/cards/${cardId}/labels`, data, headers);
|
||||
|
||||
const deleteCardLabel = (cardId, labelId, headers) => socket.delete(`/cards/${cardId}/labels/${labelId}`, undefined, headers);
|
||||
|
||||
export default {
|
||||
createCardLabel,
|
||||
deleteCardLabel,
|
||||
};
|
12
client/src/api/card-memberships.js
Normal file
12
client/src/api/card-memberships.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import socket from './socket';
|
||||
|
||||
/* Actions */
|
||||
|
||||
const createCardMembership = (cardId, data, headers) => socket.post(`/cards/${cardId}/memberships`, data, headers);
|
||||
|
||||
const deleteCardMembership = (cardId, userId, headers) => socket.delete(`/cards/${cardId}/memberships?userId=${userId}`, undefined, headers);
|
||||
|
||||
export default {
|
||||
createCardMembership,
|
||||
deleteCardMembership,
|
||||
};
|
70
client/src/api/cards.js
Executable file
70
client/src/api/cards.js
Executable file
|
@ -0,0 +1,70 @@
|
|||
import socket from './socket';
|
||||
|
||||
/* Transformers */
|
||||
|
||||
export const transformCard = (card) => ({
|
||||
...card,
|
||||
deadline: card.deadline && new Date(card.deadline),
|
||||
timer: card.timer && {
|
||||
...card.timer,
|
||||
startedAt: card.timer.startedAt && new Date(card.timer.startedAt),
|
||||
},
|
||||
});
|
||||
|
||||
export const transformCardData = (data) => ({
|
||||
...data,
|
||||
...(data.deadline && {
|
||||
deadline: data.deadline.toISOString(),
|
||||
}),
|
||||
...(data.timer && {
|
||||
...data.timer,
|
||||
...(data.timer.startedAt && {
|
||||
startedAt: data.timer.startedAt.toISOString(),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
/* Actions */
|
||||
|
||||
const createCard = (listId, data, headers) => socket.post(`/lists/${listId}/cards`, transformCardData(data), headers).then((body) => ({
|
||||
...body,
|
||||
item: transformCard(body.item),
|
||||
}));
|
||||
|
||||
const getCard = (id, headers) => socket.get(`/cards/${id}`, undefined, headers).then((body) => ({
|
||||
...body,
|
||||
item: transformCard(body.item),
|
||||
}));
|
||||
|
||||
const updateCard = (id, data, headers) => socket.patch(`/cards/${id}`, transformCardData(data), headers).then((body) => ({
|
||||
...body,
|
||||
item: transformCard(body.item),
|
||||
}));
|
||||
|
||||
const deleteCard = (id, headers) => socket.delete(`/cards/${id}`, undefined, headers).then((body) => ({
|
||||
...body,
|
||||
item: transformCard(body.item),
|
||||
}));
|
||||
|
||||
/* Event handlers */
|
||||
|
||||
const makeHandleCardCreate = (next) => (body) => {
|
||||
next({
|
||||
...body,
|
||||
item: transformCard(body.item),
|
||||
});
|
||||
};
|
||||
|
||||
const makeHandleCardUpdate = makeHandleCardCreate;
|
||||
|
||||
const makeHandleCardDelete = makeHandleCardCreate;
|
||||
|
||||
export default {
|
||||
createCard,
|
||||
getCard,
|
||||
updateCard,
|
||||
deleteCard,
|
||||
makeHandleCardCreate,
|
||||
makeHandleCardUpdate,
|
||||
makeHandleCardDelete,
|
||||
};
|
25
client/src/api/comment-actions.js
Executable file
25
client/src/api/comment-actions.js
Executable file
|
@ -0,0 +1,25 @@
|
|||
import socket from './socket';
|
||||
import { transformAction } from './actions';
|
||||
|
||||
/* Actions */
|
||||
|
||||
const createCommentAction = (cardId, data, headers) => socket.post(`/cards/${cardId}/comment-actions`, data, headers).then((body) => ({
|
||||
...body,
|
||||
item: transformAction(body.item),
|
||||
}));
|
||||
|
||||
const updateCommentAction = (id, data, headers) => socket.patch(`/comment-actions/${id}`, data, headers).then((body) => ({
|
||||
...body,
|
||||
item: transformAction(body.item),
|
||||
}));
|
||||
|
||||
const deleteCommentAction = (id, headers) => socket.delete(`/comment-actions/${id}`, undefined, headers).then((body) => ({
|
||||
...body,
|
||||
item: transformAction(body.item),
|
||||
}));
|
||||
|
||||
export default {
|
||||
createCommentAction,
|
||||
updateCommentAction,
|
||||
deleteCommentAction,
|
||||
};
|
35
client/src/api/http.js
Executable file
35
client/src/api/http.js
Executable file
|
@ -0,0 +1,35 @@
|
|||
import { fetch } from 'whatwg-fetch';
|
||||
|
||||
import Config from '../constants/Config';
|
||||
|
||||
const http = {};
|
||||
|
||||
// TODO: all methods
|
||||
['POST'].forEach((method) => {
|
||||
http[method.toLowerCase()] = (url, data, headers) => {
|
||||
const formData = Object.keys(data).reduce((result, key) => {
|
||||
result.append(key, data[key]);
|
||||
|
||||
return result;
|
||||
}, new FormData());
|
||||
|
||||
return fetch(`${Config.API_URL}${Config.API_PATH}${url}`, {
|
||||
method,
|
||||
headers,
|
||||
body: formData,
|
||||
})
|
||||
.then((response) => response.json().then((body) => ({
|
||||
body,
|
||||
isError: response.status !== 200,
|
||||
})))
|
||||
.then(({ body, isError }) => {
|
||||
if (isError) {
|
||||
throw body;
|
||||
}
|
||||
|
||||
return body;
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
export default http;
|
35
client/src/api/index.js
Executable file
35
client/src/api/index.js
Executable file
|
@ -0,0 +1,35 @@
|
|||
import http from './http';
|
||||
import socket from './socket';
|
||||
import accessTokens from './access-tokens';
|
||||
import users from './users';
|
||||
import projects from './projects';
|
||||
import projectMemberships from './project-memberships';
|
||||
import boards from './boards';
|
||||
import lists from './lists';
|
||||
import labels from './labels';
|
||||
import cards from './cards';
|
||||
import cardMemberships from './card-memberships';
|
||||
import cardLabels from './card-labels';
|
||||
import tasks from './tasks';
|
||||
import actions from './actions';
|
||||
import commentActions from './comment-actions';
|
||||
import notifications from './notifications';
|
||||
|
||||
export { http, socket };
|
||||
|
||||
export default {
|
||||
...accessTokens,
|
||||
...users,
|
||||
...projects,
|
||||
...projectMemberships,
|
||||
...boards,
|
||||
...lists,
|
||||
...labels,
|
||||
...cards,
|
||||
...cardMemberships,
|
||||
...cardLabels,
|
||||
...tasks,
|
||||
...actions,
|
||||
...commentActions,
|
||||
...notifications,
|
||||
};
|
15
client/src/api/labels.js
Executable file
15
client/src/api/labels.js
Executable file
|
@ -0,0 +1,15 @@
|
|||
import socket from './socket';
|
||||
|
||||
/* Actions */
|
||||
|
||||
const createLabel = (boardId, data, headers) => socket.post(`/boards/${boardId}/labels`, data, headers);
|
||||
|
||||
const updateLabel = (id, data, headers) => socket.patch(`/labels/${id}`, data, headers);
|
||||
|
||||
const deleteLabel = (id, headers) => socket.delete(`/labels/${id}`, undefined, headers);
|
||||
|
||||
export default {
|
||||
createLabel,
|
||||
updateLabel,
|
||||
deleteLabel,
|
||||
};
|
15
client/src/api/lists.js
Executable file
15
client/src/api/lists.js
Executable file
|
@ -0,0 +1,15 @@
|
|||
import socket from './socket';
|
||||
|
||||
/* Actions */
|
||||
|
||||
const createList = (boardId, data, headers) => socket.post(`/boards/${boardId}/lists`, data, headers);
|
||||
|
||||
const updateList = (id, data, headers) => socket.patch(`/lists/${id}`, data, headers);
|
||||
|
||||
const deleteList = (id, headers) => socket.delete(`/lists/${id}`, undefined, headers);
|
||||
|
||||
export default {
|
||||
createList,
|
||||
updateList,
|
||||
deleteList,
|
||||
};
|
35
client/src/api/notifications.js
Executable file
35
client/src/api/notifications.js
Executable file
|
@ -0,0 +1,35 @@
|
|||
import socket from './socket';
|
||||
import { transformCard } from './cards';
|
||||
import { transformAction } from './actions';
|
||||
|
||||
/* Actions */
|
||||
|
||||
const getNotifications = (headers) => socket.get('/notifications', undefined, headers).then((body) => ({
|
||||
...body,
|
||||
included: {
|
||||
...body.included,
|
||||
cards: body.included.cards.map(transformCard),
|
||||
actions: body.included.actions.map(transformAction),
|
||||
},
|
||||
}));
|
||||
|
||||
const updateNotifications = (ids, data, headers) => socket.patch(`/notifications/${ids.join(',')}`, data, headers);
|
||||
|
||||
/* Event handlers */
|
||||
|
||||
const makeHandleNotificationCreate = (next) => (body) => {
|
||||
next({
|
||||
...body,
|
||||
included: {
|
||||
...body.included,
|
||||
cards: body.included.cards.map(transformCard),
|
||||
actions: body.included.actions.map(transformAction),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export default {
|
||||
getNotifications,
|
||||
updateNotifications,
|
||||
makeHandleNotificationCreate,
|
||||
};
|
12
client/src/api/project-memberships.js
Executable file
12
client/src/api/project-memberships.js
Executable file
|
@ -0,0 +1,12 @@
|
|||
import socket from './socket';
|
||||
|
||||
/* Actions */
|
||||
|
||||
const createProjectMembership = (projectId, data, headers) => socket.post(`/projects/${projectId}/memberships`, data, headers);
|
||||
|
||||
const deleteProjectMembership = (id, headers) => socket.delete(`/project-memberships/${id}`, undefined, headers);
|
||||
|
||||
export default {
|
||||
createProjectMembership,
|
||||
deleteProjectMembership,
|
||||
};
|
18
client/src/api/projects.js
Executable file
18
client/src/api/projects.js
Executable file
|
@ -0,0 +1,18 @@
|
|||
import socket from './socket';
|
||||
|
||||
/* Actions */
|
||||
|
||||
const getProjects = (headers) => socket.get('/projects', undefined, headers);
|
||||
|
||||
const createProject = (data, headers) => socket.post('/projects', data, headers);
|
||||
|
||||
const updateProject = (id, data, headers) => socket.patch(`/projects/${id}`, data, headers);
|
||||
|
||||
const deleteProject = (id, headers) => socket.delete(`/projects/${id}`, undefined, headers);
|
||||
|
||||
export default {
|
||||
getProjects,
|
||||
createProject,
|
||||
updateProject,
|
||||
deleteProject,
|
||||
};
|
37
client/src/api/socket.js
Executable file
37
client/src/api/socket.js
Executable file
|
@ -0,0 +1,37 @@
|
|||
import socketIOClient from 'socket.io-client';
|
||||
import sailsIOClient from 'sails.io.js';
|
||||
|
||||
import Config from '../constants/Config';
|
||||
|
||||
const io = sailsIOClient(socketIOClient);
|
||||
|
||||
io.sails.url = Config.API_URL;
|
||||
io.sails.autoConnect = false;
|
||||
io.sails.reconnection = true;
|
||||
io.sails.useCORSRouteToGetCookie = false;
|
||||
|
||||
const { socket } = io;
|
||||
|
||||
socket.connect = socket._connect; // eslint-disable-line no-underscore-dangle
|
||||
|
||||
['GET', 'POST', 'PUT', 'PATCH', 'DELETE'].forEach((method) => {
|
||||
socket[method.toLowerCase()] = (url, data, headers) => new Promise((resolve, reject) => {
|
||||
socket.request(
|
||||
{
|
||||
method,
|
||||
data,
|
||||
headers,
|
||||
url: `${Config.API_PATH}${url}`,
|
||||
},
|
||||
(_, { body, error }) => {
|
||||
if (error) {
|
||||
reject(body);
|
||||
} else {
|
||||
resolve(body);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
export default socket;
|
15
client/src/api/tasks.js
Executable file
15
client/src/api/tasks.js
Executable file
|
@ -0,0 +1,15 @@
|
|||
import socket from './socket';
|
||||
|
||||
/* Actions */
|
||||
|
||||
const createTask = (cardId, data, headers) => socket.post(`/cards/${cardId}/tasks`, data, headers);
|
||||
|
||||
const updateTask = (id, data, headers) => socket.patch(`/tasks/${id}`, data, headers);
|
||||
|
||||
const deleteTask = (id, headers) => socket.delete(`/tasks/${id}`, undefined, headers);
|
||||
|
||||
export default {
|
||||
createTask,
|
||||
updateTask,
|
||||
deleteTask,
|
||||
};
|
31
client/src/api/users.js
Executable file
31
client/src/api/users.js
Executable file
|
@ -0,0 +1,31 @@
|
|||
import http from './http';
|
||||
import socket from './socket';
|
||||
|
||||
/* Actions */
|
||||
|
||||
const getUsers = (headers) => socket.get('/users', undefined, headers);
|
||||
|
||||
const createUser = (data, headers) => socket.post('/users', data, headers);
|
||||
|
||||
const getCurrentUser = (headers) => socket.get('/users/me', undefined, headers);
|
||||
|
||||
const updateUser = (id, data, headers) => socket.patch(`/users/${id}`, data, headers);
|
||||
|
||||
const uploadUserAvatar = (id, file, headers) => http.post(
|
||||
`/users/${id}/upload-avatar`,
|
||||
{
|
||||
file,
|
||||
},
|
||||
headers,
|
||||
);
|
||||
|
||||
const deleteUser = (id, headers) => socket.delete(`/users/${id}`, undefined, headers);
|
||||
|
||||
export default {
|
||||
getUsers,
|
||||
createUser,
|
||||
getCurrentUser,
|
||||
updateUser,
|
||||
uploadUserAvatar,
|
||||
deleteUser,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue