Changeset 11

Show
Ignore:
Timestamp:
05/17/05 18:40:56 (3 years ago)
Author:
evdb
Message:

Changed: Added pages to the system.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/Scrpbk.pm

    r8 r11  
    2727 
    2828# If we are testing turn on debugging. 
    29 #sub debug { $yaml_config->{setting} eq 'testing' ? 1 : 0 }; 
     29sub debug { $yaml_config->{setting} eq 'testing' ? 1 : 0 }; 
    3030 
    3131sub begin : Private { 
     
    4343 
    4444    # Get user 'homepage' onto stash as 'target'. 
    45     $c->stash->{target} = Scrpbk::M::Person->retrieve( tag => 'homepage' ) 
    46       || warn "Could not load user 'homepage'"; 
     45    my $target = Scrpbk::M::Person->retrieve( tag => 'homepage' ); 
     46     
     47    if ( $target ) { 
     48        $c->stash->{target}   = $target; 
     49        ( $c->stash->{page} ) = $target->pages( url => 'home' ); 
     50    } else { 
     51        warn "Could not load user 'homepage'"; 
     52    } 
    4753} 
    4854 
     
    5258    # If there is a redirect going change the template. 
    5359    if ( $c->res->redirect ) { 
    54         $c->stash->{template} = 'redirect'; 
     60        $c->res->output("You are being redirected."); 
     61    } else { 
     62        $c->forward('Scrpbk::V::TT'); 
    5563    } 
    5664 
    57     $c->forward('Scrpbk::V::TT')
     65    return 1
    5866} 
     67 
    5968 
    6069sub load_session_from_cookie : Private { 
  • trunk/lib/Scrpbk/C/Holder.pm

    r5 r11  
    129129    return unless $c->req->param('form_submitted'); 
    130130 
     131    # Get the page to use. 
     132    my $page_id = $c->req->param('page'); 
     133    my $page = Scrpbk::M::Page->retrieve( id => $page_id, person => $person ) 
     134        || Scrpbk::M::Page->retrieve( tag => 'home', person => $person ) 
     135        || die "Could not load 'home' page for user '$person'"; 
     136     
    131137    # Get and tidy the name. 
    132138    my $name = $c->req->param('name'); 
     
    149155    # Update or create the holder. 
    150156    if ($holder) { 
    151         $holder->name($name); 
     157        $holder->name( $name ); 
     158        $holder->page( $page ); 
     159 
     160        # If the page has changed then set rank and col to low values. 
     161        if ( grep { m/page/ } $holder->is_changed ) { 
     162            $holder->rank( 0 ); 
     163            $holder->col( 1 ); 
     164        } 
     165 
    152166        $holder->update; 
    153167    } 
    154168    else { 
    155169        $holder = 
    156           Scrpbk::M::Holder->create( { person => $person, name => $name } ); 
     170          Scrpbk::M::Holder->create 
     171          ( { person => $person, name => $name, page => $page } ); 
    157172    } 
    158173    $holder->rerank_column; 
    159174 
    160175    # Send the user to the page with the holder on. 
    161     return $c->res->redirect( '/~' . $person->tag ); 
     176    return $c->res->redirect( $page->path ); 
    162177} 
    163178 
  • trunk/lib/Scrpbk/C/Person.pm

    r5 r11  
    1313    $c->stash->{fatal_error} = "You need to tell us what to do."; 
    1414    return $c->forward('/fatal_error'); 
    15 } 
    16  
    17 ################################################################################ 
    18  
    19 sub person_page : Regex('^~(\w+)$') { 
    20     my ( $self, $c ) = @_; 
    21     my $target = Scrpbk::M::Person->retrieve( tag => $c->req->snippets->[0] ); 
    22     $c->stash->{target} = $target if $target; 
    23     $c->stash->{template} = 'person/page'; 
    2415} 
    2516 
     
    179170    if ($template) { 
    180171 
     172        my %page_id_lkup   = (); 
    181173        my %holder_id_lkup = (); 
    182174 
    183         foreach my $holder ( $template->holders ) { 
    184  
    185             # Create the holder and add to the lookup table. 
    186             my $new_holder = $holder->copy( { person => $person } ); 
    187             $holder_id_lkup{ $holder->id } = $new_holder; 
    188         } 
    189  
    190         foreach my $scrap ( $template->scraps ) { 
    191  
    192             # Copy the scrap. 
    193             my %args = (); 
    194             $args{holder} = $holder_id_lkup{ $scrap->holder->id } 
    195               if $scrap->holder; 
    196  
    197             my $new_scrap = $scrap->copy( 
    198                 { 
    199                     person => $person, 
    200                     %args 
    201                 } 
    202             ); 
    203         } 
    204  
    205     } 
     175        foreach my $page ( $template->pages ) { 
     176            # Create the holder and add to the lookup table. 
     177            my $new_page = $page->copy( { person => $person } ); 
     178            $page_id_lkup{ $page->id } = $new_page; 
     179        } 
     180         
     181        foreach my $holder ( $template->holders ) { 
     182            # Create the holder and add to the lookup table. 
     183            my $new_holder = $holder->copy 
     184                ( { person => $person, 
     185                    page   => $page_id_lkup{ $holder->page->id } 
     186                } ); 
     187 
     188            $holder_id_lkup{ $holder->id } = $new_holder; 
     189        } 
     190 
     191        foreach my $scrap ( $template->scraps ) { 
     192            # Copy the scrap. 
     193            my %args = (); 
     194            $args{holder} = $holder_id_lkup{ $scrap->holder->id } 
     195            if $scrap->holder; 
     196                 
     197            my $new_scrap = $scrap->copy( { person => $person, %args } ); 
     198        } 
     199    } 
     200     
     201    # There is no template user. 
    206202    else { 
    207203        $c->log->info("You should create the template user to copy from."); 
     
    211207    $c->forward('create_session'); 
    212208    $c->res->redirect( "/~" . $person->tag ); 
     209    return 1; 
    213210} 
    214211 
  • trunk/lib/Scrpbk/M/Holder.pm

    r5 r11  
    66__PACKAGE__->table('holders'); 
    77 
    8 __PACKAGE__->columns( All => qw( id person name col rank ) ); 
     8__PACKAGE__->columns( All => qw( id page person name col rank ) ); 
    99 
    1010__PACKAGE__->has_a( person => 'Scrpbk::M::Person' ); 
     11__PACKAGE__->has_a( page => 'Scrpbk::M::Page' ); 
    1112 
    1213__PACKAGE__->has_many( scraps => 'Scrpbk::M::Scrap' ); 
     
    8889    my @holders = __PACKAGE__->search( 
    8990        person => $self->person, 
     91        page   => $self->page, 
    9092        col    => $column, 
    9193        { order_by => 'rank, id' } 
  • trunk/lib/Scrpbk/M/Person.pm

    r5 r11  
    1111 
    1212__PACKAGE__->has_many( sessions => 'Scrpbk::M::Session' ); 
     13__PACKAGE__->has_many( pages    => 'Scrpbk::M::Page' ); 
    1314__PACKAGE__->has_many( holders  => 'Scrpbk::M::Holder' ); 
    1415__PACKAGE__->has_many( scraps   => 'Scrpbk::M::Scrap' ); 
  • trunk/misc/sql/0001.sql

    r9 r11  
    1  
     1-------------------------------------------------------------------------------- 
    22-- email must be unique. 
    33CREATE UNIQUE INDEX persons_email_key ON persons(email); 
     4 
    45 
    56-------------------------------------------------------------------------------- 
     
    2122 
    2223-- get rid of bad urls. 
    23 UPDATE scraps SET url = '' where url = 'http://'; 
     24UPDATE scraps SET url = '' WHERE url = 'http://'; 
    2425 
    2526-- add the content column. 
     
    2728 
    2829-- get rid of name. 
    29 UPDATE scraps SET content = '**' || name || '**' where name != ''; 
     30UPDATE scraps SET content = '**' || name || '**' WHERE name != ''; 
    3031ALTER TABLE scraps DROP COLUMN name; 
    3132 
    3233-- get rid of note 
    33 UPDATE scraps SET content = content || ' ' || note where note != ''; 
     34UPDATE scraps SET content = content || ' ' || note WHERE note != ''; 
    3435ALTER TABLE scraps DROP COLUMN note; 
    3536 
    3637-- get rid of url. 
    37 UPDATE scraps SET content = content || ' [' || url || ']' where url != ''; 
     38UPDATE scraps SET content = content || ' [' || url || ']' WHERE url != ''; 
    3839ALTER TABLE scraps DROP COLUMN url; 
    3940 
     
    4142ALTER TABLE scraps ALTER content SET NOT NULL; 
    4243 
     44 
     45-------------------------------------------------------------------------------- 
     46-- Create pages for the users. 
     47 
     48-- create the table 
     49CREATE TABLE pages ( 
     50  id       int8    PRIMARY KEY, 
     51  person   int8    NOT NULL 
     52                   REFERENCES persons(id), 
     53  url      text    NOT NULL 
     54                   DEFAULT 'home', 
     55  name     text    NOT NULL 
     56                   DEFAULT 'Home', 
     57  rank     int8    NOT NULL 
     58                   DEFAULT 1, 
     59 
     60  CONSTRAINT pages_url_lower_and_trimmed 
     61    CHECK( url = lower(url) AND url = trim(url) ), 
     62 
     63  CONSTRAINT pages_unique_person_url 
     64    UNIQUE( person, url ), 
     65 
     66  CONSTRAINT pages_unique_person_name 
     67    UNIQUE( person, name ) 
     68); 
     69 
     70-- fill the table with defaults for all users. 
     71INSERT INTO pages ( id, person, rank ) 
     72  SELECT nextval('global_id_sequence'), id, 0 
     73  FROM persons; 
     74 
     75-- create a page column in holders 
     76ALTER TABLE holders ADD page int8 REFERENCES pages; 
     77 
     78-- fill in the page column in holders. 
     79UPDATE holders 
     80  SET page = pages.id 
     81  FROM pages 
     82  WHERE holders.person = pages.person; 
     83 
     84-- set the page column not null in holders 
     85ALTER TABLE holders ALTER page SET NOT NULL; 
     86 
     87-------------------------------------------------------------------------------- 
    4388-- set the database version. 
    4489CREATE OR REPLACE  
  • trunk/root/base/holder/column

    r2 r11  
    1 [% order_by = { 'order_by' = 'rank' } %] 
    2 [% holders = target.holders( 'col', column_number, order_by ) %] 
    3  
     1[% order_by = { 'order_by' => 'rank' } %] 
     2[% holders = page.holders( 'col', column_number, order_by ) %] 
    43 
    54[% FOREACH holder = holders %] 
    6  
     5  
    76  [%  
    87    # Set up the directions that can be used. 
  • trunk/root/base/holder/edit

    r2 r11  
    1818 
    1919    <td align="right">name:</td> 
    20     <td><input type="text" name="name" size=60 value="[% new.name || holder.name | html %]"></td> 
     20    <td align="left"><input type="text" name="name" size=60 value="[% new.name || holder.name | html %]"></td> 
    2121 
    2222  <tr></tr> 
    2323 
    24     <td>&nbsp;</td> 
    25     <td><input type="submit" value="Change Holder"></td> 
     24    <td align="right">page:</td> 
     25    <td align="left"> 
     26      <select name='page'> 
     27        [% order_by = { order_by => 'rank, name' } %] 
     28        [% page_id  = new.page || holder.page %] 
     29        [% FOREACH my_page = person.pages( order_by ) %] 
     30        <option value="[% my_page.id %]"[% ' selected' IF my_page.id == page_id %]> 
     31          [% my_page.name %] 
     32        </option> 
     33        [% END %] 
     34      </select> 
     35    </td> 
     36 
     37  <tr></tr> 
     38 
     39    <td colspan="2"><input type="submit" value="Change Holder"></td> 
    2640 
    2741  </tr> 
  • trunk/root/base/menu/goodies

    r2 r11  
     1[% WRAPPER plain_table title = 'Goodies' %] 
     2<!--<p class="instruction"><a href="/go/to/random/person">Random person</a></p>--> 
     3 
    14[% IF person %] 
    2  
    3 [% WRAPPER plain_table title = 'Goodies' %] 
    4  
    5 <div class="instruction"> 
    6  
    7 Add this link to your browser to create scraps from web pages: 
    8 <a href="javascript:location.href='http://[% c.config.http_host %]/scrap/edit/new?form_submitted=1&amp;name='+encodeURIComponent(document.title)+'&amp;url='+encodeURIComponent(location.href)">Add page to Scrpbk.com</a> 
    9  
    10 </div> 
     5<p class="instruction">Add this link to your browser to create scraps from web pages:<br> 
     6<a href="javascript:location.href='http://[% c.config.http_host %]/scrap/edit/new?form_submitted=1&amp;name='+encodeURIComponent(document.title)+'&amp;url='+encodeURIComponent(location.href)">Add page to Scrpbk.com</a></p> 
     7[% END # if person %] 
    118 
    129[% END # wrapper %] 
    1310 
    14 [% END # if person %] 
  • trunk/root/base/menu/person

    r8 r11  
    5353<form action="/holder/edit/new" name="add_holder" method="POST"> 
    5454<input type="hidden" name="form_submitted" value="1"> 
     55<input type="hidden" name="page" value="[% page.id %]"> 
    5556  <tr> 
    5657    <td align=right>name:</td> 
     
    7071[% END %] 
    7172 
     73 
     74[% WRAPPER 'plain_table' title = 'Add a page' %] 
     75 
     76<a href="/page/edit/new">Add a page</a> 
     77 
     78[% END %] 
     79 
     80 
     81 
    7282[% END %] 
    7383 
  • trunk/root/base/menu/top

    r2 r11  
    1 [% IF sys_message %] 
    2   [% WRAPPER 'plain_table' table_class = 'warning_holder' %] 
    3     [% sys_message %] 
     1[% IF target %] 
     2  [% WRAPPER 'plain_table' %] 
     3 
     4    <b>~[% target.tag %]:</b> 
     5 
     6    [% order_by = { order_by => 'name' } %] 
     7    [% FOREACH mypage = target.pages( order_by ) %] 
     8      [% '<span style="background: #ffffff;">' IF mypage.url == page.url %]      
     9      <a href="[% mypage.path %]">[% mypage.name %]</a> 
     10      [% '</span>' IF mypage.url == page.url %]  
     11      [% ' ~ ' UNLESS loop.last %] 
     12    [% END %] 
     13 
    414  [% END %] 
    515[% END %] 
    616 
    7  
    8 [% IF target %] 
    9   [% WRAPPER 'plain_table' %] 
    10     <b>~[% target.tag %]:</b> 
    11     <a href="/~[% target.tag %]">Home</a> 
    12   [% END %] 
    13 [% END %] 
    14