Bulk import #26
This commit is contained in:
parent
d34f107f0f
commit
bbc4b57092
9 changed files with 421 additions and 50 deletions
|
|
@ -1,35 +1,32 @@
|
|||
import {App, SuggestModal} from 'obsidian';
|
||||
import {App} from 'obsidian';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../main';
|
||||
import {SelectModal} from './SelectModal';
|
||||
|
||||
export class MediaDbSearchResultModal extends SuggestModal<MediaTypeModel> {
|
||||
suggestion: MediaTypeModel[];
|
||||
export class MediaDbSearchResultModal extends SelectModal<MediaTypeModel> {
|
||||
plugin: MediaDbPlugin;
|
||||
onChoose: (error: Error, result?: MediaTypeModel) => void;
|
||||
heading: string;
|
||||
onChoose: (error: Error, result: MediaTypeModel[]) => void;
|
||||
|
||||
constructor(app: App, plugin: MediaDbPlugin, suggestion: MediaTypeModel[], onChoose: (error: Error, result?: MediaTypeModel) => void) {
|
||||
super(app);
|
||||
constructor(app: App, plugin: MediaDbPlugin, elements: MediaTypeModel[], onChoose: (error: Error, result: MediaTypeModel[]) => void) {
|
||||
super(app, elements);
|
||||
this.plugin = plugin;
|
||||
this.suggestion = suggestion;
|
||||
this.onChoose = onChoose;
|
||||
}
|
||||
|
||||
getSuggestions(query: string): MediaTypeModel[] {
|
||||
return this.suggestion.filter(item => {
|
||||
const searchQuery = query.toLowerCase();
|
||||
return item.title.toLowerCase().includes(searchQuery);
|
||||
});
|
||||
this.title = 'Search Results';
|
||||
this.description = 'Select one or multiple search results.';
|
||||
}
|
||||
|
||||
// Renders each suggestion item.
|
||||
renderSuggestion(item: MediaTypeModel, el: HTMLElement) {
|
||||
renderElement(item: MediaTypeModel, el: HTMLElement) {
|
||||
el.createEl('div', {text: this.plugin.mediaTypeManager.getFileName(item)});
|
||||
el.createEl('small', {text: `${item.englishTitle}\n`});
|
||||
el.createEl('small', {text: `${item.type.toUpperCase() + (item.subType ? ` (${item.subType})` : '')} from ${item.dataSource}`});
|
||||
}
|
||||
|
||||
// Perform action on the selected suggestion.
|
||||
onChooseSuggestion(item: MediaTypeModel, evt: MouseEvent | KeyboardEvent) {
|
||||
this.onChoose(null, item);
|
||||
submit() {
|
||||
this.onChoose(null, this.selectModalElements.filter(x => x.isActive()).map(x => x.value));
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue