Skip to content

Commit

Permalink
paging almost working
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoontz committed Nov 14, 2009
1 parent 39bb959 commit ed7b005
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 17 deletions.
52 changes: 38 additions & 14 deletions app/controllers/sql_view_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ def delete

def index

@from = lambda{|from|
lambda{|where|
lambda{|select|
"SELECT " + select +
" FROM " + from +
" WHERE " + where
}
}
}

# <build the kernel from the user's desired params.>
# (we assume that the "table" param is defined to real table by the
# time this function (the sql_view.index controller) is called.)
Expand All @@ -55,6 +45,16 @@ def index
if (!self.params["join1"])
self.params["join1"] = ""
end

@from = lambda{|from|
lambda{|where|
lambda{|select|
"SELECT " + select +
" FROM " + from +
" WHERE " + where
}
}
}

if (self.params["join1"] != '')
kernel = @from.
Expand All @@ -73,7 +73,25 @@ def index
# </build the kernel from the user's desired params.>

# compose the actual SQL that will be sent to the database:
@sql = kernel.call("true").call("*")
@offset = "50"

if (self.params["offset"])
@offset = self.params["offset"]
# @offset = "50"
end


if (self.params["page"] == "forward")
@offset = (@offset.to_i + 10).to_s
end

@limit = "10"
if (self.params["limit"])
@limit = self.params["limit"]
end


@sql = kernel.call("true").call("*") + " OFFSET " + @offset + " LIMIT " + @limit

# DO THE ACTUAL QUERY.
@results = ActiveRecord::Base.connection.execute(@sql)
Expand Down Expand Up @@ -102,12 +120,16 @@ def index

mytime = Time.now
# fixme: add page load time (Time.now minus request_start_time)
xml.view ("time" => mytime) {
xml.view (:time => mytime) {


# <xml output part 1: actual payload: client query results>
if @sql
xml.rows(:sql => @sql,:count => @count) {
xml.rows(:sql => @sql,
:count => @count,
:offset => @offset,
:limit => @limit
) {
@results.each do |r|
xml.row(r)
end
Expand All @@ -129,7 +151,9 @@ def index
xml.joindir(:name => "INNER")
}

xml.tables(:sql => tables_sql,:count => tables_count) {
xml.tables(:sql => tables_sql,
:count => tables_count
) {
@results_db.each do |r|
xml.table(r)
end
Expand Down
14 changes: 13 additions & 1 deletion public/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,16 @@ function update_xml_url() {
document.getElementById("as_xml_url").href=document.location + "&output=xml";
document.getElementById("as_xml_iframe").src=document.location + "&output=xml";
}
}
}

function page_forward() {
document.getElementById("page") = "forward";
}

function onload_app() {
document.getElementById("page_forward").addEventListener('click',page_forward,true);

update_xml_url();

}

2 changes: 1 addition & 1 deletion public/stylesheets/lambda_sql.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</script>

</head>
<body onload="{$onload}; update_xml_url();">
<body onload="{$onload}; onload_app();">
<div class="header">
<xsl:apply-templates select="." mode="header"/>
<div style="padding:0;margin;0;border:0;float:right">
Expand Down
35 changes: 35 additions & 0 deletions public/stylesheets/sql_view.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,39 @@
.row th {
text-align:right;
border-right:1px solid black;
}


div.pager {
margin-left:10%;
width:80%;
border:0;
padding:0;
}

div.pager button {
width:100%;
}

div.pager table {
width:100%;
border:0;
text-align:center;
margin:0.25em;
border:0;
font-size:10pt;
}

div.pager th {
padding:0.25em;
}

th.left {
text-align:left;
width:10%;
}

th.right {
text-align:right;
width:10%;
}
9 changes: 8 additions & 1 deletion public/stylesheets/sql_view.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@
<xsl:value-of select="rows/@sql"/>
</div>

<xsl:apply-templates select="rows" mode="table"/>
<xsl:apply-templates select="rows" mode="table">
<xsl:with-param name="inputs">
<xsl:apply-templates select="rows/@*" mode="table_inputs"/>
<xsl:apply-templates select="metadata/params/@*" mode="table_inputs"/>
</xsl:with-param>
</xsl:apply-templates>


</div>
</xsl:template>

Expand Down

0 comments on commit ed7b005

Please sign in to comment.