Zen-NotePad

Description


zen-notepad is a AgularJS one-page web application, running on light back-end RubyOnRails. To see it live, please visit zen-notepad for a live demo. zen-notepad is essentially a note pad to write notes, it allows user to create, delete, view and edit the note. Notes are stored on browser local storage, so if you accidentally closed the browser, data will remain.

Notepad2.png

Check out the project on GitHub: https://github.com/shawnfan/zen-notepad.git

Features and Walk Through

  • One-Page web app that runs multiple templates: Home, Note, Navigation. Code is quite clean to read.
  • MVC framework: AngularJS serves as controller and view in this demo, and the model is simulated bylocal storage + angular service
  • Device responsive. It transforms to mobile device size and feel when viewing on a phone.
  • Follow the design pattern of Google Angular Material
  • Add, View, Edit, Remove function
    Add: click "+" icon to create a new note. Page directs to that new page, then you can edit title and note contents.
    View: click on note title to view
    Edit: click on editing field when viewing the note
    Remove: click on '-' button to remove the note.
  • Add image to individual note, use AWS api to store image on AWS S3, and view image via AWS Cloud Front.
  • Limit image size to 2 MB and totaly 6 images. User can select multiple images at once. The app will throw error notice if try to go over the limit.
  • Prompt user with dialog when trying to delete a note or reset the local storage.
  • Click on Home button to return to home page.
  • Display notes with ng-repeat by order of note creation time on home page. Datetime is generate on note creation.
  • Allow user to reset local storage, which removes all notes from the notepad.
  • User can check off the note, so it works like a todo-list
  • Browser local storage: all data is stored locally
  • Auto save: user does not need to click 'save' button to store notes. It's automatic.

This app is mainly to demonstrate the the usage of some really nice web development tools, framework and UI design patterns.

Front-end: zen-notepad uses the set of tools around AngularJS: angular of course,angular-ui-router to build one-page navigation, angular-material for the Material Design Pattern, ngStorage to store data in browser local storage.

Backend: RubyOnRails with minimum backend code, majorly just serving up the angular app and support resources assets pipeline. The web app is hosted on Heroku.

Cloud Storage I used AWS S3 to store uploaded images, and use AWS Cloud Front to deliver the images to user, in case in some area a CDN could speed up the image loading.

Note, originally the angular app was using inline template for routing and page navigation. However, the routing generates error because google chrome restricts XHR calls on file:// protocol. Secondly, as the app grow, the index.html code does not look sufficient. So I made the decision to quickly serve it up with Rails. On the backend, there is just minimum configurations. Rails also helps to manage all the angular script, css input pipeline, so the index and template pages all look very clear.

Run it locally


If you want to run the server locally, simply clone this git repository, and run rails s. Though, if you are not using rails previously, you may need to make sure a few components already installed: Ruby ,Rails, sqlite(We are using browser local storage rather than sql db. Here sqlite is installed as part of Rails structure)

Clone zen-notepad:

git clone https://github.com/shawnfan/zen-notepad.git

In the root directory of zen-notepad:

If bundle not installed, make sure to install it:

gem install bundler

Then, install all packages:

bundle update 
bundle install

If bundle throws any tools or resources with error, follow the instruction to install the missing parts.
To start the server, simply run:

rails s 

The server will be running at localhost:3000 by default.

Code Structure


Quite a few dependencies and setup has been done with RubyOnRails, and basically to integrate Angular Front-end with the Assets Pipeline.

As a result, the front-end files are hosted in a very clear way: under root folder zen-notepad/app/assets/, I put all angular javasript, html template, css style sheet.

The one-page frame is part of RubyOnRails, which is the application.html.erb. This file contains the rails js and css pipeline, ng-app and ui-view, and it's basically a skeleton frame.

zen-notepad/app/views/layouts/application.html.erb

For front-end code review, the only section of code we need to look at is:

zen-notepad/app/assets/*

Just a brief view of the front-end code under zen-notepad/app/assets/:

zen-notepad/app/assets/ 
       |----javascripts 
                ||- home/ 
                        ||**||- _home.html 
                        ||**||- notePadCtrl.js 
                ||- note/ 
                        ||**||- _note.html 
                        ||**||- noteCtrl.js 
                        ||**|| noteService.js 
                ||- app.js 
                ||- application.js
       |----stylesheets 
                ||- application.css

The front-end code is grouped together by page functionality; each page has a controller. The major service is the noteService.js, which serves as Model, and is our core object in the app. I followed this pattern for coding efficiency: it's easier to navigate to templates and edit code since I'm building a one-page app with multiple templates.

App Creation Process:


Below is the thinking && plan process. Basic features mentioned below are all implemented.

UI Draft
Sketch up the pages, which is the goal to accomplish, with basic functionalities of create, edit and view note; also added a few features as next step: note check-off function, remove function, user account, add attachment function to cloud storage.

Also, see the sketch below:


alt text
alt text

Start the draft design for the core objects

NotePad (Home page), Note (Individual Note page)

Do a simple object oriented design: In each object, list out the attributes of each type of object and the possible methods to create.

The core object is the note object, and I probably will create angular service around the note object, saved on local storage; this is going to serve as the 'Model' for the MVC app, since I'm not going to implement real backend Model and controller with Rails ActiveRecord. Clearly, in this demo Angular serves as the frontend controller and it renders the view.

List all of the features and the according tech stack that maybe used

  • For objects Note and NotePad, store on browser: browser local stroage. Use JSON format to create dummy data.
  • List of Notes: Angular ng-repeat
  • One-page app and 2 templates for Home and note: Angular ui-view and ui-router
  • Host the app on a server. Google chrome won't allow XHR calls
  • Use bower, gem to nicely record dependencies, so to make it easy to clone&&run.
  • Button, layout, responsive design: Angular Material layout and directives

If with more time:

  • Image attachment: AWS S3 storage.
  • User login and account creation: Use RubyOnRails + Devise. (Not included in this demo)

Tasks

  1. Create index + angular, simple test, build Note JSON object, display list of objects on Home Page.

  2. Host RoR, link to github.

  3. Setup app structure in RoR. Move index and angular code. Configure the pipeline. Test.

  4. Test router in angular config.

  5. Create the pages in separate templates

  6. Work on simple grid and replace UI elements with angular material elements.

  7. Build methods for note object, test it with angular.

  8. Add imageattachment feature.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,684评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,143评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,214评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,788评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,796评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,665评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,027评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,679评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,346评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,664评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,766评论 1 331
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,412评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,015评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,974评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,073评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,501评论 2 343

推荐阅读更多精彩内容