diff --git a/generators/testdata/expected/vt-template/all/src/pages/Entity/Category/Form.vue b/generators/testdata/expected/vt-template/all/src/pages/Entity/Category/Form.vue index 49ec139..ab8d2d8 100644 --- a/generators/testdata/expected/vt-template/all/src/pages/Entity/Category/Form.vue +++ b/generators/testdata/expected/vt-template/all/src/pages/Entity/Category/Form.vue @@ -15,7 +15,7 @@ >

- {{ store.model.title || "..." }} + {{ model.title || "..." }}

@@ -23,7 +23,7 @@ - + done - {{ $t("common.form.saveAndCloseButtonLabel") }} + {{ t("common.form.saveAndCloseButtonLabel") }} - {{ $t("common.form.saveButtonLabel") }} + {{ t("common.form.saveButtonLabel") }} @@ -150,17 +150,58 @@ diff --git a/generators/testdata/expected/vt-template/all/src/pages/Entity/Category/List.vue b/generators/testdata/expected/vt-template/all/src/pages/Entity/Category/List.vue index f2e6d2a..261806a 100644 --- a/generators/testdata/expected/vt-template/all/src/pages/Entity/Category/List.vue +++ b/generators/testdata/expected/vt-template/all/src/pages/Entity/Category/List.vue @@ -18,27 +18,26 @@

- {{ $t("category.list.title") }} + {{ t("category.list.title") }}

- {{ store.pagination.totalItems }} + {{ pagination.totalItems }}
- - add - - {{ $t("common.list.addNewLabel") }} + add + {{ t("common.list.addNewLabel") }} @@ -64,9 +63,9 @@ mr-sm-2 > @@ -100,9 +100,9 @@ @@ -164,48 +164,76 @@ diff --git a/generators/testdata/expected/vt-template/all/src/pages/Entity/Category/components/MultiListFilters.vue b/generators/testdata/expected/vt-template/all/src/pages/Entity/Category/components/MultiListFilters.vue index fc765eb..a6fedaf 100644 --- a/generators/testdata/expected/vt-template/all/src/pages/Entity/Category/components/MultiListFilters.vue +++ b/generators/testdata/expected/vt-template/all/src/pages/Entity/Category/components/MultiListFilters.vue @@ -1,26 +1,43 @@ diff --git a/generators/testdata/expected/vt-template/all/src/pages/Entity/News/Form.vue b/generators/testdata/expected/vt-template/all/src/pages/Entity/News/Form.vue index 3892583..ff0c74e 100644 --- a/generators/testdata/expected/vt-template/all/src/pages/Entity/News/Form.vue +++ b/generators/testdata/expected/vt-template/all/src/pages/Entity/News/Form.vue @@ -15,7 +15,7 @@ >

- {{ store.model.title || "..." }} + {{ model.title || "..." }}

@@ -23,7 +23,7 @@ - + done - {{ $t("common.form.saveAndCloseButtonLabel") }} + {{ t("common.form.saveAndCloseButtonLabel") }} - {{ $t("common.form.saveButtonLabel") }} + {{ t("common.form.saveButtonLabel") }} @@ -225,17 +225,58 @@ diff --git a/generators/testdata/expected/vt-template/all/src/pages/Entity/News/List.vue b/generators/testdata/expected/vt-template/all/src/pages/Entity/News/List.vue index 8cc4aa6..c9dc873 100644 --- a/generators/testdata/expected/vt-template/all/src/pages/Entity/News/List.vue +++ b/generators/testdata/expected/vt-template/all/src/pages/Entity/News/List.vue @@ -18,27 +18,26 @@

- {{ $t("news.list.title") }} + {{ t("news.list.title") }}

- {{ store.pagination.totalItems }} + {{ pagination.totalItems }}
- - add - - {{ $t("common.list.addNewLabel") }} + add + {{ t("common.list.addNewLabel") }} @@ -64,9 +63,9 @@ mr-sm-2 > @@ -100,9 +100,9 @@ @@ -176,67 +176,95 @@ diff --git a/generators/testdata/expected/vt-template/all/src/pages/Entity/News/components/MultiListFilters.vue b/generators/testdata/expected/vt-template/all/src/pages/Entity/News/components/MultiListFilters.vue index 83bb31e..7f1ec20 100644 --- a/generators/testdata/expected/vt-template/all/src/pages/Entity/News/components/MultiListFilters.vue +++ b/generators/testdata/expected/vt-template/all/src/pages/Entity/News/components/MultiListFilters.vue @@ -1,26 +1,43 @@ diff --git a/generators/testdata/expected/vt-template/all/src/pages/Entity/Tag/Form.vue b/generators/testdata/expected/vt-template/all/src/pages/Entity/Tag/Form.vue index e46587a..6630576 100644 --- a/generators/testdata/expected/vt-template/all/src/pages/Entity/Tag/Form.vue +++ b/generators/testdata/expected/vt-template/all/src/pages/Entity/Tag/Form.vue @@ -15,7 +15,7 @@ >

- {{ store.model.title || "..." }} + {{ model.title || "..." }}

@@ -23,7 +23,7 @@ - + done - {{ $t("common.form.saveAndCloseButtonLabel") }} + {{ t("common.form.saveAndCloseButtonLabel") }} - {{ $t("common.form.saveButtonLabel") }} + {{ t("common.form.saveButtonLabel") }} @@ -142,17 +142,58 @@ diff --git a/generators/testdata/expected/vt-template/all/src/pages/Entity/Tag/List.vue b/generators/testdata/expected/vt-template/all/src/pages/Entity/Tag/List.vue index 59f5d65..71dec4b 100644 --- a/generators/testdata/expected/vt-template/all/src/pages/Entity/Tag/List.vue +++ b/generators/testdata/expected/vt-template/all/src/pages/Entity/Tag/List.vue @@ -18,27 +18,26 @@

- {{ $t("tag.list.title") }} + {{ t("tag.list.title") }}

- {{ store.pagination.totalItems }} + {{ pagination.totalItems }}
- - add - - {{ $t("common.list.addNewLabel") }} + add + {{ t("common.list.addNewLabel") }} @@ -64,9 +63,9 @@ mr-sm-2 > @@ -100,9 +100,9 @@ @@ -161,44 +161,72 @@ diff --git a/generators/testdata/expected/vt-template/all/src/pages/Entity/Tag/components/MultiListFilters.vue b/generators/testdata/expected/vt-template/all/src/pages/Entity/Tag/components/MultiListFilters.vue index 4e5ae81..523e594 100644 --- a/generators/testdata/expected/vt-template/all/src/pages/Entity/Tag/components/MultiListFilters.vue +++ b/generators/testdata/expected/vt-template/all/src/pages/Entity/Tag/components/MultiListFilters.vue @@ -1,26 +1,43 @@ diff --git a/generators/testdata/expected/vt-template/all/src/pages/Entity/routes.ts b/generators/testdata/expected/vt-template/all/src/pages/Entity/routes.ts index 7c69d18..198b28f 100644 --- a/generators/testdata/expected/vt-template/all/src/pages/Entity/routes.ts +++ b/generators/testdata/expected/vt-template/all/src/pages/Entity/routes.ts @@ -1,311 +1,344 @@ /* eslint-disable */ export default [ - /* Category */ - { - name: "categoryList", - path: "/categories", - component: () => - import("@/pages/Entity/Category/List.vue"), - meta: { - breadcrumbs: ["dashboard", "categoryList"] - } - }, - { - name: "categoryEdit", - path: "/categories/:id/edit", - component: () => - import("@/pages/Entity/Category/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "categoryList", "categoryEdit"] - } - }, - { - name: "categoryAdd", - path: "/categories/add", - component: () => - import("@/pages/Entity/Category/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "categoryList", "categoryAdd"] - } - }, - /* News */ - { - name: "newsList", - path: "/news", - component: () => - import("@/pages/Entity/News/List.vue"), - meta: { - breadcrumbs: ["dashboard", "newsList"] - } - }, - { - name: "newsEdit", - path: "/news/:id/edit", - component: () => - import("@/pages/Entity/News/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "newsList", "newsEdit"] - } - }, - { - name: "newsAdd", - path: "/news/add", - component: () => - import("@/pages/Entity/News/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "newsList", "newsAdd"] - } - }, - /* Tag */ - { - name: "tagList", - path: "/tags", - component: () => - import("@/pages/Entity/Tag/List.vue"), - meta: { - breadcrumbs: ["dashboard", "tagList"] - } - }, - { - name: "tagEdit", - path: "/tags/:id/edit", - component: () => - import("@/pages/Entity/Tag/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "tagList", "tagEdit"] - } - }, - { - name: "tagAdd", - path: "/tags/add", - component: () => - import("@/pages/Entity/Tag/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "tagList", "tagAdd"] - } - }, - /* City */ - { - name: "cityList", - path: "/cities", - component: () => - import("@/pages/Entity/City/List.vue"), - meta: { - breadcrumbs: ["dashboard", "cityList"] - } - }, - { - name: "cityEdit", - path: "/cities/:id/edit", - component: () => - import("@/pages/Entity/City/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "cityList", "cityEdit"] - } - }, - { - name: "cityAdd", - path: "/cities/add", - component: () => - import("@/pages/Entity/City/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "cityList", "cityAdd"] - } - }, - /* Country */ - { - name: "countryList", - path: "/countries", - component: () => - import("@/pages/Entity/Country/List.vue"), - meta: { - breadcrumbs: ["dashboard", "countryList"] - } - }, - { - name: "countryEdit", - path: "/countries/:id/edit", - component: () => - import("@/pages/Entity/Country/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "countryList", "countryEdit"] - } - }, - { - name: "countryAdd", - path: "/countries/add", - component: () => - import("@/pages/Entity/Country/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "countryList", "countryAdd"] - } - }, - /* Region */ - { - name: "regionList", - path: "/regions", - component: () => - import("@/pages/Entity/Region/List.vue"), - meta: { - breadcrumbs: ["dashboard", "regionList"] - } - }, - { - name: "regionEdit", - path: "/regions/:id/edit", - component: () => - import("@/pages/Entity/Region/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "regionList", "regionEdit"] - } - }, - { - name: "regionAdd", - path: "/regions/add", - component: () => - import("@/pages/Entity/Region/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "regionList", "regionAdd"] - } - }, - /* EncryptionKey */ - { - name: "encryptionKeyList", - path: "/encryption-keys", - component: () => - import("@/pages/Entity/EncryptionKey/List.vue"), - meta: { - breadcrumbs: ["dashboard", "encryptionKeyList"] - } - }, - { - name: "encryptionKeyEdit", - path: "/encryption-keys/:id/edit", - component: () => - import("@/pages/Entity/EncryptionKey/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "encryptionKeyList", "encryptionKeyEdit"] - } - }, - { - name: "encryptionKeyAdd", - path: "/encryption-keys/add", - component: () => - import("@/pages/Entity/EncryptionKey/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "encryptionKeyList", "encryptionKeyAdd"] - } - }, - /* LoginCode */ - { - name: "loginCodeList", - path: "/login-codes", - component: () => - import("@/pages/Entity/LoginCode/List.vue"), - meta: { - breadcrumbs: ["dashboard", "loginCodeList"] - } - }, - { - name: "loginCodeEdit", - path: "/login-codes/:id/edit", - component: () => - import("@/pages/Entity/LoginCode/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "loginCodeList", "loginCodeEdit"] - } - }, - { - name: "loginCodeAdd", - path: "/login-codes/add", - component: () => - import("@/pages/Entity/LoginCode/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "loginCodeList", "loginCodeAdd"] - } - }, - /* SiteUser */ - { - name: "siteUserList", - path: "/site-users", - component: () => - import("@/pages/Entity/SiteUser/List.vue"), - meta: { - breadcrumbs: ["dashboard", "siteUserList"] - } - }, - { - name: "siteUserEdit", - path: "/site-users/:id/edit", - component: () => - import("@/pages/Entity/SiteUser/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "siteUserList", "siteUserEdit"] - } - }, - { - name: "siteUserAdd", - path: "/site-users/add", - component: () => - import("@/pages/Entity/SiteUser/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "siteUserList", "siteUserAdd"] - } - }, - /* VfsFile */ - { - name: "vfsFileList", - path: "/vfs-files", - component: () => - import("@/pages/Entity/VfsFile/List.vue"), - meta: { - breadcrumbs: ["dashboard", "vfsFileList"] - } - }, - { - name: "vfsFileEdit", - path: "/vfs-files/:id/edit", - component: () => - import("@/pages/Entity/VfsFile/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "vfsFileList", "vfsFileEdit"] - } - }, - { - name: "vfsFileAdd", - path: "/vfs-files/add", - component: () => - import("@/pages/Entity/VfsFile/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "vfsFileList", "vfsFileAdd"] - } - }, - /* VfsFolder */ - { - name: "vfsFolderList", - path: "/vfs-folders", - component: () => - import("@/pages/Entity/VfsFolder/List.vue"), - meta: { - breadcrumbs: ["dashboard", "vfsFolderList"] - } - }, - { - name: "vfsFolderEdit", - path: "/vfs-folders/:id/edit", - component: () => - import("@/pages/Entity/VfsFolder/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "vfsFolderList", "vfsFolderEdit"] - } - }, - { - name: "vfsFolderAdd", - path: "/vfs-folders/add", - component: () => - import("@/pages/Entity/VfsFolder/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "vfsFolderList", "vfsFolderAdd"] - } - }, + /* Category */ + { + name: "categoryList", + path: "/categories", + component: () => + import("@/pages/Entity/Category/List.vue"), + meta: { + title: "CategoryList", + breadcrumbs: ["dashboard", "categoryList"] + } + }, + { + name: "categoryEdit", + path: "/categories/:id/edit", + component: () => + import("@/pages/Entity/Category/Form.vue"), + meta: { + title: "CategoryEdit", + breadcrumbs: ["dashboard", "categoryList", "categoryEdit"] + } + }, + { + name: "categoryAdd", + path: "/categories/add", + component: () => + import("@/pages/Entity/Category/Form.vue"), + meta: { + title: "CategoryAdd", + breadcrumbs: ["dashboard", "categoryList", "categoryAdd"] + } + }, + /* News */ + { + name: "newsList", + path: "/news", + component: () => + import("@/pages/Entity/News/List.vue"), + meta: { + title: "NewsList", + breadcrumbs: ["dashboard", "newsList"] + } + }, + { + name: "newsEdit", + path: "/news/:id/edit", + component: () => + import("@/pages/Entity/News/Form.vue"), + meta: { + title: "NewsEdit", + breadcrumbs: ["dashboard", "newsList", "newsEdit"] + } + }, + { + name: "newsAdd", + path: "/news/add", + component: () => + import("@/pages/Entity/News/Form.vue"), + meta: { + title: "NewsAdd", + breadcrumbs: ["dashboard", "newsList", "newsAdd"] + } + }, + /* Tag */ + { + name: "tagList", + path: "/tags", + component: () => + import("@/pages/Entity/Tag/List.vue"), + meta: { + title: "TagList", + breadcrumbs: ["dashboard", "tagList"] + } + }, + { + name: "tagEdit", + path: "/tags/:id/edit", + component: () => + import("@/pages/Entity/Tag/Form.vue"), + meta: { + title: "TagEdit", + breadcrumbs: ["dashboard", "tagList", "tagEdit"] + } + }, + { + name: "tagAdd", + path: "/tags/add", + component: () => + import("@/pages/Entity/Tag/Form.vue"), + meta: { + title: "TagAdd", + breadcrumbs: ["dashboard", "tagList", "tagAdd"] + } + }, + /* City */ + { + name: "cityList", + path: "/cities", + component: () => + import("@/pages/Entity/City/List.vue"), + meta: { + title: "CityList", + breadcrumbs: ["dashboard", "cityList"] + } + }, + { + name: "cityEdit", + path: "/cities/:id/edit", + component: () => + import("@/pages/Entity/City/Form.vue"), + meta: { + title: "CityEdit", + breadcrumbs: ["dashboard", "cityList", "cityEdit"] + } + }, + { + name: "cityAdd", + path: "/cities/add", + component: () => + import("@/pages/Entity/City/Form.vue"), + meta: { + title: "CityAdd", + breadcrumbs: ["dashboard", "cityList", "cityAdd"] + } + }, + /* Country */ + { + name: "countryList", + path: "/countries", + component: () => + import("@/pages/Entity/Country/List.vue"), + meta: { + title: "CountryList", + breadcrumbs: ["dashboard", "countryList"] + } + }, + { + name: "countryEdit", + path: "/countries/:id/edit", + component: () => + import("@/pages/Entity/Country/Form.vue"), + meta: { + title: "CountryEdit", + breadcrumbs: ["dashboard", "countryList", "countryEdit"] + } + }, + { + name: "countryAdd", + path: "/countries/add", + component: () => + import("@/pages/Entity/Country/Form.vue"), + meta: { + title: "CountryAdd", + breadcrumbs: ["dashboard", "countryList", "countryAdd"] + } + }, + /* Region */ + { + name: "regionList", + path: "/regions", + component: () => + import("@/pages/Entity/Region/List.vue"), + meta: { + title: "RegionList", + breadcrumbs: ["dashboard", "regionList"] + } + }, + { + name: "regionEdit", + path: "/regions/:id/edit", + component: () => + import("@/pages/Entity/Region/Form.vue"), + meta: { + title: "RegionEdit", + breadcrumbs: ["dashboard", "regionList", "regionEdit"] + } + }, + { + name: "regionAdd", + path: "/regions/add", + component: () => + import("@/pages/Entity/Region/Form.vue"), + meta: { + title: "RegionAdd", + breadcrumbs: ["dashboard", "regionList", "regionAdd"] + } + }, + /* EncryptionKey */ + { + name: "encryptionKeyList", + path: "/encryption-keys", + component: () => + import("@/pages/Entity/EncryptionKey/List.vue"), + meta: { + title: "EncryptionKeyList", + breadcrumbs: ["dashboard", "encryptionKeyList"] + } + }, + { + name: "encryptionKeyEdit", + path: "/encryption-keys/:id/edit", + component: () => + import("@/pages/Entity/EncryptionKey/Form.vue"), + meta: { + title: "EncryptionKeyEdit", + breadcrumbs: ["dashboard", "encryptionKeyList", "encryptionKeyEdit"] + } + }, + { + name: "encryptionKeyAdd", + path: "/encryption-keys/add", + component: () => + import("@/pages/Entity/EncryptionKey/Form.vue"), + meta: { + title: "EncryptionKeyAdd", + breadcrumbs: ["dashboard", "encryptionKeyList", "encryptionKeyAdd"] + } + }, + /* LoginCode */ + { + name: "loginCodeList", + path: "/login-codes", + component: () => + import("@/pages/Entity/LoginCode/List.vue"), + meta: { + title: "LoginCodeList", + breadcrumbs: ["dashboard", "loginCodeList"] + } + }, + { + name: "loginCodeEdit", + path: "/login-codes/:id/edit", + component: () => + import("@/pages/Entity/LoginCode/Form.vue"), + meta: { + title: "LoginCodeEdit", + breadcrumbs: ["dashboard", "loginCodeList", "loginCodeEdit"] + } + }, + { + name: "loginCodeAdd", + path: "/login-codes/add", + component: () => + import("@/pages/Entity/LoginCode/Form.vue"), + meta: { + title: "LoginCodeAdd", + breadcrumbs: ["dashboard", "loginCodeList", "loginCodeAdd"] + } + }, + /* SiteUser */ + { + name: "siteUserList", + path: "/site-users", + component: () => + import("@/pages/Entity/SiteUser/List.vue"), + meta: { + title: "SiteUserList", + breadcrumbs: ["dashboard", "siteUserList"] + } + }, + { + name: "siteUserEdit", + path: "/site-users/:id/edit", + component: () => + import("@/pages/Entity/SiteUser/Form.vue"), + meta: { + title: "SiteUserEdit", + breadcrumbs: ["dashboard", "siteUserList", "siteUserEdit"] + } + }, + { + name: "siteUserAdd", + path: "/site-users/add", + component: () => + import("@/pages/Entity/SiteUser/Form.vue"), + meta: { + title: "SiteUserAdd", + breadcrumbs: ["dashboard", "siteUserList", "siteUserAdd"] + } + }, + /* VfsFile */ + { + name: "vfsFileList", + path: "/vfs-files", + component: () => + import("@/pages/Entity/VfsFile/List.vue"), + meta: { + title: "VfsFileList", + breadcrumbs: ["dashboard", "vfsFileList"] + } + }, + { + name: "vfsFileEdit", + path: "/vfs-files/:id/edit", + component: () => + import("@/pages/Entity/VfsFile/Form.vue"), + meta: { + title: "VfsFileEdit", + breadcrumbs: ["dashboard", "vfsFileList", "vfsFileEdit"] + } + }, + { + name: "vfsFileAdd", + path: "/vfs-files/add", + component: () => + import("@/pages/Entity/VfsFile/Form.vue"), + meta: { + title: "VfsFileAdd", + breadcrumbs: ["dashboard", "vfsFileList", "vfsFileAdd"] + } + }, + /* VfsFolder */ + { + name: "vfsFolderList", + path: "/vfs-folders", + component: () => + import("@/pages/Entity/VfsFolder/List.vue"), + meta: { + title: "VfsFolderList", + breadcrumbs: ["dashboard", "vfsFolderList"] + } + }, + { + name: "vfsFolderEdit", + path: "/vfs-folders/:id/edit", + component: () => + import("@/pages/Entity/VfsFolder/Form.vue"), + meta: { + title: "VfsFolderEdit", + breadcrumbs: ["dashboard", "vfsFolderList", "vfsFolderEdit"] + } + }, + { + name: "vfsFolderAdd", + path: "/vfs-folders/add", + component: () => + import("@/pages/Entity/VfsFolder/Form.vue"), + meta: { + title: "VfsFolderAdd", + breadcrumbs: ["dashboard", "vfsFolderList", "vfsFolderAdd"] + } + }, ]; diff --git a/generators/testdata/expected/vt-template/entities/src/pages/Entity/Category/Form.vue b/generators/testdata/expected/vt-template/entities/src/pages/Entity/Category/Form.vue index 49ec139..ab8d2d8 100644 --- a/generators/testdata/expected/vt-template/entities/src/pages/Entity/Category/Form.vue +++ b/generators/testdata/expected/vt-template/entities/src/pages/Entity/Category/Form.vue @@ -15,7 +15,7 @@ >

- {{ store.model.title || "..." }} + {{ model.title || "..." }}

@@ -23,7 +23,7 @@ - + done - {{ $t("common.form.saveAndCloseButtonLabel") }} + {{ t("common.form.saveAndCloseButtonLabel") }} - {{ $t("common.form.saveButtonLabel") }} + {{ t("common.form.saveButtonLabel") }} @@ -150,17 +150,58 @@ diff --git a/generators/testdata/expected/vt-template/entities/src/pages/Entity/Category/List.vue b/generators/testdata/expected/vt-template/entities/src/pages/Entity/Category/List.vue index f2e6d2a..261806a 100644 --- a/generators/testdata/expected/vt-template/entities/src/pages/Entity/Category/List.vue +++ b/generators/testdata/expected/vt-template/entities/src/pages/Entity/Category/List.vue @@ -18,27 +18,26 @@

- {{ $t("category.list.title") }} + {{ t("category.list.title") }}

- {{ store.pagination.totalItems }} + {{ pagination.totalItems }}
- - add - - {{ $t("common.list.addNewLabel") }} + add + {{ t("common.list.addNewLabel") }} @@ -64,9 +63,9 @@ mr-sm-2 > @@ -100,9 +100,9 @@ @@ -164,48 +164,76 @@ diff --git a/generators/testdata/expected/vt-template/entities/src/pages/Entity/Category/components/MultiListFilters.vue b/generators/testdata/expected/vt-template/entities/src/pages/Entity/Category/components/MultiListFilters.vue index fc765eb..a6fedaf 100644 --- a/generators/testdata/expected/vt-template/entities/src/pages/Entity/Category/components/MultiListFilters.vue +++ b/generators/testdata/expected/vt-template/entities/src/pages/Entity/Category/components/MultiListFilters.vue @@ -1,26 +1,43 @@ diff --git a/generators/testdata/expected/vt-template/entities/src/pages/Entity/Tag/Form.vue b/generators/testdata/expected/vt-template/entities/src/pages/Entity/Tag/Form.vue index e46587a..6630576 100644 --- a/generators/testdata/expected/vt-template/entities/src/pages/Entity/Tag/Form.vue +++ b/generators/testdata/expected/vt-template/entities/src/pages/Entity/Tag/Form.vue @@ -15,7 +15,7 @@ >

- {{ store.model.title || "..." }} + {{ model.title || "..." }}

@@ -23,7 +23,7 @@ - + done - {{ $t("common.form.saveAndCloseButtonLabel") }} + {{ t("common.form.saveAndCloseButtonLabel") }} - {{ $t("common.form.saveButtonLabel") }} + {{ t("common.form.saveButtonLabel") }} @@ -142,17 +142,58 @@ diff --git a/generators/testdata/expected/vt-template/entities/src/pages/Entity/Tag/List.vue b/generators/testdata/expected/vt-template/entities/src/pages/Entity/Tag/List.vue index 59f5d65..71dec4b 100644 --- a/generators/testdata/expected/vt-template/entities/src/pages/Entity/Tag/List.vue +++ b/generators/testdata/expected/vt-template/entities/src/pages/Entity/Tag/List.vue @@ -18,27 +18,26 @@

- {{ $t("tag.list.title") }} + {{ t("tag.list.title") }}

- {{ store.pagination.totalItems }} + {{ pagination.totalItems }}
- - add - - {{ $t("common.list.addNewLabel") }} + add + {{ t("common.list.addNewLabel") }} @@ -64,9 +63,9 @@ mr-sm-2 > @@ -100,9 +100,9 @@ @@ -161,44 +161,72 @@ diff --git a/generators/testdata/expected/vt-template/entities/src/pages/Entity/Tag/components/MultiListFilters.vue b/generators/testdata/expected/vt-template/entities/src/pages/Entity/Tag/components/MultiListFilters.vue index 4e5ae81..523e594 100644 --- a/generators/testdata/expected/vt-template/entities/src/pages/Entity/Tag/components/MultiListFilters.vue +++ b/generators/testdata/expected/vt-template/entities/src/pages/Entity/Tag/components/MultiListFilters.vue @@ -1,26 +1,43 @@ diff --git a/generators/testdata/expected/vt-template/entities/src/pages/Entity/routes.ts b/generators/testdata/expected/vt-template/entities/src/pages/Entity/routes.ts index 7c69d18..198b28f 100644 --- a/generators/testdata/expected/vt-template/entities/src/pages/Entity/routes.ts +++ b/generators/testdata/expected/vt-template/entities/src/pages/Entity/routes.ts @@ -1,311 +1,344 @@ /* eslint-disable */ export default [ - /* Category */ - { - name: "categoryList", - path: "/categories", - component: () => - import("@/pages/Entity/Category/List.vue"), - meta: { - breadcrumbs: ["dashboard", "categoryList"] - } - }, - { - name: "categoryEdit", - path: "/categories/:id/edit", - component: () => - import("@/pages/Entity/Category/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "categoryList", "categoryEdit"] - } - }, - { - name: "categoryAdd", - path: "/categories/add", - component: () => - import("@/pages/Entity/Category/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "categoryList", "categoryAdd"] - } - }, - /* News */ - { - name: "newsList", - path: "/news", - component: () => - import("@/pages/Entity/News/List.vue"), - meta: { - breadcrumbs: ["dashboard", "newsList"] - } - }, - { - name: "newsEdit", - path: "/news/:id/edit", - component: () => - import("@/pages/Entity/News/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "newsList", "newsEdit"] - } - }, - { - name: "newsAdd", - path: "/news/add", - component: () => - import("@/pages/Entity/News/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "newsList", "newsAdd"] - } - }, - /* Tag */ - { - name: "tagList", - path: "/tags", - component: () => - import("@/pages/Entity/Tag/List.vue"), - meta: { - breadcrumbs: ["dashboard", "tagList"] - } - }, - { - name: "tagEdit", - path: "/tags/:id/edit", - component: () => - import("@/pages/Entity/Tag/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "tagList", "tagEdit"] - } - }, - { - name: "tagAdd", - path: "/tags/add", - component: () => - import("@/pages/Entity/Tag/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "tagList", "tagAdd"] - } - }, - /* City */ - { - name: "cityList", - path: "/cities", - component: () => - import("@/pages/Entity/City/List.vue"), - meta: { - breadcrumbs: ["dashboard", "cityList"] - } - }, - { - name: "cityEdit", - path: "/cities/:id/edit", - component: () => - import("@/pages/Entity/City/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "cityList", "cityEdit"] - } - }, - { - name: "cityAdd", - path: "/cities/add", - component: () => - import("@/pages/Entity/City/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "cityList", "cityAdd"] - } - }, - /* Country */ - { - name: "countryList", - path: "/countries", - component: () => - import("@/pages/Entity/Country/List.vue"), - meta: { - breadcrumbs: ["dashboard", "countryList"] - } - }, - { - name: "countryEdit", - path: "/countries/:id/edit", - component: () => - import("@/pages/Entity/Country/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "countryList", "countryEdit"] - } - }, - { - name: "countryAdd", - path: "/countries/add", - component: () => - import("@/pages/Entity/Country/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "countryList", "countryAdd"] - } - }, - /* Region */ - { - name: "regionList", - path: "/regions", - component: () => - import("@/pages/Entity/Region/List.vue"), - meta: { - breadcrumbs: ["dashboard", "regionList"] - } - }, - { - name: "regionEdit", - path: "/regions/:id/edit", - component: () => - import("@/pages/Entity/Region/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "regionList", "regionEdit"] - } - }, - { - name: "regionAdd", - path: "/regions/add", - component: () => - import("@/pages/Entity/Region/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "regionList", "regionAdd"] - } - }, - /* EncryptionKey */ - { - name: "encryptionKeyList", - path: "/encryption-keys", - component: () => - import("@/pages/Entity/EncryptionKey/List.vue"), - meta: { - breadcrumbs: ["dashboard", "encryptionKeyList"] - } - }, - { - name: "encryptionKeyEdit", - path: "/encryption-keys/:id/edit", - component: () => - import("@/pages/Entity/EncryptionKey/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "encryptionKeyList", "encryptionKeyEdit"] - } - }, - { - name: "encryptionKeyAdd", - path: "/encryption-keys/add", - component: () => - import("@/pages/Entity/EncryptionKey/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "encryptionKeyList", "encryptionKeyAdd"] - } - }, - /* LoginCode */ - { - name: "loginCodeList", - path: "/login-codes", - component: () => - import("@/pages/Entity/LoginCode/List.vue"), - meta: { - breadcrumbs: ["dashboard", "loginCodeList"] - } - }, - { - name: "loginCodeEdit", - path: "/login-codes/:id/edit", - component: () => - import("@/pages/Entity/LoginCode/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "loginCodeList", "loginCodeEdit"] - } - }, - { - name: "loginCodeAdd", - path: "/login-codes/add", - component: () => - import("@/pages/Entity/LoginCode/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "loginCodeList", "loginCodeAdd"] - } - }, - /* SiteUser */ - { - name: "siteUserList", - path: "/site-users", - component: () => - import("@/pages/Entity/SiteUser/List.vue"), - meta: { - breadcrumbs: ["dashboard", "siteUserList"] - } - }, - { - name: "siteUserEdit", - path: "/site-users/:id/edit", - component: () => - import("@/pages/Entity/SiteUser/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "siteUserList", "siteUserEdit"] - } - }, - { - name: "siteUserAdd", - path: "/site-users/add", - component: () => - import("@/pages/Entity/SiteUser/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "siteUserList", "siteUserAdd"] - } - }, - /* VfsFile */ - { - name: "vfsFileList", - path: "/vfs-files", - component: () => - import("@/pages/Entity/VfsFile/List.vue"), - meta: { - breadcrumbs: ["dashboard", "vfsFileList"] - } - }, - { - name: "vfsFileEdit", - path: "/vfs-files/:id/edit", - component: () => - import("@/pages/Entity/VfsFile/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "vfsFileList", "vfsFileEdit"] - } - }, - { - name: "vfsFileAdd", - path: "/vfs-files/add", - component: () => - import("@/pages/Entity/VfsFile/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "vfsFileList", "vfsFileAdd"] - } - }, - /* VfsFolder */ - { - name: "vfsFolderList", - path: "/vfs-folders", - component: () => - import("@/pages/Entity/VfsFolder/List.vue"), - meta: { - breadcrumbs: ["dashboard", "vfsFolderList"] - } - }, - { - name: "vfsFolderEdit", - path: "/vfs-folders/:id/edit", - component: () => - import("@/pages/Entity/VfsFolder/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "vfsFolderList", "vfsFolderEdit"] - } - }, - { - name: "vfsFolderAdd", - path: "/vfs-folders/add", - component: () => - import("@/pages/Entity/VfsFolder/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "vfsFolderList", "vfsFolderAdd"] - } - }, + /* Category */ + { + name: "categoryList", + path: "/categories", + component: () => + import("@/pages/Entity/Category/List.vue"), + meta: { + title: "CategoryList", + breadcrumbs: ["dashboard", "categoryList"] + } + }, + { + name: "categoryEdit", + path: "/categories/:id/edit", + component: () => + import("@/pages/Entity/Category/Form.vue"), + meta: { + title: "CategoryEdit", + breadcrumbs: ["dashboard", "categoryList", "categoryEdit"] + } + }, + { + name: "categoryAdd", + path: "/categories/add", + component: () => + import("@/pages/Entity/Category/Form.vue"), + meta: { + title: "CategoryAdd", + breadcrumbs: ["dashboard", "categoryList", "categoryAdd"] + } + }, + /* News */ + { + name: "newsList", + path: "/news", + component: () => + import("@/pages/Entity/News/List.vue"), + meta: { + title: "NewsList", + breadcrumbs: ["dashboard", "newsList"] + } + }, + { + name: "newsEdit", + path: "/news/:id/edit", + component: () => + import("@/pages/Entity/News/Form.vue"), + meta: { + title: "NewsEdit", + breadcrumbs: ["dashboard", "newsList", "newsEdit"] + } + }, + { + name: "newsAdd", + path: "/news/add", + component: () => + import("@/pages/Entity/News/Form.vue"), + meta: { + title: "NewsAdd", + breadcrumbs: ["dashboard", "newsList", "newsAdd"] + } + }, + /* Tag */ + { + name: "tagList", + path: "/tags", + component: () => + import("@/pages/Entity/Tag/List.vue"), + meta: { + title: "TagList", + breadcrumbs: ["dashboard", "tagList"] + } + }, + { + name: "tagEdit", + path: "/tags/:id/edit", + component: () => + import("@/pages/Entity/Tag/Form.vue"), + meta: { + title: "TagEdit", + breadcrumbs: ["dashboard", "tagList", "tagEdit"] + } + }, + { + name: "tagAdd", + path: "/tags/add", + component: () => + import("@/pages/Entity/Tag/Form.vue"), + meta: { + title: "TagAdd", + breadcrumbs: ["dashboard", "tagList", "tagAdd"] + } + }, + /* City */ + { + name: "cityList", + path: "/cities", + component: () => + import("@/pages/Entity/City/List.vue"), + meta: { + title: "CityList", + breadcrumbs: ["dashboard", "cityList"] + } + }, + { + name: "cityEdit", + path: "/cities/:id/edit", + component: () => + import("@/pages/Entity/City/Form.vue"), + meta: { + title: "CityEdit", + breadcrumbs: ["dashboard", "cityList", "cityEdit"] + } + }, + { + name: "cityAdd", + path: "/cities/add", + component: () => + import("@/pages/Entity/City/Form.vue"), + meta: { + title: "CityAdd", + breadcrumbs: ["dashboard", "cityList", "cityAdd"] + } + }, + /* Country */ + { + name: "countryList", + path: "/countries", + component: () => + import("@/pages/Entity/Country/List.vue"), + meta: { + title: "CountryList", + breadcrumbs: ["dashboard", "countryList"] + } + }, + { + name: "countryEdit", + path: "/countries/:id/edit", + component: () => + import("@/pages/Entity/Country/Form.vue"), + meta: { + title: "CountryEdit", + breadcrumbs: ["dashboard", "countryList", "countryEdit"] + } + }, + { + name: "countryAdd", + path: "/countries/add", + component: () => + import("@/pages/Entity/Country/Form.vue"), + meta: { + title: "CountryAdd", + breadcrumbs: ["dashboard", "countryList", "countryAdd"] + } + }, + /* Region */ + { + name: "regionList", + path: "/regions", + component: () => + import("@/pages/Entity/Region/List.vue"), + meta: { + title: "RegionList", + breadcrumbs: ["dashboard", "regionList"] + } + }, + { + name: "regionEdit", + path: "/regions/:id/edit", + component: () => + import("@/pages/Entity/Region/Form.vue"), + meta: { + title: "RegionEdit", + breadcrumbs: ["dashboard", "regionList", "regionEdit"] + } + }, + { + name: "regionAdd", + path: "/regions/add", + component: () => + import("@/pages/Entity/Region/Form.vue"), + meta: { + title: "RegionAdd", + breadcrumbs: ["dashboard", "regionList", "regionAdd"] + } + }, + /* EncryptionKey */ + { + name: "encryptionKeyList", + path: "/encryption-keys", + component: () => + import("@/pages/Entity/EncryptionKey/List.vue"), + meta: { + title: "EncryptionKeyList", + breadcrumbs: ["dashboard", "encryptionKeyList"] + } + }, + { + name: "encryptionKeyEdit", + path: "/encryption-keys/:id/edit", + component: () => + import("@/pages/Entity/EncryptionKey/Form.vue"), + meta: { + title: "EncryptionKeyEdit", + breadcrumbs: ["dashboard", "encryptionKeyList", "encryptionKeyEdit"] + } + }, + { + name: "encryptionKeyAdd", + path: "/encryption-keys/add", + component: () => + import("@/pages/Entity/EncryptionKey/Form.vue"), + meta: { + title: "EncryptionKeyAdd", + breadcrumbs: ["dashboard", "encryptionKeyList", "encryptionKeyAdd"] + } + }, + /* LoginCode */ + { + name: "loginCodeList", + path: "/login-codes", + component: () => + import("@/pages/Entity/LoginCode/List.vue"), + meta: { + title: "LoginCodeList", + breadcrumbs: ["dashboard", "loginCodeList"] + } + }, + { + name: "loginCodeEdit", + path: "/login-codes/:id/edit", + component: () => + import("@/pages/Entity/LoginCode/Form.vue"), + meta: { + title: "LoginCodeEdit", + breadcrumbs: ["dashboard", "loginCodeList", "loginCodeEdit"] + } + }, + { + name: "loginCodeAdd", + path: "/login-codes/add", + component: () => + import("@/pages/Entity/LoginCode/Form.vue"), + meta: { + title: "LoginCodeAdd", + breadcrumbs: ["dashboard", "loginCodeList", "loginCodeAdd"] + } + }, + /* SiteUser */ + { + name: "siteUserList", + path: "/site-users", + component: () => + import("@/pages/Entity/SiteUser/List.vue"), + meta: { + title: "SiteUserList", + breadcrumbs: ["dashboard", "siteUserList"] + } + }, + { + name: "siteUserEdit", + path: "/site-users/:id/edit", + component: () => + import("@/pages/Entity/SiteUser/Form.vue"), + meta: { + title: "SiteUserEdit", + breadcrumbs: ["dashboard", "siteUserList", "siteUserEdit"] + } + }, + { + name: "siteUserAdd", + path: "/site-users/add", + component: () => + import("@/pages/Entity/SiteUser/Form.vue"), + meta: { + title: "SiteUserAdd", + breadcrumbs: ["dashboard", "siteUserList", "siteUserAdd"] + } + }, + /* VfsFile */ + { + name: "vfsFileList", + path: "/vfs-files", + component: () => + import("@/pages/Entity/VfsFile/List.vue"), + meta: { + title: "VfsFileList", + breadcrumbs: ["dashboard", "vfsFileList"] + } + }, + { + name: "vfsFileEdit", + path: "/vfs-files/:id/edit", + component: () => + import("@/pages/Entity/VfsFile/Form.vue"), + meta: { + title: "VfsFileEdit", + breadcrumbs: ["dashboard", "vfsFileList", "vfsFileEdit"] + } + }, + { + name: "vfsFileAdd", + path: "/vfs-files/add", + component: () => + import("@/pages/Entity/VfsFile/Form.vue"), + meta: { + title: "VfsFileAdd", + breadcrumbs: ["dashboard", "vfsFileList", "vfsFileAdd"] + } + }, + /* VfsFolder */ + { + name: "vfsFolderList", + path: "/vfs-folders", + component: () => + import("@/pages/Entity/VfsFolder/List.vue"), + meta: { + title: "VfsFolderList", + breadcrumbs: ["dashboard", "vfsFolderList"] + } + }, + { + name: "vfsFolderEdit", + path: "/vfs-folders/:id/edit", + component: () => + import("@/pages/Entity/VfsFolder/Form.vue"), + meta: { + title: "VfsFolderEdit", + breadcrumbs: ["dashboard", "vfsFolderList", "vfsFolderEdit"] + } + }, + { + name: "vfsFolderAdd", + path: "/vfs-folders/add", + component: () => + import("@/pages/Entity/VfsFolder/Form.vue"), + meta: { + title: "VfsFolderAdd", + breadcrumbs: ["dashboard", "vfsFolderList", "vfsFolderAdd"] + } + }, ]; diff --git a/generators/vt-template/generator.go b/generators/vt-template/generator.go index 7375f6f..9239f76 100644 --- a/generators/vt-template/generator.go +++ b/generators/vt-template/generator.go @@ -4,7 +4,9 @@ import ( "bytes" "fmt" "html/template" + "os" "path" + "strings" "github.com/vmkteam/mfd-generator/mfd" @@ -93,7 +95,7 @@ func (g *Generator) ReadFlags(command *cobra.Command) error { if g.options.FiltersTemplatePath, err = flags.GetString(filterTemplateFlag); err != nil { return err } - if g.options.FiltersTemplatePath, err = flags.GetString(formTemplateFlag); err != nil { + if g.options.FormTemplatePath, err = flags.GetString(formTemplateFlag); err != nil { return err } @@ -141,7 +143,7 @@ func (g *Generator) Generate() error { } // generating routes for all namespaces - if _, err := g.SaveRoutes(project.VTNamespaces, routesTemplate); err != nil { + if _, err := g.SaveRoutes(project, routesTemplate); err != nil { return fmt.Errorf("generate routes, err=%w", err) } @@ -199,6 +201,32 @@ func (g *Generator) Generate() error { return mfd.SaveMFD(g.options.MFDPath, project) } +func (g *Generator) getTargetEntities(project *mfd.Project) []string { + var targetEntities []string + nsList := g.options.Namespaces + if len(nsList) == 0 { + nsList = project.NamespaceNames + } + for _, nsName := range nsList { + ns := project.VTNamespace(nsName) + if ns == nil { + continue + } + entityNames := ns.VTEntityNames() + if len(g.options.Entities) != 0 { + entityNames = g.options.Entities + } + + for _, eName := range entityNames { + if entity := ns.VTEntity(eName); entity != nil { + targetEntities = append(targetEntities, entity.Name) + } + } + } + + return targetEntities +} + // SaveEntity saves vt entity to template with special delims func (g *Generator) SaveEntity(entity mfd.VTEntity, output, tmpl string) error { parsed, err := template.New("base"). @@ -221,13 +249,20 @@ func (g *Generator) SaveEntity(entity mfd.VTEntity, output, tmpl string) error { } // SaveRoutes saves all vt namespaces to routes file -func (g *Generator) SaveRoutes(namespaces []*mfd.VTNamespace, tmpl string) (bool, error) { +func (g *Generator) SaveRoutes(project *mfd.Project, tmpl string) (bool, error) { + var targetEntities []string + isPartial := len(g.options.Namespaces) > 0 || len(g.options.Entities) > 0 + + if isPartial { + targetEntities = g.getTargetEntities(project) + } + parsed, err := template.New("base").Funcs(mfd.TemplateFunctions).Parse(tmpl) if err != nil { return false, fmt.Errorf("parsing template, err=%w", err) } - pack, err := PackRoutesNamespace(namespaces) + pack, err := PackRoutesNamespace(project.VTNamespaces) if err != nil { return false, fmt.Errorf("packing data, err=%w", err) } @@ -237,7 +272,110 @@ func (g *Generator) SaveRoutes(namespaces []*mfd.VTNamespace, tmpl string) (bool return false, fmt.Errorf("processing model template, err=%w", err) } - return mfd.Save(buffer.Bytes(), path.Join(g.options.Output, "src/pages/Entity/routes.ts")) + routesPath := path.Join(g.options.Output, "src/pages/Entity/routes.ts") + + // base flow when generate all routes + if len(targetEntities) == 0 { + return mfd.Save(buffer.Bytes(), routesPath) + } + + existingData, err := os.ReadFile(routesPath) + if err != nil { + return mfd.Save(buffer.Bytes(), routesPath) + } + + newStr := buffer.String() + existingStr := string(existingData) + + for _, entityName := range targetEntities { + // get new code block + newBlock := extractEntityBlock(newStr, entityName) + if len(newBlock) == 0 { + continue + } + // insert new code with flow + existingStr = injectEntityBlock(existingStr, entityName, newBlock) + } + + return mfd.Save([]byte(existingStr), routesPath) +} + +// extractEntityBlock get block code from content by entity name +func extractEntityBlock(content string, entityName string) []string { + var block []string + inBlock := false + marker := fmt.Sprintf("/* %s */", entityName) + + lines := strings.Split(content, "\n") + for _, line := range lines { + trimmed := strings.TrimSpace(line) + + if inBlock { + if strings.HasPrefix(trimmed, "/*") || trimmed == "];" { + break + } + block = append(block, strings.TrimPrefix(line, " ")) + } else if trimmed == marker { + inBlock = true + } + } + + return block +} + +// injectEntityBlock update or concat body with new blocks +func injectEntityBlock(existingContent string, entityName string, newBlock []string) string { + var result []string + inBlock := false + found := false + marker := fmt.Sprintf("/* %s */", entityName) + + lines := strings.Split(existingContent, "\n") + for _, line := range lines { + trimmed := strings.TrimSpace(line) + + if inBlock { + if strings.HasPrefix(trimmed, "/*") || trimmed == "];" { + inBlock = false + } else { + continue + } + } + + // Case 1 - when found + if !inBlock && trimmed == marker { + inBlock = true + found = true + + result = append(result, " "+marker) + for _, bLine := range newBlock { + result = append(result, " "+bLine) + } + continue + } + + // Case 2 - not found, create new + if !found && trimmed == "];" { + if len(result) > 0 { + lastIdx := len(result) - 1 + if strings.HasSuffix(strings.TrimSpace(result[lastIdx]), "}") { + result[lastIdx] += "," + } + } + + result = append(result, " "+marker) + for _, bLine := range newBlock { + result = append(result, " "+bLine) + } + found = true + } + + if !inBlock { + result = append(result, line) + } + } + + return strings.Join(result, "\n") } func (g *Generator) SaveLang(entity *mfd.TranslationEntity, lang string) error { diff --git a/generators/vt-template/generator_test.go b/generators/vt-template/generator_test.go index 3d5c8de..bf7727b 100644 --- a/generators/vt-template/generator_test.go +++ b/generators/vt-template/generator_test.go @@ -3,6 +3,7 @@ package vttmpl import ( "os" "path/filepath" + "reflect" "strings" "testing" @@ -56,6 +57,7 @@ func TestGenerator_Generate(t *testing.T) { Convey("Check correct generate with entities", func() { generator.options.Output = filepath.Join(testdata.PathActual, "vt-template", "entities") + // two Entities generator.options.Entities = []string{"Category", "Tag"} t.Log("Generate vt-template with entities") @@ -124,3 +126,244 @@ func fullFilesPaths(path string) ([]string, error) { return filePaths, nil } + +func TestManualGenerate(t *testing.T) { + t.Skip() + generator := New() + + generator.options.Output = "" + generator.options.MFDPath = "" + generator.options.Namespaces = []string{"article", "catalogue"} + generator.options.Entities = []string{"tag", "category"} + + err := generator.Generate() + if err != nil { + t.Error(err) + } +} + +func Test_extractEntityBlock(t *testing.T) { + type args struct { + content string + entityName string + } + tests := []struct { + name string + args args + want []string + }{ + { + name: "middle body contains", + args: args{ + entityName: "Category", + content: `export default [ + + /* News */ + { + name: "newsList", + path: "/news", + }, + /* Category */ + { + name: "categoryList", + path: "/category", + }, + /* Tag */ + { + name: "tagList", + }, +];`, + }, + want: []string{ + `{`, + ` name: "categoryList",`, + ` path: "/category",`, + `},`, + }, + }, + { + name: "last body", + args: args{ + entityName: "Tag", + content: `export default [ + /* Category */ + { + name: "categoryList", + }, + /* Tag */ + { + name: "tagList", + path: "/tags", + } +];`, + }, + want: []string{ + `{`, + ` name: "tagList",`, + ` path: "/tags",`, + `}`, + }, + }, + { + name: "now found", + args: args{ + entityName: "News", + content: `export default [ + /* Category */ + { + name: "categoryList", + }, +];`, + }, + want: nil, + }, + { + name: "empty content", + args: args{ + entityName: "Category", + content: ``, + }, + want: nil, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := extractEntityBlock(tt.args.content, tt.args.entityName) + + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("extractEntityBlock() =\n%#v\nwant\n%#v", got, tt.want) + } + }) + } +} + +func Test_injectEntityBlock(t *testing.T) { + sampleNewBlock := []string{ + `{`, + ` name: "tagList",`, + ` path: "/tags",`, + `},`, + } + + type args struct { + existingContent string + entityName string + newBlock []string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "update middle body", + args: args{ + entityName: "Tag", + newBlock: sampleNewBlock, + existingContent: `export default [ + /* Category */ + { + name: "categoryList", + }, + /* Tag */ + { + name: "oldTagList", + }, + /* News */ + { + name: "newsList", + } +];`, + }, + want: `export default [ + /* Category */ + { + name: "categoryList", + }, + /* Tag */ + { + name: "tagList", + path: "/tags", + }, + /* News */ + { + name: "newsList", + } +];`, + }, + { + name: "insert new data variant 1", + args: args{ + entityName: "Tag", + newBlock: sampleNewBlock, + existingContent: `export default [ + /* Category */ + { + name: "categoryList", + }, +];`, + }, + want: `export default [ + /* Category */ + { + name: "categoryList", + }, + /* Tag */ + { + name: "tagList", + path: "/tags", + }, +];`, + }, + { + name: "insert new data variant 2", + args: args{ + entityName: "Tag", + newBlock: sampleNewBlock, + existingContent: `export default [ + /* Category */ + { + name: "categoryList" + } +];`, + }, + want: `export default [ + /* Category */ + { + name: "categoryList" + }, + /* Tag */ + { + name: "tagList", + path: "/tags", + }, +];`, + }, + { + name: "insert new data variant 2", + args: args{ + entityName: "Tag", + newBlock: sampleNewBlock, + existingContent: `export default [ +];`, + }, + want: `export default [ + /* Tag */ + { + name: "tagList", + path: "/tags", + }, +];`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := injectEntityBlock(tt.args.existingContent, tt.args.entityName, tt.args.newBlock) + if got != tt.want { + t.Errorf("injectEntityBlock() failed.\n\n GOT \n%s\n\n WANT \n%s\n", got, tt.want) + } + }) + } +} diff --git a/generators/vt-template/template.go b/generators/vt-template/template.go index 10912aa..1d89d0b 100644 --- a/generators/vt-template/template.go +++ b/generators/vt-template/template.go @@ -2,34 +2,37 @@ package vttmpl const routesDefaultTemplate = `/* eslint-disable */ export default [{{range $model := .Entities}} - /* {{.Name}} */ - { - name: "{{.JSName}}List", - path: "/{{.TerminalPath}}", - component: () => - import("@/pages/Entity/{{.Name}}/List.vue"), - meta: { - breadcrumbs: ["dashboard", "{{.JSName}}List"] - } - }, - {{if not .ReadOnly}}{ - name: "{{.JSName}}Edit", - path: "/{{.TerminalPath}}/:id/edit", - component: () => - import("@/pages/Entity/{{.Name}}/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "{{.JSName}}List", "{{.JSName}}Edit"] - } - }, - { - name: "{{.JSName}}Add", - path: "/{{.TerminalPath}}/add", - component: () => - import("@/pages/Entity/{{.Name}}/Form.vue"), - meta: { - breadcrumbs: ["dashboard", "{{.JSName}}List", "{{.JSName}}Add"] - } - },{{end}}{{end}} + /* {{.Name}} */ + { + name: "{{.JSName}}List", + path: "/{{.TerminalPath}}", + component: () => + import("@/pages/Entity/{{.Name}}/List.vue"), + meta: { + title: "{{.Name}}List", + breadcrumbs: ["dashboard", "{{.JSName}}List"] + } + }, + {{if not .ReadOnly}}{ + name: "{{.JSName}}Edit", + path: "/{{.TerminalPath}}/:id/edit", + component: () => + import("@/pages/Entity/{{.Name}}/Form.vue"), + meta: { + title: "{{.Name}}Edit", + breadcrumbs: ["dashboard", "{{.JSName}}List", "{{.JSName}}Edit"] + } + }, + { + name: "{{.JSName}}Add", + path: "/{{.TerminalPath}}/add", + component: () => + import("@/pages/Entity/{{.Name}}/Form.vue"), + meta: { + title: "{{.Name}}Add", + breadcrumbs: ["dashboard", "{{.JSName}}List", "{{.JSName}}Add"] + } + },{{end}}{{end}} ]; ` @@ -54,27 +57,26 @@ const listDefaultTemplate = `