Add button which imports tag categories from the selected configured szurubooru instance
parent
335bc6ee2c
commit
adc25d46d3
|
|
@ -9,6 +9,7 @@ import TabPanel from "primevue/tabpanel";
|
||||||
import DataTable from "primevue/datatable";
|
import DataTable from "primevue/datatable";
|
||||||
import Column from "primevue/column";
|
import Column from "primevue/column";
|
||||||
import { SzuruSiteConfig, TagCategoryColor, getDefaultTagCategories } from "~/models";
|
import { SzuruSiteConfig, TagCategoryColor, getDefaultTagCategories } from "~/models";
|
||||||
|
import SzurubooruApi from "~/api";
|
||||||
|
|
||||||
const statusText = ref("");
|
const statusText = ref("");
|
||||||
const statusType = ref("status-quiet");
|
const statusType = ref("status-quiet");
|
||||||
|
|
@ -87,6 +88,20 @@ function addTagCategory() {
|
||||||
cfg.value.tagCategories.push(new TagCategoryColor("category", "#abcdef"));
|
cfg.value.tagCategories.push(new TagCategoryColor("category", "#abcdef"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function importTagCategoriesFromInstance() {
|
||||||
|
const szuruConfig = cfg.value.sites.find((x) => x.id == cfg.value.selectedSiteId)!;
|
||||||
|
const szuru = SzurubooruApi.createFromConfig(szuruConfig);
|
||||||
|
const cats = (await szuru.getTagCategories()).results;
|
||||||
|
|
||||||
|
for (const cat of cats) {
|
||||||
|
if (cat.name == "default") continue;
|
||||||
|
|
||||||
|
if (!cfg.value.tagCategories.find((x) => x.name == cat.name)) {
|
||||||
|
cfg.value.tagCategories.push(new TagCategoryColor(cat.name, cat.color));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// For debugging
|
// For debugging
|
||||||
const wnd = window as any;
|
const wnd = window as any;
|
||||||
wnd.szc_get_config = () => JSON.parse(JSON.stringify(cfg.value));
|
wnd.szc_get_config = () => JSON.parse(JSON.stringify(cfg.value));
|
||||||
|
|
@ -241,7 +256,7 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
|
||||||
|
|
||||||
<div class="col-12 flex flex-wrap grid grid-nogutter gap-1">
|
<div class="col-12 flex flex-wrap grid grid-nogutter gap-1">
|
||||||
<button class="primary" @click="addTagCategory">Add new category</button>
|
<button class="primary" @click="addTagCategory">Add new category</button>
|
||||||
<!-- <button>Import from connected instances</button> -->
|
<button @click="importTagCategoriesFromInstance">Import from active instance</button>
|
||||||
<button class="bg-danger sm:ml-auto" @click="resetTagCategories">Reset to default</button>
|
<button class="bg-danger sm:ml-auto" @click="resetTagCategories">Reset to default</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ const props = defineProps(["siteId", "postId"]);
|
||||||
const merge = useMergeStore();
|
const merge = useMergeStore();
|
||||||
const pop = usePopupStore();
|
const pop = usePopupStore();
|
||||||
|
|
||||||
|
// Why is this cloneDeep needed? Or maybe it isn't?
|
||||||
const szuruConfig = cloneDeep(cfg.value.sites.find((x) => x.id == props.siteId))!;
|
const szuruConfig = cloneDeep(cfg.value.sites.find((x) => x.id == props.siteId))!;
|
||||||
const szuru = SzurubooruApi.createFromConfig(szuruConfig);
|
const szuru = SzurubooruApi.createFromConfig(szuruConfig);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue