Skip to content

Commit

Permalink
Cause refresh on select changed
Browse files Browse the repository at this point in the history
  • Loading branch information
rw251 committed Apr 14, 2021
1 parent b67774a commit ce66159
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/client/controllers/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { syncToLocal } from '../scripts/global';

const itSupportsDragging = () => {
const div = document.createElement('div');
return ('draggable' in div) || ('ondragstart' in div && 'ondrop' in div);
return 'draggable' in div || ('ondragstart' in div && 'ondrop' in div);
};

const itSupportsFileReader = () => 'FileReader' in window;

const itSupportsFormData = () => 'FormData' in window;

const itSupportsDragDropUpload = () => itSupportsDragging() && itSupportsFileReader()
&& itSupportsFormData();
const itSupportsDragDropUpload = () =>
itSupportsDragging() && itSupportsFileReader() && itSupportsFormData();
const currentCodeSet = {};
const $synonym = { include: {}, exclude: {} };
const $terminologyRadio = {};
Expand Down Expand Up @@ -145,26 +145,33 @@ const wireup = () => {
const files = droppedFiles;
const reader = new FileReader();
reader.onload = function readerOnLoad() {
$form.removeClass('is-uploading');// .removeClass('is-error');
$form.removeClass('is-uploading'); // .removeClass('is-error');
const newZip = new JSZip();
// more files !
newZip
.loadAsync(reader.result)
.then((zip) => {
// you now have every files contained in the loaded zip
if (!zip) displayError(null, 'No zip file found.');
else if (!zip.files || Object.keys(zip.files).length !== 2) displayError(null, 'Zip file should contain two files.');
else if (Object.keys(zip.files).filter(v => v.toLowerCase().indexOf('metadata') > -1).length !== 1) {
else if (!zip.files || Object.keys(zip.files).length !== 2)
displayError(null, 'Zip file should contain two files.');
else if (
Object.keys(zip.files).filter((v) => v.toLowerCase().indexOf('metadata') > -1)
.length !== 1
) {
displayError(null, "Need precisely one file with 'metadata' in it's name.");
} else {
const metadataFilename = Object.keys(zip.files).filter(v => v.toLowerCase().indexOf('metadata') > -1)[0];
const codesetFilename = Object.keys(zip.files).filter(v => v.toLowerCase().indexOf('metadata') === -1)[0];
const metadataFilename = Object.keys(zip.files).filter(
(v) => v.toLowerCase().indexOf('metadata') > -1
)[0];
const codesetFilename = Object.keys(zip.files).filter(
(v) => v.toLowerCase().indexOf('metadata') === -1
)[0];

const metaDataPromise = zip.file(metadataFilename).async('string');
const codeSetPromise = zip.file(codesetFilename).async('string');

Promise
.all([metaDataPromise, codeSetPromise])
Promise.all([metaDataPromise, codeSetPromise])
.then((fileContents) => {
readMetaDataFile(fileContents[0]);
readCodeSetFile(fileContents[1]);
Expand All @@ -184,7 +191,6 @@ const wireup = () => {
return reader.readAsArrayBuffer(files[0]);
});


// restart the form if has a state of error/success

$restart.on('click', (evt) => {
Expand All @@ -204,8 +210,12 @@ const wireup = () => {

// Firefox focus bug fix for file input
$input
.on('focus', () => { $input.addClass('has-focus'); })
.on('blur', () => { $input.removeClass('has-focus'); });
.on('focus', () => {
$input.addClass('has-focus');
})
.on('blur', () => {
$input.removeClass('has-focus');
});
});
};

Expand All @@ -215,4 +225,3 @@ const show = () => {
};
// params, state, url
export { show as default };

5 changes: 5 additions & 0 deletions src/client/controllers/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,11 @@ const wireup = () => {
evt.preventDefault();
});

document.querySelector('select[name=terminology]').addEventListener('change', () => {
console.log('Terminology changed. Refreshing...');
refresh();
});

$synonym.include.add.on('click', () => {
addIfLongEnough($synonym.include.input);
});
Expand Down

0 comments on commit ce66159

Please sign in to comment.