Skip to content

Commit

Permalink
Changed Mongoose recursiveHtmlElem to use Schema.Types.Mixed to allow…
Browse files Browse the repository at this point in the history
… for storage of strings
  • Loading branch information
DavidMockler committed Jul 23, 2024
1 parent c811cf1 commit 968d632
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
3 changes: 2 additions & 1 deletion api/src/models/recursiveHtmlElem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const RecursiveHtmlElem = new Schema({

RecursiveHtmlElem.add({
'>' : {
type: [RecursiveHtmlElem],
//type: [RecursiveHtmlElem],
type: [Schema.Types.Mixed], // only for testing - allows insertion of strings as direct children
default: undefined
}
})
Expand Down
8 changes: 3 additions & 5 deletions ngapp/src/app/core/services/dr-story.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { TranslationService } from 'app/core/services/translation.service';
import config from 'abairconfig';
import { firstValueFrom, tap } from 'rxjs';

import { constructJSON } from '@phonlab-tcd/html2json';

@Injectable({
providedIn: 'root'
})
Expand Down Expand Up @@ -134,13 +132,13 @@ export class DigitalReaderStoryService {

// for testing
const parsedSegmentedDoc = htmlParser.parseFromString(segmentedHtml, 'text/html')
console.log(parsedSegmentedDoc)
/*console.log(parsedSegmentedDoc)
document.body.innerHTML = parsedSegmentedDoc.body.innerHTML
console.log(constructJSON(parsedSegmentedDoc.body))
console.log(constructJSON(parsedSegmentedDoc.body))*/

return segmentedHtml
return parsedSegmentedDoc
}

saveDRStory(title: string, dialects: Array<string>, story: Object, isPublic: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@
</div> <br>
<div>
<button class="viewStoryBtn"
(click)="getHtmlDoc()"
[disabled]="!this.htmlFile"
>*Test* Unzip the file</button> <br> <br>
<div class="viewStoryBtn" (click)="createNewStory()">Create</div>
(click)="convertDocxToHTML()"
[disabled]="!this.docxFile"
>*Test* Convert the docx to html</button> <br> <br>
<button class="viewStoryBtn"
(click)="createNewStory()"
[disabled]="!this.convertedHTMLDoc"
>*Test* Create Story</button>
</div>
</mat-action-row>
</mat-expansion-panel>
Expand Down
53 changes: 32 additions & 21 deletions ngapp/src/app/nav-bar/digital-reader/digital-reader.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { DigitalReaderStoryService } from "app/core/services/dr-story.service"
import { MatDialog, MatDialogRef } from "@angular/material/dialog";
import { BasicDialogComponent } from "../../dialogs/basic-dialog/basic-dialog.component";

import { constructJSON } from '@phonlab-tcd/html2json';

@Component({
selector: 'app-digital-reader',
templateUrl: './digital-reader.component.html',
Expand All @@ -28,7 +30,8 @@ export class DigitalReaderComponent implements OnInit {
drStories: DigitalReaderStory[] = []
user: User;
tableData: Array<Object>;
htmlFile: File | null = null;
docxFile: File | null = null;
convertedHTMLDoc: Document | null = null;
drStory: DigitalReaderStory;
dialogRef: MatDialogRef<unknown>;
@Output() isFirstDrStory = new EventEmitter<boolean>();
Expand Down Expand Up @@ -136,21 +139,23 @@ export class DigitalReaderComponent implements OnInit {
console.log("Can't save story, current user is null");
return;
}

const story = {}

this.drStoryService // maybe import RecursiveHtmlElem (?)
.saveDRStory(res[0], [dialect], story, true) // [dialect] only for testing - single dialect for now
.subscribe({
next: () => {
console.log('a response was received')
},
error: () => {
alert("Not able to create a new story");
},
});

alert("Attempted to create DR Story");

if (this.convertedHTMLDoc) {
const story = constructJSON(this.convertedHTMLDoc.body)

console.log(story)

this.drStoryService // maybe import RecursiveHtmlElem (?)
.saveDRStory(res[0], [dialect], story, true) // [dialect] only for testing - single dialect for now
.subscribe({
next: () => {
console.log('a response was received')
},
error: () => {
alert("Not able to create a new story");
},
});
}
} else {
alert(this.ts.l.title_required);
}
Expand Down Expand Up @@ -218,15 +223,21 @@ export class DigitalReaderComponent implements OnInit {

processUploadedFile(files: FileList) {
// in the future could make it so that the file is not removed if the dialog is simply opened again
this.htmlFile = files.item(0)
console.log(this.htmlFile)
this.docxFile = files.item(0)
console.log(this.docxFile)
}

async getHtmlDoc() {
async convertDocxToHTML() {

//only for testing
if (this.htmlFile) {
const test = await this.drStoryService.processUploadedFile(this.htmlFile)
if (this.docxFile) {
this.convertedHTMLDoc = await this.drStoryService.processUploadedFile(this.docxFile)

if (this.convertedHTMLDoc instanceof Document) {
console.log('file converted successfully!')
} else {
alert('could not convert docx file')
}
}

}
Expand Down

0 comments on commit 968d632

Please sign in to comment.