From b0ca9b2f1bb6da6dedce2c5c4da2b293bb49d38a Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sun, 7 Aug 2022 11:14:49 +0300 Subject: [PATCH] updated export/import form --- cmd/serve.go | 4 +- forms/admin_login.go | 35 +++++- models/base.go | 19 ++-- ui/package-lock.json | 103 +++--------------- ui/src/components/settings/ImportPopup.svelte | 6 +- .../settings/PageExportCollections.svelte | 4 +- .../settings/PageImportCollections.svelte | 8 +- 7 files changed, 66 insertions(+), 113 deletions(-) diff --git a/cmd/serve.go b/cmd/serve.go index 2c22cf38..f87078c1 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -28,7 +28,7 @@ func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command { command := &cobra.Command{ Use: "serve", - Short: "Starts the web server (default to localhost:8090)", + Short: "Starts the web server (default to 127.0.0.1:8090)", Run: func(command *cobra.Command, args []string) { // ensure that the latest migrations are applied before starting the server if err := runMigrations(app); err != nil { @@ -123,7 +123,7 @@ func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command { command.PersistentFlags().StringVar( &httpAddr, "http", - "localhost:8090", + "127.0.0.1:8090", "api HTTP server address", ) diff --git a/forms/admin_login.go b/forms/admin_login.go index 842552ed..fbdad0c4 100644 --- a/forms/admin_login.go +++ b/forms/admin_login.go @@ -6,20 +6,47 @@ import ( validation "github.com/go-ozzo/ozzo-validation/v4" "github.com/go-ozzo/ozzo-validation/v4/is" "github.com/pocketbase/pocketbase/core" + "github.com/pocketbase/pocketbase/daos" "github.com/pocketbase/pocketbase/models" ) // AdminLogin defines an admin email/pass login form. type AdminLogin struct { - app core.App + config AdminLoginConfig Email string `form:"email" json:"email"` Password string `form:"password" json:"password"` } -// NewAdminLogin creates new admin login form for the provided app. +// AdminLoginConfig is the [AdminLogin] factory initializer config. +// +// NB! Dao is a required struct member. +type AdminLoginConfig struct { + Dao *daos.Dao +} + +// NewAdminLogin creates a new [AdminLogin] form with initializer +// config created from the provided [core.App] instance. +// +// This factory method is used primarily for convenience (and backward compatibility). +// If you want to submit the form as part of another transaction, use +// [NewCollectionUpsertWithConfig] with Dao configured to your txDao. func NewAdminLogin(app core.App) *AdminLogin { - return &AdminLogin{app: app} + return NewAdminLoginWithConfig(AdminLoginConfig{ + Dao: app.Dao(), + }) +} + +// NewAdminLoginWithConfig creates a new [AdminLogin] form +// with the provided config or panics on invalid configuration. +func NewAdminLoginWithConfig(config AdminLoginConfig) *AdminLogin { + form := &AdminLogin{config: config} + + if form.config.Dao == nil { + panic("Invalid initializer config.") + } + + return form } // Validate makes the form validatable by implementing [validation.Validatable] interface. @@ -37,7 +64,7 @@ func (form *AdminLogin) Submit() (*models.Admin, error) { return nil, err } - admin, err := form.app.Dao().FindAdminByEmail(form.Email) + admin, err := form.config.Dao.FindAdminByEmail(form.Email) if err != nil { return nil, err } diff --git a/models/base.go b/models/base.go index b5477836..b965416f 100644 --- a/models/base.go +++ b/models/base.go @@ -30,9 +30,9 @@ type Model interface { IsNew() bool MarkAsNew() UnmarkAsNew() - SetId(id string) HasId() bool GetId() string + SetId(id string) GetCreated() types.DateTime GetUpdated() types.DateTime RefreshId() @@ -46,7 +46,6 @@ type Model interface { // BaseModel defines common fields and methods used by all other models. type BaseModel struct { - insertId string isNewFlag bool Id string `db:"id" json:"id"` @@ -59,22 +58,22 @@ func (m *BaseModel) HasId() bool { return m.GetId() != "" } -// GetId returns the model's id. +// GetId returns the model id. func (m *BaseModel) GetId() string { return m.Id } -// SetId sets the model's id to the provided one. +// SetId sets the model id to the provided string value. func (m *BaseModel) SetId(id string) { m.Id = id } -// UnmarkAsNew sets the model's isNewFlag enforcing [m.IsNew()] to be true. +// MarkAsNew sets the model isNewFlag enforcing [m.IsNew()] to be true. func (m *BaseModel) MarkAsNew() { m.isNewFlag = true } -// UnmarkAsNew clears the enforced model's isNewFlag. +// UnmarkAsNew resets the model isNewFlag. func (m *BaseModel) UnmarkAsNew() { m.isNewFlag = false } @@ -85,12 +84,12 @@ func (m *BaseModel) IsNew() bool { return m.isNewFlag || !m.HasId() } -// GetCreated returns the model's Created datetime. +// GetCreated returns the model Created datetime. func (m *BaseModel) GetCreated() types.DateTime { return m.Created } -// GetUpdated returns the model's Updated datetime. +// GetUpdated returns the model Updated datetime. func (m *BaseModel) GetUpdated() types.DateTime { return m.Updated } @@ -102,12 +101,12 @@ func (m *BaseModel) RefreshId() { m.Id = security.RandomString(DefaultIdLength) } -// RefreshCreated updates the model's Created field with the current datetime. +// RefreshCreated updates the model Created field with the current datetime. func (m *BaseModel) RefreshCreated() { m.Created = types.NowDateTime() } -// RefreshUpdated updates the model's Updated field with the current datetime. +// RefreshUpdated updates the model Updated field with the current datetime. func (m *BaseModel) RefreshUpdated() { m.Updated = types.NowDateTime() } diff --git a/ui/package-lock.json b/ui/package-lock.json index d5cdf1e6..03a614c8 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -8,7 +8,6 @@ "devDependencies": { "@codemirror/autocomplete": "^6.0.0", "@codemirror/commands": "^6.0.0", - "@codemirror/lang-javascript": "^6.0.2", "@codemirror/language": "^6.0.0", "@codemirror/legacy-modes": "^6.0.0", "@codemirror/search": "^6.0.0", @@ -28,7 +27,7 @@ } }, "../../js-sdk": { - "version": "0.3.1", + "version": "0.4.0", "dev": true, "license": "MIT", "devDependencies": { @@ -47,11 +46,11 @@ "node-fetch": "^3.2.8", "rollup": "^2.63.0", "rollup-plugin-terser": "^7.0.0", - "rollup-plugin-ts": "^2.0.0", + "rollup-plugin-ts": "^3.0.0", "ts-node": "^10.0.0", - "tsconfig-paths": "^3.9.0", - "tslib": "^2.3.0", - "typescript": "4.6.4" + "tsconfig-paths": "^4.0.0", + "tslib": "^2.4.0", + "typescript": "^4.7.4" } }, "node_modules/@codemirror/autocomplete": { @@ -84,21 +83,6 @@ "@lezer/common": "^1.0.0" } }, - "node_modules/@codemirror/lang-javascript": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/@codemirror/lang-javascript/-/lang-javascript-6.0.2.tgz", - "integrity": "sha512-BZRJ9u/zl16hLkSpDAWm73mrfIR7HJrr0lvnhoSOCQVea5BglguWI/slxexhvUb0CB5cXgKWuo2bM+N9EhIaZw==", - "dev": true, - "dependencies": { - "@codemirror/autocomplete": "^6.0.0", - "@codemirror/language": "^6.0.0", - "@codemirror/lint": "^6.0.0", - "@codemirror/state": "^6.0.0", - "@codemirror/view": "^6.0.0", - "@lezer/common": "^1.0.0", - "@lezer/javascript": "^1.0.0" - } - }, "node_modules/@codemirror/language": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.2.1.tgz", @@ -122,17 +106,6 @@ "@codemirror/language": "^6.0.0" } }, - "node_modules/@codemirror/lint": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.0.0.tgz", - "integrity": "sha512-nUUXcJW1Xp54kNs+a1ToPLK8MadO0rMTnJB8Zk4Z8gBdrN0kqV7uvUraU/T2yqg+grDNR38Vmy/MrhQN/RgwiA==", - "dev": true, - "dependencies": { - "@codemirror/state": "^6.0.0", - "@codemirror/view": "^6.0.0", - "crelt": "^1.0.5" - } - }, "node_modules/@codemirror/search": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.0.1.tgz", @@ -192,16 +165,6 @@ "@lezer/common": "^1.0.0" } }, - "node_modules/@lezer/javascript": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.0.2.tgz", - "integrity": "sha512-IjOVeIRhM8IuafWNnk+UzRz7p4/JSOKBNINLYLsdSGuJS9Ju7vFdc82AlTt0jgtV5D8eBZf4g0vK4d3ttBNz7A==", - "dev": true, - "dependencies": { - "@lezer/highlight": "^1.0.0", - "@lezer/lr": "^1.0.0" - } - }, "node_modules/@lezer/lr": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.2.1.tgz", @@ -930,9 +893,9 @@ "link": true }, "node_modules/postcss": { - "version": "8.4.14", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", - "integrity": "sha512-E398TUmfAYFPBSdzgeieK2Y1+1cpdxJx8yXbK/m57nRhKSmk1GB2tO4lbLBtlkfPQTDKfe4Xqv1ASWPpayPEig==", + "version": "8.4.16", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.16.tgz", + "integrity": "sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==", "dev": true, "funding": [ { @@ -1195,21 +1158,6 @@ "@lezer/common": "^1.0.0" } }, - "@codemirror/lang-javascript": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/@codemirror/lang-javascript/-/lang-javascript-6.0.2.tgz", - "integrity": "sha512-BZRJ9u/zl16hLkSpDAWm73mrfIR7HJrr0lvnhoSOCQVea5BglguWI/slxexhvUb0CB5cXgKWuo2bM+N9EhIaZw==", - "dev": true, - "requires": { - "@codemirror/autocomplete": "^6.0.0", - "@codemirror/language": "^6.0.0", - "@codemirror/lint": "^6.0.0", - "@codemirror/state": "^6.0.0", - "@codemirror/view": "^6.0.0", - "@lezer/common": "^1.0.0", - "@lezer/javascript": "^1.0.0" - } - }, "@codemirror/language": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.2.1.tgz", @@ -1233,17 +1181,6 @@ "@codemirror/language": "^6.0.0" } }, - "@codemirror/lint": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.0.0.tgz", - "integrity": "sha512-nUUXcJW1Xp54kNs+a1ToPLK8MadO0rMTnJB8Zk4Z8gBdrN0kqV7uvUraU/T2yqg+grDNR38Vmy/MrhQN/RgwiA==", - "dev": true, - "requires": { - "@codemirror/state": "^6.0.0", - "@codemirror/view": "^6.0.0", - "crelt": "^1.0.5" - } - }, "@codemirror/search": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.0.1.tgz", @@ -1294,16 +1231,6 @@ "@lezer/common": "^1.0.0" } }, - "@lezer/javascript": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.0.2.tgz", - "integrity": "sha512-IjOVeIRhM8IuafWNnk+UzRz7p4/JSOKBNINLYLsdSGuJS9Ju7vFdc82AlTt0jgtV5D8eBZf4g0vK4d3ttBNz7A==", - "dev": true, - "requires": { - "@lezer/highlight": "^1.0.0", - "@lezer/lr": "^1.0.0" - } - }, "@lezer/lr": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.2.1.tgz", @@ -1753,17 +1680,17 @@ "node-fetch": "^3.2.8", "rollup": "^2.63.0", "rollup-plugin-terser": "^7.0.0", - "rollup-plugin-ts": "^2.0.0", + "rollup-plugin-ts": "^3.0.0", "ts-node": "^10.0.0", - "tsconfig-paths": "^3.9.0", - "tslib": "^2.3.0", - "typescript": "4.6.4" + "tsconfig-paths": "^4.0.0", + "tslib": "^2.4.0", + "typescript": "^4.7.4" } }, "postcss": { - "version": "8.4.14", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", - "integrity": "sha512-E398TUmfAYFPBSdzgeieK2Y1+1cpdxJx8yXbK/m57nRhKSmk1GB2tO4lbLBtlkfPQTDKfe4Xqv1ASWPpayPEig==", + "version": "8.4.16", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.16.tgz", + "integrity": "sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==", "dev": true, "requires": { "nanoid": "^3.3.4", diff --git a/ui/src/components/settings/ImportPopup.svelte b/ui/src/components/settings/ImportPopup.svelte index 86eac0b1..a8e51961 100644 --- a/ui/src/components/settings/ImportPopup.svelte +++ b/ui/src/components/settings/ImportPopup.svelte @@ -112,7 +112,7 @@ try { await ApiClient.collections.import(newCollections); - addSuccessToast("Successfully imported the provided collections."); + addSuccessToast("Successfully imported the collections configuration."); dispatch("submit"); } catch (err) { ApiClient.errorResponseHandler(err); @@ -162,12 +162,12 @@
- {@html diff(pair.old, pair.new, [window.DIFF_DELETE, window.DIFF_EQUAL])} + {@html diff(pair.old, pair.new, [window.DIFF_DELETE, window.DIFF_EQUAL]) || "N/A"}
- {@html diff(pair.old, pair.new, [window.DIFF_INSERT, window.DIFF_EQUAL])} + {@html diff(pair.old, pair.new, [window.DIFF_INSERT, window.DIFF_EQUAL]) || "N/A"}
{/each} diff --git a/ui/src/components/settings/PageExportCollections.svelte b/ui/src/components/settings/PageExportCollections.svelte index 18f3d955..7898bfe7 100644 --- a/ui/src/components/settings/PageExportCollections.svelte +++ b/ui/src/components/settings/PageExportCollections.svelte @@ -43,7 +43,7 @@ function copy() { CommonHelper.copyToClipboard(schema); - addInfoToast("The schema was copied to your clipboard!", 3000); + addInfoToast("The collections list was copied to your clipboard!", 3000); } @@ -64,7 +64,7 @@ {:else}

- Below you'll find your current collections schema that you could import later in + Below you'll find your current collections configuration that you could import in another PocketBase environment.

diff --git a/ui/src/components/settings/PageImportCollections.svelte b/ui/src/components/settings/PageImportCollections.svelte index 18f5362e..c1cf7748 100644 --- a/ui/src/components/settings/PageImportCollections.svelte +++ b/ui/src/components/settings/PageImportCollections.svelte @@ -125,7 +125,7 @@ await tick(); if (!newCollections.length) { - addErrorToast("Invalid collections list."); + addErrorToast("Invalid collections configuration."); clear(); } }; @@ -177,7 +177,7 @@ />

- Paste below the collections you want to import or + Paste below the collections configuration you want to import or