From bfd3dfb3221c40641b5bee41a0a015f0935f54d1 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Tue, 13 Jan 2009 22:19:34 +0000 Subject: [PATCH] ebl Add limit/offset and pattern selection git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8367 91ce42f0-d328-0410-95d8-f526ca767f89 --- gui/bweb/cgi/bresto.pl | 18 +++- gui/bweb/html/bresto.js | 220 +++++++++++++++++++++++++--------------- gui/bweb/lib/Bweb.pm | 8 +- 3 files changed, 160 insertions(+), 86 deletions(-) diff --git a/gui/bweb/cgi/bresto.pl b/gui/bweb/cgi/bresto.pl index ea94c1e6b5..f736b8fb54 100755 --- a/gui/bweb/cgi/bresto.pl +++ b/gui/bweb/cgi/bresto.pl @@ -125,6 +125,12 @@ sub set_limits $self->{offset} = $offset || 0; } +sub set_pattern +{ + my ($self, $pattern) = @_; + $self->{pattern} = $pattern; +} + # fill brestore_xxx tables for speedup sub update_cache { @@ -347,6 +353,10 @@ sub ls_files my $inclause = $self->{curjobids}; my $inpath = $self->{cwdid}; + my $filter = ''; + if ($self->{pattern}) { + $filter = " AND Filename.Name $self->{sql}->{MATCH} $self->{pattern} "; + } my $query = "SELECT File.FilenameId, listfiles.id, listfiles.Name, File.LStat, File.JobId @@ -357,6 +367,7 @@ sub ls_files AND Filename.Name != '' AND File.PathId = $inpath AND File.JobId IN ($inclause) + $filter GROUP BY Filename.Name ORDER BY Filename.Name LIMIT $self->{limit} OFFSET $self->{offset} ) AS listfiles @@ -755,7 +766,7 @@ $bvfs->connect_db(); my $action = CGI::param('action') || ''; my $args = $bvfs->get_form('pathid', 'filenameid', 'fileid', 'qdate', - 'limit', 'offset', 'client'); + 'limit', 'offset', 'client', 'qpattern'); if ($action eq 'batch') { $bvfs->update_cache(); @@ -839,6 +850,11 @@ if ($pathid =~ /^(\d+)$/) { } $bvfs->ch_dir($pathid); +# permit to use a regex filter +if ($args->{qpattern}) { + $bvfs->set_pattern($args->{qpattern}); +} + if ($action eq 'restore') { # TODO: pouvoir choisir le replace et le jobname diff --git a/gui/bweb/html/bresto.js b/gui/bweb/html/bresto.js index 8bc245fe9d..dd409b12a9 100644 --- a/gui/bweb/html/bresto.js +++ b/gui/bweb/html/bresto.js @@ -56,8 +56,9 @@ Ext.brestore.media_store; // media store Ext.brestore.option_vosb = false; Ext.brestore.option_vafv = false; Ext.brestore.dlglaunch; +Ext.brestore.fpattern; Ext.brestore.use_filerelocation=false; -Ext.brestore.limit = 5000; +Ext.brestore.limit = 2000; Ext.brestore.offset = 0; function get_node_path(node) { @@ -76,16 +77,21 @@ function get_node_path(node) function init_params(baseParams) { - baseParams['client']= Ext.brestore.client; - - if (Ext.brestore.option_vosb) { - baseParams['jobid'] = Ext.brestore.jobid; - } else { - baseParams['date'] = Ext.brestore.jobdate; - } - baseParams['offset'] = Ext.brestore.offset; - baseParams['limit'] = Ext.brestore.limit; - return baseParams; + baseParams['client']= Ext.brestore.client; + + if (Ext.brestore.option_vosb) { + baseParams['jobid'] = Ext.brestore.jobid; + } else { + baseParams['date'] = Ext.brestore.jobdate; + } + baseParams['offset'] = Ext.brestore.offset; + baseParams['limit'] = Ext.brestore.limit; + if (Ext.brestore.fpattern) { + if (RegExp(Ext.brestore.fpattern)) { + baseParams['pattern'] = Ext.brestore.fpattern; + } + } + return baseParams; } function captureEvents(observable) { @@ -138,9 +144,9 @@ Ext.onReady(function(){ Ext.brestore.path = get_node_path(node); Ext.brestore.pathid = node.id; Ext.brestore.offset=0; + Ext.brestore.fpattern = Ext.get('txt-file-pattern').getValue(); where_field.setValue(Ext.brestore.path); - file_store.removeAll(); - file_versions_store.removeAll(); + update_limits(); file_store.load({params:init_params({action: 'list_files', path:Ext.brestore.path, node:node.id}) @@ -221,78 +227,113 @@ Ext.onReady(function(){ // by default columns are sortable cm.defaultSortable = true; + // reset limits function update_limits() { - Ext.get('txt-file-offset').setValue(Ext.brestore.offset); - Ext.get('txt-file-limit').setValue(Ext.brestore.limit); + Ext.get('txt-file-offset').dom.value = Ext.brestore.offset; + Ext.get('txt-file-limit').dom.value = Ext.brestore.offset + Ext.brestore.limit; } - var file_paging = new Ext.Toolbar({ - items: [ - { - id: 'bp-file-prev', - icon: '/bweb/ext/resources/images/default/grid/page-prev.gif', - cls: '.x-btn-icon', - tooltip: 'Last', - handler: function() { - if (Ext.brestore.offset > 0) { - Ext.brestore.offset -= Ext.brestore.limit; - if (Ext.brestore.offset < 0) { - Ext.brestore.offset=0; - } - file_store.removeAll(); - file_versions_store.removeAll(); - file_store.load({params:init_params({action: 'list_files', - path:Ext.brestore.path, - node:Ext.brestore.pathid}) - }); - update_limits(); - } - } - }, { - id: 'txt-file-offset', - xtype: 'numberfield', - width: 60, - value: Ext.brestore.offset - }, { - xtype: 'tbtext', - text: '-' - }, { - id: 'txt-file-limit', - xtype: 'numberfield', - width: 60, - value: Ext.brestore.limit - }, { - id: 'bp-file-next', - icon: '/bweb/ext/resources/images/default/grid/page-next.gif', - cls: '.x-btn-icon', - tooltip: 'Next', - handler: function(a,b,c) { - if (file_store.getCount() >= Ext.brestore.limit) { - Ext.brestore.offset += Ext.brestore.limit; - file_store.removeAll(); - file_versions_store.removeAll(); - file_store.load({params:init_params({action: 'list_files', - path:Ext.brestore.path, - node:Ext.brestore.pathid}) - }); - update_limits(); - } - } - }, '->', { - id: 'txt-file-pattern', - xtype: 'textfield', - text: 'pattern...' - }, { - id: 'bp-file-match', - icon: '/bweb/ext/resources/images/default/grid/refresh.gif', - cls: '.x-btn-icon', - tooltip: 'Refresh', - handler: function(a,b,c) { + // get limits from user input + function update_user_limits() { + var off = parseInt(Ext.get('txt-file-offset').getValue()); + var lim = parseInt(Ext.get('txt-file-limit').getValue()); + if (off >= 0 && lim >= 0 && off < lim) { + Ext.brestore.offset = off; + Ext.brestore.limit = lim - off; + } else { + update_limits(); + } + Ext.brestore.fpattern = Ext.get('txt-file-pattern').getValue(); + } + + var file_paging_next = new Ext.Toolbar.Button({ + id: 'bp-file-next', + icon: '/bweb/ext/resources/images/default/grid/page-next.gif', + cls: '.x-btn-icon', + tooltip: 'Next', + handler: function(a,b,c) { + update_user_limits(); + if (file_store.getCount() >= Ext.brestore.limit) { + Ext.brestore.offset += Ext.brestore.limit; + file_store.removeAll(); + file_versions_store.removeAll(); + file_store.load({params:init_params({action: 'list_files', + path:Ext.brestore.path, + node:Ext.brestore.pathid}) + }); + } + } + }); + var file_paging_prev = new Ext.Toolbar.Button({ + id: 'bp-file-prev', + icon: '/bweb/ext/resources/images/default/grid/page-prev.gif', + cls: '.x-btn-icon', + tooltip: 'Last', + handler: function() { + update_user_limits(); + if (Ext.brestore.offset > 0) { + Ext.brestore.offset -= Ext.brestore.limit; + if (Ext.brestore.offset < 0) { + Ext.brestore.offset=0; } + file_store.removeAll(); + file_versions_store.removeAll(); + file_store.load({params:init_params({action: 'list_files', + path:Ext.brestore.path, + node:Ext.brestore.pathid}) + }); } - ] + } + }); + var file_paging_pattern = new Ext.form.TextField({ + enableKeyEvents: true, + id: 'txt-file-pattern', + text: 'pattern...' + }); + file_paging_pattern.on('keyup', function(a, e) { + if (e.getKey() == e. ENTER) { + var re; + var pattern = file_paging_pattern.getValue(); + if (pattern) { + re = new RegExp(pattern, "i"); + } + if (re) { + file_store.filter('name', re); + } else { + file_store.clearFilter(false); + } + } + }); + var file_paging = new Ext.Toolbar({ + items: [file_paging_prev, { + id: 'txt-file-offset', + xtype: 'numberfield', + width: 60, + value: Ext.brestore.offset + }, { + xtype: 'tbtext', + text: '-' + }, { + id: 'txt-file-limit', + xtype: 'numberfield', + width: 60, + value: Ext.brestore.limit + }, file_paging_next, '->', file_paging_pattern, { + id: 'bp-file-match', + icon: '/bweb/ext/resources/images/default/grid/refresh.gif', + cls: '.x-btn-icon', + tooltip: 'Refresh', + handler: function(a,b,c) { + update_user_limits(); + file_store.removeAll(); + file_versions_store.removeAll(); + file_store.load({params:init_params({action: 'list_files', + path:Ext.brestore.path, + node:Ext.brestore.pathid}) + }); + } + }] }); - var file_grid = new Ext.grid.GridPanel({ id: 'div-files', store: file_store, @@ -308,14 +349,31 @@ Ext.onReady(function(){ cmargins: '5 0 0 0' }); Ext.brestore.file_grid=file_grid; -// captureEvents(file_grid); -// captureEvents(file_store); // when we reload the view, // we clear the file version box file_store.on('beforeload', function(e) { + file_store.removeAll(); file_versions_store.removeAll(); return true; }); + + // If we have more than limit elements, we can + // display the next button + file_store.on('load', function(e,o) { + update_limits(); + if (e.getCount() >= Ext.brestore.limit) { + file_paging_next.enable(); + } else { + file_paging_next.disable(); + } + + if (Ext.brestore.offset) { + file_paging_prev.enable(); + } else { + file_paging_prev.disable(); + } + + }); /* * file_store.on('loadexception', function(obj, options, response, e){ diff --git a/gui/bweb/lib/Bweb.pm b/gui/bweb/lib/Bweb.pm index 85605a78b4..64d83a2712 100644 --- a/gui/bweb/lib/Bweb.pm +++ b/gui/bweb/lib/Bweb.pm @@ -3088,15 +3088,15 @@ sub get_roles if (not $self->{info}->{enable_security}) { return 1; } - # admin is a special user that can do everything - if ($self->{loginname} eq 'admin') { - return 1; - } if (!$self->{loginname}) { $self->error("Can't get your login name"); $self->display_end(); exit 0; } + # admin is a special user that can do everything + if ($self->{loginname} eq 'admin') { + return 1; + } # already fill if (defined $self->{security}) { return 1; -- 2.39.5