From 3dda581aa47a0eb075259ba370e24f864429b258 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 21 Sep 2006 16:46:39 +0000 Subject: [PATCH] added link style option to slimtree added support for building the "from" clause on newly inserted fields added basic framework for displaying transform options some style updates git-svn-id: svn://svn.open-ils.org/ILS/trunk@6179 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/opac/common/js/slimtree.js | 16 +++-- Open-ILS/web/reports/oils_rpt.css | 14 +++- Open-ILS/web/reports/oils_rpt.js | 4 +- Open-ILS/web/reports/oils_rpt_builder.js | 100 +++++++++++++++++++++++----- Open-ILS/web/reports/oils_rpt_builder.xhtml | 13 ++++ Open-ILS/web/reports/oils_rpt_tree.js | 20 ++++-- Open-ILS/web/reports/oils_rpt_utils.js | 17 +++++ 7 files changed, 156 insertions(+), 28 deletions(-) diff --git a/Open-ILS/web/opac/common/js/slimtree.js b/Open-ILS/web/opac/common/js/slimtree.js index e1fff891e8..4a4e9d211b 100644 --- a/Open-ILS/web/opac/common/js/slimtree.js +++ b/Open-ILS/web/opac/common/js/slimtree.js @@ -2,12 +2,12 @@ var stpicopen = '../../../../images/slimtree/folder.gif'; var stpicclose = '../../../../images/slimtree/folderopen.gif'; */ -var stpicopen = '../../../../images/slimtree/folder2.gif'; -var stpicclose = '../../../../images/slimtree/folderopen2.gif'; -var stpicblank = '../../../../images/slimtree/page.gif'; -var stpicline = '../../../../images/slimtree/line.gif'; -var stpicjoin = '../../../../images/slimtree/join.gif'; -var stpicjoinb = '../../../../images/slimtree/joinbottom.gif'; +var stpicopen = '../opac/images/slimtree/folder2.gif'; +var stpicclose = '../opac/images/slimtree/folderopen2.gif'; +var stpicblank = '../opac/images/slimtree/page.gif'; +var stpicline = '../opac/images/slimtree/line.gif'; +var stpicjoin = '../opac/images/slimtree/join.gif'; +var stpicjoinb = '../opac/images/slimtree/joinbottom.gif'; var stimgopen = elem('img',{src:stpicopen,border:0}); @@ -35,7 +35,7 @@ SlimTree.prototype.addCachedChildren = function(pid) { this.cache[pid] = null; } -SlimTree.prototype.addNode = function( id, pid, name, action, title ) { +SlimTree.prototype.addNode = function( id, pid, name, action, title, cls ) { if( pid != -1 && !$(pid)) { if(!this.cache[pid]) this.cache[pid] = new Array(); @@ -53,6 +53,8 @@ SlimTree.prototype.addNode = function( id, pid, name, action, title ) { var actionref = elem('a',{href:action}, name); var contdiv = elem('div',{id:'stcont_' + id}); + if(cls) addCSSClass(actionref, cls); + actionref.setAttribute('href',action); if(title) actionref.setAttribute('title',title); else actionref.setAttribute('title',name); diff --git a/Open-ILS/web/reports/oils_rpt.css b/Open-ILS/web/reports/oils_rpt.css index e202ea980d..78a5cbcebe 100644 --- a/Open-ILS/web/reports/oils_rpt.css +++ b/Open-ILS/web/reports/oils_rpt.css @@ -1,4 +1,4 @@ -body { font-size: 9pt; } +body { font-size: 9pt; font-family: Helvetica, Arial, Tahoma, sans-serif; font-size: 9pt;} .hide_me { display: none; visibility: hidden; } .welcome_box { position:absolute; top: 5px; right: 5px; } @@ -118,4 +118,16 @@ button { border-top: 2px solid #E0E0E0; } +.oils_rpt_tform_window { + margin: 5px; + text-align: left; + padding: 5px; + padding-left: 20px; +} + +.oils_rpt_tree_link_ref { + color: #A52A2A; + font-family: courier; +} + diff --git a/Open-ILS/web/reports/oils_rpt.js b/Open-ILS/web/reports/oils_rpt.js index bdce9bf4a5..dd3f9dee75 100644 --- a/Open-ILS/web/reports/oils_rpt.js +++ b/Open-ILS/web/reports/oils_rpt.js @@ -22,7 +22,9 @@ function oilsReport() { this.def = { select : [], from : {}, - where : [] + where : [], + having : [], + order_by : [] }; this.params = {}; this.name = "" diff --git a/Open-ILS/web/reports/oils_rpt_builder.js b/Open-ILS/web/reports/oils_rpt_builder.js index 3ce92b4f80..3fc3f44882 100644 --- a/Open-ILS/web/reports/oils_rpt_builder.js +++ b/Open-ILS/web/reports/oils_rpt_builder.js @@ -1,3 +1,6 @@ +/** initializes reports, some basid display settings, + * grabs and builds the IDL tree + */ function oilsInitReportBuilder() { oilsInitReports(); oilsRpt = new oilsReport(); @@ -11,14 +14,27 @@ function oilsInitReportBuilder() { ); } +/* returns just the column name */ +function oilsRptPathCol(path) { + var parts = path.split(/-/); + return parts.pop(); +} +/* returns the IDL class of the selected column */ +function oilsRptPathClass(path) { + var parts = path.split(/-/); + parts.pop(); + return parts.pop(); +} -function oilsRptSplitPath(path) { +/* returns everything prior to the column name */ +function oilsRptPathRel(path) { var parts = path.split(/-/); - var column = parts.pop(); - return [ parts.join('-'), column ]; + parts.pop(); + return parts.join('-'); } +/* creates a label "path" based on the column path */ function oilsRptMakeLabel(path) { var parts = path.split(/-/); var str = ''; @@ -29,7 +45,8 @@ function oilsRptMakeLabel(path) { } else { var column = parts[i]; var data = oilsIDL[parts[i-1]]; - var f = grep(data.fields, function(j){return (j.name == column); })[0]; + var f = grep(data.fields, + function(j){return (j.name == column); })[0]; str += ":"+f.label; } } @@ -38,19 +55,60 @@ function oilsRptMakeLabel(path) { /* adds an item to the display window */ -function oilsAddRptDisplayItem(val, name) { - if( ! oilsAddSelectorItem(oilsRptDisplaySelector, val, name) ) +function oilsAddRptDisplayItem(path, name) { + if( ! oilsAddSelectorItem(oilsRptDisplaySelector, path, name) ) return; /* add the selected columns to the report output */ - var splitp = oilsRptSplitPath(val); - name = (name) ? name : splitp[1]; + name = (name) ? name : oilsRptPathCol(path); var param = oilsRptNextParam(); - oilsRpt.def.select.push( {relation:splitp[0], column:splitp[1], alias:param} ); + + /* add this item to the select blob */ + oilsRpt.def.select.push( { + relation:oilsRptPathRel(path), + column:oilsRptPathCol(path), + alias:param + }); + + mergeObjects( oilsRpt.def.from, oilsRptBuildFromClause(path)); oilsRpt.params[param] = name; oilsRptDebug(); } +/* takes a column path and builds a from-clause object for the path */ +function oilsRptBuildFromClause(path) { + var parts = path.split(/-/); + //var obj = {from : {}}; + var obj = {}; + var tobj = obj; + var newpath = ""; + for( var i = 0; i < parts.length; i += 2 ) { + var cls = parts[i]; + var col = parts[i+1]; + var node = oilsIDL[parts[i]]; + var field = oilsRptFindField(node, col); + newpath = (newpath) ? newpath + '-'+ cls : cls; + + tobj.table = node.table; + tobj.alias = newpath; + _debug('field type is ' + field.type); + if( i == (parts.length - 2) ) break; + + tobj.join = {}; + tobj = tobj.join; + tobj[col] = {}; + tobj = tobj[col]; + if( field.type == 'link' ) + tobj.key = field.key; + + newpath = newpath + '-'+ col; + } + + _debug("built 'from' clause: path="+path+"\n"+formatJSON(js2JSON(obj))); + return obj; +} + + /* removes a specific item from the display window */ function oilsDelDisplayItem(val) { oilsDelSelectorItem(oilsRptDisplaySelector, val); @@ -65,8 +123,8 @@ function oilsDelSelectedDisplayItems() { function(i) { for( var j = 0; j < list.length; j++ ) { var d = list[j]; - var arr = oilsRptSplitPath(d); - if( arr[0] == i.relation && arr[1] == i.column ) { + if( oilsRptPathRel(d) == i.relation + && oilsRptPathCol(d) == i.column ) { var param = (i.alias) ? i.alias.match(/::PARAM\d*/) : null; if( param ) delete oilsRpt.params[param]; return false; @@ -76,9 +134,17 @@ function oilsDelSelectedDisplayItems() { } ); if(!oilsRpt.def.select) oilsRpt.def.select = []; + + for( var j = 0; j < list.length; j++ ) + oilsRptPruneFromClause(list[j]); + oilsRptDebug(); } +/* for each item in the path list, remove the associated data +from the "from" clause */ +function oilsRptPruneFromClause(pathlist) { +} /* adds an item to the display window */ function oilsAddRptFilterItem(val) { @@ -108,6 +174,7 @@ function oilsAddSelectorItem(sel, val, name) { return true; } + /* removes a specific item from the display window */ function oilsDelSelectorItem(sel, val) { _debug("deleting selector item "+val); @@ -131,6 +198,8 @@ function oilsDelSelectedItems(sel) { return list; } + +/* hides the different field editor tabs */ function oilsRptHideEditorDivs() { hideMe($('oils_rpt_tform_div')); hideMe($('oils_rpt_filter_div')); @@ -143,10 +212,8 @@ function oilsRptHideEditorDivs() { filter, and aggregate filter picker window */ function oilsRptDrawDataWindow(path) { - - var parts = path.split(/-/); - var col = parts.pop(); - var cls = parts.pop(); + var col = oilsRptPathCol(path); + var cls = oilsRptPathClass(path); var field = grep(oilsIDL[cls].fields, function(f){return (f.name==col);})[0]; _debug("setting update data window for column "+col+' on class '+cls); @@ -184,6 +251,9 @@ function oilsRptDrawTransformWindow(path, col, cls, field) { $('oils_rpt_tform_label_input').focus(); $('oils_rpt_tform_label_input').select(); + + if( field.datatype == 'timestamp' ) + unHideMe($('oils_rpt_tform_date_div')); } diff --git a/Open-ILS/web/reports/oils_rpt_builder.xhtml b/Open-ILS/web/reports/oils_rpt_builder.xhtml index afd2af8e0e..729c5a62c7 100644 --- a/Open-ILS/web/reports/oils_rpt_builder.xhtml +++ b/Open-ILS/web/reports/oils_rpt_builder.xhtml @@ -40,6 +40,8 @@ + + @@ -48,6 +50,11 @@ You are logged in as +
+ Reports Home +
+ +
Loading...
@@ -92,6 +99,11 @@
+
+
Select how this field should be displayed:
+ + +


@@ -109,6 +121,7 @@ + diff --git a/Open-ILS/web/reports/oils_rpt_tree.js b/Open-ILS/web/reports/oils_rpt_tree.js index b913ceeb8e..27e5a5651f 100644 --- a/Open-ILS/web/reports/oils_rpt_tree.js +++ b/Open-ILS/web/reports/oils_rpt_tree.js @@ -17,6 +17,14 @@ function oilsLoadRptTree(callback) { r.send(null); } +function oilsRptFindField(node, field) { + return grep( node.fields, + function(f) { + return (f.name == field); + } + )[0]; +} + /* turns the IDL into a js object */ function oilsParseRptTree(IDL, callback) { @@ -66,6 +74,7 @@ function oilsRptParseFields( node ) { field : fields[i], name : name, label : field.getAttributeNS(oilsIDLReportsNS,'label'), + datatype : field.getAttributeNS(oilsIDLReportsNS,'datatype'), type : 'field' } @@ -79,23 +88,25 @@ function oilsRptParseFields( node ) { if( link ) { obj.type = 'link'; - obj.reltype = link.getAttribute('reltype'); obj.key = link.getAttribute('key'); obj['class'] = link.getAttribute('class'); + obj.reltype = link.getAttribute('reltype'); + if( obj.reltype == 'might_have' ) continue; } else { if( fields[i].getAttributeNS(oilsIDLPersistNS, 'virtual') == 'true' ) continue; } obj.label = (obj.label) ? obj.label : obj.name; + obj.datatype = (obj.datatype) ? obj.datatype : 'string'; data.push(obj); } /* sort by field name */ data = data.sort( function(a,b) { - if( a.name > b.name ) return 1; - if( a.name < b.name ) return -1; + if( a.label > b.label ) return 1; + if( a.label < b.name ) return -1; return 0; } ); @@ -141,7 +152,8 @@ function oilsRenderSubTree( data, subTreeId, rootName, path ) { action = 'javascript:oilsAddLinkTree("' + dataId+'","'+field['class']+'","'+fullpath+'");'; - oilsRptTree.addNode( dataId, subTreeId, field.label, action ); + oilsRptTree.addNode( dataId, subTreeId, field.label, action, field.label, + (field.type == 'link') ? 'oils_rpt_tree_link_ref' : null ); } } diff --git a/Open-ILS/web/reports/oils_rpt_utils.js b/Open-ILS/web/reports/oils_rpt_utils.js index d5bcb31b90..8fc2d7b00c 100644 --- a/Open-ILS/web/reports/oils_rpt_utils.js +++ b/Open-ILS/web/reports/oils_rpt_utils.js @@ -91,4 +91,21 @@ function buildFloatingDiv(div, width) { } +function mergeObjects( src, obj ) { + for( var i in obj ) { + _debug("merging object element: "+i + ' : ' + src[i]); + if( i =='from' ) { + _debug('------------------------------'); + _debug(formatJSON(js2JSON(src[i]))); + _debug(formatJSON(js2JSON(obj[i]))); + _debug('------------------------------'); + } + if( typeof obj[i] == 'string' ) { + src[i] = obj[i]; + } else { + if(src[i]) mergeObjects(src[i], obj[i]); + else src[i] = obj[i]; + } + } +} -- 2.11.0