Small refactoring
This commit is contained in:
parent
8e02bf62bf
commit
edefd702a8
|
@ -20,8 +20,4 @@ export default class ExoCommands {
|
||||||
new CreateEffortExoCommand(ctx)
|
new CreateEffortExoCommand(ctx)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
static bySlug(ctx: ExoContext, slug: string): ExoCommand | undefined {
|
|
||||||
return ExoCommands.all(ctx).find(c => c.slug === slug);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,10 +118,6 @@ export default class AppUtils {
|
||||||
return this.app.vault.getMarkdownFiles();
|
return this.app.vault.getMarkdownFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
getFileCache(file: TFile): CachedMetadata | null {
|
|
||||||
return this.app.metadataCache.getFileCache(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
findMdWith(filter: (f: TFile) => boolean) {
|
findMdWith(filter: (f: TFile) => boolean) {
|
||||||
return this.getAllMdFiles().filter(filter);
|
return this.getAllMdFiles().filter(filter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ export default class KObjectUtility {
|
||||||
|
|
||||||
for (let f of withoutId) {
|
for (let f of withoutId) {
|
||||||
await this.ctx.app.fileManager.processFrontMatter(f, (frontmatter) => {
|
await this.ctx.app.fileManager.processFrontMatter(f, (frontmatter) => {
|
||||||
frontmatter['uid'] = crypto.randomUUID();
|
frontmatter['uid'] = this.ctx.utils.generateUid();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import {UUID} from "node:crypto";
|
||||||
import ExoContext from "../../../../common/ExoContext";
|
import ExoContext from "../../../../common/ExoContext";
|
||||||
|
|
||||||
export default abstract class AbstractCreator<KO> {
|
export default abstract class AbstractCreator<KO> {
|
||||||
constructor(protected ctx: ExoContext) {
|
protected constructor(protected ctx: ExoContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(file: TFile): Promise<KO> {
|
async create(file: TFile): Promise<KO> {
|
||||||
|
|
|
@ -38,7 +38,7 @@ export default class ExoContext {
|
||||||
public readonly effortPathRulesHelper: EffortPathRulesHelper;
|
public readonly effortPathRulesHelper: EffortPathRulesHelper;
|
||||||
|
|
||||||
constructor(public app: App) {
|
constructor(public app: App) {
|
||||||
this.utils = new Utils(this.app);
|
this.utils = new Utils();
|
||||||
this.appUtils = new AppUtils(this.app);
|
this.appUtils = new AppUtils(this.app);
|
||||||
this.layoutFactory = new LayoutFactory(this);
|
this.layoutFactory = new LayoutFactory(this);
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ export default class ExoContext {
|
||||||
this.countNotesUseCase = new CountNotesService(this.appUtils);
|
this.countNotesUseCase = new CountNotesService(this.appUtils);
|
||||||
this.getCurrentDNUseCase = new GetCurrentDailyNoteService(this.dailyNoteRepository);
|
this.getCurrentDNUseCase = new GetCurrentDailyNoteService(this.dailyNoteRepository);
|
||||||
this.effortRepository = new EffortPersistenceAdapter(this);
|
this.effortRepository = new EffortPersistenceAdapter(this);
|
||||||
this.createEffortUseCase = new CreateEffortService(this.effortRepository);
|
this.createEffortUseCase = new CreateEffortService(this);
|
||||||
this.effortPathRulesHelper = new EffortPathRulesHelper(this);
|
this.effortPathRulesHelper = new EffortPathRulesHelper(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,29 @@
|
||||||
import CreateEffortUseCase from "../ports/input/CreateEffortUseCase";
|
import CreateEffortUseCase from "../ports/input/CreateEffortUseCase";
|
||||||
import Area from "../domain/Area";
|
import Area from "../domain/Area";
|
||||||
import {EffortStatus} from "../domain/effort/EffortStatus";
|
import {EffortStatus} from "../domain/effort/EffortStatus";
|
||||||
import EffortRepository from "../ports/output/EffortRepository";
|
|
||||||
import {UUID} from "node:crypto";
|
|
||||||
import Effort from "../domain/effort/Effort";
|
import Effort from "../domain/effort/Effort";
|
||||||
|
import ExoContext from "../../../common/ExoContext";
|
||||||
|
|
||||||
export default class CreateEffortService implements CreateEffortUseCase {
|
export default class CreateEffortService implements CreateEffortUseCase {
|
||||||
constructor(private effortRepository: EffortRepository) {
|
constructor(private ctx: ExoContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async taskUnderArea(area: Area): Promise<Effort> {
|
async taskUnderArea(area: Area): Promise<Effort> {
|
||||||
const title = crypto.randomUUID();
|
const title = this.ctx.utils.generateUid();
|
||||||
const id = crypto.randomUUID() as UUID;
|
const id = this.ctx.utils.generateUid();
|
||||||
const effort = new Effort(id, title, EffortStatus.DRAFT, null, null, area, null, "Body");
|
const effort = new Effort(id, title, EffortStatus.DRAFT, null, null, area, null, "Body");
|
||||||
|
|
||||||
await this.effortRepository.save(effort);
|
await this.ctx.effortRepository.save(effort);
|
||||||
|
|
||||||
return effort;
|
return effort;
|
||||||
}
|
}
|
||||||
|
|
||||||
async taskUnderEffort(parentEffort: Effort): Promise<Effort> {
|
async taskUnderEffort(parentEffort: Effort): Promise<Effort> {
|
||||||
const title = crypto.randomUUID();
|
const title = this.ctx.utils.generateUid();
|
||||||
const id = crypto.randomUUID() as UUID;
|
const id = this.ctx.utils.generateUid();
|
||||||
const effort = new Effort(id, title, EffortStatus.DRAFT, null, null, null, parentEffort, "Body");
|
const effort = new Effort(id, title, EffortStatus.DRAFT, null, null, null, parentEffort, "Body");
|
||||||
|
|
||||||
await this.effortRepository.save(effort);
|
await this.ctx.effortRepository.save(effort);
|
||||||
|
|
||||||
return effort;
|
return effort;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
import {App} from "obsidian";
|
import {UUID} from "node:crypto";
|
||||||
|
|
||||||
export default class Utils {
|
export default class Utils {
|
||||||
|
generateUid(): UUID {
|
||||||
constructor(private app: App) {
|
return crypto.randomUUID() as UUID;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
generateUid(): string {
|
|
||||||
return crypto.randomUUID();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue