Pull out the document into a protected property so that it can be called by subclasses
This commit is contained in:
parent
ed60f9d689
commit
4fcff3e06e
1 changed files with 16 additions and 14 deletions
|
|
@ -43,6 +43,21 @@ export function DBConnectorMixin(HandlebarsApp) {
|
|||
return super.render(options, ...args);
|
||||
};
|
||||
|
||||
async _fetchDocument() {
|
||||
if (!this._docID) { return }
|
||||
const documents = await getFile(this.dbPath);
|
||||
|
||||
if (documents[this._docID] == null) {
|
||||
ui.notifications.error(_loc(
|
||||
`TB.notifs.error.document-ID-404`,
|
||||
{ id: this._docID, dbType: this.dbType },
|
||||
));
|
||||
return false;
|
||||
};
|
||||
|
||||
Object.assign(this._doc, documents[this._docID]);
|
||||
};
|
||||
|
||||
/**
|
||||
* This fetches the DB data that we care about for the purposes of being able
|
||||
* to create/edit entries in the Artists DB
|
||||
|
|
@ -50,20 +65,7 @@ export function DBConnectorMixin(HandlebarsApp) {
|
|||
async #connectToDB() {
|
||||
if (this.#connected) { return true };
|
||||
this.#lastModified ??= await lastModifiedAt(this.dbPath);
|
||||
|
||||
if (this._docID) {
|
||||
const documents = await getFile(this.dbPath);
|
||||
|
||||
if (documents[this._docID] == null) {
|
||||
ui.notifications.error(_loc(
|
||||
`TB.notifs.error.document-ID-404`,
|
||||
{ id: this._docID, dbType: this.dbType },
|
||||
));
|
||||
return false;
|
||||
};
|
||||
|
||||
Object.assign(this._doc, documents[this._docID]);
|
||||
};
|
||||
this._fetchDocument()
|
||||
this.#connected = true;
|
||||
return true;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue