Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert entity sidebars to React #623

Merged
merged 63 commits into from Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
a8f2720
Move jquery-ui import to componentDidMount
mwiencek Sep 27, 2018
815be92
Only serialize stash keys that exist
mwiencek Mar 16, 2018
0ebdb5f
Entity::{IPI,ISNI} should not extend Entity
mwiencek Mar 16, 2018
610ae01
{IPI,ISNI} serialization
mwiencek Mar 16, 2018
c9cd2a5
Serialize show_license_in_sidebar
mwiencek Mar 16, 2018
07cfb84
Add returnUri helper
mwiencek Mar 17, 2018
aa5c46c
Pass aggregate/user tags directly to TagEditor
mwiencek Mar 17, 2018
11b4ad5
Allow SidebarTagEditor hydration
mwiencek Sep 27, 2018
f25a1d6
Use new license header in artist/utils
mwiencek Mar 20, 2018
87ed1bb
Convert artist/utils to typed ES module
mwiencek Mar 20, 2018
4a1bce3
Implement artistBeginAreaLabel, artistEndAreaLabel
mwiencek Mar 20, 2018
e6ffcae
Convert isSpecialPurposeArtist to ES module
mwiencek Mar 20, 2018
125bb65
Run eslint on components/RatingStars
mwiencek Mar 20, 2018
06bf498
Factor out getDaysInMonth helper
mwiencek Mar 20, 2018
1f98ea1
Move out relationship types from externalLinks
mwiencek Mar 20, 2018
f638a7d
Convert Entity::Role::Age and related macros to JS
mwiencek Mar 20, 2018
9f55f5a
Improve linked_entities serialization
mwiencek Mar 22, 2018
18c19dc
Convert sidebar-licenses.tt to React
mwiencek Mar 20, 2018
62d1602
Component for sidebar edit links
mwiencek Mar 25, 2018
08a70b1
last_updated serialization
mwiencek Mar 26, 2018
c0a7b17
Component for sidebar last updated date
mwiencek Mar 25, 2018
287e4e4
Convert URL sidebar to React
mwiencek Mar 25, 2018
0ede253
Sidebar property components
mwiencek Mar 25, 2018
f8305ae
Sidebar annotation links component
mwiencek Mar 25, 2018
a43e830
Collection serialization
mwiencek Mar 26, 2018
6448876
Sidebar collections component
mwiencek Mar 25, 2018
4fe7379
Sidebar merge link component
mwiencek Mar 25, 2018
d4f3c3a
Sidebar remove link component
mwiencek Mar 25, 2018
bf6ce8e
Sidebar begin date component
mwiencek Mar 25, 2018
15e9dfd
Sidebar end date component
mwiencek Mar 25, 2018
1e9b46d
Sidebar tags component
mwiencek Mar 25, 2018
ea68b8f
Require that OptionsTree types implement entity_type
mwiencek Mar 28, 2018
f762cb5
Sidebar type component
mwiencek Mar 25, 2018
2aa4e69
Convert area sidebar to React
mwiencek Mar 25, 2018
4b91ff1
Sidebar IPIs component
mwiencek Mar 25, 2018
9769fe8
Sidebar ISNIs component
mwiencek Mar 25, 2018
3102ab6
Sidebar subscriptions component
mwiencek Mar 25, 2018
026fafc
Convert artist sidebar to React
mwiencek Mar 25, 2018
87d7266
Convert event sidebar to React
mwiencek Mar 25, 2018
0c652f0
Convert instrument sidebar to React
mwiencek Mar 26, 2018
0fcd5ee
Convert label sidebar to React
mwiencek Mar 26, 2018
b079e91
Convert place sidebar to React
mwiencek Mar 26, 2018
0121b43
Convert recording sidebar to React
mwiencek Mar 26, 2018
a9c0cb2
Handle blessed entities in relationship editor
mwiencek Oct 6, 2018
45464f1
Convert release group sidebar to React
mwiencek Mar 26, 2018
b7df438
Convert components/critiquebrainz.tt to React
mwiencek Mar 26, 2018
77cd2e8
Convert link_searchable_property to React
mwiencek Mar 26, 2018
720e222
Convert release_event to React
mwiencek Mar 26, 2018
430aac1
Convert cover_art_url to React
mwiencek Mar 26, 2018
79af65e
Convert release sidebar to React
mwiencek Mar 26, 2018
2de75fd
Convert series sidebar to React
mwiencek Mar 26, 2018
acab83d
Load work_attribute.id
mwiencek Apr 3, 2018
b01eff8
Convert work sidebar to React
mwiencek Mar 26, 2018
44b07b0
Add types to parse{Date,Int*} functions
mwiencek Sep 30, 2018
59eef72
Merge CDStubTOC into CDStub
mwiencek Oct 5, 2018
982792b
Convert the cdstub sidebar to React
mwiencek Oct 1, 2018
8f8b0d7
Convert request_login to React
mwiencek Oct 2, 2018
c53b650
Convert the collection sidebar to React
mwiencek Oct 2, 2018
6ce6414
Fix ExpirationDate component
mwiencek Oct 4, 2018
af16d01
Convert root/edit/{info,vote}.tt to React
mwiencek Oct 4, 2018
d919a10
Remove last use of expiration_time macro
mwiencek Oct 4, 2018
76fdab7
Remove unused code
mwiencek Oct 2, 2017
5b27ba2
Reduce the size of embedded JSON for hydration
mwiencek Oct 6, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions entities.json
Expand Up @@ -128,9 +128,6 @@
"model": "CDStub",
"url": "cdstub"
},
"cdstubtoc": {
"model": "CDStubTOC"
},
"cdtoc": {
"model": "CDTOC"
},
Expand Down
19 changes: 16 additions & 3 deletions lib/MusicBrainz/Server.pm
Expand Up @@ -450,29 +450,38 @@ sub TO_JSON {

# Whitelist of keys that we use in the templates.
my @stash_keys = qw(
all_collections
collections
commons_image
containment
current_language
current_language_html
entity
hide_merge_helper
jsonld_data
last_replication_date
linked_entities
makes_no_changes
merge_link
more_tags
new_edit_notes
number_of_revisions
release_artwork
server_details
server_languages
subscribed
to_merge
top_tags
user_tags
);

my %stash;
for (@stash_keys) {
$stash{$_} = $self->stash->{$_};
$stash{$_} = $self->stash->{$_} if exists $self->stash->{$_};
}

if (my $entity = delete $stash{entity}) {
if (ref($entity) =~ /^MusicBrainz::Server::Entity::/) {
$entity->serialize_with_linked_entities(\%stash);
$stash{entity} = $entity->TO_JSON;
}
}

Expand Down Expand Up @@ -504,13 +513,17 @@ sub TO_JSON {
}

return {
action => {
name => $self->action->name,
},
user => ($self->user_exists ? $self->user : undef),
user_exists => boolean_to_json($self->user_exists),
debug => boolean_to_json($self->debug),
relative_uri => $self->relative_uri,
req => {
headers => \%headers,
query_params => $req->query_params,
secure => boolean_to_json($req->secure),
uri => $req->uri,
},
stash => \%stash,
Expand Down
33 changes: 15 additions & 18 deletions lib/MusicBrainz/Server/Controller/CDStub.pm
Expand Up @@ -9,8 +9,8 @@ use MusicBrainz::Server::Translation qw( l ln );
use MusicBrainz::Server::ControllerUtils::CDTOC qw( add_dash );

with 'MusicBrainz::Server::Controller::Role::Load' => {
model => 'CDStubTOC',
entity_name => 'cdstubtoc',
model => 'CDStub',
entity_name => 'cdstub',
};

sub base : Chained('/') PathPart('cdstub') CaptureArgs(0) { }
Expand All @@ -30,8 +30,8 @@ sub _load
$c->detach;
return;
}
my $cdstubtoc = $c->model('CDStubTOC')->get_by_discid($id);
if (!$cdstubtoc) {
my $cdstub = $c->model('CDStub')->get_by_discid($id);
if (!$cdstub) {
$c->stash(
template => 'cdstub/error.tt',
not_found => 1,
Expand All @@ -40,13 +40,12 @@ sub _load
$c->detach;
return;
}
$c->model('CDStub')->load($cdstubtoc);
$c->model('CDStubTrack')->load_for_cdstub($cdstubtoc->cdstub);
$cdstubtoc->update_track_lengths;
$c->model('CDStubTrack')->load_for_cdstub($cdstub);
$cdstub->update_track_lengths;

$c->stash->{show_artists} = !defined($cdstubtoc->cdstub->artist) ||
$cdstubtoc->cdstub->artist eq '';
$c->stash->{cdstub} = $cdstubtoc;
$c->stash->{show_artists} = !defined($cdstub->artist) ||
$cdstub->artist eq '';
$c->stash->{cdstub} = $cdstub;
}

sub add : Path('add') DenyWhenReadonly
Expand Down Expand Up @@ -119,26 +118,24 @@ sub browse : Path('browse')
sub edit : Chained('load') DenyWhenReadonly
{
my ($self, $c) = @_;
my $cdstub_toc = $c->stash->{cdstub};
my $stub = $cdstub_toc->cdstub;
my $cdstub = $c->stash->{cdstub};

my $form = $c->form(form => 'CDStub', init_object => $stub);
my $form = $c->form(form => 'CDStub', init_object => $cdstub);
if ($c->form_posted && $form->submitted_and_valid($c->req->params)) {
$c->model('CDStub')->update($stub, $form->value);
$c->model('CDStub')->update($cdstub, $form->value);

$c->res->redirect(
$c->uri_for_action($self->action_for('show'), [ $cdstub_toc->discid ])
$c->uri_for_action($self->action_for('show'), [ $cdstub->discid ])
);
}
}

sub import : Chained('load') RequireAuth
{
my ($self, $c) = @_;
my $cdstub_toc = $c->stash->{cdstub};
my $stub = $cdstub_toc->cdstub;
my $cdstub = $c->stash->{cdstub};

my $search_query = $stub->artist || 'Various Artists';
my $search_query = $cdstub->artist || 'Various Artists';
my $form = $c->form(
form => 'Search::Query',
item => { query => $search_query }
Expand Down
17 changes: 8 additions & 9 deletions lib/MusicBrainz/Server/Controller/CDTOC.pm
Expand Up @@ -270,20 +270,19 @@ sub attach : Local DenyWhenReadonly
$c->detach;
}
else {
my $stub_toc = $c->model('CDStubTOC')->get_by_discid($cdtoc->discid);
if ($stub_toc) {
$c->model('CDStub')->load($stub_toc);
$c->model('CDStubTrack')->load_for_cdstub($stub_toc->cdstub);
$stub_toc->update_track_lengths;
my $cdstub = $c->model('CDStub')->get_by_discid($cdtoc->discid);
if ($cdstub) {
$c->model('CDStubTrack')->load_for_cdstub($cdstub);
$cdstub->update_track_lengths;

$initial_artist ||= $stub_toc->cdstub->artist;
$initial_release ||= $stub_toc->cdstub->title;
$initial_artist ||= $cdstub->artist;
$initial_release ||= $cdstub->title;

my @mediums = $c->model('Medium')->find_for_cdstub($stub_toc);
my @mediums = $c->model('Medium')->find_for_cdstub($cdstub);
$c->model('ArtistCredit')->load(map { $_->release } @mediums);
$c->stash(
possible_mediums => [ @mediums ],
cdstubtoc => $stub_toc
cdstub => $cdstub
);
}
}
Expand Down
7 changes: 3 additions & 4 deletions lib/MusicBrainz/Server/Controller/Role/EditRelationships.pm
Expand Up @@ -86,14 +86,13 @@ role {
# Grrr. release_group => release-group.
$form_name =~ s/_/-/;

my $json = JSON->new;
my @link_type_tree = $c->model('LinkType')->get_full_tree;
my $attr_tree = $c->model('LinkAttributeType')->get_tree;

$c->stash(
source_entity => $json->encode($source_entity),
attr_info => $json->encode(build_attr_info($attr_tree)),
type_info => $json->encode(build_type_info($c, qr/(^$source_type-|-$source_type$)/, @link_type_tree)),
source_entity => $c->json->encode($source_entity),
attr_info => $c->json->encode(build_attr_info($attr_tree)),
type_info => $c->json->encode(build_type_info($c, qr/(^$source_type-|-$source_type$)/, @link_type_tree)),
);

my $post_creation = delete $opts{post_creation};
Expand Down
2 changes: 1 addition & 1 deletion lib/MusicBrainz/Server/Controller/Role/Tag.pm
Expand Up @@ -21,7 +21,7 @@ after load => sub {
$c->stash(
top_tags => \@tags,
more_tags => $count > @tags,
top_tags_json => $c->json->encode(\@tags),
user_tags => \@user_tags,
user_tags_json => $c->json->encode(\@user_tags),
);
};
Expand Down
11 changes: 5 additions & 6 deletions lib/MusicBrainz/Server/Controller/WS/1/Release.pm
Expand Up @@ -101,13 +101,12 @@ around 'search' => sub
my @recordings = map { $_->recording } map { $_->all_tracks } @mediums;
}
elsif (!exists $c->req->query_params->{cdstubs} || $c->req->query_params->{cdstubs} eq 'yes') {
my $cd_stub_toc = $c->model('CDStubTOC')->get_by_discid($disc_id);
if ($cd_stub_toc) {
$c->model('CDStub')->load($cd_stub_toc);
$c->model('CDStub')->increment_lookup_count($cd_stub_toc->cdstub->id);
$c->model('CDStubTrack')->load_for_cdstub($cd_stub_toc->cdstub);
my $cdstub = $c->model('CDStub')->get_by_discid($disc_id);
if ($cdstub) {
$c->model('CDStub')->increment_lookup_count($cdstub->id);
$c->model('CDStubTrack')->load_for_cdstub($cdstub);

push @releases, $cd_stub_toc->cdstub;
push @releases, $cdstub;
}
}

Expand Down
13 changes: 6 additions & 7 deletions lib/MusicBrainz/Server/Controller/WS/2/DiscID.pm
Expand Up @@ -70,15 +70,14 @@ sub discid : Chained('root') PathPart('discid') {

if (!exists $c->req->query_params->{cdstubs} || $c->req->query_params->{cdstubs} eq 'yes')
{
my $cd_stub_toc = $c->model('CDStubTOC')->get_by_discid($id);
if ($cd_stub_toc) {
$c->model('CDStub')->load($cd_stub_toc);
$c->model('CDStub')->increment_lookup_count($cd_stub_toc->cdstub->id);
$c->model('CDStubTrack')->load_for_cdstub($cd_stub_toc->cdstub);
$cd_stub_toc->update_track_lengths;
my $cdstub = $c->model('CDStub')->get_by_discid($id);
if ($cdstub) {
$c->model('CDStub')->increment_lookup_count($cdstub->id);
$c->model('CDStubTrack')->load_for_cdstub($cdstub);
$cdstub->update_track_lengths;

$c->res->content_type($c->stash->{serializer}->mime_type . '; charset=utf-8');
$c->res->body($c->stash->{serializer}->serialize('cdstub', $cd_stub_toc, $c->stash->{inc}, $stash));
$c->res->body($c->stash->{serializer}->serialize('cdstub', $cdstub, $c->stash->{inc}, $stash));
return;
}
}
Expand Down
13 changes: 6 additions & 7 deletions lib/MusicBrainz/Server/Controller/WS/js.pm
Expand Up @@ -73,27 +73,26 @@ sub medium : Chained('root') PathPart Args(1) {
sub cdstub : Chained('root') PathPart Args(1) {
my ($self, $c, $id) = @_;

my $cdstub_toc = $c->model('CDStubTOC')->get_by_discid($id);
my $cdstub = $c->model('CDStub')->get_by_discid($id);
my $ret = {
toc => "",
tracks => []
};

if ($cdstub_toc)
if ($cdstub)
{
$c->model('CDStub')->load($cdstub_toc);
$c->model('CDStubTrack')->load_for_cdstub($cdstub_toc->cdstub);
$cdstub_toc->update_track_lengths;
$c->model('CDStubTrack')->load_for_cdstub($cdstub);
$cdstub->update_track_lengths;

$ret->{toc} = $cdstub_toc->toc;
$ret->{toc} = $cdstub->toc;
$ret->{tracks} = [ map {
{
name => $_->title,
artist => $_->artist,
length => $_->length,
artist => $_->artist,
}
} $cdstub_toc->cdstub->all_tracks ];
} $cdstub->all_tracks ];
}

$c->res->content_type($c->stash->{serializer}->mime_type . '; charset=utf-8');
Expand Down
7 changes: 1 addition & 6 deletions lib/MusicBrainz/Server/Controller/Work.pm
Expand Up @@ -58,6 +58,7 @@ after 'load' => sub
}
}

$c->model('WorkType')->load($work);
$c->model('ISWC')->load_for_works($work);
};

Expand Down Expand Up @@ -102,12 +103,6 @@ with 'MusicBrainz::Server::Controller::Role::Merge' => {
edit_type => $EDIT_WORK_MERGE,
};

before qw( show aliases tags details edit edit_annotation open_edits edits ) => sub {
my ($self, $c) = @_;
my $work = $c->stash->{work};
$c->model('WorkType')->load($work);
};

before qw( show aliases tags details edit ) => sub {
my ($self, $c) = @_;
my $work = $c->stash->{work};
Expand Down
9 changes: 9 additions & 0 deletions lib/MusicBrainz/Server/CoverArt.pm
Expand Up @@ -32,4 +32,13 @@ sub cache_data
return $data;
}

sub TO_JSON {
my ($self) = @_;

return {
image_uri => $self->image_uri->as_string,
information_uri => $self->information_uri->as_string,
};
}

1;
35 changes: 25 additions & 10 deletions lib/MusicBrainz/Server/Data/CDStub.pm
Expand Up @@ -20,12 +20,27 @@ Readonly my $LIMIT_TOP_CDSTUBS => 1000;

sub _table
{
return 'release_raw';
return 'release_raw JOIN cdtoc_raw ON cdtoc_raw.release = release_raw.id';
}

sub _columns
{
return 'id, title, artist, added, last_modified, lookup_count, modify_count, source, barcode, comment';
return join(', ', qw(
release_raw.id
title
artist
added
last_modified
lookup_count
modify_count
source
barcode
comment
discid
track_count
leadout_offset
track_offset
));
}

sub _column_mapping
Expand All @@ -42,6 +57,9 @@ sub _column_mapping
barcode => sub { MusicBrainz::Server::Entity::Barcode->new_from_row(shift, shift) },
comment => 'comment',
discid => 'discid',
track_count => 'track_count',
leadout_offset => 'leadout_offset',
track_offset => 'track_offset',
};
}

Expand All @@ -59,9 +77,8 @@ sub load
sub load_top_cdstubs
{
my ($self, $limit, $offset) = @_;
my $query = "SELECT release_raw." . $self->_columns . ", discid
FROM " . $self->_table . ", cdtoc_raw
WHERE release_raw.id = cdtoc_raw.release
my $query = "SELECT " . $self->_columns . "
FROM " . $self->_table . "
ORDER BY lookup_count desc, modify_count DESC";
$self->query_to_list_limited($query, [], $LIMIT_TOP_CDSTUBS, $offset);
}
Expand All @@ -77,11 +94,9 @@ sub increment_lookup_count

sub get_by_discid {
my ($self, $discid) = @_;
my $query = 'SELECT release_raw.' . $self->_columns . ', discid
FROM ' . $self->_table . '
JOIN cdtoc_raw ON cdtoc_raw.release = release_raw.id
WHERE discid = ?';
$self->query_to_list($query, [$discid]);

my @cdstubs = $self->_get_by_keys('discid', $discid);
return $cdstubs[0];
}

sub insert
Expand Down