commit
f63b6187fb
|
@ -0,0 +1,99 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Script for detecting changes in a WS params or return data, version by version.
|
||||
*
|
||||
* The first parameter (required) is the path to the Moodle installation to use.
|
||||
* The second parameter (required) is the name to the WS to convert.
|
||||
* The third parameter (optional) is a number: 1 to convert the params structure,
|
||||
* 0 to convert the returns structure. Defaults to 0.
|
||||
*/
|
||||
|
||||
if (!isset($argv[1])) {
|
||||
echo "ERROR: Please pass the path to the folder containing the Moodle installations as the first parameter.\n";
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
if (!isset($argv[2])) {
|
||||
echo "ERROR: Please pass the WS name as the second parameter.\n";
|
||||
die();
|
||||
}
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
require_once('ws_to_ts_functions.php');
|
||||
|
||||
$versions = array('master', '38', '37', '36', '35', '34', '33', '32', '31');
|
||||
|
||||
$moodlespath = $argv[1];
|
||||
$wsname = $argv[2];
|
||||
$useparams = !!(isset($argv[3]) && $argv[3]);
|
||||
$pathseparator = '/';
|
||||
|
||||
// Get the path to the script.
|
||||
$index = strrpos(__FILE__, $pathseparator);
|
||||
if ($index === false) {
|
||||
$pathseparator = '\\';
|
||||
$index = strrpos(__FILE__, $pathseparator);
|
||||
}
|
||||
$scriptfolder = substr(__FILE__, 0, $index);
|
||||
$scriptpath = concatenate_paths($scriptfolder, 'get_ws_structure.php', $pathseparator);
|
||||
|
||||
$previousstructure = null;
|
||||
$previousversion = null;
|
||||
$libsloaded = false;
|
||||
|
||||
foreach ($versions as $version) {
|
||||
$moodlepath = concatenate_paths($moodlespath, 'stable_' . $version, $pathseparator);
|
||||
|
||||
if (!$libsloaded) {
|
||||
$libsloaded = true;
|
||||
|
||||
require($moodlepath . '/config.php');
|
||||
require($CFG->dirroot . '/webservice/lib.php');
|
||||
}
|
||||
|
||||
// Get the structure in this Moodle version.
|
||||
$structure = shell_exec("php $scriptpath $moodlepath $wsname " . ($useparams ? 'true' : ''));
|
||||
|
||||
if (strpos($structure, 'ERROR:') === 0) {
|
||||
echo "WS not found in version $version. Stop.\n";
|
||||
break;
|
||||
}
|
||||
|
||||
$structure = unserialize($structure);
|
||||
|
||||
if ($previousstructure != null) {
|
||||
echo "*** Check changes from version $version to $previousversion ***\n";
|
||||
|
||||
$messages = detect_ws_changes($previousstructure, $structure);
|
||||
|
||||
if (count($messages) > 0) {
|
||||
$haschanged = true;
|
||||
|
||||
foreach($messages as $message) {
|
||||
echo "$message\n";
|
||||
}
|
||||
} else {
|
||||
echo "No changes found.\n";
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
$previousstructure = $structure;
|
||||
$previousversion = $version;
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Script for getting the PHP structure of a WS returns or params.
|
||||
*
|
||||
* The first parameter (required) is the path to the Moodle installation to use.
|
||||
* The second parameter (required) is the name to the WS to convert.
|
||||
* The third parameter (optional) is a number: 1 to convert the params structure,
|
||||
* 0 to convert the returns structure. Defaults to 0.
|
||||
*/
|
||||
|
||||
if (!isset($argv[1])) {
|
||||
echo "ERROR: Please pass the Moodle path as the first parameter.\n";
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
if (!isset($argv[2])) {
|
||||
echo "ERROR: Please pass the WS name as the second parameter.\n";
|
||||
die();
|
||||
}
|
||||
|
||||
$moodlepath = $argv[1];
|
||||
$wsname = $argv[2];
|
||||
$useparams = !!(isset($argv[3]) && $argv[3]);
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
|
||||
require($moodlepath . '/config.php');
|
||||
require($CFG->dirroot . '/webservice/lib.php');
|
||||
require_once('ws_to_ts_functions.php');
|
||||
|
||||
$structure = get_ws_structure($wsname, $useparams);
|
||||
|
||||
if ($structure === false) {
|
||||
echo "ERROR: The WS wasn't found in this Moodle installation.\n";
|
||||
die();
|
||||
}
|
||||
|
||||
remove_default_closures($structure);
|
||||
echo serialize($structure);
|
|
@ -0,0 +1,62 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Script for converting a PHP WS structure to a TS type.
|
||||
*
|
||||
* The first parameter (required) is the path to the Moodle installation to use.
|
||||
* The second parameter (required) is the name to the WS to convert.
|
||||
* The third parameter (optional) is the name to put to the TS type. Defaults to "TypeName".
|
||||
* The fourth parameter (optional) is a number: 1 to convert the params structure,
|
||||
* 0 to convert the returns structure. Defaults to 0.
|
||||
*/
|
||||
|
||||
if (!isset($argv[1])) {
|
||||
echo "ERROR: Please pass the Moodle path as the first parameter.\n";
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
if (!isset($argv[2])) {
|
||||
echo "ERROR: Please pass the WS name as the second parameter.\n";
|
||||
die();
|
||||
}
|
||||
|
||||
$moodlepath = $argv[1];
|
||||
$wsname = $argv[2];
|
||||
$typename = isset($argv[3]) ? $argv[3] : 'TypeName';
|
||||
$useparams = !!(isset($argv[4]) && $argv[4]);
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
|
||||
require($moodlepath . '/config.php');
|
||||
require($CFG->dirroot . '/webservice/lib.php');
|
||||
require_once('ws_to_ts_functions.php');
|
||||
|
||||
$structure = get_ws_structure($wsname, $useparams);
|
||||
|
||||
if ($structure === false) {
|
||||
echo "ERROR: The WS wasn't found in this Moodle installation.\n";
|
||||
die();
|
||||
}
|
||||
|
||||
if ($useparams) {
|
||||
$description = "Params of WS $wsname.";
|
||||
} else {
|
||||
$description = "Result of WS $wsname.";
|
||||
}
|
||||
|
||||
echo get_ts_doc(null, $description, '') . "export type $typename = " . convert_to_ts(null, $structure, $useparams) . ";\n";
|
|
@ -659,6 +659,12 @@
|
|||
"addon.mod_glossary.noentriesfound": "local_moodlemobileapp",
|
||||
"addon.mod_glossary.searchquery": "local_moodlemobileapp",
|
||||
"addon.mod_glossary.tagarea_glossary_entries": "glossary",
|
||||
"addon.mod_h5pactivity.downloadh5pfile": "local_moodlemobileapp",
|
||||
"addon.mod_h5pactivity.errorgetactivity": "local_moodlemobileapp",
|
||||
"addon.mod_h5pactivity.filestatenotdownloaded": "local_moodlemobileapp",
|
||||
"addon.mod_h5pactivity.filestateoutdated": "local_moodlemobileapp",
|
||||
"addon.mod_h5pactivity.modulenameplural": "h5pactivity",
|
||||
"addon.mod_h5pactivity.offlinedisabledwarning": "local_moodlemobileapp",
|
||||
"addon.mod_imscp.deploymenterror": "imscp",
|
||||
"addon.mod_imscp.modulenameplural": "imscp",
|
||||
"addon.mod_imscp.showmoduledescription": "local_moodlemobileapp",
|
||||
|
@ -2033,6 +2039,7 @@
|
|||
"core.sort": "moodle",
|
||||
"core.sortby": "moodle",
|
||||
"core.start": "grouptool",
|
||||
"core.storingfiles": "local_moodlemobileapp",
|
||||
"core.strftimedate": "langconfig",
|
||||
"core.strftimedatefullshort": "langconfig",
|
||||
"core.strftimedateshort": "langconfig",
|
||||
|
|
|
@ -0,0 +1,244 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Helper functions for converting a Moodle WS structure to a TS type.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the structure of a WS params or returns.
|
||||
*/
|
||||
function get_ws_structure($wsname, $useparams) {
|
||||
global $DB;
|
||||
|
||||
// get all the function descriptions
|
||||
$functions = $DB->get_records('external_functions', array(), 'name');
|
||||
$functiondescs = array();
|
||||
foreach ($functions as $function) {
|
||||
$functiondescs[$function->name] = external_api::external_function_info($function);
|
||||
}
|
||||
|
||||
if (!isset($functiondescs[$wsname])) {
|
||||
return false;
|
||||
} else if ($useparams) {
|
||||
return $functiondescs[$wsname]->parameters_desc;
|
||||
} else {
|
||||
return $functiondescs[$wsname]->returns_desc;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix a comment: make sure first letter is uppercase and add a dot at the end if needed.
|
||||
*/
|
||||
function fix_comment($desc) {
|
||||
$desc = trim($desc);
|
||||
$desc = ucfirst($desc);
|
||||
|
||||
if (substr($desc, -1) !== '.') {
|
||||
$desc .= '.';
|
||||
}
|
||||
|
||||
return $desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an inline comment based on a certain text.
|
||||
*/
|
||||
function get_inline_comment($desc) {
|
||||
if (empty($desc)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return ' // ' . fix_comment($desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the TS documentation of a certain element.
|
||||
*/
|
||||
function get_ts_doc($type, $desc, $indentation) {
|
||||
if (empty($desc)) {
|
||||
// If no key, it's probably in an array. We only document object properties.
|
||||
return '';
|
||||
}
|
||||
|
||||
return $indentation . "/**\n" .
|
||||
$indentation . " * " . fix_comment($desc) . "\n" .
|
||||
(!empty($type) ? ($indentation . " * @type {" . $type . "}\n") : '') .
|
||||
$indentation . " */\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a certain type, with or without a key.
|
||||
*/
|
||||
function convert_key_type($key, $type, $required, $indentation) {
|
||||
if ($key) {
|
||||
// It has a key, it's inside an object.
|
||||
return $indentation . "$key" . ($required == VALUE_OPTIONAL ? '?' : '') . ": $type";
|
||||
} else {
|
||||
// No key, it's probably in an array. Just include the type.
|
||||
return $type;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a certain element into a TS structure.
|
||||
*/
|
||||
function convert_to_ts($key, $value, $boolisnumber = false, $indentation = '', $arraydesc = '') {
|
||||
if ($value instanceof external_value || $value instanceof external_warnings || $value instanceof external_files) {
|
||||
// It's a basic field or a pre-defined type like warnings.
|
||||
$type = 'string';
|
||||
|
||||
if ($value instanceof external_warnings) {
|
||||
$type = 'CoreWSExternalWarning[]';
|
||||
} else if ($value instanceof external_files) {
|
||||
$type = 'CoreWSExternalFile[]';
|
||||
} else if ($value->type == PARAM_BOOL && !$boolisnumber) {
|
||||
$type = 'boolean';
|
||||
} else if (($value->type == PARAM_BOOL && $boolisnumber) || $value->type == PARAM_INT || $value->type == PARAM_FLOAT ||
|
||||
$value->type == PARAM_LOCALISEDFLOAT || $value->type == PARAM_PERMISSION || $value->type == PARAM_INTEGER ||
|
||||
$value->type == PARAM_NUMBER) {
|
||||
$type = 'number';
|
||||
}
|
||||
|
||||
$result = convert_key_type($key, $type, $value->required, $indentation);
|
||||
|
||||
return $result;
|
||||
|
||||
} else if ($value instanceof external_single_structure) {
|
||||
// It's an object.
|
||||
$result = convert_key_type($key, '{', $value->required, $indentation);
|
||||
|
||||
if ($arraydesc) {
|
||||
// It's an array of objects. Print the array description now.
|
||||
$result .= get_inline_comment($arraydesc);
|
||||
}
|
||||
|
||||
$result .= "\n";
|
||||
|
||||
foreach ($value->keys as $key => $value) {
|
||||
$result .= convert_to_ts($key, $value, $boolisnumber, $indentation . ' ') . ';';
|
||||
|
||||
if (!$value instanceof external_multiple_structure || !$value->content instanceof external_single_structure) {
|
||||
// Add inline comments after the field, except for arrays of objects where it's added at the start.
|
||||
$result .= get_inline_comment($value->desc);
|
||||
}
|
||||
|
||||
$result .= "\n";
|
||||
}
|
||||
|
||||
$result .= "$indentation}";
|
||||
|
||||
return $result;
|
||||
|
||||
} else if ($value instanceof external_multiple_structure) {
|
||||
// It's an array.
|
||||
$result = convert_key_type($key, '', $value->required, $indentation);
|
||||
|
||||
$result .= convert_to_ts(null, $value->content, $boolisnumber, $indentation, $value->desc);
|
||||
|
||||
$result .= "[]";
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
echo "WARNING: Unknown structure: $key " . get_class($value) . " \n";
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate two paths.
|
||||
*/
|
||||
function concatenate_paths($left, $right, $separator = '/') {
|
||||
if (!is_string($left) || $left == '') {
|
||||
return $right;
|
||||
} else if (!is_string($right) || $right == '') {
|
||||
return $left;
|
||||
}
|
||||
|
||||
$lastCharLeft = substr($left, -1);
|
||||
$firstCharRight = $right[0];
|
||||
|
||||
if ($lastCharLeft === $separator && $firstCharRight === $separator) {
|
||||
return $left . substr($right, 1);
|
||||
} else if ($lastCharLeft !== $separator && $firstCharRight !== '/') {
|
||||
return $left . '/' . $right;
|
||||
} else {
|
||||
return $left . $right;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect changes between 2 WS structures. We only detect fields that have been added or modified, not removed fields.
|
||||
*/
|
||||
function detect_ws_changes($new, $old, $key = '', $path = '') {
|
||||
$messages = [];
|
||||
|
||||
if (gettype($new) != gettype($old)) {
|
||||
// The type has changed.
|
||||
$messages[] = "Property '$key' has changed type, from '" . gettype($old) . "' to '" . gettype($new) .
|
||||
($path != '' ? "' inside $path." : "'.");
|
||||
|
||||
} else if ($new instanceof external_value && $new->type != $old->type) {
|
||||
// The type has changed.
|
||||
$messages[] = "Property '$key' has changed type, from '" . $old->type . "' to '" . $new->type .
|
||||
($path != '' ? "' inside $path." : "'.");
|
||||
|
||||
} else if ($new instanceof external_warnings || $new instanceof external_files) {
|
||||
// Ignore these types.
|
||||
|
||||
} else if ($new instanceof external_single_structure) {
|
||||
// Check each subproperty.
|
||||
$newpath = ($path != '' ? "$path." : '') . $key;
|
||||
|
||||
foreach ($new->keys as $subkey => $value) {
|
||||
if (!isset($old->keys[$subkey])) {
|
||||
// New property.
|
||||
$messages[] = "New property '$subkey' found" . ($newpath != '' ? " inside '$newpath'." : '.');
|
||||
} else {
|
||||
$messages = array_merge($messages, detect_ws_changes($value, $old->keys[$subkey], $subkey, $newpath));
|
||||
}
|
||||
}
|
||||
} else if ($new instanceof external_multiple_structure) {
|
||||
// Recursive call with the content.
|
||||
$messages = array_merge($messages, detect_ws_changes($new->content, $old->content, $key, $path));
|
||||
}
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all closures (anonymous functions) in the default values so the object can be serialized.
|
||||
*/
|
||||
function remove_default_closures($value) {
|
||||
if ($value instanceof external_warnings || $value instanceof external_files) {
|
||||
// Ignore these types.
|
||||
|
||||
} else if ($value instanceof external_value) {
|
||||
if ($value->default instanceof Closure) {
|
||||
$value->default = null;
|
||||
}
|
||||
|
||||
} else if ($value instanceof external_single_structure) {
|
||||
|
||||
foreach ($value->keys as $key => $subvalue) {
|
||||
remove_default_closures($subvalue);
|
||||
}
|
||||
|
||||
} else if ($value instanceof external_multiple_structure) {
|
||||
remove_default_closures($value->content);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { IonicModule } from 'ionic-angular';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CoreComponentsModule } from '@components/components.module';
|
||||
import { CoreDirectivesModule } from '@directives/directives.module';
|
||||
import { CoreCourseComponentsModule } from '@core/course/components/components.module';
|
||||
import { CoreH5PComponentsModule } from '@core/h5p/components/components.module';
|
||||
import { AddonModH5PActivityIndexComponent } from './index/index';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AddonModH5PActivityIndexComponent,
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
IonicModule,
|
||||
TranslateModule.forChild(),
|
||||
CoreComponentsModule,
|
||||
CoreDirectivesModule,
|
||||
CoreCourseComponentsModule,
|
||||
CoreH5PComponentsModule,
|
||||
],
|
||||
providers: [
|
||||
],
|
||||
exports: [
|
||||
AddonModH5PActivityIndexComponent,
|
||||
],
|
||||
entryComponents: [
|
||||
AddonModH5PActivityIndexComponent,
|
||||
]
|
||||
})
|
||||
export class AddonModH5PActivityComponentsModule {}
|
|
@ -0,0 +1,42 @@
|
|||
<!-- Buttons to add to the header. -->
|
||||
<core-navbar-buttons end>
|
||||
<core-context-menu>
|
||||
<core-context-menu-item *ngIf="externalUrl" [priority]="900" [content]="'core.openinbrowser' | translate" [href]="externalUrl" [iconAction]="'open'"></core-context-menu-item>
|
||||
<core-context-menu-item *ngIf="description" [priority]="800" [content]="'core.moduleintro' | translate" (action)="expandDescription()" [iconAction]="'arrow-forward'"></core-context-menu-item>
|
||||
<core-context-menu-item *ngIf="blog" [priority]="750" content="{{'addon.blog.blog' | translate}}" [iconAction]="'fa-newspaper-o'" (action)="gotoBlog($event)"></core-context-menu-item>
|
||||
<core-context-menu-item *ngIf="loaded && isOnline" [priority]="700" [content]="'core.refresh' | translate" (action)="doRefresh(null, $event)" [iconAction]="refreshIcon" [closeOnClick]="false"></core-context-menu-item>
|
||||
<core-context-menu-item *ngIf="prefetchStatusIcon" [priority]="500" [content]="prefetchText" (action)="prefetch($event)" [iconAction]="prefetchStatusIcon" [closeOnClick]="false"></core-context-menu-item>
|
||||
<core-context-menu-item *ngIf="size" [priority]="400" [content]="'core.removefiles' | translate:{$a: size}" [iconDescription]="'cube'" (action)="removeFiles($event)" [iconAction]="'trash'" [closeOnClick]="false"></core-context-menu-item>
|
||||
</core-context-menu>
|
||||
</core-navbar-buttons>
|
||||
|
||||
<!-- Content. -->
|
||||
<core-loading [hideUntil]="loaded" class="core-loading-center safe-area-page">
|
||||
|
||||
<core-course-module-description [description]="description" [component]="component" [componentId]="componentId" contextLevel="module" [contextInstanceId]="module.id" [courseId]="courseId"></core-course-module-description>
|
||||
|
||||
<!-- Offline disabled. -->
|
||||
<ion-card class="core-warning-card" icon-start *ngIf="!siteCanDownload && playing">
|
||||
<ion-icon name="warning"></ion-icon> {{ 'core.h5p.offlinedisabled' | translate }} {{ 'addon.mod_h5pactivity.offlinedisabledwarning' | translate }}
|
||||
</ion-card>
|
||||
|
||||
<ion-list *ngIf="deployedFile && !playing">
|
||||
<ion-item text-wrap *ngIf="stateMessage">
|
||||
<p >{{ stateMessage | translate }}</p>
|
||||
</ion-item>
|
||||
|
||||
<!-- Button to download the package. -->
|
||||
<ion-item *ngIf="!downloading && needsDownload" text-wrap>
|
||||
<a ion-button block (click)="downloadAndPlay($event)">{{ 'addon.mod_h5pactivity.downloadh5pfile' | translate }}</a>
|
||||
</ion-item>
|
||||
|
||||
<!-- Download progress. -->
|
||||
<ion-item text-center *ngIf="downloading">
|
||||
<ion-spinner></ion-spinner>
|
||||
<h2 *ngIf="progressMessage">{{ progressMessage | translate }}</h2>
|
||||
<core-progress-bar *ngIf="percentage <= 100" [progress]="percentage"></core-progress-bar>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
|
||||
<core-h5p-iframe *ngIf="playing" [fileUrl]="fileUrl" [displayOptions]="displayOptions" [onlinePlayerUrl]="onlinePlayerUrl"></core-h5p-iframe>
|
||||
</core-loading>
|
|
@ -0,0 +1,328 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Component, Optional, Injector } from '@angular/core';
|
||||
import { Content } from 'ionic-angular';
|
||||
|
||||
import { CoreApp } from '@providers/app';
|
||||
import { CoreEvents } from '@providers/events';
|
||||
import { CoreFilepool } from '@providers/filepool';
|
||||
import { CoreWSExternalFile } from '@providers/ws';
|
||||
import { CoreDomUtils } from '@providers/utils/dom';
|
||||
import { CoreCourseModuleMainActivityComponent } from '@core/course/classes/main-activity-component';
|
||||
import { CoreH5P } from '@core/h5p/providers/h5p';
|
||||
import { CoreH5PDisplayOptions } from '@core/h5p/classes/core';
|
||||
import { CoreH5PHelper } from '@core/h5p/classes/helper';
|
||||
import { CoreConstants } from '@core/constants';
|
||||
import { CoreSite } from '@classes/site';
|
||||
|
||||
import {
|
||||
AddonModH5PActivity, AddonModH5PActivityProvider, AddonModH5PActivityData, AddonModH5PActivityAccessInfo
|
||||
} from '../../providers/h5pactivity';
|
||||
|
||||
/**
|
||||
* Component that displays an H5P activity entry page.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'addon-mod-h5pactivity-index',
|
||||
templateUrl: 'addon-mod-h5pactivity-index.html',
|
||||
})
|
||||
export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActivityComponent {
|
||||
component = AddonModH5PActivityProvider.COMPONENT;
|
||||
moduleName = 'h5pactivity';
|
||||
|
||||
h5pActivity: AddonModH5PActivityData; // The H5P activity object.
|
||||
accessInfo: AddonModH5PActivityAccessInfo; // Info about the user capabilities.
|
||||
deployedFile: CoreWSExternalFile; // The H5P deployed file.
|
||||
|
||||
stateMessage: string; // Message about the file state.
|
||||
downloading: boolean; // Whether the H5P file is being downloaded.
|
||||
needsDownload: boolean; // Whether the file needs to be downloaded.
|
||||
percentage: string; // Download/unzip percentage.
|
||||
progressMessage: string; // Message about download/unzip.
|
||||
playing: boolean; // Whether the package is being played.
|
||||
displayOptions: CoreH5PDisplayOptions; // Display options for the package.
|
||||
onlinePlayerUrl: string; // URL to play the package in online.
|
||||
fileUrl: string; // The fileUrl to use to play the package.
|
||||
state: string; // State of the file.
|
||||
siteCanDownload: boolean;
|
||||
|
||||
protected fetchContentDefaultError = 'addon.mod_h5pactivity.errorgetactivity';
|
||||
protected site: CoreSite;
|
||||
protected observer;
|
||||
|
||||
constructor(injector: Injector,
|
||||
@Optional() protected content: Content) {
|
||||
super(injector, content);
|
||||
|
||||
this.site = this.sitesProvider.getCurrentSite();
|
||||
this.siteCanDownload = this.site.canDownloadFiles() && !CoreH5P.instance.isOfflineDisabledInSite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Component being initialized.
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
|
||||
this.loadContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the completion.
|
||||
*/
|
||||
protected checkCompletion(): void {
|
||||
this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the activity data.
|
||||
*
|
||||
* @param refresh If it's refreshing content.
|
||||
* @param sync If it should try to sync.
|
||||
* @param showErrors If show errors to the user of hide them.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
protected async fetchContent(refresh: boolean = false, sync: boolean = false, showErrors: boolean = false): Promise<void> {
|
||||
try {
|
||||
this.h5pActivity = await AddonModH5PActivity.instance.getH5PActivity(this.courseId, this.module.id);
|
||||
|
||||
this.dataRetrieved.emit(this.h5pActivity);
|
||||
this.description = this.h5pActivity.intro;
|
||||
this.displayOptions = CoreH5PHelper.decodeDisplayOptions(this.h5pActivity.displayoptions);
|
||||
|
||||
if (this.h5pActivity.package && this.h5pActivity.package[0]) {
|
||||
// The online player should use the original file, not the trusted one.
|
||||
this.onlinePlayerUrl = CoreH5P.instance.h5pPlayer.calculateOnlinePlayerUrl(
|
||||
this.site.getURL(), this.h5pActivity.package[0].fileurl, this.displayOptions);
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
this.fetchAccessInfo(),
|
||||
this.fetchDeployedFileData(),
|
||||
]);
|
||||
|
||||
if (!this.siteCanDownload || this.state == CoreConstants.DOWNLOADED) {
|
||||
// Cannot download the file or already downloaded, play the package directly.
|
||||
this.play();
|
||||
|
||||
} else if ((this.state == CoreConstants.NOT_DOWNLOADED || this.state == CoreConstants.OUTDATED) &&
|
||||
CoreFilepool.instance.shouldDownload(this.deployedFile.filesize) && CoreApp.instance.isOnline()) {
|
||||
// Package is small, download it automatically. Don't block this function for this.
|
||||
this.downloadAutomatically();
|
||||
}
|
||||
} finally {
|
||||
this.fillContextMenu(refresh);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the access info and store it in the right variables.
|
||||
*
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
protected async fetchAccessInfo(): Promise<void> {
|
||||
this.accessInfo = await AddonModH5PActivity.instance.getAccessInformation(this.h5pActivity.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the deployed file data if needed and store it in the right variables.
|
||||
*
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
protected async fetchDeployedFileData(): Promise<void> {
|
||||
if (!this.siteCanDownload) {
|
||||
// Cannot download the file, no need to fetch the file data.
|
||||
return;
|
||||
}
|
||||
|
||||
this.deployedFile = await AddonModH5PActivity.instance.getDeployedFile(this.h5pActivity, {
|
||||
displayOptions: this.displayOptions,
|
||||
siteId: this.siteId,
|
||||
});
|
||||
|
||||
this.fileUrl = this.deployedFile.fileurl;
|
||||
|
||||
// Listen for changes in the state.
|
||||
const eventName = await CoreFilepool.instance.getFileEventNameByUrl(this.siteId, this.deployedFile.fileurl);
|
||||
|
||||
if (!this.observer) {
|
||||
this.observer = CoreEvents.instance.on(eventName, () => {
|
||||
this.calculateFileState();
|
||||
});
|
||||
}
|
||||
|
||||
await this.calculateFileState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the state of the deployed file.
|
||||
*
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
protected async calculateFileState(): Promise<void> {
|
||||
this.state = await CoreFilepool.instance.getFileStateByUrl(this.siteId, this.deployedFile.fileurl,
|
||||
this.deployedFile.timemodified);
|
||||
|
||||
this.showFileState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the invalidate content function.
|
||||
*
|
||||
* @return Resolved when done.
|
||||
*/
|
||||
protected invalidateContent(): Promise<any> {
|
||||
return AddonModH5PActivity.instance.invalidateActivityData(this.courseId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays some data based on the state of the main file.
|
||||
*/
|
||||
protected showFileState(): void {
|
||||
|
||||
if (this.state == CoreConstants.OUTDATED) {
|
||||
this.stateMessage = 'addon.mod_h5pactivity.filestateoutdated';
|
||||
this.needsDownload = true;
|
||||
} else if (this.state == CoreConstants.NOT_DOWNLOADED) {
|
||||
this.stateMessage = 'addon.mod_h5pactivity.filestatenotdownloaded';
|
||||
this.needsDownload = true;
|
||||
} else if (this.state == CoreConstants.DOWNLOADING) {
|
||||
this.stateMessage = '';
|
||||
|
||||
if (!this.downloading) {
|
||||
// It's being downloaded right now but the view isn't tracking it. "Restore" the download.
|
||||
this.downloadDeployedFile().then(() => {
|
||||
this.play();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.stateMessage = '';
|
||||
this.needsDownload = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the file and play it.
|
||||
*
|
||||
* @param e Click event.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
async downloadAndPlay(e: MouseEvent): Promise<void> {
|
||||
e && e.preventDefault();
|
||||
e && e.stopPropagation();
|
||||
|
||||
if (!CoreApp.instance.isOnline()) {
|
||||
CoreDomUtils.instance.showErrorModal('core.networkerrormsg', true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Confirm the download if needed.
|
||||
await CoreDomUtils.instance.confirmDownloadSize({ size: this.deployedFile.filesize, total: true });
|
||||
|
||||
await this.downloadDeployedFile();
|
||||
|
||||
if (!this.isDestroyed) {
|
||||
this.play();
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
if (CoreDomUtils.instance.isCanceledError(error) || this.isDestroyed) {
|
||||
// User cancelled or view destroyed, stop.
|
||||
return;
|
||||
}
|
||||
|
||||
CoreDomUtils.instance.showErrorModalDefault(error, 'core.errordownloading', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the file automatically.
|
||||
*
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
protected async downloadAutomatically(): Promise<void> {
|
||||
try {
|
||||
await this.downloadDeployedFile();
|
||||
|
||||
if (!this.isDestroyed) {
|
||||
this.play();
|
||||
}
|
||||
} catch (error) {
|
||||
CoreDomUtils.instance.showErrorModalDefault(error, 'core.errordownloading', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download athe H5P deployed file or restores an ongoing download.
|
||||
*
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
protected async downloadDeployedFile(): Promise<void> {
|
||||
this.downloading = true;
|
||||
this.progressMessage = 'core.downloading';
|
||||
|
||||
try {
|
||||
await CoreFilepool.instance.downloadUrl(this.siteId, this.deployedFile.fileurl, false, this.component, this.componentId,
|
||||
this.deployedFile.timemodified, (data) => {
|
||||
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.message) {
|
||||
// Show a message.
|
||||
this.progressMessage = data.message;
|
||||
this.percentage = undefined;
|
||||
} else if (typeof data.loaded != 'undefined') {
|
||||
if (this.progressMessage == 'core.downloading') {
|
||||
// Downloading package.
|
||||
this.percentage = (Number(data.loaded / this.deployedFile.filesize) * 100).toFixed(1);
|
||||
} else if (typeof data.total != 'undefined') {
|
||||
// Unzipping package.
|
||||
this.percentage = (Number(data.loaded / data.total) * 100).toFixed(1);
|
||||
} else {
|
||||
this.percentage = undefined;
|
||||
}
|
||||
} else {
|
||||
this.percentage = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
} finally {
|
||||
this.progressMessage = undefined;
|
||||
this.percentage = undefined;
|
||||
this.downloading = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the package.
|
||||
*/
|
||||
play(): void {
|
||||
this.playing = true;
|
||||
|
||||
// Mark the activity as viewed.
|
||||
AddonModH5PActivity.instance.logView(this.h5pActivity.id, this.h5pActivity.name, this.siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Component destroyed.
|
||||
*/
|
||||
ngOnDestroy(): void {
|
||||
this.observer && this.observer.off();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
|
||||
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
|
||||
import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate';
|
||||
|
||||
import { AddonModH5PActivityComponentsModule } from './components/components.module';
|
||||
import { AddonModH5PActivityModuleHandler } from './providers/module-handler';
|
||||
import { AddonModH5PActivityProvider } from './providers/h5pactivity';
|
||||
import { AddonModH5PActivityPrefetchHandler } from './providers/prefetch-handler';
|
||||
import { AddonModH5PActivityIndexLinkHandler } from './providers/index-link-handler';
|
||||
|
||||
// List of providers (without handlers).
|
||||
export const ADDON_MOD_H5P_ACTIVITY_PROVIDERS: any[] = [
|
||||
AddonModH5PActivityProvider,
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
],
|
||||
imports: [
|
||||
AddonModH5PActivityComponentsModule
|
||||
],
|
||||
providers: [
|
||||
AddonModH5PActivityProvider,
|
||||
AddonModH5PActivityModuleHandler,
|
||||
AddonModH5PActivityPrefetchHandler,
|
||||
AddonModH5PActivityIndexLinkHandler,
|
||||
]
|
||||
})
|
||||
export class AddonModH5PActivityModule {
|
||||
constructor(moduleDelegate: CoreCourseModuleDelegate,
|
||||
moduleHandler: AddonModH5PActivityModuleHandler,
|
||||
prefetchDelegate: CoreCourseModulePrefetchDelegate,
|
||||
prefetchHandler: AddonModH5PActivityPrefetchHandler,
|
||||
linksDelegate: CoreContentLinksDelegate,
|
||||
indexHandler: AddonModH5PActivityIndexLinkHandler) {
|
||||
|
||||
moduleDelegate.registerHandler(moduleHandler);
|
||||
prefetchDelegate.registerHandler(prefetchHandler);
|
||||
linksDelegate.registerHandler(indexHandler);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"downloadh5pfile": "Download H5P file",
|
||||
"errorgetactivity": "Error getting H5P activity data.",
|
||||
"filestatenotdownloaded": "The H5P package is not downloaded. You need to download it to be able to use it.",
|
||||
"filestateoutdated": "The H5P package has been modified since the last download. You need to download it again to be able to use it.",
|
||||
"modulenameplural": "H5P",
|
||||
"offlinedisabledwarning": "You will need to be online to view the H5P package."
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<ion-header>
|
||||
<ion-navbar core-back-button>
|
||||
<ion-title><core-format-text [text]="title" contextLevel="module" [contextInstanceId]="module.id" [courseId]="courseId"></core-format-text></ion-title>
|
||||
|
||||
<ion-buttons end>
|
||||
<!-- The buttons defined by the component will be added in here. -->
|
||||
</ion-buttons>
|
||||
</ion-navbar>
|
||||
</ion-header>
|
||||
<ion-content>
|
||||
<ion-refresher [enabled]="h5pComponent.loaded" (ionRefresh)="h5pComponent.doRefresh($event)">
|
||||
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
|
||||
</ion-refresher>
|
||||
|
||||
<addon-mod-h5pactivity-index [module]="module" [courseId]="courseId" (dataRetrieved)="updateData($event)"></addon-mod-h5pactivity-index>
|
||||
</ion-content>
|
|
@ -0,0 +1,33 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { NgModule } from '@angular/core';
|
||||
import { IonicPageModule } from 'ionic-angular';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CoreDirectivesModule } from '@directives/directives.module';
|
||||
import { AddonModH5PActivityComponentsModule } from '../../components/components.module';
|
||||
import { AddonModH5PActivityIndexPage } from './index';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AddonModH5PActivityIndexPage,
|
||||
],
|
||||
imports: [
|
||||
CoreDirectivesModule,
|
||||
AddonModH5PActivityComponentsModule,
|
||||
IonicPageModule.forChild(AddonModH5PActivityIndexPage),
|
||||
TranslateModule.forChild()
|
||||
],
|
||||
})
|
||||
export class AddonModH5PActivityIndexPageModule {}
|
|
@ -0,0 +1,49 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Component, ViewChild } from '@angular/core';
|
||||
import { IonicPage, NavParams } from 'ionic-angular';
|
||||
import { AddonModH5PActivityIndexComponent } from '../../components/index/index';
|
||||
import { AddonModH5PActivityData } from '../../providers/h5pactivity';
|
||||
|
||||
/**
|
||||
* Page that displays an H5P activity.
|
||||
*/
|
||||
@IonicPage({ segment: 'addon-mod-h5pactivity-index' })
|
||||
@Component({
|
||||
selector: 'page-addon-mod-h5pactivity-index',
|
||||
templateUrl: 'index.html',
|
||||
})
|
||||
export class AddonModH5PActivityIndexPage {
|
||||
@ViewChild(AddonModH5PActivityIndexComponent) h5pComponent: AddonModH5PActivityIndexComponent;
|
||||
|
||||
title: string;
|
||||
module: any;
|
||||
courseId: number;
|
||||
|
||||
constructor(navParams: NavParams) {
|
||||
this.module = navParams.get('module') || {};
|
||||
this.courseId = navParams.get('courseId');
|
||||
this.title = this.module.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update some data based on the H5P activity instance.
|
||||
*
|
||||
* @param h5p H5P activity instance.
|
||||
*/
|
||||
updateData(h5p: AddonModH5PActivityData): void {
|
||||
this.title = h5p.name || this.title;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,296 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { CoreSites } from '@providers/sites';
|
||||
import { CoreWSExternalWarning, CoreWSExternalFile } from '@providers/ws';
|
||||
import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
|
||||
import { CoreCourseLogHelper } from '@core/course/providers/log-helper';
|
||||
import { CoreH5P } from '@core/h5p/providers/h5p';
|
||||
import { CoreH5PDisplayOptions } from '@core/h5p/classes/core';
|
||||
|
||||
import { makeSingleton, Translate } from '@singletons/core.singletons';
|
||||
|
||||
/**
|
||||
* Service that provides some features for H5P activity.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonModH5PActivityProvider {
|
||||
static COMPONENT = 'mmaModH5PActivity';
|
||||
|
||||
protected ROOT_CACHE_KEY = 'mmaModH5PActivity:';
|
||||
|
||||
/**
|
||||
* Get cache key for access information WS calls.
|
||||
*
|
||||
* @param id H5P activity ID.
|
||||
* @return Cache key.
|
||||
*/
|
||||
protected getAccessInformationCacheKey(id: number): string {
|
||||
return this.ROOT_CACHE_KEY + 'accessInfo:' + id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get access information for a given H5P activity.
|
||||
*
|
||||
* @param id H5P activity ID.
|
||||
* @param forceCache True to always get the value from cache. false otherwise.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved with the data.
|
||||
*/
|
||||
async getAccessInformation(id: number, forceCache?: boolean, siteId?: string): Promise<AddonModH5PActivityAccessInfo> {
|
||||
|
||||
const site = await CoreSites.instance.getSite(siteId);
|
||||
|
||||
const params = {
|
||||
h5pactivityid: id,
|
||||
};
|
||||
const preSets = {
|
||||
cacheKey: this.getAccessInformationCacheKey(id),
|
||||
omitExpires: forceCache,
|
||||
};
|
||||
|
||||
return site.read('mod_h5pactivity_get_h5pactivity_access_information', params, preSets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get deployed file from an H5P activity instance.
|
||||
*
|
||||
* @param h5pActivity Activity instance.
|
||||
* @param options Options
|
||||
* @return Promise resolved with the file.
|
||||
*/
|
||||
async getDeployedFile(h5pActivity: AddonModH5PActivityData, options?: AddonModH5PActivityGetDeployedFileOptions)
|
||||
: Promise<CoreWSExternalFile> {
|
||||
|
||||
if (h5pActivity.deployedfile) {
|
||||
// File already deployed and still valid, use this one.
|
||||
return h5pActivity.deployedfile;
|
||||
} else {
|
||||
if (!h5pActivity.package || !h5pActivity.package[0]) {
|
||||
// Shouldn't happen.
|
||||
throw 'No H5P package found.';
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
// Deploy the file in the server.
|
||||
return CoreH5P.instance.getTrustedH5PFile(h5pActivity.package[0].fileurl, options.displayOptions,
|
||||
options.ignoreCache, options.siteId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache key for H5P activity data WS calls.
|
||||
*
|
||||
* @param courseId Course ID.
|
||||
* @return Cache key.
|
||||
*/
|
||||
protected getH5PActivityDataCacheKey(courseId: number): string {
|
||||
return this.ROOT_CACHE_KEY + 'h5pactivity:' + courseId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an H5P activity with key=value. If more than one is found, only the first will be returned.
|
||||
*
|
||||
* @param courseId Course ID.
|
||||
* @param key Name of the property to check.
|
||||
* @param value Value to search.
|
||||
* @param moduleUrl Module URL.
|
||||
* @param forceCache Whether it should always return cached data.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved with the activity data.
|
||||
*/
|
||||
protected async getH5PActivityByField(courseId: number, key: string, value: any, forceCache?: boolean, siteId?: string)
|
||||
: Promise<AddonModH5PActivityData> {
|
||||
|
||||
const site = await CoreSites.instance.getSite(siteId);
|
||||
|
||||
const params = {
|
||||
courseids: [courseId],
|
||||
};
|
||||
const preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.getH5PActivityDataCacheKey(courseId),
|
||||
updateFrequency: CoreSite.FREQUENCY_RARELY,
|
||||
};
|
||||
|
||||
if (forceCache) {
|
||||
preSets.omitExpires = true;
|
||||
}
|
||||
|
||||
const response: AddonModH5PActivityGetByCoursesResult =
|
||||
await site.read('mod_h5pactivity_get_h5pactivities_by_courses', params, preSets);
|
||||
|
||||
if (response && response.h5pactivities) {
|
||||
const currentActivity = response.h5pactivities.find((h5pActivity) => {
|
||||
return h5pActivity[key] == value;
|
||||
});
|
||||
|
||||
if (currentActivity) {
|
||||
return currentActivity;
|
||||
}
|
||||
}
|
||||
|
||||
throw Translate.instance.instant('addon.mod_h5pactivity.errorgetactivity');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an H5P activity by module ID.
|
||||
*
|
||||
* @param courseId Course ID.
|
||||
* @param cmId Course module ID.
|
||||
* @param forceCache Whether it should always return cached data.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved with the activity data.
|
||||
*/
|
||||
getH5PActivity(courseId: number, cmId: number, forceCache?: boolean, siteId?: string): Promise<AddonModH5PActivityData> {
|
||||
return this.getH5PActivityByField(courseId, 'coursemodule', cmId, forceCache, siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an H5P activity by instance ID.
|
||||
*
|
||||
* @param courseId Course ID.
|
||||
* @param id Instance ID.
|
||||
* @param forceCache Whether it should always return cached data.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved with the activity data.
|
||||
*/
|
||||
getH5PActivityById(courseId: number, id: number, forceCache?: boolean, siteId?: string): Promise<AddonModH5PActivityData> {
|
||||
return this.getH5PActivityByField(courseId, 'id', id, forceCache, siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates access information.
|
||||
*
|
||||
* @param id H5P activity ID.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved when the data is invalidated.
|
||||
*/
|
||||
async invalidateAccessInformation(id: number, siteId?: string): Promise<void> {
|
||||
|
||||
const site = await CoreSites.instance.getSite(siteId);
|
||||
|
||||
await site.invalidateWsCacheForKey(this.getAccessInformationCacheKey(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates H5P activity data.
|
||||
*
|
||||
* @param courseId Course ID.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved when the data is invalidated.
|
||||
*/
|
||||
async invalidateActivityData(courseId: number, siteId?: string): Promise<void> {
|
||||
const site = await CoreSites.instance.getSite(siteId);
|
||||
|
||||
await site.invalidateWsCacheForKey(this.getH5PActivityDataCacheKey(courseId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete launcher.
|
||||
*
|
||||
* @return Promise resolved when the launcher file is deleted.
|
||||
*/
|
||||
async isPluginEnabled(siteId?: string): Promise<boolean> {
|
||||
const site = await CoreSites.instance.getSite(siteId);
|
||||
|
||||
return site.wsAvailable('mod_h5pactivity_get_h5pactivities_by_courses');
|
||||
}
|
||||
|
||||
/**
|
||||
* Report an H5P activity as being viewed.
|
||||
*
|
||||
* @param id H5P activity ID.
|
||||
* @param name Name of the activity.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved when the WS call is successful.
|
||||
*/
|
||||
logView(id: number, name?: string, siteId?: string): Promise<void> {
|
||||
const params = {
|
||||
h5pactivityid: id,
|
||||
};
|
||||
|
||||
return CoreCourseLogHelper.instance.logSingle(
|
||||
'mod_h5pactivity_view_h5pactivity',
|
||||
params,
|
||||
AddonModH5PActivityProvider.COMPONENT,
|
||||
id,
|
||||
name,
|
||||
'h5pactivity',
|
||||
{},
|
||||
siteId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class AddonModH5PActivity extends makeSingleton(AddonModH5PActivityProvider) {}
|
||||
|
||||
/**
|
||||
* Basic data for an H5P activity, exported by Moodle class h5pactivity_summary_exporter.
|
||||
*/
|
||||
export type AddonModH5PActivityData = {
|
||||
id: number; // The primary key of the record.
|
||||
course: number; // Course id this h5p activity is part of.
|
||||
name: string; // The name of the activity module instance.
|
||||
timecreated?: number; // Timestamp of when the instance was added to the course.
|
||||
timemodified?: number; // Timestamp of when the instance was last modified.
|
||||
intro: string; // H5P activity description.
|
||||
introformat: number; // Intro format (1 = HTML, 0 = MOODLE, 2 = PLAIN or 4 = MARKDOWN).
|
||||
grade?: number; // The maximum grade for submission.
|
||||
displayoptions: number; // H5P Button display options.
|
||||
enabletracking: number; // Enable xAPI tracking.
|
||||
grademethod: number; // Which H5P attempt is used for grading.
|
||||
contenthash?: string; // Sha1 hash of file content.
|
||||
coursemodule: number; // Coursemodule.
|
||||
introfiles: CoreWSExternalFile[];
|
||||
package: CoreWSExternalFile[];
|
||||
deployedfile?: {
|
||||
filename?: string; // File name.
|
||||
filepath?: string; // File path.
|
||||
filesize?: number; // File size.
|
||||
fileurl?: string; // Downloadable file url.
|
||||
timemodified?: number; // Time modified.
|
||||
mimetype?: string; // File mime type.
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Result of WS mod_h5pactivity_get_h5pactivities_by_courses.
|
||||
*/
|
||||
export type AddonModH5PActivityGetByCoursesResult = {
|
||||
h5pactivities: AddonModH5PActivityData[];
|
||||
warnings?: CoreWSExternalWarning[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Result of WS mod_h5pactivity_get_h5pactivity_access_information.
|
||||
*/
|
||||
export type AddonModH5PActivityAccessInfo = {
|
||||
warnings?: CoreWSExternalWarning[];
|
||||
canview?: boolean; // Whether the user has the capability mod/h5pactivity:view allowed.
|
||||
canaddinstance?: boolean; // Whether the user has the capability mod/h5pactivity:addinstance allowed.
|
||||
cansubmit?: boolean; // Whether the user has the capability mod/h5pactivity:submit allowed.
|
||||
canreviewattempts?: boolean; // Whether the user has the capability mod/h5pactivity:reviewattempts allowed.
|
||||
};
|
||||
|
||||
/**
|
||||
* Options to pass to getDeployedFile function.
|
||||
*/
|
||||
export type AddonModH5PActivityGetDeployedFileOptions = {
|
||||
displayOptions?: CoreH5PDisplayOptions; // Display options
|
||||
ignoreCache?: boolean; // Whether to ignore cache. Will fail if offline or server down.
|
||||
siteId?: string; // Site ID. If not defined, current site.
|
||||
};
|
|
@ -0,0 +1,29 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler';
|
||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||
|
||||
/**
|
||||
* Handler to treat links to H5P activity index.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonModH5PActivityIndexLinkHandler extends CoreContentLinksModuleIndexHandler {
|
||||
name = 'AddonModH5PActivityIndexLinkHandler';
|
||||
|
||||
constructor(courseHelper: CoreCourseHelperProvider) {
|
||||
super(courseHelper, 'AddonModH5PActivity', 'h5pactivity');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { NavController, NavOptions } from 'ionic-angular';
|
||||
|
||||
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@core/course/providers/module-delegate';
|
||||
import { CoreCourse } from '@core/course/providers/course';
|
||||
import { CoreConstants } from '@core/constants';
|
||||
|
||||
import { AddonModH5PActivity } from './h5pactivity';
|
||||
import { AddonModH5PActivityIndexComponent } from '../components/index/index';
|
||||
|
||||
/**
|
||||
* Handler to support H5P activities.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonModH5PActivityModuleHandler implements CoreCourseModuleHandler {
|
||||
name = 'AddonModH5PActivity';
|
||||
modName = 'h5pactivity';
|
||||
|
||||
supportedFeatures = {
|
||||
[CoreConstants.FEATURE_GROUPS]: true,
|
||||
[CoreConstants.FEATURE_GROUPINGS]: true,
|
||||
[CoreConstants.FEATURE_MOD_INTRO]: true,
|
||||
[CoreConstants.FEATURE_SHOW_DESCRIPTION]: true,
|
||||
[CoreConstants.FEATURE_COMPLETION_TRACKS_VIEWS]: true,
|
||||
[CoreConstants.FEATURE_MODEDIT_DEFAULT_COMPLETION]: true,
|
||||
[CoreConstants.FEATURE_GRADE_HAS_GRADE]: true,
|
||||
[CoreConstants.FEATURE_GRADE_OUTCOMES]: true,
|
||||
[CoreConstants.FEATURE_BACKUP_MOODLE2]: true,
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the handler is enabled on a site level.
|
||||
*
|
||||
* @return Whether or not the handler is enabled on a site level.
|
||||
*/
|
||||
isEnabled(): Promise<boolean> {
|
||||
return AddonModH5PActivity.instance.isPluginEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data required to display the module in the course contents view.
|
||||
*
|
||||
* @param module The module object.
|
||||
* @param courseId The course ID.
|
||||
* @param sectionId The section ID.
|
||||
* @return Data to render the module.
|
||||
*/
|
||||
getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData {
|
||||
|
||||
return {
|
||||
icon: CoreCourse.instance.getModuleIconSrc(this.modName, module.modicon),
|
||||
title: module.name,
|
||||
class: 'addon-mod_h5pactivity-handler',
|
||||
showDownloadButton: true,
|
||||
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
|
||||
const pageParams = {module: module, courseId: courseId};
|
||||
if (params) {
|
||||
Object.assign(pageParams, params);
|
||||
}
|
||||
navCtrl.push('AddonModH5PActivityIndexPage', pageParams, options);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component to render the module. This is needed to support singleactivity course format.
|
||||
* The component returned must implement CoreCourseModuleMainComponent.
|
||||
*
|
||||
* @param course The course object.
|
||||
* @param module The module object.
|
||||
* @return The component to use, undefined if not found.
|
||||
*/
|
||||
getMainComponent(course: any, module: any): any {
|
||||
return AddonModH5PActivityIndexComponent;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { CoreAppProvider } from '@providers/app';
|
||||
import { CoreFilepoolProvider } from '@providers/filepool';
|
||||
import { CorePluginFileDelegate } from '@providers/plugin-file-delegate';
|
||||
import { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreWSExternalFile } from '@providers/ws';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CoreCourseProvider } from '@core/course/providers/course';
|
||||
import { CoreCourseActivityPrefetchHandlerBase } from '@core/course/classes/activity-prefetch-handler';
|
||||
import { CoreFilterHelperProvider } from '@core/filter/providers/helper';
|
||||
import { CoreH5PHelper } from '@core/h5p/classes/helper';
|
||||
import { CoreH5P } from '@core/h5p/providers/h5p';
|
||||
import { CoreUserProvider } from '@core/user/providers/user';
|
||||
import { AddonModH5PActivity, AddonModH5PActivityProvider, AddonModH5PActivityData } from './h5pactivity';
|
||||
|
||||
/**
|
||||
* Handler to prefetch h5p activity.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonModH5PActivityPrefetchHandler extends CoreCourseActivityPrefetchHandlerBase {
|
||||
name = 'AddonModH5PActivity';
|
||||
modName = 'h5pactivity';
|
||||
component = AddonModH5PActivityProvider.COMPONENT;
|
||||
updatesNames = /^configuration$|^.*files$|^tracks$|^usertracks$/;
|
||||
|
||||
constructor(translate: TranslateService,
|
||||
appProvider: CoreAppProvider,
|
||||
utils: CoreUtilsProvider,
|
||||
courseProvider: CoreCourseProvider,
|
||||
filepoolProvider: CoreFilepoolProvider,
|
||||
sitesProvider: CoreSitesProvider,
|
||||
domUtils: CoreDomUtilsProvider,
|
||||
filterHelper: CoreFilterHelperProvider,
|
||||
pluginFileDelegate: CorePluginFileDelegate,
|
||||
protected userProvider: CoreUserProvider,
|
||||
protected injector: Injector) {
|
||||
|
||||
super(translate, appProvider, utils, courseProvider, filepoolProvider, sitesProvider, domUtils, filterHelper,
|
||||
pluginFileDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of files.
|
||||
*
|
||||
* @param module Module.
|
||||
* @param courseId Course ID the module belongs to.
|
||||
* @param single True if we're downloading a single module, false if we're downloading a whole section.
|
||||
* @return Promise resolved with the list of files.
|
||||
*/
|
||||
async getFiles(module: any, courseId: number, single?: boolean): Promise<CoreWSExternalFile[]> {
|
||||
|
||||
const h5pActivity = await AddonModH5PActivity.instance.getH5PActivity(courseId, module.id);
|
||||
|
||||
const displayOptions = CoreH5PHelper.decodeDisplayOptions(h5pActivity.displayoptions);
|
||||
|
||||
const deployedFile = await AddonModH5PActivity.instance.getDeployedFile(h5pActivity, {
|
||||
displayOptions: displayOptions,
|
||||
});
|
||||
|
||||
return [deployedFile].concat(this.getIntroFilesFromInstance(module, h5pActivity));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate WS calls needed to determine module status (usually, to check if module is downloadable).
|
||||
* It doesn't need to invalidate check updates. It should NOT invalidate files nor all the prefetched data.
|
||||
*
|
||||
* @param module Module.
|
||||
* @param courseId Course ID the module belongs to.
|
||||
* @return Promise resolved when invalidated.
|
||||
*/
|
||||
async invalidateModule(module: any, courseId: number): Promise<void> {
|
||||
// No need to invalidate anything.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a module can be downloaded. If the function is not defined, we assume that all modules are downloadable.
|
||||
*
|
||||
* @param module Module.
|
||||
* @param courseId Course ID the module belongs to.
|
||||
* @return Whether the module can be downloaded. The promise should never be rejected.
|
||||
*/
|
||||
isDownloadable(module: any, courseId: number): boolean | Promise<boolean> {
|
||||
return this.sitesProvider.getCurrentSite().canDownloadFiles() && !CoreH5P.instance.isOfflineDisabledInSite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the handler is enabled on a site level.
|
||||
*
|
||||
* @return A boolean, or a promise resolved with a boolean, indicating if the handler is enabled.
|
||||
*/
|
||||
isEnabled(): boolean | Promise<boolean> {
|
||||
return AddonModH5PActivity.instance.isPluginEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefetch a module.
|
||||
*
|
||||
* @param module Module.
|
||||
* @param courseId Course ID the module belongs to.
|
||||
* @param single True if we're downloading a single module, false if we're downloading a whole section.
|
||||
* @param dirPath Path of the directory where to store all the content files.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
prefetch(module: any, courseId?: number, single?: boolean, dirPath?: string): Promise<any> {
|
||||
return this.prefetchPackage(module, courseId, single, this.prefetchActivity.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefetch an H5P activity.
|
||||
*
|
||||
* @param module Module.
|
||||
* @param courseId Course ID the module belongs to.
|
||||
* @param single True if we're downloading a single module, false if we're downloading a whole section.
|
||||
* @param siteId Site ID.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
protected async prefetchActivity(module: any, courseId: number, single: boolean, siteId: string): Promise<void> {
|
||||
|
||||
const h5pActivity = await AddonModH5PActivity.instance.getH5PActivity(courseId, module.id, true, siteId);
|
||||
|
||||
const introFiles = this.getIntroFilesFromInstance(module, h5pActivity);
|
||||
|
||||
await Promise.all([
|
||||
AddonModH5PActivity.instance.getAccessInformation(h5pActivity.id, true, siteId),
|
||||
this.filepoolProvider.addFilesToQueue(siteId, introFiles, AddonModH5PActivityProvider.COMPONENT, module.id),
|
||||
this.prefetchMainFile(module, h5pActivity, siteId),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefetch the deployed file of the activity.
|
||||
*
|
||||
* @param module Module.
|
||||
* @param h5pActivity Activity instance.
|
||||
* @param siteId Site ID.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
protected async prefetchMainFile(module: any, h5pActivity: AddonModH5PActivityData, siteId: string): Promise<void> {
|
||||
|
||||
const displayOptions = CoreH5PHelper.decodeDisplayOptions(h5pActivity.displayoptions);
|
||||
|
||||
const deployedFile = await AddonModH5PActivity.instance.getDeployedFile(h5pActivity, {
|
||||
displayOptions: displayOptions,
|
||||
ignoreCache: true,
|
||||
siteId: siteId,
|
||||
});
|
||||
|
||||
await this.filepoolProvider.addFilesToQueue(siteId, [deployedFile], AddonModH5PActivityProvider.COMPONENT, module.id);
|
||||
}
|
||||
}
|
|
@ -1257,7 +1257,7 @@ export class AddonModScormProvider {
|
|||
/**
|
||||
* Invalidates access information.
|
||||
*
|
||||
* @param forumId SCORM ID.
|
||||
* @param scormId SCORM ID.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved when the data is invalidated.
|
||||
*/
|
||||
|
@ -1544,7 +1544,7 @@ export class AddonModScormProvider {
|
|||
|
||||
return this.logHelper.logSingle('mod_scorm_view_scorm', params, AddonModScormProvider.COMPONENT, id, name, 'scorm', {},
|
||||
siteId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a SCORM tracking record.
|
||||
|
|
|
@ -155,6 +155,7 @@ import { AddonQbehaviourModule } from '@addon/qbehaviour/qbehaviour.module';
|
|||
import { AddonQtypeModule } from '@addon/qtype/qtype.module';
|
||||
import { AddonStorageManagerModule } from '@addon/storagemanager/storagemanager.module';
|
||||
import { AddonFilterModule } from '@addon/filter/filter.module';
|
||||
import { AddonModH5PActivityModule } from '@addon/mod/h5pactivity/h5pactivity.module';
|
||||
|
||||
import { setSingletonsInjector } from '@singletons/core.singletons';
|
||||
|
||||
|
@ -303,7 +304,8 @@ export const WP_PROVIDER: any = null;
|
|||
AddonQbehaviourModule,
|
||||
AddonQtypeModule,
|
||||
AddonStorageManagerModule,
|
||||
AddonFilterModule
|
||||
AddonFilterModule,
|
||||
AddonModH5PActivityModule,
|
||||
],
|
||||
bootstrap: [IonicApp],
|
||||
entryComponents: [
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" preserveAspectRatio="xMinYMid meet"><title>h5p finalArtboard 1</title><rect width="24" height="24" rx="3" ry="3" fill="#0882c8"/><path d="M22.1,8a3.37,3.37,0,0,0-2.42-.77H16.05v2H11.71l-.36,1.46a6.32,6.32,0,0,1,1-.35,3.49,3.49,0,0,1,.86-.06,3.24,3.24,0,0,1,2.35.88,2.93,2.93,0,0,1,.9,2.2A3.72,3.72,0,0,1,16,15.19a3.16,3.16,0,0,1-1.31,1.32,3.41,3.41,0,0,1-.67.27H17.7V13.28h1.65A3.8,3.8,0,0,0,22,12.46a3,3,0,0,0,.88-2.28A2.9,2.9,0,0,0,22.1,8Zm-2.44,3a1.88,1.88,0,0,1-1.21.29H17.7V9.2h.87a1.56,1.56,0,0,1,1.13.31,1,1,0,0,1,.3.76A.94.94,0,0,1,19.66,11Z" fill="#fff"/><path d="M12.27,12.05a1.33,1.33,0,0,0-1.19.74l-2.6-.37,1.17-5.2H7.29v4.08H4V7.23H1.1v9.55H4V13.28H7.29v3.49h3.57a3.61,3.61,0,0,1-1.13-.53A3.2,3.2,0,0,1,9,15.43a4,4,0,0,1-.48-1.09L11.09,14a1.32,1.32,0,1,0,1.18-1.92Z" fill="#fff"/></svg>
|
After Width: | Height: | Size: 859 B |
|
@ -659,6 +659,12 @@
|
|||
"addon.mod_glossary.noentriesfound": "No entries were found.",
|
||||
"addon.mod_glossary.searchquery": "Search query",
|
||||
"addon.mod_glossary.tagarea_glossary_entries": "Glossary entries",
|
||||
"addon.mod_h5pactivity.downloadh5pfile": "Download H5P file",
|
||||
"addon.mod_h5pactivity.errorgetactivity": "Error getting H5P activity data.",
|
||||
"addon.mod_h5pactivity.filestatenotdownloaded": "The H5P package is not downloaded. You need to download it to be able to use it.",
|
||||
"addon.mod_h5pactivity.filestateoutdated": "The H5P package has been modified since the last download. You need to download it again to be able to use it.",
|
||||
"addon.mod_h5pactivity.modulenameplural": "H5P",
|
||||
"addon.mod_h5pactivity.offlinedisabledwarning": "You will need to be online to view the H5P package.",
|
||||
"addon.mod_imscp.deploymenterror": "Content package error!",
|
||||
"addon.mod_imscp.modulenameplural": "IMS content packages",
|
||||
"addon.mod_imscp.showmoduledescription": "Show description",
|
||||
|
@ -2034,6 +2040,7 @@
|
|||
"core.sort": "Sort",
|
||||
"core.sortby": "Sort by",
|
||||
"core.start": "Start",
|
||||
"core.storingfiles": "Storing files",
|
||||
"core.strftimedate": "%d %B %Y",
|
||||
"core.strftimedatefullshort": "%d/%m/%y",
|
||||
"core.strftimedateshort": "%d %B",
|
||||
|
|
|
@ -109,6 +109,7 @@ import { ADDON_MOD_FEEDBACK_PROVIDERS } from '@addon/mod/feedback/feedback.modul
|
|||
import { ADDON_MOD_FOLDER_PROVIDERS } from '@addon/mod/folder/folder.module';
|
||||
import { ADDON_MOD_FORUM_PROVIDERS } from '@addon/mod/forum/forum.module';
|
||||
import { ADDON_MOD_GLOSSARY_PROVIDERS } from '@addon/mod/glossary/glossary.module';
|
||||
import { ADDON_MOD_H5P_ACTIVITY_PROVIDERS } from '@addon/mod/h5pactivity/h5pactivity.module';
|
||||
import { ADDON_MOD_IMSCP_PROVIDERS } from '@addon/mod/imscp/imscp.module';
|
||||
import { ADDON_MOD_LESSON_PROVIDERS } from '@addon/mod/lesson/lesson.module';
|
||||
import { ADDON_MOD_LTI_PROVIDERS } from '@addon/mod/lti/lti.module';
|
||||
|
@ -242,7 +243,7 @@ export class CoreCompileProvider {
|
|||
.concat(ADDON_MOD_WORKSHOP_PROVIDERS).concat(ADDON_NOTES_PROVIDERS).concat(ADDON_NOTIFICATIONS_PROVIDERS)
|
||||
.concat(CORE_PUSHNOTIFICATIONS_PROVIDERS).concat(ADDON_REMOTETHEMES_PROVIDERS).concat(CORE_BLOCK_PROVIDERS)
|
||||
.concat(CORE_FILTER_PROVIDERS).concat(CORE_H5P_PROVIDERS).concat(CORE_EDITOR_PROVIDERS)
|
||||
.concat(CORE_SEARCH_PROVIDERS);
|
||||
.concat(CORE_SEARCH_PROVIDERS).concat(ADDON_MOD_H5P_ACTIVITY_PROVIDERS);
|
||||
|
||||
// We cannot inject anything to this constructor. Use the Injector to inject all the providers into the instance.
|
||||
for (const i in providers) {
|
||||
|
|
|
@ -31,6 +31,8 @@ import { CorePushNotificationsProvider } from '@core/pushnotifications/providers
|
|||
import { CoreCoursesProvider } from '@core/courses/providers/courses';
|
||||
import { makeSingleton } from '@singletons/core.singletons';
|
||||
|
||||
import { makeSingleton } from '@singletons/core.singletons';
|
||||
|
||||
/**
|
||||
* Service that provides some features regarding a course.
|
||||
*/
|
||||
|
@ -99,7 +101,7 @@ export class CoreCourseProvider {
|
|||
protected CORE_MODULES = [
|
||||
'assign', 'assignment', 'book', 'chat', 'choice', 'data', 'database', 'date', 'external-tool',
|
||||
'feedback', 'file', 'folder', 'forum', 'glossary', 'ims', 'imscp', 'label', 'lesson', 'lti', 'page', 'quiz',
|
||||
'resource', 'scorm', 'survey', 'url', 'wiki', 'workshop'
|
||||
'resource', 'scorm', 'survey', 'url', 'wiki', 'workshop', 'h5pactivity'
|
||||
];
|
||||
|
||||
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private eventsProvider: CoreEventsProvider,
|
||||
|
@ -1162,6 +1164,8 @@ export class CoreCourseProvider {
|
|||
}
|
||||
}
|
||||
|
||||
export class CoreCourse extends makeSingleton(CoreCourseProvider) {}
|
||||
|
||||
/**
|
||||
* Data returned by course_summary_exporter.
|
||||
*/
|
||||
|
|
|
@ -20,6 +20,8 @@ import { CoreUtilsProvider } from '@providers/utils/utils';
|
|||
import { CoreAppProvider } from '@providers/app';
|
||||
import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications';
|
||||
|
||||
import { makeSingleton } from '@singletons/core.singletons';
|
||||
|
||||
/**
|
||||
* Helper to manage logging to Moodle.
|
||||
*/
|
||||
|
@ -355,3 +357,5 @@ export class CoreCourseLogHelperProvider {
|
|||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class CoreCourseLogHelper extends makeSingleton(CoreCourseLogHelperProvider) {}
|
||||
|
|
|
@ -98,13 +98,7 @@ export class FileMock extends File {
|
|||
* @return Returns a Promise that resolves to the new Entry object or rejects with an error.
|
||||
*/
|
||||
copyDir(path: string, dirName: string, newPath: string, newDirName: string): Promise<Entry> {
|
||||
return this.resolveDirectoryUrl(path).then((fse) => {
|
||||
return this.getDirectory(fse, dirName, { create: false });
|
||||
}).then((srcde) => {
|
||||
return this.resolveDirectoryUrl(newPath).then((deste) => {
|
||||
return this.copyMock(srcde, deste, newDirName);
|
||||
});
|
||||
});
|
||||
return this.copyFileOrDir(path, dirName, newPath, newDirName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,15 +111,26 @@ export class FileMock extends File {
|
|||
* @return Returns a Promise that resolves to an Entry or rejects with an error.
|
||||
*/
|
||||
copyFile(path: string, fileName: string, newPath: string, newFileName: string): Promise<Entry> {
|
||||
newFileName = newFileName || fileName;
|
||||
return this.copyFileOrDir(path, fileName, newPath, newFileName || fileName);
|
||||
}
|
||||
|
||||
return this.resolveDirectoryUrl(path).then((fse) => {
|
||||
return this.getFile(fse, fileName, { create: false });
|
||||
}).then((srcfe) => {
|
||||
return this.resolveDirectoryUrl(newPath).then((deste) => {
|
||||
return this.copyMock(srcfe, deste, newFileName);
|
||||
});
|
||||
});
|
||||
/**
|
||||
* Copy a file or dir to a given path.
|
||||
*
|
||||
* @param sourcePath Path of the file/dir to copy.
|
||||
* @param sourceName Name of file/dir to copy
|
||||
* @param destPath Path where to copy.
|
||||
* @param destName New name of file/dir.
|
||||
* @return Returns a Promise that resolves to the new Entry or rejects with an error.
|
||||
*/
|
||||
async copyFileOrDir(sourcePath: string, sourceName: string, destPath: string, destName: string): Promise<Entry> {
|
||||
const destFixed = this.fixPathAndName(destPath, destName);
|
||||
|
||||
const source = await this.resolveLocalFilesystemUrl(this.textUtils.concatenatePaths(sourcePath, sourceName));
|
||||
|
||||
const destParentDir = await this.resolveDirectoryUrl(destFixed.path);
|
||||
|
||||
return this.copyMock(source, destParentDir, destFixed.name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -431,13 +436,7 @@ export class FileMock extends File {
|
|||
* an error.
|
||||
*/
|
||||
moveDir(path: string, dirName: string, newPath: string, newDirName: string): Promise<DirectoryEntry | Entry> {
|
||||
return this.resolveDirectoryUrl(path).then((fse) => {
|
||||
return this.getDirectory(fse, dirName, { create: false });
|
||||
}).then((srcde) => {
|
||||
return this.resolveDirectoryUrl(newPath).then((deste) => {
|
||||
return this.moveMock(srcde, deste, newDirName);
|
||||
});
|
||||
});
|
||||
return this.moveFileOrDir(path, dirName, newPath, newDirName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -450,15 +449,43 @@ export class FileMock extends File {
|
|||
* @return Returns a Promise that resolves to the new Entry or rejects with an error.
|
||||
*/
|
||||
moveFile(path: string, fileName: string, newPath: string, newFileName: string): Promise<Entry> {
|
||||
newFileName = newFileName || fileName;
|
||||
return this.moveFileOrDir(path, fileName, newPath, newFileName || fileName);
|
||||
}
|
||||
|
||||
return this.resolveDirectoryUrl(path).then((fse) => {
|
||||
return this.getFile(fse, fileName, { create: false });
|
||||
}).then((srcfe) => {
|
||||
return this.resolveDirectoryUrl(newPath).then((deste) => {
|
||||
return this.moveMock(srcfe, deste, newFileName);
|
||||
});
|
||||
});
|
||||
/**
|
||||
* Move a file or dir to a given path.
|
||||
*
|
||||
* @param sourcePath Path of the file/dir to copy.
|
||||
* @param sourceName Name of file/dir to copy
|
||||
* @param destPath Path where to copy.
|
||||
* @param destName New name of file/dir.
|
||||
* @return Returns a Promise that resolves to the new Entry or rejects with an error.
|
||||
*/
|
||||
async moveFileOrDir(sourcePath: string, sourceName: string, destPath: string, destName: string): Promise<Entry> {
|
||||
const destFixed = this.fixPathAndName(destPath, destName);
|
||||
|
||||
const source = await this.resolveLocalFilesystemUrl(this.textUtils.concatenatePaths(sourcePath, sourceName));
|
||||
|
||||
const destParentDir = await this.resolveDirectoryUrl(destFixed.path);
|
||||
|
||||
return this.moveMock(source, destParentDir, destFixed.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix a path and name, making sure the name doesn't contain any folder. If it does, the folder will be moved to the path.
|
||||
*
|
||||
* @param path Path to fix.
|
||||
* @param name Name to fix.
|
||||
* @return Fixed values.
|
||||
*/
|
||||
protected fixPathAndName(path: string, name: string): {path: string, name: string} {
|
||||
|
||||
const fullPath = this.textUtils.concatenatePaths(path, name);
|
||||
|
||||
return {
|
||||
path: fullPath.substring(0, fullPath.lastIndexOf('/')),
|
||||
name: fullPath.substr(fullPath.lastIndexOf('/') + 1),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -222,7 +222,7 @@ export class CoreH5PFileStorage {
|
|||
await Array.from(result.rows).map(async (entry: {foldername: string}) => {
|
||||
try {
|
||||
// Delete the index.html.
|
||||
await CoreFile.instance.removeFile(this.getContentIndexPath(entry.foldername, site.getId()));
|
||||
await this.deleteContentIndex(entry.foldername, site.getId());
|
||||
} catch (error) {
|
||||
// Ignore errors.
|
||||
}
|
||||
|
|
|
@ -16,8 +16,9 @@ import { CoreFile, CoreFileProvider } from '@providers/file';
|
|||
import { CoreSites } from '@providers/sites';
|
||||
import { CoreMimetypeUtils } from '@providers/utils/mimetype';
|
||||
import { CoreTextUtils } from '@providers/utils/text';
|
||||
import { CoreUtils } from '@providers/utils/utils';
|
||||
import { CoreH5P } from '../providers/h5p';
|
||||
import { CoreH5PCore } from './core';
|
||||
import { CoreH5PCore, CoreH5PDisplayOptions } from './core';
|
||||
import { FileEntry } from '@ionic-native/file';
|
||||
|
||||
/**
|
||||
|
@ -25,6 +26,25 @@ import { FileEntry } from '@ionic-native/file';
|
|||
*/
|
||||
export class CoreH5PHelper {
|
||||
|
||||
/**
|
||||
* Convert the number representation of display options into an object.
|
||||
*
|
||||
* @param displayOptions Number representing display options.
|
||||
* @return Object with display options.
|
||||
*/
|
||||
static decodeDisplayOptions(displayOptions: number): CoreH5PDisplayOptions {
|
||||
const config: any = {};
|
||||
const displayOptionsObject = CoreH5P.instance.h5pCore.getDisplayOptionsAsObject(displayOptions);
|
||||
|
||||
config.export = false; // Don't allow downloading in the app.
|
||||
config.embed = CoreUtils.instance.notNullOrUndefined(displayOptionsObject[CoreH5PCore.DISPLAY_OPTION_EMBED]) ?
|
||||
displayOptionsObject[CoreH5PCore.DISPLAY_OPTION_EMBED] : false;
|
||||
config.copyright = CoreUtils.instance.notNullOrUndefined(displayOptionsObject[CoreH5PCore.DISPLAY_OPTION_COPYRIGHT]) ?
|
||||
displayOptionsObject[CoreH5PCore.DISPLAY_OPTION_COPYRIGHT] : false;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the core H5P assets, including all core H5P JavaScript and CSS.
|
||||
*
|
||||
|
@ -107,19 +127,25 @@ export class CoreH5PHelper {
|
|||
* @param fileUrl The file URL used to download the file.
|
||||
* @param file The file entry of the downloaded file.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @param onProgress Function to call on progress.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
static async saveH5P(fileUrl: string, file: FileEntry, siteId?: string): Promise<void> {
|
||||
static async saveH5P(fileUrl: string, file: FileEntry, siteId?: string, onProgress?: (event: any) => any): Promise<void> {
|
||||
siteId = siteId || CoreSites.instance.getCurrentSiteId();
|
||||
|
||||
// Unzip the file.
|
||||
const folderName = CoreMimetypeUtils.instance.removeExtension(file.name);
|
||||
const destFolder = CoreTextUtils.instance.concatenatePaths(CoreFileProvider.TMPFOLDER, 'h5p/' + folderName);
|
||||
|
||||
// Notify that the unzip is starting.
|
||||
onProgress && onProgress({message: 'core.unzipping'});
|
||||
|
||||
// Unzip the file.
|
||||
await CoreFile.instance.unzipFile(file.toURL(), destFolder);
|
||||
await CoreFile.instance.unzipFile(file.toURL(), destFolder, onProgress);
|
||||
|
||||
try {
|
||||
// Notify that the unzip is starting.
|
||||
onProgress && onProgress({message: 'core.storingfiles'});
|
||||
|
||||
// Read the contents of the unzipped dir, process them and store them.
|
||||
const contents = await CoreFile.instance.getDirectoryContents(destFolder);
|
||||
|
||||
|
|
|
@ -30,6 +30,27 @@ export class CoreH5PPlayer {
|
|||
constructor(protected h5pCore: CoreH5PCore,
|
||||
protected h5pStorage: CoreH5PStorage) { }
|
||||
|
||||
/**
|
||||
* Calculate the URL to the site H5P player.
|
||||
*
|
||||
* @param siteUrl Site URL.
|
||||
* @param fileUrl File URL.
|
||||
* @param displayOptions Display options.
|
||||
* @param component Component to send xAPI events to.
|
||||
* @return URL.
|
||||
*/
|
||||
calculateOnlinePlayerUrl(siteUrl: string, fileUrl: string, displayOptions?: CoreH5PDisplayOptions, component?: string): string {
|
||||
fileUrl = CoreH5P.instance.treatH5PUrl(fileUrl, siteUrl);
|
||||
|
||||
const params = this.getUrlParamsFromDisplayOptions(displayOptions);
|
||||
params.url = encodeURIComponent(fileUrl);
|
||||
if (component) {
|
||||
params.component = component;
|
||||
}
|
||||
|
||||
return CoreUrlUtils.instance.addParamsToUrl(CoreTextUtils.instance.concatenatePaths(siteUrl, '/h5p/embed.php'), params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the index.html to render an H5P package.
|
||||
* Part of the code of this function is equivalent to Moodle's add_assets_to_page function.
|
||||
|
@ -219,11 +240,11 @@ export class CoreH5PPlayer {
|
|||
* Get the content index file.
|
||||
*
|
||||
* @param fileUrl URL of the H5P package.
|
||||
* @param urlParams URL params.
|
||||
* @param displayOptions Display options.
|
||||
* @param siteId The site ID. If not defined, current site.
|
||||
* @return Promise resolved with the file URL if exists, rejected otherwise.
|
||||
*/
|
||||
async getContentIndexFileUrl(fileUrl: string, urlParams?: {[name: string]: string}, siteId?: string): Promise<string> {
|
||||
async getContentIndexFileUrl(fileUrl: string, displayOptions?: CoreH5PDisplayOptions, siteId?: string): Promise<string> {
|
||||
siteId = siteId || CoreSites.instance.getCurrentSiteId();
|
||||
|
||||
const path = await this.h5pCore.h5pFS.getContentIndexFileUrl(fileUrl, siteId);
|
||||
|
@ -231,9 +252,9 @@ export class CoreH5PPlayer {
|
|||
// Add display options to the URL.
|
||||
const data = await this.h5pCore.h5pFramework.getContentDataByUrl(fileUrl, siteId);
|
||||
|
||||
const options = this.h5pCore.fixDisplayOptions(this.getDisplayOptionsFromUrlParams(urlParams), data.id);
|
||||
displayOptions = this.h5pCore.fixDisplayOptions(displayOptions, data.id);
|
||||
|
||||
return CoreUrlUtils.instance.addParamsToUrl(path, options, undefined, true);
|
||||
return CoreUrlUtils.instance.addParamsToUrl(path, displayOptions, undefined, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -323,4 +344,25 @@ export class CoreH5PPlayer {
|
|||
getResizerScriptUrl(): string {
|
||||
return CoreTextUtils.instance.concatenatePaths(this.h5pCore.h5pFS.getCoreH5PPath(), 'js/h5p-resizer.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get online player URL params from display options.
|
||||
*
|
||||
* @param options Display options.
|
||||
* @return Object with URL params.
|
||||
*/
|
||||
getUrlParamsFromDisplayOptions(options: CoreH5PDisplayOptions): {[name: string]: string} {
|
||||
const params: {[name: string]: string} = {};
|
||||
|
||||
if (!options) {
|
||||
return params;
|
||||
}
|
||||
|
||||
params[CoreH5PCore.DISPLAY_OPTION_FRAME] = options[CoreH5PCore.DISPLAY_OPTION_FRAME] ? '1' : '0';
|
||||
params[CoreH5PCore.DISPLAY_OPTION_DOWNLOAD] = options[CoreH5PCore.DISPLAY_OPTION_DOWNLOAD] ? '1' : '0';
|
||||
params[CoreH5PCore.DISPLAY_OPTION_EMBED] = options[CoreH5PCore.DISPLAY_OPTION_EMBED] ? '1' : '0';
|
||||
params[CoreH5PCore.DISPLAY_OPTION_COPYRIGHT] = options[CoreH5PCore.DISPLAY_OPTION_COPYRIGHT] ? '1' : '0';
|
||||
|
||||
return params;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,9 @@ export class CoreH5PStorage {
|
|||
// Library already installed.
|
||||
libraryData.libraryId = dbData.id;
|
||||
|
||||
if (!this.h5pFramework.isPatchedLibrary(libraryData, dbData)) {
|
||||
const isNewPatch = await this.h5pFramework.isPatchedLibrary(libraryData, dbData);
|
||||
|
||||
if (!isNewPatch) {
|
||||
// Same or older version, no need to save.
|
||||
libraryData.saveDependencies = false;
|
||||
|
||||
|
|
|
@ -17,12 +17,14 @@ import { CommonModule } from '@angular/common';
|
|||
import { IonicModule } from 'ionic-angular';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CoreDirectivesModule } from '@directives/directives.module';
|
||||
import { CoreH5PPlayerComponent } from './h5p-player/h5p-player';
|
||||
import { CoreComponentsModule } from '@components/components.module';
|
||||
import { CoreH5PPlayerComponent } from './h5p-player/h5p-player';
|
||||
import { CoreH5PIframeComponent } from './h5p-iframe/h5p-iframe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
CoreH5PPlayerComponent
|
||||
CoreH5PPlayerComponent,
|
||||
CoreH5PIframeComponent,
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
|
@ -34,10 +36,12 @@ import { CoreComponentsModule } from '@components/components.module';
|
|||
providers: [
|
||||
],
|
||||
exports: [
|
||||
CoreH5PPlayerComponent
|
||||
CoreH5PPlayerComponent,
|
||||
CoreH5PIframeComponent,
|
||||
],
|
||||
entryComponents: [
|
||||
CoreH5PPlayerComponent
|
||||
CoreH5PPlayerComponent,
|
||||
CoreH5PIframeComponent,
|
||||
]
|
||||
})
|
||||
export class CoreH5PComponentsModule {}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<core-loading [hideUntil]="iframeSrc" class="core-loading-center safe-area-page">
|
||||
<core-iframe *ngIf="iframeSrc" [src]="iframeSrc" iframeHeight="auto" [allowFullscreen]="true" (loaded)="iframeLoaded()"></core-iframe>
|
||||
<script *ngIf="resizeScript && iframeSrc" type="text/javascript" [src]="resizeScript"></script>
|
||||
</core-loading>
|
|
@ -0,0 +1,173 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Component, Input, Output, ElementRef, OnChanges, SimpleChange, EventEmitter } from '@angular/core';
|
||||
import { CoreFile } from '@providers/file';
|
||||
import { CoreFilepool } from '@providers/filepool';
|
||||
import { CoreLogger } from '@providers/logger';
|
||||
import { CoreSites } from '@providers/sites';
|
||||
import { CoreDomUtils } from '@providers/utils/dom';
|
||||
import { CoreUrlUtils } from '@providers/utils/url';
|
||||
import { CoreH5P } from '@core/h5p/providers/h5p';
|
||||
import { CorePluginFileDelegate } from '@providers/plugin-file-delegate';
|
||||
import { CoreFileHelper } from '@providers/file-helper';
|
||||
import { CoreConstants } from '@core/constants';
|
||||
import { CoreSite } from '@classes/site';
|
||||
import { CoreH5PCore, CoreH5PDisplayOptions } from '../../classes/core';
|
||||
import { CoreH5PHelper } from '../../classes/helper';
|
||||
|
||||
/**
|
||||
* Component to render an iframe with an H5P package.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'core-h5p-iframe',
|
||||
templateUrl: 'core-h5p-iframe.html',
|
||||
})
|
||||
export class CoreH5PIframeComponent implements OnChanges {
|
||||
@Input() fileUrl?: string; // The URL of the H5P file. If not supplied, onlinePlayerUrl is required.
|
||||
@Input() displayOptions?: CoreH5PDisplayOptions; // Display options.
|
||||
@Input() onlinePlayerUrl?: string; // The URL of the online player to display the H5P package.
|
||||
@Output() onIframeUrlSet = new EventEmitter<{src: string, online: boolean}>();
|
||||
@Output() onIframeLoaded = new EventEmitter<void>();
|
||||
|
||||
iframeSrc: string;
|
||||
|
||||
protected site: CoreSite;
|
||||
protected siteId: string;
|
||||
protected siteCanDownload: boolean;
|
||||
protected logger;
|
||||
|
||||
constructor(public elementRef: ElementRef,
|
||||
protected pluginFileDelegate: CorePluginFileDelegate) {
|
||||
|
||||
this.logger = CoreLogger.instance.getInstance('CoreH5PIframeComponent');
|
||||
this.site = CoreSites.instance.getCurrentSite();
|
||||
this.siteId = this.site.getId();
|
||||
this.siteCanDownload = this.site.canDownloadFiles() && !CoreH5P.instance.isOfflineDisabledInSite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect changes on input properties.
|
||||
*/
|
||||
ngOnChanges(changes: {[name: string]: SimpleChange}): void {
|
||||
// If it's already playing don't change it.
|
||||
if ((changes.fileUrl || changes.onlinePlayerUrl) && !this.iframeSrc) {
|
||||
this.play();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the H5P.
|
||||
*
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
protected async play(): Promise<void> {
|
||||
let localUrl: string;
|
||||
let state: string;
|
||||
|
||||
if (this.fileUrl) {
|
||||
state = await CoreFilepool.instance.getFileStateByUrl(this.siteId, this.fileUrl);
|
||||
} else {
|
||||
state = CoreConstants.NOT_DOWNLOADABLE;
|
||||
}
|
||||
|
||||
if (this.siteCanDownload && CoreFileHelper.instance.isStateDownloaded(state)) {
|
||||
// Package is downloaded, use the local URL.
|
||||
localUrl = await this.getLocalUrl();
|
||||
}
|
||||
|
||||
try {
|
||||
if (localUrl) {
|
||||
// Local package.
|
||||
this.iframeSrc = localUrl;
|
||||
} else {
|
||||
this.onlinePlayerUrl = this.onlinePlayerUrl || CoreH5P.instance.h5pPlayer.calculateOnlinePlayerUrl(
|
||||
this.site.getURL(), this.fileUrl, this.displayOptions);
|
||||
|
||||
// Never allow downloading in the app. This will only work if the user is allowed to change the params.
|
||||
const src = this.onlinePlayerUrl.replace(CoreH5PCore.DISPLAY_OPTION_DOWNLOAD + '=1',
|
||||
CoreH5PCore.DISPLAY_OPTION_DOWNLOAD + '=0');
|
||||
|
||||
// Get auto-login URL so the user is automatically authenticated.
|
||||
const url = await CoreSites.instance.getCurrentSite().getAutoLoginUrl(src, false);
|
||||
|
||||
// Add the preventredirect param so the user can authenticate.
|
||||
this.iframeSrc = CoreUrlUtils.instance.addParamsToUrl(url, {preventredirect: false});
|
||||
}
|
||||
} catch (error) {
|
||||
CoreDomUtils.instance.showErrorModalDefault(error, 'Error loading H5P package.', true);
|
||||
|
||||
} finally {
|
||||
this.addResizerScript();
|
||||
this.onIframeUrlSet.emit({src: this.iframeSrc, online: !!localUrl});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the local URL of the package.
|
||||
*
|
||||
* @return Promise resolved with the local URL.
|
||||
*/
|
||||
protected async getLocalUrl(): Promise<string> {
|
||||
try {
|
||||
const url = await CoreH5P.instance.h5pPlayer.getContentIndexFileUrl(this.fileUrl, this.displayOptions, this.siteId);
|
||||
|
||||
return url;
|
||||
} catch (error) {
|
||||
// Index file doesn't exist, probably deleted because a lib was updated. Try to create it again.
|
||||
try {
|
||||
const path = await CoreFilepool.instance.getInternalUrlByUrl(this.siteId, this.fileUrl);
|
||||
|
||||
const file = await CoreFile.instance.getFile(path);
|
||||
|
||||
await CoreH5PHelper.saveH5P(this.fileUrl, file, this.siteId);
|
||||
|
||||
// File treated. Try to get the index file URL again.
|
||||
const url = await CoreH5P.instance.h5pPlayer.getContentIndexFileUrl(this.fileUrl, this.displayOptions,
|
||||
this.siteId);
|
||||
|
||||
return url;
|
||||
} catch (error) {
|
||||
// Still failing. Delete the H5P package?
|
||||
this.logger.error('Error loading downloaded index:', error, this.fileUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the resizer script if it hasn't been added already.
|
||||
*/
|
||||
protected addResizerScript(): void {
|
||||
if (document.head.querySelector('#core-h5p-resizer-script') != null) {
|
||||
// Script already added, don't add it again.
|
||||
return;
|
||||
}
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.id = 'core-h5p-resizer-script';
|
||||
script.type = 'text/javascript';
|
||||
script.src = CoreH5P.instance.h5pPlayer.getResizerScriptUrl();
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* H5P iframe has been loaded.
|
||||
*/
|
||||
iframeLoaded(): void {
|
||||
this.onIframeLoaded.emit();
|
||||
|
||||
// Send a resize event to the window so H5P package recalculates the size.
|
||||
window.dispatchEvent(new Event('resize'));
|
||||
}
|
||||
}
|
|
@ -1,13 +1,11 @@
|
|||
<div *ngIf="!showPackage" class="core-h5p-placeholder">
|
||||
<button *ngIf="!loading" class="core-h5p-placeholder-play-button" ion-button icon-only clear (click)="play($event)">
|
||||
<button class="core-h5p-placeholder-play-button" ion-button icon-only clear (click)="play($event)">
|
||||
<core-icon name="fa-play-circle"></core-icon>
|
||||
</button>
|
||||
|
||||
<ion-spinner *ngIf="loading" class="core-h5p-placeholder-spinner"></ion-spinner>
|
||||
|
||||
<div class="core-h5p-placeholder-download-container">
|
||||
<core-download-refresh [status]="state" [enabled]="canDownload" [loading]="calculating" [canTrustDownload]="true" (action)="download()"></core-download-refresh>
|
||||
</div>
|
||||
</div>
|
||||
<core-iframe *ngIf="showPackage" [src]="playerSrc" iframeHeight="auto" [allowFullscreen]="true" (loaded)="iframeLoaded()"></core-iframe>
|
||||
<script *ngIf="resizeScript && showPackage" type="text/javascript" [src]="resizeScript"></script>
|
||||
|
||||
<core-h5p-iframe *ngIf="showPackage" [fileUrl]="urlParams.url" [displayOptions]="displayOptions" [onlinePlayerUrl]="src"></core-h5p-iframe>
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
import { Component, Input, ElementRef, OnInit, OnDestroy, OnChanges, SimpleChange } from '@angular/core';
|
||||
import { CoreApp } from '@providers/app';
|
||||
import { CoreEvents } from '@providers/events';
|
||||
import { CoreFile } from '@providers/file';
|
||||
import { CoreFilepool } from '@providers/filepool';
|
||||
import { CoreLogger } from '@providers/logger';
|
||||
import { CoreSites } from '@providers/sites';
|
||||
|
@ -23,11 +22,9 @@ import { CoreDomUtils } from '@providers/utils/dom';
|
|||
import { CoreUrlUtils } from '@providers/utils/url';
|
||||
import { CoreH5P } from '@core/h5p/providers/h5p';
|
||||
import { CorePluginFileDelegate } from '@providers/plugin-file-delegate';
|
||||
import { CoreFileHelper } from '@providers/file-helper';
|
||||
import { CoreConstants } from '@core/constants';
|
||||
import { CoreSite } from '@classes/site';
|
||||
import { CoreH5PCore } from '../../classes/core';
|
||||
import { CoreH5PHelper } from '../../classes/helper';
|
||||
import { CoreH5PDisplayOptions } from '../../classes/core';
|
||||
|
||||
/**
|
||||
* Component to render an H5P package.
|
||||
|
@ -41,18 +38,17 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
|
|||
@Input() component?: string; // Component.
|
||||
@Input() componentId?: string | number; // Component ID to use in conjunction with the component.
|
||||
|
||||
playerSrc: string;
|
||||
showPackage = false;
|
||||
loading = false;
|
||||
state: string;
|
||||
canDownload: boolean;
|
||||
calculating = true;
|
||||
displayOptions: CoreH5PDisplayOptions;
|
||||
urlParams: {[name: string]: string};
|
||||
|
||||
protected site: CoreSite;
|
||||
protected siteId: string;
|
||||
protected siteCanDownload: boolean;
|
||||
protected observer;
|
||||
protected urlParams;
|
||||
protected logger;
|
||||
|
||||
constructor(public elementRef: ElementRef,
|
||||
|
@ -90,52 +86,7 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
|
|||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
this.loading = true;
|
||||
|
||||
let localUrl: string;
|
||||
|
||||
if (this.canDownload && CoreFileHelper.instance.isStateDownloaded(this.state)) {
|
||||
// Package is downloaded, use the local URL.
|
||||
try {
|
||||
localUrl = await CoreH5P.instance.h5pPlayer.getContentIndexFileUrl(this.urlParams.url, this.urlParams, this.siteId);
|
||||
} catch (error) {
|
||||
// Index file doesn't exist, probably deleted because a lib was updated. Try to create it again.
|
||||
try {
|
||||
const path = await CoreFilepool.instance.getInternalUrlByUrl(this.siteId, this.urlParams.url);
|
||||
|
||||
const file = await CoreFile.instance.getFile(path);
|
||||
|
||||
await CoreH5PHelper.saveH5P(this.urlParams.url, file, this.siteId);
|
||||
|
||||
// File treated. Try to get the index file URL again.
|
||||
localUrl = await CoreH5P.instance.h5pPlayer.getContentIndexFileUrl(this.urlParams.url, this.urlParams,
|
||||
this.siteId);
|
||||
} catch (error) {
|
||||
// Still failing. Delete the H5P package?
|
||||
this.logger.error('Error loading downloaded index:', error, this.src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (localUrl) {
|
||||
// Local package.
|
||||
this.playerSrc = localUrl;
|
||||
} else {
|
||||
// Never allow downloading in the app. This will only work if the user is allowed to change the params.
|
||||
const src = this.src && this.src.replace(CoreH5PCore.DISPLAY_OPTION_DOWNLOAD + '=1',
|
||||
CoreH5PCore.DISPLAY_OPTION_DOWNLOAD + '=0');
|
||||
|
||||
// Get auto-login URL so the user is automatically authenticated.
|
||||
const url = await CoreSites.instance.getCurrentSite().getAutoLoginUrl(src, false);
|
||||
|
||||
// Add the preventredirect param so the user can authenticate.
|
||||
this.playerSrc = CoreUrlUtils.instance.addParamsToUrl(url, {preventredirect: false});
|
||||
}
|
||||
} finally {
|
||||
|
||||
this.addResizerScript();
|
||||
this.loading = false;
|
||||
this.displayOptions = CoreH5P.instance.h5pPlayer.getDisplayOptionsFromUrlParams(this.urlParams);
|
||||
this.showPackage = true;
|
||||
|
||||
if (this.canDownload && (this.state == CoreConstants.OUTDATED || this.state == CoreConstants.NOT_DOWNLOADED)) {
|
||||
|
@ -147,7 +98,6 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the package.
|
||||
|
@ -203,22 +153,6 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the resizer script if it hasn't been added already.
|
||||
*/
|
||||
protected addResizerScript(): void {
|
||||
if (document.head.querySelector('#core-h5p-resizer-script') != null) {
|
||||
// Script already added, don't add it again.
|
||||
return;
|
||||
}
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.id = 'core-h5p-resizer-script';
|
||||
script.type = 'text/javascript';
|
||||
script.src = CoreH5P.instance.h5pPlayer.getResizerScriptUrl();
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the package can be downloaded.
|
||||
*
|
||||
|
@ -272,14 +206,6 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* H5P iframe has been loaded.
|
||||
*/
|
||||
iframeLoaded(): void {
|
||||
// Send a resize event to the window so H5P package recalculates the size.
|
||||
window.dispatchEvent(new Event('resize'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Component destroyed.
|
||||
*/
|
||||
|
|
|
@ -428,7 +428,7 @@ export class CoreH5PProvider {
|
|||
* @param siteUrl Site URL.
|
||||
* @return Treated url.
|
||||
*/
|
||||
protected treatH5PUrl(url: string, siteUrl: string): string {
|
||||
treatH5PUrl(url: string, siteUrl: string): string {
|
||||
if (url.indexOf(CoreTextUtils.instance.concatenatePaths(siteUrl, '/webservice/pluginfile.php')) === 0) {
|
||||
url = url.replace('/webservice/pluginfile', '/pluginfile');
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import { CoreMimetypeUtils } from '@providers/utils/mimetype';
|
|||
import { CoreUrlUtils } from '@providers/utils/url';
|
||||
import { CoreUtils } from '@providers/utils/utils';
|
||||
import { CoreH5P } from './h5p';
|
||||
import { CoreSites } from '@providers/sites';
|
||||
import { CoreWSExternalFile } from '@providers/ws';
|
||||
import { FileEntry } from '@ionic-native/file';
|
||||
import { Translate } from '@singletons/core.singletons';
|
||||
|
@ -50,7 +51,14 @@ export class CoreH5PPluginFileHandler implements CorePluginFileHandler {
|
|||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved with the file to use. Rejected if cannot download.
|
||||
*/
|
||||
getDownloadableFile(file: CoreWSExternalFile, siteId?: string): Promise<CoreWSExternalFile> {
|
||||
async getDownloadableFile(file: CoreWSExternalFile, siteId?: string): Promise<CoreWSExternalFile> {
|
||||
const site = await CoreSites.instance.getSite(siteId);
|
||||
|
||||
if (site.containsUrl(file.fileurl) && file.fileurl.match(/pluginfile\.php\/[^\/]+\/core_h5p\/export\//i)) {
|
||||
// It's already a deployed file, use it.
|
||||
return file;
|
||||
}
|
||||
|
||||
return CoreH5P.instance.getTrustedH5PFile(file.fileurl, {}, false, siteId);
|
||||
}
|
||||
|
||||
|
@ -85,7 +93,7 @@ export class CoreH5PPluginFileHandler implements CorePluginFileHandler {
|
|||
*/
|
||||
async getFileSize(file: CoreWSExternalFile, siteId?: string): Promise<number> {
|
||||
try {
|
||||
const trustedFile = await CoreH5P.instance.getTrustedH5PFile(file.fileurl, {}, false, siteId);
|
||||
const trustedFile = await this.getDownloadableFile(file, siteId);
|
||||
|
||||
return trustedFile.filesize;
|
||||
} catch (error) {
|
||||
|
@ -145,9 +153,10 @@ export class CoreH5PPluginFileHandler implements CorePluginFileHandler {
|
|||
* @param fileUrl The file URL used to download the file.
|
||||
* @param file The file entry of the downloaded file.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @param onProgress Function to call on progress.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
treatDownloadedFile(fileUrl: string, file: FileEntry, siteId?: string): Promise<void> {
|
||||
return CoreH5PHelper.saveH5P(fileUrl, file, siteId);
|
||||
treatDownloadedFile(fileUrl: string, file: FileEntry, siteId?: string, onProgress?: (event: any) => any): Promise<void> {
|
||||
return CoreH5PHelper.saveH5P(fileUrl, file, siteId, onProgress);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,6 +252,7 @@
|
|||
"sort": "Sort",
|
||||
"sortby": "Sort by",
|
||||
"start": "Start",
|
||||
"storingfiles": "Storing files",
|
||||
"strftimedate": "%d %B %Y",
|
||||
"strftimedatefullshort": "%d/%m/%y",
|
||||
"strftimedateshort": "%d %B",
|
||||
|
|
|
@ -812,30 +812,6 @@ export class CoreFileProvider {
|
|||
}
|
||||
}).then(() => {
|
||||
|
||||
if (this.isHTMLAPI) {
|
||||
// In Cordova API we need to calculate the longest matching path to make it work.
|
||||
// The function this.file.moveFile('a/', 'b/c.ext', 'a/', 'b/d.ext') doesn't work.
|
||||
// The function this.file.moveFile('a/b/', 'c.ext', 'a/b/', 'd.ext') works.
|
||||
const dirsA = originalPath.split('/'),
|
||||
dirsB = newPath.split('/');
|
||||
let commonPath = this.basePath;
|
||||
|
||||
for (let i = 0; i < dirsA.length; i++) {
|
||||
let dir = dirsA[i];
|
||||
if (dirsB[i] === dir) {
|
||||
// Found a common folder, add it to common path and remove it from each specific path.
|
||||
dir = dir + '/';
|
||||
commonPath = this.textUtils.concatenatePaths(commonPath, dir);
|
||||
originalPath = originalPath.replace(dir, '');
|
||||
newPath = newPath.replace(dir, '');
|
||||
} else {
|
||||
// Folder doesn't match, stop searching.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return moveFn(commonPath, originalPath, commonPath, newPath);
|
||||
} else {
|
||||
return moveFn(this.basePath, originalPath, this.basePath, newPath).catch((error) => {
|
||||
// The move can fail if the path has encoded characters. Try again if that's the case.
|
||||
const decodedOriginal = decodeURI(originalPath),
|
||||
|
@ -847,7 +823,6 @@ export class CoreFileProvider {
|
|||
return Promise.reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -888,8 +863,6 @@ export class CoreFileProvider {
|
|||
* @return Promise resolved when the entry is copied.
|
||||
*/
|
||||
protected copyFileOrDir(from: string, to: string, isDir?: boolean, destDirExists?: boolean): Promise<any> {
|
||||
let fromFileAndDir,
|
||||
toFileAndDir;
|
||||
const copyFn = isDir ? this.file.copyDir.bind(this.file) : this.file.copyFile.bind(this.file);
|
||||
|
||||
return this.init().then(() => {
|
||||
|
@ -897,21 +870,13 @@ export class CoreFileProvider {
|
|||
from = this.removeStartingSlash(from.replace(this.basePath, ''));
|
||||
to = this.removeStartingSlash(to.replace(this.basePath, ''));
|
||||
|
||||
fromFileAndDir = this.getFileAndDirectoryFromPath(from);
|
||||
toFileAndDir = this.getFileAndDirectoryFromPath(to);
|
||||
const toFileAndDir = this.getFileAndDirectoryFromPath(to);
|
||||
|
||||
if (toFileAndDir.directory && !destDirExists) {
|
||||
// Create the target directory if it doesn't exist.
|
||||
return this.createDir(toFileAndDir.directory);
|
||||
}
|
||||
}).then(() => {
|
||||
if (this.isHTMLAPI) {
|
||||
// In HTML API, the file name cannot include a directory, otherwise it fails.
|
||||
const fromDir = this.textUtils.concatenatePaths(this.basePath, fromFileAndDir.directory),
|
||||
toDir = this.textUtils.concatenatePaths(this.basePath, toFileAndDir.directory);
|
||||
|
||||
return copyFn(fromDir, fromFileAndDir.name, toDir, toFileAndDir.name);
|
||||
} else {
|
||||
return copyFn(this.basePath, from, this.basePath, to).catch((error) => {
|
||||
// The copy can fail if the path has encoded characters. Try again if that's the case.
|
||||
const decodedFrom = decodeURI(from),
|
||||
|
@ -923,7 +888,6 @@ export class CoreFileProvider {
|
|||
return Promise.reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1058,7 +1058,7 @@ export class CoreFilepoolProvider {
|
|||
return this.wsProvider.downloadFile(fileUrl, filePath, addExtension, onProgress).then((entry) => {
|
||||
fileEntry = entry;
|
||||
|
||||
return this.pluginFileDelegate.treatDownloadedFile(fileUrl, fileEntry, siteId);
|
||||
return this.pluginFileDelegate.treatDownloadedFile(fileUrl, fileEntry, siteId, onProgress);
|
||||
}).then(() => {
|
||||
const data: CoreFilepoolFileEntry = poolFileObject || {};
|
||||
|
||||
|
|
|
@ -110,9 +110,10 @@ export interface CorePluginFileHandler extends CoreDelegateHandler {
|
|||
* @param fileUrl The file URL used to download the file.
|
||||
* @param file The file entry of the downloaded file.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @param onProgress Function to call on progress.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
treatDownloadedFile?(fileUrl: string, file: FileEntry, siteId?: string): Promise<any>;
|
||||
treatDownloadedFile?(fileUrl: string, file: FileEntry, siteId?: string, onProgress?: (event: any) => any): Promise<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -380,13 +381,14 @@ export class CorePluginFileDelegate extends CoreDelegate {
|
|||
* @param fileUrl The file URL used to download the file.
|
||||
* @param file The file entry of the downloaded file.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @param onProgress Function to call on progress.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
treatDownloadedFile(fileUrl: string, file: FileEntry, siteId?: string): Promise<any> {
|
||||
treatDownloadedFile(fileUrl: string, file: FileEntry, siteId?: string, onProgress?: (event: any) => any): Promise<any> {
|
||||
const handler = this.getHandlerForFile({fileurl: fileUrl});
|
||||
|
||||
if (handler && handler.treatDownloadedFile) {
|
||||
return handler.treatDownloadedFile(fileUrl, file, siteId);
|
||||
return handler.treatDownloadedFile(fileUrl, file, siteId, onProgress);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
|
|
|
@ -872,6 +872,16 @@ export class CoreUtilsProvider {
|
|||
return this.uniqueArray(array1.concat(array2), key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a value isn't null or undefined.
|
||||
*
|
||||
* @param value Value to check.
|
||||
* @return True if not null and not undefined.
|
||||
*/
|
||||
notNullOrUndefined(value: any): boolean {
|
||||
return typeof value != 'undefined' && value !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a file using platform specific method.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue