Skip to content

Commit

Permalink
* allow to set the save name via savename_pl
Browse files Browse the repository at this point in the history
* work_sheet name in xls export
* search button and some more space in search mask
* calendar button
  • Loading branch information
oetiker committed Jul 6, 2011
1 parent 7c25141 commit 8b1211f
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 45 deletions.
2 changes: 1 addition & 1 deletion software/backend/lib/EP.pm
Expand Up @@ -114,7 +114,7 @@ sub startup {
my $user = $self->session('epUser');
if ($user){
my $cache = EP::Cache->new(
cacheRoot => $gcfg->{GENERAL}{cache_dir},
cacheRoot => $gcfg->{cache_dir},
user => $user,
inventory => $inventory,
treeCols => $service->getTableColumnDef('tree')->{ids},
Expand Down
21 changes: 16 additions & 5 deletions software/backend/lib/EP/Cache.pm
Expand Up @@ -49,7 +49,7 @@ the user name supplied to the inventory plugins
=cut

has user => sub { die "cacheKey is a mandatory argument" };
has user => sub { die "user is a mandatory argument" };

=head3 cacheRoot
Expand Down Expand Up @@ -107,10 +107,19 @@ meta information on the cache content

has 'meta' => sub { {} };

=head3 dbh
the db handle used by the cache.
=cut

has 'dbh';

has encodeUtf8 => sub { find_encoding('utf8') };
has tree => sub { [] };
has json => sub {Mojo::JSON::Any->new};


=head2 B<new>(I<config>)
Create an EP::nodeCache object.
Expand All @@ -121,7 +130,7 @@ Create an EP::nodeCache object.
Directory to store the cache databases.
=item B<cacheKey>
=item B<user>
An identifier for this cache ... probably the name of the current user. If a cache under this name already exists it gets attached.
Expand All @@ -135,7 +144,7 @@ A hash pointer for a list of tree building configurations.

sub new {
my $self = shift->SUPER::new(@_);
my $path = $self->cacheRoot.'/'.$self->cacheKey.'.sqlite';
my $path = $self->cacheRoot.'/'.$self->user.'.sqlite';
my $dbh = DBI->connect_cached("dbi:SQLite:dbname=$path","","",{
RaiseError => 1,
PrintError => 1,
Expand Down Expand Up @@ -330,7 +339,7 @@ sub getNodes {

=head2 getNode($nodeId)
Return node matching the given nodeId
Return node matching the given nodeId. Including the __nodeId attribute.
=cut

Expand All @@ -340,7 +349,9 @@ sub getNode {
my $dbh = $self->dbh;
my @row = $dbh->selectrow_array("SELECT data FROM node WHERE docid = ?",{},$nodeId);
my $json = $self->json;
return $json->decode($row[0]);
my $ret = $json->decode($row[0]);
$ret->{__nodeId} = $nodeId;
return $ret;
}

=head2 getBranch($parent)
Expand Down
10 changes: 7 additions & 3 deletions software/backend/lib/EP/Visualizer/TorrusChart.pm
Expand Up @@ -12,6 +12,7 @@ EP::Visualizer::TorrusChart - provide access to appropriate torrus pages via a p
caption = $R{name}
mode = traffic
skiprec_pl = $R{port.display} eq 'data_unavailable'
savename_pl = $R{sap}
# in qos mode
mode = qos
Expand Down Expand Up @@ -174,7 +175,8 @@ sub matchRecord {
$src->query(
hash => $hash,
nodeid => $nodeid,
url => $url
url => $url,
recid => $rec->{__nodeId},
);
$src->base->path($self->root);
my $plain_src = $src->to_rel;
Expand Down Expand Up @@ -269,6 +271,7 @@ sub addProxyRoute {
my $start = $req->param('start');
my $end = $req->param('end');
my $format = $req->param('format');
my $recId = $req->param('recid');
my $pxReq = Mojo::URL->new($url);
my $view = $self->view;
my $newHash = $self->calcHash($url,$nodeid);
Expand Down Expand Up @@ -297,8 +300,9 @@ sub addProxyRoute {
my $type = $res->headers->content_type;
$rp->headers->content_type($type);
if (lc $type eq 'application/pdf'){
my $name = $nodeid;
$name =~ s/[^-_0-9a-z]+/_/ig;
my $cache = $ctrl->stash('epCache');
my $rec = $cache->getNode($recId);
my $name = $self->cfg->{savename_pl} ? $self->cfg->{savename_pl}($rec) : $nodeid;
$name .= '-'.strftime('%Y-%m-%d',localtime($start)).'_'.strftime('%Y-%m-%d',localtime($end));
$rp->headers->add('Content-Disposition',"attachement; filename=$name.pdf");
}
Expand Down
25 changes: 15 additions & 10 deletions software/backend/lib/EP/Visualizer/TorrusData.pm
Expand Up @@ -15,6 +15,7 @@ EP::Visualizer::TorrusData - pull numeric data associated with torrus data sourc
sub_nodes = inbytes, outbytes
multilabel_pl = $R{SAP}
skiprec_pl = $R{port.display} eq 'data_unavailable'
savename_pl = $R{sap}
col_names = Avg In, Avg Out, Total In, Total Out, Max In, Max Out, Coverage
col_units = Mb/s, Mb/s, Gb, Gb, Mb/s, Mb/s, %
Expand Down Expand Up @@ -155,6 +156,7 @@ sub matchMultiRecord {
}
$ret->{multiRecord} = 1
}
return $ret;
}

=head2 matchRecord(rec)
Expand Down Expand Up @@ -192,7 +194,8 @@ sub matchRecord {
$src->query(
hash => $hash,
nodeid => $rec->{'torrus.nodeid'},
url => $rec->{'torrus.tree-url'}
url => $rec->{'torrus.tree-url'},
recid => $rec->{__nodeId},
);
$src->base->path($self->root);
my $plain_src = $src->to_rel;
Expand Down Expand Up @@ -341,7 +344,7 @@ sub getMultiData {
my $cache = $self->controller->stash('epCache');
my @ret;
for my $recId (@recIds){
my $rec = $self->cache->getNode($recId);
my $rec = $cache->getNode($recId);
next unless $rec->{'torrus.nodeid'} and $rec->{'torrus.tree-url'};
my $data = $self->getData($rec->{'torrus.tree-url'},$rec->{'torrus.nodeid'},$end,$interval,1);
next if not $data->{status};
Expand Down Expand Up @@ -386,7 +389,8 @@ sub addProxyRoute {
my $ctrl = shift;
my $req = $ctrl->req;
my $hash = $req->param('hash');
my $nodeid = $req->param('nodeid');
my $nodeid = $req->param('nodeid');
my $recId = $req->param('recid');
my $url = $req->param('url');
my $end = $req->param('end');
my $interval = $req->param('interval');
Expand All @@ -403,8 +407,7 @@ sub addProxyRoute {
}
my $data;
if ($req->param('rec_list')){
my $cache = $self->stash('epCache');
$data = $self->getMultiData($cache,$end,$interval,[$req->param('recList')]);
$data = $self->getMultiData($end,$interval,[$req->param('recList')]);
}
else {
$data = $self->getData($url,$nodeid,$end,$interval,$count);
Expand All @@ -419,8 +422,9 @@ sub addProxyRoute {
}
my $rp = Mojo::Message::Response->new;
$rp->code(200);
my $name = $nodeid;
$name =~ s/[^-_0-9a-z]+/_/ig;
my $cache = $ctrl->stash('epCache');
my $rec = $cache->getNode($recId);
my $name = $self->cfg->{savename_pl} ? $self->cfg->{savename_pl}($rec) : $nodeid;
$name .= '-'.strftime('%Y-%m-%d',localtime($end));
my $fileData;
for ($format) {
Expand Down Expand Up @@ -531,12 +535,13 @@ sub _excelBuilder {
my $workbook = shift;
my @cnames;
for (my $c=0;$self->cfg->{col_names}[$c];$c++){
my $name = $self->cfg->{col_names}[$c];
my $cname = $self->cfg->{col_names}[$c];
my $unit = $self->cfg->{col_units}[$c] || '';
push @cnames, qq{"$name [$unit]"};
push @cnames, qq{"$cname [$unit]"};
}
my $worksheet = $workbook->add_worksheet();
my $worksheet = $workbook->add_worksheet($name);
$worksheet->set_column('A:I',18);

my $cnames_ref = \@cnames;
my $header_format = $workbook->add_format();
$header_format->set_bold();
Expand Down
2 changes: 1 addition & 1 deletion software/backend/lib/EP/Visualizer/base.pm
Expand Up @@ -77,7 +77,7 @@ Can the Visualizer deal with multiple records of the given type?
=cut

sub matchMultiRecords {
sub matchMultiRecord {
my $self= shift;
my $rec = shift;
return undef;
Expand Down
22 changes: 13 additions & 9 deletions software/frontend/source/class/ep/theme/Appearance.js
Expand Up @@ -25,18 +25,22 @@ qx.Theme.define("ep.theme.Appearance", {
'eptable/search-box' : 'textfield',

"datefield/button" : {
alias : "combobox/button",
include : "combobox/button",
alias : "button",
include : "button",

style : function(states) {
return {
icon : "ep/date-bw.png",
padding : [0, 0, 0, 3],
backgroundColor : undefined,
decorator : undefined,
width: 19
};
}
padding : [0, 3, 0, 3],
marginLeft: 2
}
/*
decorator : states.hovered ? "button-hover" : undefined,
// backgroundColor : undefined,
// decorator : undefined,
// width: 19
}; */
}
}
}
});
});
24 changes: 17 additions & 7 deletions software/frontend/source/class/ep/ui/SearchView.js
Expand Up @@ -16,7 +16,7 @@ qx.Class.define("ep.ui.SearchView", {
*/
construct : function(colDef) {
this.base(arguments);
this._setLayout(new qx.ui.layout.VBox());
this._setLayout(new qx.ui.layout.VBox(5));
this._createSearchBox();
this.__vPane = new qx.ui.splitpane.Pane("vertical");
this._add(this.__vPane, { flex : 1 });
Expand All @@ -40,14 +40,24 @@ qx.Class.define("ep.ui.SearchView", {
* @return {void}
*/
_createSearchBox : function() {
var control = new qx.ui.form.TextField().set({
var sbox = new qx.ui.container.Composite(new qx.ui.layout.HBox(3).set({
alignY: 'middle'
}));
var field = new qx.ui.form.TextField().set({
placeholder : this.tr('wor* AND ( this OR that )'),
enabled : false
});

this._add(control);
control.addListener("changeValue", this._setSearch, this);
this.__searchBox = control;
sbox.add(field,{flex: 1});
var sb = new qx.ui.form.Button(this.tr('Search'));
field.addListener('keyup',function(e){
if (e.getKeyIdentifier() == 'Enter'){
sb.execute()
}
},this);
sbox.add(sb);
this._add(sbox);
sb.addListener("execute", this._setSearch, this);
this.__searchBox = field;
},


Expand Down Expand Up @@ -84,7 +94,7 @@ qx.Class.define("ep.ui.SearchView", {
* @return {void}
*/
_setSearch : function(e) {
var value = e.getData();
var value = this.__searchBox.getValue();
this.__table.getSelectionModel().resetSelection();
ep.data.NodeTableModel.getInstance().setSearch(value);
}
Expand Down
6 changes: 4 additions & 2 deletions software/frontend/source/class/ep/ui/View.js
Expand Up @@ -20,9 +20,10 @@ qx.Class.define("ep.ui.View", {
tabView.hide();
this._add(new ep.ui.Logo());
this._add(tabView);
this:__tabe = table;
this.__table = table;
var sm = table.getSelectionModel();
sm.setSelectionMode(qx.ui.table.selection.Model.MULTIPLE_INTERVAL_SELECTION);
// sm.setSelectionMode(qx.ui.table.selection.Model.MULTIPLE_INTERVAL_SELECTION);
sm.setSelectionMode(qx.ui.table.selection.Model.SINGLE_SELECTION);
var tm = table.getTableModel();
var rpc = ep.data.Server.getInstance();
var multiMode = false;
Expand All @@ -33,6 +34,7 @@ qx.Class.define("ep.ui.View", {
selCount++;
if (!recId){
recId = tm.getValue(0, ind);
}
},this);
if (selCount == 0){
this.__hideTimer = qx.event.Timer.once(function() {
Expand Down
14 changes: 7 additions & 7 deletions software/frontend/source/class/ep/visualizer/Data.js
Expand Up @@ -196,17 +196,17 @@ qx.Class.define("ep.visualizer.Data", {
*/

_hookSelection: function(table){
var sm = table.getSelectionModel();
var tm = table.getTableModel();
var sm = table.getSelectionModel();
var tm = table.getTableModel();
sm.addListener('changeSelection', function(e) {
if (! this.__selTrack){
return;
return;
}
var recId = [];
var recId = [];
sm.iterateSelection(function(ind) {
recId.push(tm.getValue(0, ind));
}
this.__dataTable.setRecordIds(recId);
recId.push(tm.getValue(0, ind));
});
this.__dataTable.setRecordIds(recId);
},this);
},

Expand Down

0 comments on commit 8b1211f

Please sign in to comment.