-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(model-form): first 5 components to Glimmer
- Loading branch information
Showing
31 changed files
with
513 additions
and
245 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 |
---|---|---|
@@ -1,18 +1,20 @@ | ||
<div class='{{labelClass}}'></div> | ||
<div class='{{inputWrapperClass}}'> | ||
<div class='form-check'> | ||
<Input | ||
data-test-input={{property}} | ||
@type='checkbox' | ||
id={{inputIdentifier}} | ||
@checked={{mut (get model property)}} | ||
class={{concat 'form-check-input ' inputValidityClass}} | ||
required={{required}} | ||
disabled={{disabled}} | ||
/> | ||
<label class='form-check-label'> | ||
{{label}}{{if required ' *'}} | ||
{{form-control-feedback (get @model.errors property)}} | ||
</label> | ||
<div class='mb-3 {{if this.usesGrid 'row'}}'> | ||
<div class='{{this.labelClass}}'></div> | ||
<div class='{{this.inputWrapperClass}}'> | ||
<div class='form-check'> | ||
<Input | ||
data-test-input={{@property}} | ||
@type='checkbox' | ||
id={{this.inputIdentifier}} | ||
@checked={{mut (get @model @property)}} | ||
class={{concat 'form-check-input ' this.inputValidityClass}} | ||
required={{@required}} | ||
disabled={{@disabled}} | ||
/> | ||
<label class='form-check-label'> | ||
{{@label}}{{if @required ' *'}} | ||
{{form-control-feedback (get @model.errors @property)}} | ||
</label> | ||
</div> | ||
</div> | ||
</div> |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
import TextInput from './text-input'; | ||
|
||
export default class CheckboxInput extends TextInput {} |
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 |
---|---|---|
@@ -1,19 +1,21 @@ | ||
<label | ||
class='col-sm-2 col-form-label form-label' | ||
for={{inputIdentifier}} | ||
> | ||
{{label}}{{if required ' *'}} | ||
</label> | ||
<div class='col-sm-10'> | ||
<Input::DatetimeInput | ||
@inputId={{inputIdentifier}} | ||
@dateValue={{mut (get model property)}} | ||
@inputClass={{concat 'form-control ' inputValidityClass}} | ||
@placeholder={{placeholder}} | ||
@required={{required}} | ||
@disabled={{disabled}} | ||
@yearRange={{yearRange}} | ||
/> | ||
<div class='mb-3 {{if this.usesGrid 'row'}}'> | ||
<label | ||
class='col-sm-2 col-form-label form-label' | ||
for={{this.inputIdentifier}} | ||
> | ||
{{@label}}{{if @required ' *'}} | ||
</label> | ||
<div class='col-sm-10'> | ||
<Input::DatetimeInput | ||
@inputId={{this.inputIdentifier}} | ||
@dateValue={{mut (get @model @property)}} | ||
@inputClass={{concat 'form-control ' this.inputValidityClass}} | ||
@placeholder={{this.placeholder}} | ||
@required={{@required}} | ||
@disabled={{@disabled}} | ||
@yearRange={{@yearRange}} | ||
/> | ||
|
||
{{form-control-feedback (get @model.errors property)}} | ||
{{form-control-feedback (get @model.errors @property)}} | ||
</div> | ||
</div> |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
import TextInput from './text-input'; | ||
|
||
export default class DatetimeInput extends TextInput {} |
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 |
---|---|---|
@@ -1,36 +1,63 @@ | ||
<label class='col-form-label form-label {{labelClass}}'> | ||
{{label}}{{if required ' *'}} | ||
</label> | ||
<div class='{{inputWrapperClass}}'> | ||
{{#let (file-queue name="fileUpload" onFileAdded=(action 'fileLoaded')) as |queue|}} | ||
<label for="upload-file" class="form-label {{if not (get model property) "border rounded p-2 w-100"}}"> | ||
{{#if (get model property)}} | ||
<img id={{inputIdentifier}} src={{mut (get model property)}} alt={{label}} role="button" tabindex="0" | ||
aria-controls="upload-file" /> | ||
<br /> | ||
{{else}} | ||
<span class='image-upload-text' role="button" tabindex="0" aria-controls="upload-file"> | ||
Sleep hier een nieuwe bestand naartoe of klik om een bestand te kiezen | ||
</span> | ||
{{/if}} | ||
</label> | ||
<input type="file" id="upload-file" class="" hidden accept={{validMimetypes}} {{queue.selectFile}}> | ||
{{/let}} | ||
{{#if fileToBig}} | ||
<br /> | ||
<div class='alert alert-danger'> | ||
Dit bestand is te groot om te uploaden, gebruik een bestand kleiner dan | ||
{{maxFileSize}}MB | ||
</div> | ||
{{/if}} | ||
{{#if extensionNotPermitted}} | ||
<br /> | ||
<div class='alert alert-danger'> | ||
Deze bestandsextensie wordt niet ondersteund. Geaccepteerde extensies | ||
zijn: | ||
<b>{{validExtensionsString}}</b> | ||
</div> | ||
{{/if}} | ||
<div class='mb-3 {{if this.usesGrid "row"}}'> | ||
<label class='col-form-label form-label {{this.labelClass}}'> | ||
{{@label}}{{if @required ' *'}} | ||
</label> | ||
<div class={{this.inputWrapperClass}}> | ||
{{#let | ||
(file-queue name='fileUpload' onFileAdded=this.fileLoaded) | ||
as |queue| | ||
}} | ||
<label | ||
for='upload-file' | ||
class='form-label | ||
{{if not (get @model @property) "border rounded p-2 w-100"}}' | ||
> | ||
{{#if (get @model @property)}} | ||
<img | ||
id={{this.inputIdentifier}} | ||
src={{mut (get @model @property)}} | ||
alt={{@label}} | ||
role='button' | ||
tabindex='0' | ||
aria-controls='upload-file' | ||
/> | ||
<br /> | ||
{{else}} | ||
<span | ||
class='image-upload-text' | ||
role='button' | ||
tabindex='0' | ||
aria-controls='upload-file' | ||
> | ||
Sleep hier een nieuwe bestand naartoe of klik om een bestand te | ||
kiezen | ||
</span> | ||
{{/if}} | ||
</label> | ||
<input | ||
type='file' | ||
id='upload-file' | ||
hidden | ||
accept={{this.validMimeTypes}} | ||
{{queue.selectFile}} | ||
/> | ||
{{/let}} | ||
{{#if this.fileTooBig}} | ||
<br /> | ||
<div class='alert alert-danger'> | ||
Dit bestand is te groot om te uploaden, gebruik een bestand kleiner dan | ||
{{this.maxFilesize}} | ||
</div> | ||
{{/if}} | ||
{{#if this.extensionNotPermitted}} | ||
<br /> | ||
<div class='alert alert-danger'> | ||
Deze bestandsextensie wordt niet ondersteund. Geaccepteerde extensies | ||
zijn: | ||
<b>{{join ', ' this.validExtensions}}</b> | ||
</div> | ||
{{/if}} | ||
|
||
{{form-control-feedback (get @model.errors property)}} | ||
{{form-control-feedback (get @model.errors @property)}} | ||
</div> | ||
</div> |
This file was deleted.
Oops, something went wrong.
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,51 @@ | ||
import TextInput, { type TextInputSignature } from './text-input'; | ||
import ENV from 'amber-ui/config/environment'; | ||
import type { UploadFile } from 'ember-file-upload'; | ||
import { action } from '@ember/object'; | ||
import { tracked } from '@glimmer/tracking'; | ||
|
||
export interface FileInputSignature extends TextInputSignature { | ||
validMimeTypes?: string[]; | ||
validExtensions?: string[]; | ||
loadedCallback: ( | ||
file: UploadFile, | ||
data: Awaited<ReturnType<UploadFile['readAsDataURL']>> | ||
) => void; | ||
} | ||
|
||
export default class FileInput extends TextInput<FileInputSignature> { | ||
@tracked fileTooBig = false; | ||
@tracked extensionNotPermitted = false; | ||
|
||
maxFilesize = `${ENV.maxFilesize}MB`; | ||
|
||
get validMimeTypes() { | ||
return this.args.validMimeTypes ?? ['image/jpeg', 'image/png']; | ||
} | ||
|
||
get validExtensions() { | ||
return this.args.validExtensions ?? ['jpeg', 'jpg', 'png']; | ||
} | ||
|
||
extensionInvalid(file: UploadFile): boolean { | ||
const fileExtension = file.name.split('.').slice(-1)[0]?.toLowerCase(); | ||
if (typeof fileExtension === 'undefined') { | ||
throw new Error('Could not parse file extension'); | ||
} | ||
return !this.validExtensions.includes(fileExtension); | ||
} | ||
|
||
@action async fileLoaded(file: UploadFile): Promise<void> { | ||
this.fileTooBig = false; | ||
this.extensionNotPermitted = false; | ||
|
||
// File.size is in bytes | ||
if (file.size > ENV.maxFilesize * 1048576) { | ||
this.fileTooBig = true; | ||
} else if (this.extensionInvalid(file)) { | ||
this.extensionNotPermitted = true; | ||
} else { | ||
this.args.loadedCallback(file, await file.readAsDataURL()); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,22 @@ | ||
<label | ||
class='col-form-label form-label {{labelClass}}' | ||
for={{inputIdentifier}} | ||
> | ||
{{label}}{{if required ' *'}} | ||
</label> | ||
<div class='{{inputWrapperClass}}'> | ||
<Input::SelectInput | ||
@data-test-input={{property}} | ||
@class={{concat 'form-control ' inputValidityClass}} | ||
@elementId={{inputIdentifier}} | ||
@required={{required}} | ||
@disabled={{disabled}} | ||
@options={{options}} | ||
@placeholder={{placeholder}} | ||
@value={{mut (get model property)}} | ||
/> | ||
<div class='mb-3 {{if this.usesGrid 'row'}}'> | ||
<label | ||
class='col-form-label form-label {{this.labelClass}}' | ||
for={{this.inputIdentifier}} | ||
> | ||
{{@label}}{{if @required ' *'}} | ||
</label> | ||
<div class='{{this.inputWrapperClass}}'> | ||
<Input::SelectInput | ||
@data-test-input={{@property}} | ||
@class={{concat 'form-control ' this.inputValidityClass}} | ||
@elementId={{this.inputIdentifier}} | ||
@required={{@required}} | ||
@disabled={{@disabled}} | ||
@options={{@options}} | ||
@placeholder={{this.placeholder}} | ||
@value={{mut (get @model @property)}} | ||
/> | ||
|
||
{{form-control-feedback (get @model.errors property)}} | ||
{{form-control-feedback (get @model.errors @property)}} | ||
</div> | ||
</div> |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
import TextInput from './text-input'; | ||
|
||
export default class SelectInput extends TextInput {} |
Oops, something went wrong.