Merge pull request #133 from ltctceplrm/master
Adding options to disable certain API per media type
This commit is contained in:
commit
cf3d5c6d6f
5 changed files with 131 additions and 10 deletions
|
|
@ -1,11 +1,14 @@
|
|||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||
import { MediaType } from '../utils/MediaType';
|
||||
import { MediaDbPluginSettings } from 'src/settings/Settings';
|
||||
import MediaDbPlugin from '../main';
|
||||
|
||||
export abstract class APIModel {
|
||||
apiName: string;
|
||||
apiUrl: string;
|
||||
apiDescription: string;
|
||||
types: MediaType[];
|
||||
plugin: MediaDbPlugin;
|
||||
|
||||
/**
|
||||
* This function should query the api and return a list of matches. The matches should be caped at 20.
|
||||
|
|
@ -17,7 +20,9 @@ export abstract class APIModel {
|
|||
abstract getById(id: string): Promise<MediaTypeModel>;
|
||||
|
||||
hasType(type: MediaType): boolean {
|
||||
return this.types.contains(type);
|
||||
if (this.types.contains(type) && (Boolean((this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type] as MediaDbPluginSettings) === true || (this.plugin.settings.apiToggle as any)?.[this.apiName]?.[type] as MediaDbPluginSettings === undefined)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
hasTypeOverlap(types: MediaType[]): boolean {
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ export class MediaDbSearchModal extends Modal {
|
|||
|
||||
const placeholder = 'Search by title';
|
||||
const searchComponent = new TextComponent(contentEl);
|
||||
let currentToggle: ToggleComponent = null;
|
||||
|
||||
searchComponent.inputEl.style.width = '100%';
|
||||
searchComponent.setPlaceholder(placeholder);
|
||||
searchComponent.setValue(this.query);
|
||||
|
|
@ -99,8 +101,21 @@ export class MediaDbSearchModal extends Modal {
|
|||
const apiToggleComponent = new ToggleComponent(apiToggleComponentWrapper);
|
||||
apiToggleComponent.setTooltip(unCamelCase(mediaType));
|
||||
apiToggleComponent.setValue(this.selectedTypes.find(x => x.name === mediaType).selected);
|
||||
if (apiToggleComponent.getValue()) {
|
||||
currentToggle = apiToggleComponent;
|
||||
}
|
||||
apiToggleComponent.onChange(value => {
|
||||
this.selectedTypes.find(x => x.name === mediaType).selected = value;
|
||||
if (value) {
|
||||
if (currentToggle && currentToggle !== apiToggleComponent) {
|
||||
currentToggle.setValue(false);
|
||||
this.selectedTypes.find(x => x.name === mediaType).selected = false;
|
||||
}
|
||||
currentToggle = apiToggleComponent;
|
||||
this.selectedTypes.find(x => x.name === mediaType).selected = true;
|
||||
} else {
|
||||
currentToggle = null;
|
||||
this.selectedTypes.find(x => x.name === mediaType).selected = false;
|
||||
}
|
||||
});
|
||||
apiToggleComponentWrapper.appendChild(apiToggleComponent.toggleEl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,23 @@ export interface MediaDbPluginSettings {
|
|||
openNoteInNewTab: boolean;
|
||||
useDefaultFrontMatter: boolean;
|
||||
enableTemplaterIntegration: boolean;
|
||||
|
||||
apiToggle: {
|
||||
OMDbAPI: {
|
||||
movie: boolean;
|
||||
series: boolean;
|
||||
game: boolean;
|
||||
},
|
||||
MALAPI: {
|
||||
movie: boolean;
|
||||
series: boolean;
|
||||
},
|
||||
SteamAPI: {
|
||||
game: boolean;
|
||||
},
|
||||
MobyGamesAPI: {
|
||||
game: boolean;
|
||||
}
|
||||
},
|
||||
movieTemplate: string;
|
||||
seriesTemplate: string;
|
||||
mangaTemplate: string;
|
||||
|
|
@ -69,7 +85,23 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
|||
openNoteInNewTab: true,
|
||||
useDefaultFrontMatter: true,
|
||||
enableTemplaterIntegration: false,
|
||||
|
||||
apiToggle: {
|
||||
OMDbAPI: {
|
||||
movie: true,
|
||||
series: true,
|
||||
game: true,
|
||||
},
|
||||
MALAPI: {
|
||||
movie: true,
|
||||
series: true,
|
||||
},
|
||||
SteamAPI: {
|
||||
game: true,
|
||||
},
|
||||
MobyGamesAPI: {
|
||||
game: true,
|
||||
}
|
||||
},
|
||||
movieTemplate: '',
|
||||
seriesTemplate: '',
|
||||
mangaTemplate: '',
|
||||
|
|
@ -209,10 +241,10 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
.setDesc(
|
||||
fragWithHTML(
|
||||
"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>" +
|
||||
"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() +
|
||||
'</a></b>',
|
||||
"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;'>" +
|
||||
this.plugin.dateFormatter.getPreview() +
|
||||
'</a></b>',
|
||||
),
|
||||
)
|
||||
.addText(cb => {
|
||||
|
|
@ -260,6 +292,75 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
containerEl.createEl('h3', { text: 'APIs Per Media Type' });
|
||||
containerEl.createEl('h5', { text: 'Movies' });
|
||||
new Setting(containerEl)
|
||||
.setName('OMDb API')
|
||||
.setDesc('Use OMDb API for movies.')
|
||||
.addToggle(cb => {
|
||||
cb.setValue(this.plugin.settings.apiToggle.OMDbAPI.movie).onChange(data => {
|
||||
this.plugin.settings.apiToggle.OMDbAPI.movie = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
new Setting(containerEl)
|
||||
.setName('MAL API')
|
||||
.setDesc('Use MAL API for movies.')
|
||||
.addToggle(cb => {
|
||||
cb.setValue(this.plugin.settings.apiToggle.MALAPI.movie).onChange(data => {
|
||||
this.plugin.settings.apiToggle.MALAPI.movie = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
containerEl.createEl('h5', { text: 'Series' });
|
||||
new Setting(containerEl)
|
||||
.setName('OMDb API')
|
||||
.setDesc('Use OMDb API for series.')
|
||||
.addToggle(cb => {
|
||||
cb.setValue(this.plugin.settings.apiToggle.OMDbAPI.series).onChange(data => {
|
||||
this.plugin.settings.apiToggle.OMDbAPI.series = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
new Setting(containerEl)
|
||||
.setName('MAL API')
|
||||
.setDesc('Use MAL API for series.')
|
||||
.addToggle(cb => {
|
||||
cb.setValue(this.plugin.settings.apiToggle.MALAPI.series).onChange(data => {
|
||||
this.plugin.settings.apiToggle.MALAPI.series = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
containerEl.createEl('h5', { text: 'Games' });
|
||||
new Setting(containerEl)
|
||||
.setName('OMDb API')
|
||||
.setDesc('Use OMDb API for games.')
|
||||
.addToggle(cb => {
|
||||
cb.setValue(this.plugin.settings.apiToggle.OMDbAPI.game).onChange(data => {
|
||||
this.plugin.settings.apiToggle.OMDbAPI.game = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
new Setting(containerEl)
|
||||
.setName('Steam API')
|
||||
.setDesc('Use OMDb API for games.')
|
||||
.addToggle(cb => {
|
||||
cb.setValue(this.plugin.settings.apiToggle.SteamAPI.game).onChange(data => {
|
||||
this.plugin.settings.apiToggle.SteamAPI.game = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
new Setting(containerEl)
|
||||
.setName('MobyGames API')
|
||||
.setDesc('Use MobyGames API for games.')
|
||||
.addToggle(cb => {
|
||||
cb.setValue(this.plugin.settings.apiToggle.MobyGamesAPI.game).onChange(data => {
|
||||
this.plugin.settings.apiToggle.MobyGamesAPI.game = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
containerEl.createEl('h3', { text: 'New File Location' });
|
||||
// region new file location
|
||||
new Setting(containerEl)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ export class MediaTypeManager {
|
|||
mediaTemplateMap: Map<MediaType, string>;
|
||||
mediaFolderMap: Map<MediaType, string>;
|
||||
|
||||
constructor() {}
|
||||
constructor() { }
|
||||
|
||||
updateTemplates(settings: MediaDbPluginSettings): void {
|
||||
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
|
||||
.replace(/\b([A-Z]+)([A-Z])([a-z])/, '$1 $2$3')
|
||||
// uppercase the first character
|
||||
.replace(/^./, function (str) {
|
||||
.replace(/^./, function(str) {
|
||||
return str.toUpperCase();
|
||||
})
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue