install prettier
This commit is contained in:
parent
2662c78080
commit
9e2961421d
57 changed files with 2367 additions and 1162 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import {APIModel} from './APIModel';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import { APIModel } from './APIModel';
|
||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||
|
||||
export class APIManager {
|
||||
apis: APIModel[];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||
|
||||
export abstract class APIModel {
|
||||
apiName: string;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import {APIModel} from '../APIModel';
|
||||
import {MediaTypeModel} from '../../models/MediaTypeModel';
|
||||
import { APIModel } from '../APIModel';
|
||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
import {BoardGameModel} from 'src/models/BoardGameModel';
|
||||
import {debugLog} from '../../utils/Utils';
|
||||
import {requestUrl} from 'obsidian';
|
||||
import { BoardGameModel } from 'src/models/BoardGameModel';
|
||||
import { debugLog } from '../../utils/Utils';
|
||||
import { requestUrl } from 'obsidian';
|
||||
|
||||
export class BoardGameGeekAPI extends APIModel {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -42,13 +42,15 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
const title = boardgame.querySelector('name')!.textContent!;
|
||||
const year = boardgame.querySelector('yearpublished')?.textContent ?? '';
|
||||
|
||||
ret.push(new BoardGameModel({
|
||||
dataSource: this.apiName,
|
||||
id,
|
||||
title,
|
||||
englishTitle: title,
|
||||
year,
|
||||
} as BoardGameModel));
|
||||
ret.push(
|
||||
new BoardGameModel({
|
||||
dataSource: this.apiName,
|
||||
id,
|
||||
title,
|
||||
englishTitle: title,
|
||||
year,
|
||||
} as BoardGameModel)
|
||||
);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -97,6 +99,5 @@ export class BoardGameGeekAPI extends APIModel {
|
|||
} as BoardGameModel);
|
||||
|
||||
return model;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {APIModel} from '../APIModel';
|
||||
import {MediaTypeModel} from '../../models/MediaTypeModel';
|
||||
import { APIModel } from '../APIModel';
|
||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
import {debugLog} from '../../utils/Utils';
|
||||
import { debugLog } from '../../utils/Utils';
|
||||
|
||||
// WIP
|
||||
export class LocGovAPI extends APIModel {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import {APIModel} from '../APIModel';
|
||||
import {MediaTypeModel} from '../../models/MediaTypeModel';
|
||||
import {MovieModel} from '../../models/MovieModel';
|
||||
import { APIModel } from '../APIModel';
|
||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import { MovieModel } from '../../models/MovieModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
import {SeriesModel} from '../../models/SeriesModel';
|
||||
import {debugLog} from '../../utils/Utils';
|
||||
import { SeriesModel } from '../../models/SeriesModel';
|
||||
import { debugLog } from '../../utils/Utils';
|
||||
|
||||
export class MALAPI extends APIModel {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -43,33 +43,39 @@ export class MALAPI extends APIModel {
|
|||
for (const result of data.data) {
|
||||
const type = this.typeMappings.get(result.type?.toLowerCase());
|
||||
if (type === undefined) {
|
||||
ret.push(new MovieModel({
|
||||
subType: '',
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||
dataSource: this.apiName,
|
||||
id: result.mal_id,
|
||||
} as MovieModel));
|
||||
ret.push(
|
||||
new MovieModel({
|
||||
subType: '',
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||
dataSource: this.apiName,
|
||||
id: result.mal_id,
|
||||
} as MovieModel)
|
||||
);
|
||||
}
|
||||
if (type === 'movie' || type === 'special') {
|
||||
ret.push(new MovieModel({
|
||||
subType: type,
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||
dataSource: this.apiName,
|
||||
id: result.mal_id,
|
||||
} as MovieModel));
|
||||
ret.push(
|
||||
new MovieModel({
|
||||
subType: type,
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||
dataSource: this.apiName,
|
||||
id: result.mal_id,
|
||||
} as MovieModel)
|
||||
);
|
||||
} else if (type === 'series' || type === 'ova') {
|
||||
ret.push(new SeriesModel({
|
||||
subType: type,
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||
dataSource: this.apiName,
|
||||
id: result.mal_id,
|
||||
} as SeriesModel));
|
||||
ret.push(
|
||||
new SeriesModel({
|
||||
subType: type,
|
||||
title: result.title,
|
||||
englishTitle: result.title_english ?? result.title,
|
||||
year: result.year ?? result.aired?.prop?.from?.year ?? '',
|
||||
dataSource: this.apiName,
|
||||
id: result.mal_id,
|
||||
} as SeriesModel)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +114,7 @@ export class MALAPI extends APIModel {
|
|||
image: result.images?.jpg?.image_url ?? '',
|
||||
|
||||
released: true,
|
||||
premiere: (new Date(result.aired?.from)).toLocaleDateString() ?? 'unknown',
|
||||
premiere: new Date(result.aired?.from).toLocaleDateString() ?? 'unknown',
|
||||
|
||||
userData: {
|
||||
watched: false,
|
||||
|
|
@ -137,7 +143,7 @@ export class MALAPI extends APIModel {
|
|||
image: result.images?.jpg?.image_url ?? '',
|
||||
|
||||
released: true,
|
||||
premiere: (new Date(result.aired?.from)).toLocaleDateString() ?? 'unknown',
|
||||
premiere: new Date(result.aired?.from).toLocaleDateString() ?? 'unknown',
|
||||
|
||||
userData: {
|
||||
watched: false,
|
||||
|
|
@ -165,8 +171,8 @@ export class MALAPI extends APIModel {
|
|||
image: result.images?.jpg?.image_url ?? '',
|
||||
|
||||
released: true,
|
||||
airedFrom: (new Date(result.aired?.from)).toLocaleDateString() ?? 'unknown',
|
||||
airedTo: (new Date(result.aired?.to)).toLocaleDateString() ?? 'unknown',
|
||||
airedFrom: new Date(result.aired?.from).toLocaleDateString() ?? 'unknown',
|
||||
airedTo: new Date(result.aired?.to).toLocaleDateString() ?? 'unknown',
|
||||
airing: result.airing,
|
||||
|
||||
userData: {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import {APIModel} from '../APIModel';
|
||||
import {MediaTypeModel} from '../../models/MediaTypeModel';
|
||||
import { APIModel } from '../APIModel';
|
||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
import {requestUrl} from 'obsidian';
|
||||
import {MusicReleaseModel} from '../../models/MusicReleaseModel';
|
||||
import {contactEmail, debugLog, mediaDbVersion, pluginName} from '../../utils/Utils';
|
||||
import { requestUrl } from 'obsidian';
|
||||
import { MusicReleaseModel } from '../../models/MusicReleaseModel';
|
||||
import { contactEmail, debugLog, mediaDbVersion, pluginName } from '../../utils/Utils';
|
||||
|
||||
export class MusicBrainzAPI extends APIModel {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -41,18 +41,20 @@ export class MusicBrainzAPI extends APIModel {
|
|||
let ret: MediaTypeModel[] = [];
|
||||
|
||||
for (const result of data['release-groups']) {
|
||||
ret.push(new MusicReleaseModel({
|
||||
type: 'musicRelease',
|
||||
title: result.title,
|
||||
englishTitle: result.title,
|
||||
year: (new Date(result['first-release-date'])).getFullYear().toString(),
|
||||
dataSource: this.apiName,
|
||||
url: '',
|
||||
id: result.id,
|
||||
ret.push(
|
||||
new MusicReleaseModel({
|
||||
type: 'musicRelease',
|
||||
title: result.title,
|
||||
englishTitle: result.title,
|
||||
year: new Date(result['first-release-date']).getFullYear().toString(),
|
||||
dataSource: this.apiName,
|
||||
url: '',
|
||||
id: result.id,
|
||||
|
||||
artists: result['artist-credit'].map((a: any) => a.name),
|
||||
subType: result['primary-type'],
|
||||
} as MusicReleaseModel));
|
||||
artists: result['artist-credit'].map((a: any) => a.name),
|
||||
subType: result['primary-type'],
|
||||
} as MusicReleaseModel)
|
||||
);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -81,7 +83,7 @@ export class MusicBrainzAPI extends APIModel {
|
|||
type: 'musicRelease',
|
||||
title: result.title,
|
||||
englishTitle: result.title,
|
||||
year: (new Date(result['first-release-date'])).getFullYear().toString(),
|
||||
year: new Date(result['first-release-date']).getFullYear().toString(),
|
||||
dataSource: this.apiName,
|
||||
url: '',
|
||||
id: result.id,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import {APIModel} from '../APIModel';
|
||||
import {MediaTypeModel} from '../../models/MediaTypeModel';
|
||||
import {MovieModel} from '../../models/MovieModel';
|
||||
import { APIModel } from '../APIModel';
|
||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import { MovieModel } from '../../models/MovieModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
import {SeriesModel} from '../../models/SeriesModel';
|
||||
import {GameModel} from '../../models/GameModel';
|
||||
import {debugLog} from '../../utils/Utils';
|
||||
import { SeriesModel } from '../../models/SeriesModel';
|
||||
import { GameModel } from '../../models/GameModel';
|
||||
import { debugLog } from '../../utils/Utils';
|
||||
|
||||
export class OMDbAPI extends APIModel {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -56,32 +56,38 @@ export class OMDbAPI extends APIModel {
|
|||
continue;
|
||||
}
|
||||
if (type === 'movie') {
|
||||
ret.push(new MovieModel({
|
||||
type: type,
|
||||
title: result.Title,
|
||||
englishTitle: result.Title,
|
||||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
id: result.imdbID,
|
||||
} as MovieModel));
|
||||
ret.push(
|
||||
new MovieModel({
|
||||
type: type,
|
||||
title: result.Title,
|
||||
englishTitle: result.Title,
|
||||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
id: result.imdbID,
|
||||
} as MovieModel)
|
||||
);
|
||||
} else if (type === 'series') {
|
||||
ret.push(new SeriesModel({
|
||||
type: type,
|
||||
title: result.Title,
|
||||
englishTitle: result.Title,
|
||||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
id: result.imdbID,
|
||||
} as SeriesModel));
|
||||
ret.push(
|
||||
new SeriesModel({
|
||||
type: type,
|
||||
title: result.Title,
|
||||
englishTitle: result.Title,
|
||||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
id: result.imdbID,
|
||||
} as SeriesModel)
|
||||
);
|
||||
} else if (type === 'game') {
|
||||
ret.push(new GameModel({
|
||||
type: type,
|
||||
title: result.Title,
|
||||
englishTitle: result.Title,
|
||||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
id: result.imdbID,
|
||||
} as GameModel));
|
||||
ret.push(
|
||||
new GameModel({
|
||||
type: type,
|
||||
title: result.Title,
|
||||
englishTitle: result.Title,
|
||||
year: result.Year,
|
||||
dataSource: this.apiName,
|
||||
id: result.imdbID,
|
||||
} as GameModel)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +136,7 @@ export class OMDbAPI extends APIModel {
|
|||
image: result.Poster ?? '',
|
||||
|
||||
released: true,
|
||||
premiere: (new Date(result.Released)).toLocaleDateString() ?? 'unknown',
|
||||
premiere: new Date(result.Released).toLocaleDateString() ?? 'unknown',
|
||||
|
||||
userData: {
|
||||
watched: false,
|
||||
|
|
@ -159,7 +165,7 @@ export class OMDbAPI extends APIModel {
|
|||
|
||||
released: true,
|
||||
airing: false,
|
||||
airedFrom: (new Date(result.Released)).toLocaleDateString() ?? 'unknown',
|
||||
airedFrom: new Date(result.Released).toLocaleDateString() ?? 'unknown',
|
||||
airedTo: 'unknown',
|
||||
|
||||
userData: {
|
||||
|
|
@ -185,7 +191,7 @@ export class OMDbAPI extends APIModel {
|
|||
image: result.Poster ?? '',
|
||||
|
||||
released: true,
|
||||
releaseDate: (new Date(result.Released)).toLocaleDateString() ?? 'unknown',
|
||||
releaseDate: new Date(result.Released).toLocaleDateString() ?? 'unknown',
|
||||
|
||||
userData: {
|
||||
played: false,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import {APIModel} from '../APIModel';
|
||||
import {MediaTypeModel} from '../../models/MediaTypeModel';
|
||||
import { APIModel } from '../APIModel';
|
||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
import {GameModel} from '../../models/GameModel';
|
||||
import {debugLog} from '../../utils/Utils';
|
||||
import {requestUrl} from 'obsidian';
|
||||
import {MediaType} from '../../utils/MediaType';
|
||||
import { GameModel } from '../../models/GameModel';
|
||||
import { debugLog } from '../../utils/Utils';
|
||||
import { requestUrl } from 'obsidian';
|
||||
import { MediaType } from '../../utils/MediaType';
|
||||
|
||||
export class SteamAPI extends APIModel {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -52,14 +52,16 @@ export class SteamAPI extends APIModel {
|
|||
let ret: MediaTypeModel[] = [];
|
||||
|
||||
for (const result of filteredData) {
|
||||
ret.push(new GameModel({
|
||||
type: MediaType.Game,
|
||||
title: result.name,
|
||||
englishTitle: result.name,
|
||||
year: '',
|
||||
dataSource: this.apiName,
|
||||
id: result.appid,
|
||||
} as GameModel));
|
||||
ret.push(
|
||||
new GameModel({
|
||||
type: MediaType.Game,
|
||||
title: result.name,
|
||||
englishTitle: result.name,
|
||||
year: '',
|
||||
dataSource: this.apiName,
|
||||
id: result.appid,
|
||||
} as GameModel)
|
||||
);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -98,7 +100,7 @@ export class SteamAPI extends APIModel {
|
|||
type: MediaType.Game,
|
||||
title: result.name,
|
||||
englishTitle: result.name,
|
||||
year: (new Date(result.release_date.date)).getFullYear().toString(),
|
||||
year: new Date(result.release_date.date).getFullYear().toString(),
|
||||
dataSource: this.apiName,
|
||||
url: `https://store.steampowered.com/app/${result.steam_appid}`,
|
||||
id: result.steam_appid,
|
||||
|
|
@ -108,7 +110,7 @@ export class SteamAPI extends APIModel {
|
|||
image: result.header_image ?? '',
|
||||
|
||||
released: !result.release_date?.comming_soon,
|
||||
releaseDate: (new Date(result.release_date?.date)).toLocaleDateString() ?? 'unknown',
|
||||
releaseDate: new Date(result.release_date?.date).toLocaleDateString() ?? 'unknown',
|
||||
|
||||
userData: {
|
||||
played: false,
|
||||
|
|
@ -117,6 +119,5 @@ export class SteamAPI extends APIModel {
|
|||
} as GameModel);
|
||||
|
||||
return model;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import {APIModel} from '../APIModel';
|
||||
import {MediaTypeModel} from '../../models/MediaTypeModel';
|
||||
import { APIModel } from '../APIModel';
|
||||
import { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
import {WikiModel} from '../../models/WikiModel';
|
||||
import {debugLog} from '../../utils/Utils';
|
||||
import { WikiModel } from '../../models/WikiModel';
|
||||
import { debugLog } from '../../utils/Utils';
|
||||
|
||||
export class WikipediaAPI extends APIModel {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -33,14 +33,16 @@ export class WikipediaAPI extends APIModel {
|
|||
let ret: MediaTypeModel[] = [];
|
||||
|
||||
for (const result of data.query.search) {
|
||||
ret.push(new WikiModel({
|
||||
type: 'wiki',
|
||||
title: result.title,
|
||||
englishTitle: result.title,
|
||||
year: '',
|
||||
dataSource: this.apiName,
|
||||
id: result.pageid,
|
||||
} as WikiModel));
|
||||
ret.push(
|
||||
new WikiModel({
|
||||
type: 'wiki',
|
||||
title: result.title,
|
||||
englishTitle: result.title,
|
||||
year: '',
|
||||
dataSource: this.apiName,
|
||||
id: result.pageid,
|
||||
} as WikiModel)
|
||||
);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -70,7 +72,7 @@ export class WikipediaAPI extends APIModel {
|
|||
id: result.pageid,
|
||||
|
||||
wikiUrl: result.fullurl,
|
||||
lastUpdated: (new Date(result.touched)).toLocaleDateString() ?? 'unknown',
|
||||
lastUpdated: new Date(result.touched).toLocaleDateString() ?? 'unknown',
|
||||
length: result.length,
|
||||
|
||||
userData: {},
|
||||
|
|
|
|||
142
src/main.ts
142
src/main.ts
|
|
@ -1,20 +1,20 @@
|
|||
import {MarkdownView, Notice, parseYaml, Plugin, stringifyYaml, TFile, TFolder} from 'obsidian';
|
||||
import {getDefaultSettings, MediaDbPluginSettings, MediaDbSettingTab} from './settings/Settings';
|
||||
import {APIManager} from './api/APIManager';
|
||||
import {MediaTypeModel} from './models/MediaTypeModel';
|
||||
import {CreateNoteOptions, dateTimeToString, markdownTable, replaceIllegalFileNameCharactersInString} from './utils/Utils';
|
||||
import {OMDbAPI} from './api/apis/OMDbAPI';
|
||||
import {MALAPI} from './api/apis/MALAPI';
|
||||
import {WikipediaAPI} from './api/apis/WikipediaAPI';
|
||||
import {MusicBrainzAPI} from './api/apis/MusicBrainzAPI';
|
||||
import {MediaTypeManager} from './utils/MediaTypeManager';
|
||||
import {SteamAPI} from './api/apis/SteamAPI';
|
||||
import {BoardGameGeekAPI} from './api/apis/BoardGameGeekAPI';
|
||||
import {PropertyMapper} from './settings/PropertyMapper';
|
||||
import {YAMLConverter} from './utils/YAMLConverter';
|
||||
import {MediaDbFolderImportModal} from './modals/MediaDbFolderImportModal';
|
||||
import {PropertyMapping, PropertyMappingModel} from './settings/PropertyMapping';
|
||||
import {ModalHelper, ModalResultCode} from './utils/ModalHelper';
|
||||
import { MarkdownView, Notice, parseYaml, Plugin, stringifyYaml, TFile, TFolder } from 'obsidian';
|
||||
import { getDefaultSettings, MediaDbPluginSettings, MediaDbSettingTab } from './settings/Settings';
|
||||
import { APIManager } from './api/APIManager';
|
||||
import { MediaTypeModel } from './models/MediaTypeModel';
|
||||
import { CreateNoteOptions, dateTimeToString, markdownTable, replaceIllegalFileNameCharactersInString } from './utils/Utils';
|
||||
import { OMDbAPI } from './api/apis/OMDbAPI';
|
||||
import { MALAPI } from './api/apis/MALAPI';
|
||||
import { WikipediaAPI } from './api/apis/WikipediaAPI';
|
||||
import { MusicBrainzAPI } from './api/apis/MusicBrainzAPI';
|
||||
import { MediaTypeManager } from './utils/MediaTypeManager';
|
||||
import { SteamAPI } from './api/apis/SteamAPI';
|
||||
import { BoardGameGeekAPI } from './api/apis/BoardGameGeekAPI';
|
||||
import { PropertyMapper } from './settings/PropertyMapper';
|
||||
import { YAMLConverter } from './utils/YAMLConverter';
|
||||
import { MediaDbFolderImportModal } from './modals/MediaDbFolderImportModal';
|
||||
import { PropertyMapping, PropertyMappingModel } from './settings/PropertyMapping';
|
||||
import { ModalHelper, ModalResultCode } from './utils/ModalHelper';
|
||||
|
||||
export default class MediaDbPlugin extends Plugin {
|
||||
settings: MediaDbPluginSettings;
|
||||
|
|
@ -47,20 +47,20 @@ export default class MediaDbPlugin extends Plugin {
|
|||
this.mediaTypeManager.updateTemplates(this.settings);
|
||||
|
||||
// add icon to the left ribbon
|
||||
const ribbonIconEl = this.addRibbonIcon('database', 'Add new Media DB entry', (evt: MouseEvent) =>
|
||||
this.createEntryWithAdvancedSearchModal(),
|
||||
);
|
||||
const ribbonIconEl = this.addRibbonIcon('database', 'Add new Media DB entry', (evt: MouseEvent) => this.createEntryWithAdvancedSearchModal());
|
||||
ribbonIconEl.addClass('obsidian-media-db-plugin-ribbon-class');
|
||||
|
||||
this.registerEvent(this.app.workspace.on('file-menu', (menu, file) => {
|
||||
if (file instanceof TFolder) {
|
||||
menu.addItem(item => {
|
||||
item.setTitle('Import folder as Media DB entries')
|
||||
.setIcon('database')
|
||||
.onClick(() => this.createEntriesFromFolder(file));
|
||||
});
|
||||
}
|
||||
}));
|
||||
this.registerEvent(
|
||||
this.app.workspace.on('file-menu', (menu, file) => {
|
||||
if (file instanceof TFolder) {
|
||||
menu.addItem(item => {
|
||||
item.setTitle('Import folder as Media DB entries')
|
||||
.setIcon('database')
|
||||
.onClick(() => this.createEntriesFromFolder(file));
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
// register command to open search modal
|
||||
this.addCommand({
|
||||
|
|
@ -129,8 +129,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
* - maybe custom link syntax
|
||||
*/
|
||||
async createLinkWithSearchModal() {
|
||||
|
||||
let apiSearchResults: MediaTypeModel[] = await this.modalHelper.openAdvancedSearchModal({}, async (advancedSearchModalData) => {
|
||||
let apiSearchResults: MediaTypeModel[] = await this.modalHelper.openAdvancedSearchModal({}, async advancedSearchModalData => {
|
||||
return await this.apiManager.query(advancedSearchModalData.query, advancedSearchModalData.apis);
|
||||
});
|
||||
|
||||
|
|
@ -138,7 +137,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
return;
|
||||
}
|
||||
|
||||
const selectResults: MediaTypeModel[] = await this.modalHelper.openSelectModal({elements: apiSearchResults, multiSelect: false}, async (selectModalData) => {
|
||||
const selectResults: MediaTypeModel[] = await this.modalHelper.openSelectModal({ elements: apiSearchResults, multiSelect: false }, async selectModalData => {
|
||||
return await this.queryDetails(selectModalData.selected);
|
||||
});
|
||||
|
||||
|
|
@ -158,7 +157,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
|
||||
async createEntryWithSearchModal() {
|
||||
let types: string[] = [];
|
||||
let apiSearchResults: MediaTypeModel[] = await this.modalHelper.openSearchModal({}, async (searchModalData) => {
|
||||
let apiSearchResults: MediaTypeModel[] = await this.modalHelper.openSearchModal({}, async searchModalData => {
|
||||
types = searchModalData.types;
|
||||
const apis = this.apiManager.apis.filter(x => x.hasTypeOverlap(searchModalData.types)).map(x => x.apiName);
|
||||
return await this.apiManager.query(searchModalData.query, apis);
|
||||
|
|
@ -176,14 +175,14 @@ export default class MediaDbPlugin extends Plugin {
|
|||
let proceed: boolean;
|
||||
|
||||
while (!proceed) {
|
||||
selectResults = await this.modalHelper.openSelectModal({elements: apiSearchResults}, async (selectModalData) => {
|
||||
selectResults = await this.modalHelper.openSelectModal({ elements: apiSearchResults }, async selectModalData => {
|
||||
return await this.queryDetails(selectModalData.selected);
|
||||
});
|
||||
if (!selectResults) {
|
||||
return;
|
||||
}
|
||||
|
||||
proceed = await this.modalHelper.openPreviewModal({elements: selectResults}, async (previewModalData) => {
|
||||
proceed = await this.modalHelper.openPreviewModal({ elements: selectResults }, async previewModalData => {
|
||||
return previewModalData.confirmed;
|
||||
});
|
||||
}
|
||||
|
|
@ -192,7 +191,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
}
|
||||
|
||||
async createEntryWithAdvancedSearchModal() {
|
||||
let apiSearchResults: MediaTypeModel[] = await this.modalHelper.openAdvancedSearchModal({}, async (advancedSearchModalData) => {
|
||||
let apiSearchResults: MediaTypeModel[] = await this.modalHelper.openAdvancedSearchModal({}, async advancedSearchModalData => {
|
||||
return await this.apiManager.query(advancedSearchModalData.query, advancedSearchModalData.apis);
|
||||
});
|
||||
|
||||
|
|
@ -205,14 +204,14 @@ export default class MediaDbPlugin extends Plugin {
|
|||
let proceed: boolean;
|
||||
|
||||
while (!proceed) {
|
||||
selectResults = await this.modalHelper.openSelectModal({elements: apiSearchResults}, async (selectModalData) => {
|
||||
selectResults = await this.modalHelper.openSelectModal({ elements: apiSearchResults }, async selectModalData => {
|
||||
return await this.queryDetails(selectModalData.selected);
|
||||
});
|
||||
if (!selectResults) {
|
||||
return;
|
||||
}
|
||||
|
||||
proceed = await this.modalHelper.openPreviewModal({elements: selectResults}, async (previewModalData) => {
|
||||
proceed = await this.modalHelper.openPreviewModal({ elements: selectResults }, async previewModalData => {
|
||||
return previewModalData.confirmed;
|
||||
});
|
||||
}
|
||||
|
|
@ -225,24 +224,24 @@ export default class MediaDbPlugin extends Plugin {
|
|||
let proceed: boolean;
|
||||
|
||||
while (!proceed) {
|
||||
idSearchResult = await this.modalHelper.openIdSearchModal({}, async (idSearchModalData) => {
|
||||
idSearchResult = await this.modalHelper.openIdSearchModal({}, async idSearchModalData => {
|
||||
return await this.apiManager.queryDetailedInfoById(idSearchModalData.query, idSearchModalData.api);
|
||||
});
|
||||
if (!idSearchResult) {
|
||||
return;
|
||||
}
|
||||
|
||||
proceed = await this.modalHelper.openPreviewModal({elements: [idSearchResult]}, async (previewModalData) => {
|
||||
proceed = await this.modalHelper.openPreviewModal({ elements: [idSearchResult] }, async previewModalData => {
|
||||
return previewModalData.confirmed;
|
||||
});
|
||||
}
|
||||
|
||||
await this.createMediaDbNoteFromModel(idSearchResult, {attachTemplate: true, openNote: true});
|
||||
await this.createMediaDbNoteFromModel(idSearchResult, { attachTemplate: true, openNote: true });
|
||||
}
|
||||
|
||||
async createMediaDbNotes(models: MediaTypeModel[], attachFile?: TFile): Promise<void> {
|
||||
for (const model of models) {
|
||||
await this.createMediaDbNoteFromModel(model, {attachTemplate: true, attachFile: attachFile});
|
||||
await this.createMediaDbNoteFromModel(model, { attachTemplate: true, attachFile: attachFile });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -277,16 +276,16 @@ export default class MediaDbPlugin extends Plugin {
|
|||
let fileContent = '';
|
||||
const template = options.attachTemplate ? await this.mediaTypeManager.getTemplate(mediaTypeModel, this.app) : '';
|
||||
|
||||
({fileMetadata, fileContent} = await this.attachFile(fileMetadata, fileContent, options.attachFile));
|
||||
({fileMetadata, fileContent} = await this.attachTemplate(fileMetadata, fileContent, template));
|
||||
({ fileMetadata, fileContent } = await this.attachFile(fileMetadata, fileContent, options.attachFile));
|
||||
({ fileMetadata, fileContent } = await this.attachTemplate(fileMetadata, fileContent, template));
|
||||
|
||||
fileContent = `---\n${this.settings.useCustomYamlStringifier ? YAMLConverter.toYaml(fileMetadata) : stringifyYaml(fileMetadata)}---\n` + fileContent;
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
async attachFile(fileMetadata: any, fileContent: string, fileToAttach?: TFile): Promise<{ fileMetadata: any, fileContent: string }> {
|
||||
async attachFile(fileMetadata: any, fileContent: string, fileToAttach?: TFile): Promise<{ fileMetadata: any; fileContent: string }> {
|
||||
if (!fileToAttach) {
|
||||
return {fileMetadata: fileMetadata, fileContent: fileContent};
|
||||
return { fileMetadata: fileMetadata, fileContent: fileContent };
|
||||
}
|
||||
|
||||
let attachFileMetadata: any = this.getMetadataFromFileCache(fileToAttach);
|
||||
|
|
@ -298,12 +297,12 @@ export default class MediaDbPlugin extends Plugin {
|
|||
attachFileContent = attachFileContent.startsWith('\n') ? attachFileContent.substring(1) : attachFileContent;
|
||||
fileContent += attachFileContent;
|
||||
|
||||
return {fileMetadata: fileMetadata, fileContent: fileContent};
|
||||
return { fileMetadata: fileMetadata, fileContent: fileContent };
|
||||
}
|
||||
|
||||
async attachTemplate(fileMetadata: any, fileContent: string, template: string): Promise<{ fileMetadata: any, fileContent: string }> {
|
||||
async attachTemplate(fileMetadata: any, fileContent: string, template: string): Promise<{ fileMetadata: any; fileContent: string }> {
|
||||
if (!template) {
|
||||
return {fileMetadata: fileMetadata, fileContent: fileContent};
|
||||
return { fileMetadata: fileMetadata, fileContent: fileContent };
|
||||
}
|
||||
|
||||
let templateMetadata: any = this.getMetaDataFromFileContent(template);
|
||||
|
|
@ -313,7 +312,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
const attachFileContent = template.replace(regExp, '');
|
||||
fileContent += attachFileContent;
|
||||
|
||||
return {fileMetadata: fileMetadata, fileContent: fileContent};
|
||||
return { fileMetadata: fileMetadata, fileContent: fileContent };
|
||||
}
|
||||
|
||||
getMetaDataFromFileContent(fileContent: string): any {
|
||||
|
|
@ -387,7 +386,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
console.warn('MDB | no active leaf, not opening newly created note');
|
||||
return;
|
||||
}
|
||||
await activeLeaf.openFile(targetFile, {state: {mode: 'source'}});
|
||||
await activeLeaf.openFile(targetFile, { state: { mode: 'source' } });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -424,28 +423,27 @@ export default class MediaDbPlugin extends Plugin {
|
|||
// deletion not happening anymore why is this log statement still here
|
||||
console.debug('MDB | deleting old entry');
|
||||
if (onlyMetadata) {
|
||||
await this.createMediaDbNoteFromModel(newMediaTypeModel, {attachFile: activeFile, folder: activeFile.parent, openNote: true});
|
||||
await this.createMediaDbNoteFromModel(newMediaTypeModel, { attachFile: activeFile, folder: activeFile.parent, openNote: true });
|
||||
} else {
|
||||
await this.createMediaDbNoteFromModel(newMediaTypeModel, {attachTemplate: true, folder: activeFile.parent, openNote: true});
|
||||
await this.createMediaDbNoteFromModel(newMediaTypeModel, { attachTemplate: true, folder: activeFile.parent, openNote: true });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async createEntriesFromFolder(folder: TFolder) {
|
||||
const erroredFiles: { filePath: string, error: string }[] = [];
|
||||
const erroredFiles: { filePath: string; error: string }[] = [];
|
||||
let canceled: boolean = false;
|
||||
|
||||
const {selectedAPI, titleFieldName, appendContent} = await new Promise<{ selectedAPI: string, titleFieldName: string, appendContent: boolean }>((resolve, reject) => {
|
||||
new MediaDbFolderImportModal(this.app, this, ((selectedAPI: string, titleFieldName: string, appendContent: boolean) => {
|
||||
resolve({selectedAPI, titleFieldName, appendContent});
|
||||
})).open();
|
||||
const { selectedAPI, titleFieldName, appendContent } = await new Promise<{ selectedAPI: string; titleFieldName: string; appendContent: boolean }>((resolve, reject) => {
|
||||
new MediaDbFolderImportModal(this.app, this, (selectedAPI: string, titleFieldName: string, appendContent: boolean) => {
|
||||
resolve({ selectedAPI, titleFieldName, appendContent });
|
||||
}).open();
|
||||
});
|
||||
|
||||
for (const child of folder.children) {
|
||||
if (child instanceof TFile) {
|
||||
const file: TFile = child;
|
||||
if (canceled) {
|
||||
erroredFiles.push({filePath: file.path, error: 'user canceled'});
|
||||
erroredFiles.push({ filePath: file.path, error: 'user canceled' });
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -453,7 +451,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
|
||||
let title = metadata[titleFieldName];
|
||||
if (!title) {
|
||||
erroredFiles.push({filePath: file.path, error: `metadata field \'${titleFieldName}\' not found or empty`});
|
||||
erroredFiles.push({ filePath: file.path, error: `metadata field \'${titleFieldName}\' not found or empty` });
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -461,37 +459,37 @@ export default class MediaDbPlugin extends Plugin {
|
|||
try {
|
||||
results = await this.apiManager.query(title, [selectedAPI]);
|
||||
} catch (e) {
|
||||
erroredFiles.push({filePath: file.path, error: e.toString()});
|
||||
erroredFiles.push({ filePath: file.path, error: e.toString() });
|
||||
continue;
|
||||
}
|
||||
if (!results || results.length === 0) {
|
||||
erroredFiles.push({filePath: file.path, error: `no search results`});
|
||||
erroredFiles.push({ filePath: file.path, error: `no search results` });
|
||||
continue;
|
||||
}
|
||||
|
||||
let {selectModalResult, selectModal} = await this.modalHelper.createSelectModal({elements: results, skipButton: true, modalTitle: `Results for \'${title}\'`});
|
||||
let { selectModalResult, selectModal } = await this.modalHelper.createSelectModal({ elements: results, skipButton: true, modalTitle: `Results for \'${title}\'` });
|
||||
|
||||
if (selectModalResult.code === ModalResultCode.ERROR) {
|
||||
erroredFiles.push({filePath: file.path, error: selectModalResult.error.message});
|
||||
erroredFiles.push({ filePath: file.path, error: selectModalResult.error.message });
|
||||
selectModal.close();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selectModalResult.code === ModalResultCode.CLOSE) {
|
||||
erroredFiles.push({filePath: file.path, error: 'user canceled'});
|
||||
erroredFiles.push({ filePath: file.path, error: 'user canceled' });
|
||||
selectModal.close();
|
||||
canceled = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selectModalResult.code === ModalResultCode.SKIP) {
|
||||
erroredFiles.push({filePath: file.path, error: 'user skipped'});
|
||||
erroredFiles.push({ filePath: file.path, error: 'user skipped' });
|
||||
selectModal.close();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selectModalResult.data.selected.length === 0) {
|
||||
erroredFiles.push({filePath: file.path, error: `no search results selected`});
|
||||
erroredFiles.push({ filePath: file.path, error: `no search results selected` });
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -507,7 +505,7 @@ export default class MediaDbPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async createErroredFilesReport(erroredFiles: { filePath: string, error: string }[]): Promise<void> {
|
||||
async createErroredFilesReport(erroredFiles: { filePath: string; error: string }[]): Promise<void> {
|
||||
const title = `bulk import error report ${dateTimeToString(new Date())}`;
|
||||
const filePath = `${this.settings.folder.replace(/\/$/, '')}/${title}.md`;
|
||||
|
||||
|
|
@ -528,9 +526,11 @@ export default class MediaDbPlugin extends Plugin {
|
|||
let newPropertyMappings: PropertyMappingModel[] = [];
|
||||
for (const defaultPropertyMappingModel of defaultSettings.propertyMappingModels) {
|
||||
let newPropertyMappingModel: PropertyMappingModel = loadedSettings.propertyMappingModels.find(x => x.type === defaultPropertyMappingModel.type);
|
||||
if (newPropertyMappingModel === undefined) { // if the propertyMappingModel exists in the default settings but not the loaded settings, add it
|
||||
if (newPropertyMappingModel === undefined) {
|
||||
// if the propertyMappingModel exists in the default settings but not the loaded settings, add it
|
||||
newPropertyMappings.push(defaultPropertyMappingModel);
|
||||
} else { // if the propertyMappingModel also exists in the loaded settings, add it from there
|
||||
} else {
|
||||
// if the propertyMappingModel also exists in the loaded settings, add it from there
|
||||
let newProperties: PropertyMapping[] = [];
|
||||
|
||||
for (const defaultProperty of defaultPropertyMappingModel.properties) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {ButtonComponent, Modal, Notice, Setting, TextComponent, ToggleComponent} from 'obsidian';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import { ButtonComponent, Modal, Notice, Setting, TextComponent, ToggleComponent } from 'obsidian';
|
||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../main';
|
||||
import {ADVANCED_SEARCH_MODAL_DEFAULT_OPTIONS, AdvancedSearchModalData, AdvancedSearchModalOptions} from '../utils/ModalHelper';
|
||||
import { ADVANCED_SEARCH_MODAL_DEFAULT_OPTIONS, AdvancedSearchModalData, AdvancedSearchModalOptions } from '../utils/ModalHelper';
|
||||
|
||||
export class MediaDbAdvancedSearchModal extends Modal {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -9,14 +9,13 @@ export class MediaDbAdvancedSearchModal extends Modal {
|
|||
query: string;
|
||||
isBusy: boolean;
|
||||
title: string;
|
||||
selectedApis: { name: string, selected: boolean }[];
|
||||
selectedApis: { name: string; selected: boolean }[];
|
||||
|
||||
searchBtn: ButtonComponent;
|
||||
|
||||
submitCallback?: (res: AdvancedSearchModalData) => void;
|
||||
closeCallback?: (err?: Error) => void;
|
||||
|
||||
|
||||
constructor(plugin: MediaDbPlugin, advancedSearchModalOptions: AdvancedSearchModalOptions) {
|
||||
advancedSearchModalOptions = Object.assign({}, ADVANCED_SEARCH_MODAL_DEFAULT_OPTIONS, advancedSearchModalOptions);
|
||||
super(plugin.app);
|
||||
|
|
@ -27,7 +26,7 @@ export class MediaDbAdvancedSearchModal extends Modal {
|
|||
this.query = advancedSearchModalOptions.prefilledSearchString;
|
||||
|
||||
for (const api of this.plugin.apiManager.apis) {
|
||||
this.selectedApis.push({name: api.apiName, selected: advancedSearchModalOptions.preselectedAPIs.contains(api.apiName)});
|
||||
this.selectedApis.push({ name: api.apiName, selected: advancedSearchModalOptions.preselectedAPIs.contains(api.apiName) });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -63,14 +62,14 @@ export class MediaDbAdvancedSearchModal extends Modal {
|
|||
this.searchBtn.setDisabled(false);
|
||||
this.searchBtn.setButtonText('Searching...');
|
||||
|
||||
this.submitCallback({query: this.query, apis: apis});
|
||||
this.submitCallback({ query: this.query, apis: apis });
|
||||
}
|
||||
}
|
||||
|
||||
onOpen() {
|
||||
const {contentEl} = this;
|
||||
const { contentEl } = this;
|
||||
|
||||
contentEl.createEl('h2', {text: this.title});
|
||||
contentEl.createEl('h2', { text: this.title });
|
||||
|
||||
const placeholder = 'Search by title';
|
||||
const searchComponent = new TextComponent(contentEl);
|
||||
|
|
@ -83,29 +82,29 @@ export class MediaDbAdvancedSearchModal extends Modal {
|
|||
contentEl.appendChild(searchComponent.inputEl);
|
||||
searchComponent.inputEl.focus();
|
||||
|
||||
contentEl.createDiv({cls: 'media-db-plugin-spacer'});
|
||||
contentEl.createEl('h3', {text: 'APIs to search'});
|
||||
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
||||
contentEl.createEl('h3', { text: 'APIs to search' });
|
||||
|
||||
// const apiToggleComponents: Component[] = [];
|
||||
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'});
|
||||
apiToggleTextWrapper.createEl('span', {text: api.apiName, cls: 'media-db-plugin-list-text'});
|
||||
apiToggleTextWrapper.createEl('small', {text: api.apiDescription, cls: 'media-db-plugin-list-text'});
|
||||
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('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);
|
||||
apiToggleComponent.setTooltip(api.apiName);
|
||||
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;
|
||||
});
|
||||
apiToggleComponentWrapper.appendChild(apiToggleComponent.toggleEl);
|
||||
}
|
||||
|
||||
contentEl.createDiv({cls: 'media-db-plugin-spacer'});
|
||||
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
||||
|
||||
new Setting(contentEl)
|
||||
.addButton(btn => {
|
||||
|
|
@ -126,8 +125,7 @@ export class MediaDbAdvancedSearchModal extends Modal {
|
|||
|
||||
onClose() {
|
||||
this.closeCallback();
|
||||
const {contentEl} = this;
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {App, ButtonComponent, DropdownComponent, Modal, Setting, TextComponent, ToggleComponent} from 'obsidian';
|
||||
import { App, ButtonComponent, DropdownComponent, Modal, Setting, TextComponent, ToggleComponent } from 'obsidian';
|
||||
import MediaDbPlugin from '../main';
|
||||
|
||||
export class MediaDbFolderImportModal extends Modal {
|
||||
|
|
@ -22,13 +22,13 @@ export class MediaDbFolderImportModal extends Modal {
|
|||
}
|
||||
|
||||
onOpen() {
|
||||
const {contentEl} = this;
|
||||
const { contentEl } = this;
|
||||
|
||||
contentEl.createEl('h2', {text: 'Import folder as Media DB entries'});
|
||||
contentEl.createEl('h2', { text: 'Import folder as Media DB entries' });
|
||||
|
||||
const apiSelectorWrapper = contentEl.createEl('div', {cls: 'media-db-plugin-list-wrapper'});
|
||||
const apiSelectorTextWrapper = apiSelectorWrapper.createEl('div', {cls: 'media-db-plugin-list-text-wrapper'});
|
||||
apiSelectorTextWrapper.createEl('span', {text: 'API to search', cls: 'media-db-plugin-list-text'});
|
||||
const apiSelectorWrapper = contentEl.createEl('div', { cls: 'media-db-plugin-list-wrapper' });
|
||||
const apiSelectorTextWrapper = apiSelectorWrapper.createEl('div', { cls: 'media-db-plugin-list-text-wrapper' });
|
||||
apiSelectorTextWrapper.createEl('span', { text: 'API to search', cls: 'media-db-plugin-list-text' });
|
||||
|
||||
const apiSelectorComponent = new DropdownComponent(apiSelectorWrapper);
|
||||
apiSelectorComponent.onChange((value: string) => {
|
||||
|
|
@ -39,41 +39,39 @@ export class MediaDbFolderImportModal extends Modal {
|
|||
}
|
||||
apiSelectorWrapper.appendChild(apiSelectorComponent.selectEl);
|
||||
|
||||
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
||||
contentEl.createEl('h3', { text: 'Append note content to Media DB entry.' });
|
||||
|
||||
contentEl.createDiv({cls: 'media-db-plugin-spacer'});
|
||||
contentEl.createEl('h3', {text: 'Append note content to Media DB entry.'});
|
||||
|
||||
const appendContentToggleElementWrapper = contentEl.createEl('div', {cls: 'media-db-plugin-list-wrapper'});
|
||||
const appendContentToggleTextWrapper = appendContentToggleElementWrapper.createEl('div', {cls: 'media-db-plugin-list-text-wrapper'});
|
||||
const appendContentToggleElementWrapper = contentEl.createEl('div', { cls: 'media-db-plugin-list-wrapper' });
|
||||
const appendContentToggleTextWrapper = appendContentToggleElementWrapper.createEl('div', { cls: 'media-db-plugin-list-text-wrapper' });
|
||||
appendContentToggleTextWrapper.createEl('span', {
|
||||
text: 'If this is enabled, the plugin will override metadata fields with the same name.',
|
||||
cls: 'media-db-plugin-list-text',
|
||||
});
|
||||
|
||||
const appendContentToggleComponentWrapper = appendContentToggleElementWrapper.createEl('div', {cls: 'media-db-plugin-list-toggle'});
|
||||
const appendContentToggleComponentWrapper = appendContentToggleElementWrapper.createEl('div', { cls: 'media-db-plugin-list-toggle' });
|
||||
|
||||
const appendContentToggle = new ToggleComponent(appendContentToggleElementWrapper);
|
||||
appendContentToggle.setValue(false);
|
||||
appendContentToggle.onChange(value => this.appendContent = value);
|
||||
appendContentToggle.onChange(value => (this.appendContent = value));
|
||||
appendContentToggleComponentWrapper.appendChild(appendContentToggle.toggleEl);
|
||||
|
||||
|
||||
contentEl.createDiv({cls: 'media-db-plugin-spacer'});
|
||||
contentEl.createEl('h3', {text: 'The name of the metadata field that should be used as the title to query.'});
|
||||
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
||||
contentEl.createEl('h3', { text: 'The name of the metadata field that should be used as the title to query.' });
|
||||
|
||||
const placeholder = 'title';
|
||||
const titleFieldNameComponent = new TextComponent(contentEl);
|
||||
titleFieldNameComponent.inputEl.style.width = '100%';
|
||||
titleFieldNameComponent.setPlaceholder(placeholder);
|
||||
titleFieldNameComponent.onChange(value => this.titleFieldName = value);
|
||||
titleFieldNameComponent.inputEl.addEventListener('keydown', (ke) => {
|
||||
titleFieldNameComponent.onChange(value => (this.titleFieldName = value));
|
||||
titleFieldNameComponent.inputEl.addEventListener('keydown', ke => {
|
||||
if (ke.key === 'Enter') {
|
||||
this.submit();
|
||||
}
|
||||
});
|
||||
contentEl.appendChild(titleFieldNameComponent.inputEl);
|
||||
|
||||
contentEl.createDiv({cls: 'media-db-plugin-spacer'});
|
||||
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
||||
|
||||
new Setting(contentEl)
|
||||
.addButton(btn => {
|
||||
|
|
@ -93,7 +91,7 @@ export class MediaDbFolderImportModal extends Modal {
|
|||
}
|
||||
|
||||
onClose() {
|
||||
const {contentEl} = this;
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {ButtonComponent, DropdownComponent, Modal, Notice, Setting, TextComponent} from 'obsidian';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import { ButtonComponent, DropdownComponent, Modal, Notice, Setting, TextComponent } from 'obsidian';
|
||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../main';
|
||||
import {ID_SEARCH_MODAL_DEFAULT_OPTIONS, IdSearchModalData, IdSearchModalOptions} from '../utils/ModalHelper';
|
||||
import { ID_SEARCH_MODAL_DEFAULT_OPTIONS, IdSearchModalData, IdSearchModalOptions } from '../utils/ModalHelper';
|
||||
|
||||
export class MediaDbIdSearchModal extends Modal {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -16,7 +16,6 @@ export class MediaDbIdSearchModal extends Modal {
|
|||
submitCallback?: (res: IdSearchModalData, err?: Error) => void;
|
||||
closeCallback?: (err?: Error) => void;
|
||||
|
||||
|
||||
constructor(plugin: MediaDbPlugin, idSearchModalOptions: IdSearchModalOptions) {
|
||||
idSearchModalOptions = Object.assign({}, ID_SEARCH_MODAL_DEFAULT_OPTIONS, idSearchModalOptions);
|
||||
super(plugin.app);
|
||||
|
|
@ -56,14 +55,14 @@ export class MediaDbIdSearchModal extends Modal {
|
|||
this.searchBtn.setDisabled(false);
|
||||
this.searchBtn.setButtonText('Searching...');
|
||||
|
||||
this.submitCallback({query: this.query, api: this.selectedApi});
|
||||
this.submitCallback({ query: this.query, api: this.selectedApi });
|
||||
}
|
||||
}
|
||||
|
||||
onOpen() {
|
||||
const {contentEl} = this;
|
||||
const { contentEl } = this;
|
||||
|
||||
contentEl.createEl('h2', {text: this.title});
|
||||
contentEl.createEl('h2', { text: this.title });
|
||||
|
||||
const placeholder = 'Search by id';
|
||||
const searchComponent = new TextComponent(contentEl);
|
||||
|
|
@ -75,11 +74,11 @@ export class MediaDbIdSearchModal extends Modal {
|
|||
contentEl.appendChild(searchComponent.inputEl);
|
||||
searchComponent.inputEl.focus();
|
||||
|
||||
contentEl.createDiv({cls: 'media-db-plugin-spacer'});
|
||||
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
||||
|
||||
const apiSelectorWrapper = contentEl.createEl('div', {cls: 'media-db-plugin-list-wrapper'});
|
||||
const apiSelectorTExtWrapper = apiSelectorWrapper.createEl('div', {cls: 'media-db-plugin-list-text-wrapper'});
|
||||
apiSelectorTExtWrapper.createEl('span', {text: 'API to search', cls: 'media-db-plugin-list-text'});
|
||||
const apiSelectorWrapper = contentEl.createEl('div', { cls: 'media-db-plugin-list-wrapper' });
|
||||
const apiSelectorTExtWrapper = apiSelectorWrapper.createEl('div', { cls: 'media-db-plugin-list-text-wrapper' });
|
||||
apiSelectorTExtWrapper.createEl('span', { text: 'API to search', cls: 'media-db-plugin-list-text' });
|
||||
|
||||
const apiSelectorComponent = new DropdownComponent(apiSelectorWrapper);
|
||||
apiSelectorComponent.onChange((value: string) => {
|
||||
|
|
@ -90,7 +89,7 @@ export class MediaDbIdSearchModal extends Modal {
|
|||
}
|
||||
apiSelectorWrapper.appendChild(apiSelectorComponent.selectEl);
|
||||
|
||||
contentEl.createDiv({cls: 'media-db-plugin-spacer'});
|
||||
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
||||
|
||||
new Setting(contentEl)
|
||||
.addButton(btn => {
|
||||
|
|
@ -111,8 +110,7 @@ export class MediaDbIdSearchModal extends Modal {
|
|||
|
||||
onClose() {
|
||||
this.closeCallback();
|
||||
const {contentEl} = this;
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import {ButtonComponent, MarkdownRenderer, Modal, Setting} from 'obsidian';
|
||||
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';
|
||||
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;
|
||||
|
|
@ -37,15 +37,15 @@ export class MediaDbPreviewModal extends Modal {
|
|||
}
|
||||
|
||||
async preview(): Promise<void> {
|
||||
let {contentEl} = this;
|
||||
let { contentEl } = this;
|
||||
contentEl.addClass('media-db-plugin-preview-modal');
|
||||
|
||||
contentEl.createEl('h2', {text: this.title});
|
||||
contentEl.createEl('h2', { text: this.title });
|
||||
|
||||
const previewWrapper = contentEl.createDiv({cls: 'media-db-plugin-preview-wrapper'});
|
||||
const previewWrapper = contentEl.createDiv({ cls: 'media-db-plugin-preview-wrapper' });
|
||||
|
||||
for (let result of this.elements) {
|
||||
previewWrapper.createEl('h3', {text: result.englishTitle});
|
||||
previewWrapper.createEl('h3', { text: result.englishTitle });
|
||||
const fileDiv = previewWrapper.createDiv();
|
||||
|
||||
let fileContent = await this.plugin.generateMediaDbNoteContents(result, this.createNoteOptions);
|
||||
|
|
@ -54,7 +54,7 @@ export class MediaDbPreviewModal extends Modal {
|
|||
MarkdownRenderer.renderMarkdown(fileContent, fileDiv, null, null);
|
||||
}
|
||||
|
||||
contentEl.createDiv({cls: 'media-db-plugin-spacer'});
|
||||
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
||||
|
||||
const bottomSettingRow = new Setting(contentEl);
|
||||
bottomSettingRow.addButton(btn => {
|
||||
|
|
@ -66,7 +66,7 @@ export class MediaDbPreviewModal extends Modal {
|
|||
bottomSettingRow.addButton(btn => {
|
||||
btn.setButtonText('Ok');
|
||||
btn.setCta();
|
||||
btn.onClick(() => this.submitCallback({confirmed: true}));
|
||||
btn.onClick(() => this.submitCallback({ confirmed: true }));
|
||||
btn.buttonEl.addClass('media-db-plugin-button');
|
||||
this.submitButton = btn;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import {ButtonComponent, Modal, Notice, Setting, TextComponent, ToggleComponent} from 'obsidian';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import { ButtonComponent, Modal, Notice, Setting, TextComponent, ToggleComponent } from 'obsidian';
|
||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../main';
|
||||
import {
|
||||
ADVANCED_SEARCH_MODAL_DEFAULT_OPTIONS,
|
||||
|
|
@ -9,8 +9,8 @@ import {
|
|||
SearchModalData,
|
||||
SearchModalOptions,
|
||||
} from '../utils/ModalHelper';
|
||||
import {MEDIA_TYPES} from '../utils/MediaTypeManager';
|
||||
import {unCamelCase} from '../utils/Utils';
|
||||
import { MEDIA_TYPES } from '../utils/MediaTypeManager';
|
||||
import { unCamelCase } from '../utils/Utils';
|
||||
|
||||
export class MediaDbSearchModal extends Modal {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -18,14 +18,13 @@ export class MediaDbSearchModal extends Modal {
|
|||
query: string;
|
||||
isBusy: boolean;
|
||||
title: string;
|
||||
selectedTypes: { name: string, selected: boolean }[];
|
||||
selectedTypes: { name: string; selected: boolean }[];
|
||||
|
||||
searchBtn: ButtonComponent;
|
||||
|
||||
submitCallback?: (res: SearchModalData) => void;
|
||||
closeCallback?: (err?: Error) => void;
|
||||
|
||||
|
||||
constructor(plugin: MediaDbPlugin, searchModalOptions: SearchModalOptions) {
|
||||
searchModalOptions = Object.assign({}, SEARCH_MODAL_DEFAULT_OPTIONS, searchModalOptions);
|
||||
super(plugin.app);
|
||||
|
|
@ -36,7 +35,7 @@ export class MediaDbSearchModal extends Modal {
|
|||
this.query = searchModalOptions.prefilledSearchString;
|
||||
|
||||
for (const mediaType of MEDIA_TYPES) {
|
||||
this.selectedTypes.push({name: mediaType, selected: searchModalOptions.preselectedTypes.contains(mediaType)});
|
||||
this.selectedTypes.push({ name: mediaType, selected: searchModalOptions.preselectedTypes.contains(mediaType) });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,14 +71,14 @@ export class MediaDbSearchModal extends Modal {
|
|||
this.searchBtn.setDisabled(false);
|
||||
this.searchBtn.setButtonText('Searching...');
|
||||
|
||||
this.submitCallback({query: this.query, types: types});
|
||||
this.submitCallback({ query: this.query, types: types });
|
||||
}
|
||||
}
|
||||
|
||||
onOpen() {
|
||||
const {contentEl} = this;
|
||||
const { contentEl } = this;
|
||||
|
||||
contentEl.createEl('h2', {text: this.title});
|
||||
contentEl.createEl('h2', { text: this.title });
|
||||
|
||||
const placeholder = 'Search by title';
|
||||
const searchComponent = new TextComponent(contentEl);
|
||||
|
|
@ -92,27 +91,27 @@ export class MediaDbSearchModal extends Modal {
|
|||
contentEl.appendChild(searchComponent.inputEl);
|
||||
searchComponent.inputEl.focus();
|
||||
|
||||
contentEl.createDiv({cls: 'media-db-plugin-spacer'});
|
||||
contentEl.createEl('h3', {text: 'APIs to search'});
|
||||
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
||||
contentEl.createEl('h3', { text: 'APIs to search' });
|
||||
|
||||
for (const mediaType of MEDIA_TYPES) {
|
||||
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'});
|
||||
apiToggleTextWrapper.createEl('span', {text: unCamelCase(mediaType), cls: 'media-db-plugin-list-text'});
|
||||
const apiToggleTextWrapper = apiToggleListElementWrapper.createEl('div', { cls: 'media-db-plugin-list-text-wrapper' });
|
||||
apiToggleTextWrapper.createEl('span', { text: unCamelCase(mediaType), 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);
|
||||
apiToggleComponent.setTooltip(unCamelCase(mediaType));
|
||||
apiToggleComponent.setValue(this.selectedTypes.find(x => x.name === mediaType).selected);
|
||||
apiToggleComponent.onChange((value) => {
|
||||
apiToggleComponent.onChange(value => {
|
||||
this.selectedTypes.find(x => x.name === mediaType).selected = value;
|
||||
});
|
||||
apiToggleComponentWrapper.appendChild(apiToggleComponent.toggleEl);
|
||||
}
|
||||
|
||||
contentEl.createDiv({cls: 'media-db-plugin-spacer'});
|
||||
contentEl.createDiv({ cls: 'media-db-plugin-spacer' });
|
||||
|
||||
new Setting(contentEl)
|
||||
.addButton(btn => {
|
||||
|
|
@ -133,8 +132,7 @@ export class MediaDbSearchModal extends Modal {
|
|||
|
||||
onClose() {
|
||||
this.closeCallback();
|
||||
const {contentEl} = this;
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../main';
|
||||
import {SelectModal} from './SelectModal';
|
||||
import {SELECT_MODAL_OPTIONS_DEFAULT, SelectModalData, SelectModalOptions} from '../utils/ModalHelper';
|
||||
import { SelectModal } from './SelectModal';
|
||||
import { SELECT_MODAL_OPTIONS_DEFAULT, SelectModalData, SelectModalOptions } from '../utils/ModalHelper';
|
||||
|
||||
export class MediaDbSearchResultModal extends SelectModal<MediaTypeModel> {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -13,7 +13,6 @@ export class MediaDbSearchResultModal extends SelectModal<MediaTypeModel> {
|
|||
closeCallback: (err?: Error) => void;
|
||||
skipCallback: () => void;
|
||||
|
||||
|
||||
constructor(plugin: MediaDbPlugin, selectModalOptions: SelectModalOptions) {
|
||||
selectModalOptions = Object.assign({}, SELECT_MODAL_OPTIONS_DEFAULT, selectModalOptions);
|
||||
super(plugin.app, selectModalOptions.elements, selectModalOptions.multiSelect);
|
||||
|
|
@ -42,9 +41,9 @@ export class MediaDbSearchResultModal extends SelectModal<MediaTypeModel> {
|
|||
|
||||
// Renders each suggestion item.
|
||||
renderElement(item: MediaTypeModel, el: HTMLElement) {
|
||||
el.createEl('div', {text: this.plugin.mediaTypeManager.getFileName(item)});
|
||||
el.createEl('small', {text: `${item.getSummary()}\n`});
|
||||
el.createEl('small', {text: `${item.type.toUpperCase() + (item.subType ? ` (${item.subType})` : '')} from ${item.dataSource}`});
|
||||
el.createEl('div', { text: this.plugin.mediaTypeManager.getFileName(item) });
|
||||
el.createEl('small', { text: `${item.getSummary()}\n` });
|
||||
el.createEl('small', { text: `${item.type.toUpperCase() + (item.subType ? ` (${item.subType})` : '')} from ${item.dataSource}` });
|
||||
}
|
||||
|
||||
// Perform action on the selected suggestion.
|
||||
|
|
@ -52,7 +51,7 @@ export class MediaDbSearchResultModal extends SelectModal<MediaTypeModel> {
|
|||
if (!this.busy) {
|
||||
this.busy = true;
|
||||
this.submitButton.setButtonText('Creating entry...');
|
||||
this.submitCallback({selected: this.selectModalElements.filter(x => x.isActive()).map(x => x.value)});
|
||||
this.submitCallback({ selected: this.selectModalElements.filter(x => x.isActive()).map(x => x.value) });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +61,6 @@ export class MediaDbSearchResultModal extends SelectModal<MediaTypeModel> {
|
|||
}
|
||||
|
||||
onClose() {
|
||||
|
||||
this.closeCallback();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import {App, ButtonComponent, Modal, Setting} from 'obsidian';
|
||||
import {SelectModalElement} from './SelectModalElement';
|
||||
import {mod} from '../utils/Utils';
|
||||
import { App, ButtonComponent, Modal, Setting } from 'obsidian';
|
||||
import { SelectModalElement } from './SelectModalElement';
|
||||
import { mod } from '../utils/Utils';
|
||||
|
||||
export abstract class SelectModal<T> extends Modal {
|
||||
allowMultiSelect: boolean;
|
||||
|
|
@ -17,7 +17,6 @@ export abstract class SelectModal<T> extends Modal {
|
|||
elements: T[];
|
||||
selectModalElements: SelectModalElement<T>[];
|
||||
|
||||
|
||||
protected constructor(app: App, elements: T[], allowMultiSelect: boolean = true) {
|
||||
super(app);
|
||||
this.allowMultiSelect = allowMultiSelect;
|
||||
|
|
@ -34,18 +33,18 @@ export abstract class SelectModal<T> extends Modal {
|
|||
this.elements = elements;
|
||||
this.selectModalElements = [];
|
||||
|
||||
this.scope.register([], 'ArrowUp', (evt) => {
|
||||
this.scope.register([], 'ArrowUp', evt => {
|
||||
this.highlightUp();
|
||||
evt.preventDefault();
|
||||
});
|
||||
this.scope.register([], 'ArrowDown', (evt) => {
|
||||
this.scope.register([], 'ArrowDown', evt => {
|
||||
this.highlightDown();
|
||||
evt.preventDefault();
|
||||
});
|
||||
this.scope.register([], 'ArrowRight', () => {
|
||||
this.activateHighlighted();
|
||||
});
|
||||
this.scope.register([], ' ', (evt) => {
|
||||
this.scope.register([], ' ', evt => {
|
||||
if (this.elementWrapper && this.elementWrapper === document.activeElement) {
|
||||
this.activateHighlighted();
|
||||
evt.preventDefault();
|
||||
|
|
@ -77,13 +76,13 @@ export abstract class SelectModal<T> extends Modal {
|
|||
}
|
||||
|
||||
async onOpen() {
|
||||
const {contentEl, titleEl} = this;
|
||||
const { contentEl, titleEl } = this;
|
||||
|
||||
titleEl.createEl('h2', {text: this.title});
|
||||
titleEl.createEl('h2', { text: this.title });
|
||||
contentEl.addClass('media-db-plugin-select-modal');
|
||||
contentEl.createEl('p', {text: this.description});
|
||||
contentEl.createEl('p', { text: this.description });
|
||||
|
||||
this.elementWrapper = contentEl.createDiv({cls: 'media-db-plugin-select-wrapper'});
|
||||
this.elementWrapper = contentEl.createDiv({ cls: 'media-db-plugin-select-wrapper' });
|
||||
this.elementWrapper.tabIndex = 0;
|
||||
|
||||
let i = 0;
|
||||
|
|
@ -171,5 +170,4 @@ export abstract class SelectModal<T> extends Modal {
|
|||
|
||||
return this.selectModalElements.filter(x => x.id === nextId).first();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {SelectModal} from './SelectModal';
|
||||
import { SelectModal } from './SelectModal';
|
||||
|
||||
export class SelectModalElement<T> {
|
||||
selectModal: SelectModal<T>;
|
||||
|
|
@ -21,7 +21,7 @@ export class SelectModalElement<T> {
|
|||
this.activeClass = 'media-db-plugin-select-element-selected';
|
||||
this.hoverClass = 'media-db-plugin-select-element-hover';
|
||||
|
||||
this.element = parentElement.createDiv({cls: this.cssClass});
|
||||
this.element = parentElement.createDiv({ cls: this.cssClass });
|
||||
this.element.id = this.getHTMLId();
|
||||
this.element.on('click', '#' + this.getHTMLId(), () => {
|
||||
this.setActive(!this.active);
|
||||
|
|
@ -83,5 +83,4 @@ export class SelectModalElement<T> {
|
|||
this.element.removeClass(cssClass);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import {MediaTypeModel} from './MediaTypeModel';
|
||||
import {mediaDbTag, migrateObject} from '../utils/Utils';
|
||||
import {MediaType} from '../utils/MediaType';
|
||||
|
||||
import { MediaTypeModel } from './MediaTypeModel';
|
||||
import { mediaDbTag, migrateObject } from '../utils/Utils';
|
||||
import { MediaType } from '../utils/MediaType';
|
||||
|
||||
export class BoardGameModel extends MediaTypeModel {
|
||||
genres: string[];
|
||||
|
|
@ -15,7 +14,6 @@ export class BoardGameModel extends MediaTypeModel {
|
|||
personalRating: number;
|
||||
};
|
||||
|
||||
|
||||
constructor(obj: any = {}) {
|
||||
super();
|
||||
|
||||
|
|
@ -48,5 +46,4 @@ export class BoardGameModel extends MediaTypeModel {
|
|||
getSummary(): string {
|
||||
return this.englishTitle + ' (' + this.year + ')';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import {MediaTypeModel} from './MediaTypeModel';
|
||||
import {mediaDbTag, migrateObject} from '../utils/Utils';
|
||||
import {MediaType} from '../utils/MediaType';
|
||||
|
||||
import { MediaTypeModel } from './MediaTypeModel';
|
||||
import { mediaDbTag, migrateObject } from '../utils/Utils';
|
||||
import { MediaType } from '../utils/MediaType';
|
||||
|
||||
export class GameModel extends MediaTypeModel {
|
||||
genres: string[];
|
||||
|
|
@ -16,7 +15,6 @@ export class GameModel extends MediaTypeModel {
|
|||
personalRating: number;
|
||||
};
|
||||
|
||||
|
||||
constructor(obj: any = {}) {
|
||||
super();
|
||||
|
||||
|
|
@ -50,5 +48,4 @@ export class GameModel extends MediaTypeModel {
|
|||
getSummary(): string {
|
||||
return this.englishTitle + ' (' + this.year + ')';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {MediaType} from '../utils/MediaType';
|
||||
import { MediaType } from '../utils/MediaType';
|
||||
|
||||
export abstract class MediaTypeModel {
|
||||
type: string;
|
||||
|
|
@ -12,7 +12,6 @@ export abstract class MediaTypeModel {
|
|||
|
||||
userData: object;
|
||||
|
||||
|
||||
protected constructor() {
|
||||
this.type = undefined;
|
||||
this.subType = undefined;
|
||||
|
|
@ -33,7 +32,7 @@ export abstract class MediaTypeModel {
|
|||
abstract getTags(): string[];
|
||||
|
||||
toMetaDataObject(): object {
|
||||
return {...this.getWithOutUserData(), ...this.userData, tags: this.getTags().join('/')};
|
||||
return { ...this.getWithOutUserData(), ...this.userData, tags: this.getTags().join('/') };
|
||||
}
|
||||
|
||||
getWithOutUserData(): object {
|
||||
|
|
@ -41,5 +40,4 @@ export abstract class MediaTypeModel {
|
|||
delete copy.userData;
|
||||
return copy;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import {MediaTypeModel} from './MediaTypeModel';
|
||||
import {mediaDbTag, migrateObject} from '../utils/Utils';
|
||||
import {MediaType} from '../utils/MediaType';
|
||||
|
||||
import { MediaTypeModel } from './MediaTypeModel';
|
||||
import { mediaDbTag, migrateObject } from '../utils/Utils';
|
||||
import { MediaType } from '../utils/MediaType';
|
||||
|
||||
export class MovieModel extends MediaTypeModel {
|
||||
genres: string[];
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import {MediaTypeModel} from './MediaTypeModel';
|
||||
import {mediaDbTag, migrateObject} from '../utils/Utils';
|
||||
import {MediaType} from '../utils/MediaType';
|
||||
|
||||
import { MediaTypeModel } from './MediaTypeModel';
|
||||
import { mediaDbTag, migrateObject } from '../utils/Utils';
|
||||
import { MediaType } from '../utils/MediaType';
|
||||
|
||||
export class MusicReleaseModel extends MediaTypeModel {
|
||||
type: string;
|
||||
|
|
@ -50,8 +49,7 @@ export class MusicReleaseModel extends MediaTypeModel {
|
|||
|
||||
getSummary(): string {
|
||||
let summary = this.title + ' (' + this.year + ')';
|
||||
if (this.artists.length > 0)
|
||||
summary += ' - ' + this.artists.join(', ');
|
||||
if (this.artists.length > 0) summary += ' - ' + this.artists.join(', ');
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import {MediaTypeModel} from './MediaTypeModel';
|
||||
import {mediaDbTag, migrateObject} from '../utils/Utils';
|
||||
import {MediaType} from '../utils/MediaType';
|
||||
|
||||
import { MediaTypeModel } from './MediaTypeModel';
|
||||
import { mediaDbTag, migrateObject } from '../utils/Utils';
|
||||
import { MediaType } from '../utils/MediaType';
|
||||
|
||||
export class SeriesModel extends MediaTypeModel {
|
||||
type: string;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import {MediaTypeModel} from './MediaTypeModel';
|
||||
import {mediaDbTag, migrateObject} from '../utils/Utils';
|
||||
import {MediaType} from '../utils/MediaType';
|
||||
|
||||
import { MediaTypeModel } from './MediaTypeModel';
|
||||
import { mediaDbTag, migrateObject } from '../utils/Utils';
|
||||
import { MediaType } from '../utils/MediaType';
|
||||
|
||||
export class WikiModel extends MediaTypeModel {
|
||||
type: string;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import {PropertyMappingOption} from './PropertyMapping';
|
||||
import {MEDIA_TYPES} from '../utils/MediaTypeManager';
|
||||
import { PropertyMappingOption } from './PropertyMapping';
|
||||
import { MEDIA_TYPES } from '../utils/MediaTypeManager';
|
||||
import MediaDbPlugin from '../main';
|
||||
|
||||
export class PropertyMapper {
|
||||
|
|
@ -40,7 +40,6 @@ export class PropertyMapper {
|
|||
// @ts-ignore
|
||||
newObj[propertyMapping.newProperty] = value;
|
||||
} else if (propertyMapping.mapping === PropertyMappingOption.Remove) {
|
||||
|
||||
} else if (propertyMapping.mapping === PropertyMappingOption.Default) {
|
||||
// @ts-ignore
|
||||
newObj[key] = value;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import {containsOnlyLettersAndUnderscores, PropertyMappingNameConflictError, PropertyMappingValidationError} from '../utils/Utils';
|
||||
import {MediaType} from '../utils/MediaType';
|
||||
import { containsOnlyLettersAndUnderscores, PropertyMappingNameConflictError, PropertyMappingValidationError } from '../utils/Utils';
|
||||
import { MediaType } from '../utils/MediaType';
|
||||
|
||||
export enum PropertyMappingOption {
|
||||
Default = 'default',
|
||||
|
|
@ -18,7 +18,7 @@ export class PropertyMappingModel {
|
|||
this.properties = properties ?? [];
|
||||
}
|
||||
|
||||
validate(): { res: boolean, err?: Error } {
|
||||
validate(): { res: boolean; err?: Error } {
|
||||
console.debug(`MDB | validated property mappings for ${this.type}`);
|
||||
|
||||
// check properties
|
||||
|
|
@ -43,7 +43,9 @@ export class PropertyMappingModel {
|
|||
// two or more properties are mapped to the same property
|
||||
return {
|
||||
res: false,
|
||||
err: new PropertyMappingNameConflictError(`Multiple remapped properties (${propertiesWithSameTarget.map(x => x.toString()).toString()}) may not share the same name.`),
|
||||
err: new PropertyMappingNameConflictError(
|
||||
`Multiple remapped properties (${propertiesWithSameTarget.map(x => x.toString()).toString()}) may not share the same name.`
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -93,7 +95,7 @@ export class PropertyMapping {
|
|||
this.locked = locked ?? false;
|
||||
}
|
||||
|
||||
validate(): { res: boolean, err?: Error } {
|
||||
validate(): { res: boolean; err?: Error } {
|
||||
// locked property may only be default
|
||||
if (this.locked) {
|
||||
if (this.mapping === PropertyMappingOption.Remove) {
|
||||
|
|
@ -111,10 +113,10 @@ export class PropertyMapping {
|
|||
}
|
||||
|
||||
if (this.mapping === PropertyMappingOption.Default) {
|
||||
return {res: true};
|
||||
return { res: true };
|
||||
}
|
||||
if (this.mapping === PropertyMappingOption.Remove) {
|
||||
return {res: true};
|
||||
return { res: true };
|
||||
}
|
||||
|
||||
if (!this.property || !containsOnlyLettersAndUnderscores(this.property)) {
|
||||
|
|
|
|||
|
|
@ -1,45 +1,42 @@
|
|||
import {App, Notice, PluginSettingTab, Setting} from 'obsidian';
|
||||
import { App, Notice, PluginSettingTab, Setting } from 'obsidian';
|
||||
|
||||
import MediaDbPlugin from '../main';
|
||||
import {FolderSuggest} from './suggesters/FolderSuggest';
|
||||
import {FileSuggest} from './suggesters/FileSuggest';
|
||||
import { FolderSuggest } from './suggesters/FolderSuggest';
|
||||
import { FileSuggest } from './suggesters/FileSuggest';
|
||||
import PropertyMappingModelsComponent from './PropertyMappingModelsComponent.svelte';
|
||||
import {PropertyMapping, PropertyMappingModel, PropertyMappingOption} from './PropertyMapping';
|
||||
import {MEDIA_TYPES} from '../utils/MediaTypeManager';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
|
||||
import { PropertyMapping, PropertyMappingModel, PropertyMappingOption } from './PropertyMapping';
|
||||
import { MEDIA_TYPES } from '../utils/MediaTypeManager';
|
||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||
|
||||
export interface MediaDbPluginSettings {
|
||||
folder: string,
|
||||
OMDbKey: string,
|
||||
sfwFilter: boolean,
|
||||
folder: string;
|
||||
OMDbKey: string;
|
||||
sfwFilter: boolean;
|
||||
useCustomYamlStringifier: boolean;
|
||||
templates: boolean,
|
||||
templates: boolean;
|
||||
|
||||
movieTemplate: string;
|
||||
seriesTemplate: string;
|
||||
gameTemplate: string;
|
||||
wikiTemplate: string;
|
||||
musicReleaseTemplate: string;
|
||||
boardgameTemplate: string;
|
||||
|
||||
movieTemplate: string,
|
||||
seriesTemplate: string,
|
||||
gameTemplate: string,
|
||||
wikiTemplate: string,
|
||||
musicReleaseTemplate: string,
|
||||
boardgameTemplate: string,
|
||||
movieFileNameTemplate: string;
|
||||
seriesFileNameTemplate: string;
|
||||
gameFileNameTemplate: string;
|
||||
wikiFileNameTemplate: string;
|
||||
musicReleaseFileNameTemplate: string;
|
||||
boardgameFileNameTemplate: string;
|
||||
|
||||
movieFileNameTemplate: string,
|
||||
seriesFileNameTemplate: string,
|
||||
gameFileNameTemplate: string,
|
||||
wikiFileNameTemplate: string,
|
||||
musicReleaseFileNameTemplate: string,
|
||||
boardgameFileNameTemplate: string,
|
||||
|
||||
moviePropertyConversionRules: string,
|
||||
seriesPropertyConversionRules: string,
|
||||
gamePropertyConversionRules: string,
|
||||
wikiPropertyConversionRules: string,
|
||||
musicReleasePropertyConversionRules: string,
|
||||
boardgamePropertyConversionRules: string,
|
||||
|
||||
propertyMappingModels: PropertyMappingModel[],
|
||||
moviePropertyConversionRules: string;
|
||||
seriesPropertyConversionRules: string;
|
||||
gamePropertyConversionRules: string;
|
||||
wikiPropertyConversionRules: string;
|
||||
musicReleasePropertyConversionRules: string;
|
||||
boardgamePropertyConversionRules: string;
|
||||
|
||||
propertyMappingModels: PropertyMappingModel[];
|
||||
}
|
||||
|
||||
const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||
|
|
@ -89,9 +86,7 @@ export function getDefaultSettings(plugin: MediaDbPlugin): MediaDbPluginSettings
|
|||
const propertyMappingModel: PropertyMappingModel = new PropertyMappingModel(mediaType);
|
||||
|
||||
for (const key of Object.keys(metadataObj)) {
|
||||
propertyMappingModel.properties.push(
|
||||
new PropertyMapping(key, '', PropertyMappingOption.Default, lockedPropertyMappings.contains(key)),
|
||||
);
|
||||
propertyMappingModel.properties.push(new PropertyMapping(key, '', PropertyMappingOption.Default, lockedPropertyMappings.contains(key)));
|
||||
}
|
||||
|
||||
propertyMappingModels.push(propertyMappingModel);
|
||||
|
|
@ -110,11 +105,11 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
}
|
||||
|
||||
display(): void {
|
||||
const {containerEl} = this;
|
||||
const { containerEl } = this;
|
||||
|
||||
containerEl.empty();
|
||||
|
||||
containerEl.createEl('h2', {text: 'Media DB Plugin Settings'});
|
||||
containerEl.createEl('h2', { text: 'Media DB Plugin Settings' });
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('New file location')
|
||||
|
|
@ -145,37 +140,33 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
.setName('SFW filter')
|
||||
.setDesc('Only shows SFW results for APIs that offer filtering.')
|
||||
.addToggle(cb => {
|
||||
cb.setValue(this.plugin.settings.sfwFilter)
|
||||
.onChange(data => {
|
||||
this.plugin.settings.sfwFilter = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
cb.setValue(this.plugin.settings.sfwFilter).onChange(data => {
|
||||
this.plugin.settings.sfwFilter = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('YAML formatter')
|
||||
.setDesc('Add optional quotation marks around strings in the metadata block.')
|
||||
.addToggle(cb => {
|
||||
cb.setValue(this.plugin.settings.useCustomYamlStringifier)
|
||||
.onChange(data => {
|
||||
this.plugin.settings.useCustomYamlStringifier = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
cb.setValue(this.plugin.settings.useCustomYamlStringifier).onChange(data => {
|
||||
this.plugin.settings.useCustomYamlStringifier = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Resolve {{ tags }} in templates')
|
||||
.setDesc('Whether to resolve {{ tags }} in templates. The spaces inside the curly braces are important.')
|
||||
.addToggle(cb => {
|
||||
cb.setValue(this.plugin.settings.templates)
|
||||
.onChange(data => {
|
||||
this.plugin.settings.templates = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
cb.setValue(this.plugin.settings.templates).onChange(data => {
|
||||
this.plugin.settings.templates = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
containerEl.createEl('h3', {text: 'Template Settings'});
|
||||
containerEl.createEl('h3', { text: 'Template Settings' });
|
||||
// region templates
|
||||
new Setting(containerEl)
|
||||
.setName('Movie template')
|
||||
|
|
@ -256,7 +247,7 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
});
|
||||
// endregion
|
||||
|
||||
containerEl.createEl('h3', {text: 'File Name Settings'});
|
||||
containerEl.createEl('h3', { text: 'File Name Settings' });
|
||||
// region file name templates
|
||||
new Setting(containerEl)
|
||||
.setName('Movie file name template')
|
||||
|
|
@ -333,7 +324,7 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
|
||||
// region Property Mappings
|
||||
|
||||
containerEl.createEl('h3', {text: 'Property Mappings'});
|
||||
containerEl.createEl('h3', { text: 'Property Mappings' });
|
||||
|
||||
let propertyMappingExplanation = containerEl.createEl('div');
|
||||
propertyMappingExplanation.innerHTML = `
|
||||
|
|
@ -350,7 +341,6 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
Don't forget to save your changes using the save button for each individual category.
|
||||
</p>`;
|
||||
|
||||
|
||||
new PropertyMappingModelsComponent({
|
||||
target: this.containerEl,
|
||||
props: {
|
||||
|
|
@ -374,7 +364,5 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
});
|
||||
|
||||
// endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import {TextInputSuggest} from './Suggest';
|
||||
import {TAbstractFile, TFile} from 'obsidian';
|
||||
import { TextInputSuggest } from './Suggest';
|
||||
import { TAbstractFile, TFile } from 'obsidian';
|
||||
|
||||
export class FileSuggest extends TextInputSuggest<TFile> {
|
||||
getSuggestions(inputStr: string): TFile[] {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes
|
||||
|
||||
import {TAbstractFile, TFolder} from 'obsidian';
|
||||
import {TextInputSuggest} from './Suggest';
|
||||
import { TAbstractFile, TFolder } from 'obsidian';
|
||||
import { TextInputSuggest } from './Suggest';
|
||||
|
||||
export class FolderSuggest extends TextInputSuggest<TFolder> {
|
||||
getSuggestions(inputStr: string): TFolder[] {
|
||||
|
|
@ -10,10 +10,7 @@ export class FolderSuggest extends TextInputSuggest<TFolder> {
|
|||
const lowerCaseInputStr = inputStr.toLowerCase();
|
||||
|
||||
abstractFiles.forEach((folder: TAbstractFile) => {
|
||||
if (
|
||||
folder instanceof TFolder &&
|
||||
folder.path.toLowerCase().contains(lowerCaseInputStr)
|
||||
) {
|
||||
if (folder instanceof TFolder && folder.path.toLowerCase().contains(lowerCaseInputStr)) {
|
||||
folders.push(folder);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes
|
||||
|
||||
import {App, ISuggestOwner, Scope} from 'obsidian';
|
||||
import {createPopper, Instance as PopperInstance} from '@popperjs/core';
|
||||
import {wrapAround} from 'src/utils/Utils';
|
||||
import { App, ISuggestOwner, Scope } from 'obsidian';
|
||||
import { createPopper, Instance as PopperInstance } from '@popperjs/core';
|
||||
import { wrapAround } from 'src/utils/Utils';
|
||||
|
||||
export class Suggest<T> {
|
||||
private owner: ISuggestOwner<T>;
|
||||
|
|
@ -16,27 +16,23 @@ export class Suggest<T> {
|
|||
this.containerEl = containerEl;
|
||||
|
||||
containerEl.on('click', '.suggestion-item', this.onSuggestionClick.bind(this));
|
||||
containerEl.on(
|
||||
'mousemove',
|
||||
'.suggestion-item',
|
||||
this.onSuggestionMouseover.bind(this),
|
||||
);
|
||||
containerEl.on('mousemove', '.suggestion-item', this.onSuggestionMouseover.bind(this));
|
||||
|
||||
scope.register([], 'ArrowUp', (event) => {
|
||||
scope.register([], 'ArrowUp', event => {
|
||||
if (!event.isComposing) {
|
||||
this.setSelectedItem(this.selectedItem - 1, true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
scope.register([], 'ArrowDown', (event) => {
|
||||
scope.register([], 'ArrowDown', event => {
|
||||
if (!event.isComposing) {
|
||||
this.setSelectedItem(this.selectedItem + 1, true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
scope.register([], 'Enter', (event) => {
|
||||
scope.register([], 'Enter', event => {
|
||||
if (!event.isComposing) {
|
||||
this.useSelectedItem(event);
|
||||
return false;
|
||||
|
|
@ -61,7 +57,7 @@ export class Suggest<T> {
|
|||
this.containerEl.empty();
|
||||
const suggestionEls: HTMLDivElement[] = [];
|
||||
|
||||
values.forEach((value) => {
|
||||
values.forEach(value => {
|
||||
const suggestionEl = this.containerEl.createDiv('suggestion-item');
|
||||
this.owner.renderSuggestion(value, suggestionEl);
|
||||
suggestionEls.push(suggestionEl);
|
||||
|
|
@ -145,7 +141,7 @@ export abstract class TextInputSuggest<T> implements ISuggestOwner<T> {
|
|||
{
|
||||
name: 'sameWidth',
|
||||
enabled: true,
|
||||
fn: ({state, instance}) => {
|
||||
fn: ({ state, instance }) => {
|
||||
// Note: positioning needs to be calculated twice -
|
||||
// first pass - positioning it according to the width of the popper
|
||||
// second pass - position it with the width bound to the reference element
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import fetchMock, {enableFetchMocks} from 'jest-fetch-mock';
|
||||
import {MediaDbPluginSettings} from 'src/settings/Settings';
|
||||
import {LocGovAPI} from '../api/apis/LocGovAPI';
|
||||
import {MALAPI} from '../api/apis/MALAPI';
|
||||
import {MusicBrainzAPI} from '../api/apis/MusicBrainzAPI';
|
||||
import {OMDbAPI} from '../api/apis/OMDbAPI';
|
||||
import {SteamAPI} from '../api/apis/SteamAPI';
|
||||
import {WikipediaAPI} from '../api/apis/WikipediaAPI';
|
||||
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
|
||||
import { MediaDbPluginSettings } from 'src/settings/Settings';
|
||||
import { LocGovAPI } from '../api/apis/LocGovAPI';
|
||||
import { MALAPI } from '../api/apis/MALAPI';
|
||||
import { MusicBrainzAPI } from '../api/apis/MusicBrainzAPI';
|
||||
import { OMDbAPI } from '../api/apis/OMDbAPI';
|
||||
import { SteamAPI } from '../api/apis/SteamAPI';
|
||||
import { WikipediaAPI } from '../api/apis/WikipediaAPI';
|
||||
import MediaDbPlugin from '../main';
|
||||
import {setMALResponseMock, setMusicBrainzResponseMock, setOMDbResponseMock, setSteamResponseMock, setWikipediaResponseMock} from './mockHelpers';
|
||||
import { setMALResponseMock, setMusicBrainzResponseMock, setOMDbResponseMock, setSteamResponseMock, setWikipediaResponseMock } from './mockHelpers';
|
||||
import MALMockMovie from './ResponseMocks/MALMockMovie.json';
|
||||
import MusicBrainzResponseMock from './ResponseMocks/MusicBrainzMockResponse.json';
|
||||
import OMDBMockMovie from './ResponseMocks/OMDBMockResponse.json';
|
||||
|
|
@ -17,94 +17,88 @@ import WikipediaMockResponse from './ResponseMocks/WikipediaMockResponse.json';
|
|||
enableFetchMocks();
|
||||
export let apiMock: OMDbAPI | MALAPI | LocGovAPI | MusicBrainzAPI | SteamAPI | WikipediaAPI;
|
||||
|
||||
describe.each(
|
||||
[
|
||||
{name: OMDbAPI},
|
||||
{name: MALAPI},
|
||||
{name: LocGovAPI},
|
||||
{name: MusicBrainzAPI},
|
||||
{name: SteamAPI},
|
||||
{name: WikipediaAPI},
|
||||
],
|
||||
)('$name.name', ({name: parameterizedApi}) => {
|
||||
beforeAll(() => {
|
||||
let settingsMock: MediaDbPluginSettings = {} as MediaDbPluginSettings;
|
||||
let pluginMock = {} as MediaDbPlugin;
|
||||
pluginMock.settings = settingsMock;
|
||||
// TODO: add fake API key?
|
||||
apiMock = new parameterizedApi(pluginMock);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fetchMock.resetMocks();
|
||||
});
|
||||
|
||||
test('searchByTitle behavior when API returns garbage data', async () => {
|
||||
const garbageResponse = JSON.stringify({
|
||||
data: 'string',
|
||||
describe.each([{ name: OMDbAPI }, { name: MALAPI }, { name: LocGovAPI }, { name: MusicBrainzAPI }, { name: SteamAPI }, { name: WikipediaAPI }])(
|
||||
'$name.name',
|
||||
({ name: parameterizedApi }) => {
|
||||
beforeAll(() => {
|
||||
let settingsMock: MediaDbPluginSettings = {} as MediaDbPluginSettings;
|
||||
let pluginMock = {} as MediaDbPlugin;
|
||||
pluginMock.settings = settingsMock;
|
||||
// TODO: add fake API key?
|
||||
apiMock = new parameterizedApi(pluginMock);
|
||||
});
|
||||
fetchMock.mockResponseOnce(garbageResponse);
|
||||
await expect(apiMock.searchByTitle('sample')).resolves.toEqual([]);
|
||||
// }
|
||||
expect(fetch).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('searchByTitle behavior when requestUrl/fetch returns 401', async () => {
|
||||
let sampleResponse = {
|
||||
data: 'string',
|
||||
};
|
||||
fetchMock.mockResponse(JSON.stringify(sampleResponse), {status: 401});
|
||||
// TODO: Check API name and fix message
|
||||
// TODO: Externalize string
|
||||
await expect(apiMock.searchByTitle('sample')).rejects.toThrow(`MDB | Received status code ${401} from an API.`);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
beforeEach(() => {
|
||||
fetchMock.resetMocks();
|
||||
});
|
||||
|
||||
test('searchByTitle behavior when requestUrl/fetch returns 403', async () => {
|
||||
let sampleResponse = {
|
||||
data: 'string',
|
||||
};
|
||||
fetchMock.mockResponse(JSON.stringify(sampleResponse), {status: 403});
|
||||
// TODO: Check API name and fix message
|
||||
// TODO: Externalize string/import?
|
||||
await expect(apiMock.searchByTitle('sample')).rejects.toThrow(`MDB | Received status code ${403} from an API.`);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
test('searchByTitle behavior when API returns garbage data', async () => {
|
||||
const garbageResponse = JSON.stringify({
|
||||
data: 'string',
|
||||
});
|
||||
fetchMock.mockResponseOnce(garbageResponse);
|
||||
await expect(apiMock.searchByTitle('sample')).resolves.toEqual([]);
|
||||
// }
|
||||
expect(fetch).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('searchByTitle behavior when requestUrl/fetch returns 200', async () => {
|
||||
let sampleResponse;
|
||||
let ret;
|
||||
switch (parameterizedApi) {
|
||||
case OMDbAPI:
|
||||
ret = setOMDbResponseMock();
|
||||
sampleResponse = OMDBMockMovie;
|
||||
break;
|
||||
case WikipediaAPI:
|
||||
ret = setWikipediaResponseMock();
|
||||
sampleResponse = WikipediaMockResponse;
|
||||
break;
|
||||
case MALAPI:
|
||||
// TODO: MAL needs more tests for different types of content
|
||||
ret = setMALResponseMock();
|
||||
sampleResponse = MALMockMovie;
|
||||
case LocGovAPI:
|
||||
// TODO: Add soon
|
||||
break;
|
||||
case SteamAPI:
|
||||
sampleResponse = SteamAPIResponseMock;
|
||||
ret = setSteamResponseMock();
|
||||
break;
|
||||
case MusicBrainzAPI:
|
||||
sampleResponse = MusicBrainzResponseMock;
|
||||
ret = setMusicBrainzResponseMock();
|
||||
break;
|
||||
default:
|
||||
throw Error();
|
||||
}
|
||||
fetchMock.mockResponse(JSON.stringify(sampleResponse), {status: 200});
|
||||
// TODO: Check API name and fix message
|
||||
// TODO: Externalize string
|
||||
await expect(apiMock.searchByTitle('Hooking Season Playtest')).resolves.toEqual(ret);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
test('searchByTitle behavior when requestUrl/fetch returns 401', async () => {
|
||||
let sampleResponse = {
|
||||
data: 'string',
|
||||
};
|
||||
fetchMock.mockResponse(JSON.stringify(sampleResponse), { status: 401 });
|
||||
// TODO: Check API name and fix message
|
||||
// TODO: Externalize string
|
||||
await expect(apiMock.searchByTitle('sample')).rejects.toThrow(`MDB | Received status code ${401} from an API.`);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('searchByTitle behavior when requestUrl/fetch returns 403', async () => {
|
||||
let sampleResponse = {
|
||||
data: 'string',
|
||||
};
|
||||
fetchMock.mockResponse(JSON.stringify(sampleResponse), { status: 403 });
|
||||
// TODO: Check API name and fix message
|
||||
// TODO: Externalize string/import?
|
||||
await expect(apiMock.searchByTitle('sample')).rejects.toThrow(`MDB | Received status code ${403} from an API.`);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('searchByTitle behavior when requestUrl/fetch returns 200', async () => {
|
||||
let sampleResponse;
|
||||
let ret;
|
||||
switch (parameterizedApi) {
|
||||
case OMDbAPI:
|
||||
ret = setOMDbResponseMock();
|
||||
sampleResponse = OMDBMockMovie;
|
||||
break;
|
||||
case WikipediaAPI:
|
||||
ret = setWikipediaResponseMock();
|
||||
sampleResponse = WikipediaMockResponse;
|
||||
break;
|
||||
case MALAPI:
|
||||
// TODO: MAL needs more tests for different types of content
|
||||
ret = setMALResponseMock();
|
||||
sampleResponse = MALMockMovie;
|
||||
case LocGovAPI:
|
||||
// TODO: Add soon
|
||||
break;
|
||||
case SteamAPI:
|
||||
sampleResponse = SteamAPIResponseMock;
|
||||
ret = setSteamResponseMock();
|
||||
break;
|
||||
case MusicBrainzAPI:
|
||||
sampleResponse = MusicBrainzResponseMock;
|
||||
ret = setMusicBrainzResponseMock();
|
||||
break;
|
||||
default:
|
||||
throw Error();
|
||||
}
|
||||
fetchMock.mockResponse(JSON.stringify(sampleResponse), { status: 200 });
|
||||
// TODO: Check API name and fix message
|
||||
// TODO: Externalize string
|
||||
await expect(apiMock.searchByTitle('Hooking Season Playtest')).resolves.toEqual(ret);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -27,4 +27,4 @@
|
|||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import {APIModel} from '../api/APIModel';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import { APIModel } from '../api/APIModel';
|
||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../main';
|
||||
|
||||
export class TestAPI extends APIModel {
|
||||
plugin: MediaDbPlugin;
|
||||
|
||||
|
||||
constructor(plugin: MediaDbPlugin) {
|
||||
super();
|
||||
|
||||
|
|
@ -16,7 +15,6 @@ export class TestAPI extends APIModel {
|
|||
this.types = [];
|
||||
}
|
||||
|
||||
|
||||
async getById(id: string): Promise<MediaTypeModel> {
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import {GameModel} from '../models/GameModel';
|
||||
import {MovieModel} from '../models/MovieModel';
|
||||
import {MusicReleaseModel} from '../models/MusicReleaseModel';
|
||||
import {WikiModel} from '../models/WikiModel';
|
||||
import {MediaType} from '../utils/MediaType';
|
||||
import {apiMock} from './ParameterizedAPI.test';
|
||||
import { GameModel } from '../models/GameModel';
|
||||
import { MovieModel } from '../models/MovieModel';
|
||||
import { MusicReleaseModel } from '../models/MusicReleaseModel';
|
||||
import { WikiModel } from '../models/WikiModel';
|
||||
import { MediaType } from '../utils/MediaType';
|
||||
import { apiMock } from './ParameterizedAPI.test';
|
||||
import MALMockMovie from './ResponseMocks/MALMockMovie.json';
|
||||
import MusicBrainzResponseMock from './ResponseMocks/MusicBrainzMockResponse.json';
|
||||
import OMDBMockMovie from './ResponseMocks/OMDBMockResponse.json';
|
||||
|
|
@ -13,73 +13,83 @@ import WikipediaMockResponse from './ResponseMocks/WikipediaMockResponse.json';
|
|||
export function setWikipediaResponseMock() {
|
||||
let ret = [];
|
||||
let wikiresponse = WikipediaMockResponse.query.search[0];
|
||||
ret.push(new WikiModel({
|
||||
type: 'wiki',
|
||||
title: wikiresponse.title,
|
||||
englishTitle: wikiresponse.title,
|
||||
year: '',
|
||||
dataSource: apiMock.apiName,
|
||||
id: wikiresponse.pageid,
|
||||
}));
|
||||
ret.push(
|
||||
new WikiModel({
|
||||
type: 'wiki',
|
||||
title: wikiresponse.title,
|
||||
englishTitle: wikiresponse.title,
|
||||
year: '',
|
||||
dataSource: apiMock.apiName,
|
||||
id: wikiresponse.pageid,
|
||||
})
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
||||
export function setOMDbResponseMock() {
|
||||
let ret = [];
|
||||
let omdbresponse = OMDBMockMovie.Search[0];
|
||||
ret.push(new MovieModel({
|
||||
type: 'wiki',
|
||||
title: omdbresponse.Title,
|
||||
englishTitle: omdbresponse.Title,
|
||||
year: omdbresponse.Year,
|
||||
dataSource: apiMock.apiName,
|
||||
id: omdbresponse.imdbID,
|
||||
}));
|
||||
ret.push(
|
||||
new MovieModel({
|
||||
type: 'wiki',
|
||||
title: omdbresponse.Title,
|
||||
englishTitle: omdbresponse.Title,
|
||||
year: omdbresponse.Year,
|
||||
dataSource: apiMock.apiName,
|
||||
id: omdbresponse.imdbID,
|
||||
})
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
||||
export function setMALResponseMock() {
|
||||
let ret = [];
|
||||
let result = MALMockMovie.data[0];
|
||||
ret.push(new MovieModel({
|
||||
type: result.type,
|
||||
title: result.title,
|
||||
englishTitle: result.title_english,
|
||||
year: result.aired.prop.from.year,
|
||||
dataSource: apiMock.apiName,
|
||||
id: result.mal_id,
|
||||
}));
|
||||
ret.push(
|
||||
new MovieModel({
|
||||
type: result.type,
|
||||
title: result.title,
|
||||
englishTitle: result.title_english,
|
||||
year: result.aired.prop.from.year,
|
||||
dataSource: apiMock.apiName,
|
||||
id: result.mal_id,
|
||||
})
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
||||
export function setSteamResponseMock() {
|
||||
let ret = [];
|
||||
let steamResponse = SteamAPIResponseMock.applist.apps[0];
|
||||
ret.push(new GameModel({
|
||||
type: MediaType.Game,
|
||||
title: steamResponse.name,
|
||||
englishTitle: steamResponse.name,
|
||||
year: '',
|
||||
dataSource: apiMock.apiName,
|
||||
id: steamResponse.appid,
|
||||
}));
|
||||
ret.push(
|
||||
new GameModel({
|
||||
type: MediaType.Game,
|
||||
title: steamResponse.name,
|
||||
englishTitle: steamResponse.name,
|
||||
year: '',
|
||||
dataSource: apiMock.apiName,
|
||||
id: steamResponse.appid,
|
||||
})
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
||||
export function setMusicBrainzResponseMock() {
|
||||
let ret = [];
|
||||
let result = MusicBrainzResponseMock['release-groups'][0];
|
||||
ret.push(new MusicReleaseModel({
|
||||
type: 'musicRelease',
|
||||
title: result.title,
|
||||
englishTitle: result.title,
|
||||
year: (new Date(result['first-release-date'])).getFullYear().toString(),
|
||||
dataSource: apiMock.apiName,
|
||||
url: '',
|
||||
id: result.id,
|
||||
ret.push(
|
||||
new MusicReleaseModel({
|
||||
type: 'musicRelease',
|
||||
title: result.title,
|
||||
englishTitle: result.title,
|
||||
year: new Date(result['first-release-date']).getFullYear().toString(),
|
||||
dataSource: apiMock.apiName,
|
||||
url: '',
|
||||
id: result.id,
|
||||
|
||||
artists: result['artist-credit'].map((a: any) => a.name),
|
||||
subType: result['primary-type'],
|
||||
} as MusicReleaseModel));
|
||||
artists: result['artist-credit'].map((a: any) => a.name),
|
||||
subType: result['primary-type'],
|
||||
} as MusicReleaseModel)
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {containsOnlyLettersAndUnderscores, replaceIllegalFileNameCharactersInString, wrapAround} from '../utils/Utils';
|
||||
import { containsOnlyLettersAndUnderscores, replaceIllegalFileNameCharactersInString, wrapAround } from '../utils/Utils';
|
||||
|
||||
test('If wrapAround wraps correctly', () => {
|
||||
expect(wrapAround(100, 5)).toBe(0);
|
||||
|
|
|
|||
1185
src/utils/IconList.ts
Normal file
1185
src/utils/IconList.ts
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,14 +1,14 @@
|
|||
import {MediaDbPluginSettings} from '../settings/Settings';
|
||||
import {MediaType} from './MediaType';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import {replaceTags} from './Utils';
|
||||
import {App, TFile} from 'obsidian';
|
||||
import {MovieModel} from '../models/MovieModel';
|
||||
import {SeriesModel} from '../models/SeriesModel';
|
||||
import {GameModel} from '../models/GameModel';
|
||||
import {WikiModel} from '../models/WikiModel';
|
||||
import {MusicReleaseModel} from '../models/MusicReleaseModel';
|
||||
import {BoardGameModel} from '../models/BoardGameModel';
|
||||
import { MediaDbPluginSettings } from '../settings/Settings';
|
||||
import { MediaType } from './MediaType';
|
||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||
import { replaceTags } from './Utils';
|
||||
import { App, TFile } from 'obsidian';
|
||||
import { MovieModel } from '../models/MovieModel';
|
||||
import { SeriesModel } from '../models/SeriesModel';
|
||||
import { GameModel } from '../models/GameModel';
|
||||
import { WikiModel } from '../models/WikiModel';
|
||||
import { MusicReleaseModel } from '../models/MusicReleaseModel';
|
||||
import { BoardGameModel } from '../models/BoardGameModel';
|
||||
|
||||
export const MEDIA_TYPES: MediaType[] = [MediaType.Movie, MediaType.Series, MediaType.Game, MediaType.Wiki, MediaType.MusicRelease, MediaType.BoardGame];
|
||||
|
||||
|
|
@ -16,8 +16,7 @@ export class MediaTypeManager {
|
|||
mediaFileNameTemplateMap: Map<MediaType, string>;
|
||||
mediaTemplateMap: Map<MediaType, string>;
|
||||
|
||||
constructor() {
|
||||
}
|
||||
constructor() {}
|
||||
|
||||
updateTemplates(settings: MediaDbPluginSettings) {
|
||||
this.mediaFileNameTemplateMap = new Map<MediaType, string>();
|
||||
|
|
@ -48,7 +47,10 @@ export class MediaTypeManager {
|
|||
return '';
|
||||
}
|
||||
|
||||
const templateFile: TFile = app.vault.getFiles().filter((f: TFile) => f.name === templateFileName).first();
|
||||
const templateFile: TFile = app.vault
|
||||
.getFiles()
|
||||
.filter((f: TFile) => f.name === templateFileName)
|
||||
.first();
|
||||
|
||||
if (!templateFile) {
|
||||
return '';
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
import {MediaDbAdvancedSearchModal} from '../modals/MediaDbAdvancedSearchModal';
|
||||
import {MediaDbIdSearchModal} from '../modals/MediaDbIdSearchModal';
|
||||
import {MediaTypeModel} from '../models/MediaTypeModel';
|
||||
import {MediaDbSearchResultModal} from '../modals/MediaDbSearchResultModal';
|
||||
import {Notice} from 'obsidian';
|
||||
import { MediaDbAdvancedSearchModal } from '../modals/MediaDbAdvancedSearchModal';
|
||||
import { MediaDbIdSearchModal } from '../modals/MediaDbIdSearchModal';
|
||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||
import { MediaDbSearchResultModal } from '../modals/MediaDbSearchResultModal';
|
||||
import { Notice } from 'obsidian';
|
||||
import MediaDbPlugin from '../main';
|
||||
import {MediaDbPreviewModal} from 'src/modals/MediaDbPreviewModal';
|
||||
import {CreateNoteOptions} from './Utils';
|
||||
import {MediaDbSearchModal} from '../modals/MediaDbSearchModal';
|
||||
|
||||
import { MediaDbPreviewModal } from 'src/modals/MediaDbPreviewModal';
|
||||
import { CreateNoteOptions } from './Utils';
|
||||
import { MediaDbSearchModal } from '../modals/MediaDbSearchModal';
|
||||
|
||||
export enum ModalResultCode {
|
||||
SUCCESS,
|
||||
|
|
@ -22,9 +21,9 @@ export enum ModalResultCode {
|
|||
* On {@link ModalResultCode.ERROR} this contains a reference to that error.
|
||||
*/
|
||||
export interface SearchModalResult {
|
||||
code: ModalResultCode.SUCCESS | ModalResultCode.CLOSE | ModalResultCode.ERROR,
|
||||
data?: SearchModalData,
|
||||
error?: Error,
|
||||
code: ModalResultCode.SUCCESS | ModalResultCode.CLOSE | ModalResultCode.ERROR;
|
||||
data?: SearchModalData;
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -33,9 +32,9 @@ export interface SearchModalResult {
|
|||
* On {@link ModalResultCode.ERROR} this contains a reference to that error.
|
||||
*/
|
||||
export interface AdvancedSearchModalResult {
|
||||
code: ModalResultCode.SUCCESS | ModalResultCode.CLOSE | ModalResultCode.ERROR,
|
||||
data?: AdvancedSearchModalData,
|
||||
error?: Error,
|
||||
code: ModalResultCode.SUCCESS | ModalResultCode.CLOSE | ModalResultCode.ERROR;
|
||||
data?: AdvancedSearchModalData;
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -44,9 +43,9 @@ export interface AdvancedSearchModalResult {
|
|||
* On {@link ModalResultCode.ERROR} this contains a reference to that error.
|
||||
*/
|
||||
export interface IdSearchModalResult {
|
||||
code: ModalResultCode.SUCCESS | ModalResultCode.CLOSE | ModalResultCode.ERROR,
|
||||
data?: IdSearchModalData,
|
||||
error?: Error,
|
||||
code: ModalResultCode.SUCCESS | ModalResultCode.CLOSE | ModalResultCode.ERROR;
|
||||
data?: IdSearchModalData;
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -55,9 +54,9 @@ export interface IdSearchModalResult {
|
|||
* On {@link ModalResultCode.ERROR} this contains a reference to that error.
|
||||
*/
|
||||
export interface SelectModalResult {
|
||||
code: ModalResultCode.SUCCESS | ModalResultCode.CLOSE | ModalResultCode.SKIP | ModalResultCode.ERROR,
|
||||
data?: SelectModalData,
|
||||
error?: Error,
|
||||
code: ModalResultCode.SUCCESS | ModalResultCode.CLOSE | ModalResultCode.SKIP | ModalResultCode.ERROR;
|
||||
data?: SelectModalData;
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,9 +65,9 @@ export interface SelectModalResult {
|
|||
* On {@link ModalResultCode.ERROR} this contains a reference to that error.
|
||||
*/
|
||||
export interface PreviewModalResult {
|
||||
code: ModalResultCode.SUCCESS | ModalResultCode.CLOSE | ModalResultCode.ERROR,
|
||||
data?: PreviewModalData,
|
||||
error?: Error,
|
||||
code: ModalResultCode.SUCCESS | ModalResultCode.CLOSE | ModalResultCode.ERROR;
|
||||
data?: PreviewModalData;
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,8 +76,8 @@ export interface PreviewModalResult {
|
|||
* - types: the selected APIs
|
||||
*/
|
||||
export interface SearchModalData {
|
||||
query: string,
|
||||
types: string[],
|
||||
query: string;
|
||||
types: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -87,8 +86,8 @@ export interface SearchModalData {
|
|||
* - apis: the selected APIs
|
||||
*/
|
||||
export interface AdvancedSearchModalData {
|
||||
query: string,
|
||||
apis: string[],
|
||||
query: string;
|
||||
apis: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -97,8 +96,8 @@ export interface AdvancedSearchModalData {
|
|||
* - apis: the selected APIs
|
||||
*/
|
||||
export interface IdSearchModalData {
|
||||
query: string,
|
||||
api: string,
|
||||
query: string;
|
||||
api: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -106,7 +105,7 @@ export interface IdSearchModalData {
|
|||
* - selected: the selected items
|
||||
*/
|
||||
export interface SelectModalData {
|
||||
selected: MediaTypeModel[],
|
||||
selected: MediaTypeModel[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -114,7 +113,7 @@ export interface SelectModalData {
|
|||
* - confirmed: whether the selected element has been confirmed
|
||||
*/
|
||||
export interface PreviewModalData {
|
||||
confirmed: boolean,
|
||||
confirmed: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -124,9 +123,9 @@ export interface PreviewModalData {
|
|||
* - prefilledSearchString: prefilled query
|
||||
*/
|
||||
export interface SearchModalOptions {
|
||||
modalTitle?: string,
|
||||
preselectedTypes?: string[],
|
||||
prefilledSearchString?: string,
|
||||
modalTitle?: string;
|
||||
preselectedTypes?: string[];
|
||||
prefilledSearchString?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -136,9 +135,9 @@ export interface SearchModalOptions {
|
|||
* - prefilledSearchString: prefilled query
|
||||
*/
|
||||
export interface AdvancedSearchModalOptions {
|
||||
modalTitle?: string,
|
||||
preselectedAPIs?: string[],
|
||||
prefilledSearchString?: string,
|
||||
modalTitle?: string;
|
||||
preselectedAPIs?: string[];
|
||||
prefilledSearchString?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -148,9 +147,9 @@ export interface AdvancedSearchModalOptions {
|
|||
* - prefilledSearchString: prefilled query
|
||||
*/
|
||||
export interface IdSearchModalOptions {
|
||||
modalTitle?: string,
|
||||
preselectedAPI?: string,
|
||||
prefilledSearchString?: string,
|
||||
modalTitle?: string;
|
||||
preselectedAPI?: string;
|
||||
prefilledSearchString?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -161,10 +160,10 @@ export interface IdSearchModalOptions {
|
|||
* - skipButton: whether to add a skip button to the modal
|
||||
*/
|
||||
export interface SelectModalOptions {
|
||||
modalTitle?: string,
|
||||
elements?: MediaTypeModel[],
|
||||
multiSelect?: boolean,
|
||||
skipButton?: boolean,
|
||||
modalTitle?: string;
|
||||
elements?: MediaTypeModel[];
|
||||
multiSelect?: boolean;
|
||||
skipButton?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -173,9 +172,9 @@ export interface SelectModalOptions {
|
|||
* - elements: the elements to preview
|
||||
*/
|
||||
export interface PreviewModalOptions {
|
||||
modalTitle?: string,
|
||||
elements?: MediaTypeModel[],
|
||||
createNoteOptions?: CreateNoteOptions,
|
||||
modalTitle?: string;
|
||||
elements?: MediaTypeModel[];
|
||||
createNoteOptions?: CreateNoteOptions;
|
||||
}
|
||||
|
||||
export const SEARCH_MODAL_DEFAULT_OPTIONS: SearchModalOptions = {
|
||||
|
|
@ -206,7 +205,7 @@ export const SELECT_MODAL_OPTIONS_DEFAULT: SelectModalOptions = {
|
|||
export const PREVIEW_MODAL_DEFAULT_OPTIONS: PreviewModalOptions = {
|
||||
modalTitle: 'Media DB Preview',
|
||||
elements: [],
|
||||
createNoteOptions: {attachTemplate: true},
|
||||
createNoteOptions: { attachTemplate: true },
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -215,7 +214,6 @@ export const PREVIEW_MODAL_DEFAULT_OPTIONS: PreviewModalOptions = {
|
|||
export class ModalHelper {
|
||||
plugin: MediaDbPlugin;
|
||||
|
||||
|
||||
constructor(plugin: MediaDbPlugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
|
@ -228,20 +226,20 @@ export class ModalHelper {
|
|||
* @param searchModalOptions the options for the modal, see {@link SEARCH_MODAL_DEFAULT_OPTIONS}
|
||||
* @returns the user input or nothing and a reference to the modal.
|
||||
*/
|
||||
async createSearchModal(searchModalOptions: SearchModalOptions): Promise<{ searchModalResult: SearchModalResult, searchModal: MediaDbSearchModal }> {
|
||||
async createSearchModal(searchModalOptions: SearchModalOptions): Promise<{ searchModalResult: SearchModalResult; searchModal: MediaDbSearchModal }> {
|
||||
const modal = new MediaDbSearchModal(this.plugin, searchModalOptions);
|
||||
const res: SearchModalResult = await new Promise((resolve, reject) => {
|
||||
modal.setSubmitCallback(res => resolve({code: ModalResultCode.SUCCESS, data: res}));
|
||||
modal.setSubmitCallback(res => resolve({ code: ModalResultCode.SUCCESS, data: res }));
|
||||
modal.setCloseCallback(err => {
|
||||
if (err) {
|
||||
resolve({code: ModalResultCode.ERROR, error: err});
|
||||
resolve({ code: ModalResultCode.ERROR, error: err });
|
||||
}
|
||||
resolve({code: ModalResultCode.CLOSE});
|
||||
resolve({ code: ModalResultCode.CLOSE });
|
||||
});
|
||||
|
||||
modal.open();
|
||||
});
|
||||
return {searchModalResult: res, searchModal: modal};
|
||||
return { searchModalResult: res, searchModal: modal };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -253,8 +251,8 @@ export class ModalHelper {
|
|||
* @returns the user input or nothing and a reference to the modal.
|
||||
*/
|
||||
async openSearchModal(searchModalOptions: SearchModalOptions, submitCallback: (searchModalData: SearchModalData) => Promise<MediaTypeModel[]>): Promise<MediaTypeModel[]> {
|
||||
const {searchModalResult, searchModal} = await this.createSearchModal(searchModalOptions);
|
||||
console.debug(`MDB | searchModal closed with code ${searchModalResult.code}`)
|
||||
const { searchModalResult, searchModal } = await this.createSearchModal(searchModalOptions);
|
||||
console.debug(`MDB | searchModal closed with code ${searchModalResult.code}`);
|
||||
|
||||
if (searchModalResult.code === ModalResultCode.ERROR) {
|
||||
// there was an error in the modal itself
|
||||
|
|
@ -290,20 +288,22 @@ export class ModalHelper {
|
|||
* @param advancedSearchModalOptions the options for the modal, see {@link ADVANCED_SEARCH_MODAL_DEFAULT_OPTIONS}
|
||||
* @returns the user input or nothing and a reference to the modal.
|
||||
*/
|
||||
async createAdvancedSearchModal(advancedSearchModalOptions: AdvancedSearchModalOptions): Promise<{ advancedSearchModalResult: AdvancedSearchModalResult, advancedSearchModal: MediaDbAdvancedSearchModal }> {
|
||||
async createAdvancedSearchModal(
|
||||
advancedSearchModalOptions: AdvancedSearchModalOptions
|
||||
): Promise<{ advancedSearchModalResult: AdvancedSearchModalResult; advancedSearchModal: MediaDbAdvancedSearchModal }> {
|
||||
const modal = new MediaDbAdvancedSearchModal(this.plugin, advancedSearchModalOptions);
|
||||
const res: AdvancedSearchModalResult = await new Promise((resolve, reject) => {
|
||||
modal.setSubmitCallback(res => resolve({code: ModalResultCode.SUCCESS, data: res}));
|
||||
modal.setSubmitCallback(res => resolve({ code: ModalResultCode.SUCCESS, data: res }));
|
||||
modal.setCloseCallback(err => {
|
||||
if (err) {
|
||||
resolve({code: ModalResultCode.ERROR, error: err});
|
||||
resolve({ code: ModalResultCode.ERROR, error: err });
|
||||
}
|
||||
resolve({code: ModalResultCode.CLOSE});
|
||||
resolve({ code: ModalResultCode.CLOSE });
|
||||
});
|
||||
|
||||
modal.open();
|
||||
});
|
||||
return {advancedSearchModalResult: res, advancedSearchModal: modal};
|
||||
return { advancedSearchModalResult: res, advancedSearchModal: modal };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -314,9 +314,12 @@ export class ModalHelper {
|
|||
* @param submitCallback the callback that gets executed after the modal has been submitted, but after it has been closed
|
||||
* @returns the user input or nothing and a reference to the modal.
|
||||
*/
|
||||
async openAdvancedSearchModal(advancedSearchModalOptions: AdvancedSearchModalOptions, submitCallback: (advancedSearchModalData: AdvancedSearchModalData) => Promise<MediaTypeModel[]>): Promise<MediaTypeModel[]> {
|
||||
const {advancedSearchModalResult, advancedSearchModal} = await this.createAdvancedSearchModal(advancedSearchModalOptions);
|
||||
console.debug(`MDB | advencedSearchModal closed with code ${advancedSearchModalResult.code}`)
|
||||
async openAdvancedSearchModal(
|
||||
advancedSearchModalOptions: AdvancedSearchModalOptions,
|
||||
submitCallback: (advancedSearchModalData: AdvancedSearchModalData) => Promise<MediaTypeModel[]>
|
||||
): Promise<MediaTypeModel[]> {
|
||||
const { advancedSearchModalResult, advancedSearchModal } = await this.createAdvancedSearchModal(advancedSearchModalOptions);
|
||||
console.debug(`MDB | advencedSearchModal closed with code ${advancedSearchModalResult.code}`);
|
||||
|
||||
if (advancedSearchModalResult.code === ModalResultCode.ERROR) {
|
||||
// there was an error in the modal itself
|
||||
|
|
@ -352,20 +355,20 @@ export class ModalHelper {
|
|||
* @param idSearchModalOptions the options for the modal, see {@link ID_SEARCH_MODAL_DEFAULT_OPTIONS}
|
||||
* @returns the user input or nothing and a reference to the modal.
|
||||
*/
|
||||
async createIdSearchModal(idSearchModalOptions: IdSearchModalOptions): Promise<{ idSearchModalResult: IdSearchModalResult, idSearchModal: MediaDbIdSearchModal }> {
|
||||
async createIdSearchModal(idSearchModalOptions: IdSearchModalOptions): Promise<{ idSearchModalResult: IdSearchModalResult; idSearchModal: MediaDbIdSearchModal }> {
|
||||
const modal = new MediaDbIdSearchModal(this.plugin, idSearchModalOptions);
|
||||
const res: IdSearchModalResult = await new Promise((resolve, reject) => {
|
||||
modal.setSubmitCallback(res => resolve({code: ModalResultCode.SUCCESS, data: res}));
|
||||
modal.setSubmitCallback(res => resolve({ code: ModalResultCode.SUCCESS, data: res }));
|
||||
modal.setCloseCallback(err => {
|
||||
if (err) {
|
||||
resolve({code: ModalResultCode.ERROR, error: err});
|
||||
resolve({ code: ModalResultCode.ERROR, error: err });
|
||||
}
|
||||
resolve({code: ModalResultCode.CLOSE});
|
||||
resolve({ code: ModalResultCode.CLOSE });
|
||||
});
|
||||
|
||||
modal.open();
|
||||
});
|
||||
return {idSearchModalResult: res, idSearchModal: modal};
|
||||
return { idSearchModalResult: res, idSearchModal: modal };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -376,9 +379,12 @@ export class ModalHelper {
|
|||
* @param submitCallback the callback that gets executed after the modal has been submitted, but after it has been closed
|
||||
* @returns the user input or nothing and a reference to the modal.
|
||||
*/
|
||||
async openIdSearchModal(idSearchModalOptions: IdSearchModalOptions, submitCallback: (idSearchModalData: IdSearchModalData) => Promise<MediaTypeModel>): Promise<MediaTypeModel> {
|
||||
const {idSearchModalResult, idSearchModal} = await this.createIdSearchModal(idSearchModalOptions);
|
||||
console.debug(`MDB | idSearchModal closed with code ${idSearchModalResult.code}`)
|
||||
async openIdSearchModal(
|
||||
idSearchModalOptions: IdSearchModalOptions,
|
||||
submitCallback: (idSearchModalData: IdSearchModalData) => Promise<MediaTypeModel>
|
||||
): Promise<MediaTypeModel> {
|
||||
const { idSearchModalResult, idSearchModal } = await this.createIdSearchModal(idSearchModalOptions);
|
||||
console.debug(`MDB | idSearchModal closed with code ${idSearchModalResult.code}`);
|
||||
|
||||
if (idSearchModalResult.code === ModalResultCode.ERROR) {
|
||||
// there was an error in the modal itself
|
||||
|
|
@ -414,21 +420,21 @@ export class ModalHelper {
|
|||
* @param selectModalOptions the options for the modal, see {@link SELECT_MODAL_OPTIONS_DEFAULT}
|
||||
* @returns the user input or nothing and a reference to the modal.
|
||||
*/
|
||||
async createSelectModal(selectModalOptions: SelectModalOptions): Promise<{ selectModalResult: SelectModalResult, selectModal: MediaDbSearchResultModal }> {
|
||||
async createSelectModal(selectModalOptions: SelectModalOptions): Promise<{ selectModalResult: SelectModalResult; selectModal: MediaDbSearchResultModal }> {
|
||||
const modal = new MediaDbSearchResultModal(this.plugin, selectModalOptions);
|
||||
const res: SelectModalResult = await new Promise((resolve, reject) => {
|
||||
modal.setSubmitCallback(res => resolve({code: ModalResultCode.SUCCESS, data: res}));
|
||||
modal.setSkipCallback(() => resolve({code: ModalResultCode.SKIP}));
|
||||
modal.setSubmitCallback(res => resolve({ code: ModalResultCode.SUCCESS, data: res }));
|
||||
modal.setSkipCallback(() => resolve({ code: ModalResultCode.SKIP }));
|
||||
modal.setCloseCallback(err => {
|
||||
if (err) {
|
||||
resolve({code: ModalResultCode.ERROR, error: err});
|
||||
resolve({ code: ModalResultCode.ERROR, error: err });
|
||||
}
|
||||
resolve({code: ModalResultCode.CLOSE});
|
||||
resolve({ code: ModalResultCode.CLOSE });
|
||||
});
|
||||
|
||||
modal.open();
|
||||
});
|
||||
return {selectModalResult: res, selectModal: modal};
|
||||
return { selectModalResult: res, selectModal: modal };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -440,8 +446,8 @@ export class ModalHelper {
|
|||
* @returns the user input or nothing and a reference to the modal.
|
||||
*/
|
||||
async openSelectModal(selectModalOptions: SelectModalOptions, submitCallback: (selectModalData: SelectModalData) => Promise<MediaTypeModel[]>): Promise<MediaTypeModel[]> {
|
||||
const {selectModalResult, selectModal} = await this.createSelectModal(selectModalOptions);
|
||||
console.debug(`MDB | selectModal closed with code ${selectModalResult.code}`)
|
||||
const { selectModalResult, selectModal } = await this.createSelectModal(selectModalOptions);
|
||||
console.debug(`MDB | selectModal closed with code ${selectModalResult.code}`);
|
||||
|
||||
if (selectModalResult.code === ModalResultCode.ERROR) {
|
||||
// there was an error in the modal itself
|
||||
|
|
@ -474,26 +480,26 @@ export class ModalHelper {
|
|||
}
|
||||
}
|
||||
|
||||
async createPreviewModal(previewModalOptions: PreviewModalOptions): Promise<{ previewModalResult: PreviewModalResult, previewModal: MediaDbPreviewModal }> {
|
||||
async createPreviewModal(previewModalOptions: PreviewModalOptions): Promise<{ previewModalResult: PreviewModalResult; previewModal: MediaDbPreviewModal }> {
|
||||
//todo: handle attachFile for existing files
|
||||
const modal = new MediaDbPreviewModal(this.plugin, previewModalOptions);
|
||||
const res: PreviewModalResult = await new Promise((resolve, reject) => {
|
||||
modal.setSubmitCallback(res => resolve({code: ModalResultCode.SUCCESS, data: res}));
|
||||
modal.setSubmitCallback(res => resolve({ code: ModalResultCode.SUCCESS, data: res }));
|
||||
modal.setCloseCallback(err => {
|
||||
if (err) {
|
||||
resolve({code: ModalResultCode.ERROR, error: err});
|
||||
resolve({ code: ModalResultCode.ERROR, error: err });
|
||||
}
|
||||
resolve({code: ModalResultCode.CLOSE});
|
||||
resolve({ code: ModalResultCode.CLOSE });
|
||||
});
|
||||
|
||||
modal.open();
|
||||
});
|
||||
return {previewModalResult: res, previewModal: modal};
|
||||
return { previewModalResult: res, previewModal: modal };
|
||||
}
|
||||
|
||||
async openPreviewModal(previewModalOptions: PreviewModalOptions, submitCallback: (previewModalData: PreviewModalData) => Promise<boolean>): Promise<boolean> {
|
||||
const {previewModalResult, previewModal} = await this.createPreviewModal(previewModalOptions);
|
||||
console.debug(`MDB | previewModal closed with code ${previewModalResult.code}`)
|
||||
const { previewModalResult, previewModal } = await this.createPreviewModal(previewModalOptions);
|
||||
console.debug(`MDB | previewModal closed with code ${previewModalResult.code}`);
|
||||
|
||||
if (previewModalResult.code === ModalResultCode.ERROR) {
|
||||
// there was an error in the modal itself
|
||||
|
|
@ -521,4 +527,3 @@ export class ModalHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue