Further improve tracking addition feedback
This commit is contained in:
parent
fa52d5cd17
commit
8fb7188bc9
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "fwdekker/death-notifier",
|
||||
"description": "Get notified when a famous person dies.",
|
||||
"version": "0.11.0", "_comment_version": "Also update version in `package.json`!",
|
||||
"version": "0.11.1", "_comment_version": "Also update version in `package.json`!",
|
||||
"type": "project",
|
||||
"license": "MIT",
|
||||
"homepage": "https://git.fwdekker.com/tools/death-notifier",
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "death-notifier",
|
||||
"version": "0.11.0", "_comment_version": "Also update version in `composer.json`!",
|
||||
"version": "0.11.1", "_comment_version": "Also update version in `composer.json`!",
|
||||
"description": "Get notified when a famous person dies.",
|
||||
"author": "Florine W. Dekker",
|
||||
"browser": "dist/bundle.js",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// @ts-ignore
|
||||
const {$, $a, doAfterLoad, footer, header, nav} = window.fwdekker;
|
||||
|
||||
import {csrfToken, emptyFunction, getApi, postApi, sharedMessageElement} from "./API";
|
||||
import {csrfToken, emptyFunction, getApi, postApi, ServerResponse, sharedMessageElement} from "./API";
|
||||
import {CustomEventHandler} from "./CustomEventHandler";
|
||||
import {clearMessage, clearMessages, showError, showInfo, showSuccess, showWarning} from "./Message";
|
||||
|
||||
|
@ -552,9 +552,19 @@ doAfterLoad(() => {
|
|||
person_name: $("#addTrackingPersonName").value,
|
||||
},
|
||||
addTrackingForm,
|
||||
() => {
|
||||
(response: ServerResponse) => {
|
||||
addTrackingForm.reset();
|
||||
refreshTrackings();
|
||||
|
||||
showSuccess(
|
||||
$("#addTrackingFormValidationInfo"),
|
||||
response.payload["renamed"]
|
||||
? (
|
||||
`Successfully added <b>${response.payload["input"]}</b> as ` +
|
||||
`<b>${response.payload["name"]}</b>!`
|
||||
)
|
||||
: `Successfully added <b>${response.payload["name"]}</b>!`
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -95,7 +95,6 @@ class TrackingManager
|
|||
*/
|
||||
public function add_tracking(string $user_uuid, string $person_name): Response
|
||||
{
|
||||
// TODO: Add "partially satisfied" response if normalized name is added, to prevent confusion
|
||||
$info = $this->mediawiki->query_statuses([$person_name]);
|
||||
$normalized_name = $info->redirects[$person_name];
|
||||
$status = $info->results[$normalized_name]["status"];
|
||||
|
@ -103,59 +102,64 @@ class TrackingManager
|
|||
|
||||
if (in_array($normalized_name, $info->missing))
|
||||
return Response::unsatisfied(
|
||||
"Wikipedia does not have an article about " . htmlentities($person_name) . ".",
|
||||
"Wikipedia does not have an article about " .
|
||||
"<b><a href='https://en.wikipedia.org/wiki/Special:Search?search=" .
|
||||
rawurlencode($normalized_name) . "'>" . htmlentities($person_name) . "</a></b>.",
|
||||
"person_name"
|
||||
);
|
||||
if ($type === ArticleType::Disambiguation)
|
||||
return Response::unsatisfied(
|
||||
"<a href='https://en.wikipedia.org/wiki/" . rawurlencode($normalized_name) . "'>" .
|
||||
htmlentities($normalized_name) .
|
||||
"</a> refers to multiple articles. " .
|
||||
"<a href='https://en.wikipedia.org/wiki/" . rawurlencode($normalized_name) . "'>" .
|
||||
"Check Wikipedia" .
|
||||
"</a> to see if the right article is listed.",
|
||||
"<b><a href='https://en.wikipedia.org/wiki/" . rawurlencode($normalized_name) . "'>" .
|
||||
htmlentities($normalized_name) . "</a></b> refers to multiple articles. " .
|
||||
"<a href='https://en.wikipedia.org/wiki/" . rawurlencode($normalized_name) . "'>Check Wikipedia</a> " .
|
||||
"to see if the right article is listed.",
|
||||
"person_name"
|
||||
);
|
||||
if ($type === ArticleType::Other)
|
||||
return Response::unsatisfied(
|
||||
"The Wikipedia article about " .
|
||||
"<a href='https://en.wikipedia.org/wiki/" . rawurlencode($normalized_name) . "'>" .
|
||||
htmlentities($normalized_name) .
|
||||
"</a> is not about a person.",
|
||||
"<b><a href='https://en.wikipedia.org/wiki/" . rawurlencode($normalized_name) . "'>" .
|
||||
htmlentities($normalized_name) . "</a></b> is not about a person.",
|
||||
"person_name"
|
||||
);
|
||||
|
||||
// Insert person and tracking
|
||||
return Database::transaction($this->conn, function () use ($user_uuid, $normalized_name, $status) {
|
||||
$stmt = $this->conn->prepare("SELECT EXISTS(SELECT 1
|
||||
FROM trackings
|
||||
WHERE user_uuid=:uuid AND person_name=:name);");
|
||||
$stmt->bindValue(":uuid", $user_uuid);
|
||||
$stmt->bindValue(":name", $normalized_name);
|
||||
$stmt->execute();
|
||||
if ($stmt->fetch()[0] === 1)
|
||||
return Response::unsatisfied(
|
||||
"You are already tracking " . htmlentities($normalized_name) . ".",
|
||||
"person_name"
|
||||
);
|
||||
return Database::transaction(
|
||||
$this->conn,
|
||||
function () use ($user_uuid, $person_name, $normalized_name, $status) {
|
||||
$stmt = $this->conn->prepare("SELECT EXISTS(SELECT 1
|
||||
FROM trackings
|
||||
WHERE user_uuid=:uuid AND person_name=:name);");
|
||||
$stmt->bindValue(":uuid", $user_uuid);
|
||||
$stmt->bindValue(":name", $normalized_name);
|
||||
$stmt->execute();
|
||||
if ($stmt->fetch()[0] === 1)
|
||||
return Response::unsatisfied(
|
||||
"You are already tracking " . htmlentities($normalized_name) . ".",
|
||||
"person_name"
|
||||
);
|
||||
|
||||
$stmt = $this->conn->prepare("INSERT OR IGNORE INTO people (name) VALUES (:name);");
|
||||
$stmt->bindValue(":name", $normalized_name);
|
||||
$stmt->execute();
|
||||
$stmt = $this->conn->prepare("INSERT OR IGNORE INTO people (name) VALUES (:name);");
|
||||
$stmt->bindValue(":name", $normalized_name);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt = $this->conn->prepare("UPDATE people SET status=:status WHERE name=:name;");
|
||||
$stmt->bindValue(":name", $normalized_name);
|
||||
$stmt->bindValue(":status", $status->value);
|
||||
$stmt->execute();
|
||||
$stmt = $this->conn->prepare("UPDATE people SET status=:status WHERE name=:name;");
|
||||
$stmt->bindValue(":name", $normalized_name);
|
||||
$stmt->bindValue(":status", $status->value);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt = $this->conn->prepare("INSERT OR IGNORE INTO trackings (user_uuid, person_name)
|
||||
$stmt = $this->conn->prepare("INSERT OR IGNORE INTO trackings (user_uuid, person_name)
|
||||
VALUES (:user_uuid, :person_name);");
|
||||
$stmt->bindValue(":user_uuid", $user_uuid);
|
||||
$stmt->bindValue(":person_name", $normalized_name);
|
||||
$stmt->execute();
|
||||
$stmt->bindValue(":user_uuid", $user_uuid);
|
||||
$stmt->bindValue(":person_name", $normalized_name);
|
||||
$stmt->execute();
|
||||
|
||||
return Response::satisfied();
|
||||
});
|
||||
return Response::satisfied([
|
||||
"name" => $normalized_name,
|
||||
"input" => $person_name,
|
||||
"renamed" => $person_name !== $normalized_name
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue