Skip to content

Commit

Permalink
feat: supports selecting data to display in setting tab
Browse files Browse the repository at this point in the history
Signed-off-by: edonyzpc <[email protected]>
  • Loading branch information
edonyzpc committed Mar 20, 2024
1 parent 387f1a5 commit a0b3c70
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export class PluginManager extends Plugin {
private localGraph = new LocalGraph(this.app, this);
private memos = new Memos(this.app, this);
calloutManager: CalloutManager<true> | undefined;
private updateDebouncer!:Debouncer<[file: TFile | null], void>;
private updateDebouncer!: Debouncer<[file: TFile | null], void>;
private settingTab: SettingTab = new SettingTab(this.app, this);

async onload() {
await this.loadSettings();
Expand Down Expand Up @@ -211,7 +212,7 @@ export class PluginManager extends Plugin {
})

// This adds a settings tab so the user can configure various aspects of the plugin
this.addSettingTab(new SettingTab(this.app, this));
this.addSettingTab(this.settingTab);
}

onunload() {
Expand Down Expand Up @@ -357,17 +358,23 @@ export class PluginManager extends Plugin {
}

async activeStatView() {
this.app.workspace.detachLeavesOfType(STAT_PREVIEW_TYPE);

//this.app.workspace.detachLeavesOfType(STAT_PREVIEW_TYPE);
const leaves = this.app.workspace.getLeavesOfType(STAT_PREVIEW_TYPE);
const count = leaves.length;
const viewLeaf = this.app.workspace.getLeaf('tab');

await viewLeaf.setViewState({
type: STAT_PREVIEW_TYPE,
active: true,
});

this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(STAT_PREVIEW_TYPE)[0]
this.app.workspace.getLeavesOfType(STAT_PREVIEW_TYPE)[count]
);

// detach all the other stat views
for (let i = 0; i < count; i++) {
leaves[i].detach();
}
}
}

37 changes: 35 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { App, PluginSettingTab, Setting } from "obsidian";
import Picker from "vanilla-picker";

import { PluginManager } from "./plugin"
import { STAT_PREVIEW_TYPE } from './stat'

export interface ResizeStyle {
width: number,
Expand Down Expand Up @@ -43,7 +44,8 @@ export interface PluginManagerSettings {
metadataExcludePath: string[];
isEnabledMetadataUpdating: boolean;
cachePluginRepo: {[key: string]: any;}; // eslint-disable-line @typescript-eslint/no-explicit-any
cacheThemeRepo: {[key: string]: any;}; // eslint-disable-line @typescript-eslint/no-explicit-any
cacheThemeRepo: { [key: string]: any; }; // eslint-disable-line @typescript-eslint/no-explicit-any
statisticsType: string;
}

export const DEFAULT_SETTINGS: PluginManagerSettings = {
Expand Down Expand Up @@ -93,7 +95,8 @@ export const DEFAULT_SETTINGS: PluginManagerSettings = {
},
cacheThemeRepo: {
"Minimal": "kepano/obsidian-minimal",
}
},
statisticsType: "none",
}

interface GraphColor {
Expand Down Expand Up @@ -532,6 +535,36 @@ export class SettingTab extends PluginSettingTab {
})
});


// setting for show statistics
new Setting(containerEl).setName("Show Statistics")
.setDesc("Show statistics in the status bar")
.addDropdown(dropDown => {
// reset to default
this.log(this.plugin.settings.statisticsType);
const daily = dropDown.addOption('daily', 'Daily Statistcs');
const total = dropDown.addOption('total', 'Total Statistics');
if (this.plugin.settings.statisticsType === 'daily') {
daily.setDisabled(false);
dropDown.setValue('daily');
} else {
total.setDisabled(false);
dropDown.setValue('total');
}
dropDown.onChange(async (value) => {
console.log("changing statistics type", value);
this.plugin.settings.statisticsType = value;
await this.plugin.saveSettings();

// popup view
const leaf = this.app.workspace.getLeaf("window");
await leaf.setViewState({
type: STAT_PREVIEW_TYPE,
active: false,
});
this.app.workspace.revealLeaf(leaf);
});
});
}
}

Expand Down

0 comments on commit a0b3c70

Please sign in to comment.