[Bps-public-commit] rt-extension-formtools branch form-home-icon-upload updated. 0.53-28-gcbb7497

BPS Git Server git at git.bestpractical.com
Wed Oct 4 19:56:10 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, form-home-icon-upload has been updated
       via  cbb749780a94853dadc73c17aa9510910fc9f69e (commit)
       via  53a54ad4e8312d6e5d4de7ed4618f9744db2f9d6 (commit)
      from  366ff53873c5a90d1617b802ed0d52c80915f2b6 (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 cbb749780a94853dadc73c17aa9510910fc9f69e
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Oct 4 15:55:50 2023 -0400

    Add icon upload and display for forms

diff --git a/html/Admin/FormTools/Describe.html b/html/Admin/FormTools/Describe.html
index a29ae35..a4a1635 100644
--- a/html/Admin/FormTools/Describe.html
+++ b/html/Admin/FormTools/Describe.html
@@ -2,16 +2,28 @@
 <& /Elements/Tabs &>
 <& /Elements/ListActions, actions => \@results &>
 
-<&| /Widgets/TitleBox, title => '' &>
+<&| /Widgets/TitleBox, title => '', class => 'formtools-admin-description ml-auto mr-auto' &>
   <p>Forms are shown to users on a page in the RT Self Service interface. Below you can manage how the form details will appear to end users.</p>
   <form name="EditFormDescription" action="<%RT->Config->Get('WebPath')%>/Admin/FormTools/Describe.html" method="post" enctype="multipart/form-data">
   <input type="hidden" class="hidden" name="id" value="<% $id %>" />
   <&| /Widgets/TitleBox, title => loc('Icon') &>
-    <p>Form to upload an icon</p>
+% if ( $current_form_icon ) {
+<& /Elements/Forms/ShowFormIcon, FormID => $id &>
+% } else {
+      <p>Upload an icon to be shown to users on the Forms page or select a color for the background of graphical box users can click.</p>
+% }
+
+      <div class="row">
+        <div class="col ml-5 mr-5">
+          <div class="custom-file">
+            <input type="file" name="FormUploadIcon" class="custom-file-input" id="formtools-upload-icon" />
+            <label class="custom-file-label" for="formtools-upload-icon"><&|/l&>Upload an icon for this form</&></label>
+          </div>
+        </div>
+      </div>
   </&>
   <&| /Widgets/TitleBox, title => loc('Description') &>
     <p>Describe what the form should be used for and include instructions to help users pick the correct form.</p>
-    <p>An HTML edit box for instructions</p>
       <div class="form-row">
         <div class="col-12">
           <input type="hidden" class="hidden" name="FormDescriptionType" value="text/html" />
@@ -27,6 +39,7 @@
 </div>
 </form>
 <%init>
+use Digest::MD5 'md5_hex';
 
 # Handle id getting submitted twice and becoming an array
 my @id = ( ref $id eq 'ARRAY' ) ? @{$id} : ($id);
@@ -61,6 +74,35 @@ if ( $ARGS{'SubmitDescription'} ) {
     }
 }
 
+my ($current_form_icon) = RT::Extension::FormTools::LoadFormIcon( $session{'CurrentUser'}, $form_attribute->Id );
+
+if ( my $file_hash = _UploadedFile( 'FormUploadIcon' ) ) {
+
+    my ($form_icon, $msg) = RT::Extension::FormTools::LoadFormIcon( $session{'CurrentUser'}, $form_attribute->Id );
+
+    if ( $form_icon ) {
+        # Delete the existing icon
+        my ( $del_ok, $del_msg ) = $form_icon->Delete;
+
+        RT->Logger->error("Unable to delete icon attribute id $ok, $del_msg") unless $del_ok;
+    }
+
+    my $new_form_icon = RT::Attribute->new( $session{CurrentUser} );
+    ( $ok, $msg ) = $new_form_icon->Create(
+        Name        => "FormTools Icon",
+        Description => "Icon for " . $form_attribute->Description,
+        Object      => $form_attribute,
+        Content     => {
+            type => $file_hash->{ContentType},
+            data => $file_hash->{LargeContent},
+            hash => md5_hex($file_hash->{LargeContent}),
+        },
+    );
+
+    push @results, loc("Unable to set form icon") unless $ok;
+    RT->Logger->error("Unable to set form icon: $msg") unless $ok;
+}
+
 MaybeRedirectForResults(
     Actions   => \@results,
     Arguments => { id => $id, FormDescription => $ARGS{'FormDescription'} },
diff --git a/html/Elements/Forms/ListForms b/html/Elements/Forms/ListForms
index 17bed2f..f14f482 100644
--- a/html/Elements/Forms/ListForms
+++ b/html/Elements/Forms/ListForms
@@ -6,7 +6,7 @@
 <div class="row mt-3 mb-3">
   <div class="col-4">
     <a href="<% RT->Config->Get('WebPath') %>/SelfService/Forms/<% $form_attribute->Description %>">
-      <% $m->scomp('/Elements/Forms/ShowFormGraphic', FormName => $form_attribute->Description, ItemNumber => $item_number) |n %>
+      <% $m->scomp('/Elements/Forms/ShowFormGraphic', FormObj => $form_attribute, ItemNumber => $item_number) |n %>
     </a>
   </div>
   <div class="col">
diff --git a/html/Elements/Forms/ShowFormGraphic b/html/Elements/Forms/ShowFormGraphic
index 2cc953e..fd14ab8 100644
--- a/html/Elements/Forms/ShowFormGraphic
+++ b/html/Elements/Forms/ShowFormGraphic
@@ -1,12 +1,21 @@
 <div class="formtools-form-graphic w-50 mt-2 mb-2 ml-auto mr-auto">
+% if ( $has_icon ) {
+<& /Elements/Forms/ShowFormIcon, FormID => $FormObj->Id &>
+% } else {
   <div class="rounded pt-5 pb-5" style="background-color: <%$color%>;">
     <p class="text-center formtools-form-graphic">
-      <% $FormName %>
+      <% $FormObj->Description %>
     </p>
   </div>
+% }
 </div>
 <%init>
 
+unless ( $FormObj and $FormObj->Id ) {
+    RT->Logger->error("No valid form attribute object passed");
+    return;
+}
+
 my $color_list = [
     "#1f77b4", "#ff7f0e", "#2ca02c", "#d62728",
     "#9467bd", "#8c564b", "#e377c2", "#7f7f7f"
@@ -14,8 +23,16 @@ my $color_list = [
 
 my $color = $color_list->[ $ItemNumber % 8 ];
 
+my $has_icon = 0;
+my $form_icon = RT::Attribute->new( RT->SystemUser );
+my ($ok, $msg) = $form_icon->LoadByCols( ObjectType => 'RT::Attribute', ObjectId => $FormObj->Id );
+
+if ( $ok and $form_icon->Id ) {
+    $has_icon = 1;
+}
+
 </%init>
 <%args>
-$FormName => "Form"
+$FormObj
 $ItemNumber => 1
 </%args>
diff --git a/html/Elements/Forms/ShowFormIcon b/html/Elements/Forms/ShowFormIcon
new file mode 100644
index 0000000..cdbc216
--- /dev/null
+++ b/html/Elements/Forms/ShowFormIcon
@@ -0,0 +1,28 @@
+<div id="formtools-icon-<% $FormID %>" class="">
+% if ($form_icon) {
+<img
+    class="d-block mx-auto",
+    width="100px", height="100px",
+    src="<% RT->Config->Get('WebPath') %>/NoAuth/Helpers/FormLogo/<% $form_icon->Id %>"
+    alt="<%$ARGS{'LogoAltText'}%>" />
+% }
+</div>
+<%init>
+
+my ($form_icon, $msg) = RT::Extension::FormTools::LoadFormIcon( $session{'CurrentUser'}, $FormID );
+
+if ( $form_icon ) {
+    my $content = $form_icon->Content;
+    undef $form_icon
+        unless ref $content eq 'HASH'
+           and defined $content->{'data'};
+}
+else {
+    RT->Logger->error("Unable to load logo for form id $FormID");
+}
+
+</%init>
+<%args>
+$LogoAltText => ''
+$FormID => undef
+</%args>
diff --git a/html/NoAuth/Helpers/FormLogo/dhandler b/html/NoAuth/Helpers/FormLogo/dhandler
new file mode 100644
index 0000000..f2c33e3
--- /dev/null
+++ b/html/NoAuth/Helpers/FormLogo/dhandler
@@ -0,0 +1,17 @@
+<%init>
+my $icon_id = $m->dhandler_arg;
+
+my $form_icon = RT::Attribute->new( RT->SystemUser );
+my ($ok, $msg) = $form_icon->Load($icon_id);
+
+if ( $ok ) {
+    RT::Interface::Web::StaticFileHeaders();
+    my $content = $form_icon->Content;
+    $r->content_type( $content->{type} );
+    $m->out( $content->{data} );
+}
+else {
+    # 404
+    return $m->decline;
+}
+</%init>
diff --git a/lib/RT/Extension/FormTools.pm b/lib/RT/Extension/FormTools.pm
index c1dbd38..56cfbc2 100644
--- a/lib/RT/Extension/FormTools.pm
+++ b/lib/RT/Extension/FormTools.pm
@@ -213,6 +213,33 @@ sub has_value {
     return (0, "You must provide a value for this field");
 }
 
+=head2 LoadFormIcon($current_user, $form_id)
+
+Loads the form icon attribute associated with the passed form id.
+
+Returns a tuple of attribute object or false, and a message.
+
+=cut
+
+sub LoadFormIcon {
+    my $current_user = shift;
+    my $form_id = shift;
+
+    my $form_icon = RT::Attribute->new( $current_user );
+    my ( $ok, $msg ) = $form_icon->LoadByCols(
+        Name => 'FormTools Icon',
+        ObjectType => 'RT::Attribute',
+        ObjectId => $form_id );
+
+    if ( $ok ) {
+        return ( $form_icon, $msg );
+    }
+    else {
+        RT->Logger->error("Unable to load icon: $msg");
+        return ( 0, $msg );
+    }
+}
+
 =head1 AUTHOR
 
 Best Practical Solutions, LLC E<lt>modules at bestpractical.comE<gt>
diff --git a/static/css/rt-extension-formtools.css b/static/css/rt-extension-formtools.css
index 1108657..50224f5 100644
--- a/static/css/rt-extension-formtools.css
+++ b/static/css/rt-extension-formtools.css
@@ -11,3 +11,7 @@ p.formtools-form-graphic {
 div .formtools-form-list {
     max-width: 1000px;
 }
+
+div .formtools-admin-description {
+    max-width: 1000px;
+}

commit 53a54ad4e8312d6e5d4de7ed4618f9744db2f9d6
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Oct 2 16:49:13 2023 -0400

    Improve spacing and layout for Forms page

diff --git a/html/Elements/Forms/ListForms b/html/Elements/Forms/ListForms
index 73185f1..17bed2f 100644
--- a/html/Elements/Forms/ListForms
+++ b/html/Elements/Forms/ListForms
@@ -1,16 +1,18 @@
-<&|/Widgets/TitleBox, title => '', class => 'fullwidth' &>
+<&|/Widgets/TitleBox, title => '', class => 'fullwidth formtools-form-list ml-auto mr-auto' &>
 <div class="container">
 % my $item_number = 1;
 % while ( my $form_attribute = $forms->Next ) {
 %    my $form = $form_attribute->Content;
-<div class="row border border-primary">
+<div class="row mt-3 mb-3">
   <div class="col-4">
     <a href="<% RT->Config->Get('WebPath') %>/SelfService/Forms/<% $form_attribute->Description %>">
       <% $m->scomp('/Elements/Forms/ShowFormGraphic', FormName => $form_attribute->Description, ItemNumber => $item_number) |n %>
     </a>
   </div>
   <div class="col">
-    <% $form->{'form-description'} |n %>
+    <div class="formtools-form-text w-100 mt-2 mb-2 mr-auto ml-auto">
+      <% $form->{'form-description'} |n %>
+    </div>
   </div>
 </div>
 % $item_number++;
diff --git a/html/Elements/Forms/ShowFormGraphic b/html/Elements/Forms/ShowFormGraphic
index 37679ea..2cc953e 100644
--- a/html/Elements/Forms/ShowFormGraphic
+++ b/html/Elements/Forms/ShowFormGraphic
@@ -1,6 +1,6 @@
-<div class="formtools-form-graphic w-50 mt-2 mb-2">
+<div class="formtools-form-graphic w-50 mt-2 mb-2 ml-auto mr-auto">
   <div class="rounded pt-5 pb-5" style="background-color: <%$color%>;">
-    <p class="text-center" style="font-color: white; font-weight: bold; font-size: 2rem;">
+    <p class="text-center formtools-form-graphic">
       <% $FormName %>
     </p>
   </div>
diff --git a/static/css/rt-extension-formtools.css b/static/css/rt-extension-formtools.css
index ad60315..1108657 100644
--- a/static/css/rt-extension-formtools.css
+++ b/static/css/rt-extension-formtools.css
@@ -2,3 +2,12 @@
 div .formtools-content {
     min-height: 400px;
 }
+
+p.formtools-form-graphic {
+    font-weight: bold;
+    font-size: 1.5rem;
+}
+
+div .formtools-form-list {
+    max-width: 1000px;
+}

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

Summary of changes:
 html/Admin/FormTools/Describe.html    | 48 ++++++++++++++++++++++++++++++++---
 html/Elements/Forms/ListForms         | 10 +++++---
 html/Elements/Forms/ShowFormGraphic   | 25 +++++++++++++++---
 html/Elements/Forms/ShowFormIcon      | 28 ++++++++++++++++++++
 html/NoAuth/Helpers/FormLogo/dhandler | 17 +++++++++++++
 lib/RT/Extension/FormTools.pm         | 27 ++++++++++++++++++++
 static/css/rt-extension-formtools.css | 13 ++++++++++
 7 files changed, 157 insertions(+), 11 deletions(-)
 create mode 100644 html/Elements/Forms/ShowFormIcon
 create mode 100644 html/NoAuth/Helpers/FormLogo/dhandler


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


More information about the Bps-public-commit mailing list