add claim to userdetails page

This commit is contained in:
xiaomlove
2022-09-05 19:23:10 +08:00
parent d0f120a352
commit 46cbd7209c
8 changed files with 105 additions and 29 deletions

View File

@@ -45,10 +45,10 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
REDIS_HOST=
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=
REDIS_PORT=
REDIS_DB=
REDIS_PORT=6379
REDIS_DB=0
USE_CRON_TRIGGER_CLEANUP=true
@@ -62,7 +62,6 @@ GOOGLE_DRIVE_REFRESH_TOKEN=
GOOGLE_DRIVE_FOLDER_ID=
GEOIP2_DATABASE=
EXAM_PROGRESS_UPDATE_PROBABILITY=20
TRACKER_API_LOCAL_HOST=

View File

@@ -304,4 +304,20 @@ class ClaimRepository extends BaseRepository
'msg' => implode("\n\n", $msg),
];
}
public function buildActionButtons($torrentId, $claimData, $reload = 0): string
{
$buttonHtml = '<button data-action="%s" data-reload="%s" data-confirm="%s" data-claim_id="%s" data-torrent_id="%s" style="width: max-content;display: %s;align-items: center"><img style="margin-right: 4px;" class="staff_%s" src="pic/trans.gif">%s</button>';
$addButton = sprintf($buttonHtml, 'addClaim', $reload, nexus_trans('claim.add_claim_confirm'), $claimData ? $claimData->id : 0, $torrentId, '%s', 'edit', nexus_trans('claim.add_claim'));
$removeButton = sprintf($buttonHtml, 'removeClaim', $reload, nexus_trans('claim.remove_claim_confirm'), $claimData ? $claimData->id : 0, $torrentId, '%s', 'delete', nexus_trans('claim.remove_claim'));
if ($claimData) {
//Only show remove
return sprintf($addButton, 'none') . sprintf($removeButton, 'flex');
} else {
//Only show add
return sprintf($addButton, 'flex') . sprintf($removeButton, 'none');
}
}
}

View File

@@ -28,25 +28,6 @@ if (!empty($_GET['torrent_id'])) {
print("<h1 align=center>".nexus_trans('claim.title_for_user') . "<a href=userdetails.php?id=" . htmlspecialchars($uid) . "><b>&nbsp;".htmlspecialchars($user->username)."</b></a></h1>");
if ($uid == $CURUSER['id']) {
$actionTh = sprintf("<td class='colhead' align='center'>%s</td>", nexus_trans("claim.th_action"));
$actionTd = "<td class='rowfollow nowrap' align='center'><input class='claim-remove' type='button' value='Remove' data-id='%s'></td>";
$confirmMsg = nexus_trans('claim.confirm_give_up');
$removeJs = <<<JS
jQuery("#claim-table").on("click", '.claim-remove', function () {
if (!window.confirm('$confirmMsg')) {
return
}
let params = {action: "removeClaim", params: {id: jQuery(this).attr("data-id")}}
jQuery.post('ajax.php', params, function (response) {
console.log(response)
if (response.ret == 0) {
location.reload()
} else {
window.alert(response.msg)
}
}, 'json')
})
JS;
\Nexus\Nexus::js($removeJs, 'footer', false);
}
} else {
stderr("Invalid parameters", "Require torrent_id or uid");
@@ -73,6 +54,7 @@ print("<tr>
$now = \Carbon\Carbon::now();
$seedTimeRequiredHours = \App\Models\Claim::getConfigStandardSeedTimeHours();
$uploadedRequiredTimes = \App\Models\Claim::getConfigStandardUploadedTimes();
$claimRep = new \App\Repositories\ClaimRepository();
foreach ($list as $row) {
if (
bcsub($row->snatch->seedtime, $row->seed_time_begin) >= $seedTimeRequiredHours * 3600
@@ -82,6 +64,10 @@ foreach ($list as $row) {
} else {
$reached = 'No';
}
$actionTd = '';
if ($actionTh) {
$actionTd = sprintf('<td class="rowfollow nowrap" align="center">%s</td>', $claimRep->buildActionButtons($row->torrent_id, $row, 1));
}
print("<tr>
<td class='rowfollow nowrap' align='center'>" . $row->id . "</td>
<td class='rowfollow' align='left'><a href='userdetails.php?id=" . $row->uid . "'>" . $row->user->username . "</a></td>
@@ -93,7 +79,7 @@ foreach ($list as $row) {
<td class='rowfollow nowrap' align='center'>" . mkprettytime($row->snatch->seedtime - $row->seed_time_begin) . "</td>
<td class='rowfollow nowrap' align='center'>" . mksize($row->snatch->uploaded - $row->uploaded_begin) . "</td>
<td class='rowfollow nowrap' align='center'>" . $reached . "</td>
".sprintf($actionTd, $row->id)."
".$actionTd."
</tr>");
}

View File

@@ -10,7 +10,7 @@ header("Pragma: no-cache" );
//header("Content-Type: text/xml; charset=utf-8");
$torrentRep = new \App\Repositories\TorrentRepository();
$claimRep = new \App\Repositories\ClaimRepository();
$id = intval($_GET['userid'] ?? 0);
$type = $_GET['type'];
if (!in_array($type,array('uploaded','seeding','leeching','completed','incomplete')))
@@ -21,7 +21,8 @@ if(!user_can('torrenthistory') && $id != $CURUSER["id"])
function maketable($res, $mode = 'seeding')
{
global $lang_getusertorrentlistajax,$CURUSER,$smalldescription_main, $lang_functions, $id;
global $torrentRep;
global $torrentRep, $claimRep;
$showActionClaim = false;
switch ($mode)
{
case 'uploaded': {
@@ -82,6 +83,7 @@ function maketable($res, $mode = 'seeding')
$showanonymous = false;
$showtotalsize = false;
$columncount = 8;
$showActionClaim = true;
break;
}
case 'incomplete': {
@@ -115,10 +117,21 @@ function maketable($res, $mode = 'seeding')
->get()
->keyBy('torrentid');
}
if ($showActionClaim) {
$claimData = \App\Models\Claim::query()
->where('uid', $CURUSER['id'])
->whereIn('torrent_id', $torrentIdArr)
->get()
->keyBy('torrent_id');
}
$ret = "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\" width=\"100%\"><tr><td class=\"colhead\" style=\"padding: 0px\">".$lang_getusertorrentlistajax['col_type']."</td><td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_name']."</td><td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_added']."</td>".
($showsize ? "<td class=\"colhead\" align=\"center\"><img class=\"size\" src=\"pic/trans.gif\" alt=\"size\" title=\"".$lang_getusertorrentlistajax['title_size']."\" /></td>" : "").($showsenum ? "<td class=\"colhead\" align=\"center\"><img class=\"seeders\" src=\"pic/trans.gif\" alt=\"seeders\" title=\"".$lang_getusertorrentlistajax['title_seeders']."\" /></td>" : "").($showlenum ? "<td class=\"colhead\" align=\"center\"><img class=\"leechers\" src=\"pic/trans.gif\" alt=\"leechers\" title=\"".$lang_getusertorrentlistajax['title_leechers']."\" /></td>" : "").($showuploaded ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_uploaded']."</td>" : "") . ($showdownloaded ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_downloaded']."</td>" : "").($showratio ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_ratio']."</td>" : "").($showsetime ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_se_time']."</td>" : "").($showletime ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_le_time']."</td>" : "").($showcotime ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_time_completed']."</td>" : "").($showanonymous ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_anonymous']."</td>" : "")."</tr>\n";
$total_size = 0;
($showsize ? "<td class=\"colhead\" align=\"center\"><img class=\"size\" src=\"pic/trans.gif\" alt=\"size\" title=\"".$lang_getusertorrentlistajax['title_size']."\" /></td>" : "").($showsenum ? "<td class=\"colhead\" align=\"center\"><img class=\"seeders\" src=\"pic/trans.gif\" alt=\"seeders\" title=\"".$lang_getusertorrentlistajax['title_seeders']."\" /></td>" : "").($showlenum ? "<td class=\"colhead\" align=\"center\"><img class=\"leechers\" src=\"pic/trans.gif\" alt=\"leechers\" title=\"".$lang_getusertorrentlistajax['title_leechers']."\" /></td>" : "").($showuploaded ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_uploaded']."</td>" : "") . ($showdownloaded ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_downloaded']."</td>" : "").($showratio ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_ratio']."</td>" : "").($showsetime ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_se_time']."</td>" : "").($showletime ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_le_time']."</td>" : "").($showcotime ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_time_completed']."</td>" : "").($showanonymous ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_anonymous']."</td>" : "");
if ($showActionClaim) {
$ret .= sprintf('<td class="colhead" align="center">%s</td>', $lang_functions['std_action']);
}
$ret .= "</tr>";
$total_size = 0;
foreach ($results as $arr)
{
if ($mode == 'uploaded') {
@@ -199,6 +212,11 @@ function maketable($res, $mode = 'seeding')
$ret .= "<td class=\"rowfollow\" align=\"center\">"."". str_replace("&nbsp;", "<br />", gettime($arr['completedat'],false)). "</td>";
if ($showanonymous)
$ret .= "<td class=\"rowfollow\" align=\"center\">".$arr['anonymous']."</td>";
if ($showActionClaim) {
$claim = $claimData->get($arr['torrent']);
$claimButton = $claimRep->buildActionButtons($arr['torrent'], $claim);
$ret .= sprintf('<td class="rowfollow" align="center">%s</td>', $claimButton);
}
$ret .="</tr>\n";
}
@@ -255,7 +273,7 @@ switch ($type)
// Incomplete torrents
case 'incomplete':
{
$res = sql_query("SELECT torrents.id AS torrent, torrents.name AS torrentname, small_descr, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, torrents.added,snatched.uploaded, snatched.downloaded, snatched.leechtime FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='no' AND userid=$id AND torrents.owner != $id ORDER BY snatched.id DESC") or sqlerr();
// $res = sql_query("SELECT torrents.id AS torrent, torrents.name AS torrentname, small_descr, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, torrents.added,snatched.uploaded, snatched.downloaded, snatched.leechtime FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='no' AND userid=$id AND torrents.owner != $id ORDER BY snatched.id DESC") or sqlerr();
$fields = "torrents.id AS torrent, torrents.name AS torrentname, small_descr, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, torrents.added,snatched.uploaded, snatched.downloaded, snatched.leechtime,snatched.seedtime,snatched.uploaded";
$tableWhere = "torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='no' AND userid=$id AND torrents.owner != $id";
$order = "snatched.id DESC";

43
public/js/nexus.js vendored
View File

@@ -103,4 +103,47 @@ jQuery(document).ready(function () {
imgList.forEach(img => io.observe(img))
}
//claim
jQuery("body").on("click", "[data-claim_id]", function () {
let _this = jQuery(this)
let box = _this.closest('td')
let claimId = _this.attr("data-claim_id")
let torrentId = _this.attr("data-torrent_id")
let action = _this.attr("data-action")
let reload = _this.attr("data-reload")
let confirmText = _this.attr("data-confirm")
let showStyle = "width: max-content;display: flex;align-items: center";
let hideStyle = "width: max-content;display: none;align-items: center";
let params = {}
if (claimId > 0) {
params.id = claimId
} else {
params.torrent_id = torrentId
}
let modalConfig = {title: "Info", btn: ['OK', 'Cancel'], btnAlign: 'c'}
layer.confirm(confirmText, modalConfig, function (confirmIndex) {
jQuery.post("ajax.php", {"action": action, params: params}, function (response) {
console.log(response)
if (response.ret != 0) {
layer.alert(response.msg, modalConfig)
return
}
if (reload > 0) {
window.location.reload();
return;
}
if (claimId > 0) {
//do remove, show add
box.find("[data-action=addClaim]").attr("style", showStyle).attr("data-claim_id", 0)
box.find("[data-action=removeClaim]").attr("style", hideStyle)
} else {
//do add, show remove, update claim_id
box.find("[data-action=addClaim]").attr("style", hideStyle)
box.find("[data-action=removeClaim]").attr("style", showStyle).attr("data-claim_id", response.data.id)
}
layer.close(confirmIndex)
}, "json")
})
})
})

View File

@@ -25,4 +25,8 @@ return [
'claim_unreached_summary' => 'Deduct bonus every unreached torrent<b>:deduct_per_torrent</b>, total deduct: <b>:deduct_total</b>',
'confirm_give_up' => 'Are you sure you want to give up claiming this torrent?',
'add_claim' => 'Claim',
'add_claim_confirm' => 'Confirm to claim?',
'remove_claim' => 'Give up',
'remove_claim_confirm' => 'Confirm to give up the claim?',
];

View File

@@ -25,4 +25,8 @@ return [
'claim_unreached_summary' => '未达标每个种子扣除魔力:<b>:deduct_per_torrent</b>,总扣除魔力:<b>:deduct_total</b>',
'confirm_give_up' => '确定要放弃认领此种子吗?',
'add_claim' => '认领',
'add_claim_confirm' => '确认要认领?',
'remove_claim' => '放弃',
'remove_claim_confirm' => '确认要放弃认领?',
];

View File

@@ -22,4 +22,10 @@ return [
'claim_unreached_remain_counts' => '未達標保留數:<b>:counts</b>',
'claim_unreached_remove_counts' => '未達標刪除數:<b>:counts</b>',
'claim_unreached_summary' => '未達標每個種子扣除魔力:<b>:deduct_per_torrent</b>,總扣除魔力:<b>:deduct_total</b>',
'confirm_give_up' => '確定要放棄認領此種子嗎?',
'add_claim' => '認領',
'add_claim_confirm' => '確認要認領?',
'remove_claim' => '放棄',
'remove_claim_confirm' => '確認要放棄認領?',
];