mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-11 14:10:06 +01:00
fix: lots of profile page + search fixes, mostly to do with the paste list
This commit is contained in:
parent
a1cbbc3587
commit
83f4fa56c4
14 changed files with 118 additions and 21 deletions
|
@ -239,6 +239,10 @@ const dumbFilterCallback = (datum, query) => {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (datum.author.toLowerCase().indexOf(queryLower) !== -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* this is inefficient */
|
||||
for (const tag of datum.tags) {
|
||||
if (tag.name.toLowerCase().indexOf(queryLower) !== -1) {
|
||||
|
|
|
@ -27,13 +27,16 @@ whenReady(() => {
|
|||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const myParam = urlParams.get('q');
|
||||
const myPastesElem = document.getElementById('archive');
|
||||
const apiUrl = '/api/user_pastes.php?user_id=' + myPastesElem.dataset.userId;
|
||||
console.log('myPastesElem', myPastesElem);
|
||||
const table = new DataTable(myPastesElem, {
|
||||
ajaxCallback: (resolve) => {
|
||||
resolve({
|
||||
data: Array.prototype.map.call(myPastesElem.querySelectorAll('tbody > tr'), parsePasteInfo)
|
||||
});
|
||||
fetch(apiUrl)
|
||||
.then(r => r.json())
|
||||
.then(resolve);
|
||||
},
|
||||
rowCallback: (rowData) => {
|
||||
console.log('rowData', rowData);
|
||||
const userData = getUserInfo();
|
||||
const ownedByUser = (parseInt(rowData.user_id) === parseInt(userData.userId));
|
||||
|
||||
|
@ -69,6 +72,7 @@ whenReady(() => {
|
|||
|
||||
const faveTable = new DataTable(myFavesElem, {
|
||||
ajaxCallback: (resolve) => {
|
||||
console.log('invoker invoked');
|
||||
resolve({
|
||||
data: Array.prototype.map.call(myFavesElem.querySelectorAll('tbody > tr'), parsePasteInfo)
|
||||
});
|
||||
|
|
51
public/api/user_pastes.php
Normal file
51
public/api/user_pastes.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/** @noinspection PhpDefineCanBeReplacedWithConstInspection */
|
||||
define('IN_PONEPASTE', 1);
|
||||
require_once(__DIR__ .'/../../includes/common.php');
|
||||
|
||||
use PonePaste\Models\Paste;
|
||||
|
||||
header('Content-Type: application/json; charset=UTF-8');
|
||||
|
||||
if (!isset($_GET['user_id'])) {
|
||||
echo json_encode(['error' => 'No user ID provided.']);
|
||||
die();
|
||||
}
|
||||
|
||||
$user_id = (int) $_GET['user_id'];
|
||||
|
||||
$is_current_user = $current_user !== null && $user_id === $current_user->id;
|
||||
|
||||
$pastes = Paste::with([
|
||||
'user' => function($query) {
|
||||
$query->select('users.id', 'username');
|
||||
},
|
||||
'tags' => function($query) {
|
||||
$query->select('tags.id', 'name', 'slug');
|
||||
}
|
||||
])->select(['id', 'user_id', 'title', 'expiry', 'created_at', 'views'])
|
||||
->where('hidden', false)
|
||||
->where('user_id', $user_id)
|
||||
->whereRaw("((expiry IS NULL) OR ((expiry != 'SELF') AND (expiry > NOW())))");
|
||||
|
||||
if (!$is_current_user) {
|
||||
$pastes = $pastes->where('visible', Paste::VISIBILITY_PUBLIC);
|
||||
}
|
||||
|
||||
$pastes = $pastes->get();
|
||||
|
||||
$pastes_json = json_encode(['data' => $pastes->map(function($paste) {
|
||||
return [
|
||||
'id' => $paste->id,
|
||||
'created_at' => $paste->created_at,
|
||||
'title' => $paste->title,
|
||||
'author' => $paste->user->username,
|
||||
'author_id' => $paste->user->id,
|
||||
'views' => $paste->views,
|
||||
'tags' => $paste->tags->map(function($tag) {
|
||||
return ['slug' => $tag->slug, 'name' => $tag->name];
|
||||
})
|
||||
];
|
||||
})]);
|
||||
|
||||
echo $pastes_json;
|
|
@ -284,6 +284,10 @@ const dumbFilterCallback = (datum, query) => {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (datum.author.toLowerCase().indexOf(queryLower) !== -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* this is inefficient */
|
||||
for (const tag of datum.tags) {
|
||||
if (tag.name.toLowerCase().indexOf(queryLower) !== -1) {
|
||||
|
|
2
public/assets/bundle/archive.min.js
vendored
2
public/assets/bundle/archive.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -284,6 +284,10 @@ const dumbFilterCallback = (datum, query) => {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (datum.author.toLowerCase().indexOf(queryLower) !== -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* this is inefficient */
|
||||
for (const tag of datum.tags) {
|
||||
if (tag.name.toLowerCase().indexOf(queryLower) !== -1) {
|
||||
|
@ -552,13 +556,16 @@ whenReady(() => {
|
|||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const myParam = urlParams.get('q');
|
||||
const myPastesElem = document.getElementById('archive');
|
||||
const apiUrl = '/api/user_pastes.php?user_id=' + myPastesElem.dataset.userId;
|
||||
console.log('myPastesElem', myPastesElem);
|
||||
const table = new DataTable(myPastesElem, {
|
||||
ajaxCallback: (resolve) => {
|
||||
resolve({
|
||||
data: Array.prototype.map.call(myPastesElem.querySelectorAll('tbody > tr'), parsePasteInfo)
|
||||
});
|
||||
fetch(apiUrl)
|
||||
.then(r => r.json())
|
||||
.then(resolve);
|
||||
},
|
||||
rowCallback: (rowData) => {
|
||||
console.log('rowData', rowData);
|
||||
const userData = getUserInfo();
|
||||
const ownedByUser = (parseInt(rowData.user_id) === parseInt(userData.userId));
|
||||
|
||||
|
@ -594,6 +601,7 @@ whenReady(() => {
|
|||
|
||||
const faveTable = new DataTable(myFavesElem, {
|
||||
ajaxCallback: (resolve) => {
|
||||
console.log('invoker invoked');
|
||||
resolve({
|
||||
data: Array.prototype.map.call(myFavesElem.querySelectorAll('tbody > tr'), parsePasteInfo)
|
||||
});
|
||||
|
|
2
public/assets/bundle/user_profile.min.js
vendored
2
public/assets/bundle/user_profile.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -43,8 +43,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
goto done;
|
||||
}
|
||||
|
||||
// TODO: Check if the paste has already been reported.
|
||||
|
||||
if (empty($_POST['reason'])) {
|
||||
$error = 'You must provide a report reason.';
|
||||
goto done;
|
||||
|
|
|
@ -100,6 +100,7 @@ input:checked + .slider:before {
|
|||
width: 100%;
|
||||
height: 100vh;
|
||||
overflow: auto;
|
||||
overflow-x: hidden;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 9999;
|
||||
|
|
|
@ -74,12 +74,21 @@ $profile_total_paste_views = Paste::select('views')
|
|||
->where('user_id', $profile_info->id)
|
||||
->sum('views');
|
||||
|
||||
$profile_join_date = $profile_info->created_at;
|
||||
$profile_join_date = $profile_info->created_at->format('Y-m-d');
|
||||
|
||||
$profile_pastes = $profile_info->pastes;
|
||||
$profile_favs = $profile_info->favourites;
|
||||
$is_current_user = ($current_user !== null) && ($profile_info->id == $current_user->id);
|
||||
|
||||
// Pastes filtering
|
||||
$filter_value = '';
|
||||
list($per_page, $current_page) = pp_setup_pagination();
|
||||
|
||||
$total_results = $profile_info->pastes->count();
|
||||
$profile_pastes = $profile_info->pastes()
|
||||
->limit($per_page)
|
||||
->offset($per_page * $current_page)
|
||||
->get();
|
||||
|
||||
updatePageViews();
|
||||
|
||||
$csrf_token = setupCsrfToken();
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
<h1 class="title is-4">Pastes Archive</h1>
|
||||
<form class="table_filterer" method="GET">
|
||||
<label><i class="fa fa-search"></i>
|
||||
<input class="search" type="search" name="q" placeholder="Filter..." value="<?= $filter_value; ?>" />
|
||||
<input class="search" type="search" name="q" placeholder="Filter..." value="<?= pp_html_escape($filter_value); ?>" />
|
||||
</label>
|
||||
<label>
|
||||
Show
|
||||
|
|
|
@ -107,15 +107,31 @@
|
|||
</div>
|
||||
<?php endif;?>
|
||||
<div class="tab-content" id="first-tab">
|
||||
<table id="archive" class="table is-fullwidth is-hoverable">
|
||||
<form class="table_filterer" method="GET">
|
||||
<label><i class="fa fa-search"></i>
|
||||
<input class="search" type="search" name="q" placeholder="Filter..." value="<?= pp_html_escape($filter_value); ?>" />
|
||||
</label>
|
||||
<label>
|
||||
Show
|
||||
<select name="per_page">
|
||||
<option value="10">10</option>
|
||||
<option value="25">25</option>
|
||||
<option value="50">50</option>
|
||||
<option value="100">100</option>
|
||||
</select>
|
||||
per page
|
||||
</label>
|
||||
<button type="submit" class="button js-hidden">Search</button>
|
||||
</form>
|
||||
<table id="archive" class="table is-fullwidth is-hoverable" data-user-id="<?= pp_html_escape($profile_info->id); ?>">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="td-right">Title</th>
|
||||
<th class="td-center">Paste Time</th>
|
||||
<tr class="paginator__sort">
|
||||
<th data-sort-field="title" class="td-right">Title</th>
|
||||
<th data-sort-field="created_at" class="td-center">Paste Time</th>
|
||||
<?php if ($is_current_user) {
|
||||
echo "<th class='td-center'>Visibility</th>";
|
||||
} ?>
|
||||
<th class="td-center">Views</th>
|
||||
<th data-sort-field="views" class="td-center">Views</th>
|
||||
<th class="td-center">Tags</th>
|
||||
<?php if ($is_current_user) {
|
||||
echo "<th class='td-center'>Delete</th>";
|
||||
|
@ -174,7 +190,9 @@
|
|||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<div class="paginator"></div>
|
||||
<div class="paginator">
|
||||
<?= paginate($current_page, $per_page, $total_results) ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($is_current_user) { ?>
|
||||
<div class="tab-content" id="second-tab">
|
||||
|
|
Loading…
Add table
Reference in a new issue