Skip to content

Commit

Permalink
Implemented basic story loader + tested recursive component creation
Browse files Browse the repository at this point in the history
Recursively converting the words/sentences to angular components seems like it will be very slow and so I do not plan to continue that test
  • Loading branch information
DavidMockler committed Jul 30, 2024
1 parent 3f3cf55 commit 297a97e
Show file tree
Hide file tree
Showing 19 changed files with 850 additions and 12 deletions.
32 changes: 32 additions & 0 deletions api/src/endpoint/drStory/publicOrOwnedStoryId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const DigitalReaderStory = require('../../models/drStory');
const mongoose = require('mongoose');

/**
* Set feedback status of story to 'viewed'
* @param {Object} req user: User information; params: story ID
* @param {Object} res
* @param {Object} next
* @return {Promise} Story object
*/
module.exports = async (req, res, next) => {

function yes() {
res.json(story);
}
function no(status=404, msg='not found') {
res.status(status).json(msg);
}

if (!req.user) return no(400, 'need to know user');
if (!req.user._id) return no(400, 'need to know user\'s id');

const story = await DigitalReaderStory.findById(new mongoose.mongo.ObjectId(req.params.id));
if (!story) return no();

if (story.public) return yes();

// if the story is private - but the current user is its owner, return the story
if (story.owner.toString() === req.user._id) return yes();

return no(401, 'not authorised');
};
5 changes: 5 additions & 0 deletions api/src/endpoint/drStory/verifiedCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ const handler = async (req, res) => {
ownerDoc: {$first: '$ownerDocArr'},
collections: 1,
thumbnail: 1,
public: 1,
}},
{$project: {
title: 1,
ownerRole: '$ownerDoc.role',
collections: 1,
thumbnail: 1,
public: 1,
}},
{$match: {
ownerRole: "ADMIN"
}},
{$match: {
public: true
}},
{$match: {
$expr: {
$in: [req.params.collectionName, "$collections"]
Expand Down
2 changes: 2 additions & 0 deletions api/src/routes/drStory.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let storyRoutes;
const allPublic = require("../endpoint/drStory/public");
const verified = require("../endpoint/drStory/verified");
const verifiedCollection = require("../endpoint/drStory/verifiedCollection");
const publicOrOwnedStoryId = require("../endpoint/drStory/publicOrOwnedStoryId");
/*const author = require("../endpoint/story/author");
const feedbackAudio = require("../endpoint/story/feedbackAudio");
const countGrammarErrors = require("../endpoint/story/countGrammarErrors");
Expand All @@ -45,6 +46,7 @@ let storyRoutes;
// '/myStudentsStory/:id': myStudentsStory,
"/owner/:id": ownerId,
"/public": allPublic,
"/publicOrOwned/:id": publicOrOwnedStoryId,
"/verified": verified,
"/verified/:collectionName": verifiedCollection,
/*"/:author": author,
Expand Down
21 changes: 16 additions & 5 deletions ngapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion ngapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
},
"dependencies": {
"@phonlab-tcd/gramadoir-ts": "^0.0.55",
"@phonlab-tcd/html2json": "^0.0.2",
"@phonlab-tcd/html2json": "^0.0.4",
"@phonlab-tcd/json2html": "^0.0.2",
"@popperjs/core": "^2.9.2",
"@tweenjs/tween.js": "^18.6.4",
"@types/quill": "^1.3.10",
Expand Down
3 changes: 3 additions & 0 deletions ngapp/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { AuthGuardService } from 'app/core/services/auth-guard.service';
import { RoleGuardService } from 'app/core/services/role-guard.service';
import { NotificationService } from 'app/core/services/notification-service.service';

//TODO : remove below line and create dr-story-viewer module
import('./dr-story-viewer/dr-story-builder/dr-story-builder.component')

const routes: Routes = [
{ path: '', redirectTo: 'landing', pathMatch: 'full' },
Expand All @@ -24,6 +26,7 @@ const routes: Routes = [
{ path: 'profile', loadComponent: () => import('./profile/profile/profile.component').then(m => m.ProfileComponent), canActivate: [AuthGuardService]},
{ path: 'messages/:id', loadComponent: () => import('./messages/messages.component').then(m => m.MessagesComponent), canActivate: [AuthGuardService]},
{ path: 'stats-dashboard/:id', loadComponent: () => import('./stats-dashboard/stats-dashboard.component').then(m => m.StatsDashboardComponent)},
{ path: 'dr-story-viewer', loadComponent: () => import('./dr-story-viewer/dr-story-viewer/dr-story-viewer.component').then(m => m.DigitalReaderStoryViewerComponent)},
{
path: 'student',
data: { expectedRoles: ['STUDENT'] },
Expand Down
2 changes: 1 addition & 1 deletion ngapp/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { NavBarModule } from './nav-bar/nav-bar.module';

@NgModule({
declarations: [
AppComponent,
AppComponent
],
imports: [
BrowserModule,
Expand Down
6 changes: 5 additions & 1 deletion ngapp/src/app/core/services/dr-story.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class DigitalReaderStoryService {
this.http.post<string>(this.baseUrl + 'digitalReader/docx2html', formData)
).catch((err: HttpErrorResponse) => {
alert(err.error)
alert(err)
//alert(err)
//throw new Error()
return null;
});
Expand Down Expand Up @@ -204,6 +204,10 @@ export class DigitalReaderStoryService {
return this.http.get<DigitalReaderStory[]>(this.baseUrl + 'drStory/public');
}

getPublicDRStoryById(id: string): Observable<DigitalReaderStory[]> {
return this.http.get<DigitalReaderStory[]>(this.baseUrl + 'drStory/publicOrOwned/' + id);
}

/*
createDRStory(title: string, date: Date, dialects: Array<string>, htmlText: string, author: string) {
const drstoryObj = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<!--<div class="container">
</div>-->
<span>
{{ content.nodeName }}
<span
*ngFor="let child of content.childNodes"
>
<app-dr-story-builder
[type]="'body'"
[content]="child"></app-dr-story-builder>
</span>
</span>
Loading

0 comments on commit 297a97e

Please sign in to comment.