Skip to content

Commit 21fb31f

Browse files
committed
Make trailing model ID compulsory in folder names
safer, less confusing UI. Only thing is, will people mind?
1 parent 41d6ab6 commit 21fb31f

File tree

15 files changed

+48
-62
lines changed

15 files changed

+48
-62
lines changed

app/models/concerns/path_builder.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module PathBuilder
22
extend ActiveSupport::Concern
33

44
def formatted_path
5-
SiteSettings.model_path_template.gsub(/{.+?}/) do |token|
5+
path = SiteSettings.model_path_template.gsub(/{.+?}/) do |token|
66
case token
77
when "{tags}"
88
(tags.count > 0) ?
@@ -15,11 +15,12 @@ def formatted_path
1515
when "{modelName}"
1616
path_component(self)
1717
when "{modelId}"
18-
"##{id}"
18+
"" # Deprecated, now always added below; kept for compatibility
1919
else
2020
token
2121
end
2222
end
23+
path + "##{id}"
2324
end
2425

2526
private

app/models/site_settings.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class SiteSettings < RailsSettings::Base
77
field :model_tags_stop_words_locale, type: :string, default: "en"
88
field :model_tags_custom_stop_words, type: :array, default: SupportedMimeTypes.indexable_extensions
99
field :model_tags_auto_tag_new, type: :string, default: "!new"
10-
field :model_path_template, type: :string, default: "{tags}/{modelName}{modelId}"
10+
field :model_path_template, type: :string, default: "{tags}/{modelName}"
1111
field :model_ignored_files, type: :array, default: [
1212
/^\.[^\.]+/, # Hidden files starting with .
1313
/.*\/@eaDir\/.*/, # Synology temp files

app/services/path_parser_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def path_parse_pattern
2828
when "{modelName}"
2929
"(?<model_name>[[:print:]&&[^/]]*?)"
3030
when "{modelId}"
31-
"(?<model_id>#[[:digit:]]+)?"
31+
"" # Always detected by default, moved below, kept for compatibility
3232
else
3333
"[[:print:]&&[^/]]*"
3434
end
35-
} + "$")
35+
} + "(?<model_id>#[[:digit:]]+)?" + "$")
3636
end
3737
end

app/views/settings/_folder_settings.html.erb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818
<li>
1919
<code>{modelName}</code>: <%= t ".tokens.model_name" %>
2020
</li>
21-
<li>
22-
<code>{modelId}</code>: <%= t ".tokens.model_id" %>
23-
</li>
2421
</ul>
2522
<div class="row mb-2">
2623
<%= form.label nil, t(".model_path_template.label"), for: "folders[model_path_template]", class: "col-sm-4 col-form-label" %>
2724
<div class="col-sm-8 form-check form-switch">
28-
<%= form.text_field "folders[model_path_template]", value: SiteSettings.model_path_template, class: "form-control" %>
25+
<%= form.text_field "folders[model_path_template]", value: SiteSettings.model_path_template.gsub("{modelId}",""), class: "form-control" %>
2926
</div>
3027
</div>
3128
<div class="row mb-2">

config/locales/settings/cs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ cs:
6666
tokens:
6767
collection: Název kolekce, ve které se model nachází, je-li nastavena.
6868
creator: Jméno autora, je-li nastaveno.
69-
model_id: Jedinečný číselný identifikátor modelu. Důrazně doporučujeme, aby byl vždy uveden na konci šablony, aby se předešlo konfliktům názvů na disku.
7069
model_name: Verze názvu modelu bezpečná pro souborový systém.
7170
tags_html: 'řada vnořených složek, jedna pro každý štítek, uspořádaných podle oblíbenosti štítků. Například: <code>fantasy/lidé/čarodějové</code>'
7271
general:

config/locales/settings/de.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ de:
6666
tokens:
6767
collection: Der Titel der Sammlung, in der sich das Modell befindet, falls festgelegt.
6868
creator: Der Name des Erstellers, falls festgelegt.
69-
model_id: Ein eindeutiger numerischer Bezeichner für das Modell. Wir empfehlen dringend, diese Kennung immer am Ende der Vorlage anzugeben, um Namenskonflikte zu vermeiden.
7069
model_name: Eine dateisystemsichere Version des Modellnamens.
7170
tags_html: 'eine Reihe von verschachtelten Ordnern, einen für jedes Tag, geordnet nach der Beliebtheit der Tags. Zum Beispiel: <code>fantasy/human/wizard</code>'
7271
general:

config/locales/settings/en.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ en:
5252
summary: Change file settings such as ignored files.
5353
title: File settings
5454
folder_settings:
55-
details: Folder structure follows a template that you define using tokens. You can also include other text in the template (such as folder separators) and it will be included as-is.
55+
details: Folder structure follows a template that you define using tokens. You can also include other text in the template (such as folder separators) and it will be included as-is. A model ID in the form `#123` is always appended to the folder name, to avoid folder naming clashes.
5656
model_path_template:
5757
label: Model path template
5858
parse_metadata_from_path:
@@ -66,7 +66,6 @@ en:
6666
tokens:
6767
collection: The title of the collection the model is in, if set.
6868
creator: The name of the creator, if set.
69-
model_id: A unique numerical identifier for the model. We strongly recommend always including this at the end of your template to avoid name conflicts on disk.
7069
model_name: A filesystem-safe version of the model name.
7170
tags_html: 'a series of nested folders, one for each tag, arranged in order of tag popularity. For example: <code>fantasy/human/wizard</code>. This token is "greedy"; it will parse as many tags as it can.'
7271
general:

config/locales/settings/es.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ es:
6666
tokens:
6767
collection: El título de la colección en la que se encuentra el modelo, si está establecido.
6868
creator: El nombre del creador, si se ha establecido.
69-
model_id: Un identificador numérico único para el modelo. Recomendamos encarecidamente incluirlo siempre al final del modelo para evitar conflictos de nombres en el disco.
7069
model_name: Una versión segura para el sistema de ficheros del nombre del modelo.
7170
tags_html: 'una serie de carpetas anidadas, una para cada etiqueta, ordenadas según su popularidad. Por ejemplo: <code>fantasía/humano/mago</code>'
7271
general:

config/locales/settings/fr.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ fr:
6666
tokens:
6767
collection: Le titre de la collection dans laquelle se trouve le modèle, s'il est défini.
6868
creator: Le nom du créateur, s'il est défini.
69-
model_id: Un identifiant numérique unique pour le modèle. Nous vous recommandons fortement de toujours l'inclure à la fin de votre modèle afin d'éviter les conflits de noms sur le disque.
7069
model_name: Une version sécurisée du nom du modèle pour le système de fichiers.
7170
tags_html: 'une série de dossiers imbriqués, un pour chaque étiquette, classés par ordre de popularité de l''étiquette. Par exemple : <code>fantasy/humain/sorcier</code>'
7271
general:

config/locales/settings/nl.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ nl:
6666
tokens:
6767
collection: De titel van de collectie waarin het model zich bevindt, indien ingesteld.
6868
creator: De naam van de maker, indien ingesteld.
69-
model_id: Een unieke numerieke identificatie voor het model. We raden sterk aan om dit altijd aan het einde van je sjabloon op te nemen om naamconflicten op schijf te voorkomen.
7069
model_name: Een bestandssysteem-veilige versie van de modelnaam.
7170
tags_html: 'een reeks geneste mappen, één voor elke tag, gerangschikt op volgorde van tagpopulariteit. Bijvoorbeeld: <code>fantasy/human/wizard</code>'
7271
general:

0 commit comments

Comments
 (0)