1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2024-11-28 10:03:42 +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{
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",
)

View File

@ -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
}

View File

@ -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()
}

103
ui/package-lock.json generated
View File

@ -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",

View File

@ -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 @@
</div>
<div class="col-6 p-b-10">
<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>
</div>
<div class="col-6 p-b-10">
<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>
</div>
{/each}

View File

@ -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);
}
</script>
@ -64,7 +64,7 @@
{:else}
<div class="content txt-xl m-b-base">
<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.
</p>
</div>

View File

@ -125,7 +125,7 @@
await tick();
if (!newCollections.length) {
addErrorToast("Invalid collections list.");
addErrorToast("Invalid collections configuration.");
clear();
}
};
@ -177,7 +177,7 @@
/>
<p>
Paste below the collections you want to import or
Paste below the collections configuration you want to import or
<button
class="btn btn-outline btn-sm m-l-5"
class:btn-loading={isLoadingFile}
@ -202,7 +202,7 @@
/>
{#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}
</Field>
@ -212,7 +212,7 @@
<i class="ri-information-line" />
</div>
<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>
{/if}