Skip to content

Commit

Permalink
Merge branch 'main' into 272-emin-add-unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
serhan-cakmak committed Nov 25, 2024
2 parents 86442eb + 88274b5 commit e44e7f6
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 67 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ cd bounswe2024group9</code></pre>
AWS_HOST=XXX
JUDGE0_API_KEY=XXX
DJANGO_SECRET_KEY=XXX
ALTERNATIVE_JUDGE0_API_KEY=XXX
REACT_APP_API_URL=XXX</code></pre>
JUDGE0_API_KEY_POOL=XXX
REACT_APP_API_URL=XXX
REACT_APP_FRONTEND_URL=XXX
EMAIL_HOST_USER=XXX
GEMINI_AI_KEY_POOL=XXX
</code></pre>
<li>Run the following command to run Docker image
<pre><code>docker compose up</code></pre>
</li>
Expand Down
21 changes: 0 additions & 21 deletions django_project_491/django_app/migrations/0006_topic.py

This file was deleted.

39 changes: 20 additions & 19 deletions django_project_491/django_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,25 +276,6 @@ def check_and_promote(self):

return self.userType

class Topic(models.Model):
name = models.CharField(max_length=100, unique=True)
related_url = models.URLField()

def __str__(self):
return self.name

@staticmethod
def get_all_topics():
return Topic.objects.all()

@staticmethod
def get_url_for_topic(topic_name):
try:
topic = Topic.objects.get(name__iexact=topic_name)
return topic.related_url
except Topic.DoesNotExist:
return None


class Annotation(models.Model):
_id = models.AutoField(primary_key=True)
Expand All @@ -320,3 +301,23 @@ def __repr__(self):

def __unicode__(self):
return self.text


class Topic(models.Model):
name = models.CharField(max_length=100, unique=True)
related_url = models.URLField()

def __str__(self):
return self.name

@staticmethod
def get_all_topics():
return Topic.objects.all()

@staticmethod
def get_url_for_topic(topic_name):
try:
topic = Topic.objects.get(name__iexact=topic_name)
return topic.related_url
except Topic.DoesNotExist:
return None
5 changes: 5 additions & 0 deletions django_project_491/django_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@
path('questions/<int:question_id>/topic/', question_views.get_topic_url, name='get_topic_url'),
path('topics/', question_views.list_all_topics, name='list_all_topics'),

path('create_annotation/', annotation_views.create_annotation, name='create_annotation'),
path('delete_annotation/<int:annotation_id>/', annotation_views.delete_annotation, name='delete_annotation'),
path('edit_annotation/<int:annotation_id>/', annotation_views.edit_annotation, name='edit_annotation'),
path('get_annotations_by_language_id/<int:language_qid>/', annotation_views.get_annotations_by_language, name='get_annotations_by_language_id'),
path('annotations/all/', annotation_views.get_all_annotations, name='get_all_annotations'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
15 changes: 10 additions & 5 deletions koduyorum-web/src/Annotation.css
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
.annotation {
position: relative;
cursor: pointer;
font-style: italic;
color: darkcyan; /* Example: Tomato color */
}
font-style: italic; /* Italicize the text to differentiate it from the rest */
background-color: cyan; /* Light yellow background for highlight effect */
padding: 2px; /* Add padding for better appearance */
border-radius: 2px; /* Slightly round the edges to mimic a marker stroke */
display: inline-block; /* Keep it inline while allowing styling */
color: black; /* Ensure the text is readable */
}


.annotation-tooltip {
position: absolute;
top: 120%;
left: 20%;
background-color: rgba(0, 0, 0, 0.7);
color: white;
padding: 5px;
padding: 10px; /* Comfortable padding */
border-radius: 3px;
font-size: 12px;
max-width: 200px;
max-width: 300px; /* Limit width to prevent overflowing */
white-space: nowrap;
z-index: 10;
opacity: 0;
Expand Down
29 changes: 25 additions & 4 deletions koduyorum-web/src/CreateAnnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ const CreateAnnotation = ({ visible, selectedText, startIndex, endIndex, languag
placeholder="Enter your annotation..."
/>
<div className="modal-buttons">
<button onClick={handleSubmit}>{annotationId ? 'Save Changes' : 'Create'}</button>
<button className="cancel-button" onClick={onClose}>Cancel</button>
<button
className={annotationId ? "save-button" : "create-button"}
onClick={handleSubmit}
>
{annotationId ? "Save Changes" : "Create"}
</button>
<button className="cancel-button" onClick={onClose}>
Cancel
</button>
</div>
</div>

Expand Down Expand Up @@ -109,14 +116,28 @@ const CreateAnnotation = ({ visible, selectedText, startIndex, endIndex, languag
justify-content: space-between;
gap: 10px;
}
.submit-button {
background: #4CAF50;
.save-button {
background: #007bff; /* Blue color for Save Changes */
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.save-button:hover {
background: #0056b3; /* Darker blue on hover */
}
.create-button {
background: #28a745; /* Green color for Create */
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.create-button:hover {
background: #218838; /* Darker green on hover */
}
.cancel-button {
background: #f44336;
color: white;
Expand Down
57 changes: 41 additions & 16 deletions koduyorum-web/src/SearchResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,26 @@ const fetchSearchResults = async (query) => {
};

const addAnnotations = (text, annotations) => {
console.log("Adding annotations to text:", text);
console.log("Annotations list:", annotations);

let annotatedText = [];
let lastIndex = 0;

// Sort annotations by starting point to avoid misplacement
const sortedAnnotations = annotations.sort(
(a, b) => a.annotation_starting_point - b.annotation_starting_point
);

annotations.forEach((annotation) => {
sortedAnnotations.forEach((annotation) => {
const { annotation_starting_point, annotation_ending_point, text: annotationText , annotation_id: annotationId} = annotation;
// Add text before the annotation

console.log("Processing annotation:", annotation);

if (lastIndex < annotation_starting_point) {
annotatedText.push(text.slice(lastIndex, annotation_starting_point));
}

// Add annotated text with tooltip
annotatedText.push(
<span className="annotation" key={annotation_starting_point}>
Expand Down Expand Up @@ -221,18 +231,26 @@ const fetchSearchResults = async (query) => {
if (lastIndex < text.length) {
annotatedText.push(text.slice(lastIndex));
}

console.log("Final annotated text:", annotatedText);
return annotatedText;
};

const handleEditAnnotation = async (annotationId, startOffset, endOffset) => {
// Fetch annotation data by ID
setStartIndex(startOffset);
setEndIndex(endOffset);
setModalVisible(true);
setAnnotationId(annotationId);
// Fetch the annotation to get its text
const annotationToEdit = annotationData.find((annotation) => annotation.annotation_id === annotationId);
if (annotationToEdit) {
console.log("Editing annotation:", annotationToEdit);
setSelectedText(annotationToEdit.text); // Set selected text from the annotation
setStartIndex(startOffset);
setEndIndex(endOffset);
setModalVisible(true);
setAnnotationId(annotationId);
} else {
console.error("Annotation not found for editing.");
}
};


const handleDeleteAnnotation = async (annotationId) => {
try {
const userId = localStorage.getItem('user_id');
Expand All @@ -245,6 +263,10 @@ const fetchSearchResults = async (query) => {
});

if (response.ok) {
// Update the state to remove the deleted annotation
setAnnotationData((prevAnnotations) =>
prevAnnotations.filter((annotation) => annotation.annotation_id !== annotationId)
);
alert('Annotation deleted successfully.');
// Optional: Trigger a re-fetch of annotations or update state to reflect the deletion
} else {
Expand All @@ -270,6 +292,9 @@ const fetchSearchResults = async (query) => {
const mouseX = e.clientX;
const mouseY = e.clientY;

console.log("Text selected:", selection.toString());
console.log("Selection start index:", startOffset, "end index:", endOffset);

setSelectedText(selection.toString());
setStartIndex(startOffset);
setEndIndex(endOffset);
Expand All @@ -279,7 +304,10 @@ const fetchSearchResults = async (query) => {
console.log('No text selected.');
}
};




const renderAnnotatedText = (textData) => {
const { text, annotation, start, end } = textData;

Expand Down Expand Up @@ -318,11 +346,12 @@ const fetchSearchResults = async (query) => {
searched={searched}
handleSearchResultClick={handleSearchResultClick}
/>

<div className="feed-content">
<LeftSidebar handleTagClick={handleTagClick} />

<div className='info-container'>

<div className="info-container">

<div className="tab-navigation">
<button
className={`tab-button ${activeTab === 'info' ? 'active-tab' : ''}`}
Expand All @@ -337,7 +366,6 @@ const fetchSearchResults = async (query) => {
Questions
</button>
</div>

{activeTab === 'info' ? (
<div>
<CreateAnnotation
Expand All @@ -350,8 +378,6 @@ const fetchSearchResults = async (query) => {
onClose={() => setModalVisible(false)}
/>
<div className="info-box" onMouseUp={(e) => handleTextSelection(e)}>
<h2 className="language-title">{wiki_name}</h2>
<div className="info-box">
<h2 style={{paddingBottom: '0.5rem', borderBottom: '1px solid #ccc'}} className="language-title">
{wiki_name}
</h2>
Expand Down Expand Up @@ -418,7 +444,6 @@ const fetchSearchResults = async (query) => {
)}
</div>
</div>
</div>
) : (
<div className="questions-list">
<h2 style={{ marginBottom: '1rem', paddingBottom: '0.5rem', borderBottom: '1px solid #ccc', fontSize: '1.5rem' }}>
Expand Down

0 comments on commit e44e7f6

Please sign in to comment.