Skip to content

Commit

Permalink
updated export/import form
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Aug 7, 2022
1 parent 956263d commit b0ca9b2
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 113 deletions.
4 changes: 2 additions & 2 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
)

Expand Down
35 changes: 31 additions & 4 deletions forms/admin_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand Down
19 changes: 9 additions & 10 deletions models/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"`
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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()
}
Expand Down
103 changes: 15 additions & 88 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ui/src/components/settings/ImportPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/settings/PageExportCollections.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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>
Expand Down
Loading

0 comments on commit b0ca9b2

Please sign in to comment.