-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Thies
committed
Apr 15, 2024
1 parent
db77fb1
commit 1dc8193
Showing
20 changed files
with
6,067 additions
and
2 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
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,43 @@ | ||
var upload; | ||
|
||
import * as tus from 'mediatimesrc_streamio/tus'; | ||
import Log from 'core/log'; | ||
import cfg from 'core/config'; | ||
|
||
const options = { | ||
endpoint: cfg.wwwroot + '/api/v1/videos/tus', | ||
metadata: {}, | ||
onError: Log.debug, | ||
onProgress: function(bytesUploaded, bytesTotal) { | ||
document.querySelectorAll('.progress').forEach(indicator => { | ||
indicator.style.width = (bytesUploaded / bytesTotal * 100) + '%'; | ||
}); | ||
}, | ||
onSuccess: function() { | ||
document.getElementById('upload_resource_form').submit(); | ||
Log.debug(upload.url); | ||
} | ||
}; | ||
|
||
export default { | ||
init: function(token) { | ||
options.metadata.uploadtoken = token; | ||
document.body.removeEventListener('click', this.handleClick); | ||
document.body.addEventListener('click', this.handleClick); | ||
}, | ||
|
||
handleClick: function(e) { | ||
const button = e.target.closest('button[name="upload"]'); | ||
if (button) { | ||
const file = document.querySelector('input[name="streamiofile"]').files[0]; | ||
e.preventDefault(); | ||
options.metadata.filename = file.name; | ||
options.metadata.filetype = file.type; | ||
Log.debug(options); | ||
Log.debug(tus); | ||
|
||
upload = new tus.Upload(file, options); | ||
upload.start(); | ||
} | ||
} | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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,37 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Manage Streamio source files | ||
* | ||
* @package mediatimesrc_vimeo | ||
* @copyright 2024 bdecent gmbh <https://bdecent.de> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace mediatimesrc_vimeo; | ||
|
||
use moodle_exception; | ||
use stdClass; | ||
|
||
/** | ||
* Manage Streamio source files | ||
* | ||
* @copyright 2024 bdecent gmbh <https://bdecent.de> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class api extends \videotimeplugin_repository\api { | ||
} |
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,30 @@ | ||
<?php | ||
// This file is part of Moodle - https://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
namespace mediatimesrc_vimeo\event; | ||
|
||
/** | ||
* The resource_created event class. | ||
* | ||
* @package mediatimesrc_vimeo | ||
* @category event | ||
* @copyright 2024 bdecent gmbh <https://bdecent.de> | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class resource_created extends core_event\base { | ||
|
||
// For more information about the Events API please visit {@link https://docs.moodle.org/dev/Events_API}. | ||
} |
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,134 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Media Time media edit form | ||
* | ||
* @package mediatimesrc_vimeo | ||
* @copyright 2024 bdecent gmbh <https://bdecent.de> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace mediatimesrc_vimeo\form; | ||
|
||
use context_system; | ||
use moodleform; | ||
use videotimeplugin_repository\api; | ||
use mediatimesrc_vimeo\output\media_resource; | ||
|
||
/** | ||
* Media Time media edit form | ||
* | ||
* @copyright 2024 bdecent gmbh <https://bdecent.de> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class edit_resource extends \tool_mediatime\form\edit_resource { | ||
|
||
/** | ||
* Definition | ||
*/ | ||
public function definition() { | ||
$mform = $this->_form; | ||
|
||
$mform->addElement('hidden', 'create'); | ||
$mform->setType('create', PARAM_TEXT); | ||
|
||
$mform->addElement('hidden', 'source'); | ||
$mform->setType('source', PARAM_TEXT); | ||
$mform->setDefault('source', 'vimeo'); | ||
|
||
$mform->addElement('text', 'name', get_string('resourcename', 'tool_mediatime')); | ||
$mform->setType('name', PARAM_TEXT); | ||
$mform->addHelpButton('name', 'resourcename', 'tool_mediatime'); | ||
|
||
$mform->addElement('text', 'title', get_string('title', 'tool_mediatime')); | ||
$mform->setType('title', PARAM_TEXT); | ||
$mform->addHelpButton('title', 'title', 'tool_mediatime'); | ||
|
||
$mform->addElement('hidden', 'edit'); | ||
$mform->setType('edit', PARAM_INT); | ||
|
||
$filesource = [ | ||
$mform->createElement('radio', 'newfile', '', get_string('uploadnewfile', 'mediatimesrc_vimeo'), 1, []), | ||
$mform->createElement('radio', 'newfile', '', get_string('selectexistingfile', 'mediatimesrc_vimeo'), 0, []), | ||
$mform->createElement('radio', 'newfile', '', get_string('selecturl', 'mediatimesrc_vimeo'), 2, []), | ||
]; | ||
$mform->addGroup($filesource, 'filesource', get_string('videofile', 'mediatimesrc_vimeo'), [' '], false); | ||
$mform->setType('newfile', PARAM_INT); | ||
$mform->addHelpButton('filesource', 'videofile', 'mediatimesrc_vimeo'); | ||
|
||
$mform->addElement('url', 'vimeo_url', get_string('vimeo_url', 'mod_videotime')); | ||
$mform->hideIf('vimeo_url', 'newfile', 'neq', 2); | ||
$mform->setType('vimeo_url', PARAM_URL); | ||
|
||
$mform->addElement('textarea', 'description', get_string('description')); | ||
$mform->setType('description', PARAM_TEXT); | ||
|
||
$this->tag_elements(); | ||
|
||
$this->add_action_buttons(); | ||
} | ||
|
||
/** | ||
* Display resource or add file fields | ||
*/ | ||
public function definition_after_data() { | ||
global $DB, $OUTPUT; | ||
|
||
$mform =& $this->_form; | ||
|
||
$id = $mform->getElementValue('edit'); | ||
$record = $DB->get_record('tool_mediatime', ['id' => $id]); | ||
$context = context_system::instance(); | ||
if ($record) { | ||
$resource = new media_resource($record); | ||
$content = json_decode($record->content); | ||
$mform->insertElementBefore( | ||
$mform->createElement('html', $content->embed->html), | ||
'name' | ||
); | ||
$mform->insertElementBefore( | ||
$mform->createElement('static', 'vimeolink', get_string('vimeolink', 'mediatimesrc_vimeo'), $content->link), | ||
'filesource' | ||
); | ||
$mform->removeElement('filesource'); | ||
} else { | ||
if (has_capability('mediatimesrc/vimeo:viewall', $context)) { | ||
$options = [null => '']; | ||
$api = new api(); | ||
$videos = $api->request('/me/videos')['body']['data']; | ||
foreach ($videos as $video) { | ||
$options[$video['uri']] = $video['name']; | ||
} | ||
|
||
$mform->insertElementBefore( | ||
$mform->createElement('autocomplete', 'file', '', $options, [ | ||
]), | ||
'description' | ||
); | ||
$mform->hideIf('file', 'newfile', 'neq', 0); | ||
$mform->setDefault('newfile', 1); | ||
$mform->setDefault('file', []); | ||
} else if (has_capability('mediatimesrc/vimeo:upload', context_system::instance())) { | ||
$mform->removeElement('filesource'); | ||
$mform->insertElementBefore( | ||
$mform->createElement('hidden', 'newfile', 1), | ||
'description' | ||
); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.