Author: acid2
Date: 2008-07-24 20:35:52 +0000 (Thu, 24 Jul 2008)
New Revision: 10156
Added:
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Facade/
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Facade/Alias.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Facade/Artist.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Facade/Link.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Facade/Release.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Alias.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Artist.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Relation.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Release.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Tag.pm
mb_server/branches/TemplateToolkit/root/components/grouped.tt
Modified:
mb_server/branches/TemplateToolkit/Makefile.PL
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Adapter.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Adapter/Relations.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Artist.pm
mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Release.pm
mb_server/branches/TemplateToolkit/root/artist/appearances.tt
mb_server/branches/TemplateToolkit/root/artist/compact.tt
mb_server/branches/TemplateToolkit/root/artist/details.tt
mb_server/branches/TemplateToolkit/root/artist/header.tt
mb_server/branches/TemplateToolkit/root/artist/landing.tt
mb_server/branches/TemplateToolkit/root/components/entity-link.tt
Log:
Beginning the move to facades... lots of changes here, many of which are not fully decided yet
Modified: mb_server/branches/TemplateToolkit/Makefile.PL
===================================================================
--- mb_server/branches/TemplateToolkit/Makefile.PL 2008-07-23 15:56:55 UTC (rev 10155)
+++ mb_server/branches/TemplateToolkit/Makefile.PL 2008-07-24 20:35:52 UTC (rev 10156)
@@ -10,6 +10,7 @@
requires 'Apache::Session::File';
requires 'Cache::Memcached';
requires 'Catalyst::Action::RenderView';
+requires 'Catalyst::Model::Adaptor';
requires 'Catalyst::Plugin::Authentication';
requires 'Catalyst::Plugin::ConfigLoader';
requires 'Catalyst::Plugin::FormBuilder';
Modified: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Adapter/Relations.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Adapter/Relations.pm 2008-07-23 15:56:55 UTC (rev 10155)
+++ mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Adapter/Relations.pm 2008-07-24 20:35:52 UTC (rev 10156)
@@ -37,56 +37,9 @@
sub LoadRelations
{
my ($entity, $type, %opts) = @_;
-
- my $link = MusicBrainz::Server::Link->new($entity->{DBH});
- my @links = $link->FindLinkedEntities($entity->GetId, $type, %opts);
-
- NormaliseLinkDirections(\@links, $entity->GetId, $type);
- @links = SortLinks(\@links);
-
- return ExportLinks(\@links, $entity);
+ die "Don't call this!"
}
-=head2 NormaliseLinkDirections \@links, $id, $type
-
-Takes an array ref of L<MusicBrainz::Server::Link>s (C<\@links>) and
-re-arranges them such that link0 is always the same entity (the entity
-with the same id as C<$id>). $type should be either 'artist', 'album',
-'label' or 'track'.
-
-=cut
-
-sub NormaliseLinkDirections
-{
- my ($arLinks, $id, $type) = @_;
-
- foreach my $link (@$arLinks)
- {
- if($link->{link0_id} != $id || $link->{link0_type} ne $type)
- {
- @$link{qw(
- link0_type link1_type
- link0_id link1_id
- link0_name link1_name
- link0_sortname link1_sortname
- link0_resolution link1_resolution
- link0_mbid link1_mbid
- link_phrase rlink_phrase
- )} = @$link{qw(
- link1_type link0_type
- link1_id link0_id
- link1_name link0_name
- link1_sortname link0_sortname
- link1_resolution link0_resolution
- link1_mbid link0_mbid
- rlink_phrase link_phrase
- )};
- }
- }
-
- return $arLinks;
-}
-
=head2 SortLinks \@links
Sort a list of L<MusicBrainz::Server::Link>s (given by the array reference
@@ -99,25 +52,6 @@
{
my $links = shift;
- sort
- {
- my $c = $a->{link_phrase} cmp $b->{link_phrase};
- return $c if ($c);
-
- if (defined $a->{enddate} || defined $b->{enddate})
- {
- $c = $a->{enddate} cmp $b->{enddate};
- return $c if ($c);
- }
-
- if (defined $a->{begindate} || $b->{begindate})
- {
- $c = $a->{begindate} cmp $b->{begindate};
- return $c if ($c);
- }
-
- return $a->{link1_name} cmp $b->{link1_name};
- } @$links;
}
=head2 ExportLink $link, [$index]
@@ -224,44 +158,7 @@
sub ExportLinks
{
my ($links, $entity) = @_;
-
- sub require_new_group
- {
- my ($current_group, $relation) = @_;
-
- if (not defined $current_group or
- $current_group->{connector} ne $relation->{link_phrase} or
- $current_group->{start_date} ne $relation->{begindate} or
- $current_group->{end_date} ne $relation->{enddate})
- {
- return 1;
- }
- else
- {
- return 0;
- }
- };
- my @stashData;
- my $currentGroup = undef;
- for my $link (@$links)
- {
- if (require_new_group($currentGroup, $link))
- {
- $currentGroup = {
- connector => $link->{link_phrase},
- type => $link->{link_type},
- start_date => $link->{begindate},
- end_date => $link->{enddate},
- entities => [],
- };
- push @stashData, $currentGroup;
- }
-
- push @{$currentGroup->{entities}}, ExportLink($link, "link1", $entity);
- }
-
- return \@stashData;
}
=head1 LICENSE
Modified: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Adapter.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Adapter.pm 2008-07-23 15:56:55 UTC (rev 10155)
+++ mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Adapter.pm 2008-07-24 20:35:52 UTC (rev 10156)
@@ -104,12 +104,13 @@
my ($c, $entity, $action, $query_params) = @_;
my $url = '';
+ my $type = $entity->entity_type;
- my $controller = $c->controller($entity->{link_type})
- or die "Not a valid type";
+ my $controller = $c->controller($type)
+ or die "$type is not a valid type";
my $catalyst_action = $controller->action_for($action)
- or die "$action is not a valid action (for $entity->{link_type})";
+ or die "$action is not a valid action for the controller $type";
$query_params ||= {};
Modified: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Artist.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Artist.pm 2008-07-23 15:56:55 UTC (rev 10155)
+++ mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Controller/Artist.pm 2008-07-24 20:35:52 UTC (rev 10156)
@@ -36,6 +36,10 @@
=head1 METHODS
+=head2 READ ONLY PAGES
+
+The follow pages can are all read only
+
=head2 artist
Private chained action for loading enough information on the artist header
@@ -48,17 +52,12 @@
if (defined $mbid)
{
- my $mb = $c->mb;
+ my $artist = $c->model('Artist')->load($mbid);
- my $artist = MusicBrainz::Server::Artist->new($mb->{DBH});
- LoadEntity($artist, $mbid);
-
croak "You cannot view the special DELETED_ARTIST"
- if ($artist->GetId == ModDefs::DARTIST_ID);
+ if ($artist->id == ModDefs::DARTIST_ID);
- $c->stash->{_artist} = $artist;
- $c->stash->{artist} = $artist->ExportStash qw( name mbid type date
- quality resolution );
+ $c->stash->{artist} = $artist;
}
else
{
@@ -76,27 +75,10 @@
sub similar : Chained('artist')
{
my ($self, $c) = @_;
-
- my $artist = $c->stash->{_artist};
+ my $artist = $c->stash->{artist};
- my $similar_artists = $artist->GetRelations();
-
- $c->stash->{similar_artists} = [];
- for my $similar_artist (@$similar_artists)
- {
- my $weight = $similar_artist->{weight};
- my $id = $similar_artist->{id};
- my $name = $similar_artist->{name};
-
- push @{ $c->stash->{similar_artists} }, {
- link_type => 'artist',
- mbid => $id,
- name => $name,
- weight => $weight,
- };
- }
-
- $c->stash->{template} = 'artist/similar.tt';
+ $c->stash->{similar_artists} = $c->model('Artist')->find_similar_artists($artist);
+ $c->stash->{template} = 'artist/similar.tt';
}
=head2 google
@@ -108,10 +90,9 @@
sub google : Chained('artist')
{
my ($self, $c) = @_;
+ my $artist = $c->stash->{artist};
- my $artist = $c->stash->{_artist};
-
- $c->response->redirect(Google($artist->GetName));
+ $c->response->redirect(Google($artist->name));
}
=head2 tags
@@ -123,13 +104,9 @@
sub tags : Chained('artist')
{
my ($self, $c) = @_;
- my $artist = $c->stash->{_artist};
+ my $artist = $c->stash->{artist};
- my $t = MusicBrainz::Server::Tag->new($c->mb->{DBH});
- my $tags = $t->GetTagHashForEntity('artist', $artist->GetId, 200);
-
- $c->stash->{tagcloud} = PrepareForTagCloud($tags);
-
+ $c->stash->{tagcloud} = $c->model('Tag')->generate_tag_cloud($artist);
$c->stash->{template} = 'artist/tags.tt';
}
@@ -142,93 +119,12 @@
sub relations : Chained('artist')
{
my ($self, $c, $mbid) = @_;
- my $artist = $c->stash->{_artist};
+ my $artist = $c->stash->{artist};
- $c->stash->{relations} = load_relations($artist);
-
- $c->stash->{template} = 'artist/relations.tt';
+ $c->stash->{relations} = $c->model('Relation')->load_relations($artist);
+ $c->stash->{template} = 'artist/relations.tt';
}
-=head2 create
-
-When given a GET request this displays a form allowing the user to enter
-data, creating a new artist. If a POST request is received, the data
-is validated and if validation succeeds, the artist is entered into the
-MusicBrainz database.
-
-The heavy work validating the form and entering data into the database
-is done via L<MusicBrainz::Server::Form::Artist;
-
-=cut
-
-sub create : Local
-{
- my ($self, $c) = @_;
-
- use MusicBrainz::Server::Form::Artist;
-
- my $form = new MusicBrainz::Server::Form::Artist;
- $form->context($c);
-
- $c->stash->{form} = $form;
-
- if ($c->form_posted)
- {
- if (my $mods = $form->update_from_form($c->req->params))
- {
- $c->flash->{ok} = "Thanks! The artist has been added to the " .
- "database, and we have redirected you to " .
- "their landing page";
-
- # Make sure that the moderation did go through, and redirect to
- # the new artist
- my $addmod = grep { $_->Type eq ModDefs::MOD_ADD_ARTIST } @$mods;
-
- $c->detach('/artist/show', $addmod->GetRowId)
- if $addmod;
- }
- }
-
- $c->stash->{template} = 'artist/create.tt';
-}
-
-=head2 edit
-
-Allows users to edit the data about this artist.
-
-When viewed with a GET request, the user is displayed a form filled with
-the current artist data. When a POST request is received, the data is
-validated and if it passed validation is the updated data is entered
-into the MusicBrainz database.
-
-=cut
-
-sub edit : Chained('artist')
-{
- my ($self, $c, $mbid) = @_;
- my $artist = $c->stash->{_artist};
-
- use MusicBrainz::Server::Form::Artist;
-
- my $form = new MusicBrainz::Server::Form::Artist($artist->GetId);
- $form->context($c);
-
- $c->stash->{form} = $form;
-
- if ($c->form_posted)
- {
- if ($form->update_from_form($c->req->params))
- {
- $c->flash->{ok} = "Thanks, your artist edit has been entered " .
- "into the moderation queue";
-
- $c->detach('/artist/show', $mbid);
- }
- }
-
- $c->stash->{template} = 'artist/edit.tt';
-}
-
=head2 appearances
Display a list of releases that an artist appears on via advanced
@@ -239,79 +135,10 @@
sub appearances : Chained('artist')
{
my ($self, $c) = @_;
+ my $artist = $c->stash->{artist};
- my $artist = $c->stash->{_artist};
- my $mb = $c->mb;
-
- my $link = new MusicBrainz::Server::Link($mb->{DBH});
- my @rawReleases = @{$link->FindLinkedAlbums("artist", $artist->GetId)};
-
- for my $release (@rawReleases)
- {
- $release->{_name_sort_} = lc decode "utf-8", $release->{name};
- $release->{_disc_no_} = 0;
-
- # Attempt to sort "disc x" correctly
- if ($release->{_name_sort_} =~
- /^(.*) # $1 <main title>
- (?:[(]disc\ (\d+) # $2 (disc x
- (?::[^()]* # [: <disc title>
- (?:[(][^()]*[)][^()]*)* # [<1 level of nested par.>]
- )? # ]
- [)] # )
- )
- (.*)$ # $4 [<rest of main title>]
- /xi)
- {
- $release->{_name_sort_} = "$1 $3";
- $release->{_disc_no_} = $2;
- }
-
- $release->{date} = $release->{begindate};
- $release->{date} =~ s/\s+//;
- $release->{date} = $release->{firstreleasedate} if !$release->{date};
- $release->{_sort_date_} = $release->{date} || "9999-99-99";
- }
-
- @rawReleases = sort {
- ($a->{linkphrase} cmp $b->{linkphrase}) or
- ($a->{_sort_date_} cmp $b->{_sort_date_}) or
- ($a->{_name_sort_} cmp $b->{_name_sort_}) or
- ($a->{_disc_no_} <=> $b->{_disc_no_})
- } @rawReleases;
-
- my @releaseGroups;
- my $group;
- for my $release (@rawReleases)
- {
- if (not defined $group or $release->{linkphrase} ne $group->{phrase})
- {
- $group = {
- phrase => $release->{linkphrase},
- releases => []
- };
-
- push @releaseGroups, $group;
- }
-
- my $stashRelease = {
- name => $release->{name},
- link_type => 'release',
- mbid => $release->{id},
- };
-
- $stashRelease->{artist} = {
- name => $release->{artist_name},
- link_type => 'artist',
- mbid => $release->{artist_id},
- };
- $stashRelease->{year} = substr($release->{date}, 0, 4) || '?';
-
- push @{$group->{releases}}, $stashRelease;
- }
-
- $c->stash->{release_groups} = \@releaseGroups;
- $c->stash->{template} = 'artist/appearances.tt';
+ $c->stash->{releases} = $c->model('Release')->find_linked_albums($artist);
+ $c->stash->{template} = 'artist/appearances.tt';
}
=head2 perma
@@ -323,7 +150,6 @@
sub perma : Chained('artist')
{
my ($self, $c) = @_;
-
$c->stash->{template} = 'artist/perma.tt';
}
@@ -336,11 +162,6 @@
sub details : Chained('artist')
{
my ($self, $c, $mbid) = @_;
-
- my $artist = $c->stash->{_artist};
-
- $c->stash->{details}->{subscriber_count} = scalar $artist->GetSubscribers;
-
$c->stash->{template} = 'artist/details.tt';
}
@@ -353,23 +174,9 @@
sub aliases : Chained('artist')
{
my ($self, $c) = @_;
+ my $artist = $c->stash->{artist};
- my $artist = $c->stash->{_artist};
-
- my $alias = MusicBrainz::Server::Alias->new($c->mb->{DBH}, "ArtistAlias");
- my @aliases = $alias->GetList($artist->GetId);
-
- my @prettyAliases = ();
- for my $alias (@aliases)
- {
- push @prettyAliases, {
- name => $alias->[1],
- useCount => $alias->[2],
- used => !($alias->[3] =~ /^1970-01-01/),
- }
- }
-
- $c->stash->{aliases} = \@prettyAliases;
+ $c->stash->{aliases} = $c->model('Alias')->load_for_entity($artist);
$c->stash->{template} = 'artist/aliases.tt';
}
@@ -386,65 +193,113 @@
sub show : PathPart('') Chained('artist')
{
my ($self, $c, $mbid) = @_;
+ my $artist = $c->stash->{artist};
- # Load the artist
- my $mb = $c->mb;
- my $artist = $c->stash->{_artist};
+ my $show_all = $c->req->query_params->{show_all} || 0;
- my $short_list = 1 - $c->req->query_params->{show_all};
+ $c->stash->{tags} = $c->model('Tag')->top_tags($artist);
+ $c->stash->{releases} = $c->model('Release')->load_for_artist($artist, $show_all);
+ $c->stash->{relations} = $c->model('Relation')->load_relations($artist);
- # Load data for the landing page
- my $annotation = LoadArtistAnnotation($mb->{DBH}, $artist);
- my @tags = LoadArtistTags($mb->{DBH}, 5, $artist);
- my @releases = LoadArtistReleases($artist, $short_list);
+ #my $annotation = LoadArtistAnnotation($mb->{DBH}, $artist);
+# my @releases = LoadArtistReleases($artist, $short_list);
# Create data structures for the template
- $c->stash->{artist_tags} = \@tags;
- $c->stash->{artist_relations} = load_relations($artist);
# $c->stash->{annotation} = $annotation->GetTextAsHTML
# if defined $annotation;
- # Releases, sorted into "release groups":
- $c->stash->{groups} = [];
+ # Decide how to display the data
+ $c->stash->{template} = defined $c->request->query_params->{full} ?
+ 'artist/full.tt' :
+ 'artist/compact.tt';
+}
- my $currentGroup;
- for my $release (@releases)
- {
- my ($type, $status) = $release->GetReleaseTypeAndStatus;
- # Releases should have sorted into groups, so if $type has changed,
- # we need to create a new "release group"
- if (not defined $currentGroup or $currentGroup->{type} != $type)
+=head2 WRITE METHODS
+
+These methods write to the database (create/update/delete)
+
+=head2 create
+
+When given a GET request this displays a form allowing the user to enter
+data, creating a new artist. If a POST request is received, the data
+is validated and if validation succeeds, the artist is entered into the
+MusicBrainz database.
+
+The heavy work validating the form and entering data into the database
+is done via L<MusicBrainz::Server::Form::Artist;
+
+=cut
+
+sub create : Local
+{
+ my ($self, $c) = @_;
+
+ use MusicBrainz::Server::Form::Artist;
+
+ my $form = new MusicBrainz::Server::Form::Artist;
+ $form->context($c);
+
+ $c->stash->{form} = $form;
+
+ if ($c->form_posted)
+ {
+ if (my $mods = $form->update_from_form($c->req->params))
{
- my $va = $release->{_is_va_} ? "Various Artist" : "";
- my $name = $release->GetAttributeNamePlural($type);
- $name = $name eq "" ? "Uncategorized Releases" : $name;
+ $c->flash->{ok} = "Thanks! The artist has been added to the " .
+ "database, and we have redirected you to " .
+ "their landing page";
- $currentGroup = {
- name => ($name ? "$va $name" : $va ? $va."s" : "None"),
- releases => [],
- type => $type,
- };
+ # Make sure that the moderation did go through, and redirect to
+ # the new artist
+ my $addmod = grep { $_->Type eq ModDefs::MOD_ADD_ARTIST } @$mods;
- push @{$c->stash->{groups}}, $currentGroup;
+ $c->detach('/artist/show', $addmod->GetRowId)
+ if $addmod;
}
+ }
- my $rel = $release->ExportStash qw/ language track_count disc_ids
- puids quality language
- status first_date attributes
- type/;
+ $c->stash->{template} = 'artist/create.tt';
+}
- push @{$currentGroup->{releases}}, $rel;
+=head2 edit
+
+Allows users to edit the data about this artist.
+
+When viewed with a GET request, the user is displayed a form filled with
+the current artist data. When a POST request is received, the data is
+validated and if it passed validation is the updated data is entered
+into the MusicBrainz database.
+
+=cut
+
+sub edit : Chained('artist')
+{
+ my ($self, $c, $mbid) = @_;
+ my $artist = $c->stash->{_artist};
+
+ use MusicBrainz::Server::Form::Artist;
+
+ my $form = new MusicBrainz::Server::Form::Artist($artist->GetId);
+ $form->context($c);
+
+ $c->stash->{form} = $form;
+
+ if ($c->form_posted)
+ {
+ if ($form->update_from_form($c->req->params))
+ {
+ $c->flash->{ok} = "Thanks, your artist edit has been entered " .
+ "into the moderation queue";
+
+ $c->detach('/artist/show', $mbid);
+ }
}
- # Decide how to display the data
- $c->stash->{template} = defined $c->request->query_params->{full} ?
- 'artist/full.tt' :
- 'artist/compact.tt';
+ $c->stash->{template} = 'artist/edit.tt';
}
-
=head2 INTERNAL METHODS
=cut
@@ -471,73 +326,6 @@
sub LoadArtistReleases
{
- my ($artist, $limited_selection) = @_;
-
- my @releases = $artist->GetReleases($limited_selection, 1);
-
- if ($limited_selection)
- {
- my $onlyHasVAReleases = (scalar @releases) == 0;
-
- my @shortList;
- for my $release (@releases)
- {
- my ($type, $status) = $release->GetReleaseTypeAndStatus;
-
- # Push onto our list of releases we are actually interested in
- push @shortList, $release
- if (defined $type && (
- $type == MusicBrainz::Server::Release::RELEASE_ATTR_ALBUM ||
- $type == MusicBrainz::Server::Release::RELEASE_ATTR_EP ||
- $type == MusicBrainz::Server::Release::RELEASE_ATTR_COMPILATION ||
- $type == MusicBrainz::Server::Release::RELEASE_ATTR_SINGLE));
- }
-
- @releases = scalar @shortList ? @shortList : @releases;
-
- if (scalar @releases == 0)
- {
- @releases = $artist->GetReleases(0, 1, $onlyHasVAReleases);
- }
- }
-
- for my $release (@releases)
- {
- my ($type, $status) = $release->GetReleaseTypeAndStatus;
-
- # Construct values to sort on
- $release->SetMultipleTrackArtists($release->GetArtist != $release->GetId() ? 1 : 0);
- $release->{_firstreleasedate_} = ($release->GetFirstReleaseDate || "9999-99-99");
- $release->{_is_va_} = ($release->GetArtist == &ModDefs::VARTIST_ID) or
- ($release->GetArtist != $release->GetId());
- $release->{_is_nonalbum_} = $type && $type == MusicBrainz::Server::Release::RELEASE_ATTR_NONALBUMTRACKS;
- $release->{_section_key_} = (defined $type ? $release->{_is_va_} . " " . $type : $release->{_is_va});
- $release->{_name_sort_} = lc decode "utf-8", $release->GetName;
- $release->{_disc_max_} = 0;
- $release->{_disc_no_} = 0;
-
- CheckAttributes($release);
-
- # Attempt to sort "disc x [of y]" correctly
- if ($release->{_name_sort_} =~
- /^(.*) # $1 <main title>
- (?:[(]disc\ (\d+) # $2 (disc x
- (?:\ of\ (\d+))? # $3 [of y]
- (?::[^()]* # [: <disc title>
- (?:[(][^()]*[)][^()]*)* # [<1 level of nested par.>]
- )? # ]
- [)] # )
- )
- (.*)$ # $4 [<rest of main title>]
- /xi)
- {
- $release->{_name_sort_} = "$1 $4";
- $release->{_disc_no_} = $2;
- $release->{_disc_max_} = $3 || 0;
- }
- }
-
- sort SortAlbums @releases;
}
=head2 load_relations $artist
@@ -582,37 +370,6 @@
unless defined $a->{_attr_status};
};
-=head2 SortAlbums
-
-Sort a list of MusicBrainz::Server::Album objects into the order they
-are displayed on the artist homepage
-
-=cut
-
-sub SortAlbums
-{
- # I edited these out of one huge "or"ed conditional as it was a bitch to debug
- my @predicates = (
- ($a->{_is_va_} <=> $b->{_is_va_}),
- ($b->{_is_nonalbum_} <=> $a->{_is_nonalbum_}),
- ($a->{_attr_type} <=> $b->{_attr_type}),
- ($a->{_firstreleasedate_} cmp $b->{_firstreleasedate_}),
- ($a->{_name_sort_} cmp $b->{_name_sort_}),
- ($a->{_disc_max_} <=> $b->{_disc_max_}),
- ($a->{_disc_no_} <=> $b->{_disc_no_}),
- ($a->{_attr_status} <=> $b->{_attr_status}),
- ($a->{trackcount} cmp $b->{trackcount}),
- ($b->{trmidcount} cmp $a->{trmidcount}),
- ($b->{puidcount} cmp $a->{puidcount}),
- ($a->GetId cmp $b->GetId),
- );
-
-
- for (@predicates) { return $_ if $_; }
-
- return 0;
-}
-
=head1 LICENSE
This software is provided "as is", without warranty of any kind, express or
Added: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Facade/Alias.pm
Added: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Facade/Artist.pm
Added: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Facade/Link.pm
Added: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Facade/Release.pm
Added: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Alias.pm
Added: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Artist.pm
Added: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Relation.pm
Added: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Release.pm
Added: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Model/Tag.pm
Modified: mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Release.pm
===================================================================
--- mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Release.pm 2008-07-23 15:56:55 UTC (rev 10155)
+++ mb_server/branches/TemplateToolkit/lib/MusicBrainz/Server/Release.pm 2008-07-24 20:35:52 UTC (rev 10156)
@@ -290,112 +290,6 @@
return (scalar(@attrs) == 2 && $attrs[1] == RELEASE_ATTR_NONALBUMTRACKS);
}
-=head2 ExportStash [ @names ]
-
-Exports data from this artist to a Template Toolkit friendly format, that can be placed in the
-Catalyst stash. You can control what data is exported by use of the @names parameter. Possible
-options are:
-
-=over
-
-=item track_count
-
-Exports the amount of tracks on this release, as in integer in the C<track_count> key. See
-L<GetTrackCount>.
-
-=item disc_ids
-
-Exports the amount of disc IDs attached to this release, as an integer in the C<disc_ids> key.
-See L<GetDiscidCount>
-
-=item puids
-
-Exports the total amount of puids attached to tracks in this release, as in integer in the
-C<puids> key. See L<GetPuidCount>.
-
-=item quality
-
-Exports the data quality of this release in a human readable format, as a string in the C<quality>
-key. This string is created by using L<ModDefs::GetQualityText>, along with L<GetQuality>.
-
-=item first_date
-
-Exports the first date this release was released, in the C<first_date> key.
-See L<GetFirstReleaseDate>.
-
-=item type
-
-Exports both the release type and status attributes of this release, in human readable form. If
-either of these attributes are missing they will be filled with an empty string. This data is stored
-as a hash (key C<type>) which has keys C<type> and C<status>.
-
-=item language
-
-Exports language related data from this release, into a hash with key C<language>. This hash contains
-3 keys: C<language>, C<script> and C<shortLanguage> which contain the name of the language, the script
-used to write the language and a short abbreviation of the language (see
-L<MusicBrainz::Server::Language::GetISOCode3T>).
-
-=back
-
-By default, the release name and MBID will also be exported, which will allow you to use this
-data with the C<entity-link.tt> component.
-
-=cut
-
-sub ExportStash
-{
- my ($self, @names) = @_;
-
- use Switch;
-
- my %stash;
- $stash{name} = $self->GetName;
- $stash{link_type} = 'release';
- $stash{mbid} = $self->GetMBId;
-
- for my $name (@names)
- {
- switch($name)
- {
- case('track_count') { $stash{track_count} = $self->GetTrackCount; }
- case('disc_ids') { $stash{disc_ids} = $self->GetDiscidCount; }
- case('puids') { $stash{puids} = $self->GetPuidCount; }
- case('quality') { $stash{quality} = ModDefs::GetQualityText($self->GetQuality); }
- case('first_date') { $stash{first_release_date} = $self->GetFirstReleaseDate; }
-
- case('type') {
- my ($type, $status) = $self->GetReleaseTypeAndStatus;
- $stash{type} = $self->GetAttributeName($type) || '';
- $stash{status} = $self->GetAttributeName($status) || '';
- }
-
- case('language') {
- $stash{language} = {
- script => defined $self->GetScript ? $self->GetScript->GetName : "",
- language => defined $self->GetLanguage ? $self->GetLanguage->GetName : "",
- shortLanguage => defined $self->GetLanguage ?
- $self->GetLanguage->GetISOCode3T : ""
- };
- }
-
- case('cover_art') {
- $stash{has_artwork} = $self->GetCoverartURL ? 1 : 0;
- $stash{cover_url } = $self->GetCoverartURL;
- }
-
- case('attributes') {
- $stash{attributes} = [];
- for ($self->GetAttributes) {
- push @{ $stash{attributes} }, $self->GetAttributeName($_);
- }
- }
- }
- }
-
- return \%stash;
-}
-
sub FindNonAlbum
{
my ($this, $artist) = @_;
Modified: mb_server/branches/TemplateToolkit/root/artist/appearances.tt
===================================================================
--- mb_server/branches/TemplateToolkit/root/artist/appearances.tt 2008-07-23 15:56:55 UTC (rev 10155)
+++ mb_server/branches/TemplateToolkit/root/artist/appearances.tt 2008-07-24 20:35:52 UTC (rev 10156)
@@ -1,24 +1,39 @@
[%- WRAPPER "artist/layout.tt" title="Appearances" -%]
-[%- FOREACH group IN release_groups -%]
-<div class="compactreleasetype">[% group.phrase | ucfirst | html %]</div>
-<table class="appears">
- <thead>
- <tr>
- <th class="year">Year</th>
- <th class="artist">Artist</th>
- <th class="title">Release Title</th>
- </tr>
- </thead>
- <tbody>
+
+[% BLOCK group_head %]
+ [%- last_year = '.' -%]
+ <h2 class="compactreleasetype">[% item.link_phrase | ucfirst %]</h2>
+ <table class="appears">
+ <thead>
+ <tr>
+ <th class="year">Year</th>
+ <th class="artist">Artist</th>
+ <th class="title">Release Title</th>
+ </tr>
+ </thead>
+ <tbody>
+[% END %]
+
+[% BLOCK group_item %]
+ <tr>
+ <td class="year[% item.year == last_year && item.year != "?" ? " timeline" : "" -%]">
+ [% item.year %]
+ </td>
+ <td>[% item.name %]</td>
+ </tr>
+ [%- last_year = item.year -%]
+[% END %]
+
+[% BLOCK group_foot %]
+ </tbody>
+</table>
+[% END %]
+
+[% INCLUDE "components/grouped.tt" items=releases group_var='link_phrase' %]
+
+[%- FOREACH group IN releases -%]
[%- lastyear = "." -%]
[%- FOREACH release IN group.releases -%]
- <tr>
- <td class="year[% release.year == lastyear && release.year != "?" ? " timeline" : "" -%]">
- [% release.year %]
- </td>
- <td class="artist">[% INCLUDE "components/entity-link.tt" entity=release.artist %]</td>
- <td class="title">[% INCLUDE "components/entity-link.tt" entity=release %]</td>
- </tr>
[%- lastyear = release.year -%]
[%- END -%]
</tbody>
Modified: mb_server/branches/TemplateToolkit/root/artist/compact.tt
===================================================================
--- mb_server/branches/TemplateToolkit/root/artist/compact.tt 2008-07-23 15:56:55 UTC (rev 10155)
+++ mb_server/branches/TemplateToolkit/root/artist/compact.tt 2008-07-24 20:35:52 UTC (rev 10156)
@@ -1,26 +1,45 @@
[%- WRAPPER "artist/landing.tt" -%]
-[%- FOREACH group IN groups -%]
- <div>
- <h2 class="compactreleasetype">[% group.name | html %]</h2>
+
+[% BLOCK group_head %]
+ <h2 class="compactreleasetype">
+ [% IF item.artist.id != artist.id; "Various Artist "; END %] [% item.release_type_plural %]</h2>
<table class="releases">
<tbody>
- [%- FOREACH release IN group.releases -%]
+[% END %]
+
+[% BLOCK group_item %]
<tr[% ' class="odd"' IF loop.count % 2 == 0 %]>
- <td class="tracks">[% release.track_count %] <img src="/static/images/notes.gif" alt="Tracks" /></td>
- <td class="discids">[% release.disc_ids %] <img src="/static/images/cd.gif" alt="Disc IDs" /></td>
- <td class="puids">[% release.puids %] <img src="/static/images/puid.gif" alt="PUIDs" /></td>
- <td class="status">[% release.status %]</td>
- <td class="date">[% release.first_release_date | release_date %]</td>
+ <td class="tracks">
+ [% item.track_count %] <img src="/static/images/notes.gif" alt="Tracks" />
+ </td>
+ <td class="discids">
+ [% IF item.disc_ids %]
+ [% item.disc_ids %] <img src="/static/images/cd.gif" alt="Disc IDs" />
+ [% END %]
+ </td>
+ <td class="puids">
+ [% IF item.puid_count %]
+ [% item.puid_count %] <img src="/static/images/puid.gif" alt="PUIDs" />
+ [% END %]
+ </td>
+ <td class="status">
+ [% item.release_status_name %]
+ </td>
+ <td class="date">[% item.first_release_date | release_date %]</td>
<td class="language">
- <abbr title="[% release.language.language %] / [% release.language.script %]">
- [% release.language.shortLanguage %]
+ <abbr title="[% item.language %] / [% item.script %]">
+ [% item.short_language %]
</abbr>
</td>
- <td>[% INCLUDE "components/entity-link.tt" entity=release icon=0 %]</td>
+ <td>[% INCLUDE "components/entity-link.tt" entity=item icon=0 %]</td>
</tr>
- [%- END -%]
+[% END %]
+
+[% BLOCK group_foot %]
</tbody>
</table>
- </div>
-[%- END -%]
[% END %]
+
+[% INCLUDE "components/grouped.tt" items=releases group_var='release_type' %]
+
+[% END %]
Modified: mb_server/branches/TemplateToolkit/root/artist/details.tt
===================================================================
--- mb_server/branches/TemplateToolkit/root/artist/details.tt 2008-07-23 15:56:55 UTC (rev 10155)
+++ mb_server/branches/TemplateToolkit/root/artist/details.tt 2008-07-24 20:35:52 UTC (rev 10156)
@@ -5,7 +5,7 @@
[% WRAPPER "components/box.tt" header="Artist Information" %]
<table class="details">
<tr>
- <th>[% INCLUDE "components/doc-link.tt" to="ArtistName" text="Name" %]:</th>
+ <th>[%- INCLUDE "components/doc-link.tt" to="ArtistName" text="Name" -%]:</th>
<td>
[% INCLUDE "components/entity-link.tt" entity=artist %]
[% IF artist.resolution %]
@@ -14,16 +14,19 @@
</td>
</tr>
<tr>
- <th>[% INCLUDE "components/doc-link.tt" to="MusicBrainzIdentifier" text="MBID" %]:</th>
+ <th>[%- INCLUDE "components/doc-link.tt" to="MusicBrainzIdentifier" text="MBID" -%]:</th>
<td>[% artist.mbid %]</td>
</tr>
</tr>
- <th>Permanent link:</th>
+ <th>Permanent link :</th>
<td>
[% perma="
http://musicbrainz.org/artist/${artist.mbid}" %]
<a href="[% perma | url %]">[% perma | html %]</a>
</td>
</tr>
+ <tr>
+ <th>Subscriber Count :</th>
+ <td>[% artist.subscriber_count %]</td>
</table>
[% END %]
Modified: mb_server/branches/TemplateToolkit/root/artist/header.tt
===================================================================
--- mb_server/branches/TemplateToolkit/root/artist/header.tt 2008-07-23 15:56:55 UTC (rev 10155)
+++ mb_server/branches/TemplateToolkit/root/artist/header.tt 2008-07-24 20:35:52 UTC (rev 10156)
@@ -18,17 +18,17 @@
</div>
<div class="info">
- [% IF artist.sortname != artist.name %][% artist.sortname | html %]<br />[% END %]
+ [% IF artist.sort_name != artist.name %][% artist.sort_name | html %]<br />[% END %]
- [%- IF artist.datespan.complete -%]
- [% artist.datespan.start %] - [% artist.datespan.end %]<br/>
- [%- ELSIF artist.datespan.start -%]
- Began: [% artist.datespan.start -%]<br />
- [%- ELSIF artist.datespan.end -%]
- End: [% artist.datespan.end -%]<br />
+ [%- IF artist.complete_date_range -%]
+ [% artist.start_date %] - [% artist.end_date %]<br/>
+ [%- ELSIF artist.start_date -%]
+ Began: [% artist.start_date -%]<br />
+ [%- ELSIF artist.end_date -%]
+ End: [% artist.end_date -%]<br />
[%- END -%]
- Type: [%- artist.type -%], [%- artist.quality.quality -%] data quality<br />
+ Type: [%- artist.type -%], [%- artist.quality -%] data quality<br />
</div>
<div class="infoLinks"> Info: [% INCLUDE "components/piped-list.tt" list=info_links %]</div>
Modified: mb_server/branches/TemplateToolkit/root/artist/landing.tt
===================================================================
--- mb_server/branches/TemplateToolkit/root/artist/landing.tt 2008-07-23 15:56:55 UTC (rev 10155)
+++ mb_server/branches/TemplateToolkit/root/artist/landing.tt 2008-07-24 20:35:52 UTC (rev 10156)
@@ -2,9 +2,9 @@
[%- INCLUDE "artist/header.tt" -%]
[%- INCLUDE "artist/annotation.tt" IF annotation -%]
<div class="TagsBox">
- [%- INCLUDE "tag/summary.tt" tags=artist_tags source=artist -%]
+ [%- INCLUDE "tag/summary.tt" source=artist -%]
</div>
-[%- INCLUDE "components/relations.tt" source=artist relations=artist_relations -%]
+[%- INCLUDE "components/relations.tt" source=artist -%]
<div style="text-align: center;">
[%- IF c.req.query_params.show_all -%]
You are viewing all releases by [% artist.name %]. You can also choose to view only
Modified: mb_server/branches/TemplateToolkit/root/components/entity-link.tt
===================================================================
--- mb_server/branches/TemplateToolkit/root/components/entity-link.tt 2008-07-23 15:56:55 UTC (rev 10155)
+++ mb_server/branches/TemplateToolkit/root/components/entity-link.tt 2008-07-24 20:35:52 UTC (rev 10156)
@@ -1,11 +1,11 @@
[%#- The formatting on this is crazy, but we need to make sure no white space -%]
[%#- escapes! -%]
-[%- IF entity.link_type == "url" -%]
+[%- IF entity.entity_type == "url" -%]
<a href="[% (entity.url || entity.name) | url %]">[% entity.name | truncate(53) | html %]</a>
[<a href="[% entity_url(entity, 'info') %]">info</a>]
[%- ELSE -%]
<a href="[% entity_url(entity, 'show') %]">
- [%- UNLESS noicon -%]<span class="[% entity.link_type %]_icon">[%- END -%]
+ [%- UNLESS noicon -%]<span class="[% entity.entity_type %]_icon">[%- END -%]
[% entity.name | html %]
[%- UNLESS noicon -%]</span>[%- END -%]</a>
[%- END -%]
Added: mb_server/branches/TemplateToolkit/root/components/grouped.tt
_______________________________________________
MusicBrainz-commits mailing list
MusicBrainz-commits@...
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-commits