cozy/cozy-files — pull request #101 by jsilvestre (2014-06-20 10:08:31+00:00)
Title: Refactoring: change the application's architecture

I changed the client architecture so the model is (hopefully) cleaner and allow us to move forward the application faster (related issue is #95).

# New architecture

## General idea
* all files and folders are stored in one collection initialized in application.coffee
* when the user browse the app, a subcollection is created based on the folder it is browsing. For now, the subcollection is recreated each time but we can do so caching if we feel it's wrong
* the folder view is recreated every time the browsed folder changes (except for the search, to maintain the input state (see comment in related code)

Regarding "philosophy", I tried to make things simpler and more declarative so it's easier to maintain, but it can surely be improved.

## Model caching
One thing to note is that I added caching to folder. That means when you browse a folder the first time, its content is cached so when you come back to that folder it is displayed instantly. The cache refresh is ensured by 1°) realtime 2°) a request run every time the folder is displayed (in the background so the user can do his stuff in the meantime). So if realtime works for the user, it won't notice anything; otherwise it'll be able to benefit from fast display without being out of sync.

## Breadcrumb
I also fixed bugs (mostly in the breadcrumb). I simplified a lot the breadcrumb management, making it a part of the folder model and caching it. It might be over-simplified now because I dropped the Backbone.Collection in favor of a simple array.

## Upload
I moved code around in the various classes in charge of uploads. The upload itself is now performed by the UploadQueue collection, which represent the files to be uploaded. I think it will be fairly easy to display a merge version of the collection (based on browse folder) and UploadQueue to implement the inline uploader.

## File templates
I changed the file's templates (file.jade; file_edit.jade; file_search.jade) because they were unmaintainable as-is. It now uses jade inheritance so they are (very) smaller.

## Public area
I tried to make sure it works as before but I didn't make any of the planned changes because I assume this is not top priority and not part of the blocking code for the rest of the team.

## Quality
Needless to say that I have most likely introduced bugs that I haven't noticed yet; so even if I know you all want to see this merged ASAP so you can start working the app again, I'd suggest we all use my master on our Cozy this week-end to detect remaining and awkward bugs.

## Review
I let numerous `console.log` on purpose so people that will review the code can understand what's going on with caching and stuff. I also let a `setTimeout` on purpose in the server to actually realize caching works. Obviously I will remove them, rebase the code and force a push on my master.

There are also numerous comment with a `REFACTORING` prefix. Those are questions that I didn't want to answer alone or questions to myself that I forgot to answer ;-)

While I think reactivity is improved thanks to that, I also noticed that the application was **significantly** slower in terms of FPS on my MPB. No issue with my desktop which is faster by far. If you find any improvements (there are many, I believe) to prevent useless reflow etc. please let me know.

So please, don't merge before the PR is tagged "good to merge", thanks!