merge #100
This commit is contained in:
commit
e416434bf3
8 changed files with 559 additions and 457 deletions
|
|
@ -8,6 +8,7 @@ import { MediaType } from '../../utils/MediaType';
|
||||||
export class MALAPI extends APIModel {
|
export class MALAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
typeMappings: Map<string, string>;
|
typeMappings: Map<string, string>;
|
||||||
|
apiDateFormat: string = 'YYYY-MM-DDTHH:mm:ssZ'; // ISO
|
||||||
|
|
||||||
constructor(plugin: MediaDbPlugin) {
|
constructor(plugin: MediaDbPlugin) {
|
||||||
super();
|
super();
|
||||||
|
|
@ -115,7 +116,7 @@ export class MALAPI extends APIModel {
|
||||||
image: result.images?.jpg?.image_url ?? '',
|
image: result.images?.jpg?.image_url ?? '',
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
premiere: new Date(result.aired?.from).toLocaleDateString() ?? 'unknown',
|
premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown',
|
||||||
streamingServices: result.streaming?.map((x: any) => x.name) ?? [],
|
streamingServices: result.streaming?.map((x: any) => x.name) ?? [],
|
||||||
|
|
||||||
userData: {
|
userData: {
|
||||||
|
|
@ -146,7 +147,7 @@ export class MALAPI extends APIModel {
|
||||||
image: result.images?.jpg?.image_url ?? '',
|
image: result.images?.jpg?.image_url ?? '',
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
premiere: new Date(result.aired?.from).toLocaleDateString() ?? 'unknown',
|
premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown',
|
||||||
streamingServices: result.streaming?.map((x: any) => x.name) ?? [],
|
streamingServices: result.streaming?.map((x: any) => x.name) ?? [],
|
||||||
|
|
||||||
userData: {
|
userData: {
|
||||||
|
|
@ -176,8 +177,8 @@ export class MALAPI extends APIModel {
|
||||||
image: result.images?.jpg?.image_url ?? '',
|
image: result.images?.jpg?.image_url ?? '',
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
airedFrom: new Date(result.aired?.from).toLocaleDateString() ?? 'unknown',
|
airedFrom: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown',
|
||||||
airedTo: new Date(result.aired?.to).toLocaleDateString() ?? 'unknown',
|
airedTo: this.plugin.dateFormatter.format(result.aired?.to, this.apiDateFormat) ?? 'unknown',
|
||||||
airing: result.airing,
|
airing: result.airing,
|
||||||
|
|
||||||
userData: {
|
userData: {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import { MediaType } from '../../utils/MediaType';
|
||||||
export class OMDbAPI extends APIModel {
|
export class OMDbAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
typeMappings: Map<string, string>;
|
typeMappings: Map<string, string>;
|
||||||
|
apiDateFormat: string = 'DD MMM YYYY';
|
||||||
|
|
||||||
constructor(plugin: MediaDbPlugin) {
|
constructor(plugin: MediaDbPlugin) {
|
||||||
super();
|
super();
|
||||||
|
|
@ -142,7 +143,7 @@ export class OMDbAPI extends APIModel {
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
streamingServices: [],
|
streamingServices: [],
|
||||||
premiere: new Date(result.Released).toLocaleDateString() ?? 'unknown',
|
premiere: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown',
|
||||||
|
|
||||||
userData: {
|
userData: {
|
||||||
watched: false,
|
watched: false,
|
||||||
|
|
@ -173,7 +174,7 @@ export class OMDbAPI extends APIModel {
|
||||||
released: true,
|
released: true,
|
||||||
streamingServices: [],
|
streamingServices: [],
|
||||||
airing: false,
|
airing: false,
|
||||||
airedFrom: new Date(result.Released).toLocaleDateString() ?? 'unknown',
|
airedFrom: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown',
|
||||||
airedTo: 'unknown',
|
airedTo: 'unknown',
|
||||||
|
|
||||||
userData: {
|
userData: {
|
||||||
|
|
@ -199,7 +200,7 @@ export class OMDbAPI extends APIModel {
|
||||||
image: result.Poster ?? '',
|
image: result.Poster ?? '',
|
||||||
|
|
||||||
released: true,
|
released: true,
|
||||||
releaseDate: new Date(result.Released).toLocaleDateString() ?? 'unknown',
|
releaseDate: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown',
|
||||||
|
|
||||||
userData: {
|
userData: {
|
||||||
played: false,
|
played: false,
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { MediaType } from '../../utils/MediaType';
|
||||||
export class SteamAPI extends APIModel {
|
export class SteamAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
typeMappings: Map<string, string>;
|
typeMappings: Map<string, string>;
|
||||||
|
apiDateFormat: string = 'DD MMM, YYYY';
|
||||||
|
|
||||||
constructor(plugin: MediaDbPlugin) {
|
constructor(plugin: MediaDbPlugin) {
|
||||||
super();
|
super();
|
||||||
|
|
@ -109,7 +110,7 @@ export class SteamAPI extends APIModel {
|
||||||
image: result.header_image ?? '',
|
image: result.header_image ?? '',
|
||||||
|
|
||||||
released: !result.release_date?.comming_soon,
|
released: !result.release_date?.comming_soon,
|
||||||
releaseDate: new Date(result.release_date?.date).toLocaleDateString() ?? 'unknown',
|
releaseDate: this.plugin.dateFormatter.format(result.release_date?.date, this.apiDateFormat) ?? 'unknown',
|
||||||
|
|
||||||
userData: {
|
userData: {
|
||||||
played: false,
|
played: false,
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { MediaType } from '../../utils/MediaType';
|
||||||
|
|
||||||
export class WikipediaAPI extends APIModel {
|
export class WikipediaAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
|
apiDateFormat: string = 'YYYY-MM-DDTHH:mm:ssZ'; // ISO
|
||||||
|
|
||||||
constructor(plugin: MediaDbPlugin) {
|
constructor(plugin: MediaDbPlugin) {
|
||||||
super();
|
super();
|
||||||
|
|
@ -72,7 +73,7 @@ export class WikipediaAPI extends APIModel {
|
||||||
id: result.pageid,
|
id: result.pageid,
|
||||||
|
|
||||||
wikiUrl: result.fullurl,
|
wikiUrl: result.fullurl,
|
||||||
lastUpdated: new Date(result.touched).toLocaleDateString() ?? 'unknown',
|
lastUpdated: this.plugin.dateFormatter.format(result.touched, this.apiDateFormat),
|
||||||
length: result.length,
|
length: result.length,
|
||||||
|
|
||||||
userData: {},
|
userData: {},
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import { YAMLConverter } from './utils/YAMLConverter';
|
||||||
import { MediaDbFolderImportModal } from './modals/MediaDbFolderImportModal';
|
import { MediaDbFolderImportModal } from './modals/MediaDbFolderImportModal';
|
||||||
import { PropertyMapping, PropertyMappingModel } from './settings/PropertyMapping';
|
import { PropertyMapping, PropertyMappingModel } from './settings/PropertyMapping';
|
||||||
import { ModalHelper, ModalResultCode, SearchModalOptions } from './utils/ModalHelper';
|
import { ModalHelper, ModalResultCode, SearchModalOptions } from './utils/ModalHelper';
|
||||||
|
import { DateFormatter } from './utils/DateFormatter';
|
||||||
|
|
||||||
export default class MediaDbPlugin extends Plugin {
|
export default class MediaDbPlugin extends Plugin {
|
||||||
settings: MediaDbPluginSettings;
|
settings: MediaDbPluginSettings;
|
||||||
|
|
@ -22,6 +23,7 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
mediaTypeManager: MediaTypeManager;
|
mediaTypeManager: MediaTypeManager;
|
||||||
modelPropertyMapper: PropertyMapper;
|
modelPropertyMapper: PropertyMapper;
|
||||||
modalHelper: ModalHelper;
|
modalHelper: ModalHelper;
|
||||||
|
dateFormatter: DateFormatter;
|
||||||
|
|
||||||
frontMatterRexExpPattern: string = '^(---)\\n[\\s\\S]*?\\n---';
|
frontMatterRexExpPattern: string = '^(---)\\n[\\s\\S]*?\\n---';
|
||||||
|
|
||||||
|
|
@ -39,6 +41,7 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
this.mediaTypeManager = new MediaTypeManager();
|
this.mediaTypeManager = new MediaTypeManager();
|
||||||
this.modelPropertyMapper = new PropertyMapper(this);
|
this.modelPropertyMapper = new PropertyMapper(this);
|
||||||
this.modalHelper = new ModalHelper(this);
|
this.modalHelper = new ModalHelper(this);
|
||||||
|
this.dateFormatter = new DateFormatter();
|
||||||
|
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
// register the settings tab
|
// register the settings tab
|
||||||
|
|
@ -46,6 +49,7 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
|
|
||||||
this.mediaTypeManager.updateTemplates(this.settings);
|
this.mediaTypeManager.updateTemplates(this.settings);
|
||||||
this.mediaTypeManager.updateFolders(this.settings);
|
this.mediaTypeManager.updateFolders(this.settings);
|
||||||
|
this.dateFormatter.setFormat(this.settings.customDateFormat);
|
||||||
|
|
||||||
// add icon to the left ribbon
|
// add icon to the left ribbon
|
||||||
const ribbonIconEl = this.addRibbonIcon('database', 'Add new Media DB entry', () => this.createEntryWithAdvancedSearchModal());
|
const ribbonIconEl = this.addRibbonIcon('database', 'Add new Media DB entry', () => this.createEntryWithAdvancedSearchModal());
|
||||||
|
|
@ -563,6 +567,7 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
async saveSettings(): Promise<void> {
|
async saveSettings(): Promise<void> {
|
||||||
this.mediaTypeManager.updateTemplates(this.settings);
|
this.mediaTypeManager.updateTemplates(this.settings);
|
||||||
this.mediaTypeManager.updateFolders(this.settings);
|
this.mediaTypeManager.updateFolders(this.settings);
|
||||||
|
this.dateFormatter.setFormat(this.settings.customDateFormat);
|
||||||
|
|
||||||
await this.saveData(this.settings);
|
await this.saveData(this.settings);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,448 +1,468 @@
|
||||||
import { App, Notice, PluginSettingTab, Setting } from 'obsidian';
|
import { App, Notice, PluginSettingTab, Setting } from 'obsidian';
|
||||||
|
|
||||||
import MediaDbPlugin from '../main';
|
import MediaDbPlugin from '../main';
|
||||||
import { FolderSuggest } from './suggesters/FolderSuggest';
|
import { FolderSuggest } from './suggesters/FolderSuggest';
|
||||||
import { FileSuggest } from './suggesters/FileSuggest';
|
import { FileSuggest } from './suggesters/FileSuggest';
|
||||||
import PropertyMappingModelsComponent from './PropertyMappingModelsComponent.svelte';
|
import PropertyMappingModelsComponent from './PropertyMappingModelsComponent.svelte';
|
||||||
import { PropertyMapping, PropertyMappingModel, PropertyMappingOption } from './PropertyMapping';
|
import { PropertyMapping, PropertyMappingModel, PropertyMappingOption } from './PropertyMapping';
|
||||||
import { MEDIA_TYPES } from '../utils/MediaTypeManager';
|
import { MEDIA_TYPES } from '../utils/MediaTypeManager';
|
||||||
import { MediaTypeModel } from '../models/MediaTypeModel';
|
import { MediaTypeModel } from '../models/MediaTypeModel';
|
||||||
|
import { fragWithHTML } from '../utils/Utils';
|
||||||
export interface MediaDbPluginSettings {
|
|
||||||
OMDbKey: string;
|
export interface MediaDbPluginSettings {
|
||||||
sfwFilter: boolean;
|
OMDbKey: string;
|
||||||
useCustomYamlStringifier: boolean;
|
sfwFilter: boolean;
|
||||||
templates: boolean;
|
useCustomYamlStringifier: boolean;
|
||||||
|
templates: boolean;
|
||||||
movieTemplate: string;
|
customDateFormat: string;
|
||||||
seriesTemplate: string;
|
|
||||||
gameTemplate: string;
|
movieTemplate: string;
|
||||||
wikiTemplate: string;
|
seriesTemplate: string;
|
||||||
musicReleaseTemplate: string;
|
gameTemplate: string;
|
||||||
boardgameTemplate: string;
|
wikiTemplate: string;
|
||||||
|
musicReleaseTemplate: string;
|
||||||
movieFileNameTemplate: string;
|
boardgameTemplate: string;
|
||||||
seriesFileNameTemplate: string;
|
|
||||||
gameFileNameTemplate: string;
|
movieFileNameTemplate: string;
|
||||||
wikiFileNameTemplate: string;
|
seriesFileNameTemplate: string;
|
||||||
musicReleaseFileNameTemplate: string;
|
gameFileNameTemplate: string;
|
||||||
boardgameFileNameTemplate: string;
|
wikiFileNameTemplate: string;
|
||||||
|
musicReleaseFileNameTemplate: string;
|
||||||
moviePropertyConversionRules: string;
|
boardgameFileNameTemplate: string;
|
||||||
seriesPropertyConversionRules: string;
|
|
||||||
gamePropertyConversionRules: string;
|
moviePropertyConversionRules: string;
|
||||||
wikiPropertyConversionRules: string;
|
seriesPropertyConversionRules: string;
|
||||||
musicReleasePropertyConversionRules: string;
|
gamePropertyConversionRules: string;
|
||||||
boardgamePropertyConversionRules: string;
|
wikiPropertyConversionRules: string;
|
||||||
|
musicReleasePropertyConversionRules: string;
|
||||||
movieFolder: string;
|
boardgamePropertyConversionRules: string;
|
||||||
seriesFolder: string;
|
|
||||||
gameFolder: string;
|
movieFolder: string;
|
||||||
wikiFolder: string;
|
seriesFolder: string;
|
||||||
musicReleaseFolder: string;
|
gameFolder: string;
|
||||||
boardgameFolder: string;
|
wikiFolder: string;
|
||||||
|
musicReleaseFolder: string;
|
||||||
propertyMappingModels: PropertyMappingModel[];
|
boardgameFolder: string;
|
||||||
}
|
|
||||||
|
propertyMappingModels: PropertyMappingModel[];
|
||||||
const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
}
|
||||||
OMDbKey: '',
|
|
||||||
sfwFilter: true,
|
const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||||
useCustomYamlStringifier: true,
|
OMDbKey: '',
|
||||||
templates: true,
|
sfwFilter: true,
|
||||||
|
useCustomYamlStringifier: true,
|
||||||
movieTemplate: '',
|
templates: true,
|
||||||
seriesTemplate: '',
|
customDateFormat: 'L',
|
||||||
gameTemplate: '',
|
|
||||||
wikiTemplate: '',
|
movieTemplate: '',
|
||||||
musicReleaseTemplate: '',
|
seriesTemplate: '',
|
||||||
boardgameTemplate: '',
|
gameTemplate: '',
|
||||||
|
wikiTemplate: '',
|
||||||
movieFileNameTemplate: '{{ title }} ({{ year }})',
|
musicReleaseTemplate: '',
|
||||||
seriesFileNameTemplate: '{{ title }} ({{ year }})',
|
boardgameTemplate: '',
|
||||||
gameFileNameTemplate: '{{ title }} ({{ year }})',
|
|
||||||
wikiFileNameTemplate: '{{ title }}',
|
movieFileNameTemplate: '{{ title }} ({{ year }})',
|
||||||
musicReleaseFileNameTemplate: '{{ title }} (by {{ ENUM:artists }} - {{ year }})',
|
seriesFileNameTemplate: '{{ title }} ({{ year }})',
|
||||||
boardgameFileNameTemplate: '{{ title }} ({{ year }})',
|
gameFileNameTemplate: '{{ title }} ({{ year }})',
|
||||||
|
wikiFileNameTemplate: '{{ title }}',
|
||||||
moviePropertyConversionRules: '',
|
musicReleaseFileNameTemplate: '{{ title }} (by {{ ENUM:artists }} - {{ year }})',
|
||||||
seriesPropertyConversionRules: '',
|
boardgameFileNameTemplate: '{{ title }} ({{ year }})',
|
||||||
gamePropertyConversionRules: '',
|
|
||||||
wikiPropertyConversionRules: '',
|
moviePropertyConversionRules: '',
|
||||||
musicReleasePropertyConversionRules: '',
|
seriesPropertyConversionRules: '',
|
||||||
boardgamePropertyConversionRules: '',
|
gamePropertyConversionRules: '',
|
||||||
|
wikiPropertyConversionRules: '',
|
||||||
movieFolder: 'Media DB/movies',
|
musicReleasePropertyConversionRules: '',
|
||||||
seriesFolder: 'Media DB/series',
|
boardgamePropertyConversionRules: '',
|
||||||
gameFolder: 'Media DB/games',
|
|
||||||
wikiFolder: 'Media DB/wiki',
|
movieFolder: 'Media DB/movies',
|
||||||
musicReleaseFolder: 'Media DB/music',
|
seriesFolder: 'Media DB/series',
|
||||||
boardgameFolder: 'Media DB/boardgames',
|
gameFolder: 'Media DB/games',
|
||||||
|
wikiFolder: 'Media DB/wiki',
|
||||||
propertyMappingModels: [],
|
musicReleaseFolder: 'Media DB/music',
|
||||||
};
|
boardgameFolder: 'Media DB/boardgames',
|
||||||
|
|
||||||
export const lockedPropertyMappings: string[] = ['type', 'id', 'dataSource'];
|
propertyMappingModels: [],
|
||||||
|
};
|
||||||
export function getDefaultSettings(plugin: MediaDbPlugin): MediaDbPluginSettings {
|
|
||||||
const defaultSettings = DEFAULT_SETTINGS;
|
export const lockedPropertyMappings: string[] = ['type', 'id', 'dataSource'];
|
||||||
|
|
||||||
// construct property mapping defaults
|
export function getDefaultSettings(plugin: MediaDbPlugin): MediaDbPluginSettings {
|
||||||
const propertyMappingModels: PropertyMappingModel[] = [];
|
const defaultSettings = DEFAULT_SETTINGS;
|
||||||
for (const mediaType of MEDIA_TYPES) {
|
|
||||||
const model: MediaTypeModel = plugin.mediaTypeManager.createMediaTypeModelFromMediaType({}, mediaType);
|
// construct property mapping defaults
|
||||||
const metadataObj = model.toMetaDataObject();
|
const propertyMappingModels: PropertyMappingModel[] = [];
|
||||||
// console.log(metadataObj);
|
for (const mediaType of MEDIA_TYPES) {
|
||||||
// console.log(model);
|
const model: MediaTypeModel = plugin.mediaTypeManager.createMediaTypeModelFromMediaType({}, mediaType);
|
||||||
|
const metadataObj = model.toMetaDataObject();
|
||||||
const propertyMappingModel: PropertyMappingModel = new PropertyMappingModel(mediaType);
|
// console.log(metadataObj);
|
||||||
|
// console.log(model);
|
||||||
for (const key of Object.keys(metadataObj)) {
|
|
||||||
propertyMappingModel.properties.push(new PropertyMapping(key, '', PropertyMappingOption.Default, lockedPropertyMappings.contains(key)));
|
const propertyMappingModel: PropertyMappingModel = new PropertyMappingModel(mediaType);
|
||||||
}
|
|
||||||
|
for (const key of Object.keys(metadataObj)) {
|
||||||
propertyMappingModels.push(propertyMappingModel);
|
propertyMappingModel.properties.push(new PropertyMapping(key, '', PropertyMappingOption.Default, lockedPropertyMappings.contains(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultSettings.propertyMappingModels = propertyMappingModels;
|
propertyMappingModels.push(propertyMappingModel);
|
||||||
return defaultSettings;
|
}
|
||||||
}
|
|
||||||
|
defaultSettings.propertyMappingModels = propertyMappingModels;
|
||||||
export class MediaDbSettingTab extends PluginSettingTab {
|
return defaultSettings;
|
||||||
plugin: MediaDbPlugin;
|
}
|
||||||
|
|
||||||
constructor(app: App, plugin: MediaDbPlugin) {
|
export class MediaDbSettingTab extends PluginSettingTab {
|
||||||
super(app, plugin);
|
plugin: MediaDbPlugin;
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
constructor(app: App, plugin: MediaDbPlugin) {
|
||||||
|
super(app, plugin);
|
||||||
display(): void {
|
this.plugin = plugin;
|
||||||
const { containerEl } = this;
|
}
|
||||||
|
|
||||||
containerEl.empty();
|
display(): void {
|
||||||
|
const { containerEl } = this;
|
||||||
containerEl.createEl('h2', { text: 'Media DB Plugin Settings' });
|
|
||||||
|
containerEl.empty();
|
||||||
new Setting(containerEl)
|
|
||||||
.setName('OMDb API key')
|
containerEl.createEl('h2', { text: 'Media DB Plugin Settings' });
|
||||||
.setDesc('API key for "www.omdbapi.com".')
|
|
||||||
.addText(cb => {
|
new Setting(containerEl)
|
||||||
cb.setPlaceholder('API key')
|
.setName('OMDb API key')
|
||||||
.setValue(this.plugin.settings.OMDbKey)
|
.setDesc('API key for "www.omdbapi.com".')
|
||||||
.onChange(data => {
|
.addText(cb => {
|
||||||
this.plugin.settings.OMDbKey = data;
|
cb.setPlaceholder('API key')
|
||||||
this.plugin.saveSettings();
|
.setValue(this.plugin.settings.OMDbKey)
|
||||||
});
|
.onChange(data => {
|
||||||
});
|
this.plugin.settings.OMDbKey = data;
|
||||||
|
this.plugin.saveSettings();
|
||||||
new Setting(containerEl)
|
});
|
||||||
.setName('SFW filter')
|
});
|
||||||
.setDesc('Only shows SFW results for APIs that offer filtering.')
|
|
||||||
.addToggle(cb => {
|
new Setting(containerEl)
|
||||||
cb.setValue(this.plugin.settings.sfwFilter).onChange(data => {
|
.setName('SFW filter')
|
||||||
this.plugin.settings.sfwFilter = data;
|
.setDesc('Only shows SFW results for APIs that offer filtering.')
|
||||||
this.plugin.saveSettings();
|
.addToggle(cb => {
|
||||||
});
|
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 => {
|
new Setting(containerEl)
|
||||||
cb.setValue(this.plugin.settings.useCustomYamlStringifier).onChange(data => {
|
.setName('YAML formatter')
|
||||||
this.plugin.settings.useCustomYamlStringifier = data;
|
.setDesc('Add optional quotation marks around strings in the metadata block.')
|
||||||
this.plugin.saveSettings();
|
.addToggle(cb => {
|
||||||
});
|
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 => {
|
new Setting(containerEl)
|
||||||
cb.setValue(this.plugin.settings.templates).onChange(data => {
|
.setName('Resolve {{ tags }} in templates')
|
||||||
this.plugin.settings.templates = data;
|
.setDesc('Whether to resolve {{ tags }} in templates. The spaces inside the curly braces are important.')
|
||||||
this.plugin.saveSettings();
|
.addToggle(cb => {
|
||||||
});
|
cb.setValue(this.plugin.settings.templates).onChange(data => {
|
||||||
});
|
this.plugin.settings.templates = data;
|
||||||
|
this.plugin.saveSettings();
|
||||||
containerEl.createEl('h3', { text: 'New File Location' });
|
});
|
||||||
// region new file location
|
});
|
||||||
new Setting(containerEl)
|
|
||||||
.setName('Movie Folder')
|
new Setting(containerEl)
|
||||||
.setDesc('Where newly imported movies should be places.')
|
.setName('Date format')
|
||||||
.addSearch(cb => {
|
.setDesc(fragWithHTML("Your custom date format. Use <em>\'YYYY-MM-DD\'</em> for example.<br>" +
|
||||||
new FolderSuggest(this.app, cb.inputEl);
|
"For more syntax, refer to <a href='https://momentjs.com/docs/#/displaying/format/'>format reference</a>.<br>" +
|
||||||
cb.setPlaceholder(DEFAULT_SETTINGS.movieFolder)
|
"Your current syntax looks like this: <b><a id='media-db-dateformat-preview' style='pointer-events: none; cursor: default; text-decoration: none;'>" +
|
||||||
.setValue(this.plugin.settings.movieFolder)
|
this.plugin.dateFormatter.getPreview() + "</a></b>"))
|
||||||
.onChange(data => {
|
.addText(cb => {
|
||||||
this.plugin.settings.movieFolder = data;
|
cb.setPlaceholder(DEFAULT_SETTINGS.customDateFormat)
|
||||||
this.plugin.saveSettings();
|
.setValue(this.plugin.settings.customDateFormat === DEFAULT_SETTINGS.customDateFormat ? '' : this.plugin.settings.customDateFormat)
|
||||||
});
|
.onChange(data => {
|
||||||
});
|
const newDateFormat = data ? data : DEFAULT_SETTINGS.customDateFormat;
|
||||||
|
this.plugin.settings.customDateFormat = newDateFormat;
|
||||||
new Setting(containerEl)
|
document.getElementById('media-db-dateformat-preview').textContent = this.plugin.dateFormatter.getPreview(newDateFormat); // update preview
|
||||||
.setName('Series Folder')
|
this.plugin.saveSettings();
|
||||||
.setDesc('Where newly imported series should be places.')
|
});
|
||||||
.addSearch(cb => {
|
});
|
||||||
new FolderSuggest(this.app, cb.inputEl);
|
|
||||||
cb.setPlaceholder(DEFAULT_SETTINGS.seriesFolder)
|
containerEl.createEl('h3', { text: 'New File Location' });
|
||||||
.setValue(this.plugin.settings.seriesFolder)
|
// region new file location
|
||||||
.onChange(data => {
|
new Setting(containerEl)
|
||||||
this.plugin.settings.seriesFolder = data;
|
.setName('Movie Folder')
|
||||||
this.plugin.saveSettings();
|
.setDesc('Where newly imported movies should be places.')
|
||||||
});
|
.addSearch(cb => {
|
||||||
});
|
new FolderSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder(DEFAULT_SETTINGS.movieFolder)
|
||||||
new Setting(containerEl)
|
.setValue(this.plugin.settings.movieFolder)
|
||||||
.setName('Game Folder')
|
.onChange(data => {
|
||||||
.setDesc('Where newly imported games should be places.')
|
this.plugin.settings.movieFolder = data;
|
||||||
.addSearch(cb => {
|
this.plugin.saveSettings();
|
||||||
new FolderSuggest(this.app, cb.inputEl);
|
});
|
||||||
cb.setPlaceholder(DEFAULT_SETTINGS.gameFolder)
|
});
|
||||||
.setValue(this.plugin.settings.gameFolder)
|
|
||||||
.onChange(data => {
|
new Setting(containerEl)
|
||||||
this.plugin.settings.gameFolder = data;
|
.setName('Series Folder')
|
||||||
this.plugin.saveSettings();
|
.setDesc('Where newly imported series should be places.')
|
||||||
});
|
.addSearch(cb => {
|
||||||
});
|
new FolderSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder(DEFAULT_SETTINGS.seriesFolder)
|
||||||
new Setting(containerEl)
|
.setValue(this.plugin.settings.seriesFolder)
|
||||||
.setName('Wiki Folder')
|
.onChange(data => {
|
||||||
.setDesc('Where newly imported wiki articles should be places.')
|
this.plugin.settings.seriesFolder = data;
|
||||||
.addSearch(cb => {
|
this.plugin.saveSettings();
|
||||||
new FolderSuggest(this.app, cb.inputEl);
|
});
|
||||||
cb.setPlaceholder(DEFAULT_SETTINGS.wikiFolder)
|
});
|
||||||
.setValue(this.plugin.settings.wikiFolder)
|
|
||||||
.onChange(data => {
|
new Setting(containerEl)
|
||||||
this.plugin.settings.wikiFolder = data;
|
.setName('Game Folder')
|
||||||
this.plugin.saveSettings();
|
.setDesc('Where newly imported games should be places.')
|
||||||
});
|
.addSearch(cb => {
|
||||||
});
|
new FolderSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder(DEFAULT_SETTINGS.gameFolder)
|
||||||
new Setting(containerEl)
|
.setValue(this.plugin.settings.gameFolder)
|
||||||
.setName('Music Folder')
|
.onChange(data => {
|
||||||
.setDesc('Where newly imported music should be places.')
|
this.plugin.settings.gameFolder = data;
|
||||||
.addSearch(cb => {
|
this.plugin.saveSettings();
|
||||||
new FolderSuggest(this.app, cb.inputEl);
|
});
|
||||||
cb.setPlaceholder(DEFAULT_SETTINGS.musicReleaseFolder)
|
});
|
||||||
.setValue(this.plugin.settings.musicReleaseFolder)
|
|
||||||
.onChange(data => {
|
new Setting(containerEl)
|
||||||
this.plugin.settings.musicReleaseFolder = data;
|
.setName('Wiki Folder')
|
||||||
this.plugin.saveSettings();
|
.setDesc('Where newly imported wiki articles should be places.')
|
||||||
});
|
.addSearch(cb => {
|
||||||
});
|
new FolderSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder(DEFAULT_SETTINGS.wikiFolder)
|
||||||
new Setting(containerEl)
|
.setValue(this.plugin.settings.wikiFolder)
|
||||||
.setName('Board Game Folder')
|
.onChange(data => {
|
||||||
.setDesc('Where newly imported board games should be places.')
|
this.plugin.settings.wikiFolder = data;
|
||||||
.addSearch(cb => {
|
this.plugin.saveSettings();
|
||||||
new FolderSuggest(this.app, cb.inputEl);
|
});
|
||||||
cb.setPlaceholder(DEFAULT_SETTINGS.boardgameFolder)
|
});
|
||||||
.setValue(this.plugin.settings.boardgameFolder)
|
|
||||||
.onChange(data => {
|
new Setting(containerEl)
|
||||||
this.plugin.settings.boardgameFolder = data;
|
.setName('Music Folder')
|
||||||
this.plugin.saveSettings();
|
.setDesc('Where newly imported music should be places.')
|
||||||
});
|
.addSearch(cb => {
|
||||||
});
|
new FolderSuggest(this.app, cb.inputEl);
|
||||||
// endregion
|
cb.setPlaceholder(DEFAULT_SETTINGS.musicReleaseFolder)
|
||||||
|
.setValue(this.plugin.settings.musicReleaseFolder)
|
||||||
containerEl.createEl('h3', { text: 'Template Settings' });
|
.onChange(data => {
|
||||||
// region templates
|
this.plugin.settings.musicReleaseFolder = data;
|
||||||
new Setting(containerEl)
|
this.plugin.saveSettings();
|
||||||
.setName('Movie template')
|
});
|
||||||
.setDesc('Template file to be used when creating a new note for a movie.')
|
});
|
||||||
.addSearch(cb => {
|
|
||||||
new FileSuggest(this.app, cb.inputEl);
|
new Setting(containerEl)
|
||||||
cb.setPlaceholder('Example: movieTemplate.md')
|
.setName('Board Game Folder')
|
||||||
.setValue(this.plugin.settings.movieTemplate)
|
.setDesc('Where newly imported board games should be places.')
|
||||||
.onChange(data => {
|
.addSearch(cb => {
|
||||||
this.plugin.settings.movieTemplate = data;
|
new FolderSuggest(this.app, cb.inputEl);
|
||||||
this.plugin.saveSettings();
|
cb.setPlaceholder(DEFAULT_SETTINGS.boardgameFolder)
|
||||||
});
|
.setValue(this.plugin.settings.boardgameFolder)
|
||||||
});
|
.onChange(data => {
|
||||||
|
this.plugin.settings.boardgameFolder = data;
|
||||||
new Setting(containerEl)
|
this.plugin.saveSettings();
|
||||||
.setName('Series template')
|
});
|
||||||
.setDesc('Template file to be used when creating a new note for a series.')
|
});
|
||||||
.addSearch(cb => {
|
// endregion
|
||||||
new FileSuggest(this.app, cb.inputEl);
|
|
||||||
cb.setPlaceholder('Example: seriesTemplate.md')
|
containerEl.createEl('h3', { text: 'Template Settings' });
|
||||||
.setValue(this.plugin.settings.seriesTemplate)
|
// region templates
|
||||||
.onChange(data => {
|
new Setting(containerEl)
|
||||||
this.plugin.settings.seriesTemplate = data;
|
.setName('Movie template')
|
||||||
this.plugin.saveSettings();
|
.setDesc('Template file to be used when creating a new note for a movie.')
|
||||||
});
|
.addSearch(cb => {
|
||||||
});
|
new FileSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder('Example: movieTemplate.md')
|
||||||
new Setting(containerEl)
|
.setValue(this.plugin.settings.movieTemplate)
|
||||||
.setName('Game template')
|
.onChange(data => {
|
||||||
.setDesc('Template file to be used when creating a new note for a game.')
|
this.plugin.settings.movieTemplate = data;
|
||||||
.addSearch(cb => {
|
this.plugin.saveSettings();
|
||||||
new FileSuggest(this.app, cb.inputEl);
|
});
|
||||||
cb.setPlaceholder('Example: gameTemplate.md')
|
});
|
||||||
.setValue(this.plugin.settings.gameTemplate)
|
|
||||||
.onChange(data => {
|
new Setting(containerEl)
|
||||||
this.plugin.settings.gameTemplate = data;
|
.setName('Series template')
|
||||||
this.plugin.saveSettings();
|
.setDesc('Template file to be used when creating a new note for a series.')
|
||||||
});
|
.addSearch(cb => {
|
||||||
});
|
new FileSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder('Example: seriesTemplate.md')
|
||||||
new Setting(containerEl)
|
.setValue(this.plugin.settings.seriesTemplate)
|
||||||
.setName('Wiki template')
|
.onChange(data => {
|
||||||
.setDesc('Template file to be used when creating a new note for a wiki entry.')
|
this.plugin.settings.seriesTemplate = data;
|
||||||
.addSearch(cb => {
|
this.plugin.saveSettings();
|
||||||
new FileSuggest(this.app, cb.inputEl);
|
});
|
||||||
cb.setPlaceholder('Example: wikiTemplate.md')
|
});
|
||||||
.setValue(this.plugin.settings.wikiTemplate)
|
|
||||||
.onChange(data => {
|
new Setting(containerEl)
|
||||||
this.plugin.settings.wikiTemplate = data;
|
.setName('Game template')
|
||||||
this.plugin.saveSettings();
|
.setDesc('Template file to be used when creating a new note for a game.')
|
||||||
});
|
.addSearch(cb => {
|
||||||
});
|
new FileSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder('Example: gameTemplate.md')
|
||||||
new Setting(containerEl)
|
.setValue(this.plugin.settings.gameTemplate)
|
||||||
.setName('Music Release template')
|
.onChange(data => {
|
||||||
.setDesc('Template file to be used when creating a new note for a music release.')
|
this.plugin.settings.gameTemplate = data;
|
||||||
.addSearch(cb => {
|
this.plugin.saveSettings();
|
||||||
new FileSuggest(this.app, cb.inputEl);
|
});
|
||||||
cb.setPlaceholder('Example: musicReleaseTemplate.md')
|
});
|
||||||
.setValue(this.plugin.settings.musicReleaseTemplate)
|
|
||||||
.onChange(data => {
|
new Setting(containerEl)
|
||||||
this.plugin.settings.musicReleaseTemplate = data;
|
.setName('Wiki template')
|
||||||
this.plugin.saveSettings();
|
.setDesc('Template file to be used when creating a new note for a wiki entry.')
|
||||||
});
|
.addSearch(cb => {
|
||||||
});
|
new FileSuggest(this.app, cb.inputEl);
|
||||||
|
cb.setPlaceholder('Example: wikiTemplate.md')
|
||||||
new Setting(containerEl)
|
.setValue(this.plugin.settings.wikiTemplate)
|
||||||
.setName('Board Game template')
|
.onChange(data => {
|
||||||
.setDesc('Template file to be used when creating a new note for a boardgame.')
|
this.plugin.settings.wikiTemplate = data;
|
||||||
.addSearch(cb => {
|
this.plugin.saveSettings();
|
||||||
new FileSuggest(this.app, cb.inputEl);
|
});
|
||||||
cb.setPlaceholder('Example: boardgameTemplate.md')
|
});
|
||||||
.setValue(this.plugin.settings.boardgameTemplate)
|
|
||||||
.onChange(data => {
|
new Setting(containerEl)
|
||||||
this.plugin.settings.boardgameTemplate = data;
|
.setName('Music Release template')
|
||||||
this.plugin.saveSettings();
|
.setDesc('Template file to be used when creating a new note for a music release.')
|
||||||
});
|
.addSearch(cb => {
|
||||||
});
|
new FileSuggest(this.app, cb.inputEl);
|
||||||
// endregion
|
cb.setPlaceholder('Example: musicReleaseTemplate.md')
|
||||||
|
.setValue(this.plugin.settings.musicReleaseTemplate)
|
||||||
containerEl.createEl('h3', { text: 'File Name Settings' });
|
.onChange(data => {
|
||||||
// region file name templates
|
this.plugin.settings.musicReleaseTemplate = data;
|
||||||
new Setting(containerEl)
|
this.plugin.saveSettings();
|
||||||
.setName('Movie file name template')
|
});
|
||||||
.setDesc('Template for the file name used when creating a new note for a movie.')
|
});
|
||||||
.addText(cb => {
|
|
||||||
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.movieFileNameTemplate}`)
|
new Setting(containerEl)
|
||||||
.setValue(this.plugin.settings.movieFileNameTemplate)
|
.setName('Board Game template')
|
||||||
.onChange(data => {
|
.setDesc('Template file to be used when creating a new note for a boardgame.')
|
||||||
this.plugin.settings.movieFileNameTemplate = data;
|
.addSearch(cb => {
|
||||||
this.plugin.saveSettings();
|
new FileSuggest(this.app, cb.inputEl);
|
||||||
});
|
cb.setPlaceholder('Example: boardgameTemplate.md')
|
||||||
});
|
.setValue(this.plugin.settings.boardgameTemplate)
|
||||||
|
.onChange(data => {
|
||||||
new Setting(containerEl)
|
this.plugin.settings.boardgameTemplate = data;
|
||||||
.setName('Series file name template')
|
this.plugin.saveSettings();
|
||||||
.setDesc('Template for the file name used when creating a new note for a series.')
|
});
|
||||||
.addText(cb => {
|
});
|
||||||
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.seriesFileNameTemplate}`)
|
// endregion
|
||||||
.setValue(this.plugin.settings.seriesFileNameTemplate)
|
|
||||||
.onChange(data => {
|
containerEl.createEl('h3', { text: 'File Name Settings' });
|
||||||
this.plugin.settings.seriesFileNameTemplate = data;
|
// region file name templates
|
||||||
this.plugin.saveSettings();
|
new Setting(containerEl)
|
||||||
});
|
.setName('Movie file name template')
|
||||||
});
|
.setDesc('Template for the file name used when creating a new note for a movie.')
|
||||||
|
.addText(cb => {
|
||||||
new Setting(containerEl)
|
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.movieFileNameTemplate}`)
|
||||||
.setName('Game file name template')
|
.setValue(this.plugin.settings.movieFileNameTemplate)
|
||||||
.setDesc('Template for the file name used when creating a new note for a game.')
|
.onChange(data => {
|
||||||
.addText(cb => {
|
this.plugin.settings.movieFileNameTemplate = data;
|
||||||
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.gameFileNameTemplate}`)
|
this.plugin.saveSettings();
|
||||||
.setValue(this.plugin.settings.gameFileNameTemplate)
|
});
|
||||||
.onChange(data => {
|
});
|
||||||
this.plugin.settings.gameFileNameTemplate = data;
|
|
||||||
this.plugin.saveSettings();
|
new Setting(containerEl)
|
||||||
});
|
.setName('Series file name template')
|
||||||
});
|
.setDesc('Template for the file name used when creating a new note for a series.')
|
||||||
|
.addText(cb => {
|
||||||
new Setting(containerEl)
|
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.seriesFileNameTemplate}`)
|
||||||
.setName('Wiki file name template')
|
.setValue(this.plugin.settings.seriesFileNameTemplate)
|
||||||
.setDesc('Template for the file name used when creating a new note for a wiki entry.')
|
.onChange(data => {
|
||||||
.addText(cb => {
|
this.plugin.settings.seriesFileNameTemplate = data;
|
||||||
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.wikiFileNameTemplate}`)
|
this.plugin.saveSettings();
|
||||||
.setValue(this.plugin.settings.wikiFileNameTemplate)
|
});
|
||||||
.onChange(data => {
|
});
|
||||||
this.plugin.settings.wikiFileNameTemplate = data;
|
|
||||||
this.plugin.saveSettings();
|
new Setting(containerEl)
|
||||||
});
|
.setName('Game file name template')
|
||||||
});
|
.setDesc('Template for the file name used when creating a new note for a game.')
|
||||||
|
.addText(cb => {
|
||||||
new Setting(containerEl)
|
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.gameFileNameTemplate}`)
|
||||||
.setName('Music Release file name template')
|
.setValue(this.plugin.settings.gameFileNameTemplate)
|
||||||
.setDesc('Template for the file name used when creating a new note for a music release.')
|
.onChange(data => {
|
||||||
.addText(cb => {
|
this.plugin.settings.gameFileNameTemplate = data;
|
||||||
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.musicReleaseFileNameTemplate}`)
|
this.plugin.saveSettings();
|
||||||
.setValue(this.plugin.settings.musicReleaseFileNameTemplate)
|
});
|
||||||
.onChange(data => {
|
});
|
||||||
this.plugin.settings.musicReleaseFileNameTemplate = data;
|
|
||||||
this.plugin.saveSettings();
|
new Setting(containerEl)
|
||||||
});
|
.setName('Wiki file name template')
|
||||||
});
|
.setDesc('Template for the file name used when creating a new note for a wiki entry.')
|
||||||
|
.addText(cb => {
|
||||||
new Setting(containerEl)
|
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.wikiFileNameTemplate}`)
|
||||||
.setName('Board Game file name template')
|
.setValue(this.plugin.settings.wikiFileNameTemplate)
|
||||||
.setDesc('Template for the file name used when creating a new note for a boardgame.')
|
.onChange(data => {
|
||||||
.addText(cb => {
|
this.plugin.settings.wikiFileNameTemplate = data;
|
||||||
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.boardgameFileNameTemplate}`)
|
this.plugin.saveSettings();
|
||||||
.setValue(this.plugin.settings.boardgameFileNameTemplate)
|
});
|
||||||
.onChange(data => {
|
});
|
||||||
this.plugin.settings.boardgameFileNameTemplate = data;
|
|
||||||
this.plugin.saveSettings();
|
new Setting(containerEl)
|
||||||
});
|
.setName('Music Release file name template')
|
||||||
});
|
.setDesc('Template for the file name used when creating a new note for a music release.')
|
||||||
// endregion
|
.addText(cb => {
|
||||||
|
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.musicReleaseFileNameTemplate}`)
|
||||||
// region Property Mappings
|
.setValue(this.plugin.settings.musicReleaseFileNameTemplate)
|
||||||
|
.onChange(data => {
|
||||||
containerEl.createEl('h3', { text: 'Property Mappings' });
|
this.plugin.settings.musicReleaseFileNameTemplate = data;
|
||||||
|
this.plugin.saveSettings();
|
||||||
const propertyMappingExplanation = containerEl.createEl('div');
|
});
|
||||||
propertyMappingExplanation.innerHTML = `
|
});
|
||||||
<p>Allow you to remap the metadata fields of newly created media db entries.</p>
|
|
||||||
<p>
|
new Setting(containerEl)
|
||||||
The different options are:
|
.setName('Board Game file name template')
|
||||||
<lu>
|
.setDesc('Template for the file name used when creating a new note for a boardgame.')
|
||||||
<li>"default": does no remapping and keeps the metadata field as it is</li>
|
.addText(cb => {
|
||||||
<li>"remap": renames the metadata field to what ever you specify</li>
|
cb.setPlaceholder(`Example: ${DEFAULT_SETTINGS.boardgameFileNameTemplate}`)
|
||||||
<li>"remove": removes the metadata field entirely</li>
|
.setValue(this.plugin.settings.boardgameFileNameTemplate)
|
||||||
</lu>
|
.onChange(data => {
|
||||||
</p>
|
this.plugin.settings.boardgameFileNameTemplate = data;
|
||||||
<p>
|
this.plugin.saveSettings();
|
||||||
Don't forget to save your changes using the save button for each individual category.
|
});
|
||||||
</p>`;
|
});
|
||||||
|
// endregion
|
||||||
new PropertyMappingModelsComponent({
|
|
||||||
target: this.containerEl,
|
// region Property Mappings
|
||||||
props: {
|
|
||||||
models: this.plugin.settings.propertyMappingModels.map(x => x.copy()),
|
containerEl.createEl('h3', { text: 'Property Mappings' });
|
||||||
save: (model: PropertyMappingModel): void => {
|
|
||||||
const propertyMappingModels: PropertyMappingModel[] = [];
|
const propertyMappingExplanation = containerEl.createEl('div');
|
||||||
|
propertyMappingExplanation.innerHTML = `
|
||||||
for (const model2 of this.plugin.settings.propertyMappingModels) {
|
<p>Allow you to remap the metadata fields of newly created media db entries.</p>
|
||||||
if (model2.type === model.type) {
|
<p>
|
||||||
propertyMappingModels.push(model);
|
The different options are:
|
||||||
} else {
|
<lu>
|
||||||
propertyMappingModels.push(model2);
|
<li>"default": does no remapping and keeps the metadata field as it is</li>
|
||||||
}
|
<li>"remap": renames the metadata field to what ever you specify</li>
|
||||||
}
|
<li>"remove": removes the metadata field entirely</li>
|
||||||
|
</lu>
|
||||||
this.plugin.settings.propertyMappingModels = propertyMappingModels;
|
</p>
|
||||||
new Notice(`MDB: Property Mappings for ${model.type} saved successfully.`);
|
<p>
|
||||||
this.plugin.saveSettings();
|
Don't forget to save your changes using the save button for each individual category.
|
||||||
},
|
</p>`;
|
||||||
},
|
|
||||||
});
|
new PropertyMappingModelsComponent({
|
||||||
|
target: this.containerEl,
|
||||||
// endregion
|
props: {
|
||||||
}
|
models: this.plugin.settings.propertyMappingModels.map(x => x.copy()),
|
||||||
}
|
save: (model: PropertyMappingModel): void => {
|
||||||
|
const propertyMappingModels: PropertyMappingModel[] = [];
|
||||||
|
|
||||||
|
for (const model2 of this.plugin.settings.propertyMappingModels) {
|
||||||
|
if (model2.type === model.type) {
|
||||||
|
propertyMappingModels.push(model);
|
||||||
|
} else {
|
||||||
|
propertyMappingModels.push(model2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.plugin.settings.propertyMappingModels = propertyMappingModels;
|
||||||
|
new Notice(`MDB: Property Mappings for ${model.type} saved successfully.`);
|
||||||
|
this.plugin.saveSettings();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
71
src/utils/DateFormatter.ts
Normal file
71
src/utils/DateFormatter.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
// obsidian already uses moment, so no need to package it twice!
|
||||||
|
// import { moment } from 'obsidian'; // doesn't work for release build
|
||||||
|
// obsidian uses a namespace-style import for moment, which ES6 doesn't allow anymore
|
||||||
|
const obsidian = require('obsidian');
|
||||||
|
const moment = obsidian.moment;
|
||||||
|
|
||||||
|
export class DateFormatter {
|
||||||
|
toFormat: string;
|
||||||
|
locale: string;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.toFormat = 'YYYY-MM-DD';
|
||||||
|
// get locale of this machine (e.g. en, en-gb, de, fr, etc.)
|
||||||
|
this.locale = new Intl.DateTimeFormat().resolvedOptions().locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
setFormat(format: string): void {
|
||||||
|
this.toFormat = format;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPreview(format?: string): string {
|
||||||
|
const today = moment();
|
||||||
|
|
||||||
|
if (!format) {
|
||||||
|
format = this.toFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
return today.locale(this.locale).format(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to format a given date string with the currently set date format.
|
||||||
|
* You can set a date format by calling `setFormat()`.
|
||||||
|
*
|
||||||
|
* @param dateString the date string to be formatted
|
||||||
|
* @param dateFormat the current format of `dateString`. When this is `null` and the actual format of the
|
||||||
|
* given date string is not `C2822` or `ISO` format, this function will try to guess the format by using the native `Date` module.
|
||||||
|
* @param locale the locale of `dateString`. This is needed when `dateString` includes a month or day name and its locale format differs
|
||||||
|
* from the locale of this machine.
|
||||||
|
* @returns formatted date string or null if `dateString` is not a valid date
|
||||||
|
*/
|
||||||
|
format(dateString: string, dateFormat?: string, locale: string = 'en'): string | null {
|
||||||
|
if (!dateString) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let date: moment.Moment;
|
||||||
|
|
||||||
|
if (!dateFormat) {
|
||||||
|
// reading date formats other then C2822 or ISO with moment is deprecated
|
||||||
|
// see https://momentjs.com/docs/#/parsing/string/
|
||||||
|
if (this.hasMomentFormat(dateString)) {
|
||||||
|
// expect C2822 or ISO format
|
||||||
|
date = moment(dateString);
|
||||||
|
} else {
|
||||||
|
// try to read date string with native Date
|
||||||
|
date = moment(new Date(dateString));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
date = moment(dateString, dateFormat, locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
// format date (if it is valid)
|
||||||
|
return date.isValid() ? date.locale(this.locale).format(this.toFormat) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private hasMomentFormat(dateString: string): boolean {
|
||||||
|
const date = moment(dateString, true); // strict mode
|
||||||
|
return date.isValid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -135,6 +135,8 @@ export function markdownTable(content: string[][]): string {
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const fragWithHTML = (html: string) => createFragment(frag => (frag.createDiv().innerHTML = html));
|
||||||
|
|
||||||
export function dateToString(date: Date): string {
|
export function dateToString(date: Date): string {
|
||||||
return `${date.getMonth() + 1}-${date.getDate()}-${date.getFullYear()}`;
|
return `${date.getMonth() + 1}-${date.getDate()}-${date.getFullYear()}`;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue