Skip to content

Commit

Permalink
Add tag testing buttons in debug view
Browse files Browse the repository at this point in the history
  • Loading branch information
luminamystere committed Oct 17, 2024
1 parent 9626b3e commit 0030042
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 1 deletion.
61 changes: 61 additions & 0 deletions src/ui/view/DebugView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,67 @@ export default ViewDefinition({
},
}))

const tagButtons = Block().appendTo(view)

tagButtons.append(createButton({
name: "Create Tag Author",
async execute () {
await BUTTON_REGISTRY.createAuthor.execute("tagging test", "thetagger")
await BUTTON_REGISTRY.privilegeGrantAuthor.execute("thetagger", "TagGlobalCreate", "TagGlobalDelete", "TagGlobalUpdate", "TagCategoryCreate", "TagCategoryUpdate", "TagCategoryDelete")
},
}))

tagButtons.append(createButton({
name: "Tag Create Test",
async execute () {
await BUTTON_REGISTRY.tagCreateCategory.execute("Category One", "the first test category")
await BUTTON_REGISTRY.tagCreateCategory.execute("Category Two", "the second test category")
await BUTTON_REGISTRY.tagCreateCategory.execute("Category Three", "the third test category")
await BUTTON_REGISTRY.tagCreateGlobal.execute("Tag One", "test tag 1", "Category One")
await BUTTON_REGISTRY.tagUpdateGlobal.execute("Tag One: Category One", "Tag One Updated", "test tag 1 updated", "Category Two")
await BUTTON_REGISTRY.tagUpdateCategory.execute("Category One", "Category One Updated", "first test category updated")
await BUTTON_REGISTRY.tagRemoveCategory.execute("Category One Updated")
await BUTTON_REGISTRY.tagRemoveGlobal.execute("Tag One Updated: Category Two")
await BUTTON_REGISTRY.tagCreateGlobal.execute("tag conflict", "conflicting", "Category Two")
await BUTTON_REGISTRY.tagCreateGlobal.execute("tag conflict", "conflicting", "Category Three")
await BUTTON_REGISTRY.tagUpdateGlobal.execute("tag conflict: Category Three", undefined, undefined, "Category Two")
},
}))

tagButtons.append(createButton({
name: "Work Tag Test",
async execute () {
await BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Two", "test tag 2", "Category Two")
await BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Three", "test tag 2", "Category Two")
await BUTTON_REGISTRY.tagCreateGlobal.execute("Tag Four", "test tag 2", "Category Two")
await BUTTON_REGISTRY.createWork.execute("Tag Test Work", "test", "testwork", "Ongoing", "Public", ["Tag Two: Category Two", "Tag Three: Category Two"], ["custom tag 1", "custom tag 2"])
await BUTTON_REGISTRY.createWork.execute("Tag Test Work Two", "test2", "testworktwo", "Ongoing", "Public", ["Tag Two: Category Two", "Tag Three: Category Two"], ["custom tag 2", "custom tag 3"])
await BUTTON_REGISTRY.deleteWork.execute("thetagger", "testwork")
},
}))

tagButtons.append(createButton({
name: "manifest test",
async execute () {
await BUTTON_REGISTRY.tagGetAll.execute()
},
}))

tagButtons.append(createButton({
name: "manifest test 2",
async execute () {
await BUTTON_REGISTRY.tagCreateGlobal.execute("extra tag", "wow", "Category Three")
await BUTTON_REGISTRY.tagGetAll.execute()
},
}))

tagButtons.append(createButton({
name: "manifest test 3",
async execute () {
await BUTTON_REGISTRY.tagGetAll.execute(Date.now() / 1000)
},
}))

return view
},
})
124 changes: 123 additions & 1 deletion src/ui/view/debug/ButtonRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const BUTTON_REGISTRY = {

createWork: {
name: "Create Work",
async execute (name: string, description: string, vanity: string, status?: string, visibility?: string) {
async execute (name: string, description: string, vanity: string, status?: string, visibility?: string, globalTags?: string[], customTags?: string[]) {
await fetch(`${Env.API_ORIGIN}work/create`, {
method: "POST",
credentials: "include",
Expand All @@ -103,6 +103,8 @@ export const BUTTON_REGISTRY = {
vanity: vanity,
status: status,
visibility: visibility,
global_tags: globalTags,
custom_tags: customTags,
}),
})
},
Expand Down Expand Up @@ -676,4 +678,124 @@ export const BUTTON_REGISTRY = {
},
},

tagCreateCategory: {
name: "Tag Create Category",
async execute (categoryName: string, categoryDescription: string) {
const response = await fetch(`${Env.API_ORIGIN}tag/create/category`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: categoryName,
description: categoryDescription,
}),
}).then(response => response.json())
console.log(response)
},
},

tagCreateGlobal: {
name: "Tag Create Global",
async execute (tagName: string, tagDescription: string, tagCategory: string) {
const response = await fetch(`${Env.API_ORIGIN}tag/create/global`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: tagName,
description: tagDescription,
category: tagCategory,
}),
}).then(response => response.json())
console.log(response)
},
},

tagUpdateCategory: {
name: "Tag Update Category",
async execute (vanity: string, categoryName?: string, categoryDescription?: string) {
const response = await fetch(`${Env.API_ORIGIN}tag/update/category/${vanity}`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: categoryName,
description: categoryDescription,
}),
}).then(response => response.json())
console.log(response)
},
},

tagUpdateGlobal: {
name: "Tag Update Global",
async execute (vanity: string, tagName?: string, tagDescription?: string, tagCategory?: string) {
const response = await fetch(`${Env.API_ORIGIN}tag/update/global/${vanity}`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: tagName,
description: tagDescription,
category: tagCategory,
}),
}).then(response => response.json())
console.log(response)
},
},

tagRemoveCategory: {
name: "Tag Remove Category",
async execute (vanity: string) {
const response = await fetch(`${Env.API_ORIGIN}tag/remove/category/${vanity}`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
}).then(response => response.json())
console.log(response)
},
},

tagRemoveGlobal: {
name: "Tag Remove Global",
async execute (vanity: string) {
const response = await fetch(`${Env.API_ORIGIN}tag/remove/global/${vanity}`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
}).then(response => response.json())
console.log(response)
},
},

tagGetAll: {
name: "Tag Get All",
async execute (timestamp?: number) {
const response = await fetch(`${Env.API_ORIGIN}tag/get/global`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
updated_after: timestamp,

}),
}).then(response => response.json())
console.log(response)
},
},

} satisfies Record<string, IButtonImplementation<any[]>>

0 comments on commit 0030042

Please sign in to comment.