added "Find Users," including back-end functionality and some bugfixes

This commit is contained in:
Eric J. Bowersox
2003-05-31 02:27:09 +00:00
parent 4f62066e6b
commit 3fa600206e
25 changed files with 1053 additions and 11 deletions

View File

@@ -19,5 +19,7 @@ importPackage(Packages.com.silverwrist.dynamo.util);
req = bsf.lookupBean("request"); // get request
rhelp = bsf.lookupBean("request_help"); // get request helper
// TEMPORARY - redirect to the one find page we have implemented, Categories
dynamo.scriptOutput(new Redirect("SERVLET","find_categories.js.vs"));
// Retrieve the last Find page we visited from the session, and redirect to that page.
session = rhelp.getSession();
page = session.getObject("/find.js.vs","last.visited");
dynamo.scriptOutput(new Redirect("SERVLET",page));

View File

@@ -25,7 +25,11 @@ importPackage(Packages.com.silverwrist.venice.content);
req = bsf.lookupBean("request"); // get request
rhelp = bsf.lookupBean("request_help"); // get request helper
user = vlib.getUser(req); // get user
session = rhelp.getSession(); // get the session
user = vlib.getUser(session); // get user
// Tell the session we visited this page last.
session.setObject("/find.js.vs","last.visited","find_categories.js.vs");
// Get the user's configured page size.
pagesize = cast.toInteger(user.getObject(VeniceNamespaces.USER_SETTINGS_NAMESPACE,"search.result.count"));
@@ -88,7 +92,8 @@ if (rc==null)
// Load the profile menu.
mprov = vcast.queryMenuProvider(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"venice-menus"));
menu = mprov.getInlineMenu(user,VeniceNamespaces.CONTENT_LAF_NAMESPACE,"find.menu",cast.newIntArray(0));
menu.setSelectedIndex(0);
ndx = menu.getItemContainingLinkText("find_categories.js.vs");
menu.setSelectedIndex(ndx);
rc.setParameter("menu",menu);
} // end if

View File

@@ -0,0 +1,105 @@
// The contents of this file are subject to the Mozilla Public License Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
// WARRANTY OF ANY KIND, either express or implied. See the License for the specific
// language governing rights and limitations under the License.
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
importPackage(java.lang);
importClass(Packages.com.silverwrist.dynamo.Namespaces);
importPackage(Packages.com.silverwrist.dynamo.iface);
importPackage(Packages.com.silverwrist.dynamo.util);
importClass(Packages.com.silverwrist.venice.SearchMode);
importClass(Packages.com.silverwrist.venice.UserSearchField);
importClass(Packages.com.silverwrist.venice.VeniceNamespaces);
importClass(Packages.com.silverwrist.venice.app.AdvancedUserService);
importPackage(Packages.com.silverwrist.venice.content);
req = bsf.lookupBean("request"); // get request
rhelp = bsf.lookupBean("request_help"); // get request helper
session = rhelp.getSession(); // get the session
user = vlib.getUser(session); // get user
// Tell the session we visited this page last.
session.setObject("/find.js.vs","last.visited","find_users.js.vs");
// Get the user's configured page size.
pagesize = cast.toInteger(user.getObject(VeniceNamespaces.USER_SETTINGS_NAMESPACE,"search.result.count"));
field = UserSearchField.USERNAME;
mode = SearchMode.PREFIX;
term = "";
ofs = 0;
fcount = -1;
results = null;
rc = null;
if (rhelp.isVerb("POST"))
{ // Read the form parameters
field = UserSearchField.getEnum(rhelp.getParameter("field"));
mode = SearchMode.getEnum(rhelp.getParameter("mode"));
term = rhelp.getParameter("term");
ofs = rhelp.getParameterInt("ofs",0);
fcount = rhelp.getParameterInt("fcount",-1);
// Adjust offset based on the button that was clicked.
if (rhelp.isImageButtonClicked("search"))
{ // beginning of a new search
ofs = 0;
fcount = -1;
} // end if
else if (rhelp.isImageButtonClicked("previous"))
ofs = Math.max(ofs - pagesize,0);
else if (rhelp.isImageButtonClicked("next"))
ofs += pagesize;
// Get the advanced user service object.
usersvc = vcast.queryAdvancedUserService(rhelp.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"adv-users"));
try
{ // search for users!
if (fcount<0)
fcount = usersvc.getSearchUserCount(user,field,mode,term);
results = usersvc.searchForUsers(user,field,mode,term,ofs,pagesize);
} // end try
catch (e)
{ // exception thrown
rc = new ErrorBox("Database Error",e,"SERVLET","find_users.js.vs");
} // end catch
} // end else
if (rc==null)
{ // create the VelocityView for the output
rc = new VelocityView("Find Users","find_users.vm");
rc.setParameter("field",field.getName());
rc.setParameter("mode",mode.getName());
rc.setParameter("term",term.toString());
rc.setParameter("ofs",cast.toIntegerObject(ofs));
rc.setParameter("fcount",cast.toIntegerObject(fcount));
rc.setParameter("pagesize",cast.toIntegerObject(pagesize));
if (results!=null)
rc.setParameter("results",results);
// Load the profile menu.
mprov = vcast.queryMenuProvider(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"venice-menus"));
menu = mprov.getInlineMenu(user,VeniceNamespaces.CONTENT_LAF_NAMESPACE,"find.menu",cast.newIntArray(0));
ndx = menu.getItemContainingLinkText("find_users.js.vs");
menu.setSelectedIndex(ndx);
rc.setParameter("menu",menu);
} // end if
dynamo.scriptOutput(rc);

View File

@@ -46,8 +46,7 @@ view.setPageQID("user/" + user.getName());
priv = cast.toOptionSet(user.getObject(VeniceNamespaces.USER_PROFILE_NAMESPACE,"privacy"));
// get the user photo renderer
uphoto = vcast.queryRenderImage(req_help.getRequestObject(VeniceNamespaces.DYNAMO_OBJECT_NAMESPACE,
"venice-userphoto"));
uphoto = vcast.queryRenderImage(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"venice-userphoto"));
// set the view parameters
view.setParameter("uid",cast.toIntegerObject(user.getUID()));
@@ -66,7 +65,8 @@ if (photo_url==null)
view.setParameter("photo",uphoto.getRenderingObject(photo_url));
view.setParameter("date_create",user.creationDate);
view.setParameter("date_lastlogin",user.lastAccessDate);
view.setParameter("date_lastupdate",user.getObject(VeniceNamespaces.USER_PROFILE_NAMESPACE,"last.update"));
view.setParameter("date_lastupdate",PropertyUtils.getPropertyNoErr(user,VeniceNamespaces.USER_PROFILE_NAMESPACE,
"last.update"));
buf = new StringBuffer();
s = PropertyUtils.getPropertyNoErr(user,VeniceNamespaces.USER_PROFILE_NAMESPACE,"name.prefix");

View File

@@ -10,7 +10,7 @@
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
// Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
@@ -62,6 +62,10 @@ if (rhelp.isRequestType("_SESSION") && rhelp.isVerb("PUT"))
// Now set up the established user (either the one that just logged in or Anonymous_Honyak).
dynamo.exec("/util/setup_user.js");
// Configure other session attributes.
session = rhelp.getSession();
session.setObject("/find.js.vs","last.visited","find_categories.js.vs");
} // end if (session is HTTP)
} // end if (session-PUT event)

View File

@@ -25,6 +25,8 @@
#macro( encodeURL $data )$std.encodeURL($data)#end
#macro( getProperty $obj $namespace $name )$std.getProperty($data,$namespace,$name)#end
#macro( render $obj )$std.renderObject($obj)#end
#macro( renderDialog $dlg )$std.renderDialog($dlg)#end

View File

@@ -17,7 +17,7 @@
*#
#*
Parameters:
mode = Search mode
mode = Search mode (string equivalent)
term = Search term
ofs = Offset within the search we're at right now
fcount = Total number of items found in current search

View File

@@ -0,0 +1,142 @@
#*
The contents of this file are subject to the Mozilla Public License Version 1.1
(the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
language governing rights and limitations under the License.
The Original Code is the Venice Web Communities System.
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
Contributor(s):
*#
#*
Parameters:
field = Search field (string equivalent)
mode = Search mode (string equivalent)
term = Search term
ofs = Offset within the search we're at right now
fcount = Total number of items found in current search
pagesize = Number of items to display per page
results = Results list from find, a List of DynamoUser objects (may be null)
menu = Tab menu to render across the top
*#
#render( $menu )
#header1( "Find Users" )
<form method="POST" action="#formatURL( "SERVLET" "find_users.js.vs")">
<input type="hidden" name="ofs" value="0">
#comment( "Find Users form" )
<div align="left"><p>
Display all users whose&nbsp;
<select name="field" size="1">
<option value="USERNAME" #if( $field.equals("USERNAME") )selected="selected"#end >username</option>
<option value="DESCRIPTION" #if( $field.equals("DESCRIPTION") )selected="selected"#end >description</option>
<option value="FIRSTNAME" #if( $field.equals("FIRSTNAME") )selected="selected"#end >first name</option>
<option value="LASTNAME" #if( $field.equals("LASTNAME") )selected="selected"#end >last name</option>
</select>&nbsp;
<select name="mode" size="1">
<option value="PREFIX" #if( $mode.equals("PREFIX") )selected="selected"#end >starts with the string</option>
<option value="SUBSTRING" #if( $mode.equals("SUBSTRING") )selected="selected"#end >contains the string</option>
<option value="REGEXP" #if( $mode.equals("REGEXP") )selected="selected"#end >matches the regular
expression</option>
</select>&nbsp;&nbsp;
<input type="text" name="term" size="32" maxlength="255" value="$!term" /></p>
<p>#button( "INPUT" "search" )</p>
</div>
#comment( "end Find Users form" )
</form>
#if( $results )
## Do a tricky set of computations here to figure out what we need to display in terms of the search results
## and the form to the right that lets us page through results.
#set( $resultcount = $results.size() )
#set( $is_next = 0 )
#set( $is_prev = 0 )
#if( $resultcount > $pagesize )
#set( $resultcount = $pagesize )
#set( $is_next = 1 )
#end
#if( $ofs > 0 )
#set( $is_prev = 1 )
#end
#set( $is_form = $is_next + $is_prev )
#set( $ndx_first = $ofs + 1 )
#set( $ndx_last = $ofs + $pagesize )
#if( $ndx_last > $fcount )
#set( $ndx_last = $fcount )
#end
#comment( "Results display" )
<hr />
<table width="100%" border="0" align="center"><tr valign="middle">
<td width="50%" align="left">
<b>Search Results</b>
#if( $is_form >= 1 )
(Displaying ${ndx_first}-${ndx_last} of ${fcount})
#end
</td>
<td width="50%" align="right">
#if( $is_form >= 1 )
#comment( "Results navigation form" )
<form method="POST" action="#formatURL( "SERVLET" "find_users.js.vs")">
<input type="hidden" name="field" value="$field" />
<input type="hidden" name="mode" value="$mode" />
<input type="hidden" name="term" value="$term" />
<input type="hidden" name="ofs" value="$ofs" />
<input type="hidden" name="fcount" value="$fcount" />
#if( $is_prev == 1 )
#button( "INPUT" "previous" )
#else
#button( "IMAGE" "0transparent" )
#end
&nbsp;&nbsp;
#if( $is_next == 1 )
#button( "INPUT" "next" )
#else
#button( "IMAGE" "0transparent" )
#end
</form>
#else
&nbsp;
#end
</td>
</tr></table>
#if( $fcount > 0 )
#set( $i = $resultcount )
#set( $prof_ns = "http://www.silverwrist.com/NS/venice/2002/12/31/user.profile" )
<table border="0" align="left" cellpadding="0" cellspacing="4">
#foreach( $usr in $results )
#set( $i = $i - 1 )
#if( $i >= 0 )
#set( $first = $std.getProperty($usr,$prof_ns,"name.given") )
#set( $last = $std.getProperty($usr,$prof_ns,"name.family") )
#set( $city = $std.getProperty($usr,$prof_ns,"locality") )
#set( $state = $std.getProperty($usr,$prof_ns,"region") )
#set( $country = $std.getProperty($usr,$prof_ns,"country") )
#set( $descr = $std.getProperty($usr,$prof_ns,"description") )
<tr valign="top">
<td align="center" width="14">#bullet()</td>
<td align="left" class="content">
<a href="#formatURL( "SERVLET" "user/${usr.Name}" )">#encodeHTML( $usr.Name )</a><br />
#encodeHTML( $first ) #encodeHTML( $last ), from #encodeHTML( $city ), #encodeHTML( $state )
&nbsp;#encodeHTML( $country.getCode() )
#if( $descr )
<br /><em>#encodeHTML( $descr )</em>
#end
</td>
</tr>
#end
#end
</table>
#else
<em>No users found.</em>
#end
#comment( "End results display" )
#end