Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
317 changes: 305 additions & 12 deletions dist/doboard-widget-bundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/doboard-widget-bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/doboard-widget-bundle.min.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let browserSync = require('browser-sync').create();
function bundle_src_js() {
const cssStream = processCSS();
const jsStream = gulp.src([
'js/src/localDB.js',
'js/src/api.js',
'js/src/constants.js',
'js/src/handlers.js',
Expand Down Expand Up @@ -54,7 +55,7 @@ function processCSS() {
const {deleteSync} = await import('del');
deleteSync('temp');
})
;
;
}

gulp.task('compress-js', gulp.series(bundle_src_js, minify_js));
Expand Down
23 changes: 20 additions & 3 deletions js/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ const logoutUserDoboard = async (projectToken, accountId) => {
}

const result = await spotfixApiCall(data, 'user_unauthorize', accountId);

if (result.operation_status === 'SUCCESS') {
await deleteDB();
clearLocalstorageOnLogout();
}
}
Expand All @@ -230,15 +232,19 @@ const getTasksDoboard = async (projectToken, sessionId, accountId, projectId, us
const tasks = result.tasks.map(task => ({
taskId: task.task_id,
taskTitle: task.name,
userId: task.user_id,
taskLastUpdate: task.updated,
taskCreated: task.created,
taskCreatorTaskUser: task.creator_user_id,
taskMeta: task.meta,
taskStatus: task.status,
}));

if (data.task_id) {
await spotfixIndexedDB.put(TABLE_TASKS, tasks);
} else {
await spotfixIndexedDB.clearPut(TABLE_TASKS, tasks);
}
storageSaveTasksCount(tasks);

return tasks;
}

Expand All @@ -250,7 +256,7 @@ const getTasksCommentsDoboard = async (sessionId, accountId, projectToken, statu
status: status
}
const result = await spotfixApiCall(data, 'comment_get', accountId);
return result.comments.map(comment => ({
const comments = result.comments.map(comment => ({
taskId: comment.task_id,
commentId: comment.comment_id,
userId: comment.user_id,
Expand All @@ -259,6 +265,12 @@ const getTasksCommentsDoboard = async (sessionId, accountId, projectToken, statu
status: comment.status,
issueTitle: comment.task_name,
}));
if (data.comment_id) {
await spotfixIndexedDB.put(TABLE_COMMENTS, comments);
} else {
await spotfixIndexedDB.clearPut(TABLE_COMMENTS, comments);
}
return comments;
};

const getUserDoboard = async (sessionId, projectToken, accountId, userId) => {
Expand All @@ -269,6 +281,11 @@ const getUserDoboard = async (sessionId, projectToken, accountId, userId) => {
if (userId) data.user_id = userId;

const result = await spotfixApiCall(data, 'user_get', accountId);
if (data.user_id) {
await spotfixIndexedDB.put(TABLE_USERS, result.users);
} else {
await spotfixIndexedDB.clearPut(TABLE_USERS, result.users);
}
return result.users;

// @ToDo Need to handle these two different answers?
Expand Down
21 changes: 14 additions & 7 deletions js/src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ async function confirmUserEmail(emailConfirmationToken, params) {
// Save session data to LS
localStorage.setItem('spotfix_email', result.email);
localStorage.setItem('spotfix_session_id', result.sessionId);
await spotfixIndexedDB.init();
localStorage.setItem('spotfix_user_id', result.userId);

// Get pending task from LS
Expand Down Expand Up @@ -39,8 +40,10 @@ async function confirmUserEmail(emailConfirmationToken, params) {
async function getTasksFullDetails(params, tasks, currentActiveTaskId) {
if (tasks.length > 0) {
const sessionId = localStorage.getItem('spotfix_session_id');
const comments = await getTasksCommentsDoboard(sessionId, params.accountId, params.projectToken);
const users = await getUserDoboard(sessionId, params.projectToken, params.accountId);
await getTasksCommentsDoboard(sessionId, params.accountId, params.projectToken);
const comments = await spotfixIndexedDB.getAll(TABLE_COMMENTS);
await getUserDoboard(sessionId, params.projectToken, params.accountId);
const users = await spotfixIndexedDB.getAll(TABLE_USERS);
const foundTask = tasks.find(item => +item.taskId === +currentActiveTaskId);

return {
Expand All @@ -55,7 +58,8 @@ async function getUserDetails(params) {
const sessionId = localStorage.getItem('spotfix_session_id');
const currentUserId = localStorage.getItem('spotfix_user_id');
if(currentUserId) {
const users = await getUserDoboard(sessionId, params.projectToken, params.accountId, currentUserId);
await getUserDoboard(sessionId, params.projectToken, params.accountId, currentUserId);
const users = await spotfixIndexedDB.getAll(TABLE_USERS);
return users[0] || {};
}
}
Expand Down Expand Up @@ -83,14 +87,15 @@ async function addTaskComment(params, taskId, commentText) {
return await createTaskCommentDoboard(params.accountId, sessionId, taskId, commentText, params.projectToken);
}

function getUserTasks(params) {
async function getUserTasks(params) {
if (!localStorage.getItem('spotfix_session_id')) {
return {};
}
const projectToken = params.projectToken;
const sessionId = localStorage.getItem('spotfix_session_id');
const userId = localStorage.getItem('spotfix_user_id');
return getTasksDoboard(projectToken, sessionId, params.accountId, params.projectId, userId);
await getTasksDoboard(projectToken, sessionId, params.accountId, params.projectId, userId);
return await spotfixIndexedDB.getAll(TABLE_TASKS, 'userId', userId);
}

async function getAllTasks(params) {
Expand All @@ -99,8 +104,8 @@ async function getAllTasks(params) {
}
const projectToken = params.projectToken;
const sessionId = localStorage.getItem('spotfix_session_id');
const tasksData = await getTasksDoboard(projectToken, sessionId, params.accountId, params.projectId);

await getTasksDoboard(projectToken, sessionId, params.accountId, params.projectId);
const tasksData = await spotfixIndexedDB.getAll(TABLE_TASKS);
// Get only tasks with metadata
const filteredTaskData = tasksData.filter(task => {
return task.taskMeta;
Expand Down Expand Up @@ -204,6 +209,7 @@ function registerUser(taskDetails) {
document.getElementById("doboard_task_widget-user_password").focus();
} else if (response.sessionId) {
localStorage.setItem('spotfix_session_id', response.sessionId);
spotfixIndexedDB.init();
localStorage.setItem('spotfix_user_id', response.userId);
localStorage.setItem('spotfix_email', response.email);
userUpdate(projectToken, accountId);
Expand Down Expand Up @@ -233,6 +239,7 @@ function loginUser(taskDetails) {
.then(response => {
if (response.sessionId) {
localStorage.setItem('spotfix_session_id', response.sessionId);
spotfixIndexedDB.init();
localStorage.setItem('spotfix_user_id', response.userId);
localStorage.setItem('spotfix_email', userEmail);
} else if (response.operationStatus === 'SUCCESS' && response.operationMessage && response.operationMessage.length > 0) {
Expand Down
Loading