Skip to content
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

Add missing assets #8

Merged
merged 1 commit into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>