Skip to content

Commit

Permalink
Update Video Viewer activity to retrieve libraries from the server in…
Browse files Browse the repository at this point in the history
…stead of a constant
  • Loading branch information
llaske committed Jun 24, 2018
1 parent 7aa5e0d commit b2b5115
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 45 deletions.
33 changes: 23 additions & 10 deletions activities/VideoViewer.activity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,29 @@ Two set of videos are linked natively with the activity: [Khan Academy](http://k

Video Viewer is a Sugar-Web activity, it could work both into Sugar Learning platform and in Sugarizer.

A standard set of libraries is set with the activity (see `constant.libraries` property in [constant.js](constant.js)). You could add your own library using the library dialog (click on the library icon on the toolbar). You should provide to the dialog the URL of a JSON file that include an object with all these properties:

{
name: "canope",
title: "Canopé",
image: "images/canope.png",
database: "http://sugarizer.org/content/canope.php",
videos: "https://videos.reseau-canope.fr/download.php?file=lesfondamentaux/%id%_sd",
images: "https://www.reseau-canope.fr/lesfondamentaux/uploads/tx_cndpfondamentaux/%image%.png"
}
A standard set of libraries is load by the activities on the URL [http://sugarizer.org/content/videos.json](http://sugarizer.org/content/videos.json). You could replace this URL by updating the variable `constant.librariesUrl` in the file [constant.js](constant.js). Note that this URL is called with a `lang` parameter set with the current language.
This file is an array of libraries:

[
{
"name": "khanacademy",
"title": "Khan Academy",
"image": "images/khanacademy.png",
"database": "http://sugarizer.org/content/khan.php?lang=%language%",
"videos": "http://s3.amazonaws.com/KA-youtube-converted/%id%.mp4/%id%",
"images": "http://s3.amazonaws.com/KA-youtube-converted/%id%.mp4/%id%.png"
},
{
"name": "canope",
"title": "Canopé",
"image": "images/canope.png",
"database": "http://sugarizer.org/content/canope.php",
"videos": "https://videos.reseau-canope.fr/download.php?file=lesfondamentaux/%id%_sd",
"images": "https://www.reseau-canope.fr/lesfondamentaux/uploads/tx_cndpfondamentaux/%image%.png"
}
]

You could dynamically add your own library using the library dialog (click on the library icon on the toolbar). You should provide to the dialog the URL of a JSON file that include an object with all these properties.

Here what means each field:

Expand Down
19 changes: 16 additions & 3 deletions activities/VideoViewer.activity/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,20 @@ enyo.kind({
this.index = 0;
this.computeSize();
this.favorite = false;
this.loadDatabase();
},

loadLibraries: function() {
var that = this;
Util.loadLibraries(
function() {
app.showLibraries();
},
function(sender) {
that.$.spinner.setShowing(false);
that.$.cloudwarning.setShowing(true);
console.log("Error loading library on '"+sender.url+"'");
}
);
},

loadDatabase: function() {
Expand Down Expand Up @@ -122,7 +135,7 @@ enyo.kind({
this.$.libraryDialog.reload();
this.$.libraryDialog.show();
},

hideLibraries: function() {
this.$.libraryDialog.hide();
},
Expand All @@ -131,7 +144,7 @@ enyo.kind({
if (Util.getLibrary() == null)
this.showLibraries();
},

setFilter: function(filter) {
Util.setFilter(filter);
},
Expand Down
21 changes: 1 addition & 20 deletions activities/VideoViewer.activity/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,5 @@
var constant = {};

constant.pageCount = 4;
constant.libraries = [
{
name: "khanacademy",
title: "Khan Academy",
image: "images/khanacademy.png",
database: "http://sugarizer.org/content/khan.php?lang=%language%",
videos: "http://s3.amazonaws.com/KA-youtube-converted/%id%.mp4/%id%",
images: "http://s3.amazonaws.com/KA-youtube-converted/%id%.mp4/%id%.png"
},
{
name: "canope",
title: "Canopé",
image: "images/canope.png",
database: "http://sugarizer.org/content/canope.php",
videos: "https://videos.reseau-canope.fr/download.php?file=lesfondamentaux/%id%_sd",
images: "https://www.reseau-canope.fr/lesfondamentaux/uploads/tx_cndpfondamentaux/%image%.png"
}
];
constant.librariesUrl = "http://sugarizer.org/content/videos.json";
constant.videoType = "mp4";


47 changes: 35 additions & 12 deletions activities/VideoViewer.activity/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Util = {};
var app;
Util.context = {
filter: {category: "", text: "", favorite: false},
libraries: constant.libraries,
libraries: null,
library: null,
favorites: {},
readtimes: {},
Expand All @@ -25,18 +25,26 @@ Util.saveContext = function() {
};
Util.loadContext = function(callback, loaded) {
if (!Util.onSugar()) {
var datastoreObject = app.activity.getDatastoreObject();
app.showLibraries();
datastoreObject.loadAsText(function (error, metadata, data) {
//console.log("LOAD CONTEXT <"+data+">");
var context = JSON.parse(data);
if (context) {
Util.context = context;
app.loadDatabase();
app.hideLibraries();
}
callback();
require(["sugar-web/env"], function (env) {
env.getEnvironment(function(err, environment) {
if (environment.objectId) {
var datastoreObject = app.activity.getDatastoreObject();
datastoreObject.loadAsText(function (error, metadata, data) {
//console.log("LOAD CONTEXT <"+data+">");
var context = JSON.parse(data);
if (context) {
Util.context = context;
app.loadDatabase();
}
callback();
});
} else {
app.loadLibraries();
}
});
});


} else {
Util.context = loaded;
app.loadDatabase();
Expand Down Expand Up @@ -92,6 +100,21 @@ Util.getReadTime = function(id) {

Util.database = [];
Util.categories = [];
Util.loadLibraries = function(response, error) {
Util.getLanguage(function(language) {
var ajax = new enyo.Ajax({
url: constant.librariesUrl+"?lang="+language,
method: "GET",
handleAs: "json"
});
ajax.response(function(sender, data) {
Util.context.libraries = data;
response();
});
ajax.error(error);
ajax.go();
});
}
Util.loadDatabase = function(response, error) {
if (Util.context.library == null)
return;
Expand Down

0 comments on commit b2b5115

Please sign in to comment.