Skip to content

Commit

Permalink
Create UI for URI rename
Browse files Browse the repository at this point in the history
Address #392
  • Loading branch information
melmothx committed Apr 30, 2022
1 parent 0027e30 commit bec8c4e
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/AmuseWikiFarm/Controller/Console.pm
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,13 @@ Display the aliases

sub alias_display :Chained('alias') :PathPart('') :Args(0) {
my ($self, $c) = @_;
my $site = $c->stash->{site};
$c->stash(
page_title => $c->loc('Redirections'),
redirections => [ $c->stash->{aliases}->all ],
author_list => [ $c->stash->{site}->my_authors ],
topic_list => [ $c->stash->{site}->my_topics ],
author_list => [ $site->my_authors ],
topic_list => [ $site->my_topics ],
uri_list => $site->my_title_uris,
);
}

Expand Down Expand Up @@ -261,6 +263,10 @@ sub alias_create :Chained('alias') :PathPart('create') :Args(0) {
$c->response->redirect($c->uri_for_action('/console/alias_display'));
}

sub rename_uri :Chained('root') :PathPart('rename-uri') :Args(0) {
my ($self, $c) = @_;
}

sub translations :Chained('root') :PathPart('translations') :Args(0) {
my ($self, $c) = @_;
my $site = $c->stash->{site};
Expand Down
15 changes: 15 additions & 0 deletions lib/AmuseWikiFarm/Schema/Result/Site.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3109,6 +3109,21 @@ sub my_authors {
return $self->categories->by_type('author');
}

sub my_title_uris {
my $self = shift;
my $rs = $self->titles->status_is_published_or_deferred->search(undef,
{
columns => [qw/id title uri f_class/],
order_by => [qw/f_class uri/],
});
my @out;
while (my $title = $rs->next) {
push @out, { id => $title->id, uri => $title->full_uri };
}
return \@out;
}


=head2 update_from_params(\%params)
If the params is valid, perform an update, otherwise return the error.
Expand Down
71 changes: 71 additions & 0 deletions root/src/console/alias_display.tt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,57 @@ Text...
here') %].
</p>

<h3>[% loc('Rename text URI') %]</h3>

<form id="rename-uri"
action="[% c.uri_for_action('/console/rename_uri') %]"
role="form"
method="POST">
<div class="form-inline">
<div class="form-group">
<label for="rename_from">[% loc('URI') %]</label>
<select class="form-control" name="rename_from" id="rename_from" style="width: 200px">
<option value="">[% loc('Please select') %]</option>
[% FOREACH uri IN uri_list %]
<option value="[% uri.id %]">[% uri.uri | html %]</option>
[% END %]
</select>
</select>
<div class="form-group">
<i class="fa fa-arrow-right"></i>
</div>
<div class="form-group">
<input class="form-control ajax-check-uri" type="text" name="rename_to" id="rename_to" pattern="[a-z0-9-]+"
onCopy="return false"
onDrag="return false"
onDrop="return false"
onPaste="return false"
autocomplete=off
required/>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">
[% loc('Rename') %]
</button>
</div>
</div>
</div>
<div style="margin-top: 10px">
<div class="check-success" style="display:none; color:green">
<i class="fa fa-check"></i>
[% loc('URI is available and valid') %]
</div>
<div class="check-failure" style="display:none">
<i class="fa fa-warning" style="color:red">
</i>
<span class="check-message" style="color:red"></span>
<div class="help-block">
[% loc('URI should be be an ASCII string, separated by hyphens, without spaces. E.g. my-author-title-1') %]
</div>
</div>
</div>
</form>

<h3>[% loc('Create an author alias') %]</h3>

<form id="alias-create-author"
Expand Down Expand Up @@ -147,5 +198,25 @@ Text...
$("#topic-src").select2();
$("#author-dest").select2();
$("#author-src").select2();
$("#rename_from").select2();
$('.ajax-check-uri').on('keyup', function() {
var el = $(this);
var query = { uri: el.val() };
button = el.closest('form').find('button');
button.prop('disabled', true);
$.post("[% c.uri_for_action('/api/check_existing_uri') %]", query, function(data) {
$('.check-failure').hide();
$('.check-success').hide();
button.prop('disabled', true);
if (data.success) {
$('.check-success').show();
button.prop('disabled', false);
}
else {
$('.check-failure').find('.check-message').text(data.error)
$('.check-failure').show();
}
});
});
});
</script>

0 comments on commit bec8c4e

Please sign in to comment.