diff --git a/docs/templates/paris/ak.json b/docs/templates/paris/v0.6.2/ak.json
similarity index 100%
rename from docs/templates/paris/ak.json
rename to docs/templates/paris/v0.6.2/ak.json
diff --git a/docs/templates/paris/dienstleistung.json b/docs/templates/paris/v0.6.2/dienstleistung.json
similarity index 100%
rename from docs/templates/paris/dienstleistung.json
rename to docs/templates/paris/v0.6.2/dienstleistung.json
diff --git a/docs/templates/paris/eigenschaft.json b/docs/templates/paris/v0.6.2/eigenschaft.json
similarity index 100%
rename from docs/templates/paris/eigenschaft.json
rename to docs/templates/paris/v0.6.2/eigenschaft.json
diff --git a/docs/templates/paris/esfa.json b/docs/templates/paris/v0.6.2/esfa.json
similarity index 100%
rename from docs/templates/paris/esfa.json
rename to docs/templates/paris/v0.6.2/esfa.json
diff --git a/docs/templates/paris/esqua.json b/docs/templates/paris/v0.6.2/esqua.json
similarity index 100%
rename from docs/templates/paris/esqua.json
rename to docs/templates/paris/v0.6.2/esqua.json
diff --git a/docs/templates/paris/glossar.json b/docs/templates/paris/v0.6.2/glossar.json
similarity index 100%
rename from docs/templates/paris/glossar.json
rename to docs/templates/paris/v0.6.2/glossar.json
diff --git a/docs/templates/paris/kontext.json b/docs/templates/paris/v0.6.2/kontext.json
similarity index 100%
rename from docs/templates/paris/kontext.json
rename to docs/templates/paris/v0.6.2/kontext.json
diff --git a/docs/templates/paris/stakeholder.json b/docs/templates/paris/v0.6.2/stakeholder.json
similarity index 100%
rename from docs/templates/paris/stakeholder.json
rename to docs/templates/paris/v0.6.2/stakeholder.json
diff --git a/docs/templates/paris/technische-eigenschaft.json b/docs/templates/paris/v0.6.2/technische-eigenschaft.json
similarity index 100%
rename from docs/templates/paris/technische-eigenschaft.json
rename to docs/templates/paris/v0.6.2/technische-eigenschaft.json
diff --git a/docs/templates/paris/technische.json b/docs/templates/paris/v0.6.2/technische.json
similarity index 100%
rename from docs/templates/paris/technische.json
rename to docs/templates/paris/v0.6.2/technische.json
diff --git a/docs/templates/paris/ziel.json b/docs/templates/paris/v0.6.2/ziel.json
similarity index 100%
rename from docs/templates/paris/ziel.json
rename to docs/templates/paris/v0.6.2/ziel.json
diff --git a/src/app/template/web/service.go b/src/app/template/web/service.go
index df68c9f52094ac2bed6f225c606a60b9724eed16..b3131a49b496ede4b3b7f6a7ad0375e0ff42a150 100644
--- a/src/app/template/web/service.go
+++ b/src/app/template/web/service.go
@@ -130,10 +130,58 @@ func CopyTemplate(ctx context.Context, tmpl *template.Template, tmplSetID, usrID
return newTmpl, nil
}
-func ImportDefaultParisTemplates(ctx context.Context, tmplSetRepo template.SetRepository, tmplRepo template.Repository, usrID uuid.UUID) error {
+func LatestPARISVersion(baseDir string) (string, error) {
+ dir, err := os.ReadDir(baseDir)
+ if err != nil {
+ return "", err
+ }
+
+ var currentVersion string
+ var latestVersion string
+ for _, file := range dir {
+ if !file.IsDir() {
+ continue
+ }
+
+ if file.Name()[0] == 'v' {
+ currentVersion = file.Name()[1:]
+ }
+
+ if validation.Validate("semVer", "PARIS", currentVersion, validation.SemanticVersion()) != nil {
+ continue
+ }
+
+ if latestVersion == "" {
+ latestVersion = currentVersion
+ continue
+ }
+
+ if currentVersion > latestVersion {
+ latestVersion = currentVersion
+ }
+ }
+
+ if latestVersion == "" {
+ return "", ErrDefaultTemplateDoesNotExist
+ }
+
+ return latestVersion, nil
+}
+
+func ImportDefaultPARISTemplates(ctx context.Context, baseDir string, tmplSetRepo template.SetRepository, tmplRepo template.Repository, usrID uuid.UUID) error {
+ latestVersion, err := LatestPARISVersion(baseDir)
+ if err != nil {
+ return ErrDefaultTemplateDoesNotExist
+ }
+
+ versionDir, err := os.ReadDir(filepath.Join(baseDir, "v"+latestVersion))
+ if err != nil {
+ return ErrDefaultTemplateDoesNotExist
+ }
+
tmplSet, err := tmplSetRepo.Create(ctx, &template.SetToCreate{
Name: "PARIS",
- Version: "0.6.2",
+ Version: latestVersion,
CreatedBy: usrID,
Description: "Default PARIS templates. Change description and templates as needed.",
})
@@ -141,18 +189,12 @@ func ImportDefaultParisTemplates(ctx context.Context, tmplSetRepo template.SetRe
return web.ErrInternal
}
- // read each json file from the default paris template directory for import and create a template from it
- dir, err := os.ReadDir("docs/templates/paris")
- if err != nil {
- return ErrDefaultTemplateDoesNotExist
- }
-
- for _, file := range dir {
+ for _, file := range versionDir {
if file.IsDir() {
continue
}
- jsonCfg, err := os.ReadFile(filepath.Join("docs/templates/paris/", file.Name()))
+ jsonCfg, err := os.ReadFile(filepath.Join(baseDir, "v"+latestVersion, file.Name()))
if err != nil {
return ErrDefaultTemplateDoesNotExist
}
diff --git a/src/app/template/web/web.go b/src/app/template/web/web.go
index abc7c41e071ae17a80b38b0f64bc397d02f9dd78..3f95917e68f0e3d554ccadf5256d9f1a0f8dce65 100644
--- a/src/app/template/web/web.go
+++ b/src/app/template/web/web.go
@@ -28,6 +28,12 @@ type TemplateCopyFormData struct {
Copied bool
}
+// TemplateSetListData is passed to the template set list and contains the additional paris version.
+type TemplateSetListData struct {
+ TemplateSets []*template.Set
+ PARISVersion string
+}
+
// RegisterController registers the controllers and navigation for the template module.
func RegisterController(appCtx *hctx.AppCtx, webCtx *web.Ctx) {
registerNavigation(appCtx, webCtx)
@@ -71,12 +77,15 @@ func templateSetListController(appCtx *hctx.AppCtx, webCtx *web.Ctx) http.Handle
return io.Error(web.ErrInternal, err)
}
- return io.Render(
- templateSets,
- "template.set.list.page",
- "template/set-list-page.go.html",
- "template/_list-set.go.html",
- )
+ ver, err := LatestPARISVersion("docs/templates/paris")
+ if err != nil {
+ return io.Error(ErrDefaultTemplateDoesNotExist, err)
+ }
+
+ return io.Render(TemplateSetListData{
+ TemplateSets: templateSets,
+ PARISVersion: ver,
+ }, "template.set.list.page", "template/set-list-page.go.html", "template/_list-set.go.html")
})
}
@@ -168,7 +177,15 @@ func templateSetDeleteController(appCtx *hctx.AppCtx, webCtx *web.Ctx) http.Hand
return err
}
- return io.Render(templateSets, "template.set.list", "template/_list-set.go.html")
+ ver, err := LatestPARISVersion("docs/templates/paris")
+ if err != nil {
+ return io.InlineError(ErrDefaultTemplateDoesNotExist, err)
+ }
+
+ return io.Render(TemplateSetListData{
+ TemplateSets: templateSets,
+ PARISVersion: ver,
+ }, "template.set.list", "template/_list-set.go.html")
})
}
@@ -402,7 +419,7 @@ func templateSetImportDefaultParisController(appCtx *hctx.AppCtx, webCtx *web.Ct
return web.NewController(appCtx, webCtx, func(io web.IO) error {
ctx := io.Context()
- err := ImportDefaultParisTemplates(ctx, templateSetRepository, templateRepository, user.MustCtxUser(ctx).ID)
+ err := ImportDefaultPARISTemplates(ctx, "docs/templates/paris", templateSetRepository, templateRepository, user.MustCtxUser(ctx).ID)
if err != nil {
return io.InlineError(err)
}
@@ -412,6 +429,14 @@ func templateSetImportDefaultParisController(appCtx *hctx.AppCtx, webCtx *web.Ct
return io.InlineError(web.ErrInternal, err)
}
- return io.Render(templateSets, "template.set.list", "template/_list-set.go.html")
+ ver, err := LatestPARISVersion("docs/templates/paris")
+ if err != nil {
+ return io.InlineError(ErrDefaultTemplateDoesNotExist, err)
+ }
+
+ return io.Render(TemplateSetListData{
+ TemplateSets: templateSets,
+ PARISVersion: ver,
+ }, "template.set.list", "template/_list-set.go.html")
})
}
diff --git a/templates/template/_list-set.go.html b/templates/template/_list-set.go.html
index 4acba001af0f98803f414745b4593da39e553975..72d7cdb8d63ef432a6f9df6d71349dca79a55fcd 100644
--- a/templates/template/_list-set.go.html
+++ b/templates/template/_list-set.go.html
@@ -6,7 +6,7 @@
</div>
<div class="col">
<a href="/template-set/new" hx-boost="true" hx-target="body" class="btn btn-secondary">{{ "template.set.new" | t }}</a>
- <button hx-post="/template-set/import/default-paris" hx-target=".template-set-list" hx-swap="outerHTML" class="btn btn-secondary mt-1">{{ "template.set.import.paris" | t }}</button>
+ <button hx-post="/template-set/import/default-paris" hx-target=".template-set-list" hx-swap="outerHTML" class="btn btn-secondary mt-1">{{ tf "template.set.import.paris" "version" .Data.PARISVersion }}</button>
</div>
<div class="col">
<button hx-get="/template-set/list" hx-target="body" class="btn btn-secondary">
@@ -26,13 +26,13 @@
</tr>
</thead>
<tbody>
- {{ if not .Data }}
+ {{ if not .Data.TemplateSets }}
<tr class="text-center">
<td colspan="3">{{ "template.set.list.empty" | t }}</td>
</tr>
{{ end }}
- {{ range .Data }}
+ {{ range .Data.TemplateSets }}
<tr>
<td><a class="template-set-view" href="/template-set/{{ .ID }}/list" hx-boost="true" hx-target="body">{{ .Name }}</a></td>
<td>{{ .Version }}</td>
diff --git a/translations/de.json b/translations/de.json
index 43a8ab6c411a7d9ba9415810effc23ea1b79c041..c1c9158c1ff7d654e8019a5fddbbbb73d186f769 100644
--- a/translations/de.json
+++ b/translations/de.json
@@ -56,7 +56,7 @@
"updated": "Der Schablonensatz wurde aktualisiert."
},
"import": {
- "paris": "PARIS importieren"
+ "paris": "PARIS importieren (Ver.: {{ .version }})"
}
},
"title": "Schablone",
diff --git a/translations/en.json b/translations/en.json
index 98f8f4e3a156bf8304ea4c586ee57fccfc023aeb..db2c2f057314cf57cb19962aa463dd5e24859b15 100644
--- a/translations/en.json
+++ b/translations/en.json
@@ -56,7 +56,7 @@
"updated": "The template set has been updated."
},
"import": {
- "paris": "Import PARIS"
+ "paris": "Import PARIS (ver. {{ .version }})"
}
},
"title": "Template",