Commit 093565a6 authored by Frank Bergmann's avatar Frank Bergmann

- baselkb changes:

	- DynField extended with include_in_search_p and display function
parent 8ebc41e9
...@@ -58,7 +58,12 @@ create table im_dynfield_widgets ( ...@@ -58,7 +58,12 @@ create table im_dynfield_widgets (
sql_datatype varchar(200) sql_datatype varchar(200)
constraint im_dynfield_widgets_datatype_nn constraint im_dynfield_widgets_datatype_nn
not null, not null,
parameters varchar(4000) parameters varchar(4000),
-- Name of a PlPg/SQL function to convert a
-- reference (integer, timestamptz) into a
-- printable value. Example: im_name_from_user_id,
-- im_cost_center_name_from_id
deref_plpgsql_function varchar(100) default 'im_name_from_id'
); );
...@@ -184,10 +189,13 @@ create table im_dynfield_attributes ( ...@@ -184,10 +189,13 @@ create table im_dynfield_attributes (
deprecated_p char default 'f' deprecated_p char default 'f'
constraint im_dynfield_attr_deprecated_nn constraint im_dynfield_attr_deprecated_nn
not null not null
-- Should the field be included in intranet-search-pg?
include_in_search_p char(1) default 'f'
constraint im_dynfield_attributes_search_ch
check (include_in_search_p in ('t','f'))
); );
-- --
create table im_dynfield_type_attribute_map ( create table im_dynfield_type_attribute_map (
......
...@@ -36,8 +36,22 @@ ad_proc -public template::widget::generic_sql { element_reference tag_attributes ...@@ -36,8 +36,22 @@ ad_proc -public template::widget::generic_sql { element_reference tag_attributes
return "Generic SQL Widget: Error: Didn't find 'sql' parameter" return "Generic SQL Widget: Error: Didn't find 'sql' parameter"
} }
# The "include_empty_p" adds an empty line
set include_empty_p 1
set include_empty_p_pos [lsearch $params include_empty_p]
if { $include_empty_p_pos >= 0 } {
set include_empty_p [lindex $params [expr $include_empty_p_pos + 1]]
}
# The "include_empty_name" pops up as first line
set include_empty_name ""
# [lang::message::lookup "" intranet-dynfield.no_value]
set include_empty_name_pos [lsearch $params include_empty_name]
if { $include_empty_name_pos >= 0 } {
set include_empty_name [lindex $params [expr $include_empty_name_pos + 1]]
}
array set attributes $tag_attributes array set attributes $tag_attributes
#set attributes(multiple) {}
set key_value_list [list] set key_value_list [list]
if {[catch {set key_value_list [db_list_of_lists sql_statement $sql_statement]} errmsg]} { if {[catch {set key_value_list [db_list_of_lists sql_statement $sql_statement]} errmsg]} {
...@@ -70,9 +84,11 @@ ad_proc -public template::widget::generic_sql { element_reference tag_attributes ...@@ -70,9 +84,11 @@ ad_proc -public template::widget::generic_sql { element_reference tag_attributes
incr i 2 incr i 2
} }
append sql_html " >\n" append sql_html " >\n"
if {[exists_and_not_null element(optional)] && $element(optional)} {
append sql_html "<option value=\"\"> [_ intranet-dynfield.no_value]</option>" if {$include_empty_p} {
append sql_html "<option value=\"\">$include_empty_name</option>"
} }
foreach sql $key_value_list { foreach sql $key_value_list {
set key [lindex $sql 0] set key [lindex $sql 0]
set value [lindex $sql 1] set value [lindex $sql 1]
......
...@@ -1292,6 +1292,42 @@ ad_proc -public im_dynfield::set_form_values_from_http { ...@@ -1292,6 +1292,42 @@ ad_proc -public im_dynfield::set_form_values_from_http {
} }
ad_proc -public im_dynfield::set_local_form_vars_from_http {
-form_id:required
} {
Set local variables to the values passed on in HTTP,
so that we don't need to add all of them into the ad_header.
@param form_id: search form id
@return: Form_vars that are also in the HTTP are set to the
calling variable frame
} {
ns_log Notice "im_dynfield::set_local_form_vars_form_http: form_id=$form_id"
set form_elements [template::form::get_elements $form_id]
set form_vars [ns_conn form]
if {"" == $form_vars} {
# There are no variables from HTTP - so there
# are not values to be set...
return ""
}
foreach element $form_elements {
# Only set the values for variables that are found in the
# HTTP variable frame to avoid ambiguities
set pos [ns_set find $form_vars $element]
if {$pos >= 0} {
set value [ns_set get $form_vars $element]
# Write the values to the calling stack frame
upvar $element $element
set $element $value
}
append debug " $element"
}
}
ad_proc -public im_dynfield::attribute_store { ad_proc -public im_dynfield::attribute_store {
-object_type:required -object_type:required
-object_id:required -object_id:required
...@@ -1968,15 +2004,20 @@ ad_proc -public im_dynfield::search_query { ...@@ -1968,15 +2004,20 @@ ad_proc -public im_dynfield::search_query {
ad_proc -public im_dynfield::append_attributes_to_form { ad_proc -public im_dynfield::append_attributes_to_form {
{-object_type_id "" } {-object_subtype_id "" }
-object_type:required -object_type:required
-form_id:required -form_id:required
{-object_id ""} {-object_id ""}
{-search_p "0"} {-search_p "0"}
{-form_display_mode "edit" } {-form_display_mode "edit" }
{-advanced_filter_p 0}
} { } {
Append intranet-dynfield attributes for object_type to an existing form.<p> Append intranet-dynfield attributes for object_type to an existing form.<p>
@option object_type The object_type attributes you want to add to the form @option object_type The object_type attributes you want to add to the form
@option object_subtype_id Specifies the "subtype" of the objects (i.e. project_type_id)
@option advanced_filter_p Tells us that the dynfields are used for an
"advanced filter" as oposed to a data form. Text fields dont make
much sense here, so we'll skip them.
The code consists of two main parts: The code consists of two main parts:
<ul> <ul>
...@@ -2015,10 +2056,9 @@ ad_proc -public im_dynfield::append_attributes_to_form { ...@@ -2015,10 +2056,9 @@ ad_proc -public im_dynfield::append_attributes_to_form {
} }
} }
# Get display mode per attribute and object_type_id # Get display mode per attribute and object_type_id
set sql " set sql "
select m.attribute_id, select m.attribute_id,
m.object_type_id as ot, m.object_type_id as ot,
m.display_mode as dm m.display_mode as dm
from from
...@@ -2039,8 +2079,8 @@ ad_proc -public im_dynfield::append_attributes_to_form { ...@@ -2039,8 +2079,8 @@ ad_proc -public im_dynfield::append_attributes_to_form {
set display_mode_hash($key) $dm set display_mode_hash($key) $dm
# Now we've got atleast one display mode configured: # Now we've got atleast one display mode configured:
# Set the default to "none", so that non except for the # Set the default to "none", so that no field is shown
# configured fields appear. # except for the configured fields.
set default_display_mode "none" set default_display_mode "none"
ns_log Notice "append_attributes_to_form: display_mode($key) <= $dm" ns_log Notice "append_attributes_to_form: display_mode($key) <= $dm"
...@@ -2048,8 +2088,17 @@ ad_proc -public im_dynfield::append_attributes_to_form { ...@@ -2048,8 +2088,17 @@ ad_proc -public im_dynfield::append_attributes_to_form {
# Disable the mechanism if the object_type_id hasn't been specified # Disable the mechanism if the object_type_id hasn't been specified
# (compatibility mode) # (compatibility mode)
if {"" == $object_type_id} { set default_display_mode "edit" } if {"" == $object_subtype_id} { set default_display_mode "edit" }
set extra_wheres [list "1=1"]
if {$advanced_filter_p} {
lappend extra_wheres "aw.widget in (
'select', 'generic_sql',
'im_category_tree', 'im_cost_center_tree',
'checkbox'
)"
}
set extra_where [join $extra_wheres "\n\t\tand "]
set attributes_sql " set attributes_sql "
select a.attribute_id, select a.attribute_id,
...@@ -2084,6 +2133,7 @@ ad_proc -public im_dynfield::append_attributes_to_form { ...@@ -2084,6 +2133,7 @@ ad_proc -public im_dynfield::append_attributes_to_form {
and a.attribute_id = aa.acs_attribute_id and a.attribute_id = aa.acs_attribute_id
and aa.widget_name = aw.widget_name and aa.widget_name = aw.widget_name
and im_object_permission_p(aa.attribute_id, :user_id, 'read') = 't' and im_object_permission_p(aa.attribute_id, :user_id, 'read') = 't'
and $extra_where
order by order by
dl.pos_y, dl.pos_y,
aa.attribute_id aa.attribute_id
...@@ -2092,8 +2142,10 @@ ad_proc -public im_dynfield::append_attributes_to_form { ...@@ -2092,8 +2142,10 @@ ad_proc -public im_dynfield::append_attributes_to_form {
db_foreach attributes $attributes_sql { db_foreach attributes $attributes_sql {
set display_mode $default_display_mode set display_mode $default_display_mode
set key "$dynfield_attribute_id.$object_type_id" set key "$dynfield_attribute_id.$object_subtype_id"
if {[info exists display_mode_hash($key)]} { set display_mode $display_mode_hash($key) } if {[info exists display_mode_hash($key)]} {
set display_mode $display_mode_hash($key)
}
if {"edit" == $display_mode && "display" == $form_display_mode} { if {"edit" == $display_mode && "display" == $form_display_mode} {
set display_mode $form_display_mode set display_mode $form_display_mode
...@@ -2189,7 +2241,7 @@ ad_proc -public im_dynfield::append_attributes_to_form { ...@@ -2189,7 +2241,7 @@ ad_proc -public im_dynfield::append_attributes_to_form {
db_foreach attributes $attributes_sql { db_foreach attributes $attributes_sql {
set display_mode $default_display_mode set display_mode $default_display_mode
set key "$dynfield_attribute_id.$object_type_id" set key "$dynfield_attribute_id.$object_subtype_id"
if {[info exists display_mode_hash($key)]} { set display_mode $display_mode_hash($key) } if {[info exists display_mode_hash($key)]} { set display_mode $display_mode_hash($key) }
if {"none" == $display_mode} { continue } if {"none" == $display_mode} { continue }
...@@ -2821,3 +2873,5 @@ ad_proc -public im_dynfield::option::map { ...@@ -2821,3 +2873,5 @@ ad_proc -public im_dynfield::option::map {
} { } {
return [db_exec_plsql im_dynfield_option_map {}] return [db_exec_plsql im_dynfield_option_map {}]
} }
...@@ -47,6 +47,7 @@ if {0 != $attribute_id} { ...@@ -47,6 +47,7 @@ if {0 != $attribute_id} {
a.table_name, a.table_name,
case when a.min_n_values = 0 then 'f' else 't' end as required_p, case when a.min_n_values = 0 then 'f' else 't' end as required_p,
fa.widget_name, fa.widget_name,
fa.include_in_search_p,
dl.pos_x, dl.pos_y, dl.pos_x, dl.pos_y,
dl.size_x, dl.size_y, dl.size_x, dl.size_y,
dl.label_style, dl.div_class dl.label_style, dl.div_class
...@@ -208,7 +209,6 @@ if {[string equal $action "already_existing"]} { ...@@ -208,7 +209,6 @@ if {[string equal $action "already_existing"]} {
} }
#{description:text(textarea),optional {label Description} {nospell} {html {cols 55 rows 4}}}
foreach field { foreach field {
{action:text(hidden),optional {}} {action:text(hidden),optional {}}
{pretty_name:text {label {Pretty Name}} {html {size 30 maxlength 100}}} {pretty_name:text {label {Pretty Name}} {html {size 30 maxlength 100}}}
...@@ -222,6 +222,7 @@ foreach field { ...@@ -222,6 +222,7 @@ foreach field {
{size_x:text(hidden),optional {label {Size-X}} {html {size 5 maxlength 4}}} {size_x:text(hidden),optional {label {Size-X}} {html {size 5 maxlength 4}}}
{size_y:text(hidden),optional {label {Size-Y}} {html {size 5 maxlength 4}}} {size_y:text(hidden),optional {label {Size-Y}} {html {size 5 maxlength 4}}}
{label_style:text(hidden) {label {Label Style}} {options {{Plain plain} {{No Label} no_label} }} {value $required_p}} {label_style:text(hidden) {label {Label Style}} {options {{Plain plain} {{No Label} no_label} }} {value $required_p}}
{include_in_search_p:text(checkbox) {label {Include in Search?}} {options {{Yes t}}} {value $required_p}}
} { } {
lappend form_fields $field lappend form_fields $field
} }
...@@ -287,7 +288,8 @@ ad_form -name attribute_form -form $form_fields -new_request { ...@@ -287,7 +288,8 @@ ad_form -name attribute_form -form $form_fields -new_request {
# update im_dynfield_attributes table # update im_dynfield_attributes table
db_dml "update im_dynfield_attributes" " db_dml "update im_dynfield_attributes" "
update im_dynfield_attributes set update im_dynfield_attributes set
widget_name = :widget_name widget_name = :widget_name,
include_in_search_p = :include_in_search_p
where attribute_id = :attribute_id where attribute_id = :attribute_id
" "
} }
...@@ -330,12 +332,3 @@ ad_form -name attribute_form -form $form_fields -new_request { ...@@ -330,12 +332,3 @@ ad_form -name attribute_form -form $form_fields -new_request {
ad_return_template ad_return_template
#set a {
# {attribute_name:text {label "Attribute Name"} {html {size 30 maxlength 100}} {help_text {Attribute name = column_name. <br>This name must be lower case, contain only letters and underscores, and contain no spaces}}} \
# {object_type:text {label "Object Type"} {} {html {size 30 maxlength 100}} }
# {table_name:text {label "Table Name"} {html {size 30 maxlength 100}}}
# {modify_sql_p:text(radio) {label "Modify the<br>SQL Table?"} {options {{"Yes" "t"} {No f}}} {value $modify_sql_p} {help_text {Please choose 'No' if you are unsure.<br>The system will try to add a new column to the database schema if you choose "Yes".}} }
# {widget_name:text(multiselect) {label "Widget"} {options $widget_options } {help_text {<a href="widgets">Widgets descriptions</a> are available}}}
# {description:text(textarea),optional {label "Description"} {nospell} {html {cols 55 rows 4}}}
#}
...@@ -48,6 +48,8 @@ set sql " ...@@ -48,6 +48,8 @@ set sql "
m.attribute_id = a.attribute_id m.attribute_id = a.attribute_id
and a.acs_attribute_id = aa.attribute_id and a.acs_attribute_id = aa.attribute_id
and aa.object_type = 'im_project' and aa.object_type = 'im_project'
order by
aa.sort_order, aa.pretty_name
" "
db_foreach attribute_table_map $sql { db_foreach attribute_table_map $sql {
set key "$attribute_id.$object_type_id" set key "$attribute_id.$object_type_id"
......
...@@ -4,6 +4,22 @@ ...@@ -4,6 +4,22 @@
<h1>@page_title;noquote@</h1> <h1>@page_title;noquote@</h1>
<form action="attribute-type-map" method=POST>
<%= [export_form_vars acs_object_type return_url] %>
<table>
<tr class=rowtitle><td class=rowtitle align=center colspan=2>Filter Subtypes</td></tr>
<tr>
<td class=form-label>Object Subtype</td>
<td class=form-widget><%= [im_category_select -include_empty_p 1 $category_type object_subtype_id $object_subtype_id] %></td>
</tr>
<tr>
<td class=form-label></td>
<td class=form-widget><input type=submit></td>
</tr>
</table>
</form>
<b>Explanation</b> <b>Explanation</b>
<ul> <ul>
<li>N - D - E <li>N - D - E
...@@ -12,8 +28,9 @@ ...@@ -12,8 +28,9 @@
<li>Third = "Edit" - Edit the field <li>Third = "Edit" - Edit the field
</ul> </ul>
<form action=attribute-type-map-2 method=POST>
<%= [export_form_vars acs_object_type return_url] %> <form action="attribute-type-map-2" method=POST>
<%= [export_form_vars acs_object_type object_subtype_id return_url] %>
<table> <table>
@header_html;noquote@ @header_html;noquote@
...@@ -23,6 +40,7 @@ ...@@ -23,6 +40,7 @@
<td colspan=99><input type=submit></td> <td colspan=99><input type=submit></td>
</tr> </tr>
</table> </table>
</form> </form>
...@@ -8,6 +8,7 @@ ad_page_contract { ...@@ -8,6 +8,7 @@ ad_page_contract {
@cvs-id $Id$ @cvs-id $Id$
} { } {
{ acs_object_type "im_project" } { acs_object_type "im_project" }
{ object_subtype_id 0 }
} }
# -------------------------------------------------------------- # --------------------------------------------------------------
...@@ -41,11 +42,28 @@ switch $acs_object_type { ...@@ -41,11 +42,28 @@ switch $acs_object_type {
default { set category_type "" } default { set category_type "" }
} }
set object_subtype_sql ""
if {$object_subtype_id} {
set object_subtype_sql "
and category_id in (
select child_id
from im_category_hierarchy
where parent_id = :object_subtype_id
UNION
select :object_subtype_id
)
"
}
# The "dimension" is a list of values to be displayed on top. # The "dimension" is a list of values to be displayed on top.
set top_scale [db_list top_dim " set top_scale [db_list top_dim "
select category_id select category_id
from im_categories from im_categories
where category_type = :category_type where category_type = :category_type
$object_subtype_sql
order by
category_id
"] "]
# The array maps category_id into "category" - a pretty # The array maps category_id into "category" - a pretty
...@@ -56,6 +74,9 @@ db_foreach top_scale_map " ...@@ -56,6 +74,9 @@ db_foreach top_scale_map "
category category
from im_categories from im_categories
where category_type = :category_type where category_type = :category_type
$object_subtype_sql
order by
category_id
" { " {
set col_title "" set col_title ""
foreach c $category { foreach c $category {
...@@ -84,6 +105,8 @@ set left_scale [db_list left_dim " ...@@ -84,6 +105,8 @@ set left_scale [db_list left_dim "
where where
a.acs_attribute_id = aa.attribute_id a.acs_attribute_id = aa.attribute_id
and aa.object_type = :acs_object_type and aa.object_type = :acs_object_type
order by
aa.sort_order, aa.pretty_name
"] "]
# The array maps category_id into "attribute_id category" - a pretty # The array maps category_id into "attribute_id category" - a pretty
...@@ -97,6 +120,8 @@ db_foreach left_scale_map " ...@@ -97,6 +120,8 @@ db_foreach left_scale_map "
where where
a.acs_attribute_id = aa.attribute_id a.acs_attribute_id = aa.attribute_id
and aa.object_type = :acs_object_type and aa.object_type = :acs_object_type
order by
aa.sort_order, aa.pretty_name
" { set left_scale_map($attribute_id) $pretty_name } " { set left_scale_map($attribute_id) $pretty_name }
...@@ -116,6 +141,8 @@ set sql " ...@@ -116,6 +141,8 @@ set sql "
m.attribute_id = a.attribute_id m.attribute_id = a.attribute_id
and a.acs_attribute_id = aa.attribute_id and a.acs_attribute_id = aa.attribute_id
and aa.object_type = 'im_project' and aa.object_type = 'im_project'
order by
aa.sort_order, aa.pretty_name
" "
db_foreach attribute_table_map $sql { db_foreach attribute_table_map $sql {
set key "$attribute_id.$object_type_id" set key "$attribute_id.$object_type_id"
...@@ -131,7 +158,11 @@ db_foreach attribute_table_map $sql { ...@@ -131,7 +158,11 @@ db_foreach attribute_table_map $sql {
set header "<td></td>\n" set header "<td></td>\n"
foreach top $top_scale { foreach top $top_scale {
set top_pretty $top_scale_map($top) set top_pretty $top_scale_map($top)
append header "<td class=rowtitle>$top_pretty</td>\n" append header "
<td class=rowtitle>
$top_pretty
</td>
"
} }
set header_html "<tr class=rowtitle valign=top>\n$header</tr>\n" set header_html "<tr class=rowtitle valign=top>\n$header</tr>\n"
...@@ -161,9 +192,11 @@ foreach left $left_scale { ...@@ -161,9 +192,11 @@ foreach left $left_scale {
set val " set val "
<nobr> <nobr>
<font size=-2>
<input value=none type=radio name=\"attrib.$attribute_id.$object_type_id\" $none_checked> <input value=none type=radio name=\"attrib.$attribute_id.$object_type_id\" $none_checked>
<input value=display type=radio name=\"attrib.$attribute_id.$object_type_id\" $disp_checked> <input value=display type=radio name=\"attrib.$attribute_id.$object_type_id\" $disp_checked>
<input value=edit type=radio name=\"attrib.$attribute_id.$object_type_id\" $edit_checked> <input value=edit type=radio name=\"attrib.$attribute_id.$object_type_id\" $edit_checked>
</font>
</nobr> </nobr>
" "
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
where where
aa.object_type = :object_type aa.object_type = :object_type
and fa.widget_name = w.widget_name and fa.widget_name = w.widget_name
order by
la.pos_y, la.pos_x, aa.attribute_name
</querytext> </querytext>
</fullquery> </fullquery>
......
...@@ -73,6 +73,16 @@ set widget_options [list \ ...@@ -73,6 +73,16 @@ set widget_options [list \
] ]
set deref_options [list \
[list "Generic Default (im_name_from_id)" "im_name_from_id"] \
[list "User Name (im_name_from_user_id)" "im_name_from_user_id"] \
[list "User Email (im_email_from_user_id)" "im_email_from_user_id"] \
[list "Cost Center Name (im_cost_center_name_from_id)" "im_cost_center_name_from_id"] \
]
# [list "" ""] \
ad_form \ ad_form \
-name widget \ -name widget \
-cancel_url $return_url \ -cancel_url $return_url \
...@@ -87,8 +97,9 @@ ad_form \ ...@@ -87,8 +97,9 @@ ad_form \
{storage_type_id:text(select) {label "Storage Type"} {options $storage_options} } {storage_type_id:text(select) {label "Storage Type"} {options $storage_options} }
{acs_datatype:text(select) {label "ACS Datatype"} {options $acs_datatype_options} } {acs_datatype:text(select) {label "ACS Datatype"} {options $acs_datatype_options} }
{sql_datatype:text(text) {label "SQL Datatype"} {html {size 60}} {help_text {Please specify the datatype for this attribute when we generate a new SQL column. Examples: <table><tr><td><li>integer<li>varchar(200)</td><td><li>number(12,2)<li>clob</td></tr></table>}} } {sql_datatype:text(text) {label "SQL Datatype"} {html {size 60}} {help_text {Please specify the datatype for this attribute when we generate a new SQL column. Examples: <table><tr><td><li>integer<li>varchar(200)</td><td><li>number(12,2)<li>clob</td></tr></table>}} }
{widget:text(select) {label "Widget"} {options $widget_options} } {widget:text(select) {label "TCL Widget"} {options $widget_options} }
{parameters:text(text),optional {label "Parameters"} {html {size 60}}} {deref_plpgsql_function:text(select) {label "Dereferencing function"} {options $deref_options} {help_text {Select the function that converts an attribute of this widget into a printable/ searchable string.<br>Default is im_name_from_id which deals reasonably with most data.}} }
{parameters:text(textarea),optional {label "Parameters"} {nospell} {html {cols 65 rows 8}}}
} }
...@@ -124,6 +135,7 @@ ad_form -extend -name widget -on_request { ...@@ -124,6 +135,7 @@ ad_form -extend -name widget -on_request {
acs_datatype = :acs_datatype, acs_datatype = :acs_datatype,
sql_datatype = :sql_datatype, sql_datatype = :sql_datatype,
widget = :widget, widget = :widget,
deref_plpgsql_function = :deref_plpgsql_function,
parameters = :parameters parameters = :parameters
where where
widget_id = :widget_id widget_id = :widget_id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment