Skip to content

Commit 584f6b1

Browse files
authored
Merge pull request os-checker#120 from os-checker/feat/info-columns-select
feat: info 页面 实现所有列的筛选下拉框
2 parents 49adb08 + 88655b5 commit 584f6b1

File tree

6 files changed

+217
-166
lines changed

6 files changed

+217
-166
lines changed

os-checks/assets/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ html, body {
4545
}
4646

4747
.nav-link {
48-
color: var(--p-indigo-500);
48+
color: var(--p-sky-500);
4949
/* 统一的链接颜色 */
5050
text-decoration: none;
5151
}
5252

5353
.nav-link.router-link-active {
54-
color: var(--p-indigo-500);
54+
color: var(--p-sky-500);
5555
/* 重置激活链接的颜色 */
5656
}

os-checks/pages/info.vue

Lines changed: 78 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<MultiSelect v-model="selected.kinds" display="chip" :options="kinds" filter :maxSelectedLabels="4"
2222
placeholder="Select Crate Kinds" />
2323

24-
<MultiSelect v-model="selected.displays" display="chip" :options="displays" filter :maxSelectedLabels="4"
25-
placeholder="Select Columns" />
24+
<MultiSelect v-model="selected.columns" display="chip" :options="columns" :optionLabel="o => C.option(o)" filter
25+
:maxSelectedLabels="4" placeholder="Select Columns" />
2626
</div>
2727

2828
<div>
@@ -48,28 +48,28 @@
4848

4949
<Column frozen sortable field="pkg" header="Package" style="min-width: 200px;" />
5050

51-
<Column sortable field="version" header="Version" style="text-align: center;" />
52-
<Column sortable v-if="display.digits" field="lib" header="Lib" style="text-align: center;" />
53-
<Column sortable v-if="display.digits" field="bin" header="Bin" style="text-align: center;" />
54-
<Column sortable v-if="display.digits" field="dependencies" header="Depen-dencies" style="text-align: center;" />
55-
<Column sortable field="release_count" header="crates.io Releases" style="text-align: center;">
51+
<Column v-if="C.display('version')" sortable field="version" :header="C.name('version')"
52+
style="text-align: center;" />
53+
54+
<Column v-if="C.display('release_count')" sortable field="release_count" :header="C.name('release_count')"
55+
style="text-align: center;">
5656
<template #body="{ data }">
5757
<NuxtLink :to="`https://crates.io/crates/${data.pkg}`" target="_blank" class="nav-link">
5858
{{ data.release_count }}
5959
</NuxtLink>
6060
</template>
6161
</Column>
6262

63-
<Column sortable field="diag_total_count" header="Diag-nostics" style="text-align: center;">
63+
<Column v-if="C.display('diag_total_count')" sortable field="diag_total_count"
64+
:header="C.name('diag_total_count')" style="text-align: center;">
6465
<template #body="{ data }">
6566
<NuxtLink :to="`/${data.user}/${data.repo}`" target="_blank" class="nav-link">
6667
{{ data.diag_total_count }}
6768
</NuxtLink>
6869
</template>
6970
</Column>
7071

71-
72-
<Column sortable v-if="display.digits" field="testcases" header="Test Cases"
72+
<Column v-if="C.display('testcases')" sortable field="testcases" :header="C.name('testcases')"
7373
style="text-align: center; font-weight: bold">
7474
<template #body="{ data }">
7575
<span :style="{ color: data.testcases_color }">
@@ -78,53 +78,69 @@
7878
</template>
7979
</Column>
8080

81-
<Column sortable v-if="display.digits" field="tests" header="Tests" style="text-align: center;" />
82-
<Column sortable v-if="display.digits" field="examples" header="Examples" style="text-align: center;" />
83-
<Column sortable v-if="display.digits" field="benches" header="Benches" style="text-align: center;" />
81+
<Column v-if="C.display('lib')" sortable field="lib" :header="C.name('lib')" style="text-align: center;" />
82+
<Column v-if="C.display('bin')" sortable field="bin" :header="C.name('bin')" style="text-align: center;" />
83+
<Column v-if="C.display('dependencies')" sortable field="dependencies" :header="C.name('dependencies')"
84+
style="text-align: center;" />
85+
86+
<Column v-if="C.display('tests')" sortable field="tests" :header="C.name('tests')" style="text-align: center;" />
87+
<Column v-if="C.display('examples')" sortable field="examples" :header="C.name('examples')"
88+
style="text-align: center;" />
89+
<Column v-if="C.display('benches')" sortable field="benches" :header="C.name('benches')"
90+
style="text-align: center;" />
8491

85-
<Column v-if="display.links" field="documentation" header="Doc" style="text-align: center;">
92+
<Column v-if="C.display('documentation')" field="documentation" :header="C.name('documentation')"
93+
style="text-align: center;">
8694
<template #body="{ data }">
8795
<NuxtLink v-if="data.documentation" :to="data.documentation" target="_blank" class="nav-link">
88-
<Button icon="pi pi-external-link" link />
96+
link
97+
<!-- <Button icon="pi pi-external-link" link /> -->
8998
</NuxtLink>
9099
</template>
91100
</Column>
92101

93-
<Column v-if="display.links" field="latest_doc" header="Latest Doc" style="text-align: center;">
102+
<Column v-if="C.display('latest_doc')" field="latest_doc" :header="C.name('latest_doc')"
103+
style="text-align: center;">
94104
<template #body="{ data }">
95105
<NuxtLink v-if="data.latest_doc" :to="data.latest_doc" target="_blank" class="nav-link">
96-
<Button icon="pi pi-external-link" link />
106+
link
107+
<!-- <Button icon="pi pi-external-link" link /> -->
97108
</NuxtLink>
98109
</template>
99110
</Column>
100111

101-
<Column v-if="display.links" field="homepage" header="Home Page" style="text-align: center;">
112+
<Column v-if="C.display('homepage')" field="homepage" :header="C.name('homepage')" style="text-align: center;">
102113
<template #body="{ data }">
103114
<NuxtLink v-if="data.homepage" :to="data.homepage" target="_blank" class="nav-link">
104-
<Button icon="pi pi-external-link" link />
115+
link
116+
<!-- <Button icon="pi pi-external-link" link /> -->
105117
</NuxtLink>
106118
</template>
107119
</Column>
108120

109-
<Column v-if="display.texts" sortable field="categories" header="Categories" style="min-width: 200px;">
121+
<Column v-if="C.display('categories')" sortable field="categories" :header="C.name('categories')"
122+
style="min-width: 200px;">
110123
<template #body="{ data: { categories } }">
111124
<div v-for="tag of categories">
112125
<Tag severity="warn" :value="tag" style="margin-bottom: 5px;"></Tag>
113126
</div>
114127
</template>
115128
</Column>
116129

117-
<Column v-if="display.texts" sortable field="keywords" header="KeyWords" style="min-width: 150px;">
130+
<Column v-if="C.display('keywords')" sortable field="keywords" :header="C.name('keywords')"
131+
style="min-width: 150px;">
118132
<template #body="{ data: { keywords } }">
119133
<div v-for="tag of keywords">
120134
<Tag severity="warn" :value="tag" style="margin-bottom: 5px;"></Tag>
121135
</div>
122136
</template>
123137
</Column>
124138

125-
<Column v-if="display.texts" field="description" header="Description" style="min-width: 280px;" />
139+
<Column v-if="C.display('description')" field="description" :header="C.name('description')"
140+
style="min-width: 280px;" />
126141

127-
<Column v-if="display.texts" sortable field="authors" header="Authors" style="min-width: 300px;">
142+
<Column v-if="C.display('authors')" sortable field="authors" :header="C.name('authors')"
143+
style="min-width: 300px;">
128144
<template #body="{ data: { authors } }">
129145
<div v-for="tag of authors">
130146
<Tag severity="info" :value="tag" style="margin-bottom: 5px;"></Tag>
@@ -212,7 +228,7 @@
212228

213229
<script setup lang="ts">
214230
import type { Pkg, PkgInfo, Test } from '~/shared/info';
215-
import { unique_field, unique_field_bool } from '~/shared/info';
231+
import { unique_field, unique_field_bool, InfoCols } from '~/shared/info';
216232
import { FilterMatchMode } from '@primevue/core/api';
217233
import type { DataTableSortMeta } from 'primevue/datatable';
218234
@@ -221,8 +237,6 @@ const tableHeight = computed(() => `${Math.round(viewportHeight.value * 0.8)}px`
221237
222238
const summaries = ref<PkgInfo[]>([]);
223239
224-
const display = reactive<{ digits: boolean, links: boolean, texts: boolean }>({ digits: true, links: false, texts: false });
225-
226240
githubFetch<PkgInfo[]>({
227241
path: "plugin/cargo/info/summaries.json"
228242
}).then(val => {
@@ -256,25 +270,24 @@ const summaryTable = computed<SummaryTable[]>(() => {
256270
repo: val.repo,
257271
pkg: name,
258272
version: pkg.version,
273+
release_count: pkg.release_count,
274+
diag_total_count: pkg.diag_total_count,
275+
testcases: pkg.testcases?.pkg_tests_count ?? null,
276+
testcases_color,
259277
lib: pkg.lib ? "" : null,
260278
bin: pkg.bin ? "" : null,
261279
dependencies: pkg.dependencies || null,
262-
testcases: pkg.testcases?.pkg_tests_count ?? null,
263-
testcases_color,
264280
tests: pkg.tests || null,
265281
examples: pkg.examples || null,
266282
benches: pkg.benches || null,
267-
authors: pkg.authors.length === 0 ? null : pkg.authors,
268-
description: pkg.description,
269-
keywords: pkg.keywords.length === 0 ? null : pkg.keywords,
270-
categories: pkg.categories.length === 0 ? null : pkg.categories,
271-
// os_categories: pkg.os_categories.length === 0 ? null : pkg.os_categories,
272283
documentation: pkg.documentation,
284+
latest_doc: docs.value?.[val.user]?.[val.repo]?.[name] ?? null,
273285
readme: pkg.readme,
274286
homepage: pkg.homepage,
275-
latest_doc: docs.value?.[val.user]?.[val.repo]?.[name] ?? null,
276-
diag_total_count: pkg.diag_total_count,
277-
release_count: pkg.release_count,
287+
categories: pkg.categories.length === 0 ? null : pkg.categories,
288+
keywords: pkg.keywords.length === 0 ? null : pkg.keywords,
289+
description: pkg.description,
290+
authors: pkg.authors.length === 0 ? null : pkg.authors,
278291
}
279292
})
280293
}).flat();
@@ -338,38 +351,30 @@ const kinds = computed(() => {
338351
if (is_benches) { arr.push("Benches"); }
339352
return arr;
340353
});
341-
const displays = computed(() => Object.keys(display));
354+
355+
const C = reactive(InfoCols.init());
356+
C.setDefaultColumns();
357+
const columns = C.options();
342358
343359
const selected = reactive<{
344360
categories: string[],
345361
keywords: string[],
346362
authors: string[],
347363
kinds: string[],
348364
text: any,
349-
displays: string[],
365+
columns: string[],
350366
sorts: DataTableSortMeta[],
351367
}>({
352368
categories: [], keywords: [], authors: [], kinds: [],
353369
// interactive filter/search inputs
354370
text: { global: { value: null, matchMode: FilterMatchMode.CONTAINS }, },
355371
// columns to be displayed
356-
displays: [],
372+
columns: [],
357373
sorts: [],
358374
});
359375
360-
watch(() => selected.displays, (disp) => {
361-
if (disp.length === 0) {
362-
//@ts-ignore
363-
// Object.keys(display).map(k => display[k] = true);
364-
display.digits = true;
365-
display.links = false;
366-
display.texts = false;
367-
return;
368-
}
369-
370-
const set = new Set(disp);
371-
//@ts-ignore
372-
Object.keys(display).map(k => display[k] = set.has(k));
376+
watch(() => selected.columns, (cols) => {
377+
C.setDisplay(cols);
373378
});
374379
375380
watchEffect(() => {
@@ -462,31 +467,27 @@ function updateFilter(query: {
462467
authors?: string,
463468
kinds?: string,
464469
text?: string,
465-
displays?: string,
470+
columns?: string,
466471
sorts?: string,
467472
}) {
468-
if (query.categories) { selected.categories = decodeURIComponent(query.categories).split(","); }
469-
if (query.keywords) { selected.keywords = decodeURIComponent(query.keywords).split(","); }
470-
if (query.authors) { selected.authors = decodeURIComponent(query.authors).split(","); }
473+
const { categories, keywords, authors, kinds, text, columns, sorts } = query;
474+
475+
if (categories) { selected.categories = decodeURIComponent(categories).split(","); }
476+
if (keywords) { selected.keywords = decodeURIComponent(keywords).split(","); }
477+
if (authors) { selected.authors = decodeURIComponent(authors).split(","); }
471478
472-
if (query.kinds) {
479+
if (kinds) {
473480
const filter = new Set([
474481
"Lib", "Bin", "TestCases", "Tests", "Examples", "Benches"
475482
]);
476-
selected.kinds = decodeURIComponent(query.kinds).split(",").filter(k => filter.has(k));
483+
selected.kinds = decodeURIComponent(kinds).split(",").filter(k => filter.has(k));
477484
}
478485
479-
if (query.text) {
480-
selected.text.global.value = decodeURIComponent(query.text);
481-
}
486+
if (text) { selected.text.global.value = decodeURIComponent(text); }
487+
if (columns) { selected.columns = decodeURIComponent(columns).split(","); }
482488
483-
if (query.displays) {
484-
const filter = new Set(displays.value);
485-
selected.displays = decodeURIComponent(query.displays).split(",").filter(k => filter.has(k));
486-
}
487-
488-
if (query.sorts) {
489-
const args = decodeURIComponent(query.sorts).split(",");
489+
if (sorts) {
490+
const args = decodeURIComponent(sorts).split(",");
490491
//@ts-ignore
491492
selected.sorts = args.map(arg => {
492493
let [field, order] = arg.split("=");
@@ -498,29 +499,22 @@ updateFilter(route.query);
498499
499500
const router = useRouter();
500501
watchEffect(() => {
501-
const { categories, keywords, authors, kinds, text, displays, sorts } = selected;
502+
const { categories, keywords, authors, kinds, text, columns, sorts } = selected;
502503
503504
let query: any = {};
504505
505-
if (categories.length !== 0) {
506-
query.categories = encodeURIComponent(categories.join(","));
507-
}
508-
if (keywords.length !== 0) {
509-
query.keywords = encodeURIComponent(keywords.join(","));
510-
}
506+
if (categories.length !== 0) { query.categories = encodeURIComponent(categories.join(",")); }
507+
if (keywords.length !== 0) { query.keywords = encodeURIComponent(keywords.join(",")); }
508+
511509
if (authors.length !== 0) {
512510
// FIXME: what if author string contains `,`
513511
query.authors = encodeURIComponent(authors.join(","));
514512
}
515-
if (kinds.length !== 0) {
516-
query.kinds = encodeURIComponent(kinds.join(","));
517-
}
518-
if (text.global.value) {
519-
query.text = encodeURIComponent(text.global.value);
520-
}
521-
if (displays.length !== 0) {
522-
query.displays = encodeURIComponent(displays.join(","));
523-
}
513+
514+
if (kinds.length !== 0) { query.kinds = encodeURIComponent(kinds.join(",")); }
515+
if (text.global.value) { query.text = encodeURIComponent(text.global.value); }
516+
if (columns.length !== 0) { query.columns = encodeURIComponent(columns.join(",")); }
517+
524518
if (sorts.length !== 0) {
525519
const args = sorts.map(({ field, order }) => order ? `${field}=${order}` : null);
526520
query.sorts = encodeURIComponent(args.filter(x => x).join(","));

os-checks/pages/repos.vue

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<MultiSelect v-model="selected.topics" display="chip" :options="topics" filter :maxSelectedLabels="4"
99
placeholder="Select Topics" />
1010

11-
<MultiSelect v-model="selected.columns" display="chip" :options="columns" :optionLabel="o => Cols.option(o)"
12-
filter :maxSelectedLabels="4" placeholder="Select Columns" />
11+
<MultiSelect v-model="selected.columns" display="chip" :options="columns" :optionLabel="o => C.option(o)" filter
12+
:maxSelectedLabels="4" placeholder="Select Columns" />
1313
</div>
1414

1515
<div>
@@ -117,7 +117,7 @@
117117
<script setup lang="ts">
118118
import { FilterMatchMode } from '@primevue/core/api';
119119
import type { DataTableSortMeta } from 'primevue/datatable';
120-
import { formatBytes, Cols } from '~/shared/repos';
120+
import { formatBytes, RepoCols } from '~/shared/repos';
121121
import type { Output, Repo } from '~/shared/repos';
122122
123123
useHead({ title: 'Repositories Information' });
@@ -183,9 +183,9 @@ const selectedRepo = ref();
183183
const licenses = computed(() => [...new Set(repo.value.map(r => r.license))].sort());
184184
const topics = computed(() => [...new Set(repo.value.map(r => r.topics).flat())].sort());
185185
186-
const C = reactive(new Cols());
186+
const C = reactive(RepoCols.init());
187187
C.setDefaultColumns();
188-
const columns = Cols.options();
188+
const columns = C.options();
189189
190190
const selected = reactive<{
191191
licenses: string[],
@@ -237,16 +237,15 @@ function updateFilter(query: {
237237
text?: string,
238238
sorts?: string,
239239
}) {
240-
if (query.licenses) { selected.licenses = decodeURIComponent(query.licenses).split(","); }
241-
if (query.topics) { selected.topics = decodeURIComponent(query.topics).split(","); }
242-
if (query.columns) { selected.columns = decodeURIComponent(query.columns).split(","); }
240+
const { licenses, topics, columns, text, sorts } = query;
243241
244-
if (query.text) {
245-
selected.text.global.value = decodeURIComponent(query.text);
246-
}
242+
if (licenses) { selected.licenses = decodeURIComponent(licenses).split(","); }
243+
if (topics) { selected.topics = decodeURIComponent(topics).split(","); }
244+
if (columns) { selected.columns = decodeURIComponent(columns).split(","); }
245+
if (text) { selected.text.global.value = decodeURIComponent(text); }
247246
248-
if (query.sorts) {
249-
const args = decodeURIComponent(query.sorts).split(",");
247+
if (sorts) {
248+
const args = decodeURIComponent(sorts).split(",");
250249
//@ts-ignore
251250
selected.sorts = args.map(arg => {
252251
let [field, order] = arg.split("=");

0 commit comments

Comments
 (0)