mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-12 06:30:07 +01:00
fix: more user profile fixes
This commit is contained in:
parent
0b6f54b0d6
commit
dfa22dbde1
7 changed files with 28 additions and 18 deletions
|
@ -35,7 +35,7 @@ class Paste extends Model {
|
|||
return $this->hasMany(Report::class);
|
||||
}
|
||||
|
||||
public function replaceTags(array $tags) {
|
||||
public function replaceTags(array $tags) : void {
|
||||
$this->tags()->detach();
|
||||
|
||||
foreach ($tags as $tagName) {
|
||||
|
|
|
@ -38,8 +38,8 @@ whenReady(() => {
|
|||
rowCallback: (rowData) => {
|
||||
console.log('rowData', rowData);
|
||||
const userData = getUserInfo();
|
||||
const ownedByUser = (parseInt(rowData.user_id) === parseInt(userData.userId));
|
||||
|
||||
const ownedByUser = (parseInt(rowData.author_id) === parseInt(userData.userId));
|
||||
console.log(ownedByUser);
|
||||
const deleteElem = ownedByUser ? `<td class="td-center">
|
||||
<form action="/${rowData.id}" method="POST">
|
||||
<input type="hidden" name="delete" value="delete" />
|
||||
|
@ -48,7 +48,7 @@ whenReady(() => {
|
|||
</form>
|
||||
</td>` : '';
|
||||
const pasteCreatedAt = new Date(rowData.created_at).toLocaleString();
|
||||
const pasteVisibility = ownedByUser ? `<td class="td-center">${rowData.visibility}</td>` : '';
|
||||
const pasteVisibility = ownedByUser ? `<td class="td-center">${['Public', 'Unlisted', 'Private'][rowData.visibility]}</td>` : '';
|
||||
|
||||
return `<tr>
|
||||
<td><a href="/${rowData.id}">${escape(rowData.title)}</a></td>
|
||||
|
|
|
@ -23,7 +23,7 @@ $pastes = Paste::with([
|
|||
'tags' => function($query) {
|
||||
$query->select('tags.id', 'name', 'slug');
|
||||
}
|
||||
])->select(['id', 'user_id', 'title', 'expiry', 'created_at', 'views'])
|
||||
])->select(['id', 'user_id', 'title', 'expiry', 'created_at', 'views', 'visible'])
|
||||
->where('hidden', false)
|
||||
->where('user_id', $user_id)
|
||||
->whereRaw("((expiry IS NULL) OR ((expiry != 'SELF') AND (expiry > NOW())))");
|
||||
|
@ -42,6 +42,7 @@ $pastes_json = json_encode(['data' => $pastes->map(function($paste) {
|
|||
'author' => $paste->user->username,
|
||||
'author_id' => $paste->user->id,
|
||||
'views' => $paste->views,
|
||||
'visibility' => $paste->visible,
|
||||
'tags' => $paste->tags->map(function($tag) {
|
||||
return ['slug' => $tag->slug, 'name' => $tag->name];
|
||||
})
|
||||
|
|
|
@ -567,8 +567,8 @@ whenReady(() => {
|
|||
rowCallback: (rowData) => {
|
||||
console.log('rowData', rowData);
|
||||
const userData = getUserInfo();
|
||||
const ownedByUser = (parseInt(rowData.user_id) === parseInt(userData.userId));
|
||||
|
||||
const ownedByUser = (parseInt(rowData.author_id) === parseInt(userData.userId));
|
||||
console.log(ownedByUser);
|
||||
const deleteElem = ownedByUser ? `<td class="td-center">
|
||||
<form action="/${rowData.id}" method="POST">
|
||||
<input type="hidden" name="delete" value="delete" />
|
||||
|
@ -577,7 +577,7 @@ whenReady(() => {
|
|||
</form>
|
||||
</td>` : '';
|
||||
const pasteCreatedAt = new Date(rowData.created_at).toLocaleString();
|
||||
const pasteVisibility = ownedByUser ? `<td class="td-center">${rowData.visibility}</td>` : '';
|
||||
const pasteVisibility = ownedByUser ? `<td class="td-center">${['Public', 'Unlisted', 'Private'][rowData.visibility]}</td>` : '';
|
||||
|
||||
return `<tr>
|
||||
<td><a href="/${rowData.id}">${escape(rowData.title)}</a></td>
|
||||
|
|
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
|
@ -31,6 +31,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
$tab = 'pastes';
|
||||
if ($is_current_user && isset($_GET['tab']) && $_GET['tab'] === 'favourites') {
|
||||
$tab = 'favourites';
|
||||
}
|
||||
?>
|
||||
<main class="bd-main">
|
||||
<div class="bd-side-background"></div>
|
||||
|
@ -101,12 +105,12 @@
|
|||
<br />
|
||||
<div class="tabs">
|
||||
<ul class="tabs-menu">
|
||||
<li class="is-active" data-target="first-tab"><a>My Pastes</a></li>
|
||||
<li data-target="second-tab"><a>Favorites</a></li>
|
||||
<li class="<?= $tab === 'pastes' ? 'is-active' : '' ?>" data-target="first-tab"><a href="?tab=pastes">My Pastes</a></li>
|
||||
<li class="<?= $tab === 'favourites' ? 'is-active' : '' ?>" data-target="second-tab"><a href="?tab=favourites">Favorites</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
<div class="tab-content" id="first-tab">
|
||||
<div class="tab-content<?= $tab === 'favourites' ? ' is-hidden' : '' ?>" id="first-tab">
|
||||
<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); ?>" />
|
||||
|
@ -128,12 +132,12 @@
|
|||
<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) {
|
||||
<?php if ($is_current_user || $can_administrate) {
|
||||
echo "<th class='td-center'>Visibility</th>";
|
||||
} ?>
|
||||
<th data-sort-field="views" class="td-center">Views</th>
|
||||
<th class="td-center">Tags</th>
|
||||
<?php if ($is_current_user) {
|
||||
<?php if ($is_current_user || $can_administrate) {
|
||||
echo "<th class='td-center'>Delete</th>";
|
||||
} ?>
|
||||
</tr>
|
||||
|
@ -195,8 +199,8 @@
|
|||
</div>
|
||||
</div>
|
||||
<?php if ($is_current_user) { ?>
|
||||
<div class="tab-content" id="second-tab">
|
||||
<table id="favs" class="table is-fullwidth is-hoverable">
|
||||
<div class="tab-content<?= $tab === 'pastes' ? ' is-hidden' : '' ?>" id="second-tab">
|
||||
<table id="favs" class="table is-fullwidth is-hoverable<?= $current_page === 'favourites' ? 'is-active' : '' ?>">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="td-right">Title</th>
|
||||
|
@ -254,6 +258,7 @@
|
|||
init() {
|
||||
document.querySelectorAll('.tabs-menu').forEach(tabMenu => {
|
||||
Array.from(tabMenu.children).forEach((child, ind) => {
|
||||
child.querySelector('a').href = 'javascript:void(0);';
|
||||
child.addEventListener('click', () => {
|
||||
tabSystem.toggle(child.dataset.target);
|
||||
});
|
||||
|
@ -265,7 +270,11 @@
|
|||
},
|
||||
toggle(targetId) {
|
||||
document.querySelectorAll('.tab-content').forEach(contentElement => {
|
||||
contentElement.style.display = contentElement.id === targetId ? 'block' : 'none';
|
||||
if (contentElement.id === targetId) {
|
||||
contentElement.classList.remove('is-hidden');
|
||||
} else {
|
||||
contentElement.classList.add('is-hidden');
|
||||
}
|
||||
document.querySelector(`[data-target="${contentElement.id}"]`).classList[contentElement.id === targetId ? 'add' : 'remove']('is-active');
|
||||
})
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue