summaryrefslogtreecommitdiffstats
path: root/module/web/static/js
diff options
context:
space:
mode:
Diffstat (limited to 'module/web/static/js')
-rw-r--r--module/web/static/js/app.js1
-rw-r--r--module/web/static/js/helpers/fileHelper.js51
-rw-r--r--module/web/static/js/helpers/formatSize.js4
-rw-r--r--module/web/static/js/models/File.js18
-rw-r--r--module/web/static/js/utils/initHB.js5
-rw-r--r--module/web/static/js/views/fileView.js19
-rw-r--r--module/web/static/js/views/filterView.js16
7 files changed, 88 insertions, 26 deletions
diff --git a/module/web/static/js/app.js b/module/web/static/js/app.js
index e3fad4ea1..b081022af 100644
--- a/module/web/static/js/app.js
+++ b/module/web/static/js/app.js
@@ -33,7 +33,6 @@ define([
options.url = 'api/restartFailed';
$.ajax(options);
}
-
});
diff --git a/module/web/static/js/helpers/fileHelper.js b/module/web/static/js/helpers/fileHelper.js
new file mode 100644
index 000000000..d7cf03f53
--- /dev/null
+++ b/module/web/static/js/helpers/fileHelper.js
@@ -0,0 +1,51 @@
+// Helpers to render the file view
+define('helpers/fileHelper', ['handlebars', 'utils/apitypes'],
+ function(Handlebars, Api) {
+
+ function fileClass(file, options) {
+ if (file.finished)
+ return 'finished';
+ else if (file.failed)
+ return "failed";
+ else if (file.offline)
+ return "offline";
+ else if (file.online)
+ return "online";
+ else if (file.waiting)
+ return "waiting";
+ else if (file.downloading)
+ return "downloading";
+
+ return "";
+ }
+
+ // TODO
+ function fileIcon(media, options) {
+ return 'iconf-music';
+ }
+
+ // TODO rest of the states
+ function fileStatus(file, options) {
+ var s;
+ var msg = file.download.statusmsg;
+
+ if (file.failed) {
+ s = "<i class='iconf-remove'></i>&nbsp;";
+ if (file.download.error)
+ s += file.download.error;
+ else s += msg;
+ } else if (file.finished)
+ s = "<i class='iconf-ok'></i>&nbsp;" + msg;
+ else if(file.downloading)
+ s= "<div class='progress'><div class='bar' style='width: 50%'></div></div>";
+ else
+ s = msg;
+
+ return new Handlebars.SafeString(s);
+ }
+
+ Handlebars.registerHelper('fileClass', fileClass);
+ Handlebars.registerHelper('fileIcon', fileIcon);
+ Handlebars.registerHelper('fileStatus', fileStatus);
+ return fileClass;
+ }); \ No newline at end of file
diff --git a/module/web/static/js/helpers/formatSize.js b/module/web/static/js/helpers/formatSize.js
index 1b1d96a73..a792392b7 100644
--- a/module/web/static/js/helpers/formatSize.js
+++ b/module/web/static/js/helpers/formatSize.js
@@ -1,8 +1,8 @@
// Format bytes in human readable format
define('helpers/formatSize', ['handlebars'], function(Handlebars) {
+ var sizes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"];
function formatSize(bytes, options) {
- var sizes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"];
- if (bytes == 0) return '0 B';
+ if (bytes === 0) return '0 B';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
// round to two digits
return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i];
diff --git a/module/web/static/js/models/File.js b/module/web/static/js/models/File.js
index e965df9df..42275a452 100644
--- a/module/web/static/js/models/File.js
+++ b/module/web/static/js/models/File.js
@@ -1,4 +1,8 @@
-define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) {
+define(['jquery', 'backbone', 'underscore', 'utils/apitypes'], function($, Backbone, _, Api) {
+
+ var Finished = [Api.DownloadStatus.Finished, Api.DownloadStatus.Skipped];
+ var Failed = [Api.DownloadStatus.Failed, Api.DownloadStatus.Aborted, Api.DownloadStatus.TempOffline, Api.DownloadStatus.Offline];
+ // Unfinished - Other
return Backbone.Model.extend({
@@ -45,6 +49,18 @@ define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) {
isDownload : function() {
return this.has('download');
+ },
+
+ isFinished: function() {
+ return _.indexOf(Finished, this.get('download').status) > -1;
+ },
+
+ isUnfinished: function() {
+ return _.indexOf(Finished, this.get('download').status) === -1 && _.indexOf(Failed, this.get('download').status) === -1;
+ },
+
+ isFailed: function() {
+ return _.indexOf(Failed, this.get('download').status) > -1;
}
});
diff --git a/module/web/static/js/utils/initHB.js b/module/web/static/js/utils/initHB.js
index 784032ca0..f3a0955b3 100644
--- a/module/web/static/js/utils/initHB.js
+++ b/module/web/static/js/utils/initHB.js
@@ -1,9 +1,10 @@
// Loads all helper and set own handlebars rules
-define(['underscore', 'handlebars', 'helpers/formatSize'],
+define(['underscore', 'handlebars',
+ 'helpers/formatSize', 'helpers/fileHelper'],
function(_, Handlebars) {
// Replace with own lexer rules compiled from handlebars.l
Handlebars.Parser.lexer.rules = [/^(?:[^\x00]*?(?=(<%)))/, /^(?:[^\x00]+)/, /^(?:[^\x00]{2,}?(?=(\{\{|$)))/, /^(?:\{\{>)/, /^(?:<%=)/, /^(?:<%\/)/, /^(?:\{\{\^)/, /^(?:<%\s*else\b)/, /^(?:\{<%%)/, /^(?:\{\{&)/, /^(?:<%![\s\S]*?%>)/, /^(?:<%)/, /^(?:=)/, /^(?:\.(?=[%} ]))/, /^(?:\.\.)/, /^(?:[\/.])/, /^(?:\s+)/, /^(?:%%>)/, /^(?:%>)/, /^(?:"(\\["]|[^"])*")/, /^(?:'(\\[']|[^'])*')/, /^(?:@[a-zA-Z]+)/, /^(?:true(?=[%}\s]))/, /^(?:false(?=[%}\s]))/, /^(?:[0-9]+(?=[%}\s]))/, /^(?:[a-zA-Z0-9_$-]+(?=[=%}\s\/.]))/, /^(?:\[[^\]]*\])/, /^(?:.)/, /^(?:$)/];
_.compile = Handlebars.compile;
- return Handlebars
+ return Handlebars;
}); \ No newline at end of file
diff --git a/module/web/static/js/views/fileView.js b/module/web/static/js/views/fileView.js
index a8cac9503..59a26d7c9 100644
--- a/module/web/static/js/views/fileView.js
+++ b/module/web/static/js/views/fileView.js
@@ -1,5 +1,5 @@
-define(['jquery', 'backbone', 'underscore', 'app', 'views/abstract/itemView'],
- function($, Backbone, _, App, ItemView) {
+define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'views/abstract/itemView'],
+ function($, Backbone, _, App, Api, ItemView) {
// Renders single file item
return ItemView.extend({
@@ -26,18 +26,17 @@ define(['jquery', 'backbone', 'underscore', 'app', 'views/abstract/itemView'],
var data = this.model.toJSON();
if (data.download) {
var status = data.download.status;
- // TODO: remove hardcoded states
- if (status === 1 || status === 11)
+ if (status === Api.DownloadStatus.Offline || status === Api.DownloadStatus.TempOffline)
data.offline = true;
- else if (status === 7)
- data.failed = true;
- else if (status === 2)
+ else if (status === Api.DownloadStatus.Online)
data.online = true;
- else if (status === 9)
+ else if (status === Api.DownloadStatus.Waiting)
data.waiting = true;
- else if (status === 10)
+ else if (status === Api.DownloadStatus.Downloading)
data.downloading = true;
- else if (status === 5 || status === 6)
+ else if (this.model.isFailed())
+ data.failed = true;
+ else if (this.model.isFinished())
data.finished = true;
}
diff --git a/module/web/static/js/views/filterView.js b/module/web/static/js/views/filterView.js
index 2c2aecf0b..a085fdad5 100644
--- a/module/web/static/js/views/filterView.js
+++ b/module/web/static/js/views/filterView.js
@@ -1,10 +1,6 @@
define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'],
function($, Backbone, _, App, Api) {
- var Finished = [Api.DownloadStatus.Finished, Api.DownloadStatus.Skipped];
- var Failed = [Api.DownloadStatus.Failed, Api.DownloadStatus.Aborted, Api.DownloadStatus.TempOffline, Api.DownloadStatus.Offline];
- // Unfinished - Other
-
// Renders the actionbar for the dashboard, handles everything related to filtering displayed files
return Backbone.View.extend({
el: 'ul.actionbar',
@@ -77,12 +73,12 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'],
// determine if a file should be visible
// TODO: non download files
is_visible: function(file) {
- if (this.state == Api.DownloadState.Finished)
- return _.indexOf(Finished, file.get('download').status) > -1;
- else if (this.state == Api.DownloadState.Unfinished)
- return _.indexOf(Finished, file.get('download').status) == -1 && _.indexOf(Failed, file.get('download').status) == -1;
- else if (this.state == Api.DownloadState.Failed)
- return _.indexOf(Failed, file.get('download').status) > -1;
+ if (this.state === Api.DownloadState.Finished)
+ return file.isFinished();
+ else if (this.state === Api.DownloadState.Unfinished)
+ return file.isUnfinished();
+ else if (this.state === Api.DownloadState.Failed)
+ return file.isFailed();
return true;
},