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

Stops loading of blend-module when offset unavailable #654

Merged
merged 11 commits into from
Jan 16, 2019
Merged

Stops loading of blend-module when offset unavailable #654

merged 11 commits into from
Jan 16, 2019

Conversation

Divy123
Copy link
Member

@Divy123 Divy123 commented Jan 11, 2019

Fixes #649

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts
  • PR is descriptively titled
  • ask @publiclab/reviewers for help, in a comment below

We're happy to help you get this ready -- don't be afraid to ask for help, and don't be discouraged if your tests fail at first!

If tests do fail, click on the red X to learn why by reading the logs.

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software

Thanks!

@Divy123
Copy link
Member Author

Divy123 commented Jan 11, 2019

ezgif com-video-to-gif

@Divy123
Copy link
Member Author

Divy123 commented Jan 11, 2019

@jywarren please review.

@harshkhandeparkar
Copy link
Member

@Divy123 I think you should not interact with the DOM directly form the library. Instead maybe you can send the error to the ui somehow and let the ui handle it?

@harshkhandeparkar
Copy link
Member

Or you can get the number of steps in the ui and let or not let the user add beln module.

@Divy123
Copy link
Member Author

Divy123 commented Jan 11, 2019

Well we have already provided an option as offset for user to handle.
Also if you have seen I have produced same output as input without making any other changes and produced one notification for user to know.
Rest user can always change an offset by the input option provided.
So I think providing an extra functionality for something already created is not worth.

@harshkhandeparkar
Copy link
Member

But if the library is used without ui or in cli thn it is going to produce an error

@harshkhandeparkar
Copy link
Member

Also if you want to add the notification then you can remove the #stepRemovedNotify css and add a class called notification-toast maybe.

@Divy123
Copy link
Member Author

Divy123 commented Jan 11, 2019

Since the callback is invoked immediately if offset step is not available, I don't think there should be any problem I don't think there should be an error.
Yeah css can be implemented like that.

@harshkhandeparkar
Copy link
Member

What if that notification is activated somehow and without cli the file doesnt find the notification and then goes crazy?

@harshkhandeparkar
Copy link
Member

Oh ok the notification is only activated if in browser is true. My mistake sorry. If that is so then you can maybe add the notification function to a different file?

@harshkhandeparkar
Copy link
Member

Maybe a util function which fires a custom event in the ui? The ui can listen for it and produce the appropriate notification?

@harshkhandeparkar
Copy link
Member

@Divy123 the css should be a class not id. The notifications can be given specific ids by the function later.

@harshkhandeparkar
Copy link
Member

The ids will have to be generated from the payload itself

@Divy123
Copy link
Member Author

Divy123 commented Jan 11, 2019

Well I don't think there is any need of id(s) as of now . It may be done later if needed.
Lets wait for the core team to review.

@Divy123
Copy link
Member Author

Divy123 commented Jan 11, 2019

@jywarren please review.

@harshkhandeparkar
Copy link
Member

harshkhandeparkar commented Jan 11, 2019 via email

@harshkhandeparkar
Copy link
Member

harshkhandeparkar commented Jan 11, 2019

@Divy123 can you please change the CSS to .notification-styles as the function is going to create more than one element with the same id.

@Divy123
Copy link
Member Author

Divy123 commented Jan 11, 2019

Sure @harshkhandeparkar . Thanks for your suggestions. 😄

@harshkhandeparkar
Copy link
Member

@Divy123 I think

$('.notification-styles').length

will always be > 0 once the first notification has been shown.

@Divy123
Copy link
Member Author

Divy123 commented Jan 11, 2019

Any thing you suggest @harshkhandeparkar ? I think adding class to css was misleading.
I don't think that should have been done.

@harshkhandeparkar
Copy link
Member

Any thing you suggest @harshkhandeparkar ? I think adding class to css was misleading.
I don't think that should have been done.

No, we add class only for styling not for the notification which is why ids exist. For referring to a single element in the whole DOM

@harshkhandeparkar
Copy link
Member

This is why we need to auto-generate ids for each notification as each of them has a different message but same styling.

@Divy123
Copy link
Member Author

Divy123 commented Jan 11, 2019

One more thing I didn't find any problem in the code when class was not added.
Any idea @harshkhandeparkar ?
I found adding class unrequired.

@harshkhandeparkar
Copy link
Member

harshkhandeparkar commented Jan 11, 2019

One more thing I didn't find any problem in the code when class was not added.
Any idea @harshkhandeparkar ?
I found adding class unrequired.

That is because step removed notification and offset notification were not used together. It is going to create ambiguity even is both are given the same class or if both are given the same id. Therefore they have to be given the same class but different ids to refer to them individually without repeating any styles.

@Divy123
Copy link
Member Author

Divy123 commented Jan 11, 2019

@harshkhandeparkar sure I will look into.

@harshkhandeparkar
Copy link
Member

@Divy123 how about dynamically generating IDs based on input like maybe using .toLowerCase() so that no inconsistencies take place and same duplicated only if msg is different.

@harshkhandeparkar
Copy link
Member

Or actually no.
Your solution is better as IDs will not be duplicated anyways

@Divy123
Copy link
Member Author

Divy123 commented Jan 11, 2019

@jywarren the work is done. Please review.

if (priorStep.output === undefined) {
this.output = input;
if(options.inBrowser)
produceNotification("Offset Unavailable","unavailable-offset");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, interesting! could we have a generic notification function that is passed to the UI code like this:

UI.notify('message');

Then the UI would know what to do with it -- the CLI ui would print it out, but the HTML ui would display it. Does that make sense? We'd have to make sure each UI has a .notify() function, and/or we'd have to check that it exists before using it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure @jywarren that will be great to implement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please provide a bit more details?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So basically the UI we use is just one option -- we can pass in a different UI in the options when the sequencer is started up (see examples/index.html). Our default HTML ui is here: lib/defaultHtmlSequencerUi.js

So, we should think of how different UIs will handle notifications. The CLI is written here, and actually doesn't supply a UI, although really it should:

sequencer = ImageSequencer({ ui: false });

Perhaps we should add a new item to the UI spec as described here: https://github.com/publiclab/image-sequencer/#creating-a-user-interface

We could say all UIs can supply an optional notify() or onNotify() handler. Does this make sense?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure . Great changes . Will love to work on this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jywarren I have made the said changes. Please review.

@harshkhandeparkar
Copy link
Member

harshkhandeparkar commented Jan 14, 2019

@Divy124 I have another idea. You could use the same id for each notification toast but just change the text each time for each notification. How well would that work?

@Divy123
Copy link
Member Author

Divy123 commented Jan 14, 2019

That's a good idea but since I have provided different id's to different types of notifications that would do the work as same type of notificattions won't display at same time.

@harshkhandeparkar
Copy link
Member

Yes but if you do that like the way I suggested, it will be future proof.

@harshkhandeparkar
Copy link
Member

harshkhandeparkar commented Jan 14, 2019

Append a notification to the dom and change its innerText to the notification message. Everytime the function is triggered, the same element's text can be changed and then it can be animated.

@harshkhandeparkar
Copy link
Member

No problem after that. No two elements with same id. No crowding of dom and no redundant styles.

@Divy123
Copy link
Member Author

Divy123 commented Jan 14, 2019

The idea is of course nice but as I told you that it is not possible for two notifications to pop up simultaneously so it won't do any bad.
As of future we will make as per your idea but that depends when we need it.
It can be a good issue in itself when needed.
BTW thanks for your help.

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small changes requested, thank you!!!! Great work! 👍 🎉

@@ -24,6 +24,12 @@ module.exports = function Dynamic(options, UI, util) {
// save first image's pixels
var priorStep = this.getStep(options.offset);

if (priorStep.output === undefined) {
this.output = input;
UI.onNotify('Offset Unavailable','offset-notification');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, if we're going to use it like this, maybe best have it just be UI.notify(...), is that OK?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure..

@@ -69,6 +69,9 @@ if (program.saveSequence) {
for (var output in step.info.outputs) {
console.log("[" + program.step + "]: " + output + " = " + step[output]);
}
},
onNotify: function(msg) {
console.log('\x1b[36m%s\x1b[0m','🌟 '+msg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this overwrite the default in /src/ui/...? Just checking!

Copy link
Member Author

@Divy123 Divy123 Jan 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much though providing a beautiful version in console.log
An effort to look it more like a notification.


.savesequencemsg{
display: none;
text-align: center;
}

#stepRemovedNotification {
#offset-notification,#remove-notification {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make a generic reusable .notification class here?

We can still leave the ids for hiding/showing uniquely. But to have a generic style seems nice and then it can be reused for more things later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

@Divy123
Copy link
Member Author

Divy123 commented Jan 14, 2019

@jywarren please review.

@jywarren
Copy link
Member

This looks great. I think it's ready to be merged, and I'd like to ask if you're interested in developing a simple test for the UIs - to confirm that they have a notify() method. In the default, we may be able to check the console.log output? This could be a good place to start on developing UI tests!

Merging!

@jywarren jywarren merged commit 81719a9 into publiclab:main Jan 16, 2019
@jywarren
Copy link
Member

Oh! Also, shall we update the READMEs to mention the notify() method?

@Divy123
Copy link
Member Author

Divy123 commented Jan 17, 2019

Ya sure @jywarren I am working on it.

@Divy123
Copy link
Member Author

Divy123 commented Jan 18, 2019

@jywarren I am almost done.
Just one thing if you can guide me how may I test the CLI interface notify() which is present in index.js file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants