Skip to content

Commit

Permalink
Implemented deleting drStories and added synth in progress popups
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMockler committed Aug 12, 2024
1 parent 5b7093d commit 34f9aa7
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 51 deletions.
29 changes: 18 additions & 11 deletions api/src/endpoint/drStory/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@ const DigitalReaderSentenceAudio = require('../../models/drSentenceAudio');
module.exports = async (req, res) => {
let storyFoundAndRemoved = false;

console.log(req.params.drStoryId)

DigitalReaderStory.findOneAndRemove({ _id: req.params.drStoryId }, (err, drStory) => {
if (err) {
console.log(err);
return res.json(err);
} else storyFoundAndRemoved = true;
} else {
//console.log(drStory)
DigitalReaderSentenceAudio.remove(
{drStoryId: req.params.drStoryId},
(err, sentenceAudios) => {
if (err) {
console.log(err);
res.json(err);
} else res.json('Digital Reader Story removed sucessfully')
}
)
}
})

/*console.log(storyFoundAndRemoved)
if (storyFoundAndRemoved) {
DigitalReaderSentenceAudio.remove(
{drStoryId: req.params.drStoryId},
(err, sentenceAudios) => {
if (err) {
console.log(err);
res.json(err);
} else res.json('Digital Reader Story removed sucessfully')
}
)
}
} else res.json('error removing Digital Reader story');*/
};
7 changes: 5 additions & 2 deletions api/src/endpoint/drStory/synthesiseAndStoreSent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const DigitalReaderStory = require('../../models/drStory');
const {API500Error} = require('../../utils/APIError');
const axios = require('axios');

const mongoose = require('mongoose');

const http = axios.create({
baseURL: "https://abair.ie/api2",
Expand Down Expand Up @@ -32,7 +33,7 @@ async function synthesiseAndStoreSent (req:any) {
voice: req.body.voiceCode
});
console.log(story)
if (!(Array.isArray(story) && story.length!==0)) {
if (!(Array.isArray(story) && story.length!==0) && drStory) {

// make a call to the synthesis API
console.log('storing!')
Expand Down Expand Up @@ -83,7 +84,9 @@ async function synthesiseAndStoreSent (req:any) {
let reqBody: any;

// check that the story still exists (hasn't been deleted)
const drStory = DigitalReaderStory.find({drStoryId: req.body.drStoryId});
//const drStory = await DigitalReaderStory.findOne({drStoryId: req.body.drStoryId});
const drStory = await DigitalReaderStory.findById(new mongoose.mongo.ObjectId(req.body.drStoryId))
console.log(drStory)
if (!drStory) return no();

// prepare the body of the call to the synthesis API
Expand Down
2 changes: 1 addition & 1 deletion ngapp/src/app/core/services/dr-story.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class DigitalReaderStoryService {

deleteDRStory(drStoryId:string) {

return this.http.get<any[]>(this.baseUrl + 'drStory/sentenceAudio' + drStoryId);
return this.http.get<any[]>(this.baseUrl + 'drStory/delete/' + drStoryId);
}

runTestQueue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { MatMenuModule } from "@angular/material/menu";
import { MatIconModule } from "@angular/material/icon";
import { MatButtonModule } from "@angular/material/button";
import { MatSidenavModule } from "@angular/material/sidenav";
import { MatSnackBar, MatSnackBarModule } from "@angular/material/snack-bar";

const dialectToVoiceIndex = new Map<string, number>([
["Connacht f", 0],
Expand All @@ -50,7 +51,8 @@ const dialectToVoiceIndex = new Map<string, number>([
MatMenuModule,
MatIconModule,
MatButtonModule,
MatSidenavModule
MatSidenavModule,
MatSnackBarModule
],
selector: "app-dr-story-builder",
templateUrl: "./dr-story-builder.component.html",
Expand Down Expand Up @@ -92,6 +94,7 @@ export class DigitalReaderStoryBuilderComponent implements OnInit {
public voiceIndex:number = 0;
public speaker = this.functioningVoices[this.voiceIndex]; // defaults to Sibéal nemo


constructor(

private auth: AuthenticationService,
Expand All @@ -101,6 +104,7 @@ export class DigitalReaderStoryBuilderComponent implements OnInit {
public ts: TranslationService,
protected sanitizer: DomSanitizer,
private drStoryService: DigitalReaderStoryService,
public snackbar:MatSnackBar
) {}

async ngOnInit() {
Expand All @@ -116,14 +120,6 @@ export class DigitalReaderStoryBuilderComponent implements OnInit {

// only for testing
const firstSentSpans = this.content?.querySelectorAll('.sentence')
/*for (let i=0;i<3;i++) {
const sent = firstSentSpans.item(i)
this.synthRequest(sent?.textContent, this.speaker).then( (data) => {
console.log(data)
this.listOfAudios[this.voiceIndex][i] = data // only for testing
console.log(this.listOfAudios)
})
}*/

const allGeneratedAudio = await firstValueFrom(this.drStoryService.getSynthAudio(this.storyId));
console.log(allGeneratedAudio);
Expand All @@ -132,17 +128,39 @@ export class DigitalReaderStoryBuilderComponent implements OnInit {
this.sortGeneratedAudio(allGeneratedAudio, firstSentSpans);
console.log(this.listOfAudios);

/*for (let i=0;i<30;i++) {
const testQueue = firstValueFrom(this.drStoryService.runTestQueue(`${i}`,
'ga_UL_anb_nemo',
'MP3',
1,
this.storyId,
0));
//console.log(testQueue);
}*/

//console.log(testQueue);
let allAudioSynthesised = true;
const numSentences = firstSentSpans.length;
for (let entry of dialectToVoiceIndex.entries()) { // check if all sentences have been synthesised
const voiceIndex = entry[1];
if (this.listOfAudios[voiceIndex].length !== numSentences) {
allAudioSynthesised = false;
}
}
if (!allAudioSynthesised) {
const dialectToVoiceIndexArr = Array.from(dialectToVoiceIndex.entries());
if (dialectToVoiceIndexArr.length>1) {
const firstVoiceIndex = dialectToVoiceIndexArr[0][1];
const numSynthesisedSents = this.listOfAudios[firstVoiceIndex].length;
// check if all speakers have the same no. of sentences synthesised,
// in which case there is a problem with synthesising one or more sentences
if (dialectToVoiceIndexArr.every( (entry) => {
const voiceIndex = entry[1];
if (this.listOfAudios[voiceIndex].length!==numSynthesisedSents) return false;
else return true;
} )) {
this.snackbar.open(this.ts.l.problem_with_synth, this.ts.l.okay, {duration: 4000});
} else {
this.snackbar.open(this.ts.l.synth_in_progress, this.ts.l.okay, {duration: 4000});
}
} else {
this.snackbar.open(this.ts.l.synth_in_progress, this.ts.l.okay, {duration: 4000});
}
/*if ((...(dialectToVoiceIndex.entries())).every())
for (let entry of dialectToVoiceIndex.entries()) {
const voiceIndex = entry[1];
}*/

}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
<!--appFilter below not working correctly here-->
<div *ngFor="let story of storyList | appFilter : searchText; let i = index" style="display: flex;">
<!-- story entry-->
<div class="contentSection" [attr.id]="story._id">
<div class="contentSection" [attr.id]="story._id" (click)="openStory(story, $event)">
<!-- date and menu icon-->
<div class="contentsDateContainer">
<div class="contentsDate">
<!--{{ story.updatedAt | date : "d/M/yy" }}-->

<button mat-icon-button [matMenuTriggerFor]="menu" aria-label="Options to delete or rename your story"
*ngIf="story.owner===user._id">
*ngIf="story.owner===user._id" (click)="$event.stopPropagation()">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item >
<button mat-menu-item (click)="openDeleteStoryDialog(story._id)">
<mat-icon>delete</mat-icon>
<span>{{ ts.l.delete }}</span>
</button>
Expand All @@ -41,14 +41,14 @@
</mat-menu>
</div>
</div>
<div class="imgContainer" (click)="openStory(story)">
<div class="imgContainer">
<!--<img src="assets/img/logo-S.png" class="storyImg" alt="image">-->
<!--<img [src]="story.thumbnail==''? 'assets/img/logo-S.png' : story.thumbnail" class="storyImg" alt="image">-->
<img [src]="story.thumbnail==''?'assets/img/logo-S.png':story.thumbnail" class="storyImg" alt="image">
</div>

<!-- title container-->
<div class="titleContainer" (click)="openStory(story)">
<div class="titleContainer">
<div class="contentsTitle"
[attr.id]="i"
(blur)="saveStoryTitle(i, story)"
Expand Down
26 changes: 14 additions & 12 deletions ngapp/src/app/nav-bar/dr-story-drawer/dr-story-drawer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class DigitalReaderStoryDrawerComponent implements OnInit {
openStory(story: DigitalReaderStory){
this.router.navigateByUrl('dr-story-viewer?storyId=' + story._id)
}

/*setStory(story: Story) {
if (story.htmlText == null) {
story.htmlText = story.text;
Expand Down Expand Up @@ -171,7 +172,8 @@ export class DigitalReaderStoryDrawerComponent implements OnInit {
* Call the function to delete the story if the user clicks 'yes'
* @param id story id to be deleted
*/
/*openDeleteStoryDialog(id: string) {
openDeleteStoryDialog(id: string) {
console.log('gets to here!')
this.dialogRef = this.dialog.open(BasicDialogComponent, {
data: {
title: this.ts.l.delete_story,
Expand All @@ -188,35 +190,35 @@ export class DigitalReaderStoryDrawerComponent implements OnInit {
this.deleteStory(id);
}
});
}*/
}

/**
* Delete the given story and any associated recordings
* Set the new 'current story' => next one in the list, or first one
* if the last story in the list was deleted
* @param id story id to be deleted
*/
/*deleteStory(id: string) {
deleteStory(id: string) {
// remove any associated recordings
this.recordingService.deleteStoryRecordingAudio(id).subscribe((_) => {});
this.recordingService.deleteStoryRecording(id).subscribe((_) => {});
//this.recordingService.deleteStoryRecordingAudio(id).subscribe((_) => {});
//this.recordingService.deleteStoryRecording(id).subscribe((_) => {});

// remove any associated feedback comments
this.feedbackCommentService.deleteFeedbackCommentsForStory(id).subscribe((_) => {});
//this.feedbackCommentService.deleteFeedbackCommentsForStory(id).subscribe((_) => {});

// get index of story to be deleted within story list
const storyIndex = this.stories.findIndex((story) => story._id === id);
//const storyIndex = this.stories.findIndex((story) => story._id === id);

// delete the story
this.storyService.deleteStory(id).subscribe((_) => {
this.engagement.addEvent(EventType["DELETE-STORY"], { storyId: id });
this.drStoryService.deleteDRStory(id).subscribe((_) => {
//this.engagement.addEvent(EventType["DELETE-STORY"], { storyId: id });

// reset the story list to empty if list contains only one story
// If we have 2+ stories, delete the story for deletion, and set the new current story to the first in the list
this.stories.splice(storyIndex, 1);
this.stories.length ? this.setStory(this.stories[0]) : this.storyEmitter.emit();
//this.stories.splice(storyIndex, 1);
//this.stories.length ? this.setStory(this.stories[0]) : this.storyEmitter.emit();
});
}*/
}

/**
* Make the div containing the story title editable so the student can
Expand Down
9 changes: 9 additions & 0 deletions ngapp/src/app/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ const translations = {
processing: {
ga: 'Á phróiseáil',
en: 'Processing' },
synth_in_progress: {
ga: 'Tá fuaimeanna an scéil seo fós á sintéisiú',
en: 'The audio of this story is still being synthesised' },
problem_with_synth: {
ga: 'Níor fhéadadh ar a laghad abairt amháin a shintéisiú',
en: 'There were issues synthesising one or more sentences' },
okay: {
ga: 'Ceart go leor',
en: 'Okay' },
verified_dr_stories: {
ga: 'Scéalta Bailí',
en: 'Verified Stories' },
Expand Down

0 comments on commit 34f9aa7

Please sign in to comment.