1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-02-16 09:21:45 +02:00

updated export/import form

This commit is contained in:
Gani Georgiev 2022-08-07 11:14:49 +03:00
parent 956263d1fc
commit b0ca9b2f1b
7 changed files with 66 additions and 113 deletions

View File

@ -28,7 +28,7 @@ func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command {
command := &cobra.Command{ command := &cobra.Command{
Use: "serve", 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) { Run: func(command *cobra.Command, args []string) {
// ensure that the latest migrations are applied before starting the server // ensure that the latest migrations are applied before starting the server
if err := runMigrations(app); err != nil { if err := runMigrations(app); err != nil {
@ -123,7 +123,7 @@ func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command {
command.PersistentFlags().StringVar( command.PersistentFlags().StringVar(
&httpAddr, &httpAddr,
"http", "http",
"localhost:8090", "127.0.0.1:8090",
"api HTTP server address", "api HTTP server address",
) )

View File

@ -6,20 +6,47 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/go-ozzo/ozzo-validation/v4/is" "github.com/go-ozzo/ozzo-validation/v4/is"
"github.com/pocketbase/pocketbase/core" "github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/models" "github.com/pocketbase/pocketbase/models"
) )
// AdminLogin defines an admin email/pass login form. // AdminLogin defines an admin email/pass login form.
type AdminLogin struct { type AdminLogin struct {
app core.App config AdminLoginConfig
Email string `form:"email" json:"email"` Email string `form:"email" json:"email"`
Password string `form:"password" json:"password"` 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 { 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. // Validate makes the form validatable by implementing [validation.Validatable] interface.
@ -37,7 +64,7 @@ func (form *AdminLogin) Submit() (*models.Admin, error) {
return nil, err return nil, err
} }
admin, err := form.app.Dao().FindAdminByEmail(form.Email) admin, err := form.config.Dao.FindAdminByEmail(form.Email)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -30,9 +30,9 @@ type Model interface {
IsNew() bool IsNew() bool
MarkAsNew() MarkAsNew()
UnmarkAsNew() UnmarkAsNew()
SetId(id string)
HasId() bool HasId() bool
GetId() string GetId() string
SetId(id string)
GetCreated() types.DateTime GetCreated() types.DateTime
GetUpdated() types.DateTime GetUpdated() types.DateTime
RefreshId() RefreshId()
@ -46,7 +46,6 @@ type Model interface {
// BaseModel defines common fields and methods used by all other models. // BaseModel defines common fields and methods used by all other models.
type BaseModel struct { type BaseModel struct {
insertId string
isNewFlag bool isNewFlag bool
Id string `db:"id" json:"id"` Id string `db:"id" json:"id"`
@ -59,22 +58,22 @@ func (m *BaseModel) HasId() bool {
return m.GetId() != "" return m.GetId() != ""
} }
// GetId returns the model's id. // GetId returns the model id.
func (m *BaseModel) GetId() string { func (m *BaseModel) GetId() string {
return m.Id 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) { func (m *BaseModel) SetId(id string) {
m.Id = id 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() { func (m *BaseModel) MarkAsNew() {
m.isNewFlag = true m.isNewFlag = true
} }
// UnmarkAsNew clears the enforced model's isNewFlag. // UnmarkAsNew resets the model isNewFlag.
func (m *BaseModel) UnmarkAsNew() { func (m *BaseModel) UnmarkAsNew() {
m.isNewFlag = false m.isNewFlag = false
} }
@ -85,12 +84,12 @@ func (m *BaseModel) IsNew() bool {
return m.isNewFlag || !m.HasId() return m.isNewFlag || !m.HasId()
} }
// GetCreated returns the model's Created datetime. // GetCreated returns the model Created datetime.
func (m *BaseModel) GetCreated() types.DateTime { func (m *BaseModel) GetCreated() types.DateTime {
return m.Created return m.Created
} }
// GetUpdated returns the model's Updated datetime. // GetUpdated returns the model Updated datetime.
func (m *BaseModel) GetUpdated() types.DateTime { func (m *BaseModel) GetUpdated() types.DateTime {
return m.Updated return m.Updated
} }
@ -102,12 +101,12 @@ func (m *BaseModel) RefreshId() {
m.Id = security.RandomString(DefaultIdLength) 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() { func (m *BaseModel) RefreshCreated() {
m.Created = types.NowDateTime() 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() { func (m *BaseModel) RefreshUpdated() {
m.Updated = types.NowDateTime() m.Updated = types.NowDateTime()
} }

103
ui/package-lock.json generated
View File

@ -8,7 +8,6 @@
"devDependencies": { "devDependencies": {
"@codemirror/autocomplete": "^6.0.0", "@codemirror/autocomplete": "^6.0.0",
"@codemirror/commands": "^6.0.0", "@codemirror/commands": "^6.0.0",
"@codemirror/lang-javascript": "^6.0.2",
"@codemirror/language": "^6.0.0", "@codemirror/language": "^6.0.0",
"@codemirror/legacy-modes": "^6.0.0", "@codemirror/legacy-modes": "^6.0.0",
"@codemirror/search": "^6.0.0", "@codemirror/search": "^6.0.0",
@ -28,7 +27,7 @@
} }
}, },
"../../js-sdk": { "../../js-sdk": {
"version": "0.3.1", "version": "0.4.0",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
@ -47,11 +46,11 @@
"node-fetch": "^3.2.8", "node-fetch": "^3.2.8",
"rollup": "^2.63.0", "rollup": "^2.63.0",
"rollup-plugin-terser": "^7.0.0", "rollup-plugin-terser": "^7.0.0",
"rollup-plugin-ts": "^2.0.0", "rollup-plugin-ts": "^3.0.0",
"ts-node": "^10.0.0", "ts-node": "^10.0.0",
"tsconfig-paths": "^3.9.0", "tsconfig-paths": "^4.0.0",
"tslib": "^2.3.0", "tslib": "^2.4.0",
"typescript": "4.6.4" "typescript": "^4.7.4"
} }
}, },
"node_modules/@codemirror/autocomplete": { "node_modules/@codemirror/autocomplete": {
@ -84,21 +83,6 @@
"@lezer/common": "^1.0.0" "@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": { "node_modules/@codemirror/language": {
"version": "6.2.1", "version": "6.2.1",
"resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.2.1.tgz", "resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.2.1.tgz",
@ -122,17 +106,6 @@
"@codemirror/language": "^6.0.0" "@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": { "node_modules/@codemirror/search": {
"version": "6.0.1", "version": "6.0.1",
"resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.0.1.tgz", "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.0.1.tgz",
@ -192,16 +165,6 @@
"@lezer/common": "^1.0.0" "@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": { "node_modules/@lezer/lr": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.2.1.tgz", "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.2.1.tgz",
@ -930,9 +893,9 @@
"link": true "link": true
}, },
"node_modules/postcss": { "node_modules/postcss": {
"version": "8.4.14", "version": "8.4.16",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.16.tgz",
"integrity": "sha512-E398TUmfAYFPBSdzgeieK2Y1+1cpdxJx8yXbK/m57nRhKSmk1GB2tO4lbLBtlkfPQTDKfe4Xqv1ASWPpayPEig==", "integrity": "sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {
@ -1195,21 +1158,6 @@
"@lezer/common": "^1.0.0" "@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": { "@codemirror/language": {
"version": "6.2.1", "version": "6.2.1",
"resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.2.1.tgz", "resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.2.1.tgz",
@ -1233,17 +1181,6 @@
"@codemirror/language": "^6.0.0" "@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": { "@codemirror/search": {
"version": "6.0.1", "version": "6.0.1",
"resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.0.1.tgz", "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.0.1.tgz",
@ -1294,16 +1231,6 @@
"@lezer/common": "^1.0.0" "@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": { "@lezer/lr": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.2.1.tgz", "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.2.1.tgz",
@ -1753,17 +1680,17 @@
"node-fetch": "^3.2.8", "node-fetch": "^3.2.8",
"rollup": "^2.63.0", "rollup": "^2.63.0",
"rollup-plugin-terser": "^7.0.0", "rollup-plugin-terser": "^7.0.0",
"rollup-plugin-ts": "^2.0.0", "rollup-plugin-ts": "^3.0.0",
"ts-node": "^10.0.0", "ts-node": "^10.0.0",
"tsconfig-paths": "^3.9.0", "tsconfig-paths": "^4.0.0",
"tslib": "^2.3.0", "tslib": "^2.4.0",
"typescript": "4.6.4" "typescript": "^4.7.4"
} }
}, },
"postcss": { "postcss": {
"version": "8.4.14", "version": "8.4.16",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.16.tgz",
"integrity": "sha512-E398TUmfAYFPBSdzgeieK2Y1+1cpdxJx8yXbK/m57nRhKSmk1GB2tO4lbLBtlkfPQTDKfe4Xqv1ASWPpayPEig==", "integrity": "sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"nanoid": "^3.3.4", "nanoid": "^3.3.4",

View File

@ -112,7 +112,7 @@
try { try {
await ApiClient.collections.import(newCollections); await ApiClient.collections.import(newCollections);
addSuccessToast("Successfully imported the provided collections."); addSuccessToast("Successfully imported the collections configuration.");
dispatch("submit"); dispatch("submit");
} catch (err) { } catch (err) {
ApiClient.errorResponseHandler(err); ApiClient.errorResponseHandler(err);
@ -162,12 +162,12 @@
</div> </div>
<div class="col-6 p-b-10"> <div class="col-6 p-b-10">
<code class="code-block"> <code class="code-block">
{@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"}
</code> </code>
</div> </div>
<div class="col-6 p-b-10"> <div class="col-6 p-b-10">
<code class="code-block"> <code class="code-block">
{@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"}
</code> </code>
</div> </div>
{/each} {/each}

View File

@ -43,7 +43,7 @@
function copy() { function copy() {
CommonHelper.copyToClipboard(schema); CommonHelper.copyToClipboard(schema);
addInfoToast("The schema was copied to your clipboard!", 3000); addInfoToast("The collections list was copied to your clipboard!", 3000);
} }
</script> </script>
@ -64,7 +64,7 @@
{:else} {:else}
<div class="content txt-xl m-b-base"> <div class="content txt-xl m-b-base">
<p> <p>
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. another PocketBase environment.
</p> </p>
</div> </div>

View File

@ -125,7 +125,7 @@
await tick(); await tick();
if (!newCollections.length) { if (!newCollections.length) {
addErrorToast("Invalid collections list."); addErrorToast("Invalid collections configuration.");
clear(); clear();
} }
}; };
@ -177,7 +177,7 @@
/> />
<p> <p>
Paste below the collections you want to import or Paste below the collections configuration you want to import or
<button <button
class="btn btn-outline btn-sm m-l-5" class="btn btn-outline btn-sm m-l-5"
class:btn-loading={isLoadingFile} class:btn-loading={isLoadingFile}
@ -202,7 +202,7 @@
/> />
{#if !!schemas && !isValid} {#if !!schemas && !isValid}
<div class="help-block help-block-error">Invalid collections schemas.</div> <div class="help-block help-block-error">Invalid collections configuration.</div>
{/if} {/if}
</Field> </Field>
@ -212,7 +212,7 @@
<i class="ri-information-line" /> <i class="ri-information-line" />
</div> </div>
<div class="content"> <div class="content">
<string>Your collections structure is already up-to-date!</string> <string>Your collections configuration is already up-to-date!</string>
</div> </div>
</div> </div>
{/if} {/if}