-
Notifications
You must be signed in to change notification settings - Fork 152
[My Site Migration] migration of profile page [PR-3] #980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iamitprakash
merged 17 commits into
RealDevSquad:develop
from
Suvidh-kaushik:migrate/profile_view_PR-3
Feb 5, 2025
Merged
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
430b052
basic setup and images and svg file
Suvidh-kaushik b066146
profile route and controller
Suvidh-kaushik 4f55393
changed urls.js file
Suvidh-kaushik a372e6d
components and profile template
Suvidh-kaushik 5cef76c
Merge branch 'develop' into migrate/profile_view_PR-3
Suvidh-kaushik 55917e2
fixes regardinng spinner and link fixes
Suvidh-kaushik 047d20a
fixed headers test
Suvidh-kaushik 14858f3
fixed uncessecary changes during rebase
Suvidh-kaushik f416e76
fixed file type in upload-image test
Suvidh-kaushik 8bb1a75
fixed constants file and tests
Suvidh-kaushik e5a1b35
Merge branch 'develop' into migrate/profile_view_PR-3
Suvidh-kaushik 80ec12e
failing test fixes
Suvidh-kaushik 1ff1e3f
Merge branch 'develop' into migrate/profile_view_PR-3
Suvidh-kaushik bd9bc26
removed yarn.lock file
Suvidh-kaushik 27624ff
moved profile-image button to /profile in componente
Suvidh-kaushik 850aa13
Merge branch 'develop' into migrate/profile_view_PR-3
iamitprakash f8e0ea5
Merge branch 'develop' into migrate/profile_view_PR-3
Suvidh-kaushik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,12 @@ | ||
| <button | ||
| data-test-btn={{@data-test-btn}} | ||
| type='button' | ||
| class={{if @disabled (concat @class ' btn-disabled') @class}} | ||
| disabled={{@disabled}} | ||
| {{on 'click' @onClick}} | ||
| > | ||
| {{#if @isLoading}} | ||
| <i class='fa fa-spinner fa-spin' data-test-button-spinner></i> | ||
| {{/if}} | ||
| {{yield}} | ||
| </button> |
This file contains hidden or 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 hidden or 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,10 @@ | ||
| <div class='image-cropper-container'> | ||
| <img | ||
| data-test-image-cropper | ||
| class='image-cropper' | ||
| id='image-cropper' | ||
| alt='Cropper' | ||
| src={{this.image}} | ||
| onload={{this.loadCropper}} | ||
| /> | ||
| </div> |
This file contains hidden or 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,38 @@ | ||
| import Component from '@glimmer/component'; | ||
| import Cropper from 'cropperjs'; | ||
| import { action } from '@ember/object'; | ||
|
|
||
| export default class ImageCropperComponent extends Component { | ||
| get image() { | ||
| if (this.cropper) { | ||
| this.cropper.destroy(); | ||
| } | ||
| return this.args.image; | ||
| } | ||
|
|
||
| @action loadCropper() { | ||
| const image = document.getElementById('image-cropper'); | ||
| this.cropper = new Cropper(image, { | ||
| autoCrop: true, | ||
| viewMode: 1, | ||
| dragMode: 'crop', | ||
| aspectRatio: 1, | ||
| cropBoxResizable: true, | ||
| movable: false, | ||
| zoomOnWheel: false, | ||
| rotatable: false, | ||
| toggleDragModeOnDblclick: false, | ||
| ready: () => { | ||
| this.setImageData(); | ||
| }, | ||
| cropend: () => { | ||
| this.setImageData(); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| setImageData() { | ||
| const { x, y, width, height } = this.cropper.getData(true); | ||
| this.args.setImageCoordinates({ x, y, width, height }); | ||
| } | ||
| } |
This file contains hidden or 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,23 @@ | ||
| <section data-test-profile-field class={{if @showError 'profile-field profile-field-error' 'profile-field'}}> | ||
| <label data-test-profile-field-label class='profile-field-label' for={{@id}}>{{@label}}</label> | ||
| <div class="profile-field-input-container"> | ||
| <img data-test-profile-field-icon src={{@icon_url}} alt=""> | ||
| <Input | ||
| data-test-profile-field-input | ||
| @type="text" | ||
| id={{@id}} | ||
| @value={{@value}} | ||
| placeholder={{@placeholder}} | ||
| class="profile-field-input" | ||
| required={{@required}} | ||
| disabled={{@isDeveloper}} | ||
| {{on 'input' this.inputFieldChanged}} | ||
| {{on 'blur' this.checkInputValidation}} | ||
| /> | ||
| </div> | ||
| {{#if @showError}} | ||
| <p data-test-profile-field-error class="profile-field-error-message"> | ||
| {{@errorMessage}} | ||
| </p> | ||
| {{/if}} | ||
| </section> |
This file contains hidden or 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,20 @@ | ||
| import Component from '@glimmer/component'; | ||
| import { action } from '@ember/object'; | ||
|
|
||
| export default class ProfileFieldComponent extends Component { | ||
| @action | ||
| inputFieldChanged(event) { | ||
| const { id, onChange } = this.args; | ||
| const value = event.target.value; | ||
|
|
||
| onChange(id, value); | ||
| } | ||
|
|
||
| @action | ||
| checkInputValidation(event) { | ||
| const { id, onBlur } = this.args; | ||
| let isValid = event.target.validity.valid; | ||
|
|
||
| onBlur(id, isValid); | ||
| } | ||
| } |
This file contains hidden or 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,78 @@ | ||
| {{#if this.isImageSelected}} | ||
| <h1 class="image-h1"> | ||
| Crop Selected Image | ||
| </h1> | ||
|
|
||
| <Profile::ImageCropper | ||
| @image={{this.image}} | ||
| @setImageCoordinates={{this.setImageCoordinates}} | ||
| /> | ||
| <div> | ||
| <button | ||
| class='image-form__button btn' | ||
| type='button' | ||
| disabled={{this.isImageUploading}} | ||
| data-test-btn='back' | ||
| {{on 'click' this.goBack}} | ||
| > | ||
| Back | ||
| </button> | ||
| <button | ||
| class='image-form__button btn' | ||
| type='button' | ||
| data-test-btn='upload-image' | ||
| disabled={{this.isImageUploading}} | ||
| {{on 'click' this.onSubmit}} | ||
| > | ||
| {{#if this.isImageUploading}} | ||
| <Spinner /> | ||
| {{else}} | ||
| Upload | ||
| {{/if}} | ||
| </button> | ||
| </div> | ||
| <p | ||
| class='{{if | ||
| this.imageUploadSuccess | ||
| "message-text__success" | ||
| "message-text__failure" | ||
| }}' | ||
| > | ||
| {{this.statusMessage}} | ||
| </p> | ||
|
|
||
| {{else}} | ||
| <h1 class="image-h1"> | ||
| Upload Image | ||
| </h1> | ||
| <p class="image-p">( Max size 2MB )</p> | ||
| <div | ||
| data-test-drop-area | ||
| class='drop-area {{if this.overDropZone "drop-area__highlight"}}' | ||
| {{on 'drop' this.handleDrop}} | ||
| {{on 'dragover' this.handleDragOver}} | ||
| {{on 'dragenter' this.handleDragEnter}} | ||
| {{on 'dragleave' this.handleDragLeave}} | ||
| > | ||
| <form class='image-form'> | ||
| <p class='image-form__text'> | ||
| Drag and drop file here or | ||
| </p> | ||
| <label | ||
| class='image-form__button btn | ||
| {{if this.isImageUploading "image-form__button--disabled"}}' | ||
| for='image' | ||
| data-test-btn='browse' | ||
| > | ||
| Browse | ||
| </label> | ||
| <input | ||
| class='image-form__input' | ||
| type='file' | ||
| id='image' | ||
| accept='image/png, image/jpeg' | ||
Suvidh-kaushik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {{on 'change' this.handleBrowseImage}} | ||
| /> | ||
| </form> | ||
| </div> | ||
| {{/if}} | ||
This file contains hidden or 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,145 @@ | ||
| import Component from '@glimmer/component'; | ||
| import { action } from '@ember/object'; | ||
| import { tracked } from '@glimmer/tracking'; | ||
| import { TOAST_OPTIONS } from '../../constants/toast-options'; | ||
| import { inject as service } from '@ember/service'; | ||
|
|
||
| export default class UploadImageComponent extends Component { | ||
| formData; | ||
| @service toast; | ||
| @service router; | ||
| @tracked image; | ||
| @tracked isImageSelected = false; | ||
| @tracked overDropZone = false; | ||
| @tracked isImageUploading = false; | ||
| @tracked imageUploadSuccess = false; | ||
| @tracked statusMessage; | ||
| @tracked imageFileName; | ||
| imageCoordinates = null; | ||
| uploadUrl = this.args.uploadUrl; | ||
| formKeyName = this.args.formKeyName; | ||
|
|
||
| @action goBack() { | ||
| this.image = null; | ||
| this.setImageSelected(false); | ||
| } | ||
| @action updateImage(file) { | ||
| this.setStatusMessage(''); | ||
| const reader = new FileReader(); | ||
|
|
||
| if (file) { | ||
| this.updateFormData(file, this.formKeyName); | ||
| reader.readAsDataURL(file); | ||
| this.imageFileName = file.name; | ||
| } | ||
| reader.onload = () => { | ||
| const image = reader.result; | ||
| this.image = image; | ||
| }; | ||
| } | ||
|
|
||
| @action setImageCoordinates(data) { | ||
| this.imageCoordinates = data; | ||
| } | ||
|
|
||
| @action handleBrowseImage(e) { | ||
| const [file] = e.target.files; | ||
| this.updateImage(file); | ||
| this.setImageSelected(true); | ||
| } | ||
|
|
||
| @action handleDrop(e) { | ||
| this.preventDefaults(e); // This is used to prevent opening of image in new tab while drag and drop | ||
| const [file] = e.dataTransfer.files; | ||
| this.updateImage(file); | ||
| this.setImageSelected(true); | ||
| this.setOverDropZone(false); | ||
| } | ||
| @action handleDragOver(e) { | ||
| this.preventDefaults(e); | ||
| this.setOverDropZone(true); | ||
| e.dataTransfer.dropEffect = 'move'; | ||
| } | ||
| @action handleDragEnter(e) { | ||
| this.preventDefaults(e); | ||
| this.setOverDropZone(true); | ||
| } | ||
| @action handleDragLeave(e) { | ||
| this.preventDefaults(e); | ||
| this.setOverDropZone(false); | ||
| } | ||
|
|
||
| @action onSubmit(e) { | ||
| this.preventDefaults(e); | ||
| this.formData.set('coordinates', JSON.stringify(this.imageCoordinates)); | ||
| this.uploadImage(this.formData); | ||
| } | ||
|
|
||
| uploadImage(data) { | ||
| const url = this.uploadUrl; | ||
| this.setImageUploading(true); | ||
| fetch(`${url}`, { | ||
| method: 'POST', | ||
| credentials: 'include', | ||
| body: data, | ||
| }) | ||
| .then(async (res) => { | ||
| const status = res.status; | ||
| const data = await res.json(); | ||
| const message = data.message; | ||
| this.handleResponseStatusMessage(status, message); | ||
| }) | ||
| .catch((err) => { | ||
| this.setImageUploadSuccess(false); | ||
| this.setStatusMessage( | ||
| 'Error occured, please try again and if the issue still exists contact administrator and create a issue on the repo with logs', | ||
| ); | ||
| console.error(err); | ||
| }) | ||
| .finally(() => { | ||
| this.setImageUploading(false); | ||
| }); | ||
| } | ||
|
|
||
| updateFormData(file, key) { | ||
| const formData = new FormData(); | ||
| formData.append(key, file); | ||
| this.formData = formData; | ||
| } | ||
|
|
||
| handleResponseStatusMessage(status, message) { | ||
| if (status === 200) { | ||
| this.setImageUploadSuccess(true); | ||
| this.args.outsideClickModel(); | ||
| this.toast.success(message, '', TOAST_OPTIONS); | ||
| } else { | ||
| this.setImageUploadSuccess(false); | ||
| this.setStatusMessage(message); | ||
| } | ||
| } | ||
|
|
||
| preventDefaults(e) { | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| } | ||
|
|
||
| setOverDropZone(bool) { | ||
| this.overDropZone = bool; | ||
| } | ||
|
|
||
| setImageSelected(bool) { | ||
| this.isImageSelected = bool; | ||
| } | ||
|
|
||
| setImageUploading(bool) { | ||
| this.isImageUploading = bool; | ||
| } | ||
|
|
||
| setImageUploadSuccess(bool) { | ||
| this.imageUploadSuccess = bool; | ||
| } | ||
|
|
||
| setStatusMessage(message) { | ||
| this.statusMessage = message; | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| <i class="fa fa-spinner fa-spin"></i> |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.