Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add sort in user timeline card #2061

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions resource/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,26 @@
},
"updateat": "Update at: ",
"user": {
"uploads": "Uploads: ",
"uploaded": "Uploaded: ",
"downloaded": "Downloaded: ",
"seedingSize": "Seeding size: ",
"averageSeedtime": "Average Seedtime: {day} day(s)",
"ratio": "Ratio: ",
"bonus": "Bonus: ",
"bonusPerHour": "Bonus per hour: "
"colonSeparator": ": ",
"uploads": "Uploads",
"uploaded": "Uploaded",
"downloaded": "Downloaded",
"seedingSize": "Seeding size",
"averageSeedtime": "Average Seedtime(Day)",
"ratio": "Ratio",
"bonus": "Bonus",
"bonusPerHour": "Bonus per hour"
},
"sortSites": {
"name": "Sort Sites",
"key": {
"label": "Sort By"
},
"order": {
"label": "Sort Order",
"asc": "ascending",
"dsc": "descending"
}
},
"inputDisplayName": "Please enter a name to display:",
"inputShareMessage": "Please enter a message to display:"
Expand Down
29 changes: 21 additions & 8 deletions resource/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,27 @@
},
"updateat": "数据更新于:",
"user": {
"uploads": "发布数:",
"uploaded": "上传量:",
"downloaded": "下载量:",
"seedingSize": "做种量:",
"averageSeedtime": "均保时:{day} 天",
"ratio": "分享率:",
"bonus": "积分值:",
"bonusPerHour": "时 魔:"
"colonSeparator": ":",
"uploads": "发布数",
"uploaded": "上传量",
"downloaded": "下载量",
"seedingSize": "做种量",
"averageSeedtime": "均保时(天)",
"ratio": "分享率",
"bonus": "积分值",
"bonusPerHour": "时 魔",
"joinTime": "加入时间"
},
"sortSites": {
"name": "站点排序",
"key": {
"label": "排序依据"
},
"order": {
"label": "排序方式",
"asc": "正序",
"dsc": "倒序"
}
},
"inputDisplayName": "请输入需要显示的名称:",
"inputShareMessage": "请输入需要显示的信息:"
Expand Down
1 change: 0 additions & 1 deletion src/interface/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ export interface Site {
apiCdn?: string[];
getInfoAjaxCache?: boolean;
}

/**
* desc & href 都不为空才被认为是有效链接
* href 必须是网址
Expand Down
97 changes: 77 additions & 20 deletions src/options/views/UserDataTimeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@
<div>
<v-divider v-if="i>0" class="mb-2"></v-divider>
<div class="headline font-weight-light mb-2" v-if="showSiteName">{{ site.name }}</div>
<div v-if="showUserUploads && site.user.uploads && site.user.uploads > 0">{{ $t('timeline.user.uploads') }}{{ site.user.uploads }}</div>
<div>{{ $t('timeline.user.uploaded') }}{{ site.user.uploaded | formatSize}}</div>
<div>{{ $t('timeline.user.downloaded') }}{{ site.user.downloaded | formatSize }}</div>
<div>{{ $t('timeline.user.ratio') }}{{ site.user.ratio | formatRatio }}</div>
<div>{{ $t('timeline.user.seedingSize') }}{{ site.user.seedingSize | formatSize }} ({{ site.user.seeding }})</div>
<div v-if="site.user.averageSeedtime && site.user.averageSeedtime > 0">{{ $t('timeline.user.averageSeedtime', {day: site.user.averageSeedtime | formatInteger}) }}</div>
<div>{{ $t('timeline.user.bonus') }}{{ site.user.bonus | formatNumber }}</div>
<div v-if="site.user.bonusPerHour && site.user.bonusPerHour != 'N/A'">{{ $t('timeline.user.bonusPerHour') }}{{ site.user.bonusPerHour | formatNumber }}</div>
<div v-if="showUserUploads && site.user.uploads && site.user.uploads > 0">{{ $t('timeline.user.uploads') }}{{$t('timeline.user.colonSeparator')}}{{ site.user.uploads }}</div>
<div>{{ $t('timeline.user.uploaded') }}{{$t('timeline.user.colonSeparator')}}{{ site.user.uploaded | formatSize}}</div>
<div>{{ $t('timeline.user.downloaded') }}{{$t('timeline.user.colonSeparator')}}{{ site.user.downloaded | formatSize }}</div>
<div>{{ $t('timeline.user.ratio') }}{{$t('timeline.user.colonSeparator')}}{{ site.user.ratio | formatRatio }}</div>
<div>{{ $t('timeline.user.seedingSize') }}{{$t('timeline.user.colonSeparator')}}{{ site.user.seedingSize | formatSize }} ({{ site.user.seeding }})</div>
<div v-if="site.user.averageSeedtime && site.user.averageSeedtime > 0">{{ $t('timeline.user.averageSeedtime') }}{{$t('timeline.user.colonSeparator')}}{{ site.user.averageSeedtime | formatInteger }}</div>
<div>{{ $t('timeline.user.bonus') }}{{$t('timeline.user.colonSeparator')}}{{ site.user.bonus | formatNumber }}</div>
<div v-if="site.user.bonusPerHour && site.user.bonusPerHour != 'N/A'">{{ $t('timeline.user.bonusPerHour') }}{{$t('timeline.user.colonSeparator')}}{{ site.user.bonusPerHour | formatNumber }}</div>
</div>
</v-timeline-item>
</v-timeline>
Expand Down Expand Up @@ -220,12 +220,42 @@
></v-switch>
</v-flex>
</v-layout>
<v-divider />
<!-- 排序 -->
<h1 style="padding: 5px;">{{ $t('timeline.sortSites.name') }}</h1>
<!-- SortBy-->
<h2 style="padding: 7px;">{{ $t('timeline.sortSites.key.label') }}</h2>
<v-radio-group v-model="siteSortBy" row class="ml-5">

<v-radio v-for="(key, i) in siteSortKeys" :key="i"
:label="$t('timeline.user.'+key)" color="success" :value="key"
></v-radio>
</v-radio-group>
<!-- sort order-->
<h2 style="padding: 7px;">{{ $t('timeline.sortSites.order.label') }}</h2>
<v-radio-group v-model="siteSortOrder" row class="ml-5">
<v-radio
:label="$t('timeline.sortSites.order.asc')" color="success" value="asc"
></v-radio>
<v-radio
:label="$t('timeline.sortSites.order.dsc')" color="success" value="dsc"
></v-radio>
</v-radio-group>
</div>
</div>
</template>
<script lang="ts">
import Vue from "vue";
import {Site, Dictionary, EAction, Options, EViewKey, ETagType, EUserDataRequestStatus} from "@/interface/common";
import {
Site,
Dictionary,
EAction,
Options,
EViewKey,
ETagType,
EUserDataRequestStatus,
UserInfo
} from "@/interface/common";
import FileSaver from "file-saver";
import domtoimage from 'dom-to-image';
import Extension from "@/service/extension";
Expand Down Expand Up @@ -297,6 +327,9 @@ export default Vue.extend({
showUserLevel: true,
showUserUploads: true,
showUid: true,
siteSortKeys: ["joinTime", "uploaded", "seedingSize", "ratio"],
siteSortBy: "joinTime",
siteSortOrder: "asc",
blurSiteIcon: true,
iconCache: {} as Dictionary<any>
};
Expand All @@ -320,6 +353,14 @@ export default Vue.extend({
}
}
},
watch: {
siteSortBy(newVal) {
this.datas = this.sortSitesByUserInfo(this.datas, newVal, this.siteSortOrder == "asc")
},
siteSortOrder(newVal) {
this.datas = this.sortSitesByUserInfo(this.datas, this.siteSortBy, newVal == "asc")
}
},
methods: {
filteredSitesByTags(sites: Site[]) {
if (this.selectedTagValues.length === 0) return sites
Expand Down Expand Up @@ -535,24 +576,40 @@ export default Vue.extend({
.diff(result.joinTimeInfo.time, "year", true)
.toFixed(2);
}

this.infos = result;

// 按加入时间排序
this.datas = sites.sort((a, b) => {
this.datas = this.sortSitesByUserInfo(sites, this.siteSortBy, this.siteSortOrder == "asc")

console.log(this.datas)

this.infos.total.ratio = this.getRatio(this.infos.total);

if (!a.user || !b.user) {
},
sortSitesByUserInfo(sites: Site[], key: keyof UserInfo, ascending: boolean): Site[]{
return sites.sort((a, b) => {
if ((!a.user || !b.user) || (typeof a.user[key] != "number") ){
return 0;
}
const sortA = a.user.joinTime || 0;
const sortB = b.user.joinTime || 0;
let sortA = a.user[key] ? a.user[key] as number : 0
let sortB = b.user[key] ? b.user[key] as number : 0

if (sortA < sortB) return -1;
if (sortA > sortB) return 1;
return 0;
// handle the condition of ratio is infinitely
if ((key == "ratio") && (this.ratioIsInfinitely(sortA) || this.ratioIsInfinitely(sortB))) {
if (this.ratioIsInfinitely(sortA) && this.ratioIsInfinitely(sortB)) {
return 0
}
if (this.ratioIsInfinitely(sortA)) {
return ascending ? 1: -1
}
if (this.ratioIsInfinitely(sortB)) {
return ascending ? -1: 1
}
}
return ascending ? sortA - sortB : sortB - sortA;
});

this.infos.total.ratio = this.getRatio(this.infos.total);
},
ratioIsInfinitely(v: number): boolean {
return v > 10000 || v == -1
},
getRatio(info: any): number {
let downloaded = info.downloaded as number;
Expand Down