Small refactoring
This commit is contained in:
parent
01196da3b7
commit
3a0b807ed5
|
@ -4,12 +4,11 @@ import {KOC} from "../../../core/src/domain/KOC";
|
|||
import AppUtils from "./AppUtils";
|
||||
import Area from "../../../core/src/domain/Area";
|
||||
import {UUID} from "node:crypto";
|
||||
import Effort from "../../../core/src/domain/effort/Effort";
|
||||
import {EffortStatus} from "../../../core/src/domain/effort/EffortStatus";
|
||||
import KOCFactory from "./KOCFactory";
|
||||
import ExoContext from "../../../common/ExoContext";
|
||||
|
||||
export default class KObjectCreator {
|
||||
constructor(private appUtils: AppUtils) {
|
||||
constructor(private appUtils: AppUtils, private ctx: ExoContext) {
|
||||
}
|
||||
|
||||
createFromTFile(file: TFile) {
|
||||
|
@ -25,7 +24,7 @@ export default class KObjectCreator {
|
|||
case KOC.EMS_AREA:
|
||||
return this.createArea(file);
|
||||
case KOC.EMS_EFFORT:
|
||||
return await this.createEffort(file);
|
||||
return await this.ctx.effortCreator.create(file);
|
||||
default:
|
||||
throw new Error("Not implemented createFromTFileTyped")
|
||||
}
|
||||
|
@ -46,35 +45,6 @@ export default class KObjectCreator {
|
|||
return new Area(id, file.name.replace(".md", ""), parentArea)
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
async createEffort(file: TFile): Promise<Effort> {
|
||||
const koProperties = this.appUtils.getFrontmatterOrThrow(file);
|
||||
|
||||
const id: UUID = koProperties["uid"] as UUID;
|
||||
const status: EffortStatus = koProperties["e-status"] as EffortStatus;
|
||||
const started: Date | null = koProperties["started"] ? koProperties["started"] as Date : null;
|
||||
const ended: Date | null = koProperties["ended"] ? koProperties["ended"] as Date : null;
|
||||
|
||||
let area: Area | null = null;
|
||||
const areaStr: string = koProperties["area"];
|
||||
if (areaStr) {
|
||||
const file = this.appUtils.getTFileFromStrLink(areaStr);
|
||||
area = this.createArea(file);
|
||||
}
|
||||
|
||||
let parent: Effort | null = null;
|
||||
const parentStr: string = koProperties["e-parent"];
|
||||
if (parentStr) {
|
||||
const file = this.appUtils.getTFileFromStrLink(parentStr);
|
||||
parent = await this.createEffort(file);
|
||||
}
|
||||
|
||||
const body: string = await this.appUtils.getFileBody(file);
|
||||
return new Effort(id, file.name.replace(".md", ""), status, started, ended, area, parent, body);
|
||||
}
|
||||
|
||||
getFileKoc(file: TFile): KOC {
|
||||
const tags = this.appUtils.getTagsFromFile(file);
|
||||
return KOCFactory.create(tags);
|
||||
|
|
|
@ -42,10 +42,10 @@ export default class ExoContext {
|
|||
this.appUtils = new AppUtils(this.app);
|
||||
this.layoutFactory = new LayoutFactory(this);
|
||||
|
||||
this.kObjectCreator = new KObjectCreator(this.appUtils);
|
||||
this.dailyNoteCreator = new DailyNoteCreator(this.appUtils);
|
||||
this.areaCreator = new AreaCreator(this.appUtils);
|
||||
this.effortCreator = new EffortCreator(this.appUtils, this.areaCreator);
|
||||
this.kObjectCreator = new KObjectCreator(this.appUtils, this);
|
||||
|
||||
this.dailyNoteRepository = new DailyNotePersistenceAdapter(this.appUtils, this.dailyNoteCreator);
|
||||
this.kObjectUtility = new KObjectUtility(this);
|
||||
|
|
Loading…
Reference in New Issue