Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ManoliIsFat
Oct 4, 2002

Pollyanna posted:

What experience have you guys had with Knockout.js? Is it like a replacement for Angular or something, or is it totally different from that?

It's way more low level, really it's whole purpose is the model binding. I love it, but it's very bare bones. Before, for a task like this, you'd have jquery all over the place, updating the UI when a value changes. With knockout, you just change a property on your JS object, and the changes ripple throughout your bindings.

I mean, just look at the documentation (http://knockoutjs.com/documentation/introduction.html), that's really about all you can do with it. Bind to HTML properties, bind to click events and some control logic (if, foreach). The live examples really make it click, what you do with it after that is up to you.

Adbot
ADBOT LOVES YOU

ManoliIsFat
Oct 4, 2002

NovemberMike posted:

To clarify, the tech will never be here because what you are talking about is fundamentally a bad idea. The problem is generally solved by wrapping the database in an API of some kind and then having the client query against the API. The goal is to never allow the client to say "I want to run SQL", you let them say "I want data" or "I want to write data" instead.

[20 pages of that Super Meat Boy hi score mysql fiasco]

ManoliIsFat
Oct 4, 2002

Pollyanna posted:

...Incidentally, I'm thinking about another approach. Is it possible to disable the input box "border" on an unfocused input box, such that it looks like the input is text before you click on it, or is there a better way to do what I'm describing?
The way I've seen this done you have a span and a text field hidden next to it. When you click on the text field, it hides the text, shows the form input and focuses on it. When you click away or hit "Save" or whatever, you update that text span with the new value.

Like this, right? http://www.appelsiini.net/projects/jeditable/default.html

ManoliIsFat
Oct 4, 2002

Corla Plankun posted:

This is a really dumb question but I am having a hard time figuring out how to approach finding a solution.

How do I get local information onto a website in real(ish)* time?

A toy example: I have an ubuntu machine that is currently hosting the default "It works!" apache homepage; the same machine is also running a python script that communicates with an external temperature sensor. I want to host a website that updates the temperature as it changes (without refreshing). How do I bridge the information from python (or some other language if it is more convenient, idgaf) to a website?

I am pretty sure the answer is some kind of javascript library, but I can't figure out a concise way to describe (and then google) this problem.

*500ms of latency on a LAN would be ideal but longer turnaround times would not be the end of the world.
I don't know if you really need to get deep in to sockets, I think you basically want AJAX $().get(). You would "poll" some web server every 250ms and it would return a JSON object (or even just that number if you wanted to be really dumb about it), and you'd fill in a <span> or something with that value. Or it could be even dumber and your python script can write a text file in a web accessible directory, and you just read the value of that file.

code:
<script>
function updateTemp()
{
  $.get( "/data/thermo.txt", function( data ) {
    $( "#result" ).html( data );
  });
}
//TODO: setup the timer and all that to call this function every 250ms
</script>

Current Temp is: <span id="result"></span>
Then again, I don't know your exact requirements, so maybe you do need socket.io for the data to be pushed from the server instead of you polling it constantly.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply