Merge branch 'O_O' into O_O
This commit is contained in:
commit
6517bd9c49
9 changed files with 251 additions and 46 deletions
|
|
@ -47,7 +47,7 @@ export class MediaDbAdvancedSearchModal extends Modal {
|
|||
|
||||
async search(): Promise<MediaTypeModel[]> {
|
||||
if (!this.query || this.query.length < 3) {
|
||||
new Notice('MDB | Query to short');
|
||||
new Notice('MDB | Query too short');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
82
src/modals/MediaDbPreviewModal.ts
Normal file
82
src/modals/MediaDbPreviewModal.ts
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
import {ButtonComponent, MarkdownRenderer, Modal, Setting} from 'obsidian';
|
||||
import MediaDbPlugin from 'src/main';
|
||||
import {MediaTypeModel} from 'src/models/MediaTypeModel';
|
||||
import {PREVIEW_MODAL_DEFAULT_OPTIONS, PreviewModalData, PreviewModalOptions} from '../utils/ModalHelper';
|
||||
import {CreateNoteOptions} from '../utils/Utils';
|
||||
|
||||
export class MediaDbPreviewModal extends Modal {
|
||||
plugin: MediaDbPlugin;
|
||||
|
||||
createNoteOptions: CreateNoteOptions;
|
||||
elements: MediaTypeModel[];
|
||||
isBusy: boolean;
|
||||
title: string;
|
||||
cancelButton: ButtonComponent;
|
||||
submitButton: ButtonComponent;
|
||||
|
||||
submitCallback: (previewModalData: PreviewModalData) => void;
|
||||
closeCallback: (err?: Error) => void;
|
||||
|
||||
constructor(plugin: MediaDbPlugin, previewModalOptions: PreviewModalOptions) {
|
||||
previewModalOptions = Object.assign({}, PREVIEW_MODAL_DEFAULT_OPTIONS, previewModalOptions);
|
||||
|
||||
super(plugin.app);
|
||||
|
||||
this.plugin = plugin;
|
||||
this.title = previewModalOptions.modalTitle;
|
||||
this.elements = previewModalOptions.elements;
|
||||
this.createNoteOptions = previewModalOptions.createNoteOptions;
|
||||
}
|
||||
|
||||
setSubmitCallback(submitCallback: (previewModalData: PreviewModalData) => void): void {
|
||||
this.submitCallback = submitCallback;
|
||||
}
|
||||
|
||||
setCloseCallback(closeCallback: (err?: Error) => void): void {
|
||||
this.closeCallback = closeCallback;
|
||||
}
|
||||
|
||||
async preview(): Promise<void> {
|
||||
let {contentEl} = this;
|
||||
contentEl.addClass('media-db-plugin-preview-modal');
|
||||
|
||||
contentEl.createEl('h2', {text: this.title});
|
||||
|
||||
const previewWrapper = contentEl.createDiv({cls: 'media-db-plugin-preview-wrapper'});
|
||||
|
||||
for (let result of this.elements) {
|
||||
previewWrapper.createEl('h3', {text: result.englishTitle});
|
||||
const fileDiv = previewWrapper.createDiv();
|
||||
|
||||
let fileContent = await this.plugin.generateMediaDbNoteContents(result, this.createNoteOptions);
|
||||
fileContent = `\n${fileContent}\n`;
|
||||
|
||||
MarkdownRenderer.renderMarkdown(fileContent, fileDiv, null, null);
|
||||
}
|
||||
|
||||
contentEl.createDiv({cls: 'media-db-plugin-spacer'});
|
||||
|
||||
const bottomSettingRow = new Setting(contentEl);
|
||||
bottomSettingRow.addButton(btn => {
|
||||
btn.setButtonText('Cancel');
|
||||
btn.onClick(() => this.closeCallback());
|
||||
btn.buttonEl.addClass('media-db-plugin-button');
|
||||
this.cancelButton = btn;
|
||||
});
|
||||
bottomSettingRow.addButton(btn => {
|
||||
btn.setButtonText('Ok');
|
||||
btn.setCta();
|
||||
btn.onClick(() => this.submitCallback({confirmed: true}));
|
||||
btn.buttonEl.addClass('media-db-plugin-button');
|
||||
this.submitButton = btn;
|
||||
});
|
||||
}
|
||||
|
||||
onOpen(): void {
|
||||
this.preview();
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
this.closeCallback();
|
||||
}
|
||||
}
|
||||
|
|
@ -80,9 +80,8 @@ export abstract class SelectModal<T> extends Modal {
|
|||
const {contentEl, titleEl} = this;
|
||||
|
||||
titleEl.createEl('h2', {text: this.title});
|
||||
contentEl.createEl('p', {text: this.description});
|
||||
|
||||
contentEl.addClass('media-db-plugin-select-modal');
|
||||
contentEl.createEl('p', {text: this.description});
|
||||
|
||||
this.elementWrapper = contentEl.createDiv({cls: 'media-db-plugin-select-wrapper'});
|
||||
this.elementWrapper.tabIndex = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue