Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 09c8c053

Von Moritz Bunkus vor fast 7 Jahren hinzugefügt

  • ID 09c8c053181f182143beff935d011af15afddb01
  • Vorgänger e713c314
  • Nachfolger bc0e2eda

Benutzerdefinierte Datenexporte: Standardwerte für Parameter angeben können

Unterschiede anzeigen:

SL/Controller/CustomDataExport.pm
17 17
use Rose::Object::MakeMethods::Generic
18 18
(
19 19
  scalar                  => [ qw(rows) ],
20
  'scalar --get_set_init' => [ qw(query queries parameters today) ],
20
  'scalar --get_set_init' => [ qw(query queries parameters) ],
21 21
);
22 22

  
23 23
__PACKAGE__->run_before('check_auth');
......
72 72

  
73 73
sub init_query      { $::form->{id} ? SL::DB::CustomDataExportQuery->new(id => $::form->{id})->load : SL::DB::CustomDataExportQuery->new }
74 74
sub init_parameters { [ sort_by { lc $_->name } @{ $_[0]->query->parameters // [] } ] }
75
sub init_today      { DateTime->today_local }
76 75

  
77 76
sub init_queries {
78 77
  my %rights_map     = %{ $::auth->load_rights_for_user($::form->{login}) };
SL/Controller/CustomDataExportDesigner.pm
82 82
}
83 83

  
84 84
sub setup_javascripts {
85
  $::request->layout->add_javascripts('kivi.Validator.js');
85
  $::request->layout->add_javascripts('kivi.Validator.js', 'kivi.CustomDataExportDesigner.js');
86 86
}
87 87

  
88 88
#
......
181 181
  my %used_parameter_names  = map  { ($_ => 1) }                       $self->query->used_parameter_names;
182 182
  my @existing_parameters   = grep { $used_parameter_names{$_->name} } @{ $self->query->parameters // [] };
183 183
  my %parameters_by_name    = map  { ($_->name => $_) }                @existing_parameters;
184
  $parameters_by_name{$_} //= SL::DB::CustomDataExportQueryParameter->new(name => $_, parameter_type => 'text') for keys %used_parameter_names;
184
  $parameters_by_name{$_} //= SL::DB::CustomDataExportQueryParameter->new(name => $_, parameter_type => 'text', default_value_type => 'none') for keys %used_parameter_names;
185 185

  
186 186
  foreach my $parameter_data (@{ $::form->{parameters} // [] }) {
187 187
    my $parameter_obj = $parameters_by_name{ $parameter_data->{name} };
188 188
    next unless $parameter_obj;
189 189

  
190
    $parameter_obj->$_($parameter_data->{$_}) for qw(parameter_type description);
190
    $parameter_obj->$_($parameter_data->{$_}) for qw(parameter_type description default_value_type default_value);
191 191
  }
192 192

  
193 193
  return sort_by { lc $_->name } values %parameters_by_name;
SL/DB/CustomDataExportQueryParameter.pm
1
# This file has been auto-generated only because it didn't exist.
2
# Feel free to modify it at will; it will not be overwritten automatically.
3

  
4 1
package SL::DB::CustomDataExportQueryParameter;
5 2

  
6 3
use strict;
......
10 7

  
11 8
__PACKAGE__->meta->initialize;
12 9

  
10
sub _default_value_type_fixed_value        { $_[0]->default_value }
11
sub _default_value_type_current_user_login { $::myconfig{login} }
12

  
13
sub _default_value_type_sql_query {
14
  my ($self) = @_;
15

  
16
  return '' if !$self->default_value;
17

  
18
  my @result = $self->db->dbh->selectrow_array($self->default_value);
19
  $::form->dberror if !@result;
20

  
21
  return $result[0];
22
}
23

  
24
sub calculate_default_value {
25
  my ($self) = @_;
26

  
27
  my $method = "_default_value_type_" . ($self->default_value_type // '');
28
  return $self->can($method) ? $self->$method : '';
29
}
30

  
13 31
1;
SL/DB/MetaSetup/CustomDataExportQueryParameter.pm
9 9
__PACKAGE__->meta->table('custom_data_export_query_parameters');
10 10

  
11 11
__PACKAGE__->meta->columns(
12
  description    => { type => 'text' },
13
  id             => { type => 'serial', not_null => 1 },
14
  itime          => { type => 'timestamp', default => 'now()', not_null => 1 },
15
  mtime          => { type => 'timestamp', default => 'now()', not_null => 1 },
16
  name           => { type => 'text', not_null => 1 },
17
  parameter_type => { type => 'enum', check_in => [ 'text', 'number', 'date', 'timestamp' ], db_type => 'custom_data_export_query_parameter_type_enum', not_null => 1 },
18
  query_id       => { type => 'integer', not_null => 1 },
12
  default_value      => { type => 'text' },
13
  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 },
14
  description        => { type => 'text' },
15
  id                 => { type => 'serial', not_null => 1 },
16
  itime              => { type => 'timestamp', default => 'now()', not_null => 1 },
17
  mtime              => { type => 'timestamp', default => 'now()', not_null => 1 },
18
  name               => { type => 'text', not_null => 1 },
19
  parameter_type     => { type => 'enum', check_in => [ 'text', 'number', 'date', 'timestamp' ], db_type => 'custom_data_export_query_parameter_type_enum', not_null => 1 },
20
  query_id           => { type => 'integer', not_null => 1 },
19 21
);
20 22

  
21 23
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
js/kivi.CustomDataExportDesigner.js
1
namespace('kivi.CustomDataExportDesigner', function(ns){
2
  'use strict';
3

  
4
  ns.enable_default_value = function() {
5
    var count = $(this).prop('id').replace("default_value_type_", "");
6
    var type  = $(this).val();
7
    $('#default_value_' + count).prop('disabled', (type === 'none') || (type === 'current_user_login'));
8
  };
9
});
10

  
11
$(function() {
12
  $('[id^="default_value_type_"]').change(kivi.CustomDataExportDesigner.enable_default_value);
13
});
locale/de/all
784 784
  'Current profile'             => 'Aktuelles Profil',
785 785
  'Current status'              => 'Aktueller Status',
786 786
  'Current status:'             => 'Aktueller Status:',
787
  'Current user\'s login'       => 'Login der aktuellen BenutzerIn',
787 788
  'Current value:'              => 'Aktueller Wert:',
788 789
  'Current version'             => 'Aktuelle Version',
789 790
  'Current year'                => 'Aktuelles Jahr',
......
1398 1399
  'Firstname'                   => 'Vorname',
1399 1400
  'Fix transaction'             => 'Buchung korrigieren',
1400 1401
  'Fix transactions'            => 'Buchungen korrigieren',
1402
  'Fixed value'                 => 'Fester Wert',
1401 1403
  'Focus position after update' => 'Eingabe-Fokus-Position nach Erneuern',
1402 1404
  'Folgekonto'                  => 'Folgekonto',
1403 1405
  'Follow-Up'                   => 'Wiedervorlage',
......
1952 1954
  'No customer has been selected yet.' => 'Es wurde noch kein Kunde ausgewählt.',
1953 1955
  'No data was found.'          => 'Es wurden keine Daten gefunden.',
1954 1956
  'No default currency'         => 'Keine Standardwährung',
1957
  'No default value'            => 'Kein Standardwert',
1955 1958
  'No delivery orders have been selected.' => 'Es wurden keine Lieferscheine ausgewählt.',
1956 1959
  'No delivery term has been created yet.' => 'Es wurden noch keine Lieferbedingungen angelegt',
1957 1960
  'No dunnings have been selected for printing.' => 'Es wurden keine Mahnungen zum Drucken ausgewählt.',
......
2572 2575
  'Requirement specs'           => 'Pflichtenhefte',
2573 2576
  'Reset'                       => 'Zurücksetzen',
2574 2577
  'Result'                      => 'Ergebnis',
2578
  'Result of SQL query'         => 'Ergebnis einer SQL-Abfrage',
2575 2579
  'Revenue'                     => 'Erlöskonto',
2576 2580
  'Revenue Account'             => 'Erlöskonto',
2577 2581
  'Reversal invoices cannot be canceled.' => 'Stornorechnungen können nicht storniert werden.',
sql/Pg-upgrade2/custom_data_export_default_values_for_parameters.sql
1
-- @tag: custom_data_export_default_values_for_parameters
2
-- @description: Bentuzerdefinierter Datenexport: Vorgabewerte für Parameter
3
-- @depends: custom_data_export
4
CREATE TYPE custom_data_export_query_parameter_default_value_type_enum AS ENUM ('none', 'current_user_login', 'sql_query', 'fixed_value');
5

  
6
ALTER TABLE custom_data_export_query_parameters
7
ADD COLUMN default_value_type custom_data_export_query_parameter_default_value_type_enum,
8
ADD COLUMN default_value      TEXT;
9

  
10
UPDATE custom_data_export_query_parameters
11
SET default_value_type = 'none';
12

  
13
ALTER TABLE custom_data_export_query_parameters
14
ALTER COLUMN default_value_type
15
SET NOT NULL;
templates/webpages/custom_data_export/export.html
32 32
      [% HTML.escape(parameter.name) %]
33 33
     </td>
34 34

  
35
     [% SET value = parameter.calculate_default_value %]
36

  
35 37
     [% IF parameter.parameter_type == "number" %]
36 38
      <td>[% LxERP.t8("Number") %]</td>
37
      <td>[% L.input_tag("parameters." _ parameter.name, "", style="width: 300px", "data-validate"="required") %]</td>
39
      <td>[% L.input_tag("parameters." _ parameter.name, value, style="width: 300px", "data-validate"="required") %]</td>
38 40

  
39 41
     [% ELSIF parameter.parameter_type == "date" %]
40 42
      <td>[% LxERP.t8("Date") %]</td>
41
      <td>[% L.date_tag("parameters." _ parameter.name, SELF.today.to_kivitendo, style="width: 300px", "data-validate"="required") %]</td>
43
      <td>[% L.date_tag("parameters." _ parameter.name, value, style="width: 300px", "data-validate"="required") %]</td>
42 44

  
43 45
     [% ELSE %]
44 46
      <td>[% LxERP.t8("Text") %]</td>
45
      <td>[% L.input_tag("parameters." _ parameter.name, "", style="width: 300px", "data-validate"="required") %]</td>
47
      <td>[% L.input_tag("parameters." _ parameter.name, value, style="width: 300px", "data-validate"="required") %]</td>
46 48
     [% END %]
47 49

  
48 50
     <td>[% HTML.escape(parameter.description) %]</td>
templates/webpages/custom_data_export_designer/edit_parameters.html
24 24
    <th>[% LxERP.t8("Variable Name") %]</th>
25 25
    <th>[% LxERP.t8("Type") %]</th>
26 26
    <th>[% LxERP.t8("Description") %]</th>
27
    <th colspan="2">[% LxERP.t8("Default value") %]</th>
27 28
   </tr>
28 29
  </thead>
29 30

  
30 31
  <tbody>
31 32
   [% FOREACH parameter = PARAMETERS %]
32 33
    <tr class="listrow">
33
     <td>
34
     <td valign="top">
34 35
      [% L.hidden_tag("parameters[+].name", parameter.name) %]
35 36
      [% HTML.escape(parameter.name) %]
36 37
     </td>
37
     <td>
38
     <td valign="top">
38 39
      [% L.select_tag("parameters[].parameter_type", [ [ "text", LxERP.t8("Text") ], [ "number", LxERP.t8("Number") ], [ "date", LxERP.t8("Date") ] ], default=parameter.parameter_type) %]
39 40
     </td>
40
     <td>[% L.input_tag("parameters[].description", parameter.description, size=100) %]</td>
41
     <td valign="top">[% L.input_tag("parameters[].description", parameter.description, size=100) %]</td>
42
     <td valign="top">
43
      [% L.select_tag("parameters[].default_value_type",
44
                      [ [ "none", LxERP.t8("No default value") ], [ "current_user_login", LxERP.t8("Current user's login") ], [ "sql_query", LxERP.t8("Result of SQL query") ],
45
                        [ "fixed_value", LxERP.t8("Fixed value") ] ],
46
                      default=parameter.default_value_type,
47
                      id="default_value_type_" _ loop.count) %]
48
     </td>
49
     <td valign="top">
50
      [% SET disabled = (parameter.default_value_type == "none") || (parameter.default_value_type == "current_user_login") ? "disabled" : "" %]
51
      [% L.textarea_tag("parameters[].default_value", parameter.default_value, id="default_value_" _ loop.count, cols=80, rows=3, disabled=disabled) %]
52
     </td>
41 53
    </tr>
42 54
   [% END %]
43 55
  </tbody>

Auch abrufbar als: Unified diff