Add AbstractCreator
This commit is contained in:
parent
3a0b807ed5
commit
8e02bf62bf
|
@ -14,3 +14,7 @@ Every KO should have properties:
|
||||||
|
|
||||||
- uid
|
- uid
|
||||||
- tags (with class)
|
- tags (with class)
|
||||||
|
|
||||||
|
## Abbreviations
|
||||||
|
|
||||||
|
- fm - FrontMatter
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import DailyNote from "../../../../core/src/domain/DailyNote";
|
import DailyNote from "../../../../core/src/domain/DailyNote";
|
||||||
import {TFile} from "obsidian";
|
import {TFile} from "obsidian";
|
||||||
import DailyNoteCreator from "../../utils/DailyNoteCreator";
|
import DailyNoteCreator from "../../utils/creators/DailyNoteCreator";
|
||||||
import AppUtils from "../../utils/AppUtils";
|
import AppUtils from "../../utils/AppUtils";
|
||||||
import DailyNoteRepository from "../../../../core/src/ports/output/DailyNoteRepository";
|
import DailyNoteRepository from "../../../../core/src/ports/output/DailyNoteRepository";
|
||||||
|
|
||||||
|
@ -20,6 +20,6 @@ export default class DailyNotePersistenceAdapter implements DailyNoteRepository
|
||||||
return this.appUtils.getTagsFromFile(f).includes("TMS/DailyNote");
|
return this.appUtils.getTagsFromFile(f).includes("TMS/DailyNote");
|
||||||
});
|
});
|
||||||
|
|
||||||
return rawDailyNotes.map(f => this.dailyNoteCreator.createFromTFile(f));
|
return Promise.all(rawDailyNotes.map(async f => await this.dailyNoteCreator.create(f)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
import AppUtils from "./AppUtils";
|
|
||||||
import {TFile} from "obsidian";
|
|
||||||
import Area from "../../../core/src/domain/Area";
|
|
||||||
import {UUID} from "node:crypto";
|
|
||||||
|
|
||||||
export default class AreaCreator {
|
|
||||||
constructor(private appUtils: AppUtils) {
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(file: TFile): Promise<Area> {
|
|
||||||
const koProperties = this.appUtils.getFrontmatterOrThrow(file);
|
|
||||||
|
|
||||||
const id: UUID = koProperties["uid"] as UUID;
|
|
||||||
|
|
||||||
let parentArea: Area | null = null;
|
|
||||||
const parentStr: string = koProperties["a-parent"];
|
|
||||||
if (parentStr) {
|
|
||||||
const file = this.appUtils.getTFileFromStrLink(parentStr);
|
|
||||||
parentArea = await this.create(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Area(id, file.name.replace(".md", ""), parentArea)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
import {TFile} from "obsidian";
|
|
||||||
import DailyNote from "../../../core/src/domain/DailyNote";
|
|
||||||
import AppUtils from "./AppUtils";
|
|
||||||
import {UUID} from "node:crypto";
|
|
||||||
|
|
||||||
export default class DailyNoteCreator {
|
|
||||||
constructor(private appUtils: AppUtils) {
|
|
||||||
}
|
|
||||||
|
|
||||||
createFromTFile(file: TFile) {
|
|
||||||
const frontmatter = this.appUtils.getFrontmatterOrThrow(file);
|
|
||||||
const id = frontmatter["uid"] as UUID;
|
|
||||||
const dateStr = frontmatter["dn-date"];
|
|
||||||
const date = new Date(dateStr);
|
|
||||||
return new DailyNote(id, date);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
import AppUtils from "./AppUtils";
|
|
||||||
import {TFile} from "obsidian";
|
|
||||||
import {UUID} from "node:crypto";
|
|
||||||
import Effort from "../../../core/src/domain/effort/Effort";
|
|
||||||
import {EffortStatus} from "../../../core/src/domain/effort/EffortStatus";
|
|
||||||
import Area from "../../../core/src/domain/Area";
|
|
||||||
import AreaCreator from "./AreaCreator";
|
|
||||||
|
|
||||||
export default class EffortCreator {
|
|
||||||
constructor(private appUtils: AppUtils, private areaCreator: AreaCreator) {
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(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 = await this.areaCreator.create(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
let parent: Effort | null = null;
|
|
||||||
const parentStr: string = koProperties["e-parent"];
|
|
||||||
if (parentStr) {
|
|
||||||
const file = this.appUtils.getTFileFromStrLink(parentStr);
|
|
||||||
parent = await this.create(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
const body: string = await this.appUtils.getFileBody(file);
|
|
||||||
return new Effort(id, file.name.replace(".md", ""), status, started, ended, area, parent, body);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
import {TFile} from "obsidian";
|
|
||||||
import KObject from "../../../core/src/domain/KObject";
|
|
||||||
import {KOC} from "../../../core/src/domain/KOC";
|
|
||||||
import AppUtils from "./AppUtils";
|
|
||||||
import Area from "../../../core/src/domain/Area";
|
|
||||||
import {UUID} from "node:crypto";
|
|
||||||
import KOCFactory from "./KOCFactory";
|
|
||||||
import ExoContext from "../../../common/ExoContext";
|
|
||||||
|
|
||||||
export default class KObjectCreator {
|
|
||||||
constructor(private appUtils: AppUtils, private ctx: ExoContext) {
|
|
||||||
}
|
|
||||||
|
|
||||||
createFromTFile(file: TFile) {
|
|
||||||
const frontmatter = this.appUtils.getFrontmatterOrThrow(file);
|
|
||||||
const id = frontmatter["uid"] as UUID;
|
|
||||||
const koc = this.getFileKoc(file);
|
|
||||||
return new KObject(id, koc);
|
|
||||||
}
|
|
||||||
|
|
||||||
async createFromTFileTyped(file: TFile) {
|
|
||||||
const koc = this.getFileKoc(file);
|
|
||||||
switch (koc) {
|
|
||||||
case KOC.EMS_AREA:
|
|
||||||
return this.createArea(file);
|
|
||||||
case KOC.EMS_EFFORT:
|
|
||||||
return await this.ctx.effortCreator.create(file);
|
|
||||||
default:
|
|
||||||
throw new Error("Not implemented createFromTFileTyped")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
createArea(file: TFile): Area {
|
|
||||||
const koProperties = this.appUtils.getFrontmatterOrThrow(file);
|
|
||||||
|
|
||||||
const id: UUID = koProperties["uid"] as UUID;
|
|
||||||
|
|
||||||
let parentArea: Area | null = null;
|
|
||||||
const parentStr: string = koProperties["a-parent"];
|
|
||||||
if (parentStr) {
|
|
||||||
const file = this.appUtils.getTFileFromStrLink(parentStr);
|
|
||||||
parentArea = this.createArea(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Area(id, file.name.replace(".md", ""), parentArea)
|
|
||||||
}
|
|
||||||
|
|
||||||
getFileKoc(file: TFile): KOC {
|
|
||||||
const tags = this.appUtils.getTagsFromFile(file);
|
|
||||||
return KOCFactory.create(tags);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,6 +4,7 @@ export default class KObjectUtility {
|
||||||
constructor(private ctx: ExoContext) {
|
constructor(private ctx: ExoContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
async addMissingId(): Promise<void> {
|
async addMissingId(): Promise<void> {
|
||||||
let allMdFiles = this.ctx.appUtils.getAllMdFiles();
|
let allMdFiles = this.ctx.appUtils.getAllMdFiles();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import {FrontMatterCache, TFile} from "obsidian";
|
||||||
|
import {UUID} from "node:crypto";
|
||||||
|
import ExoContext from "../../../../common/ExoContext";
|
||||||
|
|
||||||
|
export default abstract class AbstractCreator<KO> {
|
||||||
|
constructor(protected ctx: ExoContext) {
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(file: TFile): Promise<KO> {
|
||||||
|
const fm = this.ctx.appUtils.getFrontmatterOrThrow(file);
|
||||||
|
const id: UUID = fm["uid"] as UUID;
|
||||||
|
return this.createInternal(file, id, fm);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract createInternal(file: TFile, id: UUID, fm: FrontMatterCache): Promise<KO>;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
import {FrontMatterCache, TFile} from "obsidian";
|
||||||
|
import Area from "../../../../core/src/domain/Area";
|
||||||
|
import {UUID} from "node:crypto";
|
||||||
|
import AbstractCreator from "./AbstractCreator";
|
||||||
|
import ExoContext from "../../../../common/ExoContext";
|
||||||
|
|
||||||
|
export default class AreaCreator extends AbstractCreator<Area> {
|
||||||
|
constructor(ctx: ExoContext) {
|
||||||
|
super(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
async createInternal(file: TFile, id: UUID, fm: FrontMatterCache): Promise<Area> {
|
||||||
|
let parentArea: Area | null = null;
|
||||||
|
const parentStr: string = fm["a-parent"];
|
||||||
|
if (parentStr) {
|
||||||
|
const file = this.ctx.appUtils.getTFileFromStrLink(parentStr);
|
||||||
|
parentArea = await this.create(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Area(id, file.name.replace(".md", ""), parentArea)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
import {FrontMatterCache, TFile} from "obsidian";
|
||||||
|
import DailyNote from "../../../../core/src/domain/DailyNote";
|
||||||
|
import {UUID} from "node:crypto";
|
||||||
|
import AbstractCreator from "./AbstractCreator";
|
||||||
|
import ExoContext from "../../../../common/ExoContext";
|
||||||
|
|
||||||
|
export default class DailyNoteCreator extends AbstractCreator<DailyNote> {
|
||||||
|
constructor(ctx: ExoContext) {
|
||||||
|
super(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
async createInternal(file: TFile, id: UUID, fm: FrontMatterCache): Promise<DailyNote> {
|
||||||
|
const dateStr = fm["dn-date"];
|
||||||
|
const date = new Date(dateStr);
|
||||||
|
return new DailyNote(id, date);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
import {FrontMatterCache, TFile} from "obsidian";
|
||||||
|
import {UUID} from "node:crypto";
|
||||||
|
import Effort from "../../../../core/src/domain/effort/Effort";
|
||||||
|
import {EffortStatus} from "../../../../core/src/domain/effort/EffortStatus";
|
||||||
|
import Area from "../../../../core/src/domain/Area";
|
||||||
|
import AbstractCreator from "./AbstractCreator";
|
||||||
|
import ExoContext from "../../../../common/ExoContext";
|
||||||
|
|
||||||
|
export default class EffortCreator extends AbstractCreator<Effort> {
|
||||||
|
constructor(ctx: ExoContext) {
|
||||||
|
super(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
async createInternal(file: TFile, id: UUID, fm: FrontMatterCache): Promise<Effort> {
|
||||||
|
const status: EffortStatus = fm["e-status"] as EffortStatus;
|
||||||
|
const started: Date | null = fm["started"] ? fm["started"] as Date : null;
|
||||||
|
const ended: Date | null = fm["ended"] ? fm["ended"] as Date : null;
|
||||||
|
|
||||||
|
let area: Area | null = null;
|
||||||
|
const areaStr: string = fm["area"];
|
||||||
|
if (areaStr) {
|
||||||
|
const file = this.ctx.appUtils.getTFileFromStrLink(areaStr);
|
||||||
|
area = await this.ctx.areaCreator.create(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
let parent: Effort | null = null;
|
||||||
|
const parentStr: string = fm["e-parent"];
|
||||||
|
if (parentStr) {
|
||||||
|
const file = this.ctx.appUtils.getTFileFromStrLink(parentStr);
|
||||||
|
parent = await this.create(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
const body: string = await this.ctx.appUtils.getFileBody(file);
|
||||||
|
return new Effort(id, file.name.replace(".md", ""), status, started, ended, area, parent, body);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
import {TFile} from "obsidian";
|
||||||
|
import KObject from "../../../../core/src/domain/KObject";
|
||||||
|
import {KOC} from "../../../../core/src/domain/KOC";
|
||||||
|
import {UUID} from "node:crypto";
|
||||||
|
import KOCFactory from "../KOCFactory";
|
||||||
|
import ExoContext from "../../../../common/ExoContext";
|
||||||
|
|
||||||
|
export default class KObjectCreator {
|
||||||
|
constructor(private ctx: ExoContext) {
|
||||||
|
}
|
||||||
|
|
||||||
|
createFromTFile(file: TFile) {
|
||||||
|
const frontmatter = this.ctx.appUtils.getFrontmatterOrThrow(file);
|
||||||
|
const id = frontmatter["uid"] as UUID;
|
||||||
|
const koc = this.getFileKoc(file);
|
||||||
|
return new KObject(id, koc);
|
||||||
|
}
|
||||||
|
|
||||||
|
async createFromTFileTyped(file: TFile) {
|
||||||
|
const koc = this.getFileKoc(file);
|
||||||
|
switch (koc) {
|
||||||
|
case KOC.EMS_AREA:
|
||||||
|
return this.ctx.areaCreator.create(file);
|
||||||
|
case KOC.EMS_EFFORT:
|
||||||
|
return await this.ctx.effortCreator.create(file);
|
||||||
|
default:
|
||||||
|
throw new Error("Not implemented createFromTFileTyped")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getFileKoc(file: TFile): KOC {
|
||||||
|
const tags = this.ctx.appUtils.getTagsFromFile(file);
|
||||||
|
return KOCFactory.create(tags);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
import {App} from "obsidian";
|
import {App} from "obsidian";
|
||||||
import DailyNoteRepository from "../core/src/ports/output/DailyNoteRepository";
|
import DailyNoteRepository from "../core/src/ports/output/DailyNoteRepository";
|
||||||
import Utils from "../core/src/utils/Utils";
|
import Utils from "../core/src/utils/Utils";
|
||||||
import DailyNoteCreator from "../app/src/utils/DailyNoteCreator";
|
import DailyNoteCreator from "../app/src/utils/creators/DailyNoteCreator";
|
||||||
import KObjectCreator from "../app/src/utils/KObjectCreator";
|
import KObjectCreator from "../app/src/utils/creators/KObjectCreator";
|
||||||
import AppUtils from "../app/src/utils/AppUtils";
|
import AppUtils from "../app/src/utils/AppUtils";
|
||||||
import CountNotesUseCase from "../core/src/ports/input/CountNotesUseCase";
|
import CountNotesUseCase from "../core/src/ports/input/CountNotesUseCase";
|
||||||
import CountNotesService from "../core/src/service/CountNotesService";
|
import CountNotesService from "../core/src/service/CountNotesService";
|
||||||
|
@ -15,8 +15,8 @@ import EffortRepository from "../core/src/ports/output/EffortRepository";
|
||||||
import EffortPersistenceAdapter from "../app/src/adapters/output/EffortPersistenceAdapter";
|
import EffortPersistenceAdapter from "../app/src/adapters/output/EffortPersistenceAdapter";
|
||||||
import KObjectUtility from "../app/src/utils/KObjectUtility";
|
import KObjectUtility from "../app/src/utils/KObjectUtility";
|
||||||
import EffortPathRulesHelper from "../app/src/helpers/EffortPathRulesHelper";
|
import EffortPathRulesHelper from "../app/src/helpers/EffortPathRulesHelper";
|
||||||
import EffortCreator from "../app/src/utils/EffortCreator";
|
import EffortCreator from "../app/src/utils/creators/EffortCreator";
|
||||||
import AreaCreator from "../app/src/utils/AreaCreator";
|
import AreaCreator from "../app/src/utils/creators/AreaCreator";
|
||||||
import LayoutFactory from "../app/src/adapters/input/layouts/LayoutFactory";
|
import LayoutFactory from "../app/src/adapters/input/layouts/LayoutFactory";
|
||||||
|
|
||||||
export default class ExoContext {
|
export default class ExoContext {
|
||||||
|
@ -42,10 +42,10 @@ export default class ExoContext {
|
||||||
this.appUtils = new AppUtils(this.app);
|
this.appUtils = new AppUtils(this.app);
|
||||||
this.layoutFactory = new LayoutFactory(this);
|
this.layoutFactory = new LayoutFactory(this);
|
||||||
|
|
||||||
this.dailyNoteCreator = new DailyNoteCreator(this.appUtils);
|
this.dailyNoteCreator = new DailyNoteCreator(this);
|
||||||
this.areaCreator = new AreaCreator(this.appUtils);
|
this.areaCreator = new AreaCreator(this);
|
||||||
this.effortCreator = new EffortCreator(this.appUtils, this.areaCreator);
|
this.effortCreator = new EffortCreator(this);
|
||||||
this.kObjectCreator = new KObjectCreator(this.appUtils, this);
|
this.kObjectCreator = new KObjectCreator(this);
|
||||||
|
|
||||||
this.dailyNoteRepository = new DailyNotePersistenceAdapter(this.appUtils, this.dailyNoteCreator);
|
this.dailyNoteRepository = new DailyNotePersistenceAdapter(this.appUtils, this.dailyNoteCreator);
|
||||||
this.kObjectUtility = new KObjectUtility(this);
|
this.kObjectUtility = new KObjectUtility(this);
|
||||||
|
|
Loading…
Reference in New Issue