-
Notifications
You must be signed in to change notification settings - Fork 2
Add file upload option for bulk import #59
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -318,21 +318,37 @@ <h1 class="title"> | |
<button id="BulkImportModal__close" class="delete" aria-label="close"></button> | ||
</header> | ||
<section class="modal-card-body"> | ||
<div class="field"> | ||
<label class="label">Import Type</label> | ||
<div class="control"> | ||
<div class="select"> | ||
<select id="BulkImportModal__typesSelect"> | ||
<option id="BulkImportModal__typesSelect--ImportAsNew" value="ImportAsNew"> | ||
Import as new lists | ||
</option> | ||
<option id="BulkImportModal__typesSelect--ImportAndMerge" value="ImportAndMerge"> | ||
Import and merge lists | ||
</option> | ||
<option id="BulkImportModal__typesSelect--Replace" value="Replace"> | ||
Replace existing lists | ||
</option> | ||
</select> | ||
<div class="BulkImport__optionsBody"> | ||
<div class="field"> | ||
<label class="label">Import Type</label> | ||
<div class="control"> | ||
<div class="select"> | ||
<select id="BulkImportModal__typesSelect"> | ||
<option id="BulkImportModal__typesSelect--ImportAsNew" value="ImportAsNew"> | ||
Import as new lists | ||
</option> | ||
<option id="BulkImportModal__typesSelect--ImportAndMerge" value="ImportAndMerge"> | ||
Import and merge lists | ||
</option> | ||
<option id="BulkImportModal__typesSelect--Replace" value="Replace"> | ||
Replace existing lists | ||
</option> | ||
</select> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="field"> | ||
<label class="label">Import from File</label> | ||
<div id="BulkImport__file" class="file is-normal"> | ||
<label class="file-label"> | ||
<input class="file-input" type="file" accept=".json, .txt" name="resume"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. name probably doesn't do anything here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can add an ID here |
||
<span class="file-cta"> | ||
<span class="file-label"> | ||
Choose a file… | ||
</span> | ||
</span> | ||
<span class="file-name" style="display: none"></span> | ||
</label> | ||
</div> | ||
</div> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -545,6 +545,30 @@ $(function () { | |
$('#BulkImportPreviewModal__optionName').text(importName); | ||
}); | ||
|
||
$('.file-input').on('change', (e) => { | ||
const file = e.target.files[0]; | ||
if (!file) return; | ||
|
||
const allowedExtensions = ['txt', 'json']; | ||
const fileName = file.name; | ||
const fileExtension = fileName.split('.').pop().toLowerCase(); | ||
|
||
if (!allowedExtensions.includes(fileExtension)) { | ||
alert('Please upload a file with .txt or .json extension.'); | ||
return; | ||
} | ||
|
||
const reader = new FileReader(); | ||
reader.onload = function (e) { | ||
const contents = e.target.result; | ||
$('#BulkImport__file').removeClass('is-normal'); | ||
$('#BulkImport__file').addClass('has-name'); | ||
$('.file-name').text(fileName).show(); | ||
$('#BulkImportModal__body').val(contents); | ||
}; | ||
reader.readAsText(file); | ||
}); | ||
|
||
$('#BulkImportModal__previewImport').on('click', (e) => { | ||
const importType = $('#BulkImportModal__typesSelect').val(); | ||
const importBody = $('#BulkImportModal__body').val(); | ||
|
@@ -717,6 +741,10 @@ $(function () { | |
$('#BulkExportModal').removeClass('is-active'); | ||
}); | ||
$('#BulkImportModal__cancel, #BulkImportModal__close').on('click', (e) => { | ||
$('.file-input').val(''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use convention |
||
$('.file-name').text('').hide(); | ||
$('#BulkImport__file').removeClass('has-name'); | ||
$('#BulkImport__file').addClass('is-normal'); | ||
$('#BulkImportModal').removeClass('is-active'); | ||
}); | ||
$('#BulkImportPreviewModal__cancel, #BulkImportPreviewModal__close').on('click', (e) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep the naming convention of
BulkImportModal__fileName