Skip to content

Commit

Permalink
start fleshing out publications
Browse files Browse the repository at this point in the history
  • Loading branch information
pjc09h committed Jun 9, 2024
1 parent d4697d6 commit d17ddeb
Show file tree
Hide file tree
Showing 17 changed files with 632 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Thanks for your interest in improving BioGazelle's codebase.
## General application layout

The core objects all follow the [JSON:API specification format](https://jsonapi.org/format/1.2/) from instantiation.
Relationships can be loaded by type, e.g., `torrentGroups`, and made available to supported clients, e.g., `$app->env->executionContext`.
Relationships can be loaded by type, e.g., `torrentGroups`, and made available to supported clients, e.g., `$app->executionContext`.

### Request timeline breakdown

Expand Down
6 changes: 6 additions & 0 deletions app/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ public function determineId(int|string $id, bool $insteadExtractId = false): str
# cast to string
$id = urldecode(strval($id));

# normal numeric id
$good = preg_match("/{$app->env->regexShortUuid}/i", $id, $matches);
if ($good) {
return (!$insteadExtractId ? "id" : $id);
}

# doi
$good = preg_match("/{$app->env->regexDoi}/i", $id, $matches);
if ($good) {
Expand Down
7 changes: 7 additions & 0 deletions app/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ class LazyCollection extends \Illuminate\Support\LazyCollection
*/
public function __get(mixed $key): mixed
{
$app = App::go();

# native laravel function
$value = $this->get($key);

# do we need to express a canonical id as a uri?
if ($app->executionContext === "api" && $key === "id") {
return "https://{$app->env->siteDomain}/{$value}";
}

# try to decode any json fields that might be present
# (because custom reading is tedious and no longer works)
if (is_string($value)) {
Expand Down
15 changes: 6 additions & 9 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,15 @@
}


# universally resolve an identifier
Flight::route("/@id", function (string $id) {
# universal id finder or not found
Flight::route("*", function () {
$app = Gazelle\App::go();
$redirect = $app->resolveUriById($id);
($redirect) ? Gazelle\Http::redirect($redirect) : $app->error(404);
});

$request = Flight::request();
$id = $request->url ?? null;

# not found
Flight::route("*", function (\flight\net\Route $route) {
$app = Gazelle\App::go();
($app->env->dev) ? !d($route) : $app->error(404);
$redirect = $app->resolveUriById($id);
($redirect) ? Gazelle\Http::redirect($redirect) : $app->error(404);
}, true);


Expand Down
3 changes: 0 additions & 3 deletions routes/web/literature.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@
});


/*
# read: doi
Flight::route("/literature(/@prefix/@suffix)", function ($prefix, $suffix) {
$app = Gazelle\App::go();
$app->middleware(["literature" => "read"]);
require_once "{$app->env->serverRoot}/sections/literature/details.php";
});
*/


# update
Flight::route("/literature/@id/edit", function ($id) {
Expand Down
62 changes: 62 additions & 0 deletions sections/creators/browse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);


/**
* creator search page
*/

$app = Gazelle\App::go();

$get = Gazelle\Http::get();
$manticore = new Gazelle\Manticore("creators");

/** search handling */

$searchResults = $manticore->search($get);
$pagination = $manticore->paginate($searchResults);

# build query string
foreach ($get as $key => $value) {
if (empty($value)) {
unset($get[$key]);
}
}

$queryString = "/creators" . http_build_query($get);
#!d($queryString);

/** info */

$app->debug["time"]->startMeasure("browse", "get creators");

$ids = array_column($searchResults, "id");
$ids = array_slice($ids, $pagination["offset"], $pagination["pageSize"]);

$creators = [];
foreach ($ids as $id) {
$creators[] = new Gazelle\Creators($id);
}

$app->debug["time"]->stopMeasure("browse", "get creators");

/** twig template */

$app->twig->display("creators/browse.twig", [
"title" => "Browse creators",

"css" => [],
"js" => ["browse"],

"manticore" => $manticore,
"creators" => $creators,

"pagination" => $pagination,
"queryString" => $queryString,

/** */

"categories" => $app->env->categories->pluck("title"),
"officialTags" => Gazelle\Tags::getOfficialTags(),
]);
7 changes: 7 additions & 0 deletions sections/literature/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

try {
# is it an id or a doi?
$prefix ??= null;
$suffix ??= null;

if ($prefix && $suffix) {
$id = "{$prefix}/{$suffix}";
}

$id ??= null;
$literature = new Gazelle\Literature($id);

Expand Down
62 changes: 62 additions & 0 deletions sections/publications/browse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);


/**
* publications search page
*/

$app = Gazelle\App::go();

$get = Gazelle\Http::get();
$manticore = new Gazelle\Manticore("publications");

/** search handling */

$searchResults = $manticore->search($get);
$pagination = $manticore->paginate($searchResults);

# build query string
foreach ($get as $key => $value) {
if (empty($value)) {
unset($get[$key]);
}
}

$queryString = "/publications" . http_build_query($get);
#!d($queryString);

/** info */

$app->debug["time"]->startMeasure("browse", "get publications");

$ids = array_column($searchResults, "id");
$ids = array_slice($ids, $pagination["offset"], $pagination["pageSize"]);

$publications = [];
foreach ($ids as $id) {
$publications[] = new Gazelle\Publications($id);
}

$app->debug["time"]->stopMeasure("browse", "get publications");

/** twig template */

$app->twig->display("publications/browse.twig", [
"title" => "Browse publications",

"css" => [],
"js" => ["browse"],

"manticore" => $manticore,
"publications" => $publications,

"pagination" => $pagination,
"queryString" => $queryString,

/** */

"categories" => $app->env->categories->pluck("title"),
"officialTags" => Gazelle\Tags::getOfficialTags(),
]);
47 changes: 47 additions & 0 deletions sections/publications/details.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);


/**
* publication details page
*/

$app = Gazelle\App::go();

try {
$id ??= null;
$publication = new Gazelle\Publications($id);

if (!$publication->id) {
throw new Exception("not found");
}
} catch (Throwable $e) {
$app->error(404);
}

# request variables
$get = Gazelle\Http::request("get");
$post = Gazelle\Http::request("post");

# create a conversation if it doesn't exist
$conversation = Gazelle\Conversations::createIfNotExists($publication->id, "publications");

# twig template
$app->twig->display("publication/details.twig", [
"title" => $publication->attributes->name,
"sidebar" => true,

"css" => [],
"js" => ["conversations"],

"breadcrumbs" => [
"/publications" => "publications",
"/publications/{$publication->id}" => $publication->attributes->name,
],

"publication" => $publication,

"enableConversation" => true,
"conversation" => $conversation,
]);
22 changes: 22 additions & 0 deletions templates/creators/browse.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "base.twig" %}

{% block content %}

<h2>Browse creators</h2>

{# include the main search form #}
{{ include("creators/search.twig") }}

{# no results message #}
{% if pagination.resultCount == 0 %}
<div class="alertbar warning halfwide">
<h3>No search results :(</h3>
<p>Please ensure you didn't make too many typos or apply too many filters.</p>
</div>
{% else %}
{{ include("manticore/pagination.twig") }}
{{ include("tables/creators.twig", {"grouping": "grouping"}) }}
{{ include("manticore/pagination.twig") }}
{% endif %}

{% endblock %}
45 changes: 45 additions & 0 deletions templates/creators/search.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{##
# literature search form
#}

<form id="torrentSearch" name="torrentSearch" method="get">
{# simpleSearch #}
<section id="simpleSearch">
<div id="searchFormHeader">
<h3>Simple search</h3>
<a id="showComplexSearch" class="button button-orange u-pull-right">show complex search</a>
</div>

<table class="torrentSearch">
{{ include("manticore/simpleSearch.twig") }}
</table>
</section>


{# complexSearch #}
<section id="complexSearch">
<div id="searchFormHeader">
<h3>Complex search</h3>
<a id="showSimpleSearch" class="button button-orange u-pull-right">show simple search</a>
</div>

<table class="torrentSearch">
{{ include("manticore/complexSearch.twig") }}
{{ include("manticore/people.twig") }}
{{ include("manticore/places.twig") }}
{{ include("manticore/relationships.twig") }}
</table>
</section>


{# sortOptions #}
<section id="sortOptions">
<h3>Sorting options</h3>

<table class="torrentSearch">
{{ include("manticore/organization.twig") }}
{{ include("manticore/ordering.twig") }}
{{ include("manticore/formControls.twig") }}
</table>
</section>
</form>
22 changes: 22 additions & 0 deletions templates/publications/browse.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "base.twig" %}

{% block content %}

<h2>Browse publications</h2>

{# include the main search form #}
{{ include("publications/search.twig") }}

{# no results message #}
{% if pagination.resultCount == 0 %}
<div class="alertbar warning halfwide">
<h3>No search results :(</h3>
<p>Please ensure you didn't make too many typos or apply too many filters.</p>
</div>
{% else %}
{{ include("manticore/pagination.twig") }}
{{ include("tables/publications.twig", {"grouping": "grouping"}) }}
{{ include("manticore/pagination.twig") }}
{% endif %}

{% endblock %}
Loading

0 comments on commit d17ddeb

Please sign in to comment.