[mb-commits] branch, nes-edit-view, created. Basic support for viewing the edit history of an entity

MusicBrainz Git Server <[email protected]> Mon, 28 Jan 2013 15:26:21 +0000
Newsgroups gmane.comp.audio.musicbrainz.cvs
Message-ID <E1TzqbF-0005Ym-4M@wiley>
The branch, nes-edit-view has been created
        at  9a41a92cb3d783140f5e0ef3b00cce0753779a44 (commit)

- Log -----------------------------------------------------------------
commit 9a41a92cb3d783140f5e0ef3b00cce0753779a44
Author: Oliver Charles <[email protected]>
Date:   Mon Jan 28 15:26:02 2013 +0000

    Basic support for viewing the edit history of an entity

diff --git a/lib/MusicBrainz/Server/Controller/Role/EditListing.pm b/lib/MusicBrainz/Server/Controller/Role/EditListing.pm
index 1c81e62..6bc4be9 100644
--- a/lib/MusicBrainz/Server/Controller/Role/EditListing.pm
+++ b/lib/MusicBrainz/Server/Controller/Role/EditListing.pm
@@ -13,18 +13,18 @@ sub edits : Chained('load') PathPart RequireAuth
         my ($type, $entity) = @_;
         return sub {
             my ($offset, $limit) = @_;
-            $c->model('Edit')->find({ $type => $entity->id }, $offset, $limit);
+            return $c->model('NES::Edit')->find_for_work($entity)
         }
     });
-    $c->stash( 
-        refine_url_args => 
-            { auto_edit_filter => '', order=> 'desc', negation=> 0, 
-              combinator=>'and', 
-              'conditions.0.field' => model_to_type( $self->{model} ), 
-              'conditions.0.operator' => '=', 
-              'conditions.0.name' => $c->stash->{ $self->{entity_name} }->name, 
-              'conditions.0.args.0' => $c->stash->{ $self->{entity_name} }->id, 
-              'conditions.0.user_id' => $c->user->id },
+    $c->stash(
+        # refine_url_args =>
+        #     { auto_edit_filter => '', order=> 'desc', negation=> 0,
+        #       combinator=>'and',
+        #       'conditions.0.field' => model_to_type( $self->{model} ),
+        #       'conditions.0.operator' => '=',
+        #       'conditions.0.name' => $c->stash->{ $self->{entity_name} }->name,
+        #       'conditions.0.args.0' => $c->stash->{ $self->{entity_name} }->id,
+        #       'conditions.0.user_id' => $c->user->id },
     );
 }
 
@@ -59,13 +59,14 @@ sub _list {
     my ($self, $c, $find) = @_;
 
     my $type   = model_to_type( $self->{model} );
-    my $entity = $c->stash->{ $self->{entity_name} };
-    my $edits  = $self->_load_paged($c, $find->($type, $entity));
+    my $entity = $c->stash->{entity};
+    # my $edits  = $self->_load_paged($c, $find->($type, $entity));
+    my $edits = [ $find->($type, $entity)->(0, 50) ];
 
-    $c->model('Edit')->load_all(@$edits);
-    $c->model('Vote')->load_for_edits(@$edits);
-    $c->model('EditNote')->load_for_edits(@$edits);
-    $c->model('Editor')->load(map { ($_, @{ $_->votes, $_->edit_notes }) } @$edits);
+    # $c->model('Edit')->load_all(@$edits);
+    # $c->model('Vote')->load_for_edits(@$edits);
+    # $c->model('EditNote')->load_for_edits(@$edits);
+    # $c->model('Editor')->load(map { ($_, @{ $_->votes, $_->edit_notes }) } @$edits);
 
     $c->stash(
         edits => $edits,
diff --git a/lib/MusicBrainz/Server/Data/NES/Edit.pm b/lib/MusicBrainz/Server/Data/NES/Edit.pm
index c7b1996..0a18867 100644
--- a/lib/MusicBrainz/Server/Data/NES/Edit.pm
+++ b/lib/MusicBrainz/Server/Data/NES/Edit.pm
@@ -1,16 +1,44 @@
 package MusicBrainz::Server::Data::NES::Edit;
 use Moose;
 
-use MusicBrainz::Server::Entity::NES::Edit;
+use MusicBrainz::Server::Entity::Edit;
+
+use Try::Tiny;
 
 with 'MusicBrainz::Server::Data::Role::NES';
 
 sub open {
     my $self = shift;
-    return MusicBrainz::Server::Entity::NES::Edit->new(
+    return MusicBrainz::Server::Entity::Edit->new(
         id => $self->request('/edit/open', {})->{ref}
     );
 }
 
+sub find_for_work {
+    my ($self, $work) = @_;
+
+    my @edit_ids = @{
+        $self->request('/edit/find-edits-involving-all', {
+            works => [ { mbid => $work->gid } ]
+        })
+    };
+
+    my @edits;
+    for my $id (@edit_ids) {
+        try {
+            my $edit = MusicBrainz::Server::Entity::Edit->new(
+                id => $id,
+                html => $self->request('/edit/view-changes', {
+                    edit => $id
+                })->{html}
+            );
+
+            push @edits, $edit;
+        };
+    }
+
+    return @edits;
+}
+
 __PACKAGE__->meta->make_immutable;
 1;
diff --git a/root/edit/edit_header.tt b/root/edit/edit_header.tt
index 85bc25d..14bbe0e 100644
--- a/root/edit/edit_header.tt
+++ b/root/edit/edit_header.tt
@@ -72,7 +72,7 @@
             </table>
         </div>
         <h2>
-            [%- link_edit(edit, show, html_escape(l('Edit #{id} - {name}', { id => edit.id, name => edit.l_edit_name}))) -%]
+            [%- link_edit(edit, show, html_escape(l('Edit #{id}', { id => edit.id }))) -%]
         </h2>
     [% ELSE %]
         [% IF edit.can_approve(c.user) || edit.can_cancel(c.user) %]
diff --git a/root/edit/list.tt b/root/edit/list.tt
index 3f6e1e6..80e07b0 100644
--- a/root/edit/list.tt
+++ b/root/edit/list.tt
@@ -75,17 +75,10 @@
                     <div class="edit-actions c[%- PROCESS edit_status -%]">
                         [%- INCLUDE 'edit/info.tt' summary=1 -%]
                     </div>
+                    [% edit.html %]
 
-                    <div class="edit-details">
-                        [% IF edit.data.defined %]
-                           [%-INCLUDE "edit/details/${edit.edit_template}.tt" %]
-                        [% ELSE %]
-                           <p>[% l('An error occured while loading this edit') %]</p>
-                        [% END %]
-                    </div>
-                    
                     [% INCLUDE 'edit/notes.tt' verbose='not-verbose' hide=1 rows=1 index=loop.index %]
-    
+
                     <div class="seperator">
                     </div>
                 </div>

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


hooks/post-receive
-- 
mb_server