cleanup and reduced number of settings validations
This commit is contained in:
parent
68ec5135cc
commit
3db3496e0d
12 changed files with 171 additions and 297 deletions
|
|
@ -19,6 +19,8 @@ export class PropertyMappingModel {
|
|||
}
|
||||
|
||||
validate(): { res: boolean, err?: Error } {
|
||||
console.debug(`MDB | validated property mappings for ${this.type}`);
|
||||
|
||||
// check properties
|
||||
for (const property of this.properties) {
|
||||
const propertyValidation = property.validate();
|
||||
|
|
@ -89,28 +91,6 @@ export class PropertyMapping {
|
|||
this.newProperty = newProperty;
|
||||
this.mapping = mapping;
|
||||
this.locked = locked ?? false;
|
||||
|
||||
/*
|
||||
const conversionRuleParts = conversionRule.split('->');
|
||||
if (conversionRuleParts.length !== 2) {
|
||||
throw Error(`Conversion rule "${conversionRule}" may only have exactly one "->"`);
|
||||
}
|
||||
|
||||
let property = conversionRuleParts[0].trim();
|
||||
let newProperty = conversionRuleParts[1].trim();
|
||||
|
||||
if (!property || !containsOnlyLettersAndUnderscores(property)) {
|
||||
throw Error(`Error in conversion rule "${conversionRule}": property may not be empty and only contain letters and underscores.`);
|
||||
}
|
||||
|
||||
if (!newProperty || !containsOnlyLettersAndUnderscores(newProperty)) {
|
||||
throw Error(`Error in conversion rule "${conversionRule}": new property may not be empty and only contain letters and underscores.`);
|
||||
}
|
||||
|
||||
this.property = property;
|
||||
this.newProperty = newProperty;
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
validate(): { res: boolean, err?: Error } {
|
||||
|
|
|
|||
63
src/settings/PropertyMappingModelComponent.svelte
Normal file
63
src/settings/PropertyMappingModelComponent.svelte
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<script lang="ts">
|
||||
import {PropertyMappingModel, PropertyMappingOption, propertyMappingOptions} from './PropertyMapping';
|
||||
import {capitalizeFirstLetter} from '../utils/Utils';
|
||||
import Icon from './Icon.svelte';
|
||||
|
||||
export let model: PropertyMappingModel;
|
||||
export let save: (model: PropertyMappingModel) => void;
|
||||
|
||||
let validationResult: { res: boolean, err?: Error };
|
||||
|
||||
$: modelChanged(model);
|
||||
|
||||
function modelChanged(model: PropertyMappingModel) {
|
||||
validationResult = model.validate();
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
|
||||
<div class="media-db-plugin-property-mappings-model-container">
|
||||
<div class="setting-item-name">{capitalizeFirstLetter(model.type)}</div>
|
||||
<div class="media-db-plugin-property-mappings-container">
|
||||
{ #each model.properties as property }
|
||||
<div class="media-db-plugin-property-mapping-element">
|
||||
<div class="media-db-plugin-property-mapping-element-property-name-wrapper">
|
||||
<pre
|
||||
class="media-db-plugin-property-mapping-element-property-name"><code>{property.property}</code></pre>
|
||||
</div>
|
||||
{ #if property.locked }
|
||||
<div class="media-db-plugin-property-binding-text">
|
||||
property can not be remapped
|
||||
</div>
|
||||
{ :else }
|
||||
<select class="dropdown" bind:value={property.mapping}>
|
||||
{#each propertyMappingOptions as remappingOption}
|
||||
<option value={remappingOption}>
|
||||
{remappingOption}
|
||||
</option>
|
||||
{/each}
|
||||
</select>
|
||||
|
||||
{ #if property.mapping === PropertyMappingOption.Map }
|
||||
<Icon iconName="arrow-right"/>
|
||||
<div class="media-db-plugin-property-mapping-to">
|
||||
<input type="text" spellcheck="false" bind:value="{property.newProperty}">
|
||||
</div>
|
||||
{ /if }
|
||||
{ /if }
|
||||
</div>
|
||||
{ /each }
|
||||
</div>
|
||||
{ #if !validationResult?.res }
|
||||
<div class="media-db-plugin-property-mapping-validation">
|
||||
{validationResult?.err?.message}
|
||||
</div>
|
||||
{ /if }
|
||||
<button
|
||||
class="media-db-plugin-property-mappings-save-button {validationResult?.res ? 'mod-cta' : 'mod-muted'}"
|
||||
on:click={() => { if(model.validate().res) save(model) }}>Save
|
||||
</button>
|
||||
</div>
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
<script lang="ts">
|
||||
import {capitalizeFirstLetter} from '../utils/Utils';
|
||||
import {PropertyMappingModel, PropertyMappingOption, propertyMappingOptions} from './PropertyMapping';
|
||||
import Icon from './Icon.svelte';
|
||||
import {PropertyMappingModel} from './PropertyMapping';
|
||||
import PropertyMappingModelComponent from './PropertyMappingModelComponent.svelte';
|
||||
|
||||
export let models: PropertyMappingModel[] = [];
|
||||
|
||||
|
|
@ -11,108 +10,21 @@
|
|||
</script>
|
||||
|
||||
<style>
|
||||
.media-db-plugin-property-mappings-model-container {
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-radius: 5px;
|
||||
padding: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.media-db-plugin-property-mappings-container {
|
||||
margin: 10px 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.media-db-plugin-property-mapping-element {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.media-db-plugin-property-mapping-element-property-name-wrapper {
|
||||
min-width: 160px;
|
||||
background: var(--background-modifier-form-field);
|
||||
padding: 2px 5px;
|
||||
border-radius: 5px;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.media-db-plugin-property-mapping-element-property-name {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.media-db-plugin-property-mappings-save-button {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.media-db-plugin-property-mapping-to {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.media-db-plugin-property-mapping-validation {
|
||||
color: var(--text-error);
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="setting-item" style="display: flex; gap: 10px; flex-direction: column; align-items: stretch;">
|
||||
{ #each models as model }
|
||||
<div class="media-db-plugin-property-mappings-model-container">
|
||||
<div class="setting-item-name">{capitalizeFirstLetter(model.type)}</div>
|
||||
<div class="media-db-plugin-property-mappings-container">
|
||||
{ #each model.properties as property }
|
||||
<div class="media-db-plugin-property-mapping-element">
|
||||
<div class="media-db-plugin-property-mapping-element-property-name-wrapper">
|
||||
<pre
|
||||
class="media-db-plugin-property-mapping-element-property-name"><code>{property.property}</code></pre>
|
||||
</div>
|
||||
{#if property.locked}
|
||||
<div class="media-db-plugin-property-binding-text">
|
||||
property can not be remapped
|
||||
</div>
|
||||
{:else}
|
||||
<select class="dropdown" bind:value={property.mapping}>
|
||||
{#each propertyMappingOptions as remappingOption}
|
||||
<option value={remappingOption}>
|
||||
{remappingOption}
|
||||
</option>
|
||||
{/each}
|
||||
</select>
|
||||
|
||||
{#if property.mapping === PropertyMappingOption.Map}
|
||||
<Icon iconName="arrow-right"/>
|
||||
<div class="media-db-plugin-property-mapping-to">
|
||||
<input type="text" spellcheck="false" bind:value="{property.newProperty}">
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{ /each }
|
||||
</div>
|
||||
{ #if !model.validate().res }
|
||||
<div class="media-db-plugin-property-mapping-validation">
|
||||
{model.validate().err?.message}
|
||||
</div>
|
||||
{/if}
|
||||
<button
|
||||
class="media-db-plugin-property-mappings-save-button {model.validate().res ? 'mod-cta' : 'mod-muted'}"
|
||||
on:click={() => { if(model.validate().res) save(model) }}>Save
|
||||
</button>
|
||||
</div>
|
||||
{ /each }
|
||||
|
||||
<pre>{JSON.stringify(models, null, 4)}</pre>
|
||||
<PropertyMappingModelComponent model={model} save={save}></PropertyMappingModelComponent>
|
||||
{ /each }
|
||||
|
||||
<!--
|
||||
{ #each ICON_LIST as icon }
|
||||
<p>
|
||||
{icon} <Icon iconName="{icon}"/>
|
||||
</p>
|
||||
{/each}
|
||||
<pre>{JSON.stringify(models, null, 4)}</pre>
|
||||
|
||||
{ #each ICON_LIST as icon }
|
||||
<p>
|
||||
{icon} <Icon iconName="{icon}"/>
|
||||
</p>
|
||||
{/each}
|
||||
-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ export interface MediaDbPluginSettings {
|
|||
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||
const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
||||
folder: 'Media DB',
|
||||
OMDbKey: '',
|
||||
sfwFilter: true,
|
||||
|
|
@ -70,63 +70,7 @@ export const DEFAULT_SETTINGS: MediaDbPluginSettings = {
|
|||
musicReleasePropertyConversionRules: '',
|
||||
boardgamePropertyConversionRules: '',
|
||||
|
||||
propertyMappingModels: [
|
||||
/*
|
||||
{
|
||||
type: MediaType.Movie,
|
||||
properties: [
|
||||
new PropertyMapping('type', '', PropertyMappingOption.Default, true),
|
||||
new PropertyMapping('subType', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('title', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('englishTitle', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('year', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('dataSource', '', PropertyMappingOption.Default, true),
|
||||
new PropertyMapping('url', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('id', '', PropertyMappingOption.Default, true),
|
||||
|
||||
new PropertyMapping('genres', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('producer', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('duration', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('onlineRating', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('image', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('released', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('premiere', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('watched', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('lastWatched', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('personalRating', '', PropertyMappingOption.Default),
|
||||
],
|
||||
},
|
||||
{
|
||||
type: MediaType.Series,
|
||||
properties: [
|
||||
new PropertyMapping('type', '', PropertyMappingOption.Default, true),
|
||||
new PropertyMapping('subType', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('title', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('englishTitle', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('year', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('dataSource', '', PropertyMappingOption.Default, true),
|
||||
new PropertyMapping('url', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('id', '', PropertyMappingOption.Default, true),
|
||||
|
||||
new PropertyMapping('genres', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('studios', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('episodes', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('duration', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('onlineRating', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('image', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('released', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('airing', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('airedFrom', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('airedTo', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('watched', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('lastWatched', '', PropertyMappingOption.Default),
|
||||
new PropertyMapping('personalRating', '', PropertyMappingOption.Default),
|
||||
],
|
||||
},
|
||||
|
||||
*/
|
||||
],
|
||||
|
||||
propertyMappingModels: [],
|
||||
};
|
||||
|
||||
export const lockedPropertyMappings: string[] = ['type', 'id', 'dataSource'];
|
||||
|
|
@ -387,89 +331,13 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
});
|
||||
// endregion
|
||||
|
||||
containerEl.createEl('h3', {text: 'Property Mappings'});
|
||||
// region Property Mappings
|
||||
/*
|
||||
new Setting(containerEl)
|
||||
.setName('Movie model property mappings')
|
||||
.setDesc('Mappings for the property names of a movie.')
|
||||
.addTextArea(cb => {
|
||||
cb.setPlaceholder(`Example: \ntitle -> name\nyear -> releaseYear`)
|
||||
.setValue(this.plugin.settings.moviePropertyConversionRules)
|
||||
.onChange(data => {
|
||||
this.plugin.settings.moviePropertyConversionRules = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Series model property mappings')
|
||||
.setDesc('Mappings for the property names of a series.')
|
||||
.addTextArea(cb => {
|
||||
cb.setPlaceholder(`Example: \ntitle -> name\nyear -> releaseYear`)
|
||||
.setValue(this.plugin.settings.seriesPropertyConversionRules)
|
||||
.onChange(data => {
|
||||
this.plugin.settings.seriesPropertyConversionRules = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Game model property mappings')
|
||||
.setDesc('Mappings for the property names of a game.')
|
||||
.addTextArea(cb => {
|
||||
cb.setPlaceholder(`Example: \ntitle -> name\nyear -> releaseYear`)
|
||||
.setValue(this.plugin.settings.gamePropertyConversionRules)
|
||||
.onChange(data => {
|
||||
this.plugin.settings.gamePropertyConversionRules = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Wiki model property mappings')
|
||||
.setDesc('Mappings for the property names of a wiki entry.')
|
||||
.addTextArea(cb => {
|
||||
cb.setPlaceholder(`Example: \ntitle -> name\nyear -> releaseYear`)
|
||||
.setValue(this.plugin.settings.wikiPropertyConversionRules)
|
||||
.onChange(data => {
|
||||
this.plugin.settings.wikiPropertyConversionRules = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Music Release model property mappings')
|
||||
.setDesc('Mappings for the property names of a music release.')
|
||||
.addTextArea(cb => {
|
||||
cb.setPlaceholder(`Example: \ntitle -> name\nyear -> releaseYear`)
|
||||
.setValue(this.plugin.settings.musicReleasePropertyConversionRules)
|
||||
.onChange(data => {
|
||||
this.plugin.settings.musicReleasePropertyConversionRules = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Board Game model property mappings')
|
||||
.setDesc('Mappings for the property names of a boardgame.')
|
||||
.addTextArea(cb => {
|
||||
cb.setPlaceholder(`Example: \ntitle -> name\nyear -> releaseYear`)
|
||||
.setValue(this.plugin.settings.boardgamePropertyConversionRules)
|
||||
.onChange(data => {
|
||||
this.plugin.settings.boardgamePropertyConversionRules = data;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
*/
|
||||
// endregion
|
||||
|
||||
console.log(this.plugin.settings.propertyMappingModels);
|
||||
// console.log(getDefaultSettings(this.plugin));
|
||||
containerEl.createEl('h3', {text: 'Property Mappings'});
|
||||
|
||||
let propertyMappingExplanation = containerEl.createEl('div');
|
||||
propertyMappingExplanation.innerHTML = `<p>Allow you to remap the metadata fields of newly created media db entries.</p>
|
||||
propertyMappingExplanation.innerHTML = `
|
||||
<p>Allow you to remap the metadata fields of newly created media db entries.</p>
|
||||
<p>
|
||||
The different options are:
|
||||
<lu>
|
||||
|
|
@ -477,6 +345,9 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
<li>"remap": renames the metadata field to what ever you specify</li>
|
||||
<li>"remove": removes the metadata field entirely</li>
|
||||
</lu>
|
||||
</p>
|
||||
<p>
|
||||
Don't forget to save your changes using the save button for each individual category.
|
||||
</p>`;
|
||||
|
||||
|
||||
|
|
@ -502,6 +373,8 @@ export class MediaDbSettingTab extends PluginSettingTab {
|
|||
},
|
||||
});
|
||||
|
||||
// endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue