-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
735 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
export const Combobox = { | ||
mounted() { | ||
const wrapperEl = this.el.closest('div') | ||
const toggleButton = wrapperEl.querySelector('button[phx-click="toggle-options"]') | ||
const myself = this.el.getAttribute('phx-target') | ||
|
||
this.el.addEventListener('keydown', event => { | ||
if (['ArrowUp', 'ArrowDown'].includes(event.key)) { | ||
// Prevent cursor-move from first to last character | ||
event.preventDefault() | ||
} | ||
|
||
if (event.key === 'Enter' && document.activeElement === this.el) { | ||
// Prevent Submit when combobox is focused | ||
event.preventDefault() | ||
|
||
const listEl = wrapperEl.querySelector('ul') | ||
const value = listEl && listEl.dataset.focusedOption || null | ||
|
||
// The focused value are stored in a data attribute. | ||
// So, send the selected value to the component. | ||
this.pushEventTo(myself, "select-option", {option: value}) | ||
} | ||
}) | ||
|
||
this.el.addEventListener('keyup', event => { | ||
if (['Enter', 'Tab', 'Escape', 'ArrowUp', 'ArrowDown'].includes(event.key)) return | ||
|
||
// Push the search phrase to the LiveComponent | ||
this.pushEventTo(myself, "filter-options", {search_phrase: this.el.value}) | ||
}) | ||
|
||
toggleButton && toggleButton.addEventListener('click', event => { | ||
this.el.focus() | ||
}) | ||
|
||
this.handleEvent("set-input-value", data => { | ||
// This is sent to all instances of this hook so we need to compare id:s | ||
if (data.id !== this.el.id) return | ||
this.el.value = data.label | ||
}) | ||
} | ||
} | ||
|
||
export const ComboboxOption = { | ||
mounted() { | ||
this.el.addEventListener('mouseover', event => { | ||
const el = event.target | ||
const value = el.getAttribute('phx-value-option') | ||
const target = el.getAttribute('phx-target') | ||
|
||
this.pushEventTo(target, "set-focus-to", {value: value}) | ||
}) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule MakerPassport.Maker.ProfileSkill do | ||
@moduledoc false | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
alias MakerPassport.Maker.{Profile, Skill} | ||
|
||
schema "profile_skills" do | ||
|
||
belongs_to :profile, Profile | ||
belongs_to :skill, Skill | ||
|
||
timestamps(type: :utc_datetime) | ||
end | ||
|
||
@doc false | ||
def changeset(profile_skill, attrs) do | ||
profile_skill | ||
|> cast(attrs, [:profile_id, :skill_id]) | ||
|> validate_required([:profile_id, :skill_id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule MakerPassport.Maker.Skill do | ||
@moduledoc false | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
alias MakerPassport.Maker.Profile | ||
|
||
schema "skills" do | ||
field :name, :string | ||
|
||
many_to_many :profiles, Profile, join_through: "profile_skills" | ||
|
||
timestamps(type: :utc_datetime) | ||
end | ||
|
||
@doc false | ||
def changeset(skill, attrs \\ %{}) do | ||
skill | ||
|> cast(attrs, [:name]) | ||
|> validate_required([:name]) | ||
end | ||
end |
Oops, something went wrong.