Skip to content

Commit

Permalink
Add missing assets
Browse files Browse the repository at this point in the history
  • Loading branch information
little9 committed Aug 1, 2019
1 parent 80d0c25 commit 3bc5f8b
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 9 deletions.
43 changes: 43 additions & 0 deletions app/assets/javascripts/zizia/DisplayUploadedFile.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export default class DisplayUploadedFile {
constructor() {
this.regexp = /[^a-zA-Z0-9\.\-\+_]/g
}
replaceWhitespace(input) {
return input.replace(this.regexp, '_')
}

requiresEscape(input) {
return this.regexp.test(input)
}

displayReplaceMessage(input) {
if (this.requiresEscape(input)) {
return `<b> Note: </b> Your file name contained spaces, which have been replaced by underscores.
This will have no effect on your import.`
} else {
return ''
}
}

display() {
var fileInput = document.querySelector('#file-upload')
var files = fileInput.files
for (var i = 0; i < files.length; i++) {
var file = files[i]
document.querySelector('#file-upload-display').innerHTML = `
<div class="row">
<div class="col-md-12">
<div class="well style="
background-color: #dff0d8;
border-color: #d6e9c6;
color: #3c763d;">
<p>You sucessfully uploaded this CSV: <b> ${this.replaceWhitespace(file.name)} </b>
</p>
${this.displayReplaceMessage(file.name)}
<p>
</div>
</div>
</div>`
}
}
}
6 changes: 6 additions & 0 deletions app/assets/javascripts/zizia/zizia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var Zizia = {
displayUploadedFile: function() {
var DisplayUploadedFile = require('./DisplayUploadedFile')
new DisplayUploadedFile().display()
}
}
17 changes: 17 additions & 0 deletions app/assets/stylesheets/zizia/_file_upload.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.file-upload {
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}

.file-upload + label {
margin-bottom: 1em;
}

.file-upload:focus + label {
outline: 1px dotted #000;
outline: -webkit-focus-ring-color auto 5px;
}
2 changes: 1 addition & 1 deletion app/assets/stylesheets/zizia/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require zizia
*= require_self
*/
1 change: 1 addition & 0 deletions app/assets/stylesheets/zizia/zizia.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@require 'file-upload';
7 changes: 0 additions & 7 deletions app/mailers/zizia/application_mailer.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/zizia/csv_imports/_file_upload.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<%= form.file_field :manifest, required: true, id: 'file-upload', class: "file-upload form-control", onchange: "Tenejo.displayUploadedFile()" %>
<%= form.file_field :manifest, required: true, id: 'file-upload', class: "file-upload form-control", onchange: "Zizia.displayUploadedFile()" %>
<label for="file-upload" class="btn btn-lg btn-primary"><span class="glyphicon glyphicon-upload"></span> Upload Your CSV</label>
<div id="file-upload-display"></div>

0 comments on commit 3bc5f8b

Please sign in to comment.