diff --git a/src/controller/BricksViewController.ts b/src/controller/BricksViewController.ts index c8880a7..0d836b9 100644 --- a/src/controller/BricksViewController.ts +++ b/src/controller/BricksViewController.ts @@ -37,12 +37,22 @@ class BricksViewController implements Disposable { } // 今天搬的 public async getTodayNodes() { + // 增加tooltip let all_qid: string[] = await bricksDao.getTodayBricksSubmit(); + let qid_tip = await bricksDao.getTodayBricksSubmitToolTip(all_qid); const baseNode: BricksNode[] = []; all_qid.forEach((qid) => { let node = treeViewController.getNodeByQid(qid); if (node) { - baseNode.push(node); + let new_obj = new BricksNode( + Object.assign({}, node.data, {}), + true, + node.user_score, + TreeItemCollapsibleState.None, + 0, + qid_tip.get(qid) + ); + baseNode.push(new_obj); } }); return baseNode; diff --git a/src/dao/bricksDao.ts b/src/dao/bricksDao.ts index 8279451..9f7d55d 100644 --- a/src/dao/bricksDao.ts +++ b/src/dao/bricksDao.ts @@ -8,10 +8,10 @@ */ import { fetchProblemLanguage, selectWorkspaceFolder } from "../utils/ConfigUtils"; -import { useWsl, toWinPath, getDayStart, getDayNow } from "../utils/SystemUtils"; +import { useWsl, toWinPath, getDayStart, getDayNow, getYMD } from "../utils/SystemUtils"; import * as path from "path"; import * as fse from "fs-extra"; -import { BricksType } from "../model/Model"; +import { BricksType, BricksTypeName } from "../model/Model"; // let bricks_json = { // version: 1, @@ -75,7 +75,7 @@ class BricksDao { return allData.all_bricks || {}; } - private getTimeByType(type: number, today_time: number) { + private getTimeByType(type: number, today_time: number, add_flag?: boolean) { let need_day_ago = 7; switch (type) { case BricksType.TYPE_0: @@ -108,7 +108,35 @@ class BricksDao { default: break; } - return today_time - need_day_ago * 86400; + + return add_flag ? today_time + need_day_ago * 86400 : today_time - need_day_ago * 86400; + } + + private getTypeName(type: number) { + switch (type) { + case BricksType.TYPE_0: + return BricksTypeName.TYPE_0; + case BricksType.TYPE_1: + // 1:(14天搬砖simple) + return BricksTypeName.TYPE_1; + case BricksType.TYPE_2: + // 2:(7天后搬砖simple_error) + return BricksTypeName.TYPE_2; + case BricksType.TYPE_3: + // 3:(5天后搬砖simple_time) + return BricksTypeName.TYPE_3; + case BricksType.TYPE_4: + // 4:(3天后搬砖(time_limit)) + return BricksTypeName.TYPE_4; + case BricksType.TYPE_5: + // 5:(2天后搬砖(medium)) + return BricksTypeName.TYPE_5; + case BricksType.TYPE_6: + // 6: (1天后搬砖(hard)) + return BricksTypeName.TYPE_6; + default: + return ""; + } } public async getTodayBricks(): Promise { @@ -143,6 +171,34 @@ class BricksDao { return all_qid; } + public async getTodayBricksSubmitToolTip(qid_list: Array) { + let today_time = getDayStart(); + let all_bricks = await this.getAllBricks(); + let result: Map = new Map(); + qid_list.forEach((qid) => { + const value = all_bricks[qid]; + if (value == undefined) { + result.set(qid, this.TypetimeToMan(BricksType.TYPE_2, this.getTimeByType(BricksType.TYPE_2, today_time, true))); + } else { + result.set( + qid, + this.TypetimeToMan( + value.type ? value.type : BricksType.TYPE_2, + this.getTimeByType(value.type ? value.type : BricksType.TYPE_2, today_time, true) + ) + ); + } + }); + return result; + } + public TypetimeToMan(type, time: number) { + if (time < 10) { + return BricksTypeName.TYPE_0; + } + + return `${this.getTypeName(type)}后${getYMD(time)}出现`; //this.getTypeName(type) + getYMD(time) + "出现"; + } + public async getInfoByQid(qid: string) { let all_bricks = await this.getAllBricks(); return all_bricks[qid] || {}; diff --git a/src/model/Model.ts b/src/model/Model.ts index e11464a..32196b0 100644 --- a/src/model/Model.ts +++ b/src/model/Model.ts @@ -170,6 +170,17 @@ export enum BricksType { TYPE_7 = 7, } +export enum BricksTypeName { + TYPE_0 = "不再出现", + TYPE_1 = "14天", + TYPE_2 = "7天", + TYPE_3 = "5天", + TYPE_4 = "3天", + TYPE_5 = "2天", + TYPE_6 = "1天", + TYPE_7 = "999天", +} + export enum Category { All = "All", Difficulty = "Difficulty", diff --git a/src/model/NodeModel.ts b/src/model/NodeModel.ts index c85a1c2..d4e5f2d 100644 --- a/src/model/NodeModel.ts +++ b/src/model/NodeModel.ts @@ -143,10 +143,19 @@ export class NodeModel { export class BricksNode extends NodeModel { public collapsibleState?; public groupTime?; - constructor(data: IProblem, ipn: boolean = true, userscore: number = 0, collapsibleState = 0, groupTime?: number) { + public toolTip?; + constructor( + data: IProblem, + ipn: boolean = true, + userscore: number = 0, + collapsibleState = 0, + groupTime?: number, + toolTip?: string + ) { super(data, ipn, userscore); this.isProblemNode = ipn; this.collapsibleState = collapsibleState; this.groupTime = groupTime; + this.toolTip = toolTip; } } diff --git a/src/service/BricksDataService.ts b/src/service/BricksDataService.ts index b9753be..e78d11e 100644 --- a/src/service/BricksDataService.ts +++ b/src/service/BricksDataService.ts @@ -125,6 +125,9 @@ export class BricksDataService implements TreeDataProvider { if (element.id === "ROOT") { return ""; } + if (element.toolTip) { + return element.toolTip; + } return ""; } diff --git a/src/utils/SystemUtils.ts b/src/utils/SystemUtils.ts index 84bd6ff..0fe1886 100644 --- a/src/utils/SystemUtils.ts +++ b/src/utils/SystemUtils.ts @@ -101,3 +101,12 @@ export function getRemakeName(): string { const newDate = `${year}-${month}-${day} ${hours}:${min}:${s}`; return newDate; } + +export function getYMD(timeSecond: number): string { + const date = timeSecond ? new Date(timeSecond * 1000) : new Date(); + const year = date.getFullYear(); + const month = date.getMonth() + 1 >= 10 ? date.getMonth() + 1 : `0${date.getMonth() + 1}`; + const day = date.getDate() >= 10 ? date.getDate() : `0${date.getDate()}`; + const newDate = `${year}-${month}-${day}`; + return newDate; +}