Skip to content

Commit

Permalink
MED-100: Update from Vimeo before loading form
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thies committed Apr 20, 2024
1 parent 9fcc17c commit 6f3a655
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion source/vimeo/amd/build/file_upload.min.js

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

2 changes: 1 addition & 1 deletion source/vimeo/amd/build/file_upload.min.js.map

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

3 changes: 0 additions & 3 deletions source/vimeo/amd/src/file_upload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Ajax from 'core/ajax';
import Config from 'core/config';
import Log from 'core/log';
import Notification from 'core/notification';

const upload = async(resource) => {
Expand All @@ -25,7 +24,6 @@ const upload = async(resource) => {
offset = response.headers.get('Upload-Offset');
}
document.querySelector('.progress').style.width = ( offset / file.size * 100) + '%';
Log.debug(offset);
} while (offset < file.size);
window.location.href = url;
};
Expand Down Expand Up @@ -54,7 +52,6 @@ export default {
fail: Notification.exception,
methodname: 'mediatimesrc_vimeo_create_token'
}]);
Log.debug(file.size);
}
}
};
2 changes: 1 addition & 1 deletion source/vimeo/classes/external/create_token.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static function execute($description, $filesize, $name, $tags, $title): a
],
]);
$updatedvideo = $api->request($video['uri'], [
'name' => $params['title'],
'name' => $params['title'] ?: $params['name'],
'description' => $params['description'],
], 'PATCH')['body'];
$id = $DB->insert_record('tool_mediatime', [
Expand Down
2 changes: 1 addition & 1 deletion source/vimeo/classes/form/delete_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function definition() {
];
$mform->addGroup($action, 'vimeofileaction', get_string('vimeofileaction', 'mediatimesrc_vimeo'), [' '], false);
$mform->setType('action', PARAM_INT);
$mform->setDefault('action', 2);
$mform->setDefault('action', 1);
$mform->addHelpButton('vimeofileaction', 'vimeofileaction', 'mediatimesrc_vimeo');

$this->add_action_buttons(true, get_string('delete'));
Expand Down
1 change: 1 addition & 0 deletions source/vimeo/classes/form/edit_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function definition() {
$mform->addElement('text', 'name', get_string('resourcename', 'tool_mediatime'));
$mform->setType('name', PARAM_TEXT);
$mform->addHelpButton('name', 'resourcename', 'tool_mediatime');
$mform->addRule('name', get_string('required'), 'required', null, 'client');

$mform->addElement('text', 'title', get_string('title', 'tool_mediatime'));
$mform->setType('title', PARAM_TEXT);
Expand Down
15 changes: 14 additions & 1 deletion source/vimeo/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,17 @@ public function __construct($record = null) {

$this->content->tags = core_tag_tag::get_item_tags_array('tool_mediatime', 'tool_mediatime', $edit);

$data += ['name' => $this->record->name, 'title' => $this->content->name] + (array)$this->content;
// Check for updated values at Vimeo.
if (!$this->form->is_submitted()) {
$video = $this->api->request($this->content->uri)['body'];
$data = [
'description' => $video['description'],
'title' => $video['name'],
'name' => $this->record->name,
] + $data;
} else {
$data += ['name' => $this->record->name, 'title' => $this->content->name] + (array)$this->content;
}
}
$this->form->set_data($data);
if ($this->form->is_cancelled()) {
Expand All @@ -123,6 +133,9 @@ public function __construct($record = null) {
foreach ($fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $data->videofile) as $file) {
if (!$file->is_directory()) {
$data->edit = $DB->insert_record('tool_mediatime', $data);
if (empty($data->title)) {
$data->title = $data->name;
}

file_save_draft_area_files(
$data->videofile,
Expand Down

0 comments on commit 6f3a655

Please sign in to comment.