Skip to content

Commit

Permalink
Use the uri checker for nodes as well
Browse files Browse the repository at this point in the history
  • Loading branch information
melmothx committed Feb 1, 2024
1 parent e62cf67 commit d32fde8
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 70 deletions.
3 changes: 3 additions & 0 deletions lib/AmuseWikiFarm/Controller/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ sub check_existing_uri :Chained('api') :PathPart('check-existing-uri') :Args(0)
elsif ($type eq 'aggregation') {
$exists = $site->aggregations->by_uri($uri)->count;
}
elsif ($type eq 'nodes') {
$exists = $site->nodes->by_uri($uri)->count;
}

if ($exists) {
$out{error} = $c->loc("Such URI already exists");
Expand Down
6 changes: 6 additions & 0 deletions lib/AmuseWikiFarm/Schema/ResultSet/Node.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ sub hri {
return shift->search(undef, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' });
}

sub by_uri {
my ($self, $uri) = @_;
my $me = $self->current_source_alias;
return $self->search({ "$me.uri" => $uri });
}

sub find_by_uri {
my ($self, $uri) = @_;
return unless $uri;
Expand Down
29 changes: 1 addition & 28 deletions root/src/aggregation/edit.tt
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,7 @@
</small>
</div>
<div class="col-sm-3">
<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>
[% INCLUDE 'include/uri-checker.tt' %]
</div>
</div>
[% END %]
Expand Down Expand Up @@ -271,25 +263,6 @@
$('.remove-item').on('click', function() {
$(this).closest('li').remove();
});
$('.ajax-check-uri').on('keyup', function() {
var el = $(this);
var query = {
"uri": el.val(),
"type": el.data('uri-type'),
};
console.log("here");
$.post(el.data('check-target'), query, function(data) {
$('.check-failure').hide();
$('.check-success').hide();
if (data.success) {
$('.check-success').show();
}
else {
$('.check-failure').find('.check-message').text(data.error)
$('.check-failure').show();
}
});
});
function check_series() {
console.log("Checking");
if ($('#aggregation_series_uri').val()) {
Expand Down
29 changes: 1 addition & 28 deletions root/src/aggregation/edit_series.tt
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,7 @@
</small>
</div>
<div class="col-sm-3">
<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>
[% INCLUDE 'include/uri-checker.tt' %]
</div>
</div>
[% END %]
Expand Down Expand Up @@ -114,24 +106,5 @@
<script>
$(document).ready(function(data) {
$('#aggregation-titles').sortable();
$('.ajax-check-uri').on('keyup', function() {
var el = $(this);
var query = {
"uri": el.val(),
"type": el.data('uri-type'),
};
console.log("here");
$.post(el.data('check-target'), query, function(data) {
$('.check-failure').hide();
$('.check-success').hide();
if (data.success) {
$('.check-success').show();
}
else {
$('.check-failure').find('.check-message').text(data.error)
$('.check-failure').show();
}
});
});
});
</script>
31 changes: 31 additions & 0 deletions root/src/include/uri-checker.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="check-uri-success" style="display:none; color:green">
<i class="fa fa-check"></i>
[% loc('URI is available and valid') %]
</div>
<div class="check-uri-failure" style="display:none">
<i class="fa fa-warning" style="color:red">
</i>
<span class="check-uri-message" style="color:red"></span>
</div>
<script>
$(document).ready(function(data) {
$('.ajax-check-uri').on('keyup', function() {
var el = $(this);
var query = {
"uri": el.val(),
"type": el.data('uri-type'),
};
$.post(el.data('check-target'), query, function(data) {
$('.check-uri-failure').hide();
$('.check-uri-success').hide();
if (data.success) {
$('.check-uri-success').show();
}
else {
$('.check-uri-failure').find('.check-uri-message').text(data.error)
$('.check-uri-failure').show();
}
});
});
});
</script>
47 changes: 33 additions & 14 deletions root/src/nodes/node_root.tt
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,64 @@
<h2>[% loc('Create') %]</h2>
</div>
<div class="col-xs-12">
<form method="POST" id="create-node-form" action="[% c.uri_for_action('/nodes/create') %]">
<form method="POST"
class="form-horizontal"
id="create-node-form" action="[% c.uri_for_action('/nodes/create') %]">
<div class="form-group">
<label for="create_node">
<label class="col-sm-2 control-label" for="create_node">
[% loc('URI') %]
([% loc('only lowercase ASCII and hyphens') %])
</label>
<input type="text" name="uri" class="form-control"
id="create_node"
pattern="[a-z0-9][a-z0-9-]*[a-z0-9]" required/>
<div class="col-sm-7">
<input type="text" name="uri"
class="form-control ajax-check-uri"
data-uri-type="nodes"
data-check-target="[% c.uri_for_action('/api/check_existing_uri') | html %]"
id="create_node"
pattern="[a-z0-9][a-z0-9-]*[a-z0-9]" required/>
<small>[% loc('only lowercase ASCII and hyphens') %]</small>

</div>
<div class="col-sm-3">
[% INCLUDE 'include/uri-checker.tt' %]
</div>
</div>
<div class="form-group">
<label for="canonical_title">
<label class="col-sm-2 control-label" for="canonical_title">
[% loc('Title') %]
</label>
<input type="text" name="canonical_title" class="form-control"
id="canonical_title">
<div class="col-sm-10">
<input type="text" name="canonical_title" class="form-control"
id="canonical_title">
</div>
</div>
<div class="form-group">
<label for="parent_node_id">
<label class="col-sm-2 control-label" for="parent_node_id">
[% loc('Parent collection') %]
</label>
<select name="parent_node_uri"
<div class="col-sm-10">
<select name="parent_node_uri"
id="parent_node_uri"
data-preseeded="[% c.request.query_params.node | html %]"
class="form-control">
<option value="0">[% loc('Root Collection') %]</option>
[% FOREACH node IN all_nodes %]
<option value="[% node.uri %]"[% IF node.selected %] selected="selected"[% END %]>[% node.title %]</option>
[% END %]
</select>
</select>
</div>
</div>
<label for="attached_uris">
<div class="form-group">
<label for="attached_uris" class="col-xs-12 text-center">
[% loc('List of paths to attach to this collection, one per line.') %]
</label>
</label>
</div>
<div class="form-group">
<div class="col-xs-12">
<textarea name="attached_uris"
id="attached_uris"
rows="3"
class="form-control">[% c.request.query_params.add_text | html %]</textarea>
</div>
</div>
<div class="form-group center">
<button type="submit" class="btn btn-default">
Expand Down

0 comments on commit d32fde8

Please sign in to comment.