Skip to content

Commit c7de493

Browse files
authored
Merge pull request #125 from ccagml/main
2.11.1
2 parents 39c4466 + 501553a commit c7de493

File tree

6 files changed

+104
-6
lines changed

6 files changed

+104
-6
lines changed

src/controller/BricksViewController.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,22 @@ class BricksViewController implements Disposable {
3737
}
3838
// 今天搬的
3939
public async getTodayNodes() {
40+
// 增加tooltip
4041
let all_qid: string[] = await bricksDao.getTodayBricksSubmit();
42+
let qid_tip = await bricksDao.getTodayBricksSubmitToolTip(all_qid);
4143
const baseNode: BricksNode[] = [];
4244
all_qid.forEach((qid) => {
4345
let node = treeViewController.getNodeByQid(qid);
4446
if (node) {
45-
baseNode.push(node);
47+
let new_obj = new BricksNode(
48+
Object.assign({}, node.data, {}),
49+
true,
50+
node.user_score,
51+
TreeItemCollapsibleState.None,
52+
0,
53+
qid_tip.get(qid)
54+
);
55+
baseNode.push(new_obj);
4656
}
4757
});
4858
return baseNode;

src/dao/bricksDao.ts

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

1010
import { fetchProblemLanguage, selectWorkspaceFolder } from "../utils/ConfigUtils";
11-
import { useWsl, toWinPath, getDayStart, getDayNow } from "../utils/SystemUtils";
11+
import { useWsl, toWinPath, getDayStart, getDayNow, getYMD } from "../utils/SystemUtils";
1212
import * as path from "path";
1313
import * as fse from "fs-extra";
14-
import { BricksType } from "../model/Model";
14+
import { BricksType, BricksTypeName } from "../model/Model";
1515

1616
// let bricks_json = {
1717
// version: 1,
@@ -75,7 +75,7 @@ class BricksDao {
7575
return allData.all_bricks || {};
7676
}
7777

78-
private getTimeByType(type: number, today_time: number) {
78+
private getTimeByType(type: number, today_time: number, add_flag?: boolean) {
7979
let need_day_ago = 7;
8080
switch (type) {
8181
case BricksType.TYPE_0:
@@ -108,7 +108,35 @@ class BricksDao {
108108
default:
109109
break;
110110
}
111-
return today_time - need_day_ago * 86400;
111+
112+
return add_flag ? today_time + need_day_ago * 86400 : today_time - need_day_ago * 86400;
113+
}
114+
115+
private getTypeName(type: number) {
116+
switch (type) {
117+
case BricksType.TYPE_0:
118+
return BricksTypeName.TYPE_0;
119+
case BricksType.TYPE_1:
120+
// 1:(14天搬砖simple)
121+
return BricksTypeName.TYPE_1;
122+
case BricksType.TYPE_2:
123+
// 2:(7天后搬砖simple_error)
124+
return BricksTypeName.TYPE_2;
125+
case BricksType.TYPE_3:
126+
// 3:(5天后搬砖simple_time)
127+
return BricksTypeName.TYPE_3;
128+
case BricksType.TYPE_4:
129+
// 4:(3天后搬砖(time_limit))
130+
return BricksTypeName.TYPE_4;
131+
case BricksType.TYPE_5:
132+
// 5:(2天后搬砖(medium))
133+
return BricksTypeName.TYPE_5;
134+
case BricksType.TYPE_6:
135+
// 6: (1天后搬砖(hard))
136+
return BricksTypeName.TYPE_6;
137+
default:
138+
return "";
139+
}
112140
}
113141

114142
public async getTodayBricks(): Promise<string[]> {
@@ -143,6 +171,34 @@ class BricksDao {
143171
return all_qid;
144172
}
145173

174+
public async getTodayBricksSubmitToolTip(qid_list: Array<string>) {
175+
let today_time = getDayStart();
176+
let all_bricks = await this.getAllBricks();
177+
let result: Map<string, string> = new Map<string, string>();
178+
qid_list.forEach((qid) => {
179+
const value = all_bricks[qid];
180+
if (value == undefined) {
181+
result.set(qid, this.TypetimeToMan(BricksType.TYPE_2, this.getTimeByType(BricksType.TYPE_2, today_time, true)));
182+
} else {
183+
result.set(
184+
qid,
185+
this.TypetimeToMan(
186+
value.type ? value.type : BricksType.TYPE_2,
187+
this.getTimeByType(value.type ? value.type : BricksType.TYPE_2, today_time, true)
188+
)
189+
);
190+
}
191+
});
192+
return result;
193+
}
194+
public TypetimeToMan(type, time: number) {
195+
if (time < 10) {
196+
return BricksTypeName.TYPE_0;
197+
}
198+
199+
return `${this.getTypeName(type)}${getYMD(time)}出现`; //this.getTypeName(type) + getYMD(time) + "出现";
200+
}
201+
146202
public async getInfoByQid(qid: string) {
147203
let all_bricks = await this.getAllBricks();
148204
return all_bricks[qid] || {};

src/model/Model.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ export enum BricksType {
170170
TYPE_7 = 7,
171171
}
172172

173+
export enum BricksTypeName {
174+
TYPE_0 = "不再出现",
175+
TYPE_1 = "14天",
176+
TYPE_2 = "7天",
177+
TYPE_3 = "5天",
178+
TYPE_4 = "3天",
179+
TYPE_5 = "2天",
180+
TYPE_6 = "1天",
181+
TYPE_7 = "999天",
182+
}
183+
173184
export enum Category {
174185
All = "All",
175186
Difficulty = "Difficulty",

src/model/NodeModel.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,19 @@ export class NodeModel {
143143
export class BricksNode extends NodeModel {
144144
public collapsibleState?;
145145
public groupTime?;
146-
constructor(data: IProblem, ipn: boolean = true, userscore: number = 0, collapsibleState = 0, groupTime?: number) {
146+
public toolTip?;
147+
constructor(
148+
data: IProblem,
149+
ipn: boolean = true,
150+
userscore: number = 0,
151+
collapsibleState = 0,
152+
groupTime?: number,
153+
toolTip?: string
154+
) {
147155
super(data, ipn, userscore);
148156
this.isProblemNode = ipn;
149157
this.collapsibleState = collapsibleState;
150158
this.groupTime = groupTime;
159+
this.toolTip = toolTip;
151160
}
152161
}

src/service/BricksDataService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ export class BricksDataService implements TreeDataProvider<BricksNode> {
125125
if (element.id === "ROOT") {
126126
return "";
127127
}
128+
if (element.toolTip) {
129+
return element.toolTip;
130+
}
128131
return "";
129132
}
130133

src/utils/SystemUtils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,12 @@ export function getRemakeName(): string {
101101
const newDate = `${year}-${month}-${day} ${hours}:${min}:${s}`;
102102
return newDate;
103103
}
104+
105+
export function getYMD(timeSecond: number): string {
106+
const date = timeSecond ? new Date(timeSecond * 1000) : new Date();
107+
const year = date.getFullYear();
108+
const month = date.getMonth() + 1 >= 10 ? date.getMonth() + 1 : `0${date.getMonth() + 1}`;
109+
const day = date.getDate() >= 10 ? date.getDate() : `0${date.getDate()}`;
110+
const newDate = `${year}-${month}-${day}`;
111+
return newDate;
112+
}

0 commit comments

Comments
 (0)