mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-12 06:30:07 +01:00
Deduplicate some JS
This commit is contained in:
parent
85d411fd12
commit
02715158d3
4 changed files with 39 additions and 61 deletions
|
@ -1,5 +1,6 @@
|
|||
import { escape, whenReady } from './dom';
|
||||
import { DataTable, dumbFilterCallback } from './data_tables';
|
||||
import { tagsToHtml } from "./utils";
|
||||
import { globalSetup } from './main';
|
||||
|
||||
whenReady(() => {
|
||||
|
@ -16,27 +17,10 @@ whenReady(() => {
|
|||
.then(resolve);
|
||||
},
|
||||
rowCallback: (rowData) => {
|
||||
const tags = rowData.tags.map((tagData) => {
|
||||
let tagColorClass;
|
||||
if (tagData.name.indexOf('nsfw') !== -1) {
|
||||
tagColorClass = 'is-danger';
|
||||
} else if (tagData.name.indexOf('safe') !== -1) {
|
||||
tagColorClass = 'is-success';
|
||||
} else if (tagData.name.indexOf('/') !== -1) {
|
||||
tagColorClass = 'is-primary';
|
||||
} else {
|
||||
tagColorClass = 'is-info';
|
||||
}
|
||||
|
||||
return `<a href="/archive?q=${tagData.slug}">
|
||||
<span class="tag ${tagColorClass}">${escape(tagData.name)}</span>
|
||||
</a>`;
|
||||
}).join('');
|
||||
|
||||
return `<tr>
|
||||
<td><a href="/${rowData.id}">${escape(rowData.title)}</a></td>
|
||||
<td><a href="/user/${escape(rowData.author)}">${escape(rowData.author)}</a></td>
|
||||
<td>${tags}</td>
|
||||
<td>${tagsToHtml(rowData.tags)}</td>
|
||||
</tr>`;
|
||||
},
|
||||
filterCallback: dumbFilterCallback,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { escape, whenReady } from './dom';
|
||||
import { DataTable, dumbFilterCallback } from './data_tables';
|
||||
import { tagsToHtml } from "./utils";
|
||||
import { globalSetup } from './main';
|
||||
|
||||
const getUserInfo = () => {
|
||||
|
@ -33,39 +34,23 @@ whenReady(() => {
|
|||
});
|
||||
},
|
||||
rowCallback: (rowData) => {
|
||||
const tags = rowData.tags.map((tagData) => {
|
||||
let tagColorClass;
|
||||
if (tagData.name.indexOf('nsfw') !== -1) {
|
||||
tagColorClass = 'is-danger';
|
||||
} else if (tagData.name.indexOf('safe') !== -1) {
|
||||
tagColorClass = 'is-success';
|
||||
} else if (tagData.name.indexOf('/') !== -1) {
|
||||
tagColorClass = 'is-primary';
|
||||
} else {
|
||||
tagColorClass = 'is-info';
|
||||
}
|
||||
|
||||
return `<a href="/archive?q=${tagData.slug}">
|
||||
<span class="tag ${tagColorClass}">${escape(tagData.name)}</span>
|
||||
</a>`;
|
||||
}).join('');
|
||||
|
||||
const userData = getUserInfo();
|
||||
|
||||
const deleteElem = true ? `<td>
|
||||
const deleteElem = true ? `<td class="td-center">
|
||||
<form action="/${rowData.id}" method="POST">
|
||||
<input type="hidden" name="delete" value="delete" />
|
||||
<input type="hidden" name="csrf_token" value="${userData.csrfToken}" />
|
||||
<input type="submit" value="Delete" />
|
||||
</form>
|
||||
</td>` : '';
|
||||
const pasteCreatedAt = new Date(rowData.created_at).toLocaleString();
|
||||
|
||||
return `<tr>
|
||||
<td><a href="/${rowData.id}">${escape(rowData.title)}</a></td>
|
||||
<td>${rowData.created_at}</td>
|
||||
<td>${rowData.visibility}</td>
|
||||
<td>${rowData.views || 0}</td>
|
||||
<td>${tags}</td>
|
||||
<td class="td-center">${pasteCreatedAt}</td>
|
||||
<td class="td-center">${rowData.visibility}</td>
|
||||
<td class="td-center">${rowData.views || 0}</td>
|
||||
<td>${tagsToHtml(rowData.tags)}</td>
|
||||
${deleteElem}
|
||||
</tr>`;
|
||||
},
|
||||
|
@ -87,33 +72,17 @@ whenReady(() => {
|
|||
});
|
||||
},
|
||||
rowCallback: (rowData) => {
|
||||
const tags = rowData.tags.map((tagData) => {
|
||||
let tagColorClass;
|
||||
if (tagData.name.indexOf('nsfw') !== -1) {
|
||||
tagColorClass = 'is-danger';
|
||||
} else if (tagData.name.indexOf('safe') !== -1) {
|
||||
tagColorClass = 'is-success';
|
||||
} else if (tagData.name.indexOf('/') !== -1) {
|
||||
tagColorClass = 'is-primary';
|
||||
} else {
|
||||
tagColorClass = 'is-info';
|
||||
}
|
||||
|
||||
return `<a href="/archive?q=${tagData.slug}">
|
||||
<span class="tag ${tagColorClass}">${escape(tagData.name)}</span>
|
||||
</a>`;
|
||||
}).join('');
|
||||
|
||||
const recentUpdate = rowData.recently_updated ?
|
||||
`<i class='far fa-check-square fa-lg' aria-hidden='true'></i>` :
|
||||
`<i class='far fa-minus-square fa-lg' aria-hidden='true'></i>`;
|
||||
const pasteFavedAt = new Date(rowData.favourited_at).toLocaleString();
|
||||
|
||||
// <td><a href="/user/${escape(rowData.author)}">${escape(rowData.author)}</a></td>
|
||||
return `<tr>
|
||||
<td><a href="/${rowData.id}">${escape(rowData.title)}</a></td>
|
||||
<td>${rowData.favourited_at}</td>
|
||||
<td>${recentUpdate}</td>
|
||||
<td>${tags}</td>
|
||||
<td class="td-center">${pasteFavedAt}</td>
|
||||
<td class="td-center">${recentUpdate}</td>
|
||||
<td>${tagsToHtml(rowData.tags)}</td>
|
||||
</tr>`;
|
||||
},
|
||||
filterCallback: dumbFilterCallback
|
||||
|
|
23
js/utils.js
Normal file
23
js/utils.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { escape } from "./dom";
|
||||
|
||||
const tagsToHtml = (tags) => {
|
||||
|
||||
return tags.map(tagData => {
|
||||
let tagColorClass;
|
||||
if (tagData.name.indexOf('nsfw') !== -1) {
|
||||
tagColorClass = 'is-danger';
|
||||
} else if (tagData.name.indexOf('safe') !== -1) {
|
||||
tagColorClass = 'is-success';
|
||||
} else if (tagData.name.indexOf('/') !== -1) {
|
||||
tagColorClass = 'is-primary';
|
||||
} else {
|
||||
tagColorClass = 'is-info';
|
||||
}
|
||||
|
||||
return `<a href="/archive?q=${tagData.slug}">
|
||||
<span class="tag ${tagColorClass}">${escape(tagData.name)}</span>
|
||||
</a>`;
|
||||
}).join('');
|
||||
};
|
||||
|
||||
export { tagsToHtml };
|
|
@ -132,7 +132,9 @@
|
|||
<?php if ($is_current_user || $paste->visible == Paste::VISIBILITY_PUBLIC): ?>
|
||||
<tr data-paste-info="<?= pp_html_escape(json_encode($pasteJson)); ?>">
|
||||
<td><a href="<?= urlForPaste($paste) ?>" title="<?= $escaped_title ?>"><?= $escaped_title ?></a></td>
|
||||
<td data-sort="<?= $p_date->format('U') ?>" class="td-center"><?= $p_date->format('d F Y') ?></td>
|
||||
<td data-sort="<?= $p_date->format('U') ?>" class="td-center">
|
||||
<?= $p_date->format('d F Y') ?>
|
||||
</td>
|
||||
<td class="td-center"><?= $p_visible; ?></td>
|
||||
<td class="td-center"><?= $paste->views ?></td>
|
||||
<td class="td-left"><?= tagsToHtmlUser($paste->tags, $profile_username); ?></td>
|
||||
|
|
Loading…
Add table
Reference in a new issue