Item5924: Make EditRowPlugin even more reusable

pencil
Priority: Enhancement
Current State: Closed
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: EditRowPlugin
Branches:
Reported By: TWiki:Main.ThomasWeigert
Waiting For: CrawfordCurrie
Last Change By: CrawfordCurrie
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/()// ) {

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;

I incorporated (1) and (2) as per the patch above (after fixing all the knock-on effects) but am leaving this open for the other two.

-- CrawfordCurrie - 15 Feb 2009

Not going to do any more on this, unless a fresh request is raised.

-- CrawfordCurrie - 14 Feb 2011

ItemTemplate edit

Summary Make EditRowPlugin even more reusable
ReportedBy TWiki:Main.ThomasWeigert
Codebase
SVN Range TWiki-5.0.0, Mon, 11 Aug 2008, build 17408
AppliesTo Extension
Component EditRowPlugin
Priority Enhancement
CurrentState Closed
WaitingFor CrawfordCurrie
Checkins distro:41d7ba5141e0
TargetRelease n/a
ReleasedIn n/a
Topic revision: r10 - 14 Feb 2011, CrawfordCurrie - This page was cached on 10 Dec 2016 - 02:17.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License