DevMoore94 / TextThem

This is an app to send text messages from the web browser
GNU General Public License v2.0
5 stars 2 forks source link

Merge RandomGenerator with send #13

Closed syntonym closed 9 years ago

syntonym commented 9 years ago

Instead of having a seperate page for the random generator a button "Insert random text" could be under the send form that inserts the random words into the form.

Best for this would be probably be a javascript function that calls to an endpoint `textthem.com/random" or something like that and inserts that into the form.

Would that be okay?

DevMoore94 commented 9 years ago

Sounds fine to me. Would the python function still generate the words that are being used?

syntonym commented 9 years ago

Yes, but it would be modified to only return json.

DevMoore94 commented 9 years ago

alrighty.

DevMoore94 commented 9 years ago

Accidently closed this. Realize the random generator still needs to be styled. Loving the changes though. got everything setup and installed on my laptop at home.

syntonym commented 9 years ago

I've implemented the changes on https://github.com/syntonym/TextThem/tree/merge_random, but it's... slow. Each time the "random" button is pressed, an ajax request is send to /RandomGenerator which returns a json with {adjective: [adjective], noun: [noun]} and then entered in the form. But the request is still a request and needs some time to return.

Another possibility would be to load the entire dict of random words when loading the page and doing the random stuff in javascript only. Or maybe just load a subset of the dict. Or maybe load random words as soon the page loads.

To checkout my changes just clone my merge_random branch.

DevMoore94 commented 9 years ago

Looking good! Just trying to understand what you are doing,

$("#InputMessage").val(response.adjective + " " + response.noun);

This grabs the adjective and noun variables that were returned by the generatemessage() function correct? I am not that proficient in java script :P

syntonym commented 9 years ago

$.getJSON("/RandomGenerator", function(response) { This will get the json object lacated at "/RandomGenerator" (you can visit it with your webbrowser too see how it looks like) and pass it to the anonymous function as response.

$("#InputMessage").val(response.adjective + " " + response.noun); This will then locate the form with the id=#InputMessage and set its value to response.adjective + " " + response.noun. response is something like: { "adjective" : "greedy", "noun" : "rabbit" } a simple json which is often used in compound with javascript and works similiar to a python dict. Infact python dicts can easy be converted to json with flask.jsonify which is used in TextThem.py line 151.

DevMoore94 commented 9 years ago

Makes sense! so what are the advantages to using json?

syntonym commented 9 years ago

Json is a simple format for data and especially suited for "small things" like this. An alternative to json is XML but json is way more human readable.