diff options
Diffstat (limited to 'module/web/static/js/views')
-rw-r--r-- | module/web/static/js/views/actionbarView.js | 28 | ||||
-rw-r--r-- | module/web/static/js/views/dashboardView.js | 6 | ||||
-rw-r--r-- | module/web/static/js/views/fileView.js | 10 | ||||
-rw-r--r-- | module/web/static/js/views/filterView.js | 93 | ||||
-rw-r--r-- | module/web/static/js/views/packageView.js | 5 | ||||
-rw-r--r-- | module/web/static/js/views/selectionView.js | 24 |
6 files changed, 115 insertions, 51 deletions
diff --git a/module/web/static/js/views/actionbarView.js b/module/web/static/js/views/actionbarView.js deleted file mode 100644 index bdfb9ef7b..000000000 --- a/module/web/static/js/views/actionbarView.js +++ /dev/null @@ -1,28 +0,0 @@ -define(['jquery', 'backbone', 'underscore', 'app'], - function($, Backbone, _, App) { - - // Renders the actionbar for the dashboard - return Backbone.View.extend({ - el: 'ul.actionbar', - - events: { - }, - - initialize: function() { - - this.$('.search-query').typeahead({ - minLength: 2, - source: this.getAutocompletion - }); - - }, - - render: function() { - }, - - getAutocompletion: function() { - return ["static", "autocompletion", "demo", "with", "some", "keywords", - "a very long proposal for autocompletion"]; - } - }); - });
\ No newline at end of file diff --git a/module/web/static/js/views/dashboardView.js b/module/web/static/js/views/dashboardView.js index 64f61eeaf..58ca8faf0 100644 --- a/module/web/static/js/views/dashboardView.js +++ b/module/web/static/js/views/dashboardView.js @@ -1,6 +1,6 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', - 'views/packageView', 'views/fileView', 'views/selectionView', 'views/actionbarView'], - function($, Backbone, _, App, TreeCollection, packageView, fileView, selectionView, actionbarView) { + 'views/packageView', 'views/fileView', 'views/selectionView', 'views/filterView'], + function($, Backbone, _, App, TreeCollection, packageView, fileView, selectionView, filterView) { // Renders whole dashboard return Backbone.View.extend({ @@ -24,7 +24,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', this.tree = new TreeCollection(); var view = new selectionView(this.tree); - view = new actionbarView(); + view = new filterView(); // When package is added we reload the data App.vent.on('package:added', function() { diff --git a/module/web/static/js/views/fileView.js b/module/web/static/js/views/fileView.js index 3a4183289..f4f228559 100644 --- a/module/web/static/js/views/fileView.js +++ b/module/web/static/js/views/fileView.js @@ -14,6 +14,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'views/abstract/itemView'], initialize: function() { this.listenTo(this.model, 'change', this.render); + this.listenTo(this.model, 'change:visible', this.visibility_changed); this.listenTo(this.model, 'remove', this.destroy); }, @@ -45,7 +46,10 @@ define(['jquery', 'backbone', 'underscore', 'app', 'views/abstract/itemView'], else this.$el.removeClass('ui-selected'); - this.$('.iconf-chevron-down').dropdown(); + if (this.model.get('visible')) + this.$el.show(); + else + this.$el.hide(); return this; }, @@ -57,6 +61,10 @@ define(['jquery', 'backbone', 'underscore', 'app', 'views/abstract/itemView'], this.model.set('selected', !checked, {silent: true}); this.$el.toggleClass('ui-selected'); App.vent.trigger('file:selection'); + }, + + visibility_changed: function() { + } }); diff --git a/module/web/static/js/views/filterView.js b/module/web/static/js/views/filterView.js new file mode 100644 index 000000000..eef5db92f --- /dev/null +++ b/module/web/static/js/views/filterView.js @@ -0,0 +1,93 @@ +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', + + events: { + 'click .filter-type': 'filter_type', + 'click .filter-state': 'switch_filter' + }, + + state: null, + stateMenu: null, + + initialize: function() { + this.$('.search-query').typeahead({ + minLength: 2, + source: this.getAutocompletion + }); + + this.stateMenu = this.$('.dropdown-toggle .state'); + this.state = Api.DownloadState.All; + }, + + render: function() { + return this; + }, + + getAutocompletion: function() { + return ["static", "autocompletion", "demo", "with", "some", "keywords", + "a very long proposal for autocompletion"]; + }, + + switch_filter: function(e) { + e.stopPropagation(); + var element = $(e.target); + var state = parseInt(element.data('state'), 10); + var menu = this.stateMenu.parent().parent(); + menu.removeClass('open'); + + if (state === Api.DownloadState.Finished) { + menu.removeClass().addClass('dropdown finished'); + } else if (state === Api.DownloadState.Unfinished) { + menu.removeClass().addClass('dropdown active'); + } else if (state === Api.DownloadState.Failed) { + menu.removeClass().addClass('dropdown failed'); + } else { + menu.removeClass().addClass('dropdown'); + } + + this.state = state; + this.stateMenu.text(element.text()); + this.apply_filter(); + }, + + // Applies the filtering to current open files + apply_filter: function() { + if (!App.dashboard.files) + return; + + var self = this; + App.dashboard.files.map(function(file) { + var visible = file.get('visible'); + if (visible !== self.is_visible(file)) + file.set('visible', !visible); + }); + + }, + + // 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; + + return true; + }, + + filter_type: function(e) { + + } + + }); + });
\ No newline at end of file diff --git a/module/web/static/js/views/packageView.js b/module/web/static/js/views/packageView.js index 095121d87..9eb1ecf5f 100644 --- a/module/web/static/js/views/packageView.js +++ b/module/web/static/js/views/packageView.js @@ -24,7 +24,7 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore'], this.listenTo(this.model, 'change', this.render); this.listenTo(this.model, 'remove', this.unrender); -// // Clear drop down menu + // Clear drop down menu var self = this; this.$el.on('mouseleave', function() { self.$('.dropdown-menu').parent().removeClass('open'); @@ -39,9 +39,6 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore'], this.$el.html(this.template(this.model.toJSON())); this.$el.initTooltips(); - // Init the dropdown-menu - this.$('.iconf-chevron-down').dropdown(); - return this; }, diff --git a/module/web/static/js/views/selectionView.js b/module/web/static/js/views/selectionView.js index 4c433e31c..eaed33d59 100644 --- a/module/web/static/js/views/selectionView.js +++ b/module/web/static/js/views/selectionView.js @@ -15,18 +15,15 @@ define(['jquery', 'backbone', 'underscore', 'app'], // available packages tree: null, - // selected files - files: null, // Element of the action bar actionBar: null, - // needed to know when slide down + // number of currently selected elements current: 0, initialize: function(tree) { this.tree = tree; - this.files = tree.get('files'); - App.vent.on('dashboard:show', _.bind(this.set_files, this)); + App.vent.on('dashboard:show', _.bind(this.render, this)); App.vent.on('package:selection', _.bind(this.render, this)); App.vent.on('file:selection', _.bind(this.render, this)); @@ -37,10 +34,13 @@ define(['jquery', 'backbone', 'underscore', 'app'], // this.tree.get('packages').on('delete', _.bind(this.render, this)); }, - get_files: function() { + get_files: function(all) { var files = []; - if (this.files) - files = this.files.where({selected: true}); + if (App.dashboard.files) + if (all) + files = App.dashboard.files.where({visible: true}); + else + files = App.dashboard.files.where({selected: true, visible: true}); return files; }, @@ -71,11 +71,6 @@ define(['jquery', 'backbone', 'underscore', 'app'], this.current = files + packs; }, - set_files: function(files) { - this.files = files; - this.render(); - }, - // Deselects all items, optional only files deselect: function(filesOnly) { this.get_files().map(function(file) { @@ -123,8 +118,7 @@ define(['jquery', 'backbone', 'underscore', 'app'], select_toggle: function() { var files = this.get_files(); if (files.length === 0) { - // TODO Select only visible files - this.files.map(function(file) { + this.get_files(true).map(function(file) { file.set('selected', true); }); |