Skip to content

Commit

Permalink
added redirect link to importing exercise page in first message
Browse files Browse the repository at this point in the history
  • Loading branch information
RY997 committed Oct 20, 2023
1 parent f205a05 commit 13dd601
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ <h4 class="modal-title">
</div>
<div *ngIf="isServerSentMessage(message)" style="width: fit-content">
<div class="bubble-left" *ngIf="isTextContent(content)">
<span *ngIf="isFirstMessage && i === 0" [innerHTML]="getTextContent(content)! | artemisTranslate"></span>
<span *ngIf="!isFirstMessage || (isFirstMessage && i > 0)" [innerHTML]="getTextContent(content)! | htmlForMarkdown"></span>
<span [innerHTML]="getTextContent(content)! | htmlForMarkdown"></span>
</div>
<div *ngIf="isRateMessage()" class="rate-message-buttons">
<button style="all: unset" (click)="rateMessage(message.id, i, true)" [disabled]="message.helpful">
Expand Down Expand Up @@ -109,7 +108,7 @@ <h4 class="modal-title">
</div>
<div *ngIf="isArtemisClientSentMessage(message)" style="width: fit-content">
<div class="bubble-left" *ngIf="isTextContent(content)">
<span [innerHTML]="getTextContent(content)! | artemisTranslate"></span>
<span [innerHTML]="getTextContent(content)!"></span>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
IrisMessageContent,
IrisMessageContentType,
IrisMessageTextContent,
getComponentInstruction,
getPlanComponent,
getTextContent,
isPlanContent,
Expand All @@ -57,9 +56,9 @@ import { IrisLogoSize } from '../../iris-logo/iris-logo.component';
import interact from 'interactjs';
import { DOCUMENT } from '@angular/common';
import { IrisHttpChatMessageService } from 'app/iris/http-chat-message.service';
import { IrisExercisePlanComponent } from 'app/entities/iris/iris-exercise-plan-component.model';
import { IrisHttpCodeEditorMessageService } from 'app/iris/http-code-editor-message.service';
import { IrisChatSessionService } from 'app/iris/chat-session.service';
import { TranslateService } from '@ngx-translate/core';

@Component({
selector: 'jhi-exercise-chat-widget',
Expand Down Expand Up @@ -120,17 +119,18 @@ export class ExerciseChatWidgetComponent implements OnInit, OnDestroy, AfterView
unreadMessageIndex: number;
error: IrisErrorType | null;
dots = 1;
isFirstMessage = false;
resendAnimationActive = false;
shakeErrorField = false;
shouldLoadGreetingMessage = true;
fadeState = '';
courseId: number;
exerciseId: number;
sessionService: IrisSessionService;
shouldShowEmptyMessageError = false;
currentMessageCount: number;
rateLimit: number;
rateLimitTimeframeHours: number;
importExerciseUrl: string;

// User preferences
userAccepted: boolean;
Expand All @@ -149,14 +149,15 @@ export class ExerciseChatWidgetComponent implements OnInit, OnDestroy, AfterView
constructor(
private dialog: MatDialog,
@Inject(MAT_DIALOG_DATA) public data: any,
//private httpMessageService: IrisHttpMessageService,
private userService: UserService,
private router: Router,
private sharedService: SharedService,
private modalService: NgbModal,
@Inject(DOCUMENT) private document: Document,
private translateService: TranslateService,
) {
this.stateStore = data.stateStore;
this.courseId = data.courseId;
this.exerciseId = data.exerciseId;
this.sessionService = data.sessionService;
this.navigationSubscription = this.router.events.subscribe((event) => {
Expand Down Expand Up @@ -320,14 +321,26 @@ export class ExerciseChatWidgetComponent implements OnInit, OnDestroy, AfterView
}, 500);
}

/**
* Inserts the correct link to import the current programming exercise for a new variant generation.
*/
getFirstMessageContent(): string {
if (this.isChatSession()) {
return this.translateService.instant('artemisApp.exerciseChatbot.tutorFirstMessage');
}
this.importExerciseUrl = `/course-management/${this.courseId}/programming-exercises/import/${this.exerciseId}`;
return this.translateService
.instant('artemisApp.exerciseChatbot.codeEditorFirstMessage')
.replace(/{link:(.*)}/, '<a href="' + this.importExerciseUrl + '" target="_blank">$1</a>');
}

/**
* Loads the first message in the conversation if it's not already loaded.
*/
loadFirstMessage(): void {
const textContent = this.isChatSession() ? 'artemisApp.exerciseChatbot.tutorFirstMessage' : 'artemisApp.exerciseChatbot.codeEditorFirstMessage';
const firstMessageContent = {
type: IrisMessageContentType.TEXT,
textContent: textContent,
textContent: this.getFirstMessageContent(),
} as IrisMessageTextContent;

const firstMessage = {
Expand All @@ -337,10 +350,7 @@ export class ExerciseChatWidgetComponent implements OnInit, OnDestroy, AfterView
} as IrisArtemisClientMessage;

if (this.messages.length === 0) {
this.isFirstMessage = true;
this.stateStore.dispatch(new ActiveConversationMessageLoadedAction(firstMessage));
} else if (this.messages[0].sender === IrisSender.ARTEMIS_CLIENT) {
this.isFirstMessage = true;
}
}

Expand Down Expand Up @@ -737,10 +747,6 @@ export class ExerciseChatWidgetComponent implements OnInit, OnDestroy, AfterView
return getPlanComponent(content);
}

getComponentInstruction(component: IrisExercisePlanComponent) {
return getComponentInstruction(component);
}

isRateMessage() {
return this.sessionService.httpMessageService instanceof IrisHttpChatMessageService;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/i18n/en/exerciseChatbot.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"rateLimitExceeded": "You have reached the maximum number of messages you can send to Iris in a {{ hours }} hour window. Please try again later!"
},
"tutorFirstMessage": "Hi, I'm Iris! I can help you with your programming exercise. You can learn more about me <a href='/about-iris' target='_blank'>here</a>.",
"codeEditorFirstMessage": "Hi, I'm Iris! I can help you to create programming exercises. For example: <ul><li>create a brand-new exercise</li><li><a href='/' target='_blank'>create a variant of another existing exercise</a></li><li>adapt an existing exercise to new requirements</li></ul> You can learn more about me <a href='/about-iris' target='_blank'>here</a>.",
"codeEditorFirstMessage": "Hi, I'm Iris! I can help you to create programming exercises. For example: <ul><li>create a brand-new exercise</li><li>{link:create a variant of another existing exercise}</li><li>adapt an existing exercise to new requirements</li></ul> You can learn more about me <a href='/about-iris' target='_blank'>here</a>.",
"rateLimitTooltip": "This is the maximum number of messages you can send to Iris in a {{ hours }} hour window."
}
}
Expand Down

0 comments on commit 13dd601

Please sign in to comment.