Skip to content

update #69

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

Merged
merged 1 commit into from
Nov 30, 2022
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## version 2.6.1

- 新增题目自定义分类

## version 2.5.1

- 今日提交的分类,方便设置下次回顾时间
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [新增搬砖功能(重复练习?)](#搬砖功能的说明)
- [状态栏增加简易计时器](#状态栏增加简易计时器)
- [新增一个 remark 功能](#新增在工作目录存放数据)
- [新增题目自定义分类](#新增在工作目录存放数据)

# 关于本项目

Expand Down Expand Up @@ -105,6 +106,8 @@
> > > remark 备注数据
> > >
> > > > qid 备注 remark 数据
> >
> > > group.json

### bricks.json 存放格式

Expand All @@ -121,6 +124,24 @@

```

### group.json 存放格式

```
{
"version": 1,
"all_group": [
{
"name": "www", // 分类名称
"time": 1669791273308, // 分类编号
"qid_list": [ // 该分类的题目qid
"1000229",
"1000231"
]
}
]
}
```

## 运行条件

- [VS Code 1.57.0+](https://code.visualstudio.com/)
Expand Down
60 changes: 50 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-leetcode-problem-rating",
"displayName": "LeetCode",
"description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了",
"version": "2.5.1",
"version": "2.6.1",
"author": "ccagml",
"publisher": "ccagml",
"license": "MIT",
Expand Down Expand Up @@ -69,28 +69,28 @@
},
{
"command": "lcpr.refreshExplorer",
"title": "Refresh",
"title": "刷新",
"category": "LeetCode",
"icon": "$(refresh)"
},
{
"command": "lcpr.pickOne",
"title": "Pick One",
"title": "手气一下",
"category": "LeetCode"
},
{
"command": "lcpr.deleteAllCache",
"title": "deleteAllCache",
"title": "删除题目缓存",
"category": "LeetCode"
},
{
"command": "lcpr.showProblem",
"title": "Show Problem",
"title": "做题",
"category": "LeetCode"
},
{
"command": "lcpr.previewProblem",
"title": "Preview Problem",
"title": "预览题目",
"category": "LeetCode"
},
{
Expand Down Expand Up @@ -222,6 +222,26 @@
{
"command": "lcpr.remarkDispose",
"title": "Remove All Notes"
},
{
"command": "lcpr.newBrickGroup",
"title": "新建一个自定义分类",
"icon": "$(file-directory-create)"
},
{
"command": "lcpr.addQidToGroup",
"title": "添加题目到自定义分类",
"icon": "$(add)"
},
{
"command": "lcpr.removeBrickGroup",
"title": "移除这个自定义分类",
"icon": "$(remove)"
},
{
"command": "lcpr.removeQidFromGroup",
"title": "从分类中移除这个题目",
"icon": "$(remove)"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -333,6 +353,11 @@
"command": "lcpr.deleteAllCache",
"when": "view == QuestionExplorer",
"group": "overflow@2"
},
{
"command": "lcpr.newBrickGroup",
"when": "view == BricksExplorer",
"group": "navigation@1"
}
],
"view/item/context": [
Expand All @@ -356,6 +381,11 @@
"when": "view == QuestionExplorer && viewItem =~ /problem*/",
"group": "leetcode@4"
},
{
"command": "lcpr.addQidToGroup",
"when": "view == QuestionExplorer && viewItem =~ /problem*/",
"group": "leetcode@5"
},
{
"command": "lcpr.addFavorite",
"when": "view == QuestionExplorer && viewItem == problem",
Expand All @@ -368,23 +398,33 @@
},
{
"command": "lcpr.previewProblem",
"when": "view == BricksExplorer && viewItem == bricks",
"when": "view == BricksExplorer && viewItem =~ /nodebricks*/",
"group": "leetcode@1"
},
{
"command": "lcpr.showProblem",
"when": "view == BricksExplorer && viewItem == bricks",
"when": "view == BricksExplorer && viewItem =~ /nodebricks*/",
"group": "leetcode@2"
},
{
"command": "lcpr.showSolution",
"when": "view == BricksExplorer && viewItem == bricks",
"when": "view == BricksExplorer && viewItem =~ /nodebricks*/",
"group": "leetcode@3"
},
{
"submenu": "lcpr.setBricksType_sub1",
"when": "view == BricksExplorer && viewItem == bricks",
"when": "view == BricksExplorer && viewItem =~ /nodebricks*/ ",
"group": "leetcode@4"
},
{
"command": "lcpr.removeQidFromGroup",
"when": "view == BricksExplorer && viewItem == nodebricksdiy",
"group": "leetcode@5"
},
{
"command": "lcpr.removeBrickGroup",
"when": "view == BricksExplorer && viewItem == bricksdiy",
"group": "leetcode@1"
}
],
"commandPalette": [
Expand Down
102 changes: 99 additions & 3 deletions src/controller/BricksViewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
* Copyright (c) 2022 ccagml . All rights reserved.
*/

import { Disposable, TreeItemCollapsibleState } from "vscode";
import { Disposable, TreeItemCollapsibleState, window } from "vscode";

import { bricksDao } from "../dao/bricksDao";
import { BricksNormalId, defaultProblem } from "../model/Model";
import { groupDao } from "../dao/groupDao";
import { BricksNormalId, defaultProblem, IQuickItemEx } from "../model/Model";
import { BricksNode } from "../model/NodeModel";
import { bricksDataService } from "../service/BricksDataService";
import { eventService } from "../service/EventService";
import { treeViewController } from "./TreeViewController";

// 视图控制器
Expand Down Expand Up @@ -46,14 +48,37 @@ class BricksViewController implements Disposable {
return baseNode;
}

public async getDiyNode(element: BricksNode) {
let time = element.groupTime;
if (time == undefined) {
return [];
}
let all_qid: string[] = await groupDao.getQidByTime(time);
const baseNode: BricksNode[] = [];
all_qid.forEach((qid) => {
let node = treeViewController.getNodeByQid(qid);
if (node) {
let new_obj = new BricksNode(
Object.assign({}, node.data, {}),
true,
node.user_score,
TreeItemCollapsibleState.None,
time
);
baseNode.push(new_obj);
}
});
return baseNode;
}

public async getRootNodes(): Promise<BricksNode[]> {
let all_qid: string[] = await bricksDao.getTodayBricks();
let all_submit_qid: string[] = await bricksDao.getTodayBricksSubmit();

let has_qid = all_qid.length > 0;
let has_submit = all_submit_qid.length > 0;
const baseNode: BricksNode[] = [];

// 监工
baseNode.push(
new BricksNode(
Object.assign({}, defaultProblem, {
Expand All @@ -66,6 +91,7 @@ class BricksViewController implements Disposable {
)
);

// 今日提交
if (has_submit) {
let temp_score = 0;
all_submit_qid.forEach((qid) => {
Expand All @@ -89,6 +115,22 @@ class BricksViewController implements Disposable {
)
);
}
// 分类
let all_group = await groupDao.getAllGroup();
all_group.forEach((element) => {
baseNode.push(
new BricksNode(
Object.assign({}, defaultProblem, {
id: BricksNormalId.DIY,
name: element.name,
}),
false,
0,
TreeItemCollapsibleState.Collapsed,
element.time
)
);
});

return baseNode;
}
Expand All @@ -97,6 +139,60 @@ class BricksViewController implements Disposable {
await bricksDataService.setBricksType(node, type);
}
public dispose(): void {}

public async newBrickGroup() {
let name = await window.showInputBox({
title: "创建新的分类",
validateInput: (s: string): string | undefined => (s && s.trim() ? undefined : "分类名称不能为空"),
placeHolder: "输入新分类名称",
ignoreFocusOut: true,
});
if (name && name.trim()) {
bricksDataService.newBrickGroup(name);
eventService.emit("groupUpdate");
}
}

public async removeBrickGroup(node) {
let time = node.groupTime;
bricksDataService.removeBrickGroup(time);
eventService.emit("groupUpdate");
}

public async addQidToGroup(node: BricksNode) {
const picks: Array<IQuickItemEx<string>> = [];

let all_group = await bricksDataService.getAllGroup();
all_group.forEach((element) => {
picks.push({
label: element.name,
detail: "",
value: element.time,
});
});

const choice: Array<IQuickItemEx<string>> | undefined = await window.showQuickPick(picks, {
title: "正在添加题目到分类中",
matchOnDescription: false,
matchOnDetail: false,
placeHolder: "选择要添加的分类",
canPickMany: true,
});
if (!choice) {
return;
}
let time_list: Array<any> = [];
choice.forEach((element) => {
time_list.push(element.value);
});
groupDao.addQidToTimeList(node.qid, time_list);
eventService.emit("groupUpdate");
}

public async removeQidFromGroup(node) {
groupDao.removeQidFromTime(node.qid, node.groupTime);
eventService.emit("groupUpdate");
}
}

export const bricksViewController: BricksViewController = new BricksViewController();
3 changes: 2 additions & 1 deletion src/controller/TreeViewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,8 @@ class TreeViewController implements Disposable {
}

public getNodeByQid(qid: string): NodeModel | undefined {
return this.getNodeById(this.qidToFid.get(qid) || "");
let new_qid = qid.toString();
return this.getNodeById(this.qidToFid.get(new_qid) || "");
}

public getQidByFid(id: string) {
Expand Down
16 changes: 8 additions & 8 deletions src/dao/bricksDao.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// > workspace/ 工作目录
// >
// > > .lcpr_data/ 存数据
// > >
// > > > remake/ 备注
// > > >
// > > > > 题目内部编号.json 根据 qid 备注的信息
// > >
/*
* Filename: /home/cc/vscode-leetcode-problem-rating/src/dao/bricksDao.ts
* Path: /home/cc/vscode-leetcode-problem-rating
* Created Date: Wednesday, November 23rd 2022, 4:36:38 pm
* Author: ccagml
*
* Copyright (c) 2022 ccagml . All rights reserved.
*/

import { fetchProblemLanguage, selectWorkspaceFolder } from "../utils/ConfigUtils";
import { useWsl, toWinPath, getDayStart, getDayNow } from "../utils/SystemUtils";
Expand Down
Loading