Improve Angular project structure and code organization (#1328)
This commit is contained in:
+280
@@ -0,0 +1,280 @@
|
||||
<div class="main-container enclosing-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-file"></i>
|
||||
File Naming Patterns
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
Configure automatic file organization using metadata placeholders. Patterns are applied when uploading files, moving files within your library, and after metadata updates.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-content">
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-cog"></i>
|
||||
Default File Naming Pattern
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
This pattern serves as the fallback when no library-specific override is configured.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="form-field">
|
||||
<div class="library-header pb-2">
|
||||
<i [class]="'pi pi-bolt'"></i>
|
||||
<span class="library-name">Default Pattern</span>
|
||||
</div>
|
||||
<div class="pattern-input-group">
|
||||
<input
|
||||
pInputText
|
||||
id="defaultPattern"
|
||||
[(ngModel)]="defaultPattern"
|
||||
placeholder="e.g., {title} - {authors}"
|
||||
(input)="onDefaultPatternChange(defaultPattern)"
|
||||
class="w-full"/>
|
||||
<p-button
|
||||
label="Save"
|
||||
icon="pi pi-save"
|
||||
(onClick)="savePatterns()"
|
||||
severity="success"
|
||||
[outlined]="true"
|
||||
[disabled]="!!defaultErrorMessage">
|
||||
</p-button>
|
||||
</div>
|
||||
@if (defaultErrorMessage) {
|
||||
<div class="error-message">{{ defaultErrorMessage }}</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="preview-section">
|
||||
<div class="preview-item">
|
||||
<span class="preview-label">Preview:</span>
|
||||
<span class="preview-value">{{ generateDefaultPreview() }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-folder"></i>
|
||||
Library-Specific Overrides
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
Define custom naming patterns for specific libraries. Leave empty to use the default pattern.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="library-patterns">
|
||||
@for (library of libraries; track library.id) {
|
||||
<div class="library-pattern-item">
|
||||
<div class="library-header">
|
||||
<i [class]="'pi pi-' + library.icon"></i>
|
||||
<span class="library-name">{{ library.name }}</span>
|
||||
</div>
|
||||
<div class="library-input-group">
|
||||
<input
|
||||
pInputText
|
||||
[(ngModel)]="library.fileNamingPattern"
|
||||
placeholder="Leave empty to use default pattern"
|
||||
(input)="onLibraryPatternChange(library)"
|
||||
class="w-full"/>
|
||||
<p-button
|
||||
label="Clear"
|
||||
(onClick)="clearLibraryPattern(library)"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
[disabled]="!library.fileNamingPattern">
|
||||
</p-button>
|
||||
</div>
|
||||
<div class="preview-section">
|
||||
<span class="preview-label">Preview:</span>
|
||||
<span class="preview-value">{{ generateLibraryPreview(library) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<p-button
|
||||
label="Save All Library Patterns"
|
||||
(onClick)="saveLibraryPatterns()"
|
||||
severity="success"
|
||||
icon="pi pi-save"
|
||||
[outlined]="true">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
Available Placeholders
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
Use placeholders to dynamically insert book metadata into file names and folder paths. These will be replaced with actual values when uploading or moving files.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="placeholders-info">
|
||||
<div class="placeholders-grid">
|
||||
<div class="placeholders-list">
|
||||
<h4 class="subsection-title">Available Placeholders</h4>
|
||||
<ul>
|
||||
<li><code class="placeholder-code">{{ '{title}' }}</code> – Book title</li>
|
||||
<li><code class="placeholder-code">{{ '{subtitle}' }}</code> – Book subtitle</li>
|
||||
<li><code class="placeholder-code">{{ '{authors}' }}</code> – Author(s)</li>
|
||||
<li><code class="placeholder-code">{{ '{year}' }}</code> – Full year (e.g. 2025)</li>
|
||||
<li><code class="placeholder-code">{{ '{series}' }}</code> – Series name</li>
|
||||
<li><code class="placeholder-code">{{ '{seriesIndex}' }}</code> – Series index (e.g. 01)</li>
|
||||
<li><code class="placeholder-code">{{ '{language}' }}</code> – Language code (e.g. en)</li>
|
||||
<li><code class="placeholder-code">{{ '{publisher}' }}</code> – Publisher name</li>
|
||||
<li><code class="placeholder-code">{{ '{isbn}' }}</code> – ISBN number</li>
|
||||
<li><code class="placeholder-code">{{ '{currentFilename}' }}</code> Original file name (with extension)</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="optional-blocks-info">
|
||||
<h4 class="subsection-title">Optional blocks</h4>
|
||||
<p>
|
||||
Surround parts of your pattern with angle brackets
|
||||
<code class="placeholder-code">{{ '{<...>}' }}</code>
|
||||
<br>
|
||||
to make them optional. If any placeholder inside the block has no value, the whole block is excluded.
|
||||
</p>
|
||||
<div class="example-section">
|
||||
<p class="example-label">Example:</p>
|
||||
<p><code class="placeholder-code">{{ '{<{seriesIndex} - >{title}' }}</code></p>
|
||||
<ul class="example-list">
|
||||
<li><code>01 - Dune</code> (if <code class="placeholder-code">{{ '{seriesIndex}' }}</code> exists)</li>
|
||||
<li><code>Dune</code> (if <code class="placeholder-code">{{ '{seriesIndex}' }}</code> is missing)</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-eye"></i>
|
||||
Example Patterns & Output
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
See how different patterns work with sample book metadata and learn best practices for organizing your library.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="examples-section">
|
||||
<div class="example-category">
|
||||
<h4 class="subsection-title">Examples with Full Metadata</h4>
|
||||
<div class="metadata-sample">
|
||||
<span>title: <code>Harry Potter and the Sorcerer's Stone</code></span>
|
||||
<span>subtitle: <code>The Boy Who Lived</code></span>
|
||||
<span>authors: <code>J.K. Rowling</code></span>
|
||||
<span>series: <code>Harry Potter</code></span>
|
||||
<span>seriesIndex: <code>01</code></span>
|
||||
<span>year: <code>1997</code></span>
|
||||
<span>currentFilename: <code>harry1_original.epub</code></span>
|
||||
</div>
|
||||
|
||||
<div class="example-list">
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Basic pattern:</strong> <code>{{ '{authors} - {title}' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>J.K. Rowling - Harry Potter and the Sorcerer's Stone.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Pattern with punctuation:</strong> <code>{{ '{title}: {series}' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>Harry Potter and the Sorcerer's Stone: Harry Potter.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Series in folder path:</strong> <code>{{ '{authors}/{series}/{seriesIndex} - {title}' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>J.K. Rowling/Harry Potter/01 - Harry Potter and the Sorcerer's Stone.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Folder only:</strong> <code>{{ '{title}/' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>/Harry Potter and the Sorcerer's Stone/harry1_original.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Absolute path:</strong> <code>{{ '/{authors}/{title}' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>/J.K. Rowling/Harry Potter and the Sorcerer's Stone.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Reuse original filename in path:</strong> <code>{{ '{authors}/{series}/{currentFilename}' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>J.K. Rowling/Harry Potter/harry1_original.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Title + Subtitle:</strong> <code>{{ '{title}: {subtitle}' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>Harry Potter and the Sorcerer's Stone: The Boy Who Lived.epub</code></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="example-category">
|
||||
<h4 class="subsection-title">Examples with Missing Optional Fields</h4>
|
||||
<div class="metadata-sample">
|
||||
<span>title: <code>Project Hail Mary</code></span>
|
||||
<span>subtitle: <code>(not provided)</code></span>
|
||||
<span>authors: <code>Andy Weir</code></span>
|
||||
<span>year: <code>2021</code></span>
|
||||
<span>series: <code>(not provided)</code></span>
|
||||
<span>seriesIndex: <code>(not provided)</code></span>
|
||||
<span>currentFilename: <code>project_hail_mary_final.epub</code></span>
|
||||
</div>
|
||||
|
||||
<div class="example-list">
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Pattern with optional blocks:</strong> <code>{{ '{authors}/<{series}/><{seriesIndex}. >{title}< ({year})>' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>Andy Weir/Project Hail Mary (2021).epub</code></p>
|
||||
</div>
|
||||
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Fallback with seriesIndex and dash:</strong> <code>{{ '<{seriesIndex}. >{title}< - {authors}>' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>Project Hail Mary - Andy Weir.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Brackets & punctuation fallback:</strong> <code>{{ '<[{series}] >{title} - {authors}' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>Project Hail Mary - Andy Weir.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Series + punctuation fallback:</strong> <code>{{ '<{series}: >{title} by {authors}' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>Project Hail Mary by Andy Weir.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Use original filename with year suffix:</strong> <code>{{ '{authors}/{year}__{currentFilename}' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>Andy Weir/2021__project_hail_mary_final.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div class="example-item">
|
||||
<p class="example-pattern"><strong>Title + Subtitle fallback:</strong> <code>{{ '{title}<: {subtitle}>' }}</code></p>
|
||||
<p class="example-output"><strong>Output:</strong> <code>Project Hail Mary.epub</code></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+408
@@ -0,0 +1,408 @@
|
||||
.main-container {
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
height: calc(100dvh - 10.5rem);
|
||||
overflow-y: auto;
|
||||
border-width: 1px;
|
||||
border-radius: 0.5rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
height: calc(100dvh - 11.65rem);
|
||||
}
|
||||
}
|
||||
|
||||
.enclosing-container {
|
||||
border-color: var(--p-content-border-color);
|
||||
background: var(--p-content-background);
|
||||
}
|
||||
|
||||
.settings-header {
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.settings-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.75rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3rem;
|
||||
}
|
||||
|
||||
.preferences-section {
|
||||
@media (min-width: 768px) {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.5rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.section-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 8px;
|
||||
background: var(--p-content-background);
|
||||
padding: 1.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
padding: 1rem;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.form-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
label {
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.pattern-input-group {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: var(--p-red-500);
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.preview-section {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.preview-label {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.preview-value {
|
||||
color: var(--p-green-500);
|
||||
font-size: 0.8rem;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.library-patterns {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.library-pattern-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
border: 1px solid var(--p-surface-800);
|
||||
border-left: 3px solid var(--p-primary-color);
|
||||
border-radius: 6px;
|
||||
background: var(--p-surface-900);
|
||||
padding: 1rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.library-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.library-name {
|
||||
font-weight: 500;
|
||||
color: var(--p-text-color);
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
.library-input-group {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
justify-content: stretch;
|
||||
|
||||
p-button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.subsection-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.placeholders-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.placeholders-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
|
||||
code {
|
||||
padding: 0.125rem 0.25rem;
|
||||
border-radius: 3px;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.placeholders-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 2rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
gap: 1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.placeholders-list {
|
||||
ul {
|
||||
list-style: disc;
|
||||
padding-left: 1.5rem;
|
||||
margin: 0;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
padding-left: 1rem;
|
||||
}
|
||||
|
||||
li {
|
||||
color: var(--p-text-color);
|
||||
font-size: 0.875rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.placeholder-code {
|
||||
color: var(--p-orange-400);
|
||||
padding: 0.125rem 0.25rem;
|
||||
border-radius: 3px;
|
||||
font-size: 0.75rem;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.optional-blocks-info {
|
||||
p {
|
||||
color: var(--p-text-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.example-section {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.example-label {
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.example-list {
|
||||
list-style: disc;
|
||||
padding-left: 1.5rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
padding-left: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
li {
|
||||
color: var(--p-text-color);
|
||||
font-size: 0.875rem;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.examples-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
gap: 1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.example-category {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.metadata-sample {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
background: var(--p-surface-800);
|
||||
padding: 1rem;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 1rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
|
||||
code {
|
||||
color: var(--p-text-color);
|
||||
padding: 0.125rem 0.25rem;
|
||||
border-radius: 3px;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.example-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.example-item {
|
||||
background: var(--p-surface-800);
|
||||
padding: 1rem;
|
||||
border-radius: 6px;
|
||||
border-left: 3px solid var(--p-primary-color);
|
||||
|
||||
@media (max-width: 767px) {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.example-pattern {
|
||||
font-size: 0.875rem;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
strong {
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
code {
|
||||
color: var(--p-text-muted-color);
|
||||
padding: 0.125rem 0.25rem;
|
||||
border-radius: 3px;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.example-output {
|
||||
font-size: 0.875rem;
|
||||
margin: 0;
|
||||
|
||||
strong {
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
code {
|
||||
color: var(--p-text-muted-color);
|
||||
padding: 0.125rem 0.25rem;
|
||||
border-radius: 3px;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {AppSettingsService} from '../../../shared/service/app-settings.service';
|
||||
import {forkJoin, Observable, of} from 'rxjs';
|
||||
import {AppSettingKey, AppSettings} from '../../../shared/model/app-settings.model';
|
||||
import {catchError, filter, take} from 'rxjs/operators';
|
||||
import {Library} from '../../book/model/library.model';
|
||||
import {LibraryService} from '../../book/service/library.service';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Divider} from 'primeng/divider';
|
||||
|
||||
@Component({
|
||||
selector: 'app-file-naming-pattern',
|
||||
templateUrl: './file-naming-pattern.component.html',
|
||||
standalone: true,
|
||||
imports: [FormsModule, Button, InputText, Divider],
|
||||
styleUrls: ['./file-naming-pattern.component.scss'],
|
||||
})
|
||||
export class FileNamingPatternComponent implements OnInit {
|
||||
readonly exampleMetadata: Record<string, string> = {
|
||||
title: "Harry Potter and the Sorcerer's Stone",
|
||||
subtitle: 'The Boy Who Lived',
|
||||
authors: 'J.K. Rowling',
|
||||
year: '1997',
|
||||
series: 'Harry Potter',
|
||||
seriesIndex: '01',
|
||||
language: 'en',
|
||||
publisher: 'Bloomsbury',
|
||||
isbn: '9780747532699',
|
||||
};
|
||||
|
||||
defaultPattern = '';
|
||||
libraries: Library[] = [];
|
||||
defaultErrorMessage = '';
|
||||
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private messageService = inject(MessageService);
|
||||
private libraryService = inject(LibraryService);
|
||||
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.appSettings$
|
||||
.pipe(filter((settings) => settings != null), take(1))
|
||||
.subscribe((settings) => {
|
||||
this.defaultPattern = settings?.uploadPattern ?? '';
|
||||
});
|
||||
|
||||
this.libraryService.libraryState$
|
||||
.pipe(filter(state => state.loaded && !!state.libraries))
|
||||
.subscribe(state => {
|
||||
this.libraries = state.libraries ?? [];
|
||||
});
|
||||
}
|
||||
|
||||
private replacePlaceholders(pattern: string, values: Record<string, string>): string {
|
||||
pattern = pattern.replace(/<([^<>]+)>/g, (_, block) => {
|
||||
const placeholders = [...block.matchAll(/{(.*?)}/g)].map((m) => m[1]);
|
||||
const allHaveValues = placeholders.every((key) => values[key]?.trim());
|
||||
return allHaveValues
|
||||
? block.replace(/{(.*?)}/g, (_: string, key: string) => values[key] ?? '')
|
||||
: '';
|
||||
});
|
||||
return pattern.replace(/{(.*?)}/g, (_, key) => values[key] ?? '').trim();
|
||||
}
|
||||
|
||||
private appendExtensionIfMissing(path: string, ext = '.pdf'): string {
|
||||
const lastSegment = path.split('/').pop() ?? '';
|
||||
const hasExtension = /\.[a-z0-9]{2,5}$/i.test(lastSegment);
|
||||
return hasExtension ? path : path + ext;
|
||||
}
|
||||
|
||||
private generatePreview(pattern: string): string {
|
||||
let path = this.replacePlaceholders(pattern || '', this.exampleMetadata);
|
||||
|
||||
if (!path) return '/original_filename.pdf';
|
||||
if (path.endsWith('/')) return path + 'original_filename.pdf';
|
||||
if (path.includes('{originalFilename}')) {
|
||||
path = path.replace('{originalFilename}', 'original_filename.pdf');
|
||||
return path.startsWith('/') ? path : `/${path}`;
|
||||
}
|
||||
path = this.appendExtensionIfMissing(path);
|
||||
return path.startsWith('/') ? path : `/${path}`;
|
||||
}
|
||||
|
||||
generateDefaultPreview(): string {
|
||||
return this.generatePreview(this.defaultPattern);
|
||||
}
|
||||
|
||||
generateLibraryPreview(library: Library): string {
|
||||
return this.generatePreview(library.fileNamingPattern || this.defaultPattern);
|
||||
}
|
||||
|
||||
validatePattern(pattern: string): boolean {
|
||||
const validPatternRegex = /^[\w\s\-{}\/().<>.,:'"]*$/;
|
||||
return validPatternRegex.test(pattern);
|
||||
}
|
||||
|
||||
onDefaultPatternChange(pattern: string): void {
|
||||
this.defaultPattern = pattern;
|
||||
this.defaultErrorMessage = this.validatePattern(pattern) ? '' : 'Pattern contains invalid characters.';
|
||||
}
|
||||
|
||||
onLibraryPatternChange(library: Library): void {
|
||||
// Optionally add per-library validation here
|
||||
}
|
||||
|
||||
clearLibraryPattern(library: Library): void {
|
||||
library.fileNamingPattern = '';
|
||||
}
|
||||
|
||||
savePatterns(): void {
|
||||
if (this.defaultErrorMessage) {
|
||||
this.showMessage('error', 'Invalid Pattern', 'Please fix errors before saving.');
|
||||
return;
|
||||
}
|
||||
this.appSettingsService
|
||||
.saveSettings([
|
||||
{ key: AppSettingKey.UPLOAD_FILE_PATTERN, newValue: this.defaultPattern },
|
||||
])
|
||||
.subscribe({
|
||||
next: () => this.showMessage('success', 'Settings Saved', 'The default pattern was successfully saved!'),
|
||||
error: () => this.showMessage('error', 'Error', 'There was an error saving the settings.'),
|
||||
});
|
||||
}
|
||||
|
||||
saveLibraryPatterns(): void {
|
||||
const patchRequests = this.libraries.map(library =>
|
||||
this.libraryService.updateLibraryFileNamingPattern(library.id!, library.fileNamingPattern || '').pipe(
|
||||
catchError(() => of(null))
|
||||
)
|
||||
);
|
||||
forkJoin(patchRequests).subscribe(results => {
|
||||
const failures = results.filter(result => result === null);
|
||||
if (failures.length === 0) {
|
||||
this.showMessage('success', 'Library Patterns Saved', 'Library-specific patterns were successfully saved!');
|
||||
} else {
|
||||
this.showMessage('error', 'Error', `Failed to save ${failures.length} library pattern(s).`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private showMessage(severity: 'success' | 'error', summary: string, detail: string): void {
|
||||
this.messageService.add({ severity, summary, detail });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user