-
Notifications
You must be signed in to change notification settings - Fork 160
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
Capture code refactor for new interface #672
Conversation
13caa10
to
4abe613
Compare
a87589d
to
74370b3
Compare
279e9c3
to
a52a5a4
Compare
ed240c7
to
0bb9130
Compare
For reference, here's the new interface in action: new.mov |
def webrtc? | ||
request.env['HTTP_USER_AGENT'] && (request.env['HTTP_USER_AGENT'].match('Opera') || request.env['HTTP_USER_AGENT'].match('Firefox') || request.env['HTTP_USER_AGENT'].match('Chrome')) | ||
request.env['HTTP_USER_AGENT'] && (request.env['HTTP_USER_AGENT'].match('Opera') || request.env['HTTP_USER_AGENT'].match('Safari') || request.env['HTTP_USER_AGENT'].match('Firefox') || request.env['HTTP_USER_AGENT'].match('Chrome')) |
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.
nice!
@@ -17,7 +17,7 @@ | |||
|
|||
<form class="form" action="/spectrums" method="post" id="saveForm" target="_blank" onSubmit="$W.cancelSave();window.location='#page1'"> | |||
|
|||
<input placeholder="Title (required)" name="spectrum[title]" id="spectrum_notes" type="text" /><br /> | |||
<input placeholder="Title (required)" name="spectrum[title]" type="text" /><br /> |
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.
Oops, are you sure here? This is the legacy capture interface, would this break it?
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.
A warning was popping up in the console that there were 2 id's associated with the same name - spectrum_notes
:
<input placeholder="Title (required)" name="spectrum[title]" id="spectrum_notes" type="text" /><br /> |
<textarea placeholder="Describe your spectrum: light source? Sample preparation? What's your goal?" style="span8" rows="6" name="spectrum[notes]" id="spectrum_notes"></textarea> |
I don't see the id being used anywhere, so maybe it is ok to proceed 🤞
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.
hm, ok! As long as you can confirm it's not broken, sounds good! And indeed, a quick search shows it's not used in code anywhere -- https://github.com/publiclab/spectral-workbench/search?q=spectrum_notes
looks like it was simply duplicated! Good catch!
# Compress JavaScripts and CSS. | ||
config.assets.js_compressor = :uglifier | ||
# Compress JavaScripts and CSS (Using ES6 syntax). | ||
config.assets.js_compressor = Uglifier.new(harmony: true) |
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.
Aha - ok so here we are missing something as it created this error:
Run bundle exec rake assets:precompile
rake aborted!
NameError: uninitialized constant Uglifier
/home/runner/work/spectral-workbench/spectral-workbench/config/environments/production.rb:38:in `block in <top (required)>'
https://github.com/publiclab/spectral-workbench/pull/672/checks?check_run_id=3109251932#step:5:7
Do you need to include Uglifier
or something?
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.
This is actually supposed to make the uglifier compatible with the ES6 syntax used in new-capture.js
according to lautis/uglifier#127 but still the problem remains unsolved...😕
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.
So this is a new error uninitialised constant Uglifier
which should be resolved by https://stackoverflow.com/questions/30338860/heroku-push-error-nameerror-uninitialized-constant-uglifierversion-on-rake but still the problem is persisting when I tried this out.
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.
Hm, they note:
The problem seemed to be an incompatibility between Sprockets 3.1 and the Uglifier compressor version I was using, 2.1. Upgrading Uglifier by putting this line in my Gemfile resolved the issue:
gem 'uglifier', '~> 2.7'
Have you tried that? Else possibly @noi5e may be able to help a bit (or at least have some ideas?) as he's worked a lot with Rails precompilation in his React project!
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.
OK here is another possibility:
Installing the gem "therubyracer" and rolling uglifier back to 2.6.1 in the Gemfile ( gem 'uglifier', '~> 2.6.1' ) fixes the problem.
...i think we removed therubyracer? Yes -
Lines 16 to 18 in 8f89e0f
# gem 'therubyracer', :platforms => :ruby | |
gem 'uglifier', '>= 1.0.3' |
Try turning it back on and then pegging the uglifier gem to v2.6.1?
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.
@@ -8,6 +8,7 @@ | |||
"dependencies": { | |||
"ace-builds": "jywarren/ace-builds#v1.2.4", | |||
"bootstrap-css": "jozefizso/bower-bootstrap-css#~2.3.2", | |||
"bs-stepper": "^1.7.0", |
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.
Nice!
Very cool @waridrox ! Looking awesome. I left some notes in the comments and once we get past this asset precompilation issue this looks good to merge! |
@@ -0,0 +1,724 @@ | |||
//= require graph.js |
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.
Oh wait, hmm, so, is what's going on here that you've made a copy of the older version of capture.js
(from https://github.com/publiclab/spectral-workbench.js/blob/main/examples/capture/capture.js) with some modifications in order to make it safari compatible?
But I'm not sure I'm understanding what the changes were -- here's a diff: https://gist.github.com/jywarren/534b0d8dfb4e58f7833ac92bdee8cd20/revisions
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.
I'm just not sure what those new sections auto_detect_sample_row
etc are replacing - what older code are they overriding? I'd like to avoid duplicating the majority of this file if possible. What, as narrowly as possible, are the required changes we want to make here?
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.
And if there is no other simpler way, what is our plan moving forward to stop using this redundant file and unify the codebase again?
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.
So the new capture code in the sw.js lib at https://github.com/publiclab/spectral-workbench.js/blob/main/examples/capture/capture.js is making use of https://github.com/publiclab/spectral-workbench.js/blob/main/examples/capture/capture.js as well as https://github.com/publiclab/spectral-workbench.js/blob/main/dist/capture.dist.js. I've refactored the code to fit under one file at new-capture.js
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.
Ah, hmm. I think perhaps this should be done upstream in that library, as well as perhaps in a separate PR. Is it possible to leave this file out and include exactly as it was in the demo?
<script src="../capture/capture.js" type="text/javascript"></script>
<script src="../../dist/capture.dist.js" type="text/javascript"></script>
I just think this is a major change and a duplication of code with the upstream library. Keep this file though! the refactor is not a bad idea it's just something we should do in the pure JS library, as well as in a distinct PR.
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.
Sure! but
<script src="../capture/capture.js" type="text/javascript"></script>
is also calling different functions like getRow
, getUsermedia
, detect_sample_row
which are in different files at https://github.com/publiclab/spectral-workbench.js/tree/main/examples/capture
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.
OK, but are those functions represented in other files also included from the new-capture/index.html?
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.
Other than capture.dist.js
and capture.js
all other files are included as assets so I think there should be no problems there...
app/views/capture/index2.html.erb
Outdated
<span class="bs-stepper-label">Capture</span> | ||
<script> | ||
function capturePage() { |
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.
Oof these are rough, huh? So basically the stepper plugin wasn't compatible with the canvas/getusermedia webcam stuff, when run in safari? Is this really the only way forward? It's so much extra code and work!
Could we at least move these all into one file so as not to mix them with the HTML?
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.
The stepper is just stopping the graph so I am rendering all the content first and then hiding it with the scripts instead of using the default stepper behaviour. Sure we could move this to a separate file for a cleaner code.
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.
We can also mark them as a temporary step. If we resolve the Safari issue, how much work would it be to revert back, and can we consolidate the code as well as clearly mark it with comments that it's addressing #665 and that upon solving that it could be removed and simplified?
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.
Sure, the only thing that would be required in that case would be to simply remove the temporary script and add the pre-defined script section on the page which would use the buttons to toggle the divs that would then be rendered as different pages.
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.
It may even be helpful to make this particular set of changes all in a single commit. Then we can point at that commit which will include the complete diff of just this steps-fix, and nothing else.
<div> | ||
<p><small>Using calibration:</small></p> | ||
<select name="spectrum[calibration_id]" class="select-calibration select-calibration-capture span2"> | ||
<%= render partial: 'capture/calibrations', locals: { calibrations: @calibrations, calibration: @calibration } %> |
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.
Wow very cool! Can you screenshot this as well, for documentation?
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.
It's still not functioning as intended (separated out) as of now since I tested it using the old capture controller. Will need to refactor this to the new capture controller.
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.
It should be OK to use the same controller actions and routes between the two interfaces -- the functionality is the same, right?
Also just want to say, great work here, and keep it up! There's a lot going on and more to tweak before we're ready, but I appreciate the hard work! |
Oof, ok i'm sorry this is such a blocker. I'll try to work on it today or tomorrow. If @noi5e is able to see any way around this too, that's great as well! |
I should be honest and say that I don't have the expertise in this that might be desired. 😬 BUT, I am willing to get my hands dirty, maybe it will help to have an extra set of eyes on this. I'm going to start by forking the repo and setting up locally. The comments are a lot to sift through here! Something that would help me: can you please give me a step-by-step to reproduce the error? |
Sure @noi5e thanks a lot 🙌 !! The error is produced once the app gets ready for production and the assets pre-compile. We are using the ES6 arrow syntax in the sw.js lib at but the Uglifier is throwing an error lautis/uglifier#127 was supposed to fix the ES6 issue but this created another one - and so far we have tried -
but still no help 😕 |
Hmm, @waridrox I was actually able to run rake assets:precompile without an error here in Gitpod: https://gist.github.com/jywarren/79073c832009089c58a885cfc5891f84 I wonder why this is different from the tests. Can you reproduce the error in Gitpod? I had to install bundler, yarn install, etc. first. |
Oh @jywarren so could this be due to the bundler gem. I see the production environment set to false in the gitpod config file: spectral-workbench/.gitpod.yml Lines 6 to 15 in 7e1fb80
Also the commands like |
Ahhhhh ok yes I need to set RAILS_ENV=production, thank you
…On Wed, Jul 28, 2021, 9:51 AM Mohammad Warid ***@***.***> wrote:
Oh @jywarren <https://github.com/jywarren> so could this be due to the
bundler gem. I see the production environment set to false in the gitpod
config file:
https://github.com/publiclab/spectral-workbench/blob/7e1fb804500723e6dfd8dff557070acdea2e8897/.gitpod.yml#L6-L15
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#672 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAF6JYIHY6K26CGHNMFQDLT2ADOXANCNFSM47XMNCGQ>
.
|
OK! I think i may have resolved it by using and by upgrading to the latest (v4) uglifier. Let's see. It'll need a rebase after but we can just see how it does here. |
ec07d02
to
46ffb17
Compare
Yay ✨ the test for asset pre-compilation passed!! |
…ort and rear camera on mobile devices on old capture
513b825
to
089e252
Compare
@@ -0,0 +1,610 @@ | |||
* { |
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 de-duplicate this with https://github.com/publiclab/spectral-workbench.js/blob/main/examples/new-capture/new-capture.css - and name it differently so it's clear that it isn't redundant - so this file in this PR should have only those things that are specific to the Rails app here, and everything else should go upstream in the JS library, and then https://github.com/publiclab/spectral-workbench.js/blob/main/examples/new-capture/new-capture.css would be referenced in addition to the local version here from index2.html. Make sense?
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.
@waridrox i liked what you said about including both stylesheets in succession. Let's do that!
|
@@ -0,0 +1,463 @@ | |||
@import 'spectral-workbench/examples/new-capture/new-capture.css'; |
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.
nice!
OK! I think this is good to merge! Just in case, in the future can you comment that you think it's ready? But since we've reviewed this a lot i think we're OK. Merging! Great job!! |
Great job here @waridrox! |
Part of #645
Hi @jywarren, until further progress at the safari issue blocker, can we use this as an alternative.
I've implemented the following with this PR:
I know it has a lot of changes but the problem is that the new-capture code requires the new interface which in turn requires the styles to function properly. So all of them are linked to each other...😅
I was thinking of implementing cross browser support on the old interface as well, but I think it will require some refactor of the old capture.js as well. So until the tests are implemented, I am putting that on hold...The asset pre-compilation test seems to be failing due to the use of ES6 arrow syntax under WebRTC.
spectral-workbench/app/assets/javascripts/new-capture.js
Lines 40 to 60 in 56e417e
I've tried to fix it but still it's failing...it's related to Uglifier not being able to recognise the ES6 syntax.