CSC/ECE 517 Spring 2015 E1526: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
__TOC__
__TOC__


= Problem Statement =
= Strategy =


Despite an amazing set of functionality Expertiza offers, there are numerous parts of it that could use a more stylish look and an improved user experience. The goal of this project is to use both Bootstrap and AngularJS to improve the look of the entire Expertiza including the representations of buttons, tables, and other elements. Certain changes in design will also improve the efficiency of the web app when it comes to the amount of time it takes for a page to be loaded.
We analyzed the three Expertiza pages that we need to modify for this project, as well as all of their dependencies, and tried to identify all the tasks that we need to complete for this project. It became clear to us that a large majority of this project will be based on AngularJS, while the small fraction will be related to Bootstrap. Therefore, our strategy is to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page is completed, we will split in two groups. One group will work on implementing AngularJS on Manage-course page, while the other group will work on introducing AngularJS to Manage-User page.
The reasoning behind this strategy is that all of us working together on the Login page first will allow us to closely cooperate and learn from each other. Hence, by the time we complete the Login page, each one of us will have a decent understanding of AngularJS, allowing us to split into groups of two and work effectively on the remaining two pages, which are more complex.
We plan to complete AngularJS constituents first and then add Bootstrap. Our decision was based on the fact that Bootstrap does not require much work to be completed and it can be considered to be pretty straight-forward to implement. Therefore, we believe that we can implement Bootstrap in two days or less, while AngularJS will require some learning at first.


= List of Tasks =
= Implementation =
Below are detailed explanations to the tasks listed in the description documentation.
Below are detailed explanations of essential constituents of this project.




== 1. Replace Buttons and Links to Bootstrap styled Buttons ==
== AngularJS Implementation ==
Expertiza, being an extensive web application with numerous features, heavily relies on buttons when it comes to interacting with the user. We plan to improve the user experience by replacing the plain html buttons with stylish bootstrap buttons. However, numerous elements in the current version of Expertiza, like 'Back' element, are hyperlinks rather than buttons. To make the design of Expertiza consistent, our goal is to replace this plain-styled text with color coded Bootstrap buttons.


== 2. Create new theme ==
1. Retrieving data from database
One of the entities responsible for the primitive look of Expertiza, as of now, is the lack of fixed navbar. The new design of Expertiza will include the fixed menu bar on the top of the page. Please refer to the screenshot shown below for an example from Virgin American website. As it can be seen on the screenshot, the user has scrolled down the page, but the menu bar is still visible on the top of the page, making it convenient for the user to navigate throughout the website.
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we can load data is through rails controller. For example, we can do a http get/post request(GET /users/fetch_10_users) from AngularJS controller using $http injection or jQuery AJAX, which calls a new method ‘def fetch_10_users’ in the users_controller, which execute some database query via accessing methods in the user model, and returns json formatted data to the AngularJS controller. After getting the returning data, the AngularJS controller can present the data to the screen.


[[File:Picture4-2.png]]
2. Build custom directives
Instead of using the original Rails page, I think it would be better to replace some forms and components using AngularJS directives, which enable us to do some live modifications to the pages without loading.


== 3. Auto hides contents on the dashboard for instructors ==
== Database ==
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design
Now the problem is how to fetch parts of database records which meets the query conditions, now what comes in our mind is using SQL statements like “SELECT FROM { SELECT * FROM STUDENTS WHERE id BETWEEN 1 TO 100} WHERE STUDENT.DEPARTMENT = ‘CSC’”. Then we store the result into a hash, and presenting only maybe 10 of the qualified records to the screen. Once the hash is used up, another query to id 100-200 will be executed and fetch something more. Therefore the loading time could be greatly reduced, so that the time needed for representing the page is also reduced.


Now, when trying to open manage-courses, all records are loaded before rendering them onto the page, which takes too long time to load and is not responsive at all.


Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402
== Integration of Rails and AngularJS ==


When the website is representing the calendar, the price for each day is not actually loaded. But the skeleton of the page, which is the calendar in this case, can be displayed first.
Guidelines:


[[File:Picture5.png]]
a. ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’ and REMOVE ‘gem turbolinks’ from the Gemfile, THEN execute bundle install


So in Expertiza, we can create several buttons for course semesters in the page. After clicking on Fall 2014, the courses for Fall 2014 will come out.  
b. ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection) TO A NEWLY CREATED Bowerfile, THEN rake bower:install. Bower installs dependencies in vender/assets/bower_components.


And if the list is still too long and takes a long time load, we can use a ‘show more’ button ,or automatically load more data when the scroll bar reaching the end of the page, to minimize the content we need to load after one single mouse click.
c.  ADD
<pre>
config.assets.paths << Rails.root.join("vendor","assets","bower_components")
config.assets.paths << Rails.root.join("vendor","assets","bower_components","bootstrap-sass-official","assets","fonts")


[[File:Picture6.png]]
config.assets.precompile << %r(.*.(?:eot|svg|ttf|woff|woff2)$)
to the config/application.rb
</pre>


d. REMOVE //= require turbolinks AND ADD
<pre>
//= require angular/angular
//= require angular-route/angular-route
//= require angular-rails-templates
//= require angular-bootstrap
</pre>
to assets/javascripts/application.js,
Then rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. ADD
<pre>
@import "bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets"; and
@import "bootstrap-sass-official/assets/stylesheets/bootstrap";
</pre>
to application.css.scss


 
Now because we are not building a new website using AngularJS from the beginning. It is better to remain the routing system of Rails rather than taking charge of routing system in AngularJS.
== 4. Simplify Action Panel ==
So, we add a new tag <div ng-app='MPApp'> into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, naming ‘MPApp’ in this case.
We will need to reduce the number of buttons. For example, the first row are actions for assignments and the second row is for participant. So we can replace them to 5 buttons with responsive design, that is, no redirecting happens after clicking on the buttons.
Then, for the home page: app/views/content_pages/view.html.erb. We add a tag to make this page controlled by ‘testCtrl’, which is defined in app.coffee.
 
[[File:Picture7.png]]
 
 
 
== 5. Offer Better UI for Managing Users ==
 
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]
 
 
 
== 6. Make grades_view Responsive with Better Design ==
 
Similar to the previous tasks, we will need to make it responsive.
 
After clicking on ‘Your scores’, all reviews are loaded before rendering the page now. That takes a long time to load and the length of review list is too long.
 
[[File:Picture8.png]]
 
=Design Patterns=
 
As an assignment with a goal of improving the graphic design and responsiveness of Expertiza web application, this project mainly follows design patterns from two design pattern groups: structural and behavioral.
 
==Structural Design Patterns==
Flyweight, a design pattern aiming to minimize the memory usage by sharing as much data as possible, is heavily implemented on the css and bootstrap side. Our team leans towards creating classes for styling that can be efficiently reused in a variety of Expertiza sections, rather than separately refining the design of each little section. This will both save us time and keep the code concise, while optimizing the memory needed to store the code.
 
Another structural design pattern that will be seen in this project is Front Controller pattern. While this pattern suggests that there is a single controller that takes all the requests, when we have both Rails and AngularJS coexisting, we can think of Rails framework as being the "single bridge" to the database from AngularJS's stand point. AngularJS, being an outstanding front-end framework, will interact with the user and pass all the request to Rails framework. Rails framework then queries/updates the database and provides AngularJS with the data.
 
Finally, the third structural design pattern that this project follows is Module pattern. Modules are one of the essential constructs in the skeleton of AngularJS framework and, hence, this project is bound to follow module pattern.
[[File:E1526-1.png]]
 
==Behavioral Design Patterns==
Since the large part of this project is to iterate through the database query and show the data to the user with a reduced delay, this project follows the well known Iterator pattern.
 
Along the similar lines, Observer pattern is followed to efficiently handle query requests to a large database (the main culprit behind the unpleasantly long delay). Our project intends to tackle this challenge by fetching only a screen-full of results and showing it to the user right away (fast response). While the user is looking at this first chunk of data displayed on the screen, further queries are made to the database in the background and the rest of the matching results are being returned, efficiently populating the page further. This approach greatly improves the user experience since it does not leave the user waiting empty-handed until Rails framework completes the full query of the database. <br>
[[File:E1526-2.png]]
 
= Pages To Be Modified =
For this project, it is difficult to re-design all webpages and make them responsive. After discussing with the contact person, we will be focusing only on these 3 pages:
 
=='''Login Page'''==
[[File:Picture1.png]]
 
=== What's wrong with it ===
1. Now it takes more than 15 seconds to even login to the admin's home page with the sample development database. This is definitely not good enough for a daily used web application.  
 
The cause for the long rendering time is that it will be redirected to 'tree_display/list', which needs to fetch all questionnaires, courses and assignments before page rendering.
 
2. The webpage looks primitive.
 
=== What changes need to be made ===
1. Actually it is unnecessary to fetch all data at the very beginning; if there is too much data to present, the list will be extremely long and it is quite hard for users to locate a specific course.
 
So, we will use AngularJS and jQuery to make a asynchronous webpage that delays the database query until all the basic html elements are correctly rendered, or until the user explicitly asks for that part of data.
 
2. Bootstrap will be applied for better user interfaces.
 
 
 
=='''Manage-Course page'''==
[[File:Picture2.png]]
 
=== What's wrong with it ===
As illustrated above, now the displaying list is too long and it takes too long to scroll to the end, which makes locating a specific course quite difficult.
 
Also, loading time can be reduced.
 
=== What changes need to be made ===
1. Create several buttons for different time intervals, for example, after clicking on the button '2013-2014', only courses for 2013 to 2014 are presenting, and there is no redirection during this process.
 
2. The database should not be executed before the user clicks on the button. Only parts of databased is fetched when each button is clicked.
 
3. Bootstrap will be applied for better user interfaces.
 
 
 
=='''Manage-User page'''==
[[File:Picture3.png]]
 
=== What's wrong with it ===
1. The list is too long: if there are 20k users in the database, there will be 20k rows in this table in a one page!
 
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.
 
=== What changes need to be made ===
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.
 
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.

Revision as of 19:36, 2 May 2015

E1526. Responsive web design for Expertiza

Strategy

We analyzed the three Expertiza pages that we need to modify for this project, as well as all of their dependencies, and tried to identify all the tasks that we need to complete for this project. It became clear to us that a large majority of this project will be based on AngularJS, while the small fraction will be related to Bootstrap. Therefore, our strategy is to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page is completed, we will split in two groups. One group will work on implementing AngularJS on Manage-course page, while the other group will work on introducing AngularJS to Manage-User page. The reasoning behind this strategy is that all of us working together on the Login page first will allow us to closely cooperate and learn from each other. Hence, by the time we complete the Login page, each one of us will have a decent understanding of AngularJS, allowing us to split into groups of two and work effectively on the remaining two pages, which are more complex. We plan to complete AngularJS constituents first and then add Bootstrap. Our decision was based on the fact that Bootstrap does not require much work to be completed and it can be considered to be pretty straight-forward to implement. Therefore, we believe that we can implement Bootstrap in two days or less, while AngularJS will require some learning at first.

Implementation

Below are detailed explanations of essential constituents of this project.


AngularJS Implementation

1. Retrieving data from database Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we can load data is through rails controller. For example, we can do a http get/post request(GET /users/fetch_10_users) from AngularJS controller using $http injection or jQuery AJAX, which calls a new method ‘def fetch_10_users’ in the users_controller, which execute some database query via accessing methods in the user model, and returns json formatted data to the AngularJS controller. After getting the returning data, the AngularJS controller can present the data to the screen.

2. Build custom directives Instead of using the original Rails page, I think it would be better to replace some forms and components using AngularJS directives, which enable us to do some live modifications to the pages without loading.

Database

Now the problem is how to fetch parts of database records which meets the query conditions, now what comes in our mind is using SQL statements like “SELECT FROM { SELECT * FROM STUDENTS WHERE id BETWEEN 1 TO 100} WHERE STUDENT.DEPARTMENT = ‘CSC’”. Then we store the result into a hash, and presenting only maybe 10 of the qualified records to the screen. Once the hash is used up, another query to id 100-200 will be executed and fetch something more. Therefore the loading time could be greatly reduced, so that the time needed for representing the page is also reduced.


Integration of Rails and AngularJS

Guidelines:

a. ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’ and REMOVE ‘gem turbolinks’ from the Gemfile, THEN execute bundle install

b. ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection) TO A NEWLY CREATED Bowerfile, THEN rake bower:install. Bower installs dependencies in vender/assets/bower_components.

c. ADD

 config.assets.paths << Rails.root.join("vendor","assets","bower_components")
 
config.assets.paths << Rails.root.join("vendor","assets","bower_components","bootstrap-sass-official","assets","fonts")

config.assets.precompile << %r(.*.(?:eot|svg|ttf|woff|woff2)$) 
to the config/application.rb

d. REMOVE //= require turbolinks AND ADD

//= require angular/angular
//= require angular-route/angular-route
//= require angular-rails-templates
//= require angular-bootstrap 

to assets/javascripts/application.js, Then rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. ADD

@import "bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets"; and
@import "bootstrap-sass-official/assets/stylesheets/bootstrap"; 

to application.css.scss

Now because we are not building a new website using AngularJS from the beginning. It is better to remain the routing system of Rails rather than taking charge of routing system in AngularJS.

So, we add a new tag

into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, naming ‘MPApp’ in this case.

Then, for the home page: app/views/content_pages/view.html.erb. We add a tag to make this page controlled by ‘testCtrl’, which is defined in app.coffee.