| 1 | package Daje::Workflow::Activities::Tools::Generate::Angular; | ||
| 2 | use Mojo::Base 'Daje::Workflow::Activities::Tools::Generate::Base', -base, -signatures; | ||
| 3 | use v5.42; | ||
| 4 | |||
| 5 | use POSIX; | ||
| 6 | use Mojo::Util qw { camelize }; | ||
| 7 | use String::Util 'trim'; | ||
| 8 | |||
| 9 | sub generate_angular($self) { | ||
| 10 | # $self->model->insert_history( | ||
| 11 | # "Generate Angular", | ||
| 12 | # "Daje::Workflow::Activities::Tools::Generate::Angular::generate_angular", | ||
| 13 | # 1 | ||
| 14 | # ); | ||
| 15 | |||
| 16 | my $tools_projects_pkey = $self->context->{context}->{payload}->{tools_projects_fkey}; | ||
| 17 | my @outputs = split /,/, $self->get_parameter('Angular', 'Outputs', $tools_projects_pkey);; | ||
| 18 | try { | ||
| 19 | my $documents; | ||
| 20 | my $source = $self->get_parameter('Angular', 'Template Source', $tools_projects_pkey); | ||
| 21 | foreach my $output (@outputs) { | ||
| 22 | my $generate = "generate_" . trim($output); | ||
| 23 | my $doc = $self->$generate($tools_projects_pkey, $source); | ||
| 24 | if (ref $doc eq 'ARRAY') { | ||
| 25 | my $length = scalar @{ $doc }; | ||
| 26 | for (my $i = 0; $i < $length; $i++) { | ||
| 27 | push @{$documents}, @{ $doc }[$i]; | ||
| 28 | } | ||
| 29 | } else { | ||
| 30 | push @{$documents}, $doc; | ||
| 31 | } | ||
| 32 | |||
| 33 | } | ||
| 34 | my @data; | ||
| 35 | my $length = scalar @{$documents}; | ||
| 36 | for (my $i = 0; $i < $length; $i++) { | ||
| 37 | my $data->{data} = @{$documents}[$i]->{document}; | ||
| 38 | $data->{file} = @{ $documents }[$i]->{file}; | ||
| 39 | $data->{new_only} = @{ $documents }[$i]->{new_only} | ||
| 40 | if exists @{ $documents }[$i]->{new_only}; | ||
| 41 | $data->{path} = 1; | ||
| 42 | push(@data, $data); | ||
| 43 | } | ||
| 44 | $self->context->{context}->{payload}->{angular} = \@data; | ||
| 45 | |||
| 46 | } catch($e) { | ||
| 47 | say $e | ||
| 48 | $self->error->add_error($e); | ||
| 49 | }; | ||
| 50 | |||
| 51 | } | ||
| 52 | |||
| 53 | sub generate_interface($self, $tools_projects_pkey, $source) { | ||
| 54 | my $docs; | ||
| 55 | my $project_name = $self->load_project_name($tools_projects_pkey); | ||
| 56 | if($self->load_active_tables($tools_projects_pkey)) { | ||
| 57 | my $length = scalar @{$self->tables}; | ||
| 58 | for (my $i = 0; $i < $length; $i++) { | ||
| 59 | my $table->{table} = @{$self->tables}[$i]; | ||
| 60 | $table->{date_time} = strftime "%Y-%m-%d %H:%M:%S", localtime time; | ||
| 61 | $table->{project_name} = $project_name; | ||
| 62 | $table->{fields} = $self->load_active_table_fields($table->{table}->{tools_objects_pkey}); | ||
| 63 | $table->{class_name} = camelize $table->{project_name} . "_" . $table->{table}->{table_name}; | ||
| 64 | $self->versions($table); | ||
| 65 | my $documents = $self->build_documents($source,'interface'); | ||
| 66 | @{ $documents }[0]->{class_name} = $table->{class_name}; | ||
| 67 | @{ $documents }[0]->{file} = $self->get_parameter('Angular', 'Interface file path', $tools_projects_pkey) . $table->{project_name} . "." . $table->{table}->{table_name}. '.interface.ts'; | ||
| 68 | @{ $documents }[0]->{new_only} = 0; | ||
| 69 | push @{$docs}, @{ $documents }[0]; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | return $docs; | ||
| 73 | } | ||
| 74 | |||
| 75 | sub generate_component($self, $tools_projects_pkey, $source) { | ||
| 76 | my $docs; | ||
| 77 | my $project_name = $self->load_project_name($tools_projects_pkey); | ||
| 78 | if($self->load_active_tables($tools_projects_pkey)) { | ||
| 79 | my $length = scalar @{$self->tables}; | ||
| 80 | for (my $i = 0; $i < $length; $i++) { | ||
| 81 | my $table->{table} = @{$self->tables}[$i]; | ||
| 82 | $table->{date_time} = strftime "%Y-%m-%d %H:%M:%S", localtime time; | ||
| 83 | $table->{project_name} = $project_name; | ||
| 84 | $table->{fields} = $self->load_active_table_fields($table->{table}->{tools_objects_pkey}); | ||
| 85 | $table->{class_name} = camelize $table->{project_name} . "_" . $table->{table}->{table_name}; | ||
| 86 | $self->versions($table); | ||
| 87 | my $documents = $self->build_documents($source,'component'); | ||
| 88 | @{ $documents }[0]->{class_name} = $table->{class_name}; | ||
| 89 | @{ $documents }[0]->{file} = $self->get_parameter('Angular', 'Component file path', $tools_projects_pkey) . $table->{table}->{table_name} . '/' . $table->{table}->{table_name} . '.component.ts'; | ||
| 90 | @{ $documents }[0]->{new_only} = 0; | ||
| 91 | push @{$docs}, @{ $documents }[0]; | ||
| 92 | $documents = $self->build_documents($source,'component_html'); | ||
| 93 | @{ $documents }[0]->{class_name} = $table->{class_name}; | ||
| 94 | @{ $documents }[0]->{file} = $self->get_parameter('Angular', 'Component file path', $tools_projects_pkey) . $table->{table}->{table_name} . '/' . $table->{table}->{table_name} . '.component.html'; | ||
| 95 | @{ $documents }[0]->{new_only} = 0; | ||
| 96 | push @{$docs}, @{ $documents }[0]; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | return $docs; | ||
| 101 | } | ||
| 102 | 1; |