Skip to content

Commit 24d9990

Browse files
authored
Merge pull request #69 from ccagml/main
update
2 parents 9413862 + 1140e70 commit 24d9990

File tree

12 files changed

+354
-26
lines changed

12 files changed

+354
-26
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## version 2.6.1
2+
3+
- 新增题目自定义分类
4+
15
## version 2.5.1
26

37
- 今日提交的分类,方便设置下次回顾时间

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- [新增搬砖功能(重复练习?)](#搬砖功能的说明)
2626
- [状态栏增加简易计时器](#状态栏增加简易计时器)
2727
- [新增一个 remark 功能](#新增在工作目录存放数据)
28+
- [新增题目自定义分类](#新增在工作目录存放数据)
2829

2930
# 关于本项目
3031

@@ -105,6 +106,8 @@
105106
> > > remark 备注数据
106107
> > >
107108
> > > > qid 备注 remark 数据
109+
> >
110+
> > > group.json
108111
109112
### bricks.json 存放格式
110113

@@ -121,6 +124,24 @@
121124
122125
```
123126

127+
### group.json 存放格式
128+
129+
```
130+
{
131+
"version": 1,
132+
"all_group": [
133+
{
134+
"name": "www", // 分类名称
135+
"time": 1669791273308, // 分类编号
136+
"qid_list": [ // 该分类的题目qid
137+
"1000229",
138+
"1000231"
139+
]
140+
}
141+
]
142+
}
143+
```
144+
124145
## 运行条件
125146

126147
- [VS Code 1.57.0+](https://code.visualstudio.com/)

package.json

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode-problem-rating",
33
"displayName": "LeetCode",
44
"description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了",
5-
"version": "2.5.1",
5+
"version": "2.6.1",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",
@@ -69,28 +69,28 @@
6969
},
7070
{
7171
"command": "lcpr.refreshExplorer",
72-
"title": "Refresh",
72+
"title": "刷新",
7373
"category": "LeetCode",
7474
"icon": "$(refresh)"
7575
},
7676
{
7777
"command": "lcpr.pickOne",
78-
"title": "Pick One",
78+
"title": "手气一下",
7979
"category": "LeetCode"
8080
},
8181
{
8282
"command": "lcpr.deleteAllCache",
83-
"title": "deleteAllCache",
83+
"title": "删除题目缓存",
8484
"category": "LeetCode"
8585
},
8686
{
8787
"command": "lcpr.showProblem",
88-
"title": "Show Problem",
88+
"title": "做题",
8989
"category": "LeetCode"
9090
},
9191
{
9292
"command": "lcpr.previewProblem",
93-
"title": "Preview Problem",
93+
"title": "预览题目",
9494
"category": "LeetCode"
9595
},
9696
{
@@ -222,6 +222,26 @@
222222
{
223223
"command": "lcpr.remarkDispose",
224224
"title": "Remove All Notes"
225+
},
226+
{
227+
"command": "lcpr.newBrickGroup",
228+
"title": "新建一个自定义分类",
229+
"icon": "$(file-directory-create)"
230+
},
231+
{
232+
"command": "lcpr.addQidToGroup",
233+
"title": "添加题目到自定义分类",
234+
"icon": "$(add)"
235+
},
236+
{
237+
"command": "lcpr.removeBrickGroup",
238+
"title": "移除这个自定义分类",
239+
"icon": "$(remove)"
240+
},
241+
{
242+
"command": "lcpr.removeQidFromGroup",
243+
"title": "从分类中移除这个题目",
244+
"icon": "$(remove)"
225245
}
226246
],
227247
"viewsContainers": {
@@ -333,6 +353,11 @@
333353
"command": "lcpr.deleteAllCache",
334354
"when": "view == QuestionExplorer",
335355
"group": "overflow@2"
356+
},
357+
{
358+
"command": "lcpr.newBrickGroup",
359+
"when": "view == BricksExplorer",
360+
"group": "navigation@1"
336361
}
337362
],
338363
"view/item/context": [
@@ -356,6 +381,11 @@
356381
"when": "view == QuestionExplorer && viewItem =~ /problem*/",
357382
"group": "leetcode@4"
358383
},
384+
{
385+
"command": "lcpr.addQidToGroup",
386+
"when": "view == QuestionExplorer && viewItem =~ /problem*/",
387+
"group": "leetcode@5"
388+
},
359389
{
360390
"command": "lcpr.addFavorite",
361391
"when": "view == QuestionExplorer && viewItem == problem",
@@ -368,23 +398,33 @@
368398
},
369399
{
370400
"command": "lcpr.previewProblem",
371-
"when": "view == BricksExplorer && viewItem == bricks",
401+
"when": "view == BricksExplorer && viewItem =~ /nodebricks*/",
372402
"group": "leetcode@1"
373403
},
374404
{
375405
"command": "lcpr.showProblem",
376-
"when": "view == BricksExplorer && viewItem == bricks",
406+
"when": "view == BricksExplorer && viewItem =~ /nodebricks*/",
377407
"group": "leetcode@2"
378408
},
379409
{
380410
"command": "lcpr.showSolution",
381-
"when": "view == BricksExplorer && viewItem == bricks",
411+
"when": "view == BricksExplorer && viewItem =~ /nodebricks*/",
382412
"group": "leetcode@3"
383413
},
384414
{
385415
"submenu": "lcpr.setBricksType_sub1",
386-
"when": "view == BricksExplorer && viewItem == bricks",
416+
"when": "view == BricksExplorer && viewItem =~ /nodebricks*/ ",
387417
"group": "leetcode@4"
418+
},
419+
{
420+
"command": "lcpr.removeQidFromGroup",
421+
"when": "view == BricksExplorer && viewItem == nodebricksdiy",
422+
"group": "leetcode@5"
423+
},
424+
{
425+
"command": "lcpr.removeBrickGroup",
426+
"when": "view == BricksExplorer && viewItem == bricksdiy",
427+
"group": "leetcode@1"
388428
}
389429
],
390430
"commandPalette": [

src/controller/BricksViewController.ts

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
* Copyright (c) 2022 ccagml . All rights reserved.
88
*/
99

10-
import { Disposable, TreeItemCollapsibleState } from "vscode";
10+
import { Disposable, TreeItemCollapsibleState, window } from "vscode";
1111

1212
import { bricksDao } from "../dao/bricksDao";
13-
import { BricksNormalId, defaultProblem } from "../model/Model";
13+
import { groupDao } from "../dao/groupDao";
14+
import { BricksNormalId, defaultProblem, IQuickItemEx } from "../model/Model";
1415
import { BricksNode } from "../model/NodeModel";
1516
import { bricksDataService } from "../service/BricksDataService";
17+
import { eventService } from "../service/EventService";
1618
import { treeViewController } from "./TreeViewController";
1719

1820
// 视图控制器
@@ -46,14 +48,37 @@ class BricksViewController implements Disposable {
4648
return baseNode;
4749
}
4850

51+
public async getDiyNode(element: BricksNode) {
52+
let time = element.groupTime;
53+
if (time == undefined) {
54+
return [];
55+
}
56+
let all_qid: string[] = await groupDao.getQidByTime(time);
57+
const baseNode: BricksNode[] = [];
58+
all_qid.forEach((qid) => {
59+
let node = treeViewController.getNodeByQid(qid);
60+
if (node) {
61+
let new_obj = new BricksNode(
62+
Object.assign({}, node.data, {}),
63+
true,
64+
node.user_score,
65+
TreeItemCollapsibleState.None,
66+
time
67+
);
68+
baseNode.push(new_obj);
69+
}
70+
});
71+
return baseNode;
72+
}
73+
4974
public async getRootNodes(): Promise<BricksNode[]> {
5075
let all_qid: string[] = await bricksDao.getTodayBricks();
5176
let all_submit_qid: string[] = await bricksDao.getTodayBricksSubmit();
5277

5378
let has_qid = all_qid.length > 0;
5479
let has_submit = all_submit_qid.length > 0;
5580
const baseNode: BricksNode[] = [];
56-
81+
// 监工
5782
baseNode.push(
5883
new BricksNode(
5984
Object.assign({}, defaultProblem, {
@@ -66,6 +91,7 @@ class BricksViewController implements Disposable {
6691
)
6792
);
6893

94+
// 今日提交
6995
if (has_submit) {
7096
let temp_score = 0;
7197
all_submit_qid.forEach((qid) => {
@@ -89,6 +115,22 @@ class BricksViewController implements Disposable {
89115
)
90116
);
91117
}
118+
// 分类
119+
let all_group = await groupDao.getAllGroup();
120+
all_group.forEach((element) => {
121+
baseNode.push(
122+
new BricksNode(
123+
Object.assign({}, defaultProblem, {
124+
id: BricksNormalId.DIY,
125+
name: element.name,
126+
}),
127+
false,
128+
0,
129+
TreeItemCollapsibleState.Collapsed,
130+
element.time
131+
)
132+
);
133+
});
92134

93135
return baseNode;
94136
}
@@ -97,6 +139,60 @@ class BricksViewController implements Disposable {
97139
await bricksDataService.setBricksType(node, type);
98140
}
99141
public dispose(): void {}
142+
143+
public async newBrickGroup() {
144+
let name = await window.showInputBox({
145+
title: "创建新的分类",
146+
validateInput: (s: string): string | undefined => (s && s.trim() ? undefined : "分类名称不能为空"),
147+
placeHolder: "输入新分类名称",
148+
ignoreFocusOut: true,
149+
});
150+
if (name && name.trim()) {
151+
bricksDataService.newBrickGroup(name);
152+
eventService.emit("groupUpdate");
153+
}
154+
}
155+
156+
public async removeBrickGroup(node) {
157+
let time = node.groupTime;
158+
bricksDataService.removeBrickGroup(time);
159+
eventService.emit("groupUpdate");
160+
}
161+
162+
public async addQidToGroup(node: BricksNode) {
163+
const picks: Array<IQuickItemEx<string>> = [];
164+
165+
let all_group = await bricksDataService.getAllGroup();
166+
all_group.forEach((element) => {
167+
picks.push({
168+
label: element.name,
169+
detail: "",
170+
value: element.time,
171+
});
172+
});
173+
174+
const choice: Array<IQuickItemEx<string>> | undefined = await window.showQuickPick(picks, {
175+
title: "正在添加题目到分类中",
176+
matchOnDescription: false,
177+
matchOnDetail: false,
178+
placeHolder: "选择要添加的分类",
179+
canPickMany: true,
180+
});
181+
if (!choice) {
182+
return;
183+
}
184+
let time_list: Array<any> = [];
185+
choice.forEach((element) => {
186+
time_list.push(element.value);
187+
});
188+
groupDao.addQidToTimeList(node.qid, time_list);
189+
eventService.emit("groupUpdate");
190+
}
191+
192+
public async removeQidFromGroup(node) {
193+
groupDao.removeQidFromTime(node.qid, node.groupTime);
194+
eventService.emit("groupUpdate");
195+
}
100196
}
101197

102198
export const bricksViewController: BricksViewController = new BricksViewController();

src/controller/TreeViewController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,8 @@ class TreeViewController implements Disposable {
13881388
}
13891389

13901390
public getNodeByQid(qid: string): NodeModel | undefined {
1391-
return this.getNodeById(this.qidToFid.get(qid) || "");
1391+
let new_qid = qid.toString();
1392+
return this.getNodeById(this.qidToFid.get(new_qid) || "");
13921393
}
13931394

13941395
public getQidByFid(id: string) {

src/dao/bricksDao.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// > workspace/ 工作目录
2-
// >
3-
// > > .lcpr_data/ 存数据
4-
// > >
5-
// > > > remake/ 备注
6-
// > > >
7-
// > > > > 题目内部编号.json 根据 qid 备注的信息
8-
// > >
1+
/*
2+
* Filename: /home/cc/vscode-leetcode-problem-rating/src/dao/bricksDao.ts
3+
* Path: /home/cc/vscode-leetcode-problem-rating
4+
* Created Date: Wednesday, November 23rd 2022, 4:36:38 pm
5+
* Author: ccagml
6+
*
7+
* Copyright (c) 2022 ccagml . All rights reserved.
8+
*/
99

1010
import { fetchProblemLanguage, selectWorkspaceFolder } from "../utils/ConfigUtils";
1111
import { useWsl, toWinPath, getDayStart, getDayNow } from "../utils/SystemUtils";

0 commit comments

Comments
 (0)