Skip to content

Commit 608a74b

Browse files
committed
重构node
1 parent c46694f commit 608a74b

21 files changed

+986
-728
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@
449449
},
450450
{
451451
"command": "lcpr.addQidToGroup",
452-
"when": "view == BricksExplorer && viewItem != nodebricksdiy",
452+
"when": "view == BricksExplorer && viewItem != nodebricksdiy && viewItem != brickshave && viewItem != brickstoday && viewItem != bricksdiy",
453453
"group": "leetcode@5"
454454
},
455455
{

src/BABA.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* Copyright (c) 2023 ccagml . All rights reserved
88
*/
99

10+
import * as vscode from "vscode";
11+
1012
import { BaseCC } from "./utils/BaseCC";
1113
export * as BaseCC from "./utils/BaseCC";
1214
export enum BabaStr {
@@ -124,6 +126,8 @@ export enum BabaStr {
124126
BricksData_removeBrickGroupFinish = "BricksData_removeBrickGroupFinish",
125127
BricksData_addQidToGroupFinish = "BricksData_addQidToGroupFinish",
126128
BricksData_removeQidFromGroupFinish = "BricksData_removeQidFromGroupFinish",
129+
TodayDataProxy = "TodayDataProxy",
130+
TodayDataMediator = "TodayDataMediator",
127131
}
128132

129133
export class BABA {
@@ -140,10 +144,21 @@ export class BABA {
140144
this.sendNotification(BabaStr.VSCODE_DISPOST);
141145
}
142146
public static sendNotification(name: string, body?: any, type?: string) {
143-
this.fa.sendNotification(name, body, type);
147+
try {
148+
this.fa.sendNotification(name, body, type);
149+
} catch (error) {
150+
console.log(error);
151+
vscode.window.createOutputChannel("LeetCodeProblemRatingERR").append(`${error?.message}, ${error?.stack}`);
152+
}
144153
}
154+
145155
public static async sendNotificationAsync(name: string, body?: any, type?: string) {
146-
await this.fa.sendNotificationAsync(name, body, type);
156+
try {
157+
await this.fa.sendNotificationAsync(name, body, type);
158+
} catch (error) {
159+
console.log(error);
160+
vscode.window.createOutputChannel("LeetCodeProblemRatingERR").append(`${error?.message}, ${error?.stack}`);
161+
}
147162
}
148163

149164
public static getProxy(name: string) {

src/bricksData/BricksDataService.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
*/
99

1010
import { TreeDataProvider, EventEmitter, Event, TreeItem, TreeItemCollapsibleState } from "vscode";
11-
import { BricksNormalId, defaultProblem, ISubmitEvent } from "../model/ConstDefind";
11+
import { BricksNormalId, ISubmitEvent } from "../model/ConstDefind";
1212
import { bricksViewController } from "../controller/BricksViewController";
13-
import { BricksNode } from "../model/NodeModel";
13+
import { TreeNodeModel, TreeNodeType } from "../model/TreeNodeModel";
1414
import { bricksDao } from "../dao/bricksDao";
1515
import { groupDao } from "../dao/groupDao";
1616
import { BABA, BABAMediator, BABAProxy, BabaStr, BaseCC } from "../BABA";
1717

18-
export class BricksDataService implements TreeDataProvider<BricksNode> {
19-
private onDidChangeTreeDataEvent: EventEmitter<BricksNode | undefined | null> = new EventEmitter<
20-
BricksNode | undefined | null
18+
export class BricksDataService implements TreeDataProvider<TreeNodeModel> {
19+
private onDidChangeTreeDataEvent: EventEmitter<TreeNodeModel | undefined | null> = new EventEmitter<
20+
TreeNodeModel | undefined | null
2121
>();
2222
// tslint:disable-next-line:member-ordering
2323
public readonly onDidChangeTreeData: Event<any> = this.onDidChangeTreeDataEvent.event;
@@ -32,7 +32,7 @@ export class BricksDataService implements TreeDataProvider<BricksNode> {
3232
}
3333

3434
// 节点的内容
35-
public getTreeItem(element: BricksNode): TreeItem | Thenable<TreeItem> {
35+
public getTreeItem(element: TreeNodeModel): TreeItem | Thenable<TreeItem> {
3636
if (element.id === "notSignIn") {
3737
return {
3838
label: element.name,
@@ -65,18 +65,17 @@ export class BricksDataService implements TreeDataProvider<BricksNode> {
6565
}
6666

6767
// 获取子节点信息
68-
public async getChildren(element?: BricksNode | undefined): Promise<BricksNode[] | null | undefined> {
68+
public async getChildren(element?: TreeNodeModel | undefined): Promise<TreeNodeModel[] | null | undefined> {
6969
let sbp = BABA.getProxy(BabaStr.StatusBarProxy);
7070
if (!sbp.getUser()) {
7171
return [
72-
new BricksNode(
73-
Object.assign({}, defaultProblem, {
72+
new TreeNodeModel(
73+
{
7474
id: "notSignIn",
7575
name: "工头说你不是我们工地的人",
76-
}),
77-
false,
78-
0,
79-
TreeItemCollapsibleState.None
76+
collapsibleState: TreeItemCollapsibleState.None,
77+
},
78+
TreeNodeType.BricksDataNormal
8079
),
8180
];
8281
}
@@ -103,25 +102,25 @@ export class BricksDataService implements TreeDataProvider<BricksNode> {
103102
public async checkSubmit(e: ISubmitEvent) {
104103
if (e.sub_type == "submit" && e.accepted) {
105104
let qid: string = e.qid.toString();
106-
bricksDao.addSubmitTimeByQid(qid);
105+
await bricksDao.addSubmitTimeByQid(qid);
107106
BABA.sendNotification(BabaStr.BricksData_submitAndAccepted);
108107
}
109108
}
110109

111-
public async setBricksType(node: BricksNode, type) {
110+
public async setBricksType(node: TreeNodeModel, type) {
112111
let qid: string = node.qid.toString();
113112
bricksDao.setTypeByQid(qid, type);
114113
BABA.sendNotification(BabaStr.BricksData_setBricksTypeFinish);
115114
}
116115

117-
private parseIconPathFromProblemState(element: BricksNode): string {
116+
private parseIconPathFromProblemState(element: TreeNodeModel): string {
118117
switch (element.state) {
119118
default:
120119
return "";
121120
}
122121
}
123122

124-
private getSubCategoryTooltip(element: BricksNode): string {
123+
private getSubCategoryTooltip(element: TreeNodeModel): string {
125124
// return '' unless it is a sub-category node
126125
if (element.id === "ROOT") {
127126
return "";
@@ -154,7 +153,7 @@ export class BricksDataProxy extends BABAProxy {
154153
super(BricksDataProxy.NAME);
155154
}
156155

157-
public async setBricksType(node: BricksNode, type) {
156+
public async setBricksType(node: TreeNodeModel, type) {
158157
bricksDataService.setBricksType(node, type);
159158
}
160159

@@ -204,6 +203,7 @@ export class BricksDataMediator extends BABAMediator {
204203
BabaStr.BricksData_removeBrickGroupFinish,
205204
BabaStr.BricksData_addQidToGroupFinish,
206205
BabaStr.BricksData_removeQidFromGroupFinish,
206+
BabaStr.CommitResult_showFinish,
207207
];
208208
}
209209
async handleNotification(_notification: BaseCC.BaseCC.INotification) {
@@ -234,7 +234,7 @@ export class BricksDataMediator extends BABAMediator {
234234
bricksDataService.fire();
235235
break;
236236
case BabaStr.CommitResult_showFinish:
237-
bricksDataService.checkSubmit(_notification.getBody());
237+
await bricksDataService.checkSubmit(_notification.getBody());
238238

239239
case BabaStr.BABACMD_setBricksType:
240240
bricksViewController.setBricksType(body.node, body.type);

src/childCall/childCallModule.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import * as os from "os";
1313
import * as path from "path";
1414
import { ExtensionContext, ProgressLocation, Progress } from "vscode";
1515
import { ConfigurationChangeEvent, Disposable, MessageItem, window, workspace } from "vscode";
16-
import { DialogOptions, OutPutType, Endpoint, IProblem, leetcodeHasInited } from "../model/ConstDefind";
16+
import { DialogOptions, OutPutType, Endpoint, leetcodeHasInited } from "../model/ConstDefind";
1717
import { getLeetCodeEndpoint, getNodePath } from "../utils/ConfigUtils";
1818
import { openUrl, ShowMessage } from "../utils/OutputUtils";
1919
import * as systemUtils from "../utils/SystemUtils";
2020
import { toWslPath, useWsl } from "../utils/SystemUtils";
2121
import { getOpenClearProblemCacheTime, isOpenClearProblemCache } from "../utils/ConfigUtils";
2222
import { BABA, BABAMediator, BABAProxy, BabaStr, BaseCC } from "../BABA";
2323
import { sysCall } from "../utils/SystemUtils";
24+
import { TreeNodeModel } from "../model/TreeNodeModel";
2425

2526
class ExecuteService implements Disposable {
2627
private leetCodeCliResourcesRootPath: string;
@@ -134,7 +135,7 @@ class ExecuteService implements Disposable {
134135
}
135136

136137
public async showProblem(
137-
problemNode: IProblem,
138+
problemNode: TreeNodeModel,
138139
language: string,
139140
filePath: string,
140141
showDescriptionInComment: boolean = false,
@@ -314,7 +315,7 @@ class ExecuteService implements Disposable {
314315
}
315316
}
316317

317-
public async toggleFavorite(node: IProblem, addToFavorite: boolean): Promise<void> {
318+
public async toggleFavorite(node: TreeNodeModel, addToFavorite: boolean): Promise<void> {
318319
const commandParams: string[] = [await this.getLeetCodeBinaryPath(), "star", node.qid];
319320
if (!addToFavorite) {
320321
commandParams.push("-d");

src/controller/BricksViewController.ts

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import { BABA, BabaStr } from "../BABA";
1212

1313
import { bricksDao } from "../dao/bricksDao";
1414
import { groupDao } from "../dao/groupDao";
15-
import { BricksNormalId, defaultProblem, IQuickItemEx } from "../model/ConstDefind";
16-
import { BricksNode } from "../model/NodeModel";
15+
import { BricksNormalId, IQuickItemEx } from "../model/ConstDefind";
16+
import { TreeNodeModel, TreeNodeType } from "../model/TreeNodeModel";
1717

1818
// 视图控制器
1919
class BricksViewController implements Disposable {
2020
// 需要的
2121
public async getHaveNodes() {
2222
let all_qid: string[] = await bricksDao.getTodayBricks();
23-
const baseNode: BricksNode[] = [];
23+
const baseNode: TreeNodeModel[] = [];
2424
all_qid.forEach((qid) => {
2525
let node = BABA.getProxy(BabaStr.QuestionDataProxy).getNodeByQid(qid);
2626
if (node) {
@@ -34,64 +34,63 @@ class BricksViewController implements Disposable {
3434
// 增加tooltip
3535
let all_qid: string[] = await bricksDao.getTodayBricksSubmit();
3636
let qid_tip = await bricksDao.getTodayBricksSubmitToolTip(all_qid);
37-
const baseNode: BricksNode[] = [];
37+
const baseNode: TreeNodeModel[] = [];
3838
all_qid.forEach((qid) => {
3939
let node = BABA.getProxy(BabaStr.QuestionDataProxy).getNodeByQid(qid);
4040
if (node) {
41-
let new_obj = new BricksNode(
42-
Object.assign({}, node.data, {}),
43-
true,
44-
node.user_score,
45-
TreeItemCollapsibleState.None,
46-
0,
47-
qid_tip.get(qid)
41+
let new_obj = new TreeNodeModel(
42+
Object.assign({}, node.get_data(), {
43+
collapsibleState: TreeItemCollapsibleState.None,
44+
groupTime: 0,
45+
toolTip: qid_tip.get(qid),
46+
}),
47+
TreeNodeType.BricksDataLeaf
4848
);
4949
baseNode.push(new_obj);
5050
}
5151
});
5252
return baseNode;
5353
}
5454

55-
public async getDiyNode(element: BricksNode) {
55+
public async getDiyNode(element: TreeNodeModel) {
5656
let time = element.groupTime;
5757
if (time == undefined) {
5858
return [];
5959
}
6060
let all_qid: string[] = await groupDao.getQidByTime(time);
61-
const baseNode: BricksNode[] = [];
61+
const baseNode: TreeNodeModel[] = [];
6262
all_qid.forEach((qid) => {
6363
let node = BABA.getProxy(BabaStr.QuestionDataProxy).getNodeByQid(qid);
6464
if (node) {
65-
let new_obj = new BricksNode(
66-
Object.assign({}, node.data, {}),
67-
true,
68-
node.user_score,
69-
TreeItemCollapsibleState.None,
70-
time
65+
let new_obj = new TreeNodeModel(
66+
Object.assign({}, node.get_data(), {
67+
collapsibleState: TreeItemCollapsibleState.None,
68+
groupTime: time,
69+
}),
70+
TreeNodeType.BricksDataLeaf
7171
);
7272
baseNode.push(new_obj);
7373
}
7474
});
7575
return baseNode;
7676
}
7777

78-
public async getRootNodes(): Promise<BricksNode[]> {
78+
public async getRootNodes(): Promise<TreeNodeModel[]> {
7979
let all_qid: string[] = await bricksDao.getTodayBricks();
8080
let all_submit_qid: string[] = await bricksDao.getTodayBricksSubmit();
8181

8282
let has_qid = all_qid.length > 0;
8383
let has_submit = all_submit_qid.length > 0;
84-
const baseNode: BricksNode[] = [];
84+
const baseNode: TreeNodeModel[] = [];
8585
// 监工
8686
baseNode.push(
87-
new BricksNode(
88-
Object.assign({}, defaultProblem, {
87+
new TreeNodeModel(
88+
{
8989
id: has_qid ? BricksNormalId.Have : BricksNormalId.No,
9090
name: has_qid ? BricksNormalId.HaveDesc : BricksNormalId.NoDesc,
91-
}),
92-
false,
93-
0,
94-
has_qid ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.None
91+
collapsibleState: has_qid ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.None,
92+
},
93+
TreeNodeType.BricksDataNormal
9594
)
9695
);
9796

@@ -106,40 +105,39 @@ class BricksViewController implements Disposable {
106105
});
107106

108107
baseNode.push(
109-
new BricksNode(
110-
Object.assign({}, defaultProblem, {
108+
new TreeNodeModel(
109+
{
111110
id: BricksNormalId.Today,
112111
name:
113112
`今天搬了${all_submit_qid.length}块砖,赚了${temp_score}分` +
114113
(all_submit_qid.length > 3 ? ",又是上分的一天~" : ",别吹牛了,赶紧干活啊!!!"),
115-
}),
116-
false,
117-
0,
118-
TreeItemCollapsibleState.Collapsed
114+
collapsibleState: TreeItemCollapsibleState.Collapsed,
115+
},
116+
TreeNodeType.BricksDataNormal
119117
)
120118
);
121119
}
122120
// 分类
123121
let all_group = await groupDao.getAllGroup();
124122
all_group.forEach((element) => {
125123
baseNode.push(
126-
new BricksNode(
127-
Object.assign({}, defaultProblem, {
124+
new TreeNodeModel(
125+
{
128126
id: BricksNormalId.DIY,
129127
name: element.name,
130-
}),
131-
false,
132-
0,
133-
TreeItemCollapsibleState.Collapsed,
134-
element.time
128+
collapsibleState: TreeItemCollapsibleState.Collapsed,
129+
groupTime: element.time,
130+
},
131+
132+
TreeNodeType.BricksDataNormal
135133
)
136134
);
137135
});
138136

139137
return baseNode;
140138
}
141139

142-
public async setBricksType(node: BricksNode, type) {
140+
public async setBricksType(node: TreeNodeModel, type) {
143141
await BABA.getProxy(BabaStr.BricksDataProxy).setBricksType(node, type);
144142
}
145143
public dispose(): void {}
@@ -163,7 +161,7 @@ class BricksViewController implements Disposable {
163161
BABA.sendNotification(BabaStr.BricksData_removeBrickGroupFinish);
164162
}
165163

166-
public async addQidToGroup(node: BricksNode) {
164+
public async addQidToGroup(node: TreeNodeModel) {
167165
const picks: Array<IQuickItemEx<string>> = [];
168166

169167
let all_group = await BABA.getProxy(BabaStr.BricksDataProxy).getAllGroup();

0 commit comments

Comments
 (0)