Skip to content

Commit

Permalink
Merge branch 'master' into 7386-courses-language-based-filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
dogi authored Dec 27, 2023
2 parents 53b6a6f + 33ebccd commit 8e679cf
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 25 deletions.
8 changes: 6 additions & 2 deletions chatapi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,25 @@ app.post('/', async (req: any, res: any) => {
try {
const { data, save } = req.body;

if (typeof data !== 'object' || Array.isArray(data) || Object.keys(data).length === 0) {
res.status(400).json({ 'error': 'Bad Request', 'message': 'The "data" field must be a non-empty object' });
}

if (!save) {
const response = await chatNoSave(data.content);
res.status(200).json({
'status': 'Success',
'chat': response
});
} else if (save && data && typeof data === 'object') {
} else if (save) {
const response = await chat(data);
res.status(201).json({
'status': 'Success',
'chat': response?.completionText,
'couchDBResponse': response?.couchSaveResponse
});
} else {
res.status(400).json({ 'error': 'Bad Request', 'message': 'The "data" field must be a non-empty object' });
res.status(400).json({ 'error': 'Bad Request', 'message': 'Error processing "data" object' });
}
} catch (error: any) {
res.status(500).json({ 'error': 'Internal Server Error', 'message': error.message });
Expand Down
4 changes: 4 additions & 0 deletions chatapi/src/services/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export async function chat(data: any): Promise<{
const { content, ...dbData } = data;
const messages: ChatMessage[] = [];

if (!content) {
throw new Error('"data.content" is a required non-empty field');
}

if (dbData._id) {
await retrieveChatHistory(dbData, messages);
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/app/chat/chat-sidebar/chat-sidebar.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<mat-drawer-container class="sidebar-drawer" autosize>
<mat-drawer #drawer mode="side">
<mat-drawer #drawer mode="side" [opened]="deviceType !== deviceTypes.MOBILE">
<div class="header-container">
<div class="header" i18n>
<button type="button" mat-stroked-button color="primary" class="start-button" mat-button (click)="newChat()">
<button type="button" mat-raised-button color="primary" mat-button (click)="newChat()">
<mat-icon>add</mat-icon> Start New Chat
</button>
<button class="icon-button" mat-icon-button (click)="drawer.toggle()"><i class="material-icons">chevron_left</i></button>
Expand Down Expand Up @@ -30,7 +30,7 @@
</div>
<ng-container *ngIf="filteredConversations?.length; else noChats">
<ul>
<li *ngFor="let conversation of filteredConversations.reverse(); let i = index" (click)="selectConversation(conversation)">
<li *ngFor="let conversation of filteredConversations; let i = index" (click)="selectConversation(conversation)">
<ng-container *ngIf="isEditing; else notEditing">
<ng-container *ngIf="selectedConversation?._id === conversation?._id; else conversationTitle">
<form [formGroup]="titleForm[conversation?._id]" (ngSubmit)="submitTitle(conversation)">
Expand Down
37 changes: 26 additions & 11 deletions src/app/chat/chat-sidebar/chat-sidebar.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Component, OnInit, OnDestroy, HostListener } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

import { ChatService } from '../../shared/chat.service';
import { CouchService } from '../../shared/couchdb.service';
import { DeviceInfoService, DeviceType } from '../../shared/device-info.service';
import { SearchService } from '../../shared/forms/search.service';
import { showFormErrors } from '../../shared/table-helpers';
import { UserService } from '../../shared/user.service';
Expand All @@ -17,29 +18,34 @@ import { UserService } from '../../shared/user.service';
export class ChatSidebarComponent implements OnInit, OnDestroy {
readonly dbName = 'chat_history';
private onDestroy$ = new Subject<void>();
private _titleSearch = '';
get titleSearch(): string { return this._titleSearch.trim(); }
set titleSearch(value: string) {
this._titleSearch = value;
this.recordSearch();
this.filterConversations();
}
conversations: any;
filteredConversations: any;
selectedConversation: any;
isEditing: boolean;
fullTextSearch = false;
searchType: 'questions' | 'responses';
overlayOpen = false;
deviceType: DeviceType;
deviceTypes: typeof DeviceType = DeviceType;
titleForm: { [key: string]: FormGroup } = {};
private _titleSearch = '';
get titleSearch(): string { return this._titleSearch.trim(); }
set titleSearch(value: string) {
this._titleSearch = value;
this.recordSearch();
this.filterConversations();
}

constructor(
private chatService: ChatService,
private couchService: CouchService,
private deviceInfoService: DeviceInfoService,
private formBuilder: FormBuilder,
private searchService: SearchService,
private userService: UserService
) {}
) {
this.deviceType = this.deviceInfoService.getDeviceType();
}

ngOnInit() {
this.titleSearch = '';
Expand All @@ -53,6 +59,10 @@ export class ChatSidebarComponent implements OnInit, OnDestroy {
this.recordSearch(true);
}

@HostListener('window:resize') OnResize() {
this.deviceType = this.deviceInfoService.getDeviceType();
}

subscribeToNewChats() {
this.chatService.newChatAdded$
.pipe(takeUntil(this.onDestroy$))
Expand Down Expand Up @@ -101,8 +111,13 @@ export class ChatSidebarComponent implements OnInit, OnDestroy {

getChatHistory() {
this.chatService.findConversations([], [ this.userService.get().name ]).subscribe(
(conversations) => {
this.conversations = conversations;
(conversations: any) => {
this.conversations = conversations.sort((a, b) => {
const dateA = a.updatedDate || a.createdDate;
const dateB = b.updatedDate || b.createdDate;

return dateB - dateA;
});
this.filteredConversations = [ ...conversations ];
this.initializeFormGroups();
},
Expand Down
6 changes: 1 addition & 5 deletions src/app/chat/chat-sidebar/chat-sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
.header {
padding: 10px;

.start-button {
border: solid;
margin-right: 0.5rem;
}

.icon-button {
margin-left: 10px;
background-color: $accent;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/community/community.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ <h3 style="text-align: right; margin-right: 0.5rem;">
<mat-tab i18n-label label="Reports">
<planet-teams-reports [reports]="reports" [editable]="isCommunityLeader && !planetCode" [team]="team" (reportsChanged)="dataChanged()"></planet-teams-reports>
</mat-tab>
<mat-tab i18n-label label="Calendar" *ngIf="deviceType === deviceTypes.MOBILE">
<mat-tab i18n-label label="Calendar" *ngIf="deviceType !== deviceTypes.DESKTOP">
<planet-calendar [resizeCalendar]="resizeCalendar" [link]="{ teams: teamId }" [sync]="{ type: 'sync', planetCode: planetCode || configuration.code }"></planet-calendar>
</mat-tab>
</mat-tab-group>
</div>
<planet-calendar *ngIf="deviceType != deviceTypes.MOBILE" [link]="{ teams: teamId }" [sync]="{ type: 'sync', planetCode: planetCode || configuration.code }"></planet-calendar>
<planet-calendar *ngIf="deviceType === deviceTypes.DESKTOP" [link]="{ teams: teamId }" [sync]="{ type: 'sync', planetCode: planetCode || configuration.code }"></planet-calendar>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ <h3 class="margin-lr-3 ellipsis-title"><ng-container i18n>Step</ng-container> {{
</mat-select>
</mat-form-field>
<span>{{stepNum}}/{{maxStep}}</span>
<button mat-icon-button [disabled]="stepNum === 1" (click)="changeStep(-1)"><mat-icon>navigate_before</mat-icon></button>
<button mat-icon-button *ngIf="maxStep !== 1" [disabled]="stepNum === 1" (click)="changeStep(-1)"><mat-icon>navigate_before</mat-icon></button>
<button mat-icon-button *ngIf="stepNum !== maxStep" [disabled]="stepNum === maxStep || (!parent && stepDetail?.exam?.questions.length > 0 && !attempts)" (click)="changeStep(1)"><mat-icon>navigate_next</mat-icon></button>
<button *ngIf="stepNum === maxStep" mat-raised-button color="basic" (click)="backToCourseDetail()">Finish</button>
<button mat-raised-button *ngIf="stepNum === maxStep && maxStep !== 1" [disabled]="!parent && stepDetail?.exam?.questions.length > 0 && !attempts" (click)="backToCourseDetail()">Finish</button>
</div>
</mat-toolbar>
<div class="view-container view-full-height" *ngIf="stepDetail?.description || resource?._attachments; else emptyRecord">
Expand Down

0 comments on commit 8e679cf

Please sign in to comment.