From 3bc5f8b7e7dcda76bafce9b1d8d5370eea318fd7 Mon Sep 17 00:00:00 2001 From: Jamie Little Date: Thu, 1 Aug 2019 07:51:01 -0500 Subject: [PATCH] Add missing assets --- .../javascripts/zizia/DisplayUploadedFile.es6 | 43 +++++++++++++++++++ app/assets/javascripts/zizia/zizia.js | 6 +++ .../stylesheets/zizia/_file_upload.scss | 17 ++++++++ app/assets/stylesheets/zizia/application.css | 2 +- app/assets/stylesheets/zizia/zizia.scss | 1 + app/mailers/zizia/application_mailer.rb | 7 --- .../zizia/csv_imports/_file_upload.html.erb | 2 +- 7 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 app/assets/javascripts/zizia/DisplayUploadedFile.es6 create mode 100644 app/assets/javascripts/zizia/zizia.js create mode 100644 app/assets/stylesheets/zizia/_file_upload.scss create mode 100644 app/assets/stylesheets/zizia/zizia.scss delete mode 100644 app/mailers/zizia/application_mailer.rb diff --git a/app/assets/javascripts/zizia/DisplayUploadedFile.es6 b/app/assets/javascripts/zizia/DisplayUploadedFile.es6 new file mode 100644 index 0000000..67b7860 --- /dev/null +++ b/app/assets/javascripts/zizia/DisplayUploadedFile.es6 @@ -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 ` Note: 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 = ` +
+
+
+

You sucessfully uploaded this CSV: ${this.replaceWhitespace(file.name)} +

+ ${this.displayReplaceMessage(file.name)} +

+

+
+
` + } + } +} diff --git a/app/assets/javascripts/zizia/zizia.js b/app/assets/javascripts/zizia/zizia.js new file mode 100644 index 0000000..2ac97a5 --- /dev/null +++ b/app/assets/javascripts/zizia/zizia.js @@ -0,0 +1,6 @@ +var Zizia = { + displayUploadedFile: function() { + var DisplayUploadedFile = require('./DisplayUploadedFile') + new DisplayUploadedFile().display() + } +} diff --git a/app/assets/stylesheets/zizia/_file_upload.scss b/app/assets/stylesheets/zizia/_file_upload.scss new file mode 100644 index 0000000..9c565ab --- /dev/null +++ b/app/assets/stylesheets/zizia/_file_upload.scss @@ -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; +} diff --git a/app/assets/stylesheets/zizia/application.css b/app/assets/stylesheets/zizia/application.css index 0ebd7fe..05de8c5 100644 --- a/app/assets/stylesheets/zizia/application.css +++ b/app/assets/stylesheets/zizia/application.css @@ -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 */ diff --git a/app/assets/stylesheets/zizia/zizia.scss b/app/assets/stylesheets/zizia/zizia.scss new file mode 100644 index 0000000..89ebb1e --- /dev/null +++ b/app/assets/stylesheets/zizia/zizia.scss @@ -0,0 +1 @@ +@require 'file-upload'; diff --git a/app/mailers/zizia/application_mailer.rb b/app/mailers/zizia/application_mailer.rb deleted file mode 100644 index c0300b1..0000000 --- a/app/mailers/zizia/application_mailer.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true -module Zizia - class ApplicationMailer < ActionMailer::Base - default from: 'from@example.com' - layout 'mailer' - end -end diff --git a/app/views/zizia/csv_imports/_file_upload.html.erb b/app/views/zizia/csv_imports/_file_upload.html.erb index 76e3df6..dee77b3 100644 --- a/app/views/zizia/csv_imports/_file_upload.html.erb +++ b/app/views/zizia/csv_imports/_file_upload.html.erb @@ -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()" %>