Skip to content

Instantly share code, notes, and snippets.

@mickeydarrenlau
Last active February 23, 2024 08:18
Show Gist options
  • Save mickeydarrenlau/ae2c2c4cad868b6fe0fb91773b906000 to your computer and use it in GitHub Desktop.
Save mickeydarrenlau/ae2c2c4cad868b6fe0fb91773b906000 to your computer and use it in GitHub Desktop.
My Command Center Widget

#command-center

^buttons

What you want to do today?

^9308f3


try {
   const {CommandCenter} = customJS
   const this2 = this
   CommandCenter.generate_view({this2,dv})

} catch {
 dv.span("We are working hard to prepare your buttons for you ⏳")
}

^59a0d4

class CommandCenter {
async create_finance(args) {
const { this2 } = args
let newEntry = "Financial Stuff/Spending/Record/Untitiled.md"
newEntry = await app.vault.create(newEntry, '')
app.workspace.getLeaf(false).openFile(newEntry)
}
async create_goals(args) {
const { this2 } = args
let newEntry = "Financial Stuff/Spending/Goals/Untitiled.md"
newEntry = await app.vault.create(newEntry, '')
app.workspace.getLeaf(false).openFile(newEntry)
}
async create_data_rec(args) {
const { this2 } = args
let newEntry = "data/Record/Untitiled.md"
newEntry = await app.vault.create(newEntry, '')
app.workspace.getLeaf(false).openFile(newEntry)
}
async create_domain_credit(args) {
const { this2 } = args
let newEntry = "Financial Stuff/Domain Stuff/Credit/Untitiled.md"
newEntry = await app.vault.create(newEntry, '')
app.workspace.getLeaf(false).openFile(newEntry)
}
async open_finance_calc(args) {
const { this2 } = args
const file = await app.plugins.getPlugin('templater-obsidian').templater.functions_generator.internal_functions.modules_array.find(x => x.name === "file").static_object
const existing = file.find_tfile("Financial Stuff/Spending/Calculated")
app.workspace.getLeaf(false).openFile(existing)
}
async open_credit_calc(args) {
const { this2 } = args
const file = await app.plugins.getPlugin('templater-obsidian').templater.functions_generator.internal_functions.modules_array.find(x => x.name === "file").static_object
const existing = file.find_tfile("Financial Stuff/Domain Stuff/Calculated")
app.workspace.getLeaf(false).openFile(existing)
}
async open_data_calc(args) {
const { this2 } = args
const file = await app.plugins.getPlugin('templater-obsidian').templater.functions_generator.internal_functions.modules_array.find(x => x.name === "file").static_object
const existing = file.find_tfile("data/Calculate")
app.workspace.getLeaf(false).openFile(existing)
}
async generate_view(args){
const { this2,dv } = args
const { createButton } = this2.app.plugins.plugins["buttons"];
const {CommandCenter} = customJS
createButton({
app,
el: this2.container,
args: { name: "💵 Open finance entry", id: "button-create-open-finance"},
clickOverride: { click: CommandCenter.create_finance, params: [this2] },
});
dv.span(" ")
createButton({
app,
el: this2.container,
args: { name: "💵 See calculated finance", id: "button-open-finance-calc"},
clickOverride: { click: CommandCenter.open_finance_calc, params: [this2] },
});
dv.span("<br></br>")
createButton({
app,
el: this2.container,
args: { name: "🏆 Create a new goal", id: "button-create-goals"},
clickOverride: { click: CommandCenter.create_goals, params: [this2] },
});
dv.span("<br></br>")
createButton({
app,
el: this2.container,
args: { name: "💳 Add new domain credit", id: "button-create-domain-credit"},
clickOverride: { click: CommandCenter.create_domain_credit, params: [this2] },
});
dv.span(" ")
createButton({
app,
el: this2.container,
args: { name: "💳 See calculated domain credit", id: "button-open-domain-credit-calc"},
clickOverride: { click: CommandCenter.open_credit_calc, params: [this2] },
});
dv.span("<br></br>")
createButton({
app,
el: this2.container,
args: { name: "🌎 Open data record", id: "button-create-data-rec"},
clickOverride: { click: CommandCenter.create_data_rec, params: [this2] },
});
createButton({
app,
el: this2.container,
args: { name: "🌎 See calculated mobile data usage", id: "button-open-data-calc"},
clickOverride: { click: CommandCenter.open_data_calc, params: [this2] },
});
dv.span("<br></br>")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment