Skip to content

Commit

Permalink
Features/add-create-new-project-modal
Browse files Browse the repository at this point in the history
* # `PrjTaskManagementModel` etc...
- The `aliases` field has been inserted.
- Added the option to start with an empty file.

* # `API`
- The helper class is made available in the API.

* # `Helper`
- Added a function to generate acronyms.

* # `MetadataCache`
- The field `Cache` has been renamed correctly to `cache`.

* # `PrjTaskManagementModel` etc...
- Added the `aliases` field.
- Added the option to start with an empty file.

* # `BaseModel`
- Fixed a bug in the `resolveProxyValue` method which caused problems when adding a new array.

* - Refactor modal form classes# `ModalFormBase`
- Class and file renamed.
- Further modal form types added.

* # `PrjSettings`
- Default folder for the project files added to the settings.

* # `CreateNewProjectModal`
- First version of the form for creating a new project.

# `Main`
- Corresponding command is registered.

* # `Styles`
- Added more places to optimize the display of Markdown in my tables for `ol` elements.

# `SettingTab` and `PrjSettings`
- Added settings for templates to the respective files.
- Added corresponding settings fields.
- Changed the language selection field to a dropdown field.

# `Helper`
- Added a method `openFile`, which opens a file and makes it visible.

# `MetadataCache`
- Changed the metadata cache array accessible via `get` to use the same array permanently.
- The private method `refreshMetadataCacheArray` is now called in the corresponding event handlers and updates the array, if necessary by emptying it and refilling it with the new data.
This ensures that the reference remains permanently the same.

# GetMetadata
- Switched to the `Helper.openFile` command.

* # `ProjectComponents`
- Changed the summary field to TextArea.

# `SearchInput`
- Added the possibility to specify a search text.

# `*BlockRenderComponent`
- Adjusted the logic accordingly so that the search field is retained even after a refresh.

* # `*Data`
- All four data classes have been adapted so that the correct type certainly exists in them, unless it is specified.

* # `BaseModel`
- Corrected the order of file assignment. The data is now written correctly, as `_file` is present when the transaction class writes the changes down.
- When creating an "empty" object, any existing fields are now written to the open transaction or directly.

# `CreateNewMetadataModal`
- The created file is now opened after the process.

# `CreateNewProjectModal`
- Any template is now used as a basis and the file is also opened after creation.
  • Loading branch information
PxaMMaxP authored Jan 13, 2024
1 parent f9bcaa2 commit 99e11af
Show file tree
Hide file tree
Showing 30 changed files with 672 additions and 55 deletions.
2 changes: 2 additions & 0 deletions src/classes/API.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Global from "src/classes/Global";
import Helper from "src/libs/Helper";
import { StaticDocumentModel } from "src/libs/StaticModels/StaticDocumentModel";

export default class API {
public global: Global
public documentModel = StaticDocumentModel;
public helper = Helper;

constructor() {
this.global = Global.getInstance();
Expand Down
148 changes: 144 additions & 4 deletions src/classes/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ export class SettingTab extends PluginSettingTab {
.setHeading()
.setName('Localisation');

// Language
// Language (Dropdown)
new Setting(containerEl)
.setName('Language')
.setDesc('The language to use')
.addText(text => text
.setPlaceholder('en | de')
.addDropdown(dropdown => dropdown
.addOptions({
'en': 'English',
'de': 'Deutsch'
})
.setValue(this.plugin.settings.language)
.onChange(async (value) => {
this.plugin.settings.language = value;
Expand Down Expand Up @@ -94,7 +97,7 @@ export class SettingTab extends PluginSettingTab {
.setName('Base Tag')
.setDesc('The Base Tag for all Elements')
.addText(text => text
.setPlaceholder('#YourBaseTag')
.setPlaceholder('YourBaseTag (without / and #)')
.setValue(this.plugin.settings.baseTag)
.onChange(async (value) => {
this.plugin.settings.baseTag = value;
Expand Down Expand Up @@ -254,5 +257,142 @@ export class SettingTab extends PluginSettingTab {
this.plugin.settings.documentSettings.clusterSymbol = value;
await this.plugin.saveSettings();
}));

// Default Folder
new Setting(containerEl)
.setName('Default Folder')
.setDesc('The default folder for new Documents')
.addText(text => text
.setPlaceholder('')
.setValue(this.plugin.settings.documentSettings.defaultFolder)
.onChange(async (value) => {
this.plugin.settings.documentSettings.defaultFolder = value;
await this.plugin.saveSettings();
}));

// Template file
new Setting(containerEl)
.setName('Template File')
.setDesc('The Template file for new Documents')
.addText(text => text
.setPlaceholder('')
.setValue(this.plugin.settings.documentSettings.template)
.onChange(async (value) => {
this.plugin.settings.documentSettings.template = value;
await this.plugin.saveSettings();
}));

// Project Settings
new Setting(containerEl)
.setHeading()
.setName('Project Settings');

// Topic Symbol
new Setting(containerEl)
.setName('Topic Symbol')
.setDesc('The Symbol for Topics')
.addText(text => text
.setPlaceholder('album')
.setValue(this.plugin.settings.prjSettings.topicSymbol)
.onChange(async (value) => {
this.plugin.settings.prjSettings.topicSymbol = value;
await this.plugin.saveSettings();
}));

// Topic Folder
new Setting(containerEl)
.setName('Topic Folder')
.setDesc('The default folder for new Topics')
.addText(text => text
.setPlaceholder('')
.setValue(this.plugin.settings.prjSettings.topicFolder)
.onChange(async (value) => {
this.plugin.settings.prjSettings.topicFolder = value;
await this.plugin.saveSettings();
}));

// Template file
new Setting(containerEl)
.setName('Template File')
.setDesc('The Template file for new Topics')
.addText(text => text
.setPlaceholder('')
.setValue(this.plugin.settings.prjSettings.topicTemplate)
.onChange(async (value) => {
this.plugin.settings.prjSettings.topicTemplate = value;
await this.plugin.saveSettings();
}));

// Project Symbol
new Setting(containerEl)
.setName('Project Symbol')
.setDesc('The Symbol for Projects')
.addText(text => text
.setPlaceholder('album')
.setValue(this.plugin.settings.prjSettings.projectSymbol)
.onChange(async (value) => {
this.plugin.settings.prjSettings.projectSymbol = value;
await this.plugin.saveSettings();
}));

// Project Folder
new Setting(containerEl)
.setName('Project Folder')
.setDesc('The default folder for new Projects')
.addText(text => text
.setPlaceholder('')
.setValue(this.plugin.settings.prjSettings.projectFolder)
.onChange(async (value) => {
this.plugin.settings.prjSettings.projectFolder = value;
await this.plugin.saveSettings();
}));

// Template file
new Setting(containerEl)
.setName('Template File')
.setDesc('The Template file for new Projects')
.addText(text => text
.setPlaceholder('')
.setValue(this.plugin.settings.prjSettings.projectTemplate)
.onChange(async (value) => {
this.plugin.settings.prjSettings.projectTemplate = value;
await this.plugin.saveSettings();
}));

// Task Symbol
new Setting(containerEl)
.setName('Task Symbol')
.setDesc('The Symbol for Tasks')
.addText(text => text
.setPlaceholder('album')
.setValue(this.plugin.settings.prjSettings.taskSymbol)
.onChange(async (value) => {
this.plugin.settings.prjSettings.taskSymbol = value;
await this.plugin.saveSettings();
}));

// Task Folder
new Setting(containerEl)
.setName('Task Folder')
.setDesc('The default folder for new Tasks')
.addText(text => text
.setPlaceholder('')
.setValue(this.plugin.settings.prjSettings.taskFolder)
.onChange(async (value) => {
this.plugin.settings.prjSettings.taskFolder = value;
await this.plugin.saveSettings();
}));

// Template file
new Setting(containerEl)
.setName('Template File')
.setDesc('The Template file for new Tasks')
.addText(text => text
.setPlaceholder('')
.setValue(this.plugin.settings.prjSettings.taskTemplate)
.onChange(async (value) => {
this.plugin.settings.prjSettings.taskTemplate = value;
await this.plugin.saveSettings();
}));
}
}
1 change: 1 addition & 0 deletions src/interfaces/IPrjTaskManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export default interface IPrjTaskManagement {
energy: Energy | null | undefined;
due: string | null | undefined;
history: HistoryEntries | null | undefined;
aliases: string[] | null | undefined;
}
14 changes: 12 additions & 2 deletions src/libs/BlockRenderComponents/DocumentBlockRenderComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class DocumentBlockRenderComponent extends TableBlockRenderCompon
filter: ["Documents"],
maxDocuments: this.global.settings.defaultMaxShow,
search: undefined,
searchText: undefined,
batchSize: 8,
sleepBetweenBatches: 10
};
Expand Down Expand Up @@ -136,7 +137,8 @@ export default class DocumentBlockRenderComponent extends TableBlockRenderCompon

const searchBox = SearchInput.create(
this.component,
this.onSearch.bind(this));
this.onSearch.bind(this),
this.settings.searchText);
headerFilterButtons.appendChild(searchBox);
}

Expand Down Expand Up @@ -179,13 +181,16 @@ export default class DocumentBlockRenderComponent extends TableBlockRenderCompon
private async onSearch(search: string, key: string): Promise<string> {
if (key === "Enter") {
if (search !== "") {
this.settings.searchText = search;
this.settings.search = Search.parseSearchText(search);
this.onFilter();
} else {
this.settings.searchText = undefined;
this.settings.search = undefined;
this.onFilter();
}
} else if (key === "Escape") {
this.settings.searchText = undefined;
this.settings.search = undefined;
this.onFilter();
return "";
Expand Down Expand Up @@ -488,7 +493,7 @@ export default class DocumentBlockRenderComponent extends TableBlockRenderCompon
*/
protected async getModels(): Promise<DocumentModel[]> {
const templateFolder = this.global.settings.templateFolder;
const allDocumentFiles = this.metadataCache.filter(file => {
const allDocumentFiles = this.metadataCache.cache.filter(file => {
const defaultFilter = file.metadata.frontmatter?.type === "Metadata" &&
file.file.path !== this.processorSettings.source &&
!file.file.path.startsWith(templateFolder);
Expand Down Expand Up @@ -580,6 +585,11 @@ type DocumentBlockRenderSettings = {
*/
search: SearchTermsArray | undefined,

/**
* The search text.
*/
searchText: string | undefined,

/**
* The number of documents to process in one batch.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class ProjectComponents {
description: string,
onWrite: (value: string) => void) {
new EditableDataView(container, component)
.addText(text => text
.addTextarea(text => text
.setValue(description)
.setTitle(Lng.gt("Description"))
.setPlaceholder(Lng.gt("Description"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class SearchInput {
* - `search-box-sizer` - The sizer of the search input component.
* - `search-box` - The search box of the search input component.
*/
public static create(component: Component, onSearch: SearchCallback): DocumentFragment {
public static create(component: Component, onSearch: SearchCallback, defaultText?: string): DocumentFragment {
const logger = Global.getInstance().logger;
const headerItemContainer = document.createDocumentFragment();

Expand All @@ -36,6 +36,11 @@ export default class SearchInput {
const searchBoxSizer = SearchInput.createSearchBoxSizer(searchLabelContainer);
const searchBoxInput = SearchInput.createSearchBoxInput(searchBoxSizer);

if (defaultText) {
this.setSearchBoxSizerValue(searchBoxSizer, defaultText);
this.setSearchBoxInputValue(searchBoxInput, defaultText);
}

/**
* Register input event to set the search box sizer value.
*/
Expand Down
19 changes: 17 additions & 2 deletions src/libs/BlockRenderComponents/ProjectBlockRenderComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class ProjectBlockRenderComponent extends TableBlockRenderCompone
filter: ["Topic", "Project", "Task"],
maxDocuments: this.global.settings.defaultMaxShow,
search: undefined,
searchText: undefined,
batchSize: 8,
sleepBetweenBatches: 10
};
Expand Down Expand Up @@ -56,6 +57,10 @@ export default class ProjectBlockRenderComponent extends TableBlockRenderCompone
return super.build();
}

public redraw(): Promise<void> {
return super.redraw();
}

protected async draw(): Promise<void> {
const startTime = Date.now();

Expand Down Expand Up @@ -134,7 +139,8 @@ export default class ProjectBlockRenderComponent extends TableBlockRenderCompone

const searchBox = SearchInput.create(
this.component,
this.onSearch.bind(this));
this.onSearch.bind(this),
this.settings.searchText);
headerFilterButtons.appendChild(searchBox);
}

Expand Down Expand Up @@ -284,13 +290,16 @@ export default class ProjectBlockRenderComponent extends TableBlockRenderCompone
private async onSearch(search: string, key: string): Promise<string> {
if (key === "Enter") {
if (search !== "") {
this.settings.searchText = search;
this.settings.search = Search.parseSearchText(search);
this.onFilter();
} else {
this.settings.searchText = undefined;
this.settings.search = undefined;
this.onFilter();
}
} else if (key === "Escape") {
this.settings.searchText = undefined;
this.settings.search = undefined;
this.onFilter();
return "";
Expand Down Expand Up @@ -409,7 +418,7 @@ export default class ProjectBlockRenderComponent extends TableBlockRenderCompone

protected async getModels(): Promise<(PrjTaskManagementModel<TaskData | TopicData | ProjectData>)[]> {
const templateFolder = this.global.settings.templateFolder;
const allModelFiles = this.metadataCache.filter(file => {
const allModelFiles = this.metadataCache.cache.filter(file => {
const defaultFilter = (file.metadata.frontmatter?.type === "Topic" || file.metadata.frontmatter?.type === "Project" || file.metadata.frontmatter?.type === "Task") &&
file.file.path !== this.processorSettings.source &&
!file.file.path.startsWith(templateFolder);
Expand Down Expand Up @@ -499,6 +508,12 @@ type ProjectBlockRenderSettings = {
*/
search: SearchTermsArray | undefined,


/**
* The search text.
*/
searchText: string | undefined,

/**
* The number of models to process in one batch.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default abstract class TableBlockRenderComponent<T extends IPrjModel<unkn
//#region General properties
protected global = Global.getInstance();
protected logger = this.global.logger;
protected metadataCache = this.global.metadataCache.Cache;
protected metadataCache = this.global.metadataCache;
protected fileCache = this.global.fileCache;
//#endregion
//#region Component properties
Expand Down
17 changes: 4 additions & 13 deletions src/libs/ContextMenus/GetMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import Lng from "src/classes/Lng";
import { DocumentModel } from "src/models/DocumentModel";
import { FileType } from "src/types/PrjTypes";
import { FileMetadata } from "../MetadataCache";
import Helper from "../Helper";

export default class GetMetadata {
static instance: GetMetadata;
private app = Global.getInstance().app;
private logger = Global.getInstance().logger;
private plugin = Global.getInstance().plugin;
private metadataCache = Global.getInstance().metadataCache.Cache;
private metadataCache = Global.getInstance().metadataCache.cache;
protected eventsRegistered = false;
protected bindContextMenu = this.onContextMenu.bind(this);

Expand Down Expand Up @@ -86,7 +87,7 @@ export default class GetMetadata {
item.setTitle(Lng.gt("ShowMetadataFile"))
.setIcon(document.getCorospondingSymbol())
.onClick(async () => {
await this.openMetadataFile(document.file);
await Helper.openFile(document.file);
}
);
});
Expand Down Expand Up @@ -124,16 +125,6 @@ export default class GetMetadata {
return;
}
const document = new DocumentModel(metadataFile.file);
await this.openMetadataFile(document.file);
}

private async openMetadataFile(file: TFile) {
this.logger.trace(`Opening metadata file for ${file.name}`);
const workspace = this.app.workspace;
const newLeaf = workspace.getLeaf(true);
await newLeaf.openFile(file);
const view = newLeaf.getViewState();
view.state.mode = 'preview';
newLeaf.setViewState(view);
await Helper.openFile(document.file);
}
}
Loading

0 comments on commit 99e11af

Please sign in to comment.