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