[Bps-public-commit] rt-extension-formtools branch dynamic-forms-from-config updated. 0.53-36-ga05114f

BPS Git Server git at git.bestpractical.com
Fri Oct 6 11:37:22 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt-extension-formtools".

The branch, dynamic-forms-from-config has been updated
       via  a05114f948884441090591afa516417aec4e3f28 (commit)
      from  fb9708c226cf0c435d3cc61165acf8af2da676d5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a05114f948884441090591afa516417aec4e3f28
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Oct 6 07:29:25 2023 -0400

    Switch to a shorter page id
    
    Previously its length was 36, here we change to 8 to be more user
    friendly. This might cause conflicts, but it should be really rare in
    real world, and we can still make sure no conflicts happen in the same
    form.

diff --git a/META.yml b/META.yml
index 3cfe80b..9f86295 100644
--- a/META.yml
+++ b/META.yml
@@ -21,7 +21,6 @@ no_index:
     - inc
     - static
 requires:
-  UUID::Tiny: 0
   perl: 5.10.1
 resources:
   license: http://opensource.org/licenses/gpl-license.php
diff --git a/Makefile.PL b/Makefile.PL
index 0ae9903..ed71e84 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1,7 +1,6 @@
 use inc::Module::Install;
 RTx('RT-Extension-FormTools');
 requires_rt('5.0.0');
-requires('UUID::Tiny');
 
 repository('https://github.com/bestpractical/rt-extension-formtools');
 
diff --git a/html/Admin/FormTools/Modify.html b/html/Admin/FormTools/Modify.html
index 62e1311..b9c9248 100644
--- a/html/Admin/FormTools/Modify.html
+++ b/html/Admin/FormTools/Modify.html
@@ -407,8 +407,6 @@ unless ( $ok ) {
 
 my $form = $form_attribute->Content;
 
-use UUID::Tiny 'create_uuid_as_string';
-
 my @results;
 
 if ( $AddPage ) {
@@ -417,7 +415,7 @@ if ( $AddPage ) {
 
     my @orders = map { $form->{'formtools-pages'}{$_}{sort_order} } keys %{$form->{'formtools-pages'}};
 
-    my $new_page = create_uuid_as_string();
+    my $new_page = RT::Extension::FormTools->GeneratePageId($form);
     $form->{'formtools-pages'}{$new_page} = {
         name       => 'Page New',
         sort_order => ( $orders[-2] || 0 ) + 1,
@@ -518,8 +516,8 @@ my %other_components = (
 
 
 $form->{'formtools-pages'} ||= {
-    create_uuid_as_string() => { sort_order => 1, name => 'Page 1' },
-    create_uuid_as_string() => {
+    RT::Extension::FormTools->GeneratePageId() => { sort_order => 1, name => 'Page 1' },
+    RT::Extension::FormTools->GeneratePageId() => {
         sort_order => 999,
         name       => 'Result',
         content    => [
diff --git a/lib/RT/Extension/FormTools.pm b/lib/RT/Extension/FormTools.pm
index 56cfbc2..7a85f9a 100644
--- a/lib/RT/Extension/FormTools.pm
+++ b/lib/RT/Extension/FormTools.pm
@@ -8,6 +8,45 @@ our $VERSION = '0.53';
 RT->AddStyleSheets('rt-extension-formtools.css');
 RT->AddJavaScript('rt-extension-formtools.js');
 
+use Time::HiRes 'time';
+use Digest::SHA 'sha1_hex';
+
+# page ids are based on current time, keep 100 recent ids in case CPU is really fast
+my @recent_page_ids;
+
+sub GeneratePageId {
+    shift if ( $_[0] // '' ) eq __PACKAGE__;
+    my $form = shift;
+    my %current;
+    if ($form) {
+        %current = map { $_ => 1 } keys %{ $form->{'formtools-pages'} };
+    }
+
+    my %skip = (
+        map { $_ => 1 } @recent_page_ids,
+        $form && $form->{'formtools-pages'} ? keys %{ $form->{'formtools-pages'} } : ()
+    );
+
+    my $page_id = _GeneratePageId();
+
+    for ( 1 .. 100 ) {
+        if ( $skip{$page_id} ) {
+            $page_id = _GeneratePageId();
+        }
+        else {
+            push @recent_page_ids, $page_id;
+            shift @recent_page_ids while @recent_page_ids > 100;
+            return $page_id;
+        }
+    }
+    RT->Logger->error("Could not generate a new page id");
+    return;
+}
+
+sub _GeneratePageId {
+    return substr( sha1_hex( time . int rand 10000 ), 0, 8 );
+}
+
 =head1 NAME
 
 RT-Extension-FormTools - Help write multi-page ticket creation wizards

-----------------------------------------------------------------------

Summary of changes:
 META.yml                         |  1 -
 Makefile.PL                      |  1 -
 html/Admin/FormTools/Modify.html |  8 +++-----
 lib/RT/Extension/FormTools.pm    | 39 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 42 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
rt-extension-formtools


More information about the Bps-public-commit mailing list