Cancelling / reverting changes to models in angular.

Right up front I’m going to say that i haven’t found the right answer to this problem. Yet.

outline

Add undo or save abilities to edits on a model in Angular.

I have two templates which bind to my model. The edit template and the view template. When in the view the data is bound essentially one way and there is no problem. For edit, angular has some great binding that reacts to change events and sets the model value to the current value of the input. This is a key aspect of the angular frame work, and in a lot of places, this data-binding is really useful, except if you not sure you want to keep those changes.

the two way binding will overwrite the original model with the new changes and then the original values are gone. so how do i implement a cancel/revet button?

things i have tried already

‘get’ the model again from a saved point. This involves making a request to the server for the original model value. Its expensive both in network & time, so doesn’t lead to a great user experience. Also this breaks for things not yet stored on the server.

copy & change. Take a copy of the model, edit that and push the changes back on save. The failure here is that with an async system like javascript, my model might not be fully loaded at the point i want to copy, and even if it is, how do i reflect changes to the original in my ‘editing’ copy?

cacheing the model on each ‘save’ which allows me to get the original value back if my edit are cancelled. Still changes to the original from another source need to be re-cached.

 

so im ata a loss. for now. ill write back if i find a suitable answer.

 

Expanding on some ideas

A friend of mine has been thinking about home automation recently, and this got me thinking about a few things but mainly, what would be some good concepts for the infrastructure of such a network of devices.

So whats important?

Easy to set up – technically minded people tend to overlook this aspect or worse yet, misunderstand the true meaning of easy set-up. Wi-Fi pairing is only now becoming a skill that most people are comfortable with, so if we are to have a network of devices that report back to the internet through your home internet connection then we will need to have some very clever programs to enable all this setup with as close to plug and play as possible.

Dynamic – any infrastructure is going to have to be able to deal with the dynamic nature of the standard home network/router internet connection. This will be an assign IP to the router and then local assigned IP’s for devices within the house

Simple –  If we are going to implement this on embedded devices the concepts have to have a very low overhead for computation & throughput

Proven – As with most things, its probably already been done quite well, so take some of these lessons and build on them.

The underlying functionality of a home automation ‘node’ is pretty simple, report measurements or switch outputs. The interesting thing comes when we start trying to have a system that can navigate complex network infrastructures (like the whole web, plus the LAN its part of) and report this information back to a server. Maybe we would like the ability to re-route this information to a different server, or multiple outlets.

The dreaded scaling word

As part of UOS online lessons need to be able to upload small sound clips from the client to the server. These clips are aprox 300k in size and can be sent a received reasonably quickly. So some Node.JS later i have a serve which will receive and server sound clips. Happy days.

Image

Anyone would think that the hard part is over as i have got the functionality i need up and running. but this is the internet and Im going to have to think about what happens when several users are pushing data back and forth to the server and how that will impact on storage space on my server and traffic. each of which will have there very real world costs from a hosting company.

ImageImage

For now I’m not even thinking about traffic costs but purely storage.

Each user must complete 150 reading lessons with an average of lets say 3 blocks of 5 words per lesson. so over the entive course the user will upload 300k * 5 * 3 * 150 =  675Mbytes of data. The average course takes a year so roughly 675 / 365 = 1.8 ish Mb a day. (this is spreading out the load over all days even though a large number of days will be zero traffic, holidays etc)

although they will upload 675 Mb of data we will only be holding a window of say 20Mb of data per student so:

Traffic — 1.8Mb/day/user

Storage — 20Mb/user

with roughly 5000 active users of UOS we could maybe expect a 5th of these to convert to online in the next year, so:

Traffic — 1.8Gb/day

Storage — 20Gb

This is starting to look dangerous, what happens when we catch up with users all online and even grow the total users to say 10000?

Traffic — 540Gb/month

Storage — 200Gb

this just shows how a relitively small ammount of code pushed over the network and stored on a server ver soon adds up when you start thinking about users in the thousands.

Stuff im loving today

More and more im falling in love with my raspberryPi not so much for its ultra small form factor computing power, but because its forcing me to learn more Linux bits and bobs and i love that.

today : Screen

Ever wanted to log into an ssh shell and have things exactly where you left them? ‘screen -R ‘
be able to have multiple windows open in your session ‘ctl+a, ctl+c’ and see a list ‘ctl+a, ctl+” ‘
be able to see tow things at the same time ‘ctl+a, ctl+s’

coming late into the command line ninja game this is all probably old to most people, for me its like a whole new lease of life on computing in the command line.

Node.JS & express as a replacement for Apache httpserver

In my ongoing learning with Node.js i find at each turn im more and more surprised at just how much it can do for me. Recently this surprise took the form of a problem ive been having froa while now with configuring Apache for proxy and reverse proxy to multiple web apps on my local server.

Here’s the run down of the situation:

i have 4 main web-app’s running on my server for various reasons and on various ports

  • Transmission on port 9091
  • SickBeard on port 8081
  • CouchPotato on port 5000
  • sabznbd+ on port 8085
  • XBMC on port 8080
  • Ajenti on port 8000

Currently i can reach each service in turn by sticking in the port as part of the URL http://server:5000/ gets me CouchPotato for example, but this isnt the nicest of URL’s to remember so what i really want is http://server/couchpotato instead. So some quick googling later and i find out that i can configure my allready installed and running Apache httpserver to do this with proxies and reverse proxies, excilent, and it all looks relatively simple to modify a few htaccess and other such setup files.

NO SUCH LUCK i consider myself a reasonable software developer and a fairly advanced computer user, so modifying a couple of files and reading a few API docs are not beyond me, but for love nor money i cannot get this stuff to work.

Skip ahead 6 months of nasty urls

I wonder if Node can do this sor of thing, quick google later and i find node-http-proxy and a 3 minute express config file later and ive got my proxies working like a dream.

With this experience and others ive decided to uninstall Apache completely and reply on Node.JS as my sole web server for just now. Hopefully this will simplify my life dramatically.

Moving from reader to twitter : pointless

Just a quick update to something I mentioned last week, I tried moving from google reader to a twitter list. I can’t even last a week and I’ve gone back.

Twitter is a great tool and rss feeds may be an old fashioned tech, but for me it works best. I think mostly it’s just the user interface rather than the underlying technology.

Anyway for now, reader is my choice

Adobe Brackets

So just for gun this morning i tried playing about with Adobe Brackets and i have to say well done to the guys who are building this. So far (Sprint build 12 at the time of this post) all the main functionality is there and this could well be used for simple JS development.

I love what adobe are up to here, a complete IDE (lightweight) written in the language its going to develop. Obviously this isn’t the first time this has happened but it is an exciting time for developers and im sure ill be writing some extensions soon enough. Until then, im still a big fan of Cloud9