From: Moritz Bunkus Date: Fri, 10 Nov 2017 12:59:39 +0000 (+0100) Subject: Benutzerdefinierte Datenexporte: Standardwerte für Parameter angeben können X-Git-Tag: release-3.5.4~557 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=09c8c053181f182143beff935d011af15afddb01;p=kivitendo-erp.git Benutzerdefinierte Datenexporte: Standardwerte für Parameter angeben können --- diff --git a/SL/Controller/CustomDataExport.pm b/SL/Controller/CustomDataExport.pm index dba497512..7d5eddee9 100644 --- a/SL/Controller/CustomDataExport.pm +++ b/SL/Controller/CustomDataExport.pm @@ -17,7 +17,7 @@ use SL::Locale::String qw(t8); use Rose::Object::MakeMethods::Generic ( scalar => [ qw(rows) ], - 'scalar --get_set_init' => [ qw(query queries parameters today) ], + 'scalar --get_set_init' => [ qw(query queries parameters) ], ); __PACKAGE__->run_before('check_auth'); @@ -72,7 +72,6 @@ sub setup_javascripts { sub init_query { $::form->{id} ? SL::DB::CustomDataExportQuery->new(id => $::form->{id})->load : SL::DB::CustomDataExportQuery->new } sub init_parameters { [ sort_by { lc $_->name } @{ $_[0]->query->parameters // [] } ] } -sub init_today { DateTime->today_local } sub init_queries { my %rights_map = %{ $::auth->load_rights_for_user($::form->{login}) }; diff --git a/SL/Controller/CustomDataExportDesigner.pm b/SL/Controller/CustomDataExportDesigner.pm index 0ab25f7f9..17266323b 100644 --- a/SL/Controller/CustomDataExportDesigner.pm +++ b/SL/Controller/CustomDataExportDesigner.pm @@ -82,7 +82,7 @@ sub check_auth { } sub setup_javascripts { - $::request->layout->add_javascripts('kivi.Validator.js'); + $::request->layout->add_javascripts('kivi.Validator.js', 'kivi.CustomDataExportDesigner.js'); } # @@ -181,13 +181,13 @@ sub gather_query_parameters { my %used_parameter_names = map { ($_ => 1) } $self->query->used_parameter_names; my @existing_parameters = grep { $used_parameter_names{$_->name} } @{ $self->query->parameters // [] }; my %parameters_by_name = map { ($_->name => $_) } @existing_parameters; - $parameters_by_name{$_} //= SL::DB::CustomDataExportQueryParameter->new(name => $_, parameter_type => 'text') for keys %used_parameter_names; + $parameters_by_name{$_} //= SL::DB::CustomDataExportQueryParameter->new(name => $_, parameter_type => 'text', default_value_type => 'none') for keys %used_parameter_names; foreach my $parameter_data (@{ $::form->{parameters} // [] }) { my $parameter_obj = $parameters_by_name{ $parameter_data->{name} }; next unless $parameter_obj; - $parameter_obj->$_($parameter_data->{$_}) for qw(parameter_type description); + $parameter_obj->$_($parameter_data->{$_}) for qw(parameter_type description default_value_type default_value); } return sort_by { lc $_->name } values %parameters_by_name; diff --git a/SL/DB/CustomDataExportQueryParameter.pm b/SL/DB/CustomDataExportQueryParameter.pm index 06e97f49f..bfefa82d5 100644 --- a/SL/DB/CustomDataExportQueryParameter.pm +++ b/SL/DB/CustomDataExportQueryParameter.pm @@ -1,6 +1,3 @@ -# This file has been auto-generated only because it didn't exist. -# Feel free to modify it at will; it will not be overwritten automatically. - package SL::DB::CustomDataExportQueryParameter; use strict; @@ -10,4 +7,25 @@ use SL::DB::Manager::CustomDataExportQueryParameter; __PACKAGE__->meta->initialize; +sub _default_value_type_fixed_value { $_[0]->default_value } +sub _default_value_type_current_user_login { $::myconfig{login} } + +sub _default_value_type_sql_query { + my ($self) = @_; + + return '' if !$self->default_value; + + my @result = $self->db->dbh->selectrow_array($self->default_value); + $::form->dberror if !@result; + + return $result[0]; +} + +sub calculate_default_value { + my ($self) = @_; + + my $method = "_default_value_type_" . ($self->default_value_type // ''); + return $self->can($method) ? $self->$method : ''; +} + 1; diff --git a/SL/DB/MetaSetup/CustomDataExportQueryParameter.pm b/SL/DB/MetaSetup/CustomDataExportQueryParameter.pm index d691e2662..b16c43e9e 100644 --- a/SL/DB/MetaSetup/CustomDataExportQueryParameter.pm +++ b/SL/DB/MetaSetup/CustomDataExportQueryParameter.pm @@ -9,13 +9,15 @@ use parent qw(SL::DB::Object); __PACKAGE__->meta->table('custom_data_export_query_parameters'); __PACKAGE__->meta->columns( - description => { type => 'text' }, - id => { type => 'serial', not_null => 1 }, - itime => { type => 'timestamp', default => 'now()', not_null => 1 }, - mtime => { type => 'timestamp', default => 'now()', not_null => 1 }, - name => { type => 'text', not_null => 1 }, - parameter_type => { type => 'enum', check_in => [ 'text', 'number', 'date', 'timestamp' ], db_type => 'custom_data_export_query_parameter_type_enum', not_null => 1 }, - query_id => { type => 'integer', not_null => 1 }, + default_value => { type => 'text' }, + default_value_type => { type => 'enum', check_in => [ 'none', 'current_user_login', 'sql_query', 'fixed_value' ], db_type => 'custom_data_export_query_parameter_default_value_type_enum', not_null => 1 }, + description => { type => 'text' }, + id => { type => 'serial', not_null => 1 }, + itime => { type => 'timestamp', default => 'now()', not_null => 1 }, + mtime => { type => 'timestamp', default => 'now()', not_null => 1 }, + name => { type => 'text', not_null => 1 }, + parameter_type => { type => 'enum', check_in => [ 'text', 'number', 'date', 'timestamp' ], db_type => 'custom_data_export_query_parameter_type_enum', not_null => 1 }, + query_id => { type => 'integer', not_null => 1 }, ); __PACKAGE__->meta->primary_key_columns([ 'id' ]); diff --git a/js/kivi.CustomDataExportDesigner.js b/js/kivi.CustomDataExportDesigner.js new file mode 100644 index 000000000..53e895347 --- /dev/null +++ b/js/kivi.CustomDataExportDesigner.js @@ -0,0 +1,13 @@ +namespace('kivi.CustomDataExportDesigner', function(ns){ + 'use strict'; + + ns.enable_default_value = function() { + var count = $(this).prop('id').replace("default_value_type_", ""); + var type = $(this).val(); + $('#default_value_' + count).prop('disabled', (type === 'none') || (type === 'current_user_login')); + }; +}); + +$(function() { + $('[id^="default_value_type_"]').change(kivi.CustomDataExportDesigner.enable_default_value); +}); diff --git a/locale/de/all b/locale/de/all index abeb3491b..38a608048 100755 --- a/locale/de/all +++ b/locale/de/all @@ -784,6 +784,7 @@ $self->{texts} = { 'Current profile' => 'Aktuelles Profil', 'Current status' => 'Aktueller Status', 'Current status:' => 'Aktueller Status:', + 'Current user\'s login' => 'Login der aktuellen BenutzerIn', 'Current value:' => 'Aktueller Wert:', 'Current version' => 'Aktuelle Version', 'Current year' => 'Aktuelles Jahr', @@ -1398,6 +1399,7 @@ $self->{texts} = { 'Firstname' => 'Vorname', 'Fix transaction' => 'Buchung korrigieren', 'Fix transactions' => 'Buchungen korrigieren', + 'Fixed value' => 'Fester Wert', 'Focus position after update' => 'Eingabe-Fokus-Position nach Erneuern', 'Folgekonto' => 'Folgekonto', 'Follow-Up' => 'Wiedervorlage', @@ -1952,6 +1954,7 @@ $self->{texts} = { 'No customer has been selected yet.' => 'Es wurde noch kein Kunde ausgewählt.', 'No data was found.' => 'Es wurden keine Daten gefunden.', 'No default currency' => 'Keine Standardwährung', + 'No default value' => 'Kein Standardwert', 'No delivery orders have been selected.' => 'Es wurden keine Lieferscheine ausgewählt.', 'No delivery term has been created yet.' => 'Es wurden noch keine Lieferbedingungen angelegt', 'No dunnings have been selected for printing.' => 'Es wurden keine Mahnungen zum Drucken ausgewählt.', @@ -2572,6 +2575,7 @@ $self->{texts} = { 'Requirement specs' => 'Pflichtenhefte', 'Reset' => 'Zurücksetzen', 'Result' => 'Ergebnis', + 'Result of SQL query' => 'Ergebnis einer SQL-Abfrage', 'Revenue' => 'Erlöskonto', 'Revenue Account' => 'Erlöskonto', 'Reversal invoices cannot be canceled.' => 'Stornorechnungen können nicht storniert werden.', diff --git a/sql/Pg-upgrade2/custom_data_export_default_values_for_parameters.sql b/sql/Pg-upgrade2/custom_data_export_default_values_for_parameters.sql new file mode 100644 index 000000000..7ce50569b --- /dev/null +++ b/sql/Pg-upgrade2/custom_data_export_default_values_for_parameters.sql @@ -0,0 +1,15 @@ +-- @tag: custom_data_export_default_values_for_parameters +-- @description: Bentuzerdefinierter Datenexport: Vorgabewerte für Parameter +-- @depends: custom_data_export +CREATE TYPE custom_data_export_query_parameter_default_value_type_enum AS ENUM ('none', 'current_user_login', 'sql_query', 'fixed_value'); + +ALTER TABLE custom_data_export_query_parameters +ADD COLUMN default_value_type custom_data_export_query_parameter_default_value_type_enum, +ADD COLUMN default_value TEXT; + +UPDATE custom_data_export_query_parameters +SET default_value_type = 'none'; + +ALTER TABLE custom_data_export_query_parameters +ALTER COLUMN default_value_type +SET NOT NULL; diff --git a/templates/webpages/custom_data_export/export.html b/templates/webpages/custom_data_export/export.html index 8b5ad9bae..283cae33e 100644 --- a/templates/webpages/custom_data_export/export.html +++ b/templates/webpages/custom_data_export/export.html @@ -32,17 +32,19 @@ [% HTML.escape(parameter.name) %] + [% SET value = parameter.calculate_default_value %] + [% IF parameter.parameter_type == "number" %] [% LxERP.t8("Number") %] - [% L.input_tag("parameters." _ parameter.name, "", style="width: 300px", "data-validate"="required") %] + [% L.input_tag("parameters." _ parameter.name, value, style="width: 300px", "data-validate"="required") %] [% ELSIF parameter.parameter_type == "date" %] [% LxERP.t8("Date") %] - [% L.date_tag("parameters." _ parameter.name, SELF.today.to_kivitendo, style="width: 300px", "data-validate"="required") %] + [% L.date_tag("parameters." _ parameter.name, value, style="width: 300px", "data-validate"="required") %] [% ELSE %] [% LxERP.t8("Text") %] - [% L.input_tag("parameters." _ parameter.name, "", style="width: 300px", "data-validate"="required") %] + [% L.input_tag("parameters." _ parameter.name, value, style="width: 300px", "data-validate"="required") %] [% END %] [% HTML.escape(parameter.description) %] diff --git a/templates/webpages/custom_data_export_designer/edit_parameters.html b/templates/webpages/custom_data_export_designer/edit_parameters.html index 3aeacf105..e1c94186c 100644 --- a/templates/webpages/custom_data_export_designer/edit_parameters.html +++ b/templates/webpages/custom_data_export_designer/edit_parameters.html @@ -24,20 +24,32 @@ [% LxERP.t8("Variable Name") %] [% LxERP.t8("Type") %] [% LxERP.t8("Description") %] + [% LxERP.t8("Default value") %] [% FOREACH parameter = PARAMETERS %] - + [% L.hidden_tag("parameters[+].name", parameter.name) %] [% HTML.escape(parameter.name) %] - + [% L.select_tag("parameters[].parameter_type", [ [ "text", LxERP.t8("Text") ], [ "number", LxERP.t8("Number") ], [ "date", LxERP.t8("Date") ] ], default=parameter.parameter_type) %] - [% L.input_tag("parameters[].description", parameter.description, size=100) %] + [% L.input_tag("parameters[].description", parameter.description, size=100) %] + + [% L.select_tag("parameters[].default_value_type", + [ [ "none", LxERP.t8("No default value") ], [ "current_user_login", LxERP.t8("Current user's login") ], [ "sql_query", LxERP.t8("Result of SQL query") ], + [ "fixed_value", LxERP.t8("Fixed value") ] ], + default=parameter.default_value_type, + id="default_value_type_" _ loop.count) %] + + + [% SET disabled = (parameter.default_value_type == "none") || (parameter.default_value_type == "current_user_login") ? "disabled" : "" %] + [% L.textarea_tag("parameters[].default_value", parameter.default_value, id="default_value_" _ loop.count, cols=80, rows=3, disabled=disabled) %] + [% END %]