Templates for file names #8
This commit is contained in:
parent
16299feced
commit
2c57094332
14 changed files with 231 additions and 115 deletions
|
|
@ -1,22 +1,22 @@
|
|||
import {App, ButtonComponent, Component, Modal, Notice, Setting, TextComponent, ToggleComponent} from 'obsidian';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import {APIManager} from '../api/APIManager';
|
||||
import {debugLog} from '../utils/Utils';
|
||||
import MediaDbPlugin from '../main';
|
||||
|
||||
export class MediaDbAdvancedSearchModal extends Modal {
|
||||
query: string;
|
||||
isBusy: boolean;
|
||||
apiManager: APIManager;
|
||||
plugin: MediaDbPlugin;
|
||||
searchBtn: ButtonComponent;
|
||||
selectedApis: any;
|
||||
onSubmit: (err: Error, result?: MediaTypeModel[]) => void;
|
||||
|
||||
constructor(app: App, apiManager: APIManager, onSubmit?: (err: Error, result?: MediaTypeModel[]) => void) {
|
||||
constructor(app: App, plugin: MediaDbPlugin, onSubmit?: (err: Error, result?: MediaTypeModel[]) => void) {
|
||||
super(app);
|
||||
this.apiManager = apiManager;
|
||||
this.plugin = plugin;
|
||||
this.onSubmit = onSubmit;
|
||||
this.selectedApis = [];
|
||||
for (const api of this.apiManager.apis) {
|
||||
for (const api of this.plugin.apiManager.apis) {
|
||||
this.selectedApis[api.apiName] = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ export class MediaDbAdvancedSearchModal extends Modal {
|
|||
|
||||
console.log(`MDB | query started with title ${this.query}`);
|
||||
|
||||
const res = await this.apiManager.query(this.query, this.selectedApis);
|
||||
const res = await this.plugin.apiManager.query(this.query, this.selectedApis);
|
||||
this.onSubmit(null, res);
|
||||
} catch (e) {
|
||||
this.onSubmit(e);
|
||||
|
|
@ -84,7 +84,7 @@ export class MediaDbAdvancedSearchModal extends Modal {
|
|||
contentEl.createEl('h3', {text: 'APIs to search'});
|
||||
|
||||
const apiToggleComponents: Component[] = [];
|
||||
for (const api of this.apiManager.apis) {
|
||||
for (const api of this.plugin.apiManager.apis) {
|
||||
const apiToggleListElementWrapper = contentEl.createEl('div', {cls: 'media-db-plugin-list-wrapper'});
|
||||
|
||||
const apiToggleTextWrapper = apiToggleListElementWrapper.createEl('div', {cls: 'media-db-plugin-list-text-wrapper'});
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
import {App, ButtonComponent, DropdownComponent, Modal, Notice, Setting, TextComponent} from 'obsidian';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import {APIManager} from '../api/APIManager';
|
||||
import {debugLog} from '../utils/Utils';
|
||||
import MediaDbPlugin from '../main';
|
||||
|
||||
export class MediaDbIdSearchModal extends Modal {
|
||||
query: string;
|
||||
isBusy: boolean;
|
||||
apiManager: APIManager;
|
||||
plugin: MediaDbPlugin;
|
||||
searchBtn: ButtonComponent;
|
||||
selectedApi: string;
|
||||
onSubmit: (err: Error, result?: MediaTypeModel) => void;
|
||||
|
||||
constructor(app: App, apiManager: APIManager, onSubmit?: (err: Error, result?: MediaTypeModel) => void) {
|
||||
constructor(app: App, plugin: MediaDbPlugin, onSubmit?: (err: Error, result?: MediaTypeModel) => void) {
|
||||
super(app);
|
||||
this.apiManager = apiManager;
|
||||
this.plugin = plugin;
|
||||
this.onSubmit = onSubmit;
|
||||
this.selectedApi = '';
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ export class MediaDbIdSearchModal extends Modal {
|
|||
|
||||
console.log(`MDB | query started with id ${this.query}`);
|
||||
|
||||
const api = this.apiManager.getApiByName(this.selectedApi);
|
||||
const api = this.plugin.apiManager.getApiByName(this.selectedApi);
|
||||
if (!api) {
|
||||
this.onSubmit(new Error('the selected api does not exist'));
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ export class MediaDbIdSearchModal extends Modal {
|
|||
apiSelectorComponent.onChange((value: string) => {
|
||||
this.selectedApi = value;
|
||||
});
|
||||
for (const api of this.apiManager.apis) {
|
||||
for (const api of this.plugin.apiManager.apis) {
|
||||
apiSelectorComponent.addOption(api.apiName, api.apiName);
|
||||
}
|
||||
apiSelectorWrapper.appendChild(apiSelectorComponent.selectEl);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
import {App, SuggestModal} from 'obsidian';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../main';
|
||||
|
||||
export class MediaDbSearchResultModal extends SuggestModal<MediaTypeModel> {
|
||||
suggestion: MediaTypeModel[];
|
||||
plugin: MediaDbPlugin;
|
||||
onChoose: (error: Error, result?: MediaTypeModel) => void;
|
||||
|
||||
constructor(app: App, suggestion: MediaTypeModel[], onChoose: (error: Error, result?: MediaTypeModel) => void) {
|
||||
constructor(app: App, plugin: MediaDbPlugin, suggestion: MediaTypeModel[], onChoose: (error: Error, result?: MediaTypeModel) => void) {
|
||||
super(app);
|
||||
this.plugin = plugin;
|
||||
this.suggestion = suggestion;
|
||||
this.onChoose = onChoose;
|
||||
}
|
||||
|
|
@ -20,9 +23,9 @@ export class MediaDbSearchResultModal extends SuggestModal<MediaTypeModel> {
|
|||
|
||||
// Renders each suggestion item.
|
||||
renderSuggestion(item: MediaTypeModel, el: HTMLElement) {
|
||||
el.createEl('div', {text: item.getFileName()});
|
||||
el.createEl('div', {text: this.plugin.mediaTypeManager.getFileName(item)});
|
||||
el.createEl('small', {text: `${item.englishTitle}\n`});
|
||||
el.createEl('small', {text: `${item.type.toUpperCase()} from ${item.dataSource}`});
|
||||
el.createEl('small', {text: `${item.type.toUpperCase() + (item.subType ? ` (${item.subType})` : '')} from ${item.dataSource}`});
|
||||
}
|
||||
|
||||
// Perform action on the selected suggestion.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue