This repository has been archived by the owner on Oct 20, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create basic H5P for local development with hard-coded paths * Wrap Minio-Client into priority queue * Enable creation of new documents
- Loading branch information
1 parent
79cd2dd
commit add8c1c
Showing
939 changed files
with
169,105 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
dist/** | ||
test/** | ||
src/plugins/*/static/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { priorityQueue } = require('async'); | ||
|
||
class PriorityQueue { | ||
constructor(maxConcurrency) { | ||
this.tasks = priorityQueue(this._runTask, maxConcurrency); | ||
} | ||
|
||
_runTask(task, callback) { | ||
task.func((err, result) => { | ||
if (err) { | ||
task.reject(err); | ||
} else { | ||
task.resolve(result); | ||
} | ||
callback(err); | ||
}); | ||
} | ||
|
||
push(func, priority = 0) { | ||
return new Promise((resolve, reject) => this.tasks.push({ func, reject, resolve }, priority)); | ||
} | ||
} | ||
|
||
module.exports = PriorityQueue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,106 @@ | ||
const React = require('react'); | ||
const autoBind = require('auto-bind'); | ||
const PropTypes = require('prop-types'); | ||
const { Button, Input, Modal } = require('antd'); | ||
const uniqueId = require('../../utils/unique-id'); | ||
const PageHeader = require('./../page-header.jsx'); | ||
const { inject } = require('../container-context.jsx'); | ||
const DocumentApiClient = require('../../services/document-api-client'); | ||
|
||
function Docs({ initialState }) { | ||
return ( | ||
<React.Fragment> | ||
<PageHeader /> | ||
<div className="PageContent"> | ||
<h1>Docs</h1> | ||
<ul> | ||
{initialState.map(doc => ( | ||
<li key={doc._id}> | ||
<a href={`/docs/${doc._id}`}>{doc.title}</a> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</React.Fragment> | ||
); | ||
class Docs extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
autoBind.react(this); | ||
this.state = { | ||
newDocKey: null, | ||
visible: false, | ||
loading: false | ||
}; | ||
} | ||
|
||
createNewDocument(key, title) { | ||
return { | ||
doc: { | ||
key: key, | ||
title: title || 'Unbenannt' | ||
}, | ||
sections: [], | ||
user: { | ||
name: 'Mr. Browser' | ||
} | ||
}; | ||
} | ||
|
||
handleNewDocumentClick() { | ||
this.setState({ | ||
newDocKey: uniqueId.create(), | ||
visible: true | ||
}); | ||
} | ||
|
||
handleNewDocKeyChange(event) { | ||
this.setState({ newDocKey: event.target.value }); | ||
} | ||
|
||
async handleOk() { | ||
const { newDocKey } = this.state; | ||
const { documentApiClient } = this.props; | ||
|
||
this.setState({ loading: true }); | ||
|
||
await documentApiClient.saveDocument(this.createNewDocument(newDocKey)); | ||
|
||
this.setState({ | ||
newDocKey: null, | ||
visible: false, | ||
loading: false | ||
}); | ||
} | ||
|
||
handleCancel() { | ||
this.setState({ visible: false }); | ||
} | ||
|
||
render() { | ||
const { initialState } = this.props; | ||
const { newDocKey, visible, loading } = this.state; | ||
return ( | ||
<React.Fragment> | ||
<PageHeader /> | ||
<div className="PageContent"> | ||
<h1>Docs</h1> | ||
<ul> | ||
{initialState.map(doc => ( | ||
<li key={doc._id}> | ||
<a href={`/docs/${doc._id}`}>{doc.title}</a> | ||
</li> | ||
))} | ||
</ul> | ||
<Button type="primary" shape="circle" icon="plus" size="large" onClick={this.handleNewDocumentClick} /> | ||
<Modal | ||
title="Neues Dokument" | ||
visible={visible} | ||
onOk={this.handleOk} | ||
onCancel={this.handleCancel} | ||
> | ||
<p>ID</p> | ||
<p><Input value={newDocKey} onChange={this.handleNewDocKeyChange} /></p> | ||
{loading && <p>Wird erstellt ...</p>} | ||
</Modal> | ||
</div> | ||
</React.Fragment> | ||
); | ||
} | ||
} | ||
|
||
Docs.propTypes = { | ||
documentApiClient: PropTypes.instanceOf(DocumentApiClient).isRequired, | ||
initialState: PropTypes.arrayOf(PropTypes.shape({ | ||
_id: PropTypes.string.isRequired, | ||
title: PropTypes.string.isRequired | ||
})).isRequired | ||
}; | ||
|
||
module.exports = Docs; | ||
module.exports = inject({ | ||
documentApiClient: DocumentApiClient | ||
}, Docs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const he = require('he'); | ||
const htmlescape = require('htmlescape'); | ||
const h5pHelper = require('./h5p-helper'); | ||
const Cdn = require('../../repositories/cdn'); | ||
|
||
const renderPlayTemplate = (contentId, integration) => ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>H5P Player</title> | ||
<script src="/plugins/h5p-player/static/js/jquery.js"></script> | ||
<script src="/plugins/h5p-player/static/js/h5p.js"></script> | ||
<script src="/plugins/h5p-player/static/js/h5p-event-dispatcher.js"></script> | ||
<script src="/plugins/h5p-player/static/js/h5p-x-api-event.js"></script> | ||
<script src="/plugins/h5p-player/static/js/h5p-x-api.js"></script> | ||
<script src="/plugins/h5p-player/static/js/h5p-content-type.js"></script> | ||
<script src="/plugins/h5p-player/static/js/h5p-confirmation-dialog.js"></script> | ||
<script src="/plugins/h5p-player/static/js/h5p-action-bar.js"></script> | ||
<link rel="stylesheet" href="/plugins/h5p-player/static/styles/h5p.css"> | ||
<link rel="stylesheet" href="/plugins/h5p-player/static/styles/h5p-confirmation-dialog.css"> | ||
<link rel="stylesheet" href="/plugins/h5p-player/static/styles/h5p-core-button.css"> | ||
<style> | ||
body { margin: 0; } | ||
</style> | ||
</head> | ||
<body> | ||
<div class="h5p-iframe-wrapper"> | ||
<iframe id="h5p-iframe-${he.encode(contentId)}" class="h5p-iframe" data-content-id="${he.encode(contentId)}" style="height:1px" src="about:blank" frameborder="0" scrolling="no"></iframe> | ||
</div> | ||
<script> | ||
window.H5PIntegration = ${htmlescape(integration)}; | ||
</script> | ||
</body> | ||
</html> | ||
`; | ||
|
||
class H5pPlayer { | ||
static get inject() { return [Cdn]; } | ||
|
||
static get typeName() { return 'h5p-player'; } | ||
|
||
constructor(cdn) { | ||
this.cdn = cdn; | ||
} | ||
|
||
async handlePostUpload(req, res) { | ||
if (!req.file) { | ||
return res.sendStatus(400); | ||
} | ||
|
||
const result = await h5pHelper.install(req.file.path, this.cdn); | ||
return res.send(result); | ||
} | ||
|
||
async handleGetPlay(req, res) { | ||
const { contentId } = req.params; | ||
const integration = await h5pHelper.createIntegration(contentId); | ||
const html = renderPlayTemplate(contentId, integration); | ||
return res.type('html').send(html); | ||
} | ||
} | ||
|
||
module.exports = H5pPlayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const React = require('react'); | ||
const autoBind = require('auto-bind'); | ||
const PropTypes = require('prop-types'); | ||
|
||
class H5pPlayerDisplay extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
autoBind.react(this); | ||
this.contentFrame = React.createRef(); | ||
} | ||
|
||
componentDidMount() { | ||
const { preferredLanguages, section } = this.props; | ||
const data = section.content[preferredLanguages[0]]; | ||
const playUrl = `/plugins/h5p-player/play/${data.contentId}`; | ||
|
||
fetch(playUrl).then(x => x.text()).then(html => { | ||
const iframe = this.contentFrame.current; | ||
iframe.onload = () => { | ||
iframe.style.height = `${iframe.contentWindow.document.body.scrollHeight}px`; | ||
}; | ||
iframe.contentWindow.document.open(); | ||
iframe.contentWindow.document.write(html); | ||
iframe.contentWindow.document.close(); | ||
}); | ||
} | ||
|
||
shouldComponentUpdate() { | ||
return false; | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="H5pPlayer"> | ||
<iframe className="H5pPlayer-contentFrame" frameBorder="0" scrolling="no" ref={this.contentFrame} /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
H5pPlayerDisplay.propTypes = { | ||
preferredLanguages: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
section: PropTypes.shape({ | ||
content: PropTypes.object | ||
}).isRequired | ||
}; | ||
|
||
module.exports = H5pPlayerDisplay; |
Oops, something went wrong.