Skip to content

Commit

Permalink
Merge branch 'master' into 6572-enterprises-calendar-add-a-legend
Browse files Browse the repository at this point in the history
  • Loading branch information
Mutugiii authored Dec 17, 2024
2 parents 9b92f51 + 8c8a955 commit 99e09d7
Show file tree
Hide file tree
Showing 119 changed files with 1,679 additions and 685 deletions.
160 changes: 104 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,102 +12,150 @@ Link to [Angular Doc](https://angular.io/docs) and [Material Design](https://mat

## To work on this

The only prerequisite is Vagrant. If you don't know about it, please do some research and try it. After cloning the repository, run `vagrant up dev` in the console. Once it's done installing the virtual machine it'll automatically start compiling the app. After about 10 seconds, you can open the app at `localhost:3000`.
For development, the following additional tools are required:

## Project guidelines
* Docker
* Git
* NPM v6
* Node.js v14
* Angular CLI v10

* Please check out [the project page](https://waffle.io/ole-vi/planet) for available tasks to work on.
* Before contributing also be sure to read our [style guide](Style-Guide.md)
* Please clone the repository rather than forking, unless you're from outside the organization. It's easier for us to collaborate from a new branch on the same repository.
* After cloning the repository please run `npm run install-hooks` to add the git hooks to your local repository.
* If you see something that needs work, please create an issue. If the issue is on the frontend, please try to make it specific to one component.
* To work on an issue, create a new branch with a descriptive title.
* Please wait for at least two positive reviews before merging a PR into the master branch
The only other prerequisite is Docker Desktop. After cloning the repository, follow the steps below to set up the development environment using Docker:

Create a directory for planet development data:
```
mkdir -p ~/srv/planetdev && cd ~/srv/planetdev
```

## Unit & end-to-end tests
Download the Docker Compose file:
For Linux:
```
wget https://raw.githubusercontent.com/ole-vi/planet-prod-configs/main/planet-dev.yml
```

There are two ways for running the tests. The first listed works from the host machine, and the second works after `vagrant ssh dev` and `cd /vagrant`:
For macOS/Windows:
```
curl https://gist.githubusercontent.com/xyb994/0d14dfe302df0df0d4e8d8df0d1d5feb/raw/planet-dev-mac.yml -o planet-dev.yml
```

`npm run v-test` (from host) or `ng test` (from vagrant) - Unit tests
Open `localhost:9876` once this is done compiling
Start the containers:
```
docker compose -f planet-dev.yml -p planet-dev up -d
```

`npm run v-e2e` (from host) or `ng e2e` (from vagrant) - End-to-end tests
Results will appear in the console
Verify container status:
Run ```docker ps -a``` after a minute. You should see two containers running: chatapi and couchdb. The db-init container should have exited.

## Enabling the Hub
Configure CORS for CouchDB:
```
git clone https://github.com/pouchdb/add-cors-to-couchdb.git
cd add-cors-to-couchdb
npm install
while ! curl -X GET http://127.0.0.1:2200/_all_dbs ; do sleep 1; done
node bin.js http://localhost:2200
```

On the production Vagrant there is an optional second Planet instance that can be run to test out "Hub" features.
Clone and configure the Planet project:
```
git clone https://github.com/open-learning-exchange/planet.git
cd planet
chmod +x couchdb-setup.sh
bash couchdb-setup.sh -p 2200 -i
```

To start the hub: `npm run hub-on`
The hub will be available at `localhost:3200`
Install dependencies and serve the app:
```
npm install
ng serve
```

To stop the hub: `npm run hub-off`
Visit localhost:3000 to access the Planet app.
If port 3000 is in use, try ```ng serve --port 3001```

To set the hub to automatically start on `vagrant up`, run the following: `npm run hub-boot-on`
## Project Guidelines

To disable autostart run following: `npm run hub-boot-off`
* Check out the project page for tasks.
* Before contributing also be sure to read our [style guide](Style-Guide.md).
* Please clone the repository rather than forking, unless you're from outside the organization. It's easier for us to collaborate from a new branch on the same repository.
* After cloning the repository please run `npm run install-hooks` to add the git hooks to your local repository.
* If you see something that needs work, please create an issue. If the issue is on the frontend, please try to make it specific to one component.
* To work on an issue, create a new branch with a descriptive title.
* Please wait for at least two positive reviews before merging a PR into the master branch

## Unit & End-to-End Tests

You can run tests directly from the host or within the development container.

### Unit Tests:
```
npm run test
```
Open `localhost:9876` once this is done compiling

### Additional commands
### End-to-End Tests:
```
npm run e2e
```
Results will appear in the console

Similarly, we have a few other npm commands that work from the host machine to run the `ng` commands from the [Angular CLI](https://cli.angular.io/)
## Additional Commands

`npm run v-serve` = `ng serve`

`npm run v-build` = `ng build`
Run: `ng serve`

`npm run v-lint` = `ng lint`
Build: `ng build`

`npm run v-lint-fix` = `ng lint --fix` This will fix any lint errors that TSLint can automatically fix
Lint: `ng lint`

Also, the `npm start` command can include an additional `LNG` variable to serve from different language files. This must be run from within the vagrant (so after `vagrant ssh dev` and `cd /vagrant`) and runs in the format:
This will fix any lint errors that TSLint can automatically fix:
`Fix Lint: ng lint --fix`

`LNG=es npm start`

This would serve the app from the Spanish language files.
To serve the app in a different language, use the LNG variable:
`
LNG=es npm start
`

## Troubleshooting

### I switched branches and now I'm missing a dependency...

The ideal solution would be to ssh into your vagrant and run npm install:

```
vagrant ssh dev
cd /vagrant
Run the following command to reinstall dependencies:
`
npm install
```
`

This doesn't always work. If you're having trouble or need to revert to the exact dependencies listed on the package.json, you need to remove all packages then install (after cd /vagrant above, run the commands):
If issues persist, delete and reinstall dependencies:

```
sudo rm -rf node_modules/*
sudo npm install --unsafe-perm
```

The trailing `/*` will remove all files & sub-directories of node_modules. You won't be able to remove node_modules because of the link between the vagrant VM and your host.

### Cannot create new members in development environment or database missing
rm -rf node_modules/*
npm install
````
Sometimes our custom setup for the `_users` database is overwritten by the default or new databases were added in other commits that have not been created in your local environment. If you are seeing errors with lack of authorization or missing databases, you can run the following command to run our database setup script again:
### Missing database or authentication issues
Run the CouchDB setup script:
```
./v-couchdb-setup.sh -u <your admin username> -w <your admin password>
./v-couchdb-setup.sh -u <admin-username> -w <admin-password>
```

### Cannot GET /
There are two things you can try for this. First is to reinstall the node packages with:

Reinstall packages:
```
vagrant ssh dev
cd /vagrant
sudo rm -rf node_modules/*
rm -rf node_modules/*
rm package-lock.json
sudo npm install --unsafe-perm
npm install
```
Restart the app:
`
ng serve
`
The second is to rebuild the application. First you need to cancel the app in the screen with `screen -x` then CTRL-C. Then you can bring the app back up with one of the above commands or in another screen session with `screen -dmS build bash -c 'cd /vagrant; ng serve'`.
### Mime.getType does not exist (Windows)
Use Mime 3.0.0
```
npm i [email protected]
npm i @types/mime@3.0.0
```
---
This project is tested with [BrowserStack](https://www.browserstack.com/).
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "planet",
"license": "AGPL-3.0",
"version": "0.15.42",
"version": "0.16.8",
"myplanet": {
"latest": "v0.20.94",
"min": "v0.19.94"
"latest": "v0.21.42",
"min": "v0.20.42"
},
"scripts": {
"ng": "ng",
Expand Down
53 changes: 46 additions & 7 deletions src/app/chat/chat-sidebar/chat-sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MatDialog } from '@angular/material/dialog';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

import { Conversation } from '../chat.model';
import { Conversation, AIProvider } from '../chat.model';
import { ChatService } from '../../shared/chat.service';
import { CouchService } from '../../shared/couchdb.service';
import { DeviceInfoService, DeviceType } from '../../shared/device-info.service';
Expand Down Expand Up @@ -33,6 +33,7 @@ export class ChatSidebarComponent implements OnInit, OnDestroy {
selectedConversation: Conversation;
lastRenderedConversation: number;
isEditing: boolean;
provider: AIProvider;
fullTextSearch = false;
searchType: 'questions' | 'responses';
overlayOpen = false;
Expand All @@ -56,6 +57,7 @@ export class ChatSidebarComponent implements OnInit, OnDestroy {
this.titleSearch = '';
this.getChatHistory();
this.subscribeToNewChats();
this.subscribeToAIService();
}

ngOnDestroy() {
Expand All @@ -71,14 +73,39 @@ export class ChatSidebarComponent implements OnInit, OnDestroy {
subscribeToNewChats() {
this.chatService.newChatAdded$
.pipe(takeUntil(this.onDestroy$))
.subscribe(() => this.getChatHistory());
.subscribe(() => this.getChatHistory(true));
}

subscribeToAIService() {
this.chatService.toggleAIService$
.pipe(takeUntil(this.onDestroy$))
.subscribe((aiService => {
this.provider = {
name: aiService
};
this.hasProviderChanged();
}));
}

newChat() {
this.chatService.sendNewChatSelectedSignal();
this.chatService.setChatAIProvider(undefined);
this.selectedConversation = null;
}

hasProviderChanged() {
const currentProvider = this.chatService.getChatAIProvider();
if (!currentProvider) {
// That means it's a brand-new chat
return;
}
if (currentProvider.name === this.provider.name) {
// That means the same model is still being used
return;
}
this.newChat();
}

toggleEditTitle() {
this.isEditing = !this.isEditing;
}
Expand All @@ -94,7 +121,7 @@ export class ChatSidebarComponent implements OnInit, OnDestroy {
title: title !== undefined && title !== null ? title : conversation.title,
shared: shared,
updatedDate: this.couchService.datePlaceholder
}
}
).subscribe((data) => {
this.getChatHistory();
return data;
Expand All @@ -119,7 +146,7 @@ export class ChatSidebarComponent implements OnInit, OnDestroy {
});
}

getChatHistory() {
getChatHistory(newChat: boolean = false) {
this.chatService
.findConversations([], [ this.userService.get().name ])
.subscribe(
Expand All @@ -133,6 +160,9 @@ export class ChatSidebarComponent implements OnInit, OnDestroy {
return dateB - dateA;
});
this.filteredConversations = [ ...this.conversations ];
if (newChat) {
this.selectConversation(this.filteredConversations[0], 0);
}
this.initializeFormGroups();
},
(error) => console.log(error)
Expand All @@ -141,6 +171,11 @@ export class ChatSidebarComponent implements OnInit, OnDestroy {

selectConversation(conversation, index: number) {
this.selectedConversation = conversation;
const aiProvider: AIProvider = {
name: this.selectedConversation['aiProvider'],
};
this.chatService.setChatAIProvider(aiProvider);
const currentProvider = this.chatService.getChatAIProvider();
this.chatService.setSelectedConversationId({
'_id': conversation?._id,
'_rev': conversation?._rev
Expand Down Expand Up @@ -211,14 +246,18 @@ export class ChatSidebarComponent implements OnInit, OnDestroy {
}

openShareDialog(conversation) {
this.dialog.open(DialogsChatShareComponent, {
const dialogRef = this.dialog.open(DialogsChatShareComponent, {
width: '50vw',
maxHeight: '90vh',
data: {
news: conversation,
}
});
this.updateConversation(conversation, null, true);
}

dialogRef.afterClosed().subscribe((result) => {
if (result) {
this.updateConversation(conversation, null, true);
}
});
}
}
2 changes: 1 addition & 1 deletion src/app/chat/chat-window/chat-window.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<mat-form-field class="full-width mat-form-field-type-no-underline">
<mat-label i18n>Chat</mat-label>
<div class="textarea-container">
<textarea matInput [formControl]="promptForm.controls.prompt" rows="5" placeholder="Send a message" i18n-placeholder></textarea>
<textarea #chatInput matInput [formControl]="promptForm.controls.prompt" rows="5" placeholder="Send a message" i18n-placeholder></textarea>
<button
mat-icon-button
[planetSubmit]="promptForm.valid && spinnerOn"
Expand Down
Loading

0 comments on commit 99e09d7

Please sign in to comment.