MishkaCmsMigrationWeb.Live.Admin.Dashboard.ImportSteps (Mishka CMS Migration v0.0.1)

Copy Markdown View Source

The steps of the New import window (MishkaCmsMigration.MigrationRun's form), for an admin who wants few choices. The form is Gervaz's :wizard layout: every step is in the form and only the current one shows, so an answer stays while the admin moves between them; Next checks the step before it moves on, Enter in a field is Next, and only the review starts the run:

  1. Where from: the source and its connection (group :connection);
  2. What to bring: a switch for each kind (group :bring);
  3. Languages: one language for everything, or the source's own (field :language);
  4. Review: what the run will do in plain words (review/1), and the Advanced options (group :options, collapsed), then Start the dry run.

It is the form's step handler (MishkaGervaz.Form.Web.Events.StepHandler). Leaving Where from checks more than the fields' own errors: a connection key the source requires that is blank is refused as "Enter the application password." (the key's label), and a filled connection is tried (MishkaCmsMigration.Source.connect/4): one the source refuses stays on the step with the reason in the words the save uses (MishkaCmsMigration.Resources.Changes.CheckConnection.message/2). A source that reads a file asks for the file instead, and reads it only when the run starts. A save refused on an earlier step, such as a connection that stopped answering, goes back to it with the error and an error flash naming the step (Gervaz's goto_errors/2).

start_over/1 draws Start over, which empties the window and returns it to the first step: the answers are otherwise kept while the window is closed and opened again, until a run starts.

Summary

Functions

Moves on from Where from only once the connection is filled and the source answers it (see the module doc); every other step moves on as Gervaz's step handler moves it. A refused Where from shows every error it has at once: a blank site beside a blank connection key. The connection is tried only once nothing else on the step is refused.

Whether the form may move past current_step: no field the step draws holds an error in the validated form (step_errors/2).

Move to the previous step in the wizard.

Moves a form whose save failed to the first step holding a field with an error (state.errors), and marks every step holding one :error.

Jump to a specific step (for tabs/free navigation mode).

The review step: its heading, "4 of 4: Review", and summary/1 in lines. It is part of the form, so it follows each answer as the admin changes it.

Start over, a quiet button that empties the window with the form component id and returns it to its first step (MishkaGervaz.Form.Web.Live.reset/2).

The review's lines as {role, words} pairs for the form state: :from, :bring, :left_out (omitted when nothing is switched off), :choices (omitted when every Advanced choice is at its default), :settings (omitted when none is left out), :language and :dry_run. An answer the form does not hold yet is the run's default.

Functions

advance(state, socket)

Moves on from Where from only once the connection is filled and the source answers it (see the module doc); every other step moves on as Gervaz's step handler moves it. A refused Where from shows every error it has at once: a blank site beside a blank connection key. The connection is tried only once nothing else on the step is refused.

can_advance?(state, current_step)

@spec can_advance?(MishkaGervaz.Form.Web.State.t(), atom()) :: boolean()

Whether the form may move past current_step: no field the step draws holds an error in the validated form (step_errors/2).

Override for custom per-step validation.

go_back(state, socket)

Move to the previous step in the wizard.

Uses wizard_history to determine the previous step.

goto_errors(state, socket)

Moves a form whose save failed to the first step holding a field with an error (state.errors), and marks every step holding one :error.

When that step is not the one the save was sent from, it also sends the parent LiveView {:put_flash, :error, message}, the message being the field's first error followed by the step to check, such as "Nothing answered at this address. Check it on step 1, Where from.". A form whose errors are on no field (state.form_errors) stays where it is: those show above the submit row.

goto_step(state, target_step, socket)

Jump to a specific step (for tabs/free navigation mode).

Only allowed when layout_navigation is :free, or the target step has been visited before.

review(assigns)

The review step: its heading, "4 of 4: Review", and summary/1 in lines. It is part of the form, so it follows each answer as the admin changes it.

Attributes

  • state (:map) (required)

start_over(assigns)

Start over, a quiet button that empties the window with the form component id and returns it to its first step (MishkaGervaz.Form.Web.Live.reset/2).

Attributes

  • id (:string) (required)

summary(state)

@spec summary(map()) :: [{atom(), String.t()}]

The review's lines as {role, words} pairs for the form state: :from, :bring, :left_out (omitted when nothing is switched off), :choices (omitted when every Advanced choice is at its default), :settings (omitted when none is left out), :language and :dry_run. An answer the form does not hold yet is the run's default.