Skip to content
Merged
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
25 changes: 25 additions & 0 deletions backend/src/api/boards.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Router } from 'express';
import { BoardModel, BoardScope, ViewSettings } from '../models/Board';

Check warning on line 2 in backend/src/api/boards.ts

View workflow job for this annotation

GitHub Actions / Linting and Code Formating Check CI (backend)

'ViewSettings' is defined but never used
import { ProjectModel } from '../models/Project';
import { UserModel } from '../models/User';
import dalBoard from '../repository/dalBoard';
Expand Down Expand Up @@ -171,4 +171,29 @@
res.status(200).json(deletedBoard);
});

router.patch('/:boardID/currentView', async (req, res) => {
const { boardID } = req.params;
const { viewType } = req.body; // Expect viewType in the request body

if (!viewType) {
return res.status(400).json({ error: 'viewType is required' });
}

try {
// Update the board with the new currentView
const updatedBoard = await dalBoard.update(boardID, {
currentView: viewType,
});

if (!updatedBoard) {
return res.status(404).json({ error: 'Board not found' });
}

res.status(200).json(updatedBoard);
} catch (error) {
console.error('Error updating currentView:', error);
res.status(500).json({ error: 'Internal server error' });
}
});

export default router;
3 changes: 3 additions & 0 deletions backend/src/models/Board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ export class BoardModel {
@prop({ required: false })
public defaultView?: ViewType;

@prop({ required: false })
public currentView?: ViewType;

@prop({ required: false, type: () => ViewSettings })
public viewSettings?: ViewSettings;
}
Expand Down
5 changes: 4 additions & 1 deletion backend/src/models/Trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Severity,
} from '@typegoose/typegoose';

import { BoardType } from './Board';
import { BoardType, ViewType } from './Board';

@modelOptions({
schemaOptions: { collection: 'trace', timestamps: true },
Expand All @@ -30,6 +30,9 @@ export class TraceModel {
@prop({ required: true })
boardContext!: string;

@prop({ required: false })
viewType?: ViewType | undefined;

@prop({ required: true })
agentUserID!: string;

Expand Down
17 changes: 17 additions & 0 deletions backend/src/socket/events/workflow.events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
import { SocketPayload } from '../types/event.types';
import { GroupTaskModel } from '../../models/GroupTask';
import { GroupModel } from '../../models/Group';
import { PostModel } from '../../models/Post';
import workflowTrace from '../trace/workflow.trace';

class WorkflowRunDistribution {
static type: SocketEvent = SocketEvent.WORKFLOW_RUN_DISTRIBUTION;
Expand Down Expand Up @@ -62,6 +64,20 @@ class WorkflowUpdate {
}
}

class WorkflowPostSubmit {
static type: SocketEvent = SocketEvent.WORKFLOW_POST_SUBMIT;

static async handleEvent(
input: SocketPayload<PostModel>
): Promise<PostModel> {
if (input.trace.allowTracing) await workflowTrace.addPost(input, this.type);
return input.eventData;
}

static async handleResult(io: Server, socket: Socket, result: PostModel) {
socket.to(socket.data.room).emit(this.type, result);
}
}
class WorkflowDeleteTask {
static type: SocketEvent = SocketEvent.WORKFLOW_DELETE_TASK;

Expand Down Expand Up @@ -120,6 +136,7 @@ const workflowEvents = [
WorkflowRunDistribution,
WorkflowRunTask,
WorkflowUpdate,
WorkflowPostSubmit,
WorkflowDeleteTask,
WorkflowPostAdd,
WorkflowTaskComplete,
Expand Down
1 change: 1 addition & 0 deletions backend/src/socket/trace/base.trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const createTrace = async (
boardName: board.name,
boardType: board.type,
boardContext: boardScopeAsString(board.scope),
viewType: board.currentView,
agentUserID: user.userID,
agentUserName: user.username,
clientTimestamp: new Date(traceContext.clientTimestamp),
Expand Down
5 changes: 4 additions & 1 deletion backend/src/socket/trace/board.trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ const clearBoard = async (
eventType: string
) => {
const trace = await createTrace(input.trace);
const post = input.eventData.at(0);
trace.eventType = eventType;
trace.event = {};
trace.event = {
postID: post?.postID,
};

await dalTrace.create(trace);
};
Expand Down
27 changes: 22 additions & 5 deletions backend/src/socket/trace/post.trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,29 @@ import { createTrace } from './base.trace';
const create = async (input: SocketPayload<PostModel>, eventType: string) => {
const trace = await createTrace(input.trace);
const post = input.eventData;
trace.event = {
postID: post.postID,
postModifiedTitle: post.title,
postModifiedMessage: post.desc,
};
const tagNames: string[] = [];
const tagIDs: string[] = [];
if (post.tags.length > 0) {
post.tags.forEach((tag) => {
tagNames.push(tag.name);
tagIDs.push(tag.tagID);
});
trace.event = {
postID: post.postID,
postModifiedTitle: post.title,
postModifiedMessage: post.desc,
postTagNameAdded: tagNames.toString(),
postTagIDAdded: tagIDs.toString(),
};
} else {
trace.event = {
postID: post.postID,
postModifiedTitle: post.title,
postModifiedMessage: post.desc,
};
}
trace.eventType = eventType;

return dalTrace.create(trace);
};

Expand Down
38 changes: 38 additions & 0 deletions backend/src/socket/trace/workflow.trace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { PostModel } from '../../models/Post';
import dalTrace from '../../repository/dalTrace';
import { SocketPayload } from '../types/event.types';
import { createTrace } from './base.trace';

const addPost = async (input: SocketPayload<PostModel>, eventType: string) => {
const trace = await createTrace(input.trace);
const post = input.eventData;
const tagNames: string[] = [];
const tagIDs: string[] = [];
if (post.tags.length > 0) {
post.tags.forEach((tag) => {
tagNames.push(tag.name);
tagIDs.push(tag.tagID);
});
trace.event = {
postID: post.postID,
postModifiedTitle: post.title,
postModifiedMessage: post.desc,
postTagNameAdded: tagNames.toString(),
postTagIDAdded: tagIDs.toString(),
};
} else {
trace.event = {
postID: post.postID,
postModifiedTitle: post.title,
postModifiedMessage: post.desc,
};
}
trace.eventType = eventType;
return dalTrace.create(trace);
};

const workflowTrace = {
addPost,
};

export default workflowTrace;
Loading
Loading