Skip to content

Commit

Permalink
Merge branch 'master' into 7911-myprogress-course-names-should-link-y…
Browse files Browse the repository at this point in the history
…ou-to-the-course
  • Loading branch information
dogi authored Dec 17, 2024
2 parents bbc2948 + 7f741bd commit 9162794
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"license": "AGPL-3.0",
"version": "0.16.7",
"myplanet": {
"latest": "v0.21.40",
"min": "v0.20.40"
"latest": "v0.21.42",
"min": "v0.20.42"
},
"scripts": {
"ng": "ng",
Expand Down
22 changes: 18 additions & 4 deletions src/app/chat/chat-window/chat-window.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, OnDestroy, ViewChild, ElementRef, ChangeDetectorRef, Input, AfterViewInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { filter, takeUntil } from 'rxjs/operators';

import { CustomValidators } from '../../validators/custom-validators';
import { ConversationForm, AIProvider } from '../chat.model';
Expand All @@ -20,6 +20,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy, AfterViewInit {
spinnerOn = true;
streaming: boolean;
disabled = false;
clearChat = true;
provider: AIProvider;
conversations: any[] = [];
selectedConversationId: any;
Expand Down Expand Up @@ -71,8 +72,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy, AfterViewInit {
this.chatService.newChatSelected$
.pipe(takeUntil(this.onDestroy$))
.subscribe(() => {
this.selectedConversationId = null;
this.conversations = [];
this.resetConversation();
this.focusInput();
}, error => {
console.error('Error subscribing to newChatSelected$', error);
Expand All @@ -81,7 +81,16 @@ export class ChatWindowComponent implements OnInit, OnDestroy, AfterViewInit {

subscribeToSelectedConversation() {
this.chatService.selectedConversationId$
.pipe(takeUntil(this.onDestroy$))
.pipe(
takeUntil(this.onDestroy$),
filter(() => {
if (this.clearChat) {
this.clearChat = false;
return false;
}
return true;
})
)
.subscribe((conversationId) => {
this.selectedConversationId = conversationId;
this.fetchConversation(this.selectedConversationId?._id);
Expand All @@ -102,6 +111,11 @@ export class ChatWindowComponent implements OnInit, OnDestroy, AfterViewInit {
}));
}

resetConversation() {
this.conversations = [];
this.selectedConversationId = null;
}

createForm() {
this.promptForm = this.formBuilder.group({
prompt: [ '', CustomValidators.required ],
Expand Down
6 changes: 4 additions & 2 deletions src/app/courses/courses.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export class CoursesService {

courseResignAdmission(courseId, type, courseTitle?) {
const title = courseTitle ? courseTitle : this.getCourseNameFromId(courseId);
const truncatedTitle = title.length > 180 ? `${title.slice(0, 180)}...` : title;
const courseIds: any = [ ...this.userService.shelf.courseIds ];
if (type === 'resign') {
const myCourseIndex = courseIds.indexOf(courseId);
Expand All @@ -211,8 +212,9 @@ export class CoursesService {
courseIds.push(courseId);
}
return this.userService.updateShelf(courseIds, 'courseIds').pipe(map((res) => {
const admissionMessage = type === 'resign' ? $localize`${title} successfully removed from myCourses` :
$localize`${title} added to your dashboard`;
const admissionMessage = type === 'resign'
? $localize`${truncatedTitle} successfully removed from myCourses`
: $localize`${truncatedTitle} added to your dashboard`;
this.planetMessageService.showMessage(admissionMessage);
return res;
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { dedupeObjectArray } from '../../shared/utils';
import { DialogsLoadingService } from '../../shared/dialogs/dialogs-loading.service';
import { findDocuments } from '../../shared/mangoQueries';
import { UserProfileDialogComponent } from '../../users/users-profile/users-profile-dialog.component';
import { StateService } from '../../shared/state.service';
import { DeviceInfoService, DeviceType } from '../../shared/device-info.service';

@Component({
Expand All @@ -31,6 +32,7 @@ export class CoursesProgressLeaderComponent implements OnInit, OnDestroy {
submittedExamSteps: any[] = [];
planetCodes: string[] = [];
selectedPlanetCode: string;
configuration: any = {};
deviceType: DeviceType;
deviceTypes = DeviceType;

Expand All @@ -42,6 +44,7 @@ export class CoursesProgressLeaderComponent implements OnInit, OnDestroy {
private csvService: CsvService,
private dialogsLoadingService: DialogsLoadingService,
private dialog: MatDialog,
private stateService: StateService,
private deviceInfoService: DeviceInfoService
) {
this.dialogsLoadingService.start();
Expand Down Expand Up @@ -221,23 +224,41 @@ export class CoursesProgressLeaderComponent implements OnInit, OnDestroy {
}

structureChartData(data) {
const dataArr = [];
data.forEach(element => {
const dataDict = {};
dataDict['Username'] = element.label;
for (let i = 0; i < element.items.length; i++) {
dataDict[`Step ${(i + 1)}`] = element.items[i].number;
}
return data.map(element => {
let successfulSteps = 0;
let totalSteps = 0;
let totalErrors = 0;
const steps = {};

dataArr.push(dataDict);
element.items.forEach((item, index) => {
const stepErrors = item.number || 0;
totalSteps++;
if (stepErrors === 0) {
successfulSteps++;
}
totalErrors += stepErrors;
steps[`Step ${(index + 1)}`] = stepErrors;
});

return {
'Username': element.label,
'Success Percentage': `${((successfulSteps / totalSteps) * 100).toFixed(2)}%`,
'Total Errors': totalErrors,
...steps
};
});
return dataArr;
}

exportChartData() {
const planetName = this.stateService.configuration.name;
const courseTitle = this.course.courseTitle;
const entityLabel = this.configuration.planetType === 'nation' ? 'Nation' : 'Community';
const title = $localize`${courseTitle} Course Progress for ${entityLabel} ${planetName}`;

const structuredData = this.structureChartData(this.chartData);
this.csvService.exportCSV({
data: this.structureChartData(this.chartData),
title: $localize`Course Progress Data`
data: structuredData,
title: title
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@

<ng-template #actionButtons>
<ng-container *ngIf="!parent">
<a mat-raised-button *ngIf="resource.doc?._attachments" [href]="resourceSrc" target="_blank" color="accent" i18n>Open in new tab</a>
<button mat-raised-button color="accent" (click)="libraryToggle(resource._id, 'add')" i18n class="margin-lr-3" *ngIf="!isUserEnrolled">
<a mat-raised-button *ngIf="resource.doc?._attachments" [href]="resourceSrc" target="_blank" color="accent" i18n class = "toolbar-button margin-lr-3">Open in new tab</a>
<button mat-raised-button color="accent" (click)="libraryToggle(resource._id, 'add')" i18n class="toolbar-button margin-lr-3" *ngIf="!isUserEnrolled">
Add to myLibrary
</button>
<button mat-raised-button color="accent" (click)="libraryToggle(resource._id, 'remove')" i18n class="margin-lr-3" *ngIf="isUserEnrolled">
<button mat-raised-button color="accent" (click)="libraryToggle(resource._id, 'remove')" i18n class="toolbar-button margin-lr-3" *ngIf="isUserEnrolled">
Remove from myLibrary
</button>
</ng-container>
Expand Down
4 changes: 4 additions & 0 deletions src/app/resources/view-resources/resources-view.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
max-height: 60vh;
}
}

.toolbar-button {
flex-shrink: 0;
}

@media (max-width: $screen-sm) {
.view-container {
Expand Down

0 comments on commit 9162794

Please sign in to comment.