Saturday, November 29, 2014

Planning stage

How to model the repository?

My starting point is to create a database model called Pages to hold the contents, with the following migration:
  class CreatePages < ActiveRecord::Migration
    def change
      create_table :pages do |t|
        t.string       :title
        t.text         :abstract
        t.text         :content
      end
    end
which I think is pretty self-explanatory. (Note: if you don't read rails, it basically creates a database table with three columns, title, abstract, and content, with string and text datatypes). Do I need another model for the categories? A category may not have much, or any, contents. It might be nice to have a little bit of abstract to say what it is about, but that's about all it needs. So it does look like I can represent them using the same Pages object, maybe by adding a boolean column to note that it is a category. 

However, when the webpage loads, it should display all the categories on the left hand side. If I keep all the categories in the same table as the Pages objects, it may slow things down once there is a lot of contents. I don't think it's very efficient having to scan the 'Page' table to pick out which ones are the categories, even when it is indexed. Plus, I do not see any benefit, unless I want to demote a category to a Pages object, or vice versa, and that is not something I should be doing anyway.

How about sub-categories? These will only be shown when a category is selected, and it is possible that I want to convert a Pages object into a sub-category of its own. So, I'll represent them using the Pages model.

Now, more importantly, how do you link Categories to Pages? Fortunately there is a gem (i.e. plugin) for this called Ancestry.

Should I add users?

At this point, there's only going to be one user in mind, me, but it does not take much effort to add users on the application using Devise. Each user should be able to choose which Pages and Categories are private, and displayed to everyone. I imagine a url structure like the following:
    http://<domain>/Users/1/Categories/1/Pages/1

So up till now we have the following three data models Users, Categories, and Pages.

Friday, November 28, 2014

Start of the blog

Here is the blog that I plan to keep as I build my note-taking web application using Ruby on Rails. 

My goal application is a web-based repository for all my notes, organised by categories (and sub-categories), with all the entries stored in a database. The closest analogy is like writing a book using LaTeX, with chapters, sections, and subsections. I want the chapters and sections displayed clearly at all times so that I can jump around easily. I imagine it to look something like this:


The categories are listed in the tab on the left hand side, and can be expanded to show all sub-categories and/or entries. The plan is to have a tree structure three levels deep --- category, sub-category, and content --- though I'd like to model the entries so that this can be further expanded, e.g. by using the same model to represent a category and sub-category so that one can be converted to the other, or so that adding sub-sub-category can be done easily.

Why not use an existing solution?

I have been using DevonThink in the past, but it is Mac-only, and I want something online-based. Evernote was too disorganised for me, or rather, I'm too disorganised for Evernote. TiddlyWiki was great, but I need more structure than a wiki. I have tried a few more tools, but haven't found anything suitable so far. 

Writing something from scratch also gives me more freedom than any tools I can find, particularly since I hope to be able to process LaTeX entries in the future (none of the above supports LaTeX as far as I know). Things like code highlighting can also be done easily in html. 

I plan to be using Ruby on Rails, since this is what I have been learning for the last year. I may consider using other tools that I have learned (AngularJS, node.js), but after all this is a beginner's project, so I'd like to keep it simple.

Why keep a blog?


I like keeping records on everything that I do, so that I can always refer back to it (hence the project!). It doesn't take that much effort to convert it to a blog, and maybe someone can benefit from reading my drivels as well.