fix for #67
This commit is contained in:
parent
fdbba31d84
commit
bdda8146aa
4 changed files with 14 additions and 20 deletions
28
src/main.ts
28
src/main.ts
|
|
@ -232,7 +232,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
|
||||
let fileContent = await this.generateMediaDbNoteContents(mediaTypeModel, options);
|
||||
|
||||
await this.createNote(this.mediaTypeManager.getFileName(mediaTypeModel), fileContent, options.openNote);
|
||||
await this.createNote(this.mediaTypeManager.getFileName(mediaTypeModel), fileContent, options);
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
new Notice(e.toString());
|
||||
|
|
@ -325,18 +325,18 @@ export default class MediaDbPlugin extends Plugin {
|
|||
*
|
||||
* @param fileName
|
||||
* @param fileContent
|
||||
* @param openFile
|
||||
* @param options
|
||||
*/
|
||||
async createNote(fileName: string, fileContent: string, openFile: boolean = false) {
|
||||
fileName = replaceIllegalFileNameCharactersInString(fileName);
|
||||
const filePath = `${this.settings.folder.replace(/\/$/, '')}/${fileName}.md`;
|
||||
|
||||
// find and possibly create the folder set in settings
|
||||
const folder = this.app.vault.getAbstractFileByPath(this.settings.folder);
|
||||
async createNote(fileName: string, fileContent: string, options: CreateNoteOptions) {
|
||||
// find and possibly create the folder set in settings or passed in folder
|
||||
const folder = options.folder ?? this.app.vault.getAbstractFileByPath(this.settings.folder);
|
||||
if (!folder) {
|
||||
await this.app.vault.createFolder(this.settings.folder.replace(/\/$/, ''));
|
||||
await this.app.vault.createFolder(folder.path);
|
||||
}
|
||||
|
||||
fileName = replaceIllegalFileNameCharactersInString(fileName);
|
||||
const filePath = `${folder.path}/${fileName}.md`;
|
||||
|
||||
// find and delete file with the same name
|
||||
const file = this.app.vault.getAbstractFileByPath(filePath);
|
||||
if (file) {
|
||||
|
|
@ -348,7 +348,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
console.debug(`MDB | created new file at ${filePath}`);
|
||||
|
||||
// open newly crated file
|
||||
if (openFile) {
|
||||
if (options.openNote) {
|
||||
const activeLeaf = this.app.workspace.getUnpinnedLeaf();
|
||||
if (!activeLeaf) {
|
||||
console.warn('MDB | no active leaf, not opening newly created note');
|
||||
|
|
@ -377,10 +377,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
throw new Error('MDB | active note is not a Media DB entry or is missing metadata');
|
||||
}
|
||||
|
||||
|
||||
|
||||
let oldMediaTypeModel = this.mediaTypeManager.createMediaTypeModelFromMediaType(metadata, metadata.type);
|
||||
|
||||
// console.debug(oldMediaTypeModel);
|
||||
|
||||
let newMediaTypeModel = await this.apiManager.queryDetailedInfoById(metadata.id, metadata.dataSource);
|
||||
|
|
@ -389,15 +386,14 @@ export default class MediaDbPlugin extends Plugin {
|
|||
}
|
||||
|
||||
newMediaTypeModel = Object.assign(oldMediaTypeModel, newMediaTypeModel.getWithOutUserData());
|
||||
|
||||
// console.debug(newMediaTypeModel);
|
||||
|
||||
// deletion not happening anymore why is this log statement still here
|
||||
console.debug('MDB | deleting old entry');
|
||||
if (onlyMetadata) {
|
||||
await this.createMediaDbNoteFromModel(newMediaTypeModel, {attachFile: activeFile, openNote: true});
|
||||
await this.createMediaDbNoteFromModel(newMediaTypeModel, {attachFile: activeFile, folder: activeFile.parent, openNote: true});
|
||||
} else {
|
||||
await this.createMediaDbNoteFromModel(newMediaTypeModel, {attachTemplate: true, openNote: true});
|
||||
await this.createMediaDbNoteFromModel(newMediaTypeModel, {attachTemplate: true, folder: activeFile.parent, openNote: true});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ export class MediaDbSearchResultModal extends SelectModal<MediaTypeModel> {
|
|||
}
|
||||
|
||||
onClose() {
|
||||
console.log('close');
|
||||
this.closeCallback();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ export class PropertyMapper {
|
|||
* @param obj
|
||||
*/
|
||||
convertObject(obj: object): object {
|
||||
console.log('test1');
|
||||
|
||||
if (!obj.hasOwnProperty('type')) {
|
||||
return obj;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import {TFile} from 'obsidian';
|
||||
import {TFile, TFolder} from 'obsidian';
|
||||
|
||||
|
||||
export const pluginName: string = 'obsidian-media-db-plugin';
|
||||
|
|
@ -211,6 +211,7 @@ export interface CreateNoteOptions {
|
|||
attachTemplate?: boolean,
|
||||
attachFile?: TFile,
|
||||
openNote?: boolean,
|
||||
folder?: TFolder,
|
||||
}
|
||||
|
||||
export function migrateObject<T extends object>(object: T, oldData: any, defaultData: T): void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue