Ran formatter, removed unused array and updated APIModel.ts
This commit is contained in:
parent
f52060482a
commit
5eec98d127
8 changed files with 44 additions and 45 deletions
|
|
@ -18,7 +18,7 @@ export class APIManager {
|
||||||
console.debug(`MDB | api manager queried with "${query}"`);
|
console.debug(`MDB | api manager queried with "${query}"`);
|
||||||
|
|
||||||
let res: MediaTypeModel[] = [];
|
let res: MediaTypeModel[] = [];
|
||||||
|
|
||||||
for (const api of this.apis) {
|
for (const api of this.apis) {
|
||||||
if (apisToQuery.contains(api.apiName)) {
|
if (apisToQuery.contains(api.apiName)) {
|
||||||
const apiRes = await api.searchByTitle(query);
|
const apiRes = await api.searchByTitle(query);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||||
import { MediaType } from '../utils/MediaType';
|
import { MediaType } from '../utils/MediaType';
|
||||||
|
import { MediaDbPluginSettings } from 'src/settings/Settings';
|
||||||
import MediaDbPlugin from '../main';
|
import MediaDbPlugin from '../main';
|
||||||
|
|
||||||
export abstract class APIModel {
|
export abstract class APIModel {
|
||||||
|
|
@ -19,7 +20,7 @@ export abstract class APIModel {
|
||||||
abstract getById(id: string): Promise<MediaTypeModel>;
|
abstract getById(id: string): Promise<MediaTypeModel>;
|
||||||
|
|
||||||
hasType(type: MediaType): boolean {
|
hasType(type: MediaType): boolean {
|
||||||
if (this.types.contains(type) && !(this.plugin.settings[[this.apiName, type].filter(s => s).join('') as keyof typeof this.plugin.settings] === false)){
|
if (this.types.contains(type) && !(this.plugin.settings[(this.apiName + type) as keyof MediaDbPluginSettings] === false)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -32,4 +33,4 @@ export abstract class APIModel {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -671,4 +671,4 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
|
|
||||||
await this.saveData(this.settings);
|
await this.saveData(this.settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,20 +89,20 @@ export class MediaDbAdvancedSearchModal extends Modal {
|
||||||
for (const api of this.plugin.apiManager.apis) {
|
for (const api of this.plugin.apiManager.apis) {
|
||||||
const apiToggleListElementWrapper = contentEl.createEl('div', { cls: 'media-db-plugin-list-wrapper' });
|
const apiToggleListElementWrapper = contentEl.createEl('div', { cls: 'media-db-plugin-list-wrapper' });
|
||||||
|
|
||||||
const apiToggleTextWrapper = apiToggleListElementWrapper.createEl('div', { cls: 'media-db-plugin-list-text-wrapper' });
|
const apiToggleTextWrapper = apiToggleListElementWrapper.createEl('div', { cls: 'media-db-plugin-list-text-wrapper' });
|
||||||
apiToggleTextWrapper.createEl('span', { text: api.apiName, cls: 'media-db-plugin-list-text' });
|
apiToggleTextWrapper.createEl('span', { text: api.apiName, cls: 'media-db-plugin-list-text' });
|
||||||
apiToggleTextWrapper.createEl('small', { text: api.apiDescription, cls: 'media-db-plugin-list-text' });
|
apiToggleTextWrapper.createEl('small', { text: api.apiDescription, cls: 'media-db-plugin-list-text' });
|
||||||
|
|
||||||
const apiToggleComponentWrapper = apiToggleListElementWrapper.createEl('div', { cls: 'media-db-plugin-list-toggle' });
|
const apiToggleComponentWrapper = apiToggleListElementWrapper.createEl('div', { cls: 'media-db-plugin-list-toggle' });
|
||||||
|
|
||||||
const apiToggleComponent = new ToggleComponent(apiToggleComponentWrapper);
|
const apiToggleComponent = new ToggleComponent(apiToggleComponentWrapper);
|
||||||
apiToggleComponent.setTooltip(api.apiName);
|
apiToggleComponent.setTooltip(api.apiName);
|
||||||
apiToggleComponent.setValue(this.selectedApis.find(x => x.name === api.apiName).selected);
|
apiToggleComponent.setValue(this.selectedApis.find(x => x.name === api.apiName).selected);
|
||||||
apiToggleComponent.onChange(value => {
|
apiToggleComponent.onChange(value => {
|
||||||
this.selectedApis.find(x => x.name === api.apiName).selected = value;
|
this.selectedApis.find(x => x.name === api.apiName).selected = value;
|
||||||
});
|
});
|
||||||
apiToggleComponentWrapper.appendChild(apiToggleComponent.toggleEl);
|
apiToggleComponentWrapper.appendChild(apiToggleComponent.toggleEl);
|
||||||
}
|
}
|
||||||
|
|
||||||
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,9 +76,8 @@ export class MediaDbSearchModal extends Modal {
|
||||||
|
|
||||||
const placeholder = 'Search by title';
|
const placeholder = 'Search by title';
|
||||||
const searchComponent = new TextComponent(contentEl);
|
const searchComponent = new TextComponent(contentEl);
|
||||||
const toggleComponents = [];
|
|
||||||
let currentToggle: ToggleComponent = null;
|
let currentToggle: ToggleComponent = null;
|
||||||
|
|
||||||
searchComponent.inputEl.style.width = '100%';
|
searchComponent.inputEl.style.width = '100%';
|
||||||
searchComponent.setPlaceholder(placeholder);
|
searchComponent.setPlaceholder(placeholder);
|
||||||
searchComponent.setValue(this.query);
|
searchComponent.setValue(this.query);
|
||||||
|
|
@ -119,7 +118,6 @@ export class MediaDbSearchModal extends Modal {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
apiToggleComponentWrapper.appendChild(apiToggleComponent.toggleEl);
|
apiToggleComponentWrapper.appendChild(apiToggleComponent.toggleEl);
|
||||||
toggleComponents.push(apiToggleComponent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
||||||
|
|
@ -146,4 +144,4 @@ export class MediaDbSearchModal extends Modal {
|
||||||
const { contentEl } = this;
|
const { contentEl } = this;
|
||||||
contentEl.empty();
|
contentEl.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Moby Games key')
|
.setName('Moby Games key')
|
||||||
.setDesc('API key for "www.mobygames.com".')
|
.setDesc('API key for "www.mobygames.com".')
|
||||||
.addText(cb => {
|
.addText(cb => {
|
||||||
|
|
@ -223,10 +223,10 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
.setDesc(
|
.setDesc(
|
||||||
fragWithHTML(
|
fragWithHTML(
|
||||||
"Your custom date format. Use <em>'YYYY-MM-DD'</em> for example.<br>" +
|
"Your custom date format. Use <em>'YYYY-MM-DD'</em> for example.<br>" +
|
||||||
"For more syntax, refer to <a href='https://momentjs.com/docs/#/displaying/format/'>format reference</a>.<br>" +
|
"For more syntax, refer to <a href='https://momentjs.com/docs/#/displaying/format/'>format reference</a>.<br>" +
|
||||||
"Your current syntax looks like this: <b><a id='media-db-dateformat-preview' style='pointer-events: none; cursor: default; text-decoration: none;'>" +
|
"Your current syntax looks like this: <b><a id='media-db-dateformat-preview' style='pointer-events: none; cursor: default; text-decoration: none;'>" +
|
||||||
this.plugin.dateFormatter.getPreview() +
|
this.plugin.dateFormatter.getPreview() +
|
||||||
'</a></b>',
|
'</a></b>',
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addText(cb => {
|
.addText(cb => {
|
||||||
|
|
@ -278,23 +278,23 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
containerEl.createEl('h3', { text: 'APIs Per Media Type' });
|
containerEl.createEl('h3', { text: 'APIs Per Media Type' });
|
||||||
containerEl.createEl('h5', { text: 'Movies' });
|
containerEl.createEl('h5', { text: 'Movies' });
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('OMDb API')
|
.setName('OMDb API')
|
||||||
.setDesc('Use OMDb API for movies.')
|
.setDesc('Use OMDb API for movies.')
|
||||||
.addToggle(cb => {
|
.addToggle(cb => {
|
||||||
cb.setValue(this.plugin.settings.OMDbAPImovie).onChange(data => {
|
cb.setValue(this.plugin.settings.OMDbAPImovie).onChange(data => {
|
||||||
this.plugin.settings.OMDbAPImovie = data;
|
this.plugin.settings.OMDbAPImovie = data;
|
||||||
this.plugin.saveSettings();
|
this.plugin.saveSettings();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('MAL API')
|
.setName('MAL API')
|
||||||
.setDesc('Use MAL API for movies.')
|
.setDesc('Use MAL API for movies.')
|
||||||
.addToggle(cb => {
|
.addToggle(cb => {
|
||||||
cb.setValue(this.plugin.settings.MALAPImovie).onChange(data => {
|
cb.setValue(this.plugin.settings.MALAPImovie).onChange(data => {
|
||||||
this.plugin.settings.MALAPImovie = data;
|
this.plugin.settings.MALAPImovie = data;
|
||||||
this.plugin.saveSettings();
|
this.plugin.saveSettings();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
containerEl.createEl('h5', { text: 'Series' });
|
containerEl.createEl('h5', { text: 'Series' });
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('OMDb API')
|
.setName('OMDb API')
|
||||||
|
|
@ -305,7 +305,7 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
this.plugin.saveSettings();
|
this.plugin.saveSettings();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('MAL API')
|
.setName('MAL API')
|
||||||
.setDesc('Use MAL API for series.')
|
.setDesc('Use MAL API for series.')
|
||||||
.addToggle(cb => {
|
.addToggle(cb => {
|
||||||
|
|
@ -315,7 +315,7 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
containerEl.createEl('h5', { text: 'Games' });
|
containerEl.createEl('h5', { text: 'Games' });
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('OMDb API')
|
.setName('OMDb API')
|
||||||
.setDesc('Use OMDb API for games.')
|
.setDesc('Use OMDb API for games.')
|
||||||
.addToggle(cb => {
|
.addToggle(cb => {
|
||||||
|
|
@ -324,7 +324,7 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
this.plugin.saveSettings();
|
this.plugin.saveSettings();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Steam API')
|
.setName('Steam API')
|
||||||
.setDesc('Use OMDb API for games.')
|
.setDesc('Use OMDb API for games.')
|
||||||
.addToggle(cb => {
|
.addToggle(cb => {
|
||||||
|
|
@ -333,7 +333,7 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
this.plugin.saveSettings();
|
this.plugin.saveSettings();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('MobyGames API')
|
.setName('MobyGames API')
|
||||||
.setDesc('Use MobyGames API for games.')
|
.setDesc('Use MobyGames API for games.')
|
||||||
.addToggle(cb => {
|
.addToggle(cb => {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ export class MediaTypeManager {
|
||||||
mediaTemplateMap: Map<MediaType, string>;
|
mediaTemplateMap: Map<MediaType, string>;
|
||||||
mediaFolderMap: Map<MediaType, string>;
|
mediaFolderMap: Map<MediaType, string>;
|
||||||
|
|
||||||
constructor() {}
|
constructor() { }
|
||||||
|
|
||||||
updateTemplates(settings: MediaDbPluginSettings): void {
|
updateTemplates(settings: MediaDbPluginSettings): void {
|
||||||
this.mediaFileNameTemplateMap = new Map<MediaType, string>();
|
this.mediaFileNameTemplateMap = new Map<MediaType, string>();
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,7 @@ export function unCamelCase(str: string): string {
|
||||||
// space before last upper in a sequence followed by lower
|
// space before last upper in a sequence followed by lower
|
||||||
.replace(/\b([A-Z]+)([A-Z])([a-z])/, '$1 $2$3')
|
.replace(/\b([A-Z]+)([A-Z])([a-z])/, '$1 $2$3')
|
||||||
// uppercase the first character
|
// uppercase the first character
|
||||||
.replace(/^./, function (str) {
|
.replace(/^./, function(str) {
|
||||||
return str.toUpperCase();
|
return str.toUpperCase();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue