Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
intranet-csv-import
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
project-open
intranet-csv-import
Commits
2fc08a5e
Commit
2fc08a5e
authored
Nov 02, 2011
by
Frank Bergmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- CSV Import Projects:
Fixed importing CSV DynFields
parent
0beaf36e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
91 deletions
+117
-91
intranet-csv-import-procs.tcl
tcl/intranet-csv-import-procs.tcl
+103
-89
import-2.adp
www/import-2.adp
+1
-1
import-2.tcl
www/import-2.tcl
+12
-0
index.adp
www/index.adp
+1
-1
No files found.
tcl/intranet-csv-import-procs.tcl
View file @
2fc08a5e
...
...
@@ -73,6 +73,7 @@ ad_proc -public im_csv_import_parser_category {
# Parse the category
set result
[
im_id_from_category
$arg
$parser
_args
]
if
{
""
==
$result
}
{
return
[
list
""
"Category parser: We did not find a value='
$arg
' in category type '
$parser
_args'."
]
}
else
{
...
...
@@ -130,72 +131,64 @@ ad_proc -public im_csv_import_label_from_object_type {
ad_proc -public im_csv_import_object_fields
{
-object_type:required
}
{
Returns
the main navbar lable for the object_type
Returns
a list of database columns for the specified object type.
}
{
switch
$object
_type
{
im_project
{
set object_fields
{
customer_name
parent_nrs
project_nr
project_name
project_status
project_type
start_date
end_date
customer_contact
on_track_status
percent_completed
project_manager
project_priority
program
milestone_p
description
note
material
uom
planned_units
billable_units
cost_center_code
timesheet_task_priority
sort_order
project_budget
project_budget_currency
project_budget_hours
presales_probability
presales_value
project_path
confirm_date
source_language
subject_area
final_company
expected_quality
customer_project_nr
}
}
default
{
ad_return_complaint 1
"Unknown object type '
$object
_type'"
ad_script_abort
}
# Get the list of super-types for object_type, including object_type
# and remove
"acs_object"
from the list
set super_types
[
im_object_super_types -object_type
$object
_type
]
set s
[
list
]
foreach t
$super
_types
{
if
{
$t
==
"acs_object"
}
{
continue
}
lappend s
$t
}
set super_types
$s
# ---------------------------------------------------------------
# Get the list of tables associated with the object type and its super types
set tables_sql
"
select *
from (
select table_name, id_column, 1 as sort_order
from acs_object_types
where object_type in ('
[
join
$super
_types
"', '"
]
')
UNION
select table_name, id_column, 2 as sort_order
from acs_object_type_tables
where object_type in ('
[
join
$super
_types
"', '"
]
')
) t
order by t.sort_order
"
set dynfield_sql
"
select aa.*,
a.*,
w.*
from im_dynfield_widgets w,
im_dynfield_attributes a,
acs_attributes aa
where a.widget_name = w.widget_name and
a.acs_attribute_id = aa.attribute_id and
aa.object_type in ('im_project', 'im_timesheet_task') and
(also_hard_coded_p is null OR also_hard_coded_p = 'f')
set columns_sql
"
select lower(column_name) as column_name
from user_tab_columns
where lower(table_name) = lower(:table_name)
"
db_foreach dynfields
$dynfield
_sql
{
lappend object_fields
$attribute
_name
}
return
$object
_fields
set selected_columns
{}
set selected_tables
{}
set cnt 0
db_foreach tables
$tables
_sql
{
if
{[
lsearch
$selected
_tables
$table
_name
]
>= 0
}
{
ns_log Notice
"im_csv_import_object_fields: found duplicate table:
$table
_name"
continue
}
db_foreach columns
$columns
_sql
{
if
{[
lsearch
$selected
_columns
$column
_name
]
>= 0
}
{
ns_log Notice
"im_csv_import_object_fields: found ambiguous field:
$table
_name.
$column
_name"
continue
}
lappend selected_columns
$column
_name
}
lappend selected_tables
$table
_name
incr cnt
}
return
$selected
_columns
}
...
...
@@ -209,7 +202,7 @@ ad_proc -public im_csv_import_parsers {
Returns the list of available parsers
}
{
switch
$object
_type
{
im_project
{
im_project
- im_timesheet_task - im_ticket
{
set parsers
{
no_change
"No Change"
date_european
"European Date Parser (DD.MM.YYYY)"
...
...
@@ -219,7 +212,7 @@ ad_proc -public im_csv_import_parsers {
}
}
default
{
ad_return_complaint 1
"Unknown object type '
$object
_type'"
ad_return_complaint 1
"
im_csv_import_parsers:
Unknown object type '
$object
_type'"
ad_script_abort
}
}
...
...
@@ -240,60 +233,81 @@ ad_proc -public im_csv_import_guess_parser {
Returns the best guess for a parser for the given field as
a list with 1. the parser name and 2. the parser args
}
{
# --------------------------------------------------------
# Abort if there are not enough values
if
{[
llength
$sample
_values
]
< 2
}
{
return
[
list
""
""
]
}
# --------------------------------------------------------
# Date parsers
#
set date_european_p 1
set date_american_p 1
set number_plain_p 1
set number_european_p 1
set number_american_p 1
# set the parserst to 0 if one of the values doesn't fit
foreach val
$sample
_values
{
if
{
!
[
regexp
{
^
(
.+
)
\.
(
.+
)
\.
(
....
)
$
}
$val
match
]}
{
set date_european_p 0
}
if
{
!
[
regexp
{
^
(
.+
)
\/
(
.+
)
\/
(
....
)
$
}
$val
match
]}
{
set date_american_p 0
}
if
{
!
[
regexp
{
^
[
0-9
]
+$
}
$val
match
]}
{
set number_plain 0
}
# Abort if there are not enough values
if
{[
llength
$sample
_values
]
> 1
}
{
set date_european_p 1
set date_american_p 1
set number_plain_p 1
set number_european_p 1
set number_american_p 1
# set the parserst to 0 if one of the values doesn't fit
foreach val
$sample
_values
{
if
{
!
[
regexp
{
^
(
.+
)
\.
(
.+
)
\.
(
....
)
$
}
$val
match
]}
{
set date_european_p 0
}
if
{
!
[
regexp
{
^
(
.+
)
\/
(
.+
)
\/
(
....
)
$
}
$val
match
]}
{
set date_american_p 0
}
if
{
!
[
regexp
{
^
[
0-9
]
+$
}
$val
match
]}
{
set number_plain 0
}
}
if
{
$date
_european_p
}
{
return
[
list
"date_european"
""
]
}
if
{
$date
_american_p
}
{
return
[
list
"date_american"
""
]}
}
if
{
$date
_european_p
}
{
return
[
list
"date_european"
""
]
}
if
{
$date
_american_p
}
{
return
[
list
"date_american"
""
]}
# --------------------------------------------------------
# Get the list of super-types for object_type, including object_type
# and remove
"acs_object"
from the list
set super_types
[
im_object_super_types -object_type
$object
_type
]
set s
[
list
]
foreach t
$super
_types
{
if
{
$t
==
"acs_object"
}
{
continue
}
lappend s
$t
}
set super_types
$s
ns_log Notice
"im_csv_import_guess_parser: field_name=
$field
_name, super_types=
$super
_types"
# --------------------------------------------------------
# Parsing for DynFields
if
{[
db_0or1row dynfield_info
{
#
# There can be 0, 1 or multiple dynfields with the field_name,
# unfortunately.
set dynfield_sql
"
select dw.widget as tcl_widget,
dw.parameters as tcl_widget_parameters,
substring
(
dw.parameters from 'category_type
"(.*)
"
'
)
as category_type
substring(dw.parameters from 'category_type
\"
(.*)
\
"
') as category_type
from acs_attributes aa,
im_dynfield_attributes da,
im_dynfield_widgets dw
where aa.object_type
= :object_type
and
aa.attribute_name = :field_name
and
where aa.object_type
in ('
[
join
$super
_types
"','"
]
')
and
lower(aa.attribute_name) = lower(trim(:field_name))
and
aa.attribute_id = da.acs_attribute_id and
da.widget_name = dw.widget_name
}]}
{
"
set result
[
list
""
""
]
set ttt_widget
""
db_foreach dynfields
$dynfield
_sql
{
set ttt_widget
$tcl
_widget
switch
$tcl
_widget
{
"im_category_tree"
{
return
[
list
"category"
$category
_type
]
set result
[
list
"category"
$category
_type
]
}
"im_cost_center_tree"
{
return
[
list
"cost_center"
""
]
set result
[
list
"cost_center"
""
]
}
default
{
# Default: No specific parser
return
[
list
""
""
]
set result
[
list
""
""
]
}
}
}
return
[
list
""
""
]
ns_log Notice
"im_csv_import_guess_parser: field_name=
$field
_name, tcl_widget=
$ttt
_widget =>
$result
"
return
$result
}
...
...
www/import-2.adp
View file @
2fc08a5e
...
...
@@ -3,7 +3,7 @@
<property name="context">@context_bar@</property>
<property name="main_navbar_label">@main_navbar_label@</property>
<form enctype="multipart/form-data" method=POST action="import-@object_type@.tcl">
<form enctype="multipart/form-data" method=POST action="import-@
redirect_
object_type@.tcl">
<%= [export_form_vars object_type return_url import_filename] %>
<table>
...
...
www/import-2.tcl
View file @
2fc08a5e
...
...
@@ -112,6 +112,7 @@ foreach field $object_fields { lappend object_type_pairs [string tolower $field]
set
cnt 0
foreach
header_name
$headers
{
ns_log Notice
"import-2: otype=
$object
_type, field_name=
$header
_name"
# Column - Name of the CSV colum
set column
"<input type=hidden name=column.
$cnt
value=
\"
$header
_name
\"
>"
...
...
@@ -128,6 +129,7 @@ foreach header_name $headers {
if
{
""
!=
$val
}
{
lappend parser_sample_values
$val
}
}
set defs
[
im_csv_import_guess_parser -object_type
$object
_type -field_name
$header
_name -sample_values
$parser
_sample_values
]
ns_log Notice
"import-2: otype=
$object
_type, field_name=
$header
_name => parser=
$defs
"
set default_parser
[
lindex
$defs
0
]
set default_parser_args
[
lindex
$defs
1
]
...
...
@@ -139,3 +141,13 @@ foreach header_name $headers {
incr cnt
}
# Redirect to a specific page for the import
switch
$object
_type
{
im_timesheet_task - im_ticket
{
set redirect_object_type
"im_project"
}
default
{
set redirect_object_type
$object
_type
}
}
www/index.adp
View file @
2fc08a5e
...
...
@@ -11,7 +11,7 @@
<tr>
<td>
#intranet-csv-import.Object_Type#
</td>
<td>
<
%=
[
im_select
object_type
[
list
im_project
"
Project
"
im_company
"
Company
"
person
"
User
"]
$
object_type
]
%
>
<
%=
[
im_select
object_type
[
list
im_project
"
Project
"
im_
timesheet_task
"
Timesheet
Task
"
im_
company
"
Company
"
person
"
User
"]
$
object_type
]
%
>
</td>
</tr>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment