Skip to content

Commit

Permalink
added: imageRepoService abstract service to recover chatbot profile i…
Browse files Browse the repository at this point in the history
…mage
  • Loading branch information
Gabriele Panico committed Nov 22, 2023
1 parent 7bff589 commit d05eb80
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ScriptService } from 'src/chat21-core/providers/scripts/script.service'
import { NetworkService } from './services/network.service';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { NetworkOfflineComponent } from './modals/network-offline/network-offline.component';
import { ImageRepoService } from 'src/chat21-core/providers/abstract/image-repo.service';

@Component({
selector: 'app-root',
Expand Down Expand Up @@ -44,6 +45,7 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
private userService: UsersService,
private multiChannelService: MultichannelService,
private uploadService: UploadService,
private imageRepoService: ImageRepoService,
private scriptService: ScriptService,
private networkService: NetworkService,
){
Expand Down
7 changes: 6 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HomeComponent } from './components/home/home.component';
import { NotFoundComponent } from './components/not-found/not-found.component';
import { NetworkService } from './services/network.service';
import { ImageRepoService } from 'src/chat21-core/providers/abstract/image-repo.service';

// FACTORIES
export function createTranslateLoader(http: HttpClient) {
Expand Down Expand Up @@ -96,7 +97,6 @@ export function imageRepoFactory(appConfig: AppConfigService, http: HttpClient)
}

export function uploadFactory(http: HttpClient, appConfig: AppConfigService, appStorage: AppStorageService) {

const config = appConfig.getConfig()
if (config.uploadEngine === UPLOAD_ENGINE_NATIVE) {
const nativeUploadService = new NativeUploadService(http, appStorage)
Expand Down Expand Up @@ -178,6 +178,11 @@ export function uploadFactory(http: HttpClient, appConfig: AppConfigService, app
useFactory: uploadFactory,
deps: [HttpClient, AppConfigService, AppStorageService]
},
{
provide: ImageRepoService,
useFactory: imageRepoFactory,
deps: [AppConfigService, HttpClient]
},
{
provide: AppStorageService,
useClass: LocalSessionStorage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h3 class="card_title__underlined">
<div class="card-avatar" style="display: flex;align-items: center;">
<div class="bot_avatar">

<img class="bot-profile-img" [src]="selectedChatbot?.url" onerror="this.src='assets/images/avatar_bot_tiledesk.svg'" />
<img class="bot-profile-img" [src]="selectedChatbot?.imageURL" onerror="this.src='assets/images/avatar_bot_tiledesk.svg'" />
<!-- <img *ngIf="botProfileImageExist === false" class="bot-profile-img" src="assets/images/avatar_bot_tiledesk.svg"/> -->

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { UploadService } from 'src/chat21-core/providers/abstract/upload.service
import { TiledeskAuthService } from 'src/chat21-core/providers/tiledesk/tiledesk-auth.service';
import { UserModel } from 'src/chat21-core/models/user';
import { UploadModel } from 'src/chat21-core/models/upload';
import { ImageRepoService } from 'src/chat21-core/providers/abstract/image-repo.service';
const swal = require('sweetalert');

@Component({
Expand Down Expand Up @@ -80,7 +81,7 @@ export class CDSDetailBotDetailComponent extends BotsBaseComponent implements On
private departmentService: DepartmentService,
private router: Router,
private notify: NotifyService,
private sanitizer: DomSanitizer,
private imageRepoService: ImageRepoService,
private translate: TranslateService,
public dialog: MatDialog,
) { super(); }
Expand Down Expand Up @@ -260,8 +261,10 @@ export class CDSDetailBotDetailComponent extends BotsBaseComponent implements On
destructureSelectedChatbot(selectedChatbot: Chatbot) {
this.logger.log('[CDS-CHATBOT-DTLS] - selectedChatbot', this.selectedChatbot)
if (this.selectedChatbot._id) {
this.checkImageExists(this.selectedChatbot.url, (existImage)=> {
existImage? this.botProfileImageExist = true: this.botProfileImageExist= false;
let url = this.imageRepoService.getImagePhotoUrl(this.selectedChatbot._id)
console.log('urlllll', url)
this.checkImageExists(url, (existImage)=> {
existImage? this.selectedChatbot.imageURL = url: null;
})
}

Expand Down Expand Up @@ -470,7 +473,7 @@ export class CDSDetailBotDetailComponent extends BotsBaseComponent implements On
this.uploadService.uploadProfile(this.selectedChatbot._id, currentUpload).then(downloadURL => {
that.logger.debug(`[IMAGE-UPLOAD] Successfully uploaded file and got download link - ${downloadURL}`);

// that.selectedChatbot.url = downloadURL;
that.selectedChatbot.imageURL = downloadURL;
this.botProfileImageExist = true
that.isFilePendingToUpload = false;
// return downloadURL;
Expand All @@ -492,8 +495,7 @@ export class CDSDetailBotDetailComponent extends BotsBaseComponent implements On
this.logger.log('[CDS-CHATBOT-DTLS] BOT PROFILE IMAGE (FAQ-COMP) deleteBotProfileImage')
this.uploadService.deleteProfile(this.selectedChatbot._id, this.selectedChatbot.url).then((result)=>{
this.botProfileImageExist = false;
this.selectedChatbot.url = null

this.selectedChatbot.imageURL = null
const delete_bot_image_btn = <HTMLElement>document.querySelector('#cds-delete-bot-img-btn');
delete_bot_image_btn.blur();
}).catch((error)=> {
Expand Down
3 changes: 2 additions & 1 deletion src/app/models/faq_kb-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export interface Chatbot extends FaqKb {
title?: string;
short_description?: string;
certifiedTags?: Array<{color: string, name: string}>;
intentsEngine?: 'none' | 'tiledesk-ai'
intentsEngine?: 'none' | 'tiledesk-ai',
imageURL: string;
}

0 comments on commit d05eb80

Please sign in to comment.