Skip to content

Commit

Permalink
Merge branch 'master' into 7377-community-page-broken-for-tablets
Browse files Browse the repository at this point in the history
  • Loading branch information
dogi authored Dec 26, 2023
2 parents d3fac7c + e145ec2 commit f215a10
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 29 deletions.
2 changes: 1 addition & 1 deletion chatapi/src/models/db-doc.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export interface DbDoc {
_rev: string;
user: any;
title: string;
time: number;
createdDate: number;
conversations: [];
}
2 changes: 2 additions & 0 deletions chatapi/src/services/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export async function chat(data: any): Promise<{
} else {
dbData.title = content;
dbData.conversations = [];
dbData.createdDate = Date.now();
}

dbData.conversations.push({ 'query': content, 'response': '' });
Expand All @@ -35,6 +36,7 @@ export async function chat(data: any): Promise<{

dbData.conversations[dbData.conversations.length - 1].response = completionText;

dbData.updatedDate = Date.now();
dbData._id = res?.id;
dbData._rev = res?.rev;
const couchSaveResponse = await db.insert(dbData);
Expand Down
6 changes: 4 additions & 2 deletions chatapi/src/utils/db.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ async function getChatDocument(id: string) {
const res = await db.get(id) as DbDoc;
return {
'conversations': res.conversations,
'title': res.title
'title': res.title,
'createdDate': res.createdDate,
};
// Should return user, team data as well particularly for the "/conversations" endpoint
} catch (error) {
Expand All @@ -24,9 +25,10 @@ async function getChatDocument(id: string) {
}

export async function retrieveChatHistory(dbData: any, messages: ChatMessage[]) {
const { conversations, title } = await getChatDocument(dbData._id);
const { conversations, title, createdDate } = await getChatDocument(dbData._id);
dbData.conversations = conversations;
dbData.title = title;
dbData.createdDate = createdDate;

for (const { query, response } of conversations) {
messages.push({ 'role': 'user', 'content': query });
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
39 changes: 27 additions & 12 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 All @@ -74,7 +84,7 @@ export class ChatSidebarComponent implements OnInit, OnDestroy {

updateConversation(conversation, title) {
this.couchService.updateDocument(
this.dbName, { ...conversation, title: title, updatedTime: this.couchService.datePlaceholder }
this.dbName, { ...conversation, title: title, updatedDate: this.couchService.datePlaceholder }
).subscribe((data) => {
this.getChatHistory();
return data;
Expand All @@ -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/chat/chat-window/chat-window.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class ChatWindowComponent implements OnInit, OnDestroy {
promptForm: FormGroup;
data = {
user: this.userService.get().name,
time: this.couchService.datePlaceholder,
content: '',
_id: '',
_rev: ''
Expand Down Expand Up @@ -119,7 +118,8 @@ export class ChatWindowComponent implements OnInit, OnDestroy {

submitPrompt() {
const content = this.promptForm.get('prompt').value;
this.data.content = content;
this.data = { ...this.data, content };

this.setSelectedConversation();

this.chatService.getPrompt(this.data, true).subscribe(
Expand Down
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
7 changes: 5 additions & 2 deletions src/app/meetups/add-meetups/meetups-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,22 @@ export class MeetupsAddComponent implements OnInit {
private fb: FormBuilder,
private userService: UserService,
private stateService: StateService
) { }
) {
this.createForm();
}

ngOnInit() {
if (this.meetup._id) {
this.setMeetupData({ ...this.meetup });
} else {
this.createForm();
}
if (!this.isDialog && this.route.snapshot.url[0].path === 'update') {
this.couchService.get('meetups/' + this.route.snapshot.paramMap.get('id')).subscribe(
data => this.setMeetupData(data),
error => console.log(error)
);
}
this.createForm();
}

setMeetupData(meetup: any) {
Expand Down

0 comments on commit f215a10

Please sign in to comment.