• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

Item5924: Make EditRowPlugin even more reusable

Item Form Data

AppliesTo: Component: Priority: CurrentState: WaitingFor: TargetRelease ReleasedIn
Extension EditRowPlugin Normal New CrawfordCurrie n/a  

Edit Form Data

Summary:
Reported By:
Codebase:
Applies To:
Component:
Priority:
Current State:
Waiting For:
Target Release:
Released In:
 

Detail

The documentation states that TWiki:Plugins/EditRowPlugin is meant to be object-oriented so that it can be easily reused and subclassed.

There is a small code change which would make that goal even easier: Allow a string to be passed into TWiki::Plugins::EditRowPlugin::Table::parseTables as parameter which indicates the Table class to be created. That way, the parseTables routine could be reused by subclasses while currently this routine has to be rewritten for subclasses just so that the proper subclass of Table is created.

-- TWiki:Main/ThomasWeigert - 14 Aug 2008

Excellent idea!

-- TWiki:Main.CrawfordCurrie - 14 Aug 2008

We would need a few small changes for EditRowPlugin to be highly reusable:

  1. Allow a tag to be passed into Table::parseTables as optional argument, so that we can use other tags to do our custom handling; if no tag is passed, then use EDITABLE
  2. Allow the erp_active_table parameter to be dependent on the type of table we are handling so that these can be intermixed on a topic
  3. Do not throw away the attributes from the EDITTABLE. Currently, only the included attributes (and attributes passed as urps are kept. But the attributes in the tag may have additional information or override the included tag).
  4. For the last option in renderForDisplay, do not hardwire EditRowPlugin as the rest handler. Let that be passed as argument also.

With these two changes, we can write our own driver and use the facilities of this plugin to parse and edit tables.

I have used this to build a frontend that edits tables in an sql data base. It would be great if we had these generic table facilities as Contrib and then many could use them...

-- ThomasWeigert - 29 Sep 2008

I think something along these lines would do. This covers only 1 + 2 above, as I have not figured out yet where 3 is actually showing up...

*** Table.pm.orig	2008-09-28 21:28:16.000000000 -0500
--- Table.pm	2008-09-29 00:04:44.000000000 -0500
***************
*** 23,29 ****
  # Returns an array of lines, with those lines that represent editable
  # tables plucked out and replaced with references to table objects
  sub parseTables {
!     my ($text, $web, $topic, $meta, $urps) = @_;
      my $active_table = undef;
      my $hasRows = 0;
      my @tables;
--- 23,29 ----
  # Returns an array of lines, with those lines that represent editable
  # tables plucked out and replaced with references to table objects
  sub parseTables {
!     my ($text, $web, $topic, $meta, $urps, $tag, $prefix) = @_;
      my $active_table = undef;
      my $hasRows = 0;
      my @tables;
***************
*** 31,36 ****
--- 31,37 ----
      my $disable = 0;
      my $openRow = undef;
      my @comments;
+     $tag ||= 'EDITTABLE';
  
      $text =~ s/()/
        push(@comments, $1); "\001-".scalar(@comments)."-\001"/seg;
***************
*** 59,65 ****
  
          # Process an EDITTABLE. The tag will be associated with the
          # next table encountered in the topic.
!         if (!$disable && $line =~ s/(%EDITTABLE{(.*)}%)// ) {
              my $spec = $1;
              my $attrs = new TWiki::Attrs(
                  TWiki::Func::expandCommonVariables($2, $web, $topic));
--- 60,66 ----
  
          # Process an EDITTABLE. The tag will be associated with the
          # next table encountered in the topic.
!         if (!$disable && $line =~ s/(%${tag}{(.*)}%)// ) {
              my $spec = $1;
              my $attrs = new TWiki::Attrs(
                  TWiki::Func::expandCommonVariables($2, $web, $topic));
***************
*** 113,119 ****
              }
              $active_table =
                new TWiki::Plugins::EditRowPlugin::Table(
!                   $nTables, 1, $spec, $attrs, $web, $topic);
              push(@tables, $active_table);
              $hasRows = 0;
              next;
--- 114,120 ----
              }
              $active_table =
                new TWiki::Plugins::EditRowPlugin::Table(
!                   $nTables, 1, $spec, $attrs, $web, $topic, $prefix);
              push(@tables, $active_table);
              $hasRows = 0;
              next;
***************
*** 135,141 ****
                  my $attrs => new TWiki::Attrs('');
                  $active_table =
                    new TWiki::Plugins::EditRowPlugin::Table(
!                       $nTables, 0, $line, $attrs, $web, $topic);
                  push(@tables, $active_table);
              }
              # Note use of LIMIT=-1 on the split so we don't lose empty columns
--- 136,142 ----
                  my $attrs => new TWiki::Attrs('');
                  $active_table =
                    new TWiki::Plugins::EditRowPlugin::Table(
!                       $nTables, 0, $line, $attrs, $web, $topic, $prefix);
                  push(@tables, $active_table);
              }
              # Note use of LIMIT=-1 on the split so we don't lose empty columns
***************
*** 192,202 ****
  }
  
  sub new {
!     my ($class, $tno, $editable, $spec, $attrs, $web, $topic) = @_;
  
      my $this = bless({}, $class);
      $this->{editable} = $editable;
!     $this->{number} = $tno;
      $this->{spec} = $spec;
      $this->{rows} = [];
      $this->{topic} = $topic;
--- 193,203 ----
  }
  
  sub new {
!     my ($class, $tno, $editable, $spec, $attrs, $web, $topic, $prefix) = @_;
  
      my $this = bless({}, $class);
      $this->{editable} = $editable;
!     $this->{number} = $prefix.$tno;
      $this->{spec} = $spec;
      $this->{rows} = [];
      $this->{topic} = $topic;


ItemTemplate
Summary Make EditRowPlugin even more reusable
ReportedBy TWiki:Main.ThomasWeigert
Codebase 4.2.0, 4.2.1
SVN Range TWiki-5.0.0, Mon, 11 Aug 2008, build 17408
AppliesTo Extension
Component EditRowPlugin
Priority Normal
CurrentState New
WaitingFor CrawfordCurrie
Checkins

TargetRelease n/a
ReleasedIn

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r6 - 2008-09-29 - ThomasWeigert
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback