Skip to content

Commit 8fcfaf6

Browse files
author
Aishwarya Nair
committed
Merge remote-tracking branch 'origin/collab-fix' into test-updated-merge
2 parents 183820f + cfb4cef commit 8fcfaf6

File tree

12 files changed

+297
-162
lines changed

12 files changed

+297
-162
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
node_modules
2-
.vscode
3-
.gitignore
4-
.github
1+
node_modules

CollaborationService/config/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ const SYSTEM_TERMINATE_TIMEOUT = 10 * 1000; // 10 secsS
1616
module.exports = {
1717
PORT: 3005,
1818
serverAddress: "http://collaboration-service:3005",
19+
<<<<<<< HEAD
1920
// serverAddress: "http://127.0.0.1:3005",
21+
=======
22+
// serverAddress: "http://127.0.0.1:3005",
23+
>>>>>>> origin/collab-fix
2024
matchingServiceUrl: "http://matching-service:3004",
2125
// matchingServiceUrl: "http://127.0.0.1:3004",
2226
questionServiceUrl: "http://question-service:3003/api/questions",

CollaborationService/controllers/collaborationController.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ async function getHistory(req, res, next) {
55
try {
66
const sessionId = req.params.sessionId;
77

8-
const response = await collaborationService.getCollaborationHistory(sessionId);
8+
const response = collaborationService.getCollaborationHistory(sessionId);
99

1010
if (response[0] === 'None') {
1111

1212
await res.status(500).json({ status: 'error', message: 'Collaboration data does not exist'});
1313

1414
} else {
15+
1516
const jsonRes = {
1617
status: "success",
17-
initTime: response[0],
18-
language: response[1],
19-
codes: response[2],
18+
initTime: response.initTime,
19+
language: response.language,
20+
codes: response.codes,
2021
}
2122

2223
await res.status(200).json(jsonRes);

CollaborationService/database/collaborativeInputDb.js

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
const {
23
CollaborativeInput,
34
LineInput,
@@ -214,4 +215,150 @@ module.exports = {
214215
updateCollaborativeLanguage,
215216
deleteCollaborativeInput,
216217
deleteCollaborativeLineInput,
217-
};
218+
};
219+
=======
220+
const CollaborativeInput = require('../models/collaborationCodeModel');
221+
const axios = require('axios');
222+
const config = require('../config/config');
223+
224+
const getCollaborativeInput = async(sessionId) => {
225+
try {
226+
const dataOutput = await CollaborativeInput.findOne({ sessionId: sessionId });
227+
228+
console.log(`Get collaborative input for session ${sessionId}`);
229+
230+
return [dataOutput.initTime, dataOutput.language, dataOutput.codes];
231+
232+
} catch (error) {
233+
console.log(`Error getting collaborative input for session ${sessionId}`);
234+
235+
return ["None", "", ""];
236+
}
237+
}
238+
239+
const getCollaborativeInputByLine = async(sessionId, line) => {
240+
try {
241+
const dataOutput = await CollaborativeInput.findOne({ sessionId: sessionId, 'codes.line': line });
242+
243+
console.log(`Get collaborative input for session ${sessionId} line ${line}`);
244+
245+
return [dataOutput.language, line, dataOutput.codes[line].code];
246+
247+
} catch (error) {
248+
console.error(`Error getting collaborative input by line for session ${sessionId}`);
249+
250+
return ["None", line, ""];
251+
}
252+
}
253+
254+
const initCollaborativeCode = async(initTime, sessionId, language) => {
255+
try {
256+
const input = await getCollaborativeInput(sessionId);
257+
258+
if (input[0] === "None") {
259+
const collaborativeInput = new CollaborativeInput(
260+
{ sessionId: sessionId, initTime: initTime, language: language, codes: [] });
261+
262+
await collaborativeInput.save();
263+
264+
console.log(`Successfully added:`, collaborativeInput);
265+
266+
return [collaborativeInput.initTime, language, []];
267+
268+
} else {
269+
console.log(`Collaborative input already exists for ${sessionId}`);
270+
271+
return input;
272+
}
273+
274+
} catch (error) {
275+
console.log(`Failed to add collaborative input for ${sessionId}`);
276+
277+
return ["None", ""];
278+
}
279+
}
280+
281+
const updateCollaborativeLineInput = async(sessionId, line, code, lastModifier) => {
282+
try {
283+
let collaborativeInput = await CollaborativeInput.findOne(
284+
{ sessionId: sessionId, 'codes.line': line });
285+
286+
if (collaborativeInput) {
287+
await CollaborativeInput.updateOne(
288+
{ sessionId: sessionId, 'codes.line': line },
289+
{ $set: { 'codes.$.code': code, 'codes.$.lastModifier': lastModifier } }
290+
);
291+
292+
} else {
293+
await CollaborativeInput.updateOne(
294+
{ sessionId: sessionId },
295+
{ $push: { codes: { line: line, code: code, lastModifier: lastModifier } } }
296+
);
297+
}
298+
299+
console.log(`Successfully updated line:`, line);
300+
301+
} catch (error) {
302+
console.log(`Failed to update collaborative input for ${sessionId} line ${line}`);
303+
}
304+
}
305+
306+
const updateCollaborativeInput = async(sessionId, codes) => {
307+
try {
308+
let collaborativeInput = await CollaborativeInput.findOne({ sessionId: sessionId });
309+
const sessionReq = await axios.get(`${config.matchingServiceUrl}/getSession/${sessionId}`);
310+
311+
const session = sessionReq.data.session;
312+
313+
if (collaborativeInput.codes !== null) {
314+
collaborativeInput.codes = codes;
315+
316+
} else {
317+
collaborativeInput = new CollaborativeInput({ sessionId: sessionId, initTime: session.initTime, language: session.language, codes: codes });
318+
}
319+
320+
await collaborativeInput.save();
321+
322+
console.log(`Successfully updated:`, collaborativeInput);
323+
324+
} catch (error) {
325+
console.log(`Failed to update collaborative input for ${sessionId}`);
326+
}
327+
}
328+
329+
const deleteCollaborativeInput = async(sessionId) => {
330+
try {
331+
const result = await CollaborativeInput.deleteOne({ sessionId: sessionId });
332+
333+
console.log(`Successfully deleted:`, result);
334+
335+
} catch (error) {
336+
console.log(`Failed to delete collaborative input for ${sessionId}`);
337+
}
338+
}
339+
340+
const deleteCollaborativeLineInput = async(sessionId, line) => {
341+
try {
342+
const collaborativeInput = await CollaborativeInput.findOne({ sessionId: sessionId });
343+
344+
collaborativeInput.codes.splice(line, 1);
345+
346+
await collaborativeInput.save();
347+
348+
console.log(`Successfully deleted:`, collaborativeInput);
349+
350+
} catch (error) {
351+
console.log(`Failed to delete collaborative input for ${sessionId} line ${line}`);
352+
}
353+
}
354+
355+
module.exports = {
356+
getCollaborativeInput,
357+
getCollaborativeInputByLine,
358+
initCollaborativeCode,
359+
updateCollaborativeLineInput,
360+
updateCollaborativeInput,
361+
deleteCollaborativeInput,
362+
deleteCollaborativeLineInput
363+
}
364+
>>>>>>> origin/collab-fix
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
const mongoose = require("mongoose");
1+
const mongoose = require('mongoose');
22

33
const lineInputSchema = new mongoose.Schema({
4-
line: Number,
5-
code: String,
6-
lastModifier: String,
4+
line: Number,
5+
code: String,
6+
lastModifier: String
77
});
88

99
const collaborativeInputSchema = new mongoose.Schema({
10-
sessionId: String,
11-
initTime: Number,
12-
language: String,
13-
codes: [lineInputSchema],
10+
sessionId: String,
11+
initTime: Number,
12+
language: String,
13+
codes: [lineInputSchema]
1414
});
1515

16-
const CollaborativeInput = mongoose.model(
17-
"CollaborativeInput",
18-
collaborativeInputSchema
19-
);
20-
const LineInput = mongoose.model("LineInput", lineInputSchema);
2116

22-
module.exports = {CollaborativeInput, LineInput};
17+
module.exports = mongoose.model('CollaborativeInput', collaborativeInputSchema);

Frontend/src/Components/Collaboration/CodeEditor.jsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import "./CodeEditor.css";
22
import Editor from "@monaco-editor/react";
3+
<<<<<<< HEAD
34
import React, {useState, useEffect} from "react";
45
import {getUserId} from "../../User/UserState";
56

@@ -12,6 +13,20 @@ const CodeEditor = ({
1213
socket,
1314
}) => {
1415
const OriginalResizeObserver = window.ResizeObserver;
16+
=======
17+
import React from "react";
18+
19+
const CodeEditor = ({code, setCode, language, isReadOnly}) => {
20+
const OriginalResizeObserver = window.ResizeObserver;
21+
22+
// Monaco Editor Resize Fix (https://github.com/microsoft/vscode/issues/183324#issuecomment-1575484617)
23+
window.ResizeObserver = function (callback) {
24+
const wrappedCallback = (entries, observer) => {
25+
window.requestAnimationFrame(() => {
26+
callback(entries, observer);
27+
});
28+
};
29+
>>>>>>> origin/collab-fix
1530

1631
const [originalCode, setOriginalCode] = useState(code);
1732
const [originalLanguage, setOriginalLanguage] = useState(language);
@@ -25,6 +40,7 @@ const CodeEditor = ({
2540
}
2641
}, [code]);
2742

43+
<<<<<<< HEAD
2844
// Monaco Editor Resize Fix (https://github.com/microsoft/vscode/issues/183324#issuecomment-1575484617)
2945
window.ResizeObserver = function (callback) {
3046
const wrappedCallback = (entries, observer) => {
@@ -115,6 +131,25 @@ const CodeEditor = ({
115131
/>
116132
</div>
117133
);
134+
=======
135+
return (
136+
<div className="code-editor">
137+
<Editor
138+
language={language}
139+
theme="vs-light"
140+
value={code}
141+
onChange={e => {setCode(code)}}
142+
options={{
143+
inlineSuggest: true,
144+
fontSize: "16px",
145+
formatOnType: true,
146+
minimap: { enabled: false },
147+
readOnly: isReadOnly
148+
}}
149+
/>
150+
</div>
151+
);
152+
>>>>>>> origin/collab-fix
118153
};
119154

120155
export default CodeEditor;

0 commit comments

Comments
 (0)