[Bps-public-commit] App-Changeloggr branch, master, updated. 1e13922af65ee361f0bd76d93fed7ab467602292

Alex M Vandiver alexmv at bestpractical.com
Wed Apr 1 14:48:44 EDT 2009


The branch, master has been updated
       via  1e13922af65ee361f0bd76d93fed7ab467602292 (commit)
      from  6f6b7187e39596f772e82ff988ec1f14c15d5806 (commit)

Summary of changes:
 lib/App/Changeloggr/Action/CreateTag.pm |   14 ++++++++++++++
 lib/App/Changeloggr/Model/Tag.pm        |   24 ++++++++++++++++++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)

- Log -----------------------------------------------------------------
commit 1e13922af65ee361f0bd76d93fed7ab467602292
Author: Alex Vandiver <alexmv at mit.edu>
Date:   Wed Apr 1 14:47:27 2009 -0400

    Add hotkeys to tags, and the validation thereof; not linked to the js yet

diff --git a/lib/App/Changeloggr/Action/CreateTag.pm b/lib/App/Changeloggr/Action/CreateTag.pm
index d32866a..507dfdd 100644
--- a/lib/App/Changeloggr/Action/CreateTag.pm
+++ b/lib/App/Changeloggr/Action/CreateTag.pm
@@ -3,6 +3,20 @@ use strict;
 use warnings;
 use base 'App::Changeloggr::Action::Mixin::RequiresAdminToken', 'Jifty::Action::Record::Create';
 
+sub canonicalize_text {
+    my $self = shift;
+    my $tag = shift;
+
+    if (length $tag and not length($self->argument_value('hotkey')||'')) {
+        my $possible = lc substr($tag, 0, 1);
+        my $existing = App::Changeloggr::Model::TagCollection->new;
+        $existing->limit( column => 'changelog', value => $self->argument_value('changelog') );
+        $existing->limit( column => 'hotkey',    value => $possible );
+        $self->argument_value( hotkey => $possible ) unless $existing->count;
+    }
+    return $tag;
+}
+
 sub take_action {
     my $self = shift;
     $self->record->current_user(App::Changeloggr::CurrentUser->superuser);
diff --git a/lib/App/Changeloggr/Model/Tag.pm b/lib/App/Changeloggr/Model/Tag.pm
index 6867c1b..999a4c0 100644
--- a/lib/App/Changeloggr/Model/Tag.pm
+++ b/lib/App/Changeloggr/Model/Tag.pm
@@ -12,11 +12,31 @@ use App::Changeloggr::Record schema {
 
     column text =>
         type is 'text',
-        label is 'Raw',
+        label is 'Tag',
         is mandatory,
-        is immutable;
+        is immutable,
+        ajax canonicalizes;
+
+    column hotkey =>
+        type is 'text',
+        label is 'Hotkey',
+        is case_sensitive,
+        ajax validates,
+        ajax canonicalizes;
 };
 
+sub validate_hotkey {
+    my $self = shift;
+    my $key = shift;
+    my $args = shift || {};
+    return 1 if not defined $key or not length $key;
+    my $existing = App::Changeloggr::Model::TagCollection->new;
+    $existing->limit( column => 'changelog', value => $args->{changelog} || $self->changelog->id );
+    $existing->limit( column => 'hotkey',    value => $key );
+    return (0, "Duplicate key!") if $existing->first and ($existing->first->id != ($self->id||0));
+    return 1;
+}
+
 sub current_user_can {
     my $self  = shift;
     my $right = shift;

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



More information about the Bps-public-commit mailing list