Skip to content

Commit

Permalink
MBS-12217: Add admin interface for editing alias types
Browse files Browse the repository at this point in the history
Uses the existing code for attributes, since these
are basically the same as entity types already.
Also allows users to see them and their descriptions,
once we add them.
  • Loading branch information
reosarevok committed Dec 4, 2023
1 parent 13bbe19 commit 403082f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
20 changes: 18 additions & 2 deletions lib/MusicBrainz/Server/Controller/Attributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ my @entity_type_models = qw(
WorkType
);

my @alias_type_models = qw(
AreaAliasType
ArtistAliasType
EventAliasType
GenreAliasType
InstrumentAliasType
LabelAliasType
PlaceAliasType
RecordingAliasType
ReleaseAliasType
ReleaseGroupAliasType
SeriesAliasType
WorkAliasType
);

my @other_models = qw(
CoverArtType
Gender
Expand All @@ -35,8 +50,8 @@ my @other_models = qw(
WorkAttributeType
);

my @all_models = (@entity_type_models, @other_models);
# Missing: Alias types, WorkAttributeTypeAllowedValue
my @all_models = (@entity_type_models, @alias_type_models, @other_models);
# Missing: WorkAttributeTypeAllowedValue

sub index : Path('/attributes') Args(0) {
my ($self, $c) = @_;
Expand All @@ -45,6 +60,7 @@ sub index : Path('/attributes') Args(0) {
current_view => 'Node',
component_path => 'attributes/AttributesList',
component_props => {
aliasTypeModels => \@alias_type_models,
entityTypeModels => \@entity_type_models,
otherModels => \@other_models,
},
Expand Down
14 changes: 11 additions & 3 deletions lib/MusicBrainz/Server/Data/Role/AliasType.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@ use namespace::autoclean;
use MusicBrainz::Server::Entity::AliasType;
use MusicBrainz::Server::Data::Utils qw( load_subobjects );

with 'MusicBrainz::Server::Data::Role::OptionsTree';

sub _columns { 'id, gid, name, parent AS parent_id, child_order, description' }
with 'MusicBrainz::Server::Data::Role::OptionsTree',
'MusicBrainz::Server::Data::Role::Attribute';

sub load {
my ($self, @objs) = @_;

load_subobjects($self, 'type', @objs);
}

sub in_use {
my ($self, $id) = @_;
# We can get the alias table by just dropping "_type" from the type table
my $alias_table = $self->_table =~ s/_type$//r;
return $self->sql->select_single_value(
"SELECT 1 FROM $alias_table WHERE type = ? LIMIT 1",
$id);
}

1;

=head1 COPYRIGHT AND LICENSE
Expand Down
5 changes: 5 additions & 0 deletions root/attributes/AttributesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ const AttributeList = ({modelList}: {modelList: Array<string>}) => {
};

type Props = {
+aliasTypeModels: Array<string>,
+entityTypeModels: Array<string>,
+otherModels: Array<string>,
};

const AttributesList = ({
aliasTypeModels,
entityTypeModels,
otherModels,
}: Props): React$Element<typeof Layout> => (
Expand All @@ -45,6 +47,9 @@ const AttributesList = ({
<h2>{l('Entity types')}</h2>
<AttributeList modelList={entityTypeModels} />

<h2>{l('Alias types')}</h2>
<AttributeList modelList={aliasTypeModels} />

<h2>{l('Other attributes')}</h2>
<AttributeList modelList={otherModels} />
</Layout>
Expand Down
24 changes: 24 additions & 0 deletions root/static/scripts/common/utility/attributeModelName.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,50 @@ function attributeModelName(model: string): string {
switch (model) {
case 'AreaType':
return l('Area types');
case 'AreaAliasType':
return l('Area alias types');
case 'ArtistType':
return l('Artist types');
case 'ArtistAliasType':
return l('Artist alias types');
case 'CollectionType':
return l('Collection types');
case 'CoverArtType':
return l('Cover art types');
case 'EventType':
return l('Event types');
case 'EventAliasType':
return l('Event alias types');
case 'Gender':
return l('Genders');
case 'GenreAliasType':
return l('Genre alias types');
case 'InstrumentType':
return l('Instrument types');
case 'InstrumentAliasType':
return l('Instrument alias types');
case 'LabelType':
return l('Label types');
case 'LabelAliasType':
return l('Label alias types');
case 'Language':
return l('Languages');
case 'MediumFormat':
return l('Medium formats');
case 'PlaceType':
return l('Place types');
case 'PlaceAliasType':
return l('Place alias types');
case 'RecordingAliasType':
return l('Recording alias types');
case 'ReleaseAliasType':
return l('Release alias types');
case 'ReleaseGroupSecondaryType':
return l('Release group secondary types');
case 'ReleaseGroupType':
return l('Release group primary types');
case 'ReleaseGroupAliasType':
return l('Release group alias types');
case 'ReleasePackaging':
return l('Release packagings');
case 'ReleaseStatus':
Expand All @@ -43,10 +63,14 @@ function attributeModelName(model: string): string {
return l('Scripts');
case 'SeriesType':
return l('Series types');
case 'SeriesAliasType':
return l('Series alias types');
case 'WorkAttributeType':
return l('Work attribute types');
case 'WorkType':
return l('Work types');
case 'WorkAliasType':
return l('Work alias types');
default:
return model;
}
Expand Down

0 comments on commit 403082f

Please sign in to comment.