<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ikopas</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ikopas"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Ikopas"/>
	<updated>2026-10-07T09:45:24Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=97093</id>
		<title>CSC/ECE 517 Spring 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=97093"/>
		<updated>2015-05-04T15:09:44Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* FinalProject Report */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 17 WL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 5 ZX]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 6 TZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 4 RW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 7 SA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 9 RA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 14 RI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 1 DZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 20 HA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 3 RF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 12 LS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 13 MA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 2 WA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 21 QW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 23 MS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 10 GL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 27 VC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 22 SF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 15 SH]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 18 AS]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1502 wwj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1508 MRS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1504 IMV]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1505 xzl]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1509 lds]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1510 FLP]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1506 SYZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1504 AAC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1507 DG]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1502 GVJ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1503 EDT]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1503 RSA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1501 YWS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1501 OA]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Design Document==&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1526 MPRI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 S1503 LWJZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 S1524 FSZZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 M1503 EDTS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1529 GLDS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1525 TIAA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1522 Visualization]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1527 SWAR]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Report==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1526]]&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97092</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97092"/>
		<updated>2015-05-04T06:33:36Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Resources */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Guide for future students =&lt;br /&gt;
1. Learn how to integrate AngularJS into Rails, using Rails original routing system.&lt;br /&gt;
&lt;br /&gt;
2. Learn AngularJS and Coffeescript, since the app.js is written in Coffeescript now.&lt;br /&gt;
&lt;br /&gt;
3. Learn Bootstrap, including the grid system, responsive design and etc.&lt;br /&gt;
&lt;br /&gt;
4. Read the code written by us, to know &lt;br /&gt;
&lt;br /&gt;
    a. how to pass data from Rails controller and view to AngularJS; &lt;br /&gt;
    b. how to pass data back to Rails view from AngularJS; &lt;br /&gt;
    c. how to convert JSON formatted data using in AngularJS to Rails hash and vice versa.&lt;br /&gt;
    d. how to present the data to Rails view&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD the following content to the config/application.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js&lt;br /&gt;
&lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;code&amp;gt; div ng-app='MPApp'&amp;lt;/code&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;br /&gt;
&lt;br /&gt;
=The specifics=&lt;br /&gt;
This section explains the very detailed actions and their results related to the 3 specific pages that were used to integrate AngularJS. Numerous snapshots are provided with the goal to make our approach very clear.&lt;br /&gt;
&lt;br /&gt;
== Login Page and Navigation Bar ==&lt;br /&gt;
Login procedure:&lt;br /&gt;
‘Login’ button clicked → auth_controller#login → auth_controller#after_login(user) → if user.role != ‘student’ → tree_display#drill → tree_display#list&amp;lt;br/&amp;gt;&lt;br /&gt;
If session[:menu] is defined, that is, when a user is logging in, the page will render the content of variable session[:menu].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
       &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
          :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
     &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
         :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
 &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each menu item in the nav bar, it is a dropdown menu now. For different level of dropdown menu, we apply different CSS style to it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% level += 1 %&amp;gt;&lt;br /&gt;
&amp;lt;% items.each do |item_id|&lt;br /&gt;
  item = session[:menu].get_item(item_id)&lt;br /&gt;
  selected = session[:menu].selected?(item.id)&lt;br /&gt;
  long_name = item.name.split(/\W/).collect{|word| word.capitalize}.join(' ')&lt;br /&gt;
%&amp;gt;&lt;br /&gt;
&amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown first-level&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% elsif level == 2 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown-submenu&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% else %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;lt;%= URI.encode(&amp;quot;/menu/#{item.name}&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;%= if item.children&lt;br /&gt;
        ' class=&amp;quot;daddy&amp;quot;'&lt;br /&gt;
      end %&amp;gt;title='&amp;lt;%= long_name %&amp;gt;'&amp;gt;&amp;lt;%= item.label.html_safe %&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
    &amp;lt;% if item.children -%&amp;gt;&lt;br /&gt;
    &amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu multi-level&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
    &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
      &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
    &amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Please also refer to app/assets/application.css.scss for further details.&lt;br /&gt;
&lt;br /&gt;
== Manage-course page ==&lt;br /&gt;
=== Design ===&lt;br /&gt;
After logging in, only the table frame is loaded into the page by rails. Then AngularJS takes over in the background and populate the content into the table. After all first-level content is populated into the table, in this case, all courses info belongs to the first level and their assignment is the second-level content.&lt;br /&gt;
&lt;br /&gt;
After all first level content is loaded into the table, the Angular controller starts to initialize POST request for second level content.&lt;br /&gt;
&lt;br /&gt;
In all, rendering the tree_display page is divided into 3 steps: &amp;lt;br&amp;gt;&lt;br /&gt;
1. render the table frame,  &amp;lt;br&amp;gt;&lt;br /&gt;
2. render the first level table content. &amp;lt;br&amp;gt;&lt;br /&gt;
3. fetch deeper level data. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the past, these 3 steps are done before rendering the page, which takes about 10-20 seconds. But now, it takes only 2-3 seconds to finish the first 2 steps, and 2 more seconds for the 3rd step.&lt;br /&gt;
&lt;br /&gt;
Moreover, the sorting and table record filtering is integrated into the table. No redirecting or re-rendering is needed for sorting or filtering, which was needed in the past.&lt;br /&gt;
&lt;br /&gt;
=== Code details ===&lt;br /&gt;
Pass Rails controller params to view in tree_display_controller#list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
angularParams = {}&lt;br /&gt;
angularParams[:search] = @search&lt;br /&gt;
angularParams[:show] = @show&lt;br /&gt;
angularParams[:child_nodes] = @child_nodes&lt;br /&gt;
angularParams[:sortvar] = @sortvar&lt;br /&gt;
angularParams[:sortorder] = @sortorder&lt;br /&gt;
angularParams[:user_id] = session[:user].id&lt;br /&gt;
angularParams[:nodeType] = 'FolderNode'&lt;br /&gt;
@angularParamsJSON = angularParams.to_json&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the view passes to AngularJS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-controller='TreeCtrl'&amp;gt;&lt;br /&gt;
&amp;lt;div ng-init=&amp;quot;init('&amp;lt;%= @angularParamsJSON %&amp;gt;')&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
AngularJS handles it, after all basic elements are loaded onto the page. Then AngularJS initializes a POST request for retrieving more data to populate the table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.angularParams = JSON.parse(value)&lt;br /&gt;
    $http.post('/tree_display/get_children_node_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.angularParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      $scope.tableContent = {}&lt;br /&gt;
      $scope.displayTableContent = {}&lt;br /&gt;
      $scope.lastLoadNum = {}&lt;br /&gt;
      $scope.typeList = []&lt;br /&gt;
      console.log data&lt;br /&gt;
      for nodeType, outerNode of data&lt;br /&gt;
        $scope.tableContent[nodeType] = []&lt;br /&gt;
        $scope.lastLoadNum[nodeType] = 0&lt;br /&gt;
        $scope.displayTableContent[nodeType] = []&lt;br /&gt;
        $scope.typeList.push nodeType&lt;br /&gt;
        # outerNode is the Assignments/Courses/Questionnaires&lt;br /&gt;
        for node in outerNode&lt;br /&gt;
          $scope.tableContent[nodeType].push node&lt;br /&gt;
          $scope.fetchCellContent(nodeType, node)&lt;br /&gt;
        $scope.getMoreContent(nodeType, 1)&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fetch table cell content recursively and put them into a hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.fetchCellContent = (nodeType, node) -&amp;gt;&lt;br /&gt;
    $scope.newParams = {}&lt;br /&gt;
    $scope.newParams[&amp;quot;sortvar&amp;quot;] = $scope.angularParams[&amp;quot;sortvar&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;sortorder&amp;quot;] = $scope.angularParams[&amp;quot;sortorder&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;search&amp;quot;] = $scope.angularParams[&amp;quot;search&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;show&amp;quot;] = $scope.angularParams[&amp;quot;show&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;user_id&amp;quot;] = $scope.angularParams[&amp;quot;user_id&amp;quot;]&lt;br /&gt;
    key = node.name + &amp;quot;|&amp;quot; + node.directory&lt;br /&gt;
    $scope.newParams[&amp;quot;key&amp;quot;] = key&lt;br /&gt;
    # console.log key&lt;br /&gt;
    if nodeType == 'Assignments'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'AssignmentNode'&lt;br /&gt;
    else if nodeType == 'Courses'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'CourseNode'&lt;br /&gt;
    else if nodeType == 'Questionnaires'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'FolderNode'&lt;br /&gt;
    else&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
    $scope.newParams[&amp;quot;child_nodes&amp;quot;] = node.nodeinfo&lt;br /&gt;
    $http.post('/tree_display/get_children_node_2_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.newParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      if data.length &amp;gt; 0&lt;br /&gt;
        for newNode in data&lt;br /&gt;
          if not $scope.allData[newNode.key]&lt;br /&gt;
            $scope.allData[newNode.key] = []&lt;br /&gt;
          $scope.display[newNode.key] = false&lt;br /&gt;
          $scope.allData[newNode.key].push newNode&lt;br /&gt;
          $scope.fetchCellContent(newNode.type, newNode)&lt;br /&gt;
&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After all data is fetched, the Rails view is able to presenting them onto the page!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;record in displayTableContent['Courses'] | filter:searchText | orderBy:predicate:reverse&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;tr ng-click=&amp;quot;showCellContent(record.name, record.directory)&amp;quot; class=&amp;quot;clickable-row&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
              &lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
          &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot; ng-if=&amp;quot;display[record.name+'|'+record.directory] &amp;amp;&amp;amp; allData[record.name+'|'+record.directory]&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;table class=&amp;quot;normal-table table table-bordered table-striped compact-table&amp;quot; ng-repeat=&amp;quot;cell in cellContent&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;tbody&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;: {{cell.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Directory&amp;lt;/b&amp;gt;: {{cell.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Creation Date&amp;lt;/b&amp;gt;: {{cell.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Modified Date&amp;lt;/b&amp;gt;: {{cell.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
              &amp;lt;/tbody&amp;gt;&lt;br /&gt;
            &amp;lt;/table&amp;gt;&lt;br /&gt;
          &amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
        &amp;lt;/tbody&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manage Users page ==&lt;br /&gt;
&lt;br /&gt;
===Design===&lt;br /&gt;
&lt;br /&gt;
Once logged in, choosing Manage/users option from the navbar, gets us routed to /users page which is defined in list.html.erb file. This file can be broken down to 5 constituents:&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users &amp;lt;br&amp;gt;&lt;br /&gt;
2) Paginating Users &amp;lt;br&amp;gt;&lt;br /&gt;
3) Searching Users &amp;lt;br&amp;gt;&lt;br /&gt;
4) Showing Users &amp;lt;br&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Details===&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users&lt;br /&gt;
Fetching users was challenging at first due to an extremely large number of user entries (total of 5300). Fetch of such large data produced a very long delay that was one of the major UX problems in legacy version of Expertiza. This problem has been solved with Angular by sending a post request that gets 300 users and then another post request which gets all the users. This approach provides a quick response and the first 300 users can be seen right away in the form of 3 pages (default set to 100 users per page). While the user is looking at the first couple of entries, the rest of the entries are fetched in the background. This allows for a fast response, full functionality as well as complete data.&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.getUsers = (fn) -&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    $http.post('/users/get_users_ng', {&lt;br /&gt;
      'fetchNumber': fn&lt;br /&gt;
    })&lt;br /&gt;
    .success((receivedUsers) -&amp;gt;&lt;br /&gt;
      console.log receivedUsers&lt;br /&gt;
      for user in receivedUsers&lt;br /&gt;
        $scope.users.push user&lt;br /&gt;
        $scope.user_display[user.object.id] = false&lt;br /&gt;
        $scope.editProfileVisible[user.object.id] = false&lt;br /&gt;
&lt;br /&gt;
      $scope.fetchNumber+=1&lt;br /&gt;
      console.log $scope.users.length&lt;br /&gt;
      console.log $scope.listSize&lt;br /&gt;
&lt;br /&gt;
      if $scope.users.length &amp;lt; $scope.listSize&lt;br /&gt;
        $scope.getUsers($scope.fetchNumber)&lt;br /&gt;
      )&lt;br /&gt;
&lt;br /&gt;
  $scope.getUserListSize = () -&amp;gt;&lt;br /&gt;
    $http.get('/users/get_users_list_ng')&lt;br /&gt;
    .success((listSize) -&amp;gt;&lt;br /&gt;
      $scope.listSize = listSize&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This process is initiated by init() command shown bellow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.user_display = {}&lt;br /&gt;
    $scope.editProfileVisible = {}&lt;br /&gt;
    if $scope.users.length == $scope.listSize&lt;br /&gt;
      return&lt;br /&gt;
    else if $scope.users.length == 0&lt;br /&gt;
      $scope.listSize = 0&lt;br /&gt;
      $scope.getUserListSize()&lt;br /&gt;
      $scope.fetchNumber = 0&lt;br /&gt;
    $scope.getUsers(($scope.fetchNumber))&lt;br /&gt;
    $scope.currentPage = 0&lt;br /&gt;
    $scope.pagination(50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The view resulting from this code structure can be seen bellow:&lt;br /&gt;
&lt;br /&gt;
[[File:list_users.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2) Paginating Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to paginate users, a filter needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The startFrom:currentPage*pageSize portion of the filter calls the custom filter startFrom which simply splits the data to display based on the current page of pagination (currentPage), multiplied by the number of users to display (pageSize, which is set by the user selecting either All, 25, 50, 100, or 250).&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app.filter 'startFrom', -&amp;gt;&lt;br /&gt;
  (input, start) -&amp;gt;&lt;br /&gt;
    start = +start&lt;br /&gt;
    return input.slice start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The limitTo:pageSize is a built in angular filter that says to stop displaying users after pageSize of them have been displayed.&lt;br /&gt;
&lt;br /&gt;
The aforementioned pageSize is set by the user through a dropdown; This code tells the dropdown to set the default paginate value to 100 users per page, and upon an ng-change (user selecting a different value), the pagination method will be called in app.coffee, with the appropriate pageSize:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;label&amp;gt;Paginate By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;paginate&amp;quot; ng-init=&amp;quot;paginate='50'&amp;quot; ng-change=&amp;quot;pagination(paginate)&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;All&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;25&amp;quot;&amp;gt;25&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;50&amp;quot;&amp;gt;50&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;100&amp;quot;&amp;gt;100&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;250&amp;quot;&amp;gt;250&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in app.coffee, and it posts the pageSize to the set_page_size method in the users_controller, and then sets various variable values based on the results:&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.pagination = (ps) -&amp;gt;&lt;br /&gt;
    $http.post('/users/set_page_size', {&lt;br /&gt;
      'pageSize': ps&lt;br /&gt;
    })&lt;br /&gt;
    .success((value) -&amp;gt;&lt;br /&gt;
      $scope.pageSize = value[0]&lt;br /&gt;
      $scope.div = value[1]&lt;br /&gt;
      $scope.totalSize = value[2]&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in users_controller and it takes in the user defined pageSize variable and then determines how many pages are required to divide the data into based off of the pageSize, then returns that variable, plus others:&lt;br /&gt;
&lt;br /&gt;
In app/controllers/user_controller:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def set_page_size&lt;br /&gt;
    ps = params[:pageSize].to_i&lt;br /&gt;
    user = session[:user]&lt;br /&gt;
    role = Role.find(user.role_id)&lt;br /&gt;
    all_users = User.order('name').where( ['role_id in (?) or id = ?', role.get_available_roles, user.id])&lt;br /&gt;
    users_length = all_users.length&lt;br /&gt;
    if ps == 0&lt;br /&gt;
      pageSize = users_length&lt;br /&gt;
    else&lt;br /&gt;
      pageSize = ps&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    div = (users_length/pageSize.to_f).ceil&lt;br /&gt;
    &lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: [pageSize, div, users_length]}&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once the number of pages and pageSize has been set, those numbers are then used to show the current and remaining pages to go along with the previous and next buttons:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;paginate-button&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-left&amp;quot; ng-disabled=&amp;quot;currentPage == 0&amp;quot; ng-click=&amp;quot;currentPage=currentPage-1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
  {{currentPage+1}}/{{div}}&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-right&amp;quot; ng-disabled=&amp;quot;currentPage &amp;gt;= totalSize/pageSize - 1&amp;quot; ng-click=&amp;quot;currentPage=currentPage+1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
 &amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) Searching Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to search users, a filter also needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The filter:search portion of this code simply applies the following filter criteria; the type of search is determined a dropdown (either search by any field, name, fullname, or email fields). Based on the dropdown selection, the correct search box will be shown, once that search box is show, the search criteria is set to correspond to the type of search specified by the dropdown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;pull-right form-group&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;form-inline&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label&amp;gt;Search By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;searchtype&amp;quot; ng-init=&amp;quot;searchtype='any'&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;any&amp;quot;&amp;gt;Any&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;name&amp;quot;&amp;gt;Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;fullname&amp;quot;&amp;gt;Full Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;email&amp;quot;&amp;gt;Email&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
  &amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'any'&amp;quot; ng-model=&amp;quot;search.object.$&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'name'&amp;quot; ng-model=&amp;quot;search.object.name&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'fullname'&amp;quot; ng-model=&amp;quot;search.object.fullname&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'email'&amp;quot; ng-model=&amp;quot;search.object.email&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) Showing Users&lt;br /&gt;
Clicking on each user name in the table of users uncovers a template that shows the information about that specific user. This is accomplished in a very simple way by setting the profileVisible flag to true. The information about that specific user is extracted from displayedUser object provided by showUser() method from UsersPageCtrl controller in app.coffee file.&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-if=&amp;quot;profileVisible == true&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h1&amp;gt;&amp;lt;b&amp;gt;User: {{displayedUser.object.name}}&amp;lt;/b&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Full Name: &amp;lt;/b&amp;gt;{{displayedUser.object.fullname}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Email Address: &amp;lt;/b&amp;gt;{{displayedUser.object.email}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Role: &amp;lt;/b&amp;gt;{{displayedUser.role}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;showTable(true)&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-primary&amp;quot;&amp;gt;Back&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;editUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-success&amp;quot;&amp;gt;Edit&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;deleteUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-danger&amp;quot;&amp;gt;Delete&amp;lt;/button&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.showUser = (user_id) -&amp;gt;&lt;br /&gt;
    $scope.user_display[user_id] = !$scope.user_display[user_id]&lt;br /&gt;
    $scope.editProfileVisible[user_id] = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see in the screenshot bellow, as an example, user 6 has been selected and now the editing information about this user is visible.&lt;br /&gt;
&lt;br /&gt;
[[File:select_user.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5) Editing and Deleting Users&lt;br /&gt;
&lt;br /&gt;
Editing Users is implemented in a similar way as showing users. The template contains ng-if statement which allows us to display edit page for each user. editUser() method from UsersPageCtrl controller specified in app.coffee displays information of the displayedUser but only after the Save button is clicked it saves the information from displayedUsers into updatedUser variable. POST request with :id parameter is then sent to update method in users_controller of Rails, which then updates this user information in the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.editUser = (user) -&amp;gt;&lt;br /&gt;
    # $scope.showUser(false)&lt;br /&gt;
    $scope.editProfileVisible[user.object.id] = !$scope.editProfileVisible[user.object.id]&lt;br /&gt;
    $scope.updatedUser = user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above allows us to set the edit form visible. Bellow, you will find an example screenshot of this feature.&lt;br /&gt;
&lt;br /&gt;
[[File:edit_user.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Resources=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Github link:&amp;lt;/b&amp;gt; https://github.com/CSC517-FInalProject/expertiza/tree/pei-final &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Wiki link:&amp;lt;/b&amp;gt; http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2015_E1526_MPRI  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Project Demo:&amp;lt;/b&amp;gt; https://youtu.be/qsHYE9Rgx80   &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97091</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97091"/>
		<updated>2015-05-04T06:33:01Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Resources */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Guide for future students =&lt;br /&gt;
1. Learn how to integrate AngularJS into Rails, using Rails original routing system.&lt;br /&gt;
&lt;br /&gt;
2. Learn AngularJS and Coffeescript, since the app.js is written in Coffeescript now.&lt;br /&gt;
&lt;br /&gt;
3. Learn Bootstrap, including the grid system, responsive design and etc.&lt;br /&gt;
&lt;br /&gt;
4. Read the code written by us, to know &lt;br /&gt;
&lt;br /&gt;
    a. how to pass data from Rails controller and view to AngularJS; &lt;br /&gt;
    b. how to pass data back to Rails view from AngularJS; &lt;br /&gt;
    c. how to convert JSON formatted data using in AngularJS to Rails hash and vice versa.&lt;br /&gt;
    d. how to present the data to Rails view&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD the following content to the config/application.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js&lt;br /&gt;
&lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;code&amp;gt; div ng-app='MPApp'&amp;lt;/code&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;br /&gt;
&lt;br /&gt;
=The specifics=&lt;br /&gt;
This section explains the very detailed actions and their results related to the 3 specific pages that were used to integrate AngularJS. Numerous snapshots are provided with the goal to make our approach very clear.&lt;br /&gt;
&lt;br /&gt;
== Login Page and Navigation Bar ==&lt;br /&gt;
Login procedure:&lt;br /&gt;
‘Login’ button clicked → auth_controller#login → auth_controller#after_login(user) → if user.role != ‘student’ → tree_display#drill → tree_display#list&amp;lt;br/&amp;gt;&lt;br /&gt;
If session[:menu] is defined, that is, when a user is logging in, the page will render the content of variable session[:menu].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
       &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
          :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
     &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
         :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
 &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each menu item in the nav bar, it is a dropdown menu now. For different level of dropdown menu, we apply different CSS style to it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% level += 1 %&amp;gt;&lt;br /&gt;
&amp;lt;% items.each do |item_id|&lt;br /&gt;
  item = session[:menu].get_item(item_id)&lt;br /&gt;
  selected = session[:menu].selected?(item.id)&lt;br /&gt;
  long_name = item.name.split(/\W/).collect{|word| word.capitalize}.join(' ')&lt;br /&gt;
%&amp;gt;&lt;br /&gt;
&amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown first-level&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% elsif level == 2 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown-submenu&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% else %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;lt;%= URI.encode(&amp;quot;/menu/#{item.name}&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;%= if item.children&lt;br /&gt;
        ' class=&amp;quot;daddy&amp;quot;'&lt;br /&gt;
      end %&amp;gt;title='&amp;lt;%= long_name %&amp;gt;'&amp;gt;&amp;lt;%= item.label.html_safe %&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
    &amp;lt;% if item.children -%&amp;gt;&lt;br /&gt;
    &amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu multi-level&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
    &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
      &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
    &amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Please also refer to app/assets/application.css.scss for further details.&lt;br /&gt;
&lt;br /&gt;
== Manage-course page ==&lt;br /&gt;
=== Design ===&lt;br /&gt;
After logging in, only the table frame is loaded into the page by rails. Then AngularJS takes over in the background and populate the content into the table. After all first-level content is populated into the table, in this case, all courses info belongs to the first level and their assignment is the second-level content.&lt;br /&gt;
&lt;br /&gt;
After all first level content is loaded into the table, the Angular controller starts to initialize POST request for second level content.&lt;br /&gt;
&lt;br /&gt;
In all, rendering the tree_display page is divided into 3 steps: &amp;lt;br&amp;gt;&lt;br /&gt;
1. render the table frame,  &amp;lt;br&amp;gt;&lt;br /&gt;
2. render the first level table content. &amp;lt;br&amp;gt;&lt;br /&gt;
3. fetch deeper level data. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the past, these 3 steps are done before rendering the page, which takes about 10-20 seconds. But now, it takes only 2-3 seconds to finish the first 2 steps, and 2 more seconds for the 3rd step.&lt;br /&gt;
&lt;br /&gt;
Moreover, the sorting and table record filtering is integrated into the table. No redirecting or re-rendering is needed for sorting or filtering, which was needed in the past.&lt;br /&gt;
&lt;br /&gt;
=== Code details ===&lt;br /&gt;
Pass Rails controller params to view in tree_display_controller#list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
angularParams = {}&lt;br /&gt;
angularParams[:search] = @search&lt;br /&gt;
angularParams[:show] = @show&lt;br /&gt;
angularParams[:child_nodes] = @child_nodes&lt;br /&gt;
angularParams[:sortvar] = @sortvar&lt;br /&gt;
angularParams[:sortorder] = @sortorder&lt;br /&gt;
angularParams[:user_id] = session[:user].id&lt;br /&gt;
angularParams[:nodeType] = 'FolderNode'&lt;br /&gt;
@angularParamsJSON = angularParams.to_json&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the view passes to AngularJS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-controller='TreeCtrl'&amp;gt;&lt;br /&gt;
&amp;lt;div ng-init=&amp;quot;init('&amp;lt;%= @angularParamsJSON %&amp;gt;')&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
AngularJS handles it, after all basic elements are loaded onto the page. Then AngularJS initializes a POST request for retrieving more data to populate the table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.angularParams = JSON.parse(value)&lt;br /&gt;
    $http.post('/tree_display/get_children_node_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.angularParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      $scope.tableContent = {}&lt;br /&gt;
      $scope.displayTableContent = {}&lt;br /&gt;
      $scope.lastLoadNum = {}&lt;br /&gt;
      $scope.typeList = []&lt;br /&gt;
      console.log data&lt;br /&gt;
      for nodeType, outerNode of data&lt;br /&gt;
        $scope.tableContent[nodeType] = []&lt;br /&gt;
        $scope.lastLoadNum[nodeType] = 0&lt;br /&gt;
        $scope.displayTableContent[nodeType] = []&lt;br /&gt;
        $scope.typeList.push nodeType&lt;br /&gt;
        # outerNode is the Assignments/Courses/Questionnaires&lt;br /&gt;
        for node in outerNode&lt;br /&gt;
          $scope.tableContent[nodeType].push node&lt;br /&gt;
          $scope.fetchCellContent(nodeType, node)&lt;br /&gt;
        $scope.getMoreContent(nodeType, 1)&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fetch table cell content recursively and put them into a hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.fetchCellContent = (nodeType, node) -&amp;gt;&lt;br /&gt;
    $scope.newParams = {}&lt;br /&gt;
    $scope.newParams[&amp;quot;sortvar&amp;quot;] = $scope.angularParams[&amp;quot;sortvar&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;sortorder&amp;quot;] = $scope.angularParams[&amp;quot;sortorder&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;search&amp;quot;] = $scope.angularParams[&amp;quot;search&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;show&amp;quot;] = $scope.angularParams[&amp;quot;show&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;user_id&amp;quot;] = $scope.angularParams[&amp;quot;user_id&amp;quot;]&lt;br /&gt;
    key = node.name + &amp;quot;|&amp;quot; + node.directory&lt;br /&gt;
    $scope.newParams[&amp;quot;key&amp;quot;] = key&lt;br /&gt;
    # console.log key&lt;br /&gt;
    if nodeType == 'Assignments'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'AssignmentNode'&lt;br /&gt;
    else if nodeType == 'Courses'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'CourseNode'&lt;br /&gt;
    else if nodeType == 'Questionnaires'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'FolderNode'&lt;br /&gt;
    else&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
    $scope.newParams[&amp;quot;child_nodes&amp;quot;] = node.nodeinfo&lt;br /&gt;
    $http.post('/tree_display/get_children_node_2_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.newParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      if data.length &amp;gt; 0&lt;br /&gt;
        for newNode in data&lt;br /&gt;
          if not $scope.allData[newNode.key]&lt;br /&gt;
            $scope.allData[newNode.key] = []&lt;br /&gt;
          $scope.display[newNode.key] = false&lt;br /&gt;
          $scope.allData[newNode.key].push newNode&lt;br /&gt;
          $scope.fetchCellContent(newNode.type, newNode)&lt;br /&gt;
&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After all data is fetched, the Rails view is able to presenting them onto the page!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;record in displayTableContent['Courses'] | filter:searchText | orderBy:predicate:reverse&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;tr ng-click=&amp;quot;showCellContent(record.name, record.directory)&amp;quot; class=&amp;quot;clickable-row&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
              &lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
          &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot; ng-if=&amp;quot;display[record.name+'|'+record.directory] &amp;amp;&amp;amp; allData[record.name+'|'+record.directory]&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;table class=&amp;quot;normal-table table table-bordered table-striped compact-table&amp;quot; ng-repeat=&amp;quot;cell in cellContent&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;tbody&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;: {{cell.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Directory&amp;lt;/b&amp;gt;: {{cell.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Creation Date&amp;lt;/b&amp;gt;: {{cell.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Modified Date&amp;lt;/b&amp;gt;: {{cell.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
              &amp;lt;/tbody&amp;gt;&lt;br /&gt;
            &amp;lt;/table&amp;gt;&lt;br /&gt;
          &amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
        &amp;lt;/tbody&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manage Users page ==&lt;br /&gt;
&lt;br /&gt;
===Design===&lt;br /&gt;
&lt;br /&gt;
Once logged in, choosing Manage/users option from the navbar, gets us routed to /users page which is defined in list.html.erb file. This file can be broken down to 5 constituents:&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users &amp;lt;br&amp;gt;&lt;br /&gt;
2) Paginating Users &amp;lt;br&amp;gt;&lt;br /&gt;
3) Searching Users &amp;lt;br&amp;gt;&lt;br /&gt;
4) Showing Users &amp;lt;br&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Details===&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users&lt;br /&gt;
Fetching users was challenging at first due to an extremely large number of user entries (total of 5300). Fetch of such large data produced a very long delay that was one of the major UX problems in legacy version of Expertiza. This problem has been solved with Angular by sending a post request that gets 300 users and then another post request which gets all the users. This approach provides a quick response and the first 300 users can be seen right away in the form of 3 pages (default set to 100 users per page). While the user is looking at the first couple of entries, the rest of the entries are fetched in the background. This allows for a fast response, full functionality as well as complete data.&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.getUsers = (fn) -&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    $http.post('/users/get_users_ng', {&lt;br /&gt;
      'fetchNumber': fn&lt;br /&gt;
    })&lt;br /&gt;
    .success((receivedUsers) -&amp;gt;&lt;br /&gt;
      console.log receivedUsers&lt;br /&gt;
      for user in receivedUsers&lt;br /&gt;
        $scope.users.push user&lt;br /&gt;
        $scope.user_display[user.object.id] = false&lt;br /&gt;
        $scope.editProfileVisible[user.object.id] = false&lt;br /&gt;
&lt;br /&gt;
      $scope.fetchNumber+=1&lt;br /&gt;
      console.log $scope.users.length&lt;br /&gt;
      console.log $scope.listSize&lt;br /&gt;
&lt;br /&gt;
      if $scope.users.length &amp;lt; $scope.listSize&lt;br /&gt;
        $scope.getUsers($scope.fetchNumber)&lt;br /&gt;
      )&lt;br /&gt;
&lt;br /&gt;
  $scope.getUserListSize = () -&amp;gt;&lt;br /&gt;
    $http.get('/users/get_users_list_ng')&lt;br /&gt;
    .success((listSize) -&amp;gt;&lt;br /&gt;
      $scope.listSize = listSize&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This process is initiated by init() command shown bellow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.user_display = {}&lt;br /&gt;
    $scope.editProfileVisible = {}&lt;br /&gt;
    if $scope.users.length == $scope.listSize&lt;br /&gt;
      return&lt;br /&gt;
    else if $scope.users.length == 0&lt;br /&gt;
      $scope.listSize = 0&lt;br /&gt;
      $scope.getUserListSize()&lt;br /&gt;
      $scope.fetchNumber = 0&lt;br /&gt;
    $scope.getUsers(($scope.fetchNumber))&lt;br /&gt;
    $scope.currentPage = 0&lt;br /&gt;
    $scope.pagination(50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The view resulting from this code structure can be seen bellow:&lt;br /&gt;
&lt;br /&gt;
[[File:list_users.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2) Paginating Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to paginate users, a filter needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The startFrom:currentPage*pageSize portion of the filter calls the custom filter startFrom which simply splits the data to display based on the current page of pagination (currentPage), multiplied by the number of users to display (pageSize, which is set by the user selecting either All, 25, 50, 100, or 250).&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app.filter 'startFrom', -&amp;gt;&lt;br /&gt;
  (input, start) -&amp;gt;&lt;br /&gt;
    start = +start&lt;br /&gt;
    return input.slice start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The limitTo:pageSize is a built in angular filter that says to stop displaying users after pageSize of them have been displayed.&lt;br /&gt;
&lt;br /&gt;
The aforementioned pageSize is set by the user through a dropdown; This code tells the dropdown to set the default paginate value to 100 users per page, and upon an ng-change (user selecting a different value), the pagination method will be called in app.coffee, with the appropriate pageSize:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;label&amp;gt;Paginate By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;paginate&amp;quot; ng-init=&amp;quot;paginate='50'&amp;quot; ng-change=&amp;quot;pagination(paginate)&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;All&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;25&amp;quot;&amp;gt;25&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;50&amp;quot;&amp;gt;50&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;100&amp;quot;&amp;gt;100&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;250&amp;quot;&amp;gt;250&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in app.coffee, and it posts the pageSize to the set_page_size method in the users_controller, and then sets various variable values based on the results:&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.pagination = (ps) -&amp;gt;&lt;br /&gt;
    $http.post('/users/set_page_size', {&lt;br /&gt;
      'pageSize': ps&lt;br /&gt;
    })&lt;br /&gt;
    .success((value) -&amp;gt;&lt;br /&gt;
      $scope.pageSize = value[0]&lt;br /&gt;
      $scope.div = value[1]&lt;br /&gt;
      $scope.totalSize = value[2]&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in users_controller and it takes in the user defined pageSize variable and then determines how many pages are required to divide the data into based off of the pageSize, then returns that variable, plus others:&lt;br /&gt;
&lt;br /&gt;
In app/controllers/user_controller:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def set_page_size&lt;br /&gt;
    ps = params[:pageSize].to_i&lt;br /&gt;
    user = session[:user]&lt;br /&gt;
    role = Role.find(user.role_id)&lt;br /&gt;
    all_users = User.order('name').where( ['role_id in (?) or id = ?', role.get_available_roles, user.id])&lt;br /&gt;
    users_length = all_users.length&lt;br /&gt;
    if ps == 0&lt;br /&gt;
      pageSize = users_length&lt;br /&gt;
    else&lt;br /&gt;
      pageSize = ps&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    div = (users_length/pageSize.to_f).ceil&lt;br /&gt;
    &lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: [pageSize, div, users_length]}&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once the number of pages and pageSize has been set, those numbers are then used to show the current and remaining pages to go along with the previous and next buttons:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;paginate-button&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-left&amp;quot; ng-disabled=&amp;quot;currentPage == 0&amp;quot; ng-click=&amp;quot;currentPage=currentPage-1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
  {{currentPage+1}}/{{div}}&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-right&amp;quot; ng-disabled=&amp;quot;currentPage &amp;gt;= totalSize/pageSize - 1&amp;quot; ng-click=&amp;quot;currentPage=currentPage+1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
 &amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) Searching Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to search users, a filter also needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The filter:search portion of this code simply applies the following filter criteria; the type of search is determined a dropdown (either search by any field, name, fullname, or email fields). Based on the dropdown selection, the correct search box will be shown, once that search box is show, the search criteria is set to correspond to the type of search specified by the dropdown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;pull-right form-group&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;form-inline&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label&amp;gt;Search By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;searchtype&amp;quot; ng-init=&amp;quot;searchtype='any'&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;any&amp;quot;&amp;gt;Any&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;name&amp;quot;&amp;gt;Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;fullname&amp;quot;&amp;gt;Full Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;email&amp;quot;&amp;gt;Email&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
  &amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'any'&amp;quot; ng-model=&amp;quot;search.object.$&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'name'&amp;quot; ng-model=&amp;quot;search.object.name&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'fullname'&amp;quot; ng-model=&amp;quot;search.object.fullname&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'email'&amp;quot; ng-model=&amp;quot;search.object.email&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) Showing Users&lt;br /&gt;
Clicking on each user name in the table of users uncovers a template that shows the information about that specific user. This is accomplished in a very simple way by setting the profileVisible flag to true. The information about that specific user is extracted from displayedUser object provided by showUser() method from UsersPageCtrl controller in app.coffee file.&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-if=&amp;quot;profileVisible == true&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h1&amp;gt;&amp;lt;b&amp;gt;User: {{displayedUser.object.name}}&amp;lt;/b&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Full Name: &amp;lt;/b&amp;gt;{{displayedUser.object.fullname}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Email Address: &amp;lt;/b&amp;gt;{{displayedUser.object.email}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Role: &amp;lt;/b&amp;gt;{{displayedUser.role}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;showTable(true)&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-primary&amp;quot;&amp;gt;Back&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;editUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-success&amp;quot;&amp;gt;Edit&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;deleteUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-danger&amp;quot;&amp;gt;Delete&amp;lt;/button&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.showUser = (user_id) -&amp;gt;&lt;br /&gt;
    $scope.user_display[user_id] = !$scope.user_display[user_id]&lt;br /&gt;
    $scope.editProfileVisible[user_id] = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see in the screenshot bellow, as an example, user 6 has been selected and now the editing information about this user is visible.&lt;br /&gt;
&lt;br /&gt;
[[File:select_user.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5) Editing and Deleting Users&lt;br /&gt;
&lt;br /&gt;
Editing Users is implemented in a similar way as showing users. The template contains ng-if statement which allows us to display edit page for each user. editUser() method from UsersPageCtrl controller specified in app.coffee displays information of the displayedUser but only after the Save button is clicked it saves the information from displayedUsers into updatedUser variable. POST request with :id parameter is then sent to update method in users_controller of Rails, which then updates this user information in the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.editUser = (user) -&amp;gt;&lt;br /&gt;
    # $scope.showUser(false)&lt;br /&gt;
    $scope.editProfileVisible[user.object.id] = !$scope.editProfileVisible[user.object.id]&lt;br /&gt;
    $scope.updatedUser = user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above allows us to set the edit form visible. Bellow, you will find an example screenshot of this feature.&lt;br /&gt;
&lt;br /&gt;
[[File:edit_user.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Resources=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Github link:&amp;lt;/b&amp;gt; &amp;lt;href https://github.com/CSC517-FInalProject/expertiza/tree/pei-final&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Wiki link: &amp;lt;/b&amp;gt; &amp;lt;href http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2015_E1526_MPRI&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Project Demo:&amp;lt;/b&amp;gt; &amp;lt;href https://youtu.be/qsHYE9Rgx80 &amp;gt;  &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97090</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97090"/>
		<updated>2015-05-04T06:31:39Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Guide for future students =&lt;br /&gt;
1. Learn how to integrate AngularJS into Rails, using Rails original routing system.&lt;br /&gt;
&lt;br /&gt;
2. Learn AngularJS and Coffeescript, since the app.js is written in Coffeescript now.&lt;br /&gt;
&lt;br /&gt;
3. Learn Bootstrap, including the grid system, responsive design and etc.&lt;br /&gt;
&lt;br /&gt;
4. Read the code written by us, to know &lt;br /&gt;
&lt;br /&gt;
    a. how to pass data from Rails controller and view to AngularJS; &lt;br /&gt;
    b. how to pass data back to Rails view from AngularJS; &lt;br /&gt;
    c. how to convert JSON formatted data using in AngularJS to Rails hash and vice versa.&lt;br /&gt;
    d. how to present the data to Rails view&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD the following content to the config/application.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js&lt;br /&gt;
&lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;code&amp;gt; div ng-app='MPApp'&amp;lt;/code&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;br /&gt;
&lt;br /&gt;
=The specifics=&lt;br /&gt;
This section explains the very detailed actions and their results related to the 3 specific pages that were used to integrate AngularJS. Numerous snapshots are provided with the goal to make our approach very clear.&lt;br /&gt;
&lt;br /&gt;
== Login Page and Navigation Bar ==&lt;br /&gt;
Login procedure:&lt;br /&gt;
‘Login’ button clicked → auth_controller#login → auth_controller#after_login(user) → if user.role != ‘student’ → tree_display#drill → tree_display#list&amp;lt;br/&amp;gt;&lt;br /&gt;
If session[:menu] is defined, that is, when a user is logging in, the page will render the content of variable session[:menu].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
       &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
          :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
     &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
         :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
 &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each menu item in the nav bar, it is a dropdown menu now. For different level of dropdown menu, we apply different CSS style to it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% level += 1 %&amp;gt;&lt;br /&gt;
&amp;lt;% items.each do |item_id|&lt;br /&gt;
  item = session[:menu].get_item(item_id)&lt;br /&gt;
  selected = session[:menu].selected?(item.id)&lt;br /&gt;
  long_name = item.name.split(/\W/).collect{|word| word.capitalize}.join(' ')&lt;br /&gt;
%&amp;gt;&lt;br /&gt;
&amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown first-level&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% elsif level == 2 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown-submenu&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% else %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;lt;%= URI.encode(&amp;quot;/menu/#{item.name}&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;%= if item.children&lt;br /&gt;
        ' class=&amp;quot;daddy&amp;quot;'&lt;br /&gt;
      end %&amp;gt;title='&amp;lt;%= long_name %&amp;gt;'&amp;gt;&amp;lt;%= item.label.html_safe %&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
    &amp;lt;% if item.children -%&amp;gt;&lt;br /&gt;
    &amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu multi-level&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
    &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
      &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
    &amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Please also refer to app/assets/application.css.scss for further details.&lt;br /&gt;
&lt;br /&gt;
== Manage-course page ==&lt;br /&gt;
=== Design ===&lt;br /&gt;
After logging in, only the table frame is loaded into the page by rails. Then AngularJS takes over in the background and populate the content into the table. After all first-level content is populated into the table, in this case, all courses info belongs to the first level and their assignment is the second-level content.&lt;br /&gt;
&lt;br /&gt;
After all first level content is loaded into the table, the Angular controller starts to initialize POST request for second level content.&lt;br /&gt;
&lt;br /&gt;
In all, rendering the tree_display page is divided into 3 steps: &amp;lt;br&amp;gt;&lt;br /&gt;
1. render the table frame,  &amp;lt;br&amp;gt;&lt;br /&gt;
2. render the first level table content. &amp;lt;br&amp;gt;&lt;br /&gt;
3. fetch deeper level data. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the past, these 3 steps are done before rendering the page, which takes about 10-20 seconds. But now, it takes only 2-3 seconds to finish the first 2 steps, and 2 more seconds for the 3rd step.&lt;br /&gt;
&lt;br /&gt;
Moreover, the sorting and table record filtering is integrated into the table. No redirecting or re-rendering is needed for sorting or filtering, which was needed in the past.&lt;br /&gt;
&lt;br /&gt;
=== Code details ===&lt;br /&gt;
Pass Rails controller params to view in tree_display_controller#list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
angularParams = {}&lt;br /&gt;
angularParams[:search] = @search&lt;br /&gt;
angularParams[:show] = @show&lt;br /&gt;
angularParams[:child_nodes] = @child_nodes&lt;br /&gt;
angularParams[:sortvar] = @sortvar&lt;br /&gt;
angularParams[:sortorder] = @sortorder&lt;br /&gt;
angularParams[:user_id] = session[:user].id&lt;br /&gt;
angularParams[:nodeType] = 'FolderNode'&lt;br /&gt;
@angularParamsJSON = angularParams.to_json&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the view passes to AngularJS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-controller='TreeCtrl'&amp;gt;&lt;br /&gt;
&amp;lt;div ng-init=&amp;quot;init('&amp;lt;%= @angularParamsJSON %&amp;gt;')&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
AngularJS handles it, after all basic elements are loaded onto the page. Then AngularJS initializes a POST request for retrieving more data to populate the table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.angularParams = JSON.parse(value)&lt;br /&gt;
    $http.post('/tree_display/get_children_node_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.angularParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      $scope.tableContent = {}&lt;br /&gt;
      $scope.displayTableContent = {}&lt;br /&gt;
      $scope.lastLoadNum = {}&lt;br /&gt;
      $scope.typeList = []&lt;br /&gt;
      console.log data&lt;br /&gt;
      for nodeType, outerNode of data&lt;br /&gt;
        $scope.tableContent[nodeType] = []&lt;br /&gt;
        $scope.lastLoadNum[nodeType] = 0&lt;br /&gt;
        $scope.displayTableContent[nodeType] = []&lt;br /&gt;
        $scope.typeList.push nodeType&lt;br /&gt;
        # outerNode is the Assignments/Courses/Questionnaires&lt;br /&gt;
        for node in outerNode&lt;br /&gt;
          $scope.tableContent[nodeType].push node&lt;br /&gt;
          $scope.fetchCellContent(nodeType, node)&lt;br /&gt;
        $scope.getMoreContent(nodeType, 1)&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fetch table cell content recursively and put them into a hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.fetchCellContent = (nodeType, node) -&amp;gt;&lt;br /&gt;
    $scope.newParams = {}&lt;br /&gt;
    $scope.newParams[&amp;quot;sortvar&amp;quot;] = $scope.angularParams[&amp;quot;sortvar&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;sortorder&amp;quot;] = $scope.angularParams[&amp;quot;sortorder&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;search&amp;quot;] = $scope.angularParams[&amp;quot;search&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;show&amp;quot;] = $scope.angularParams[&amp;quot;show&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;user_id&amp;quot;] = $scope.angularParams[&amp;quot;user_id&amp;quot;]&lt;br /&gt;
    key = node.name + &amp;quot;|&amp;quot; + node.directory&lt;br /&gt;
    $scope.newParams[&amp;quot;key&amp;quot;] = key&lt;br /&gt;
    # console.log key&lt;br /&gt;
    if nodeType == 'Assignments'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'AssignmentNode'&lt;br /&gt;
    else if nodeType == 'Courses'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'CourseNode'&lt;br /&gt;
    else if nodeType == 'Questionnaires'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'FolderNode'&lt;br /&gt;
    else&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
    $scope.newParams[&amp;quot;child_nodes&amp;quot;] = node.nodeinfo&lt;br /&gt;
    $http.post('/tree_display/get_children_node_2_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.newParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      if data.length &amp;gt; 0&lt;br /&gt;
        for newNode in data&lt;br /&gt;
          if not $scope.allData[newNode.key]&lt;br /&gt;
            $scope.allData[newNode.key] = []&lt;br /&gt;
          $scope.display[newNode.key] = false&lt;br /&gt;
          $scope.allData[newNode.key].push newNode&lt;br /&gt;
          $scope.fetchCellContent(newNode.type, newNode)&lt;br /&gt;
&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After all data is fetched, the Rails view is able to presenting them onto the page!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;record in displayTableContent['Courses'] | filter:searchText | orderBy:predicate:reverse&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;tr ng-click=&amp;quot;showCellContent(record.name, record.directory)&amp;quot; class=&amp;quot;clickable-row&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
              &lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
          &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot; ng-if=&amp;quot;display[record.name+'|'+record.directory] &amp;amp;&amp;amp; allData[record.name+'|'+record.directory]&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;table class=&amp;quot;normal-table table table-bordered table-striped compact-table&amp;quot; ng-repeat=&amp;quot;cell in cellContent&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;tbody&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;: {{cell.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Directory&amp;lt;/b&amp;gt;: {{cell.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Creation Date&amp;lt;/b&amp;gt;: {{cell.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Modified Date&amp;lt;/b&amp;gt;: {{cell.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
              &amp;lt;/tbody&amp;gt;&lt;br /&gt;
            &amp;lt;/table&amp;gt;&lt;br /&gt;
          &amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
        &amp;lt;/tbody&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manage Users page ==&lt;br /&gt;
&lt;br /&gt;
===Design===&lt;br /&gt;
&lt;br /&gt;
Once logged in, choosing Manage/users option from the navbar, gets us routed to /users page which is defined in list.html.erb file. This file can be broken down to 5 constituents:&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users &amp;lt;br&amp;gt;&lt;br /&gt;
2) Paginating Users &amp;lt;br&amp;gt;&lt;br /&gt;
3) Searching Users &amp;lt;br&amp;gt;&lt;br /&gt;
4) Showing Users &amp;lt;br&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Details===&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users&lt;br /&gt;
Fetching users was challenging at first due to an extremely large number of user entries (total of 5300). Fetch of such large data produced a very long delay that was one of the major UX problems in legacy version of Expertiza. This problem has been solved with Angular by sending a post request that gets 300 users and then another post request which gets all the users. This approach provides a quick response and the first 300 users can be seen right away in the form of 3 pages (default set to 100 users per page). While the user is looking at the first couple of entries, the rest of the entries are fetched in the background. This allows for a fast response, full functionality as well as complete data.&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.getUsers = (fn) -&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    $http.post('/users/get_users_ng', {&lt;br /&gt;
      'fetchNumber': fn&lt;br /&gt;
    })&lt;br /&gt;
    .success((receivedUsers) -&amp;gt;&lt;br /&gt;
      console.log receivedUsers&lt;br /&gt;
      for user in receivedUsers&lt;br /&gt;
        $scope.users.push user&lt;br /&gt;
        $scope.user_display[user.object.id] = false&lt;br /&gt;
        $scope.editProfileVisible[user.object.id] = false&lt;br /&gt;
&lt;br /&gt;
      $scope.fetchNumber+=1&lt;br /&gt;
      console.log $scope.users.length&lt;br /&gt;
      console.log $scope.listSize&lt;br /&gt;
&lt;br /&gt;
      if $scope.users.length &amp;lt; $scope.listSize&lt;br /&gt;
        $scope.getUsers($scope.fetchNumber)&lt;br /&gt;
      )&lt;br /&gt;
&lt;br /&gt;
  $scope.getUserListSize = () -&amp;gt;&lt;br /&gt;
    $http.get('/users/get_users_list_ng')&lt;br /&gt;
    .success((listSize) -&amp;gt;&lt;br /&gt;
      $scope.listSize = listSize&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This process is initiated by init() command shown bellow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.user_display = {}&lt;br /&gt;
    $scope.editProfileVisible = {}&lt;br /&gt;
    if $scope.users.length == $scope.listSize&lt;br /&gt;
      return&lt;br /&gt;
    else if $scope.users.length == 0&lt;br /&gt;
      $scope.listSize = 0&lt;br /&gt;
      $scope.getUserListSize()&lt;br /&gt;
      $scope.fetchNumber = 0&lt;br /&gt;
    $scope.getUsers(($scope.fetchNumber))&lt;br /&gt;
    $scope.currentPage = 0&lt;br /&gt;
    $scope.pagination(50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The view resulting from this code structure can be seen bellow:&lt;br /&gt;
&lt;br /&gt;
[[File:list_users.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2) Paginating Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to paginate users, a filter needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The startFrom:currentPage*pageSize portion of the filter calls the custom filter startFrom which simply splits the data to display based on the current page of pagination (currentPage), multiplied by the number of users to display (pageSize, which is set by the user selecting either All, 25, 50, 100, or 250).&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app.filter 'startFrom', -&amp;gt;&lt;br /&gt;
  (input, start) -&amp;gt;&lt;br /&gt;
    start = +start&lt;br /&gt;
    return input.slice start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The limitTo:pageSize is a built in angular filter that says to stop displaying users after pageSize of them have been displayed.&lt;br /&gt;
&lt;br /&gt;
The aforementioned pageSize is set by the user through a dropdown; This code tells the dropdown to set the default paginate value to 100 users per page, and upon an ng-change (user selecting a different value), the pagination method will be called in app.coffee, with the appropriate pageSize:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;label&amp;gt;Paginate By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;paginate&amp;quot; ng-init=&amp;quot;paginate='50'&amp;quot; ng-change=&amp;quot;pagination(paginate)&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;All&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;25&amp;quot;&amp;gt;25&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;50&amp;quot;&amp;gt;50&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;100&amp;quot;&amp;gt;100&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;250&amp;quot;&amp;gt;250&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in app.coffee, and it posts the pageSize to the set_page_size method in the users_controller, and then sets various variable values based on the results:&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.pagination = (ps) -&amp;gt;&lt;br /&gt;
    $http.post('/users/set_page_size', {&lt;br /&gt;
      'pageSize': ps&lt;br /&gt;
    })&lt;br /&gt;
    .success((value) -&amp;gt;&lt;br /&gt;
      $scope.pageSize = value[0]&lt;br /&gt;
      $scope.div = value[1]&lt;br /&gt;
      $scope.totalSize = value[2]&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in users_controller and it takes in the user defined pageSize variable and then determines how many pages are required to divide the data into based off of the pageSize, then returns that variable, plus others:&lt;br /&gt;
&lt;br /&gt;
In app/controllers/user_controller:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def set_page_size&lt;br /&gt;
    ps = params[:pageSize].to_i&lt;br /&gt;
    user = session[:user]&lt;br /&gt;
    role = Role.find(user.role_id)&lt;br /&gt;
    all_users = User.order('name').where( ['role_id in (?) or id = ?', role.get_available_roles, user.id])&lt;br /&gt;
    users_length = all_users.length&lt;br /&gt;
    if ps == 0&lt;br /&gt;
      pageSize = users_length&lt;br /&gt;
    else&lt;br /&gt;
      pageSize = ps&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    div = (users_length/pageSize.to_f).ceil&lt;br /&gt;
    &lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: [pageSize, div, users_length]}&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once the number of pages and pageSize has been set, those numbers are then used to show the current and remaining pages to go along with the previous and next buttons:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;paginate-button&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-left&amp;quot; ng-disabled=&amp;quot;currentPage == 0&amp;quot; ng-click=&amp;quot;currentPage=currentPage-1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
  {{currentPage+1}}/{{div}}&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-right&amp;quot; ng-disabled=&amp;quot;currentPage &amp;gt;= totalSize/pageSize - 1&amp;quot; ng-click=&amp;quot;currentPage=currentPage+1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
 &amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) Searching Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to search users, a filter also needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The filter:search portion of this code simply applies the following filter criteria; the type of search is determined a dropdown (either search by any field, name, fullname, or email fields). Based on the dropdown selection, the correct search box will be shown, once that search box is show, the search criteria is set to correspond to the type of search specified by the dropdown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;pull-right form-group&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;form-inline&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label&amp;gt;Search By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;searchtype&amp;quot; ng-init=&amp;quot;searchtype='any'&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;any&amp;quot;&amp;gt;Any&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;name&amp;quot;&amp;gt;Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;fullname&amp;quot;&amp;gt;Full Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;email&amp;quot;&amp;gt;Email&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
  &amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'any'&amp;quot; ng-model=&amp;quot;search.object.$&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'name'&amp;quot; ng-model=&amp;quot;search.object.name&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'fullname'&amp;quot; ng-model=&amp;quot;search.object.fullname&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'email'&amp;quot; ng-model=&amp;quot;search.object.email&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) Showing Users&lt;br /&gt;
Clicking on each user name in the table of users uncovers a template that shows the information about that specific user. This is accomplished in a very simple way by setting the profileVisible flag to true. The information about that specific user is extracted from displayedUser object provided by showUser() method from UsersPageCtrl controller in app.coffee file.&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-if=&amp;quot;profileVisible == true&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h1&amp;gt;&amp;lt;b&amp;gt;User: {{displayedUser.object.name}}&amp;lt;/b&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Full Name: &amp;lt;/b&amp;gt;{{displayedUser.object.fullname}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Email Address: &amp;lt;/b&amp;gt;{{displayedUser.object.email}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Role: &amp;lt;/b&amp;gt;{{displayedUser.role}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;showTable(true)&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-primary&amp;quot;&amp;gt;Back&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;editUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-success&amp;quot;&amp;gt;Edit&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;deleteUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-danger&amp;quot;&amp;gt;Delete&amp;lt;/button&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.showUser = (user_id) -&amp;gt;&lt;br /&gt;
    $scope.user_display[user_id] = !$scope.user_display[user_id]&lt;br /&gt;
    $scope.editProfileVisible[user_id] = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see in the screenshot bellow, as an example, user 6 has been selected and now the editing information about this user is visible.&lt;br /&gt;
&lt;br /&gt;
[[File:select_user.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5) Editing and Deleting Users&lt;br /&gt;
&lt;br /&gt;
Editing Users is implemented in a similar way as showing users. The template contains ng-if statement which allows us to display edit page for each user. editUser() method from UsersPageCtrl controller specified in app.coffee displays information of the displayedUser but only after the Save button is clicked it saves the information from displayedUsers into updatedUser variable. POST request with :id parameter is then sent to update method in users_controller of Rails, which then updates this user information in the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.editUser = (user) -&amp;gt;&lt;br /&gt;
    # $scope.showUser(false)&lt;br /&gt;
    $scope.editProfileVisible[user.object.id] = !$scope.editProfileVisible[user.object.id]&lt;br /&gt;
    $scope.updatedUser = user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above allows us to set the edit form visible. Bellow, you will find an example screenshot of this feature.&lt;br /&gt;
&lt;br /&gt;
[[File:edit_user.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Resources=&lt;br /&gt;
&lt;br /&gt;
Github link: https://github.com/CSC517-FInalProject/expertiza/tree/pei-final&lt;br /&gt;
Wiki link:http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2015_E1526_MPRI &lt;br /&gt;
Project Demo: https://youtu.be/qsHYE9Rgx80 &lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Edit_user.png&amp;diff=97089</id>
		<title>File:Edit user.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Edit_user.png&amp;diff=97089"/>
		<updated>2015-05-04T06:29:48Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97088</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97088"/>
		<updated>2015-05-04T06:29:36Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Code Details */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Guide for future students =&lt;br /&gt;
1. Learn how to integrate AngularJS into Rails, using Rails original routing system.&lt;br /&gt;
&lt;br /&gt;
2. Learn AngularJS and Coffeescript, since the app.js is written in Coffeescript now.&lt;br /&gt;
&lt;br /&gt;
3. Learn Bootstrap, including the grid system, responsive design and etc.&lt;br /&gt;
&lt;br /&gt;
4. Read the code written by us, to know &lt;br /&gt;
&lt;br /&gt;
    a. how to pass data from Rails controller and view to AngularJS; &lt;br /&gt;
    b. how to pass data back to Rails view from AngularJS; &lt;br /&gt;
    c. how to convert JSON formatted data using in AngularJS to Rails hash and vice versa.&lt;br /&gt;
    d. how to present the data to Rails view&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD the following content to the config/application.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js&lt;br /&gt;
&lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;code&amp;gt; div ng-app='MPApp'&amp;lt;/code&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;br /&gt;
&lt;br /&gt;
=The specifics=&lt;br /&gt;
This section explains the very detailed actions and their results related to the 3 specific pages that were used to integrate AngularJS. Numerous snapshots are provided with the goal to make our approach very clear.&lt;br /&gt;
&lt;br /&gt;
== Login Page and Navigation Bar ==&lt;br /&gt;
Login procedure:&lt;br /&gt;
‘Login’ button clicked → auth_controller#login → auth_controller#after_login(user) → if user.role != ‘student’ → tree_display#drill → tree_display#list&amp;lt;br/&amp;gt;&lt;br /&gt;
If session[:menu] is defined, that is, when a user is logging in, the page will render the content of variable session[:menu].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
       &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
          :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
     &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
         :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
 &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each menu item in the nav bar, it is a dropdown menu now. For different level of dropdown menu, we apply different CSS style to it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% level += 1 %&amp;gt;&lt;br /&gt;
&amp;lt;% items.each do |item_id|&lt;br /&gt;
  item = session[:menu].get_item(item_id)&lt;br /&gt;
  selected = session[:menu].selected?(item.id)&lt;br /&gt;
  long_name = item.name.split(/\W/).collect{|word| word.capitalize}.join(' ')&lt;br /&gt;
%&amp;gt;&lt;br /&gt;
&amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown first-level&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% elsif level == 2 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown-submenu&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% else %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;lt;%= URI.encode(&amp;quot;/menu/#{item.name}&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;%= if item.children&lt;br /&gt;
        ' class=&amp;quot;daddy&amp;quot;'&lt;br /&gt;
      end %&amp;gt;title='&amp;lt;%= long_name %&amp;gt;'&amp;gt;&amp;lt;%= item.label.html_safe %&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
    &amp;lt;% if item.children -%&amp;gt;&lt;br /&gt;
    &amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu multi-level&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
    &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
      &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
    &amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Please also refer to app/assets/application.css.scss for further details.&lt;br /&gt;
&lt;br /&gt;
== Manage-course page ==&lt;br /&gt;
=== Design ===&lt;br /&gt;
After logging in, only the table frame is loaded into the page by rails. Then AngularJS takes over in the background and populate the content into the table. After all first-level content is populated into the table, in this case, all courses info belongs to the first level and their assignment is the second-level content.&lt;br /&gt;
&lt;br /&gt;
After all first level content is loaded into the table, the Angular controller starts to initialize POST request for second level content.&lt;br /&gt;
&lt;br /&gt;
In all, rendering the tree_display page is divided into 3 steps: &amp;lt;br&amp;gt;&lt;br /&gt;
1. render the table frame,  &amp;lt;br&amp;gt;&lt;br /&gt;
2. render the first level table content. &amp;lt;br&amp;gt;&lt;br /&gt;
3. fetch deeper level data. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the past, these 3 steps are done before rendering the page, which takes about 10-20 seconds. But now, it takes only 2-3 seconds to finish the first 2 steps, and 2 more seconds for the 3rd step.&lt;br /&gt;
&lt;br /&gt;
Moreover, the sorting and table record filtering is integrated into the table. No redirecting or re-rendering is needed for sorting or filtering, which was needed in the past.&lt;br /&gt;
&lt;br /&gt;
=== Code details ===&lt;br /&gt;
Pass Rails controller params to view in tree_display_controller#list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
angularParams = {}&lt;br /&gt;
angularParams[:search] = @search&lt;br /&gt;
angularParams[:show] = @show&lt;br /&gt;
angularParams[:child_nodes] = @child_nodes&lt;br /&gt;
angularParams[:sortvar] = @sortvar&lt;br /&gt;
angularParams[:sortorder] = @sortorder&lt;br /&gt;
angularParams[:user_id] = session[:user].id&lt;br /&gt;
angularParams[:nodeType] = 'FolderNode'&lt;br /&gt;
@angularParamsJSON = angularParams.to_json&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the view passes to AngularJS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-controller='TreeCtrl'&amp;gt;&lt;br /&gt;
&amp;lt;div ng-init=&amp;quot;init('&amp;lt;%= @angularParamsJSON %&amp;gt;')&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
AngularJS handles it, after all basic elements are loaded onto the page. Then AngularJS initializes a POST request for retrieving more data to populate the table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.angularParams = JSON.parse(value)&lt;br /&gt;
    $http.post('/tree_display/get_children_node_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.angularParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      $scope.tableContent = {}&lt;br /&gt;
      $scope.displayTableContent = {}&lt;br /&gt;
      $scope.lastLoadNum = {}&lt;br /&gt;
      $scope.typeList = []&lt;br /&gt;
      console.log data&lt;br /&gt;
      for nodeType, outerNode of data&lt;br /&gt;
        $scope.tableContent[nodeType] = []&lt;br /&gt;
        $scope.lastLoadNum[nodeType] = 0&lt;br /&gt;
        $scope.displayTableContent[nodeType] = []&lt;br /&gt;
        $scope.typeList.push nodeType&lt;br /&gt;
        # outerNode is the Assignments/Courses/Questionnaires&lt;br /&gt;
        for node in outerNode&lt;br /&gt;
          $scope.tableContent[nodeType].push node&lt;br /&gt;
          $scope.fetchCellContent(nodeType, node)&lt;br /&gt;
        $scope.getMoreContent(nodeType, 1)&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fetch table cell content recursively and put them into a hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.fetchCellContent = (nodeType, node) -&amp;gt;&lt;br /&gt;
    $scope.newParams = {}&lt;br /&gt;
    $scope.newParams[&amp;quot;sortvar&amp;quot;] = $scope.angularParams[&amp;quot;sortvar&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;sortorder&amp;quot;] = $scope.angularParams[&amp;quot;sortorder&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;search&amp;quot;] = $scope.angularParams[&amp;quot;search&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;show&amp;quot;] = $scope.angularParams[&amp;quot;show&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;user_id&amp;quot;] = $scope.angularParams[&amp;quot;user_id&amp;quot;]&lt;br /&gt;
    key = node.name + &amp;quot;|&amp;quot; + node.directory&lt;br /&gt;
    $scope.newParams[&amp;quot;key&amp;quot;] = key&lt;br /&gt;
    # console.log key&lt;br /&gt;
    if nodeType == 'Assignments'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'AssignmentNode'&lt;br /&gt;
    else if nodeType == 'Courses'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'CourseNode'&lt;br /&gt;
    else if nodeType == 'Questionnaires'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'FolderNode'&lt;br /&gt;
    else&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
    $scope.newParams[&amp;quot;child_nodes&amp;quot;] = node.nodeinfo&lt;br /&gt;
    $http.post('/tree_display/get_children_node_2_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.newParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      if data.length &amp;gt; 0&lt;br /&gt;
        for newNode in data&lt;br /&gt;
          if not $scope.allData[newNode.key]&lt;br /&gt;
            $scope.allData[newNode.key] = []&lt;br /&gt;
          $scope.display[newNode.key] = false&lt;br /&gt;
          $scope.allData[newNode.key].push newNode&lt;br /&gt;
          $scope.fetchCellContent(newNode.type, newNode)&lt;br /&gt;
&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After all data is fetched, the Rails view is able to presenting them onto the page!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;record in displayTableContent['Courses'] | filter:searchText | orderBy:predicate:reverse&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;tr ng-click=&amp;quot;showCellContent(record.name, record.directory)&amp;quot; class=&amp;quot;clickable-row&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
              &lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
          &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot; ng-if=&amp;quot;display[record.name+'|'+record.directory] &amp;amp;&amp;amp; allData[record.name+'|'+record.directory]&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;table class=&amp;quot;normal-table table table-bordered table-striped compact-table&amp;quot; ng-repeat=&amp;quot;cell in cellContent&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;tbody&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;: {{cell.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Directory&amp;lt;/b&amp;gt;: {{cell.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Creation Date&amp;lt;/b&amp;gt;: {{cell.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Modified Date&amp;lt;/b&amp;gt;: {{cell.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
              &amp;lt;/tbody&amp;gt;&lt;br /&gt;
            &amp;lt;/table&amp;gt;&lt;br /&gt;
          &amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
        &amp;lt;/tbody&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manage Users page ==&lt;br /&gt;
&lt;br /&gt;
===Design===&lt;br /&gt;
&lt;br /&gt;
Once logged in, choosing Manage/users option from the navbar, gets us routed to /users page which is defined in list.html.erb file. This file can be broken down to 5 constituents:&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users &amp;lt;br&amp;gt;&lt;br /&gt;
2) Paginating Users &amp;lt;br&amp;gt;&lt;br /&gt;
3) Searching Users &amp;lt;br&amp;gt;&lt;br /&gt;
4) Showing Users &amp;lt;br&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Details===&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users&lt;br /&gt;
Fetching users was challenging at first due to an extremely large number of user entries (total of 5300). Fetch of such large data produced a very long delay that was one of the major UX problems in legacy version of Expertiza. This problem has been solved with Angular by sending a post request that gets 300 users and then another post request which gets all the users. This approach provides a quick response and the first 300 users can be seen right away in the form of 3 pages (default set to 100 users per page). While the user is looking at the first couple of entries, the rest of the entries are fetched in the background. This allows for a fast response, full functionality as well as complete data.&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.getUsers = (fn) -&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    $http.post('/users/get_users_ng', {&lt;br /&gt;
      'fetchNumber': fn&lt;br /&gt;
    })&lt;br /&gt;
    .success((receivedUsers) -&amp;gt;&lt;br /&gt;
      console.log receivedUsers&lt;br /&gt;
      for user in receivedUsers&lt;br /&gt;
        $scope.users.push user&lt;br /&gt;
        $scope.user_display[user.object.id] = false&lt;br /&gt;
        $scope.editProfileVisible[user.object.id] = false&lt;br /&gt;
&lt;br /&gt;
      $scope.fetchNumber+=1&lt;br /&gt;
      console.log $scope.users.length&lt;br /&gt;
      console.log $scope.listSize&lt;br /&gt;
&lt;br /&gt;
      if $scope.users.length &amp;lt; $scope.listSize&lt;br /&gt;
        $scope.getUsers($scope.fetchNumber)&lt;br /&gt;
      )&lt;br /&gt;
&lt;br /&gt;
  $scope.getUserListSize = () -&amp;gt;&lt;br /&gt;
    $http.get('/users/get_users_list_ng')&lt;br /&gt;
    .success((listSize) -&amp;gt;&lt;br /&gt;
      $scope.listSize = listSize&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This process is initiated by init() command shown bellow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.user_display = {}&lt;br /&gt;
    $scope.editProfileVisible = {}&lt;br /&gt;
    if $scope.users.length == $scope.listSize&lt;br /&gt;
      return&lt;br /&gt;
    else if $scope.users.length == 0&lt;br /&gt;
      $scope.listSize = 0&lt;br /&gt;
      $scope.getUserListSize()&lt;br /&gt;
      $scope.fetchNumber = 0&lt;br /&gt;
    $scope.getUsers(($scope.fetchNumber))&lt;br /&gt;
    $scope.currentPage = 0&lt;br /&gt;
    $scope.pagination(50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The view resulting from this code structure can be seen bellow:&lt;br /&gt;
&lt;br /&gt;
[[File:list_users.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2) Paginating Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to paginate users, a filter needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The startFrom:currentPage*pageSize portion of the filter calls the custom filter startFrom which simply splits the data to display based on the current page of pagination (currentPage), multiplied by the number of users to display (pageSize, which is set by the user selecting either All, 25, 50, 100, or 250).&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app.filter 'startFrom', -&amp;gt;&lt;br /&gt;
  (input, start) -&amp;gt;&lt;br /&gt;
    start = +start&lt;br /&gt;
    return input.slice start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The limitTo:pageSize is a built in angular filter that says to stop displaying users after pageSize of them have been displayed.&lt;br /&gt;
&lt;br /&gt;
The aforementioned pageSize is set by the user through a dropdown; This code tells the dropdown to set the default paginate value to 100 users per page, and upon an ng-change (user selecting a different value), the pagination method will be called in app.coffee, with the appropriate pageSize:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;label&amp;gt;Paginate By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;paginate&amp;quot; ng-init=&amp;quot;paginate='50'&amp;quot; ng-change=&amp;quot;pagination(paginate)&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;All&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;25&amp;quot;&amp;gt;25&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;50&amp;quot;&amp;gt;50&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;100&amp;quot;&amp;gt;100&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;250&amp;quot;&amp;gt;250&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in app.coffee, and it posts the pageSize to the set_page_size method in the users_controller, and then sets various variable values based on the results:&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.pagination = (ps) -&amp;gt;&lt;br /&gt;
    $http.post('/users/set_page_size', {&lt;br /&gt;
      'pageSize': ps&lt;br /&gt;
    })&lt;br /&gt;
    .success((value) -&amp;gt;&lt;br /&gt;
      $scope.pageSize = value[0]&lt;br /&gt;
      $scope.div = value[1]&lt;br /&gt;
      $scope.totalSize = value[2]&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in users_controller and it takes in the user defined pageSize variable and then determines how many pages are required to divide the data into based off of the pageSize, then returns that variable, plus others:&lt;br /&gt;
&lt;br /&gt;
In app/controllers/user_controller:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def set_page_size&lt;br /&gt;
    ps = params[:pageSize].to_i&lt;br /&gt;
    user = session[:user]&lt;br /&gt;
    role = Role.find(user.role_id)&lt;br /&gt;
    all_users = User.order('name').where( ['role_id in (?) or id = ?', role.get_available_roles, user.id])&lt;br /&gt;
    users_length = all_users.length&lt;br /&gt;
    if ps == 0&lt;br /&gt;
      pageSize = users_length&lt;br /&gt;
    else&lt;br /&gt;
      pageSize = ps&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    div = (users_length/pageSize.to_f).ceil&lt;br /&gt;
    &lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: [pageSize, div, users_length]}&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once the number of pages and pageSize has been set, those numbers are then used to show the current and remaining pages to go along with the previous and next buttons:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;paginate-button&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-left&amp;quot; ng-disabled=&amp;quot;currentPage == 0&amp;quot; ng-click=&amp;quot;currentPage=currentPage-1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
  {{currentPage+1}}/{{div}}&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-right&amp;quot; ng-disabled=&amp;quot;currentPage &amp;gt;= totalSize/pageSize - 1&amp;quot; ng-click=&amp;quot;currentPage=currentPage+1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
 &amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) Searching Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to search users, a filter also needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The filter:search portion of this code simply applies the following filter criteria; the type of search is determined a dropdown (either search by any field, name, fullname, or email fields). Based on the dropdown selection, the correct search box will be shown, once that search box is show, the search criteria is set to correspond to the type of search specified by the dropdown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;pull-right form-group&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;form-inline&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label&amp;gt;Search By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;searchtype&amp;quot; ng-init=&amp;quot;searchtype='any'&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;any&amp;quot;&amp;gt;Any&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;name&amp;quot;&amp;gt;Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;fullname&amp;quot;&amp;gt;Full Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;email&amp;quot;&amp;gt;Email&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
  &amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'any'&amp;quot; ng-model=&amp;quot;search.object.$&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'name'&amp;quot; ng-model=&amp;quot;search.object.name&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'fullname'&amp;quot; ng-model=&amp;quot;search.object.fullname&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'email'&amp;quot; ng-model=&amp;quot;search.object.email&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) Showing Users&lt;br /&gt;
Clicking on each user name in the table of users uncovers a template that shows the information about that specific user. This is accomplished in a very simple way by setting the profileVisible flag to true. The information about that specific user is extracted from displayedUser object provided by showUser() method from UsersPageCtrl controller in app.coffee file.&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-if=&amp;quot;profileVisible == true&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h1&amp;gt;&amp;lt;b&amp;gt;User: {{displayedUser.object.name}}&amp;lt;/b&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Full Name: &amp;lt;/b&amp;gt;{{displayedUser.object.fullname}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Email Address: &amp;lt;/b&amp;gt;{{displayedUser.object.email}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Role: &amp;lt;/b&amp;gt;{{displayedUser.role}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;showTable(true)&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-primary&amp;quot;&amp;gt;Back&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;editUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-success&amp;quot;&amp;gt;Edit&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;deleteUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-danger&amp;quot;&amp;gt;Delete&amp;lt;/button&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.showUser = (user_id) -&amp;gt;&lt;br /&gt;
    $scope.user_display[user_id] = !$scope.user_display[user_id]&lt;br /&gt;
    $scope.editProfileVisible[user_id] = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see in the screenshot bellow, as an example, user 6 has been selected and now the editing information about this user is visible.&lt;br /&gt;
&lt;br /&gt;
[[File:select_user.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5) Editing and Deleting Users&lt;br /&gt;
&lt;br /&gt;
Editing Users is implemented in a similar way as showing users. The template contains ng-if statement which allows us to display edit page for each user. editUser() method from UsersPageCtrl controller specified in app.coffee displays information of the displayedUser but only after the Save button is clicked it saves the information from displayedUsers into updatedUser variable. POST request with :id parameter is then sent to update method in users_controller of Rails, which then updates this user information in the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.editUser = (user) -&amp;gt;&lt;br /&gt;
    # $scope.showUser(false)&lt;br /&gt;
    $scope.editProfileVisible[user.object.id] = !$scope.editProfileVisible[user.object.id]&lt;br /&gt;
    $scope.updatedUser = user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above allows us to set the edit form visible. Bellow, you will find an example screenshot of this feature.&lt;br /&gt;
&lt;br /&gt;
[[File:edit_user.png]]&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Select_user.png&amp;diff=97087</id>
		<title>File:Select user.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Select_user.png&amp;diff=97087"/>
		<updated>2015-05-04T06:28:16Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97086</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97086"/>
		<updated>2015-05-04T06:28:03Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Code Details */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Guide for future students =&lt;br /&gt;
1. Learn how to integrate AngularJS into Rails, using Rails original routing system.&lt;br /&gt;
&lt;br /&gt;
2. Learn AngularJS and Coffeescript, since the app.js is written in Coffeescript now.&lt;br /&gt;
&lt;br /&gt;
3. Learn Bootstrap, including the grid system, responsive design and etc.&lt;br /&gt;
&lt;br /&gt;
4. Read the code written by us, to know &lt;br /&gt;
&lt;br /&gt;
    a. how to pass data from Rails controller and view to AngularJS; &lt;br /&gt;
    b. how to pass data back to Rails view from AngularJS; &lt;br /&gt;
    c. how to convert JSON formatted data using in AngularJS to Rails hash and vice versa.&lt;br /&gt;
    d. how to present the data to Rails view&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD the following content to the config/application.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js&lt;br /&gt;
&lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;code&amp;gt; div ng-app='MPApp'&amp;lt;/code&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;br /&gt;
&lt;br /&gt;
=The specifics=&lt;br /&gt;
This section explains the very detailed actions and their results related to the 3 specific pages that were used to integrate AngularJS. Numerous snapshots are provided with the goal to make our approach very clear.&lt;br /&gt;
&lt;br /&gt;
== Login Page and Navigation Bar ==&lt;br /&gt;
Login procedure:&lt;br /&gt;
‘Login’ button clicked → auth_controller#login → auth_controller#after_login(user) → if user.role != ‘student’ → tree_display#drill → tree_display#list&amp;lt;br/&amp;gt;&lt;br /&gt;
If session[:menu] is defined, that is, when a user is logging in, the page will render the content of variable session[:menu].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
       &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
          :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
     &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
         :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
 &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each menu item in the nav bar, it is a dropdown menu now. For different level of dropdown menu, we apply different CSS style to it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% level += 1 %&amp;gt;&lt;br /&gt;
&amp;lt;% items.each do |item_id|&lt;br /&gt;
  item = session[:menu].get_item(item_id)&lt;br /&gt;
  selected = session[:menu].selected?(item.id)&lt;br /&gt;
  long_name = item.name.split(/\W/).collect{|word| word.capitalize}.join(' ')&lt;br /&gt;
%&amp;gt;&lt;br /&gt;
&amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown first-level&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% elsif level == 2 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown-submenu&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% else %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;lt;%= URI.encode(&amp;quot;/menu/#{item.name}&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;%= if item.children&lt;br /&gt;
        ' class=&amp;quot;daddy&amp;quot;'&lt;br /&gt;
      end %&amp;gt;title='&amp;lt;%= long_name %&amp;gt;'&amp;gt;&amp;lt;%= item.label.html_safe %&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
    &amp;lt;% if item.children -%&amp;gt;&lt;br /&gt;
    &amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu multi-level&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
    &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
      &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
    &amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Please also refer to app/assets/application.css.scss for further details.&lt;br /&gt;
&lt;br /&gt;
== Manage-course page ==&lt;br /&gt;
=== Design ===&lt;br /&gt;
After logging in, only the table frame is loaded into the page by rails. Then AngularJS takes over in the background and populate the content into the table. After all first-level content is populated into the table, in this case, all courses info belongs to the first level and their assignment is the second-level content.&lt;br /&gt;
&lt;br /&gt;
After all first level content is loaded into the table, the Angular controller starts to initialize POST request for second level content.&lt;br /&gt;
&lt;br /&gt;
In all, rendering the tree_display page is divided into 3 steps: &amp;lt;br&amp;gt;&lt;br /&gt;
1. render the table frame,  &amp;lt;br&amp;gt;&lt;br /&gt;
2. render the first level table content. &amp;lt;br&amp;gt;&lt;br /&gt;
3. fetch deeper level data. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the past, these 3 steps are done before rendering the page, which takes about 10-20 seconds. But now, it takes only 2-3 seconds to finish the first 2 steps, and 2 more seconds for the 3rd step.&lt;br /&gt;
&lt;br /&gt;
Moreover, the sorting and table record filtering is integrated into the table. No redirecting or re-rendering is needed for sorting or filtering, which was needed in the past.&lt;br /&gt;
&lt;br /&gt;
=== Code details ===&lt;br /&gt;
Pass Rails controller params to view in tree_display_controller#list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
angularParams = {}&lt;br /&gt;
angularParams[:search] = @search&lt;br /&gt;
angularParams[:show] = @show&lt;br /&gt;
angularParams[:child_nodes] = @child_nodes&lt;br /&gt;
angularParams[:sortvar] = @sortvar&lt;br /&gt;
angularParams[:sortorder] = @sortorder&lt;br /&gt;
angularParams[:user_id] = session[:user].id&lt;br /&gt;
angularParams[:nodeType] = 'FolderNode'&lt;br /&gt;
@angularParamsJSON = angularParams.to_json&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the view passes to AngularJS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-controller='TreeCtrl'&amp;gt;&lt;br /&gt;
&amp;lt;div ng-init=&amp;quot;init('&amp;lt;%= @angularParamsJSON %&amp;gt;')&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
AngularJS handles it, after all basic elements are loaded onto the page. Then AngularJS initializes a POST request for retrieving more data to populate the table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.angularParams = JSON.parse(value)&lt;br /&gt;
    $http.post('/tree_display/get_children_node_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.angularParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      $scope.tableContent = {}&lt;br /&gt;
      $scope.displayTableContent = {}&lt;br /&gt;
      $scope.lastLoadNum = {}&lt;br /&gt;
      $scope.typeList = []&lt;br /&gt;
      console.log data&lt;br /&gt;
      for nodeType, outerNode of data&lt;br /&gt;
        $scope.tableContent[nodeType] = []&lt;br /&gt;
        $scope.lastLoadNum[nodeType] = 0&lt;br /&gt;
        $scope.displayTableContent[nodeType] = []&lt;br /&gt;
        $scope.typeList.push nodeType&lt;br /&gt;
        # outerNode is the Assignments/Courses/Questionnaires&lt;br /&gt;
        for node in outerNode&lt;br /&gt;
          $scope.tableContent[nodeType].push node&lt;br /&gt;
          $scope.fetchCellContent(nodeType, node)&lt;br /&gt;
        $scope.getMoreContent(nodeType, 1)&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fetch table cell content recursively and put them into a hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.fetchCellContent = (nodeType, node) -&amp;gt;&lt;br /&gt;
    $scope.newParams = {}&lt;br /&gt;
    $scope.newParams[&amp;quot;sortvar&amp;quot;] = $scope.angularParams[&amp;quot;sortvar&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;sortorder&amp;quot;] = $scope.angularParams[&amp;quot;sortorder&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;search&amp;quot;] = $scope.angularParams[&amp;quot;search&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;show&amp;quot;] = $scope.angularParams[&amp;quot;show&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;user_id&amp;quot;] = $scope.angularParams[&amp;quot;user_id&amp;quot;]&lt;br /&gt;
    key = node.name + &amp;quot;|&amp;quot; + node.directory&lt;br /&gt;
    $scope.newParams[&amp;quot;key&amp;quot;] = key&lt;br /&gt;
    # console.log key&lt;br /&gt;
    if nodeType == 'Assignments'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'AssignmentNode'&lt;br /&gt;
    else if nodeType == 'Courses'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'CourseNode'&lt;br /&gt;
    else if nodeType == 'Questionnaires'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'FolderNode'&lt;br /&gt;
    else&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
    $scope.newParams[&amp;quot;child_nodes&amp;quot;] = node.nodeinfo&lt;br /&gt;
    $http.post('/tree_display/get_children_node_2_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.newParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      if data.length &amp;gt; 0&lt;br /&gt;
        for newNode in data&lt;br /&gt;
          if not $scope.allData[newNode.key]&lt;br /&gt;
            $scope.allData[newNode.key] = []&lt;br /&gt;
          $scope.display[newNode.key] = false&lt;br /&gt;
          $scope.allData[newNode.key].push newNode&lt;br /&gt;
          $scope.fetchCellContent(newNode.type, newNode)&lt;br /&gt;
&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After all data is fetched, the Rails view is able to presenting them onto the page!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;record in displayTableContent['Courses'] | filter:searchText | orderBy:predicate:reverse&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;tr ng-click=&amp;quot;showCellContent(record.name, record.directory)&amp;quot; class=&amp;quot;clickable-row&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
              &lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
          &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot; ng-if=&amp;quot;display[record.name+'|'+record.directory] &amp;amp;&amp;amp; allData[record.name+'|'+record.directory]&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;table class=&amp;quot;normal-table table table-bordered table-striped compact-table&amp;quot; ng-repeat=&amp;quot;cell in cellContent&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;tbody&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;: {{cell.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Directory&amp;lt;/b&amp;gt;: {{cell.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Creation Date&amp;lt;/b&amp;gt;: {{cell.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Modified Date&amp;lt;/b&amp;gt;: {{cell.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
              &amp;lt;/tbody&amp;gt;&lt;br /&gt;
            &amp;lt;/table&amp;gt;&lt;br /&gt;
          &amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
        &amp;lt;/tbody&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manage Users page ==&lt;br /&gt;
&lt;br /&gt;
===Design===&lt;br /&gt;
&lt;br /&gt;
Once logged in, choosing Manage/users option from the navbar, gets us routed to /users page which is defined in list.html.erb file. This file can be broken down to 5 constituents:&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users &amp;lt;br&amp;gt;&lt;br /&gt;
2) Paginating Users &amp;lt;br&amp;gt;&lt;br /&gt;
3) Searching Users &amp;lt;br&amp;gt;&lt;br /&gt;
4) Showing Users &amp;lt;br&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Details===&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users&lt;br /&gt;
Fetching users was challenging at first due to an extremely large number of user entries (total of 5300). Fetch of such large data produced a very long delay that was one of the major UX problems in legacy version of Expertiza. This problem has been solved with Angular by sending a post request that gets 300 users and then another post request which gets all the users. This approach provides a quick response and the first 300 users can be seen right away in the form of 3 pages (default set to 100 users per page). While the user is looking at the first couple of entries, the rest of the entries are fetched in the background. This allows for a fast response, full functionality as well as complete data.&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.getUsers = (fn) -&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    $http.post('/users/get_users_ng', {&lt;br /&gt;
      'fetchNumber': fn&lt;br /&gt;
    })&lt;br /&gt;
    .success((receivedUsers) -&amp;gt;&lt;br /&gt;
      console.log receivedUsers&lt;br /&gt;
      for user in receivedUsers&lt;br /&gt;
        $scope.users.push user&lt;br /&gt;
        $scope.user_display[user.object.id] = false&lt;br /&gt;
        $scope.editProfileVisible[user.object.id] = false&lt;br /&gt;
&lt;br /&gt;
      $scope.fetchNumber+=1&lt;br /&gt;
      console.log $scope.users.length&lt;br /&gt;
      console.log $scope.listSize&lt;br /&gt;
&lt;br /&gt;
      if $scope.users.length &amp;lt; $scope.listSize&lt;br /&gt;
        $scope.getUsers($scope.fetchNumber)&lt;br /&gt;
      )&lt;br /&gt;
&lt;br /&gt;
  $scope.getUserListSize = () -&amp;gt;&lt;br /&gt;
    $http.get('/users/get_users_list_ng')&lt;br /&gt;
    .success((listSize) -&amp;gt;&lt;br /&gt;
      $scope.listSize = listSize&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This process is initiated by init() command shown bellow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.user_display = {}&lt;br /&gt;
    $scope.editProfileVisible = {}&lt;br /&gt;
    if $scope.users.length == $scope.listSize&lt;br /&gt;
      return&lt;br /&gt;
    else if $scope.users.length == 0&lt;br /&gt;
      $scope.listSize = 0&lt;br /&gt;
      $scope.getUserListSize()&lt;br /&gt;
      $scope.fetchNumber = 0&lt;br /&gt;
    $scope.getUsers(($scope.fetchNumber))&lt;br /&gt;
    $scope.currentPage = 0&lt;br /&gt;
    $scope.pagination(50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The view resulting from this code structure can be seen bellow:&lt;br /&gt;
&lt;br /&gt;
[[File:list_users.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2) Paginating Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to paginate users, a filter needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The startFrom:currentPage*pageSize portion of the filter calls the custom filter startFrom which simply splits the data to display based on the current page of pagination (currentPage), multiplied by the number of users to display (pageSize, which is set by the user selecting either All, 25, 50, 100, or 250).&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app.filter 'startFrom', -&amp;gt;&lt;br /&gt;
  (input, start) -&amp;gt;&lt;br /&gt;
    start = +start&lt;br /&gt;
    return input.slice start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The limitTo:pageSize is a built in angular filter that says to stop displaying users after pageSize of them have been displayed.&lt;br /&gt;
&lt;br /&gt;
The aforementioned pageSize is set by the user through a dropdown; This code tells the dropdown to set the default paginate value to 100 users per page, and upon an ng-change (user selecting a different value), the pagination method will be called in app.coffee, with the appropriate pageSize:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;label&amp;gt;Paginate By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;paginate&amp;quot; ng-init=&amp;quot;paginate='50'&amp;quot; ng-change=&amp;quot;pagination(paginate)&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;All&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;25&amp;quot;&amp;gt;25&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;50&amp;quot;&amp;gt;50&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;100&amp;quot;&amp;gt;100&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;250&amp;quot;&amp;gt;250&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in app.coffee, and it posts the pageSize to the set_page_size method in the users_controller, and then sets various variable values based on the results:&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.pagination = (ps) -&amp;gt;&lt;br /&gt;
    $http.post('/users/set_page_size', {&lt;br /&gt;
      'pageSize': ps&lt;br /&gt;
    })&lt;br /&gt;
    .success((value) -&amp;gt;&lt;br /&gt;
      $scope.pageSize = value[0]&lt;br /&gt;
      $scope.div = value[1]&lt;br /&gt;
      $scope.totalSize = value[2]&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in users_controller and it takes in the user defined pageSize variable and then determines how many pages are required to divide the data into based off of the pageSize, then returns that variable, plus others:&lt;br /&gt;
&lt;br /&gt;
In app/controllers/user_controller:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def set_page_size&lt;br /&gt;
    ps = params[:pageSize].to_i&lt;br /&gt;
    user = session[:user]&lt;br /&gt;
    role = Role.find(user.role_id)&lt;br /&gt;
    all_users = User.order('name').where( ['role_id in (?) or id = ?', role.get_available_roles, user.id])&lt;br /&gt;
    users_length = all_users.length&lt;br /&gt;
    if ps == 0&lt;br /&gt;
      pageSize = users_length&lt;br /&gt;
    else&lt;br /&gt;
      pageSize = ps&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    div = (users_length/pageSize.to_f).ceil&lt;br /&gt;
    &lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: [pageSize, div, users_length]}&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once the number of pages and pageSize has been set, those numbers are then used to show the current and remaining pages to go along with the previous and next buttons:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;paginate-button&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-left&amp;quot; ng-disabled=&amp;quot;currentPage == 0&amp;quot; ng-click=&amp;quot;currentPage=currentPage-1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
  {{currentPage+1}}/{{div}}&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-right&amp;quot; ng-disabled=&amp;quot;currentPage &amp;gt;= totalSize/pageSize - 1&amp;quot; ng-click=&amp;quot;currentPage=currentPage+1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
 &amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) Searching Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to search users, a filter also needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The filter:search portion of this code simply applies the following filter criteria; the type of search is determined a dropdown (either search by any field, name, fullname, or email fields). Based on the dropdown selection, the correct search box will be shown, once that search box is show, the search criteria is set to correspond to the type of search specified by the dropdown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;pull-right form-group&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;form-inline&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label&amp;gt;Search By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;searchtype&amp;quot; ng-init=&amp;quot;searchtype='any'&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;any&amp;quot;&amp;gt;Any&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;name&amp;quot;&amp;gt;Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;fullname&amp;quot;&amp;gt;Full Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;email&amp;quot;&amp;gt;Email&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
  &amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'any'&amp;quot; ng-model=&amp;quot;search.object.$&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'name'&amp;quot; ng-model=&amp;quot;search.object.name&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'fullname'&amp;quot; ng-model=&amp;quot;search.object.fullname&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'email'&amp;quot; ng-model=&amp;quot;search.object.email&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) Showing Users&lt;br /&gt;
Clicking on each user name in the table of users uncovers a template that shows the information about that specific user. This is accomplished in a very simple way by setting the profileVisible flag to true. The information about that specific user is extracted from displayedUser object provided by showUser() method from UsersPageCtrl controller in app.coffee file.&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-if=&amp;quot;profileVisible == true&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h1&amp;gt;&amp;lt;b&amp;gt;User: {{displayedUser.object.name}}&amp;lt;/b&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Full Name: &amp;lt;/b&amp;gt;{{displayedUser.object.fullname}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Email Address: &amp;lt;/b&amp;gt;{{displayedUser.object.email}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Role: &amp;lt;/b&amp;gt;{{displayedUser.role}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;showTable(true)&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-primary&amp;quot;&amp;gt;Back&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;editUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-success&amp;quot;&amp;gt;Edit&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;deleteUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-danger&amp;quot;&amp;gt;Delete&amp;lt;/button&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.showUser = (user_id) -&amp;gt;&lt;br /&gt;
    $scope.user_display[user_id] = !$scope.user_display[user_id]&lt;br /&gt;
    $scope.editProfileVisible[user_id] = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see in the screenshot bellow, as an example, user 6 has been selected and now the editing information about this user is visible.&lt;br /&gt;
&lt;br /&gt;
[[File:select_user.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5) Editing and Deleting Users&lt;br /&gt;
&lt;br /&gt;
Editing Users is implemented in a similar way as showing users. The template contains ng-if statement which allows us to display edit page for each user. editUser() method from UsersPageCtrl controller specified in app.coffee displays information of the displayedUser but only after the Save button is clicked it saves the information from displayedUsers into updatedUser variable. POST request with :id parameter is then sent to update method in users_controller of Rails, which then updates this user information in the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.editUser = (user) -&amp;gt;&lt;br /&gt;
    # $scope.showUser(false)&lt;br /&gt;
    $scope.editProfileVisible[user.object.id] = !$scope.editProfileVisible[user.object.id]&lt;br /&gt;
    $scope.updatedUser = user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:List_users.png&amp;diff=97085</id>
		<title>File:List users.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:List_users.png&amp;diff=97085"/>
		<updated>2015-05-04T06:26:08Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: uploaded a new version of &amp;amp;quot;File:List users.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:List_users.png&amp;diff=97084</id>
		<title>File:List users.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:List_users.png&amp;diff=97084"/>
		<updated>2015-05-04T06:25:14Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: uploaded a new version of &amp;amp;quot;File:List users.png&amp;amp;quot;: Reverted to version as of 06:20, 4 May 2015&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:List_users.png&amp;diff=97083</id>
		<title>File:List users.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:List_users.png&amp;diff=97083"/>
		<updated>2015-05-04T06:21:10Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: uploaded a new version of &amp;amp;quot;File:List users.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:List_users.png&amp;diff=97082</id>
		<title>File:List users.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:List_users.png&amp;diff=97082"/>
		<updated>2015-05-04T06:20:51Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97081</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97081"/>
		<updated>2015-05-04T06:20:25Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Code Details */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Guide for future students =&lt;br /&gt;
1. Learn how to integrate AngularJS into Rails, using Rails original routing system.&lt;br /&gt;
&lt;br /&gt;
2. Learn AngularJS and Coffeescript, since the app.js is written in Coffeescript now.&lt;br /&gt;
&lt;br /&gt;
3. Learn Bootstrap, including the grid system, responsive design and etc.&lt;br /&gt;
&lt;br /&gt;
4. Read the code written by us, to know &lt;br /&gt;
&lt;br /&gt;
    a. how to pass data from Rails controller and view to AngularJS; &lt;br /&gt;
    b. how to pass data back to Rails view from AngularJS; &lt;br /&gt;
    c. how to convert JSON formatted data using in AngularJS to Rails hash and vice versa.&lt;br /&gt;
    d. how to present the data to Rails view&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD the following content to the config/application.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js&lt;br /&gt;
&lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;code&amp;gt; div ng-app='MPApp'&amp;lt;/code&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;br /&gt;
&lt;br /&gt;
=The specifics=&lt;br /&gt;
This section explains the very detailed actions and their results related to the 3 specific pages that were used to integrate AngularJS. Numerous snapshots are provided with the goal to make our approach very clear.&lt;br /&gt;
&lt;br /&gt;
== Login Page and Navigation Bar ==&lt;br /&gt;
Login procedure:&lt;br /&gt;
‘Login’ button clicked → auth_controller#login → auth_controller#after_login(user) → if user.role != ‘student’ → tree_display#drill → tree_display#list&amp;lt;br/&amp;gt;&lt;br /&gt;
If session[:menu] is defined, that is, when a user is logging in, the page will render the content of variable session[:menu].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
       &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
          :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
     &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
         :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
 &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each menu item in the nav bar, it is a dropdown menu now. For different level of dropdown menu, we apply different CSS style to it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% level += 1 %&amp;gt;&lt;br /&gt;
&amp;lt;% items.each do |item_id|&lt;br /&gt;
  item = session[:menu].get_item(item_id)&lt;br /&gt;
  selected = session[:menu].selected?(item.id)&lt;br /&gt;
  long_name = item.name.split(/\W/).collect{|word| word.capitalize}.join(' ')&lt;br /&gt;
%&amp;gt;&lt;br /&gt;
&amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown first-level&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% elsif level == 2 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown-submenu&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% else %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;lt;%= URI.encode(&amp;quot;/menu/#{item.name}&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;%= if item.children&lt;br /&gt;
        ' class=&amp;quot;daddy&amp;quot;'&lt;br /&gt;
      end %&amp;gt;title='&amp;lt;%= long_name %&amp;gt;'&amp;gt;&amp;lt;%= item.label.html_safe %&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
    &amp;lt;% if item.children -%&amp;gt;&lt;br /&gt;
    &amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu multi-level&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
    &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
      &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
    &amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Please also refer to app/assets/application.css.scss for further details.&lt;br /&gt;
&lt;br /&gt;
== Manage-course page ==&lt;br /&gt;
=== Design ===&lt;br /&gt;
After logging in, only the table frame is loaded into the page by rails. Then AngularJS takes over in the background and populate the content into the table. After all first-level content is populated into the table, in this case, all courses info belongs to the first level and their assignment is the second-level content.&lt;br /&gt;
&lt;br /&gt;
After all first level content is loaded into the table, the Angular controller starts to initialize POST request for second level content.&lt;br /&gt;
&lt;br /&gt;
In all, rendering the tree_display page is divided into 3 steps: &amp;lt;br&amp;gt;&lt;br /&gt;
1. render the table frame,  &amp;lt;br&amp;gt;&lt;br /&gt;
2. render the first level table content. &amp;lt;br&amp;gt;&lt;br /&gt;
3. fetch deeper level data. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the past, these 3 steps are done before rendering the page, which takes about 10-20 seconds. But now, it takes only 2-3 seconds to finish the first 2 steps, and 2 more seconds for the 3rd step.&lt;br /&gt;
&lt;br /&gt;
Moreover, the sorting and table record filtering is integrated into the table. No redirecting or re-rendering is needed for sorting or filtering, which was needed in the past.&lt;br /&gt;
&lt;br /&gt;
=== Code details ===&lt;br /&gt;
Pass Rails controller params to view in tree_display_controller#list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
angularParams = {}&lt;br /&gt;
angularParams[:search] = @search&lt;br /&gt;
angularParams[:show] = @show&lt;br /&gt;
angularParams[:child_nodes] = @child_nodes&lt;br /&gt;
angularParams[:sortvar] = @sortvar&lt;br /&gt;
angularParams[:sortorder] = @sortorder&lt;br /&gt;
angularParams[:user_id] = session[:user].id&lt;br /&gt;
angularParams[:nodeType] = 'FolderNode'&lt;br /&gt;
@angularParamsJSON = angularParams.to_json&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the view passes to AngularJS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-controller='TreeCtrl'&amp;gt;&lt;br /&gt;
&amp;lt;div ng-init=&amp;quot;init('&amp;lt;%= @angularParamsJSON %&amp;gt;')&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
AngularJS handles it, after all basic elements are loaded onto the page. Then AngularJS initializes a POST request for retrieving more data to populate the table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.angularParams = JSON.parse(value)&lt;br /&gt;
    $http.post('/tree_display/get_children_node_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.angularParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      $scope.tableContent = {}&lt;br /&gt;
      $scope.displayTableContent = {}&lt;br /&gt;
      $scope.lastLoadNum = {}&lt;br /&gt;
      $scope.typeList = []&lt;br /&gt;
      console.log data&lt;br /&gt;
      for nodeType, outerNode of data&lt;br /&gt;
        $scope.tableContent[nodeType] = []&lt;br /&gt;
        $scope.lastLoadNum[nodeType] = 0&lt;br /&gt;
        $scope.displayTableContent[nodeType] = []&lt;br /&gt;
        $scope.typeList.push nodeType&lt;br /&gt;
        # outerNode is the Assignments/Courses/Questionnaires&lt;br /&gt;
        for node in outerNode&lt;br /&gt;
          $scope.tableContent[nodeType].push node&lt;br /&gt;
          $scope.fetchCellContent(nodeType, node)&lt;br /&gt;
        $scope.getMoreContent(nodeType, 1)&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fetch table cell content recursively and put them into a hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.fetchCellContent = (nodeType, node) -&amp;gt;&lt;br /&gt;
    $scope.newParams = {}&lt;br /&gt;
    $scope.newParams[&amp;quot;sortvar&amp;quot;] = $scope.angularParams[&amp;quot;sortvar&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;sortorder&amp;quot;] = $scope.angularParams[&amp;quot;sortorder&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;search&amp;quot;] = $scope.angularParams[&amp;quot;search&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;show&amp;quot;] = $scope.angularParams[&amp;quot;show&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;user_id&amp;quot;] = $scope.angularParams[&amp;quot;user_id&amp;quot;]&lt;br /&gt;
    key = node.name + &amp;quot;|&amp;quot; + node.directory&lt;br /&gt;
    $scope.newParams[&amp;quot;key&amp;quot;] = key&lt;br /&gt;
    # console.log key&lt;br /&gt;
    if nodeType == 'Assignments'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'AssignmentNode'&lt;br /&gt;
    else if nodeType == 'Courses'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'CourseNode'&lt;br /&gt;
    else if nodeType == 'Questionnaires'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'FolderNode'&lt;br /&gt;
    else&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
    $scope.newParams[&amp;quot;child_nodes&amp;quot;] = node.nodeinfo&lt;br /&gt;
    $http.post('/tree_display/get_children_node_2_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.newParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      if data.length &amp;gt; 0&lt;br /&gt;
        for newNode in data&lt;br /&gt;
          if not $scope.allData[newNode.key]&lt;br /&gt;
            $scope.allData[newNode.key] = []&lt;br /&gt;
          $scope.display[newNode.key] = false&lt;br /&gt;
          $scope.allData[newNode.key].push newNode&lt;br /&gt;
          $scope.fetchCellContent(newNode.type, newNode)&lt;br /&gt;
&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After all data is fetched, the Rails view is able to presenting them onto the page!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;record in displayTableContent['Courses'] | filter:searchText | orderBy:predicate:reverse&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;tr ng-click=&amp;quot;showCellContent(record.name, record.directory)&amp;quot; class=&amp;quot;clickable-row&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
              &lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
          &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot; ng-if=&amp;quot;display[record.name+'|'+record.directory] &amp;amp;&amp;amp; allData[record.name+'|'+record.directory]&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;table class=&amp;quot;normal-table table table-bordered table-striped compact-table&amp;quot; ng-repeat=&amp;quot;cell in cellContent&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;tbody&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;: {{cell.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Directory&amp;lt;/b&amp;gt;: {{cell.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Creation Date&amp;lt;/b&amp;gt;: {{cell.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Modified Date&amp;lt;/b&amp;gt;: {{cell.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
              &amp;lt;/tbody&amp;gt;&lt;br /&gt;
            &amp;lt;/table&amp;gt;&lt;br /&gt;
          &amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
        &amp;lt;/tbody&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manage Users page ==&lt;br /&gt;
&lt;br /&gt;
===Design===&lt;br /&gt;
&lt;br /&gt;
Once logged in, choosing Manage/users option from the navbar, gets us routed to /users page which is defined in list.html.erb file. This file can be broken down to 5 constituents:&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users &amp;lt;br&amp;gt;&lt;br /&gt;
2) Paginating Users &amp;lt;br&amp;gt;&lt;br /&gt;
3) Searching Users &amp;lt;br&amp;gt;&lt;br /&gt;
4) Showing Users &amp;lt;br&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Details===&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users&lt;br /&gt;
Fetching users was challenging at first due to an extremely large number of user entries (total of 5300). Fetch of such large data produced a very long delay that was one of the major UX problems in legacy version of Expertiza. This problem has been solved with Angular by sending a post request that gets 300 users and then another post request which gets all the users. This approach provides a quick response and the first 300 users can be seen right away in the form of 3 pages (default set to 100 users per page). While the user is looking at the first couple of entries, the rest of the entries are fetched in the background. This allows for a fast response, full functionality as well as complete data.&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.getUsers = (fn) -&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    $http.post('/users/get_users_ng', {&lt;br /&gt;
      'fetchNumber': fn&lt;br /&gt;
    })&lt;br /&gt;
    .success((receivedUsers) -&amp;gt;&lt;br /&gt;
      console.log receivedUsers&lt;br /&gt;
      for user in receivedUsers&lt;br /&gt;
        $scope.users.push user&lt;br /&gt;
        $scope.user_display[user.object.id] = false&lt;br /&gt;
        $scope.editProfileVisible[user.object.id] = false&lt;br /&gt;
&lt;br /&gt;
      $scope.fetchNumber+=1&lt;br /&gt;
      console.log $scope.users.length&lt;br /&gt;
      console.log $scope.listSize&lt;br /&gt;
&lt;br /&gt;
      if $scope.users.length &amp;lt; $scope.listSize&lt;br /&gt;
        $scope.getUsers($scope.fetchNumber)&lt;br /&gt;
      )&lt;br /&gt;
&lt;br /&gt;
  $scope.getUserListSize = () -&amp;gt;&lt;br /&gt;
    $http.get('/users/get_users_list_ng')&lt;br /&gt;
    .success((listSize) -&amp;gt;&lt;br /&gt;
      $scope.listSize = listSize&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This process is initiated by init() command shown bellow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.user_display = {}&lt;br /&gt;
    $scope.editProfileVisible = {}&lt;br /&gt;
    if $scope.users.length == $scope.listSize&lt;br /&gt;
      return&lt;br /&gt;
    else if $scope.users.length == 0&lt;br /&gt;
      $scope.listSize = 0&lt;br /&gt;
      $scope.getUserListSize()&lt;br /&gt;
      $scope.fetchNumber = 0&lt;br /&gt;
    $scope.getUsers(($scope.fetchNumber))&lt;br /&gt;
    $scope.currentPage = 0&lt;br /&gt;
    $scope.pagination(50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The view resulting from this code structure can be seen bellow:&lt;br /&gt;
&lt;br /&gt;
[[File:list_users.png]]&lt;br /&gt;
&lt;br /&gt;
2) Paginating Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to paginate users, a filter needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The startFrom:currentPage*pageSize portion of the filter calls the custom filter startFrom which simply splits the data to display based on the current page of pagination (currentPage), multiplied by the number of users to display (pageSize, which is set by the user selecting either All, 25, 50, 100, or 250).&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app.filter 'startFrom', -&amp;gt;&lt;br /&gt;
  (input, start) -&amp;gt;&lt;br /&gt;
    start = +start&lt;br /&gt;
    return input.slice start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The limitTo:pageSize is a built in angular filter that says to stop displaying users after pageSize of them have been displayed.&lt;br /&gt;
&lt;br /&gt;
The aforementioned pageSize is set by the user through a dropdown; This code tells the dropdown to set the default paginate value to 100 users per page, and upon an ng-change (user selecting a different value), the pagination method will be called in app.coffee, with the appropriate pageSize:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;label&amp;gt;Paginate By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;paginate&amp;quot; ng-init=&amp;quot;paginate='50'&amp;quot; ng-change=&amp;quot;pagination(paginate)&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;All&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;25&amp;quot;&amp;gt;25&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;50&amp;quot;&amp;gt;50&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;100&amp;quot;&amp;gt;100&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;250&amp;quot;&amp;gt;250&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in app.coffee, and it posts the pageSize to the set_page_size method in the users_controller, and then sets various variable values based on the results:&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.pagination = (ps) -&amp;gt;&lt;br /&gt;
    $http.post('/users/set_page_size', {&lt;br /&gt;
      'pageSize': ps&lt;br /&gt;
    })&lt;br /&gt;
    .success((value) -&amp;gt;&lt;br /&gt;
      $scope.pageSize = value[0]&lt;br /&gt;
      $scope.div = value[1]&lt;br /&gt;
      $scope.totalSize = value[2]&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in users_controller and it takes in the user defined pageSize variable and then determines how many pages are required to divide the data into based off of the pageSize, then returns that variable, plus others:&lt;br /&gt;
&lt;br /&gt;
In app/controllers/user_controller:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def set_page_size&lt;br /&gt;
    ps = params[:pageSize].to_i&lt;br /&gt;
    user = session[:user]&lt;br /&gt;
    role = Role.find(user.role_id)&lt;br /&gt;
    all_users = User.order('name').where( ['role_id in (?) or id = ?', role.get_available_roles, user.id])&lt;br /&gt;
    users_length = all_users.length&lt;br /&gt;
    if ps == 0&lt;br /&gt;
      pageSize = users_length&lt;br /&gt;
    else&lt;br /&gt;
      pageSize = ps&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    div = (users_length/pageSize.to_f).ceil&lt;br /&gt;
    &lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: [pageSize, div, users_length]}&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once the number of pages and pageSize has been set, those numbers are then used to show the current and remaining pages to go along with the previous and next buttons:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;paginate-button&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-left&amp;quot; ng-disabled=&amp;quot;currentPage == 0&amp;quot; ng-click=&amp;quot;currentPage=currentPage-1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
  {{currentPage+1}}/{{div}}&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-right&amp;quot; ng-disabled=&amp;quot;currentPage &amp;gt;= totalSize/pageSize - 1&amp;quot; ng-click=&amp;quot;currentPage=currentPage+1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
 &amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) Searching Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to search users, a filter also needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The filter:search portion of this code simply applies the following filter criteria; the type of search is determined a dropdown (either search by any field, name, fullname, or email fields). Based on the dropdown selection, the correct search box will be shown, once that search box is show, the search criteria is set to correspond to the type of search specified by the dropdown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;pull-right form-group&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;form-inline&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label&amp;gt;Search By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;searchtype&amp;quot; ng-init=&amp;quot;searchtype='any'&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;any&amp;quot;&amp;gt;Any&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;name&amp;quot;&amp;gt;Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;fullname&amp;quot;&amp;gt;Full Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;email&amp;quot;&amp;gt;Email&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
  &amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'any'&amp;quot; ng-model=&amp;quot;search.object.$&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'name'&amp;quot; ng-model=&amp;quot;search.object.name&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'fullname'&amp;quot; ng-model=&amp;quot;search.object.fullname&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'email'&amp;quot; ng-model=&amp;quot;search.object.email&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) Showing Users&lt;br /&gt;
Clicking on each user name in the table of users uncovers a template that shows the information about that specific user. This is accomplished in a very simple way by setting the profileVisible flag to true. The information about that specific user is extracted from displayedUser object provided by showUser() method from UsersPageCtrl controller in app.coffee file.&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-if=&amp;quot;profileVisible == true&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h1&amp;gt;&amp;lt;b&amp;gt;User: {{displayedUser.object.name}}&amp;lt;/b&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Full Name: &amp;lt;/b&amp;gt;{{displayedUser.object.fullname}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Email Address: &amp;lt;/b&amp;gt;{{displayedUser.object.email}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Role: &amp;lt;/b&amp;gt;{{displayedUser.role}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;showTable(true)&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-primary&amp;quot;&amp;gt;Back&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;editUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-success&amp;quot;&amp;gt;Edit&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;deleteUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-danger&amp;quot;&amp;gt;Delete&amp;lt;/button&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.showUser = (user_id) -&amp;gt;&lt;br /&gt;
    $scope.user_display[user_id] = !$scope.user_display[user_id]&lt;br /&gt;
    $scope.editProfileVisible[user_id] = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users&lt;br /&gt;
&lt;br /&gt;
Editing Users is implemented in a similar way as showing users. The template contains ng-if statement which allows us to display edit page for each user. editUser() method from UsersPageCtrl controller specified in app.coffee displays information of the displayedUser but only after the Save button is clicked it saves the information from displayedUsers into updatedUser variable. POST request with :id parameter is then sent to update method in users_controller of Rails, which then updates this user information in the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.editUser = (user) -&amp;gt;&lt;br /&gt;
    # $scope.showUser(false)&lt;br /&gt;
    $scope.editProfileVisible[user.object.id] = !$scope.editProfileVisible[user.object.id]&lt;br /&gt;
    $scope.updatedUser = user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97080</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97080"/>
		<updated>2015-05-04T06:17:17Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Code Details */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Guide for future students =&lt;br /&gt;
1. Learn how to integrate AngularJS into Rails, using Rails original routing system.&lt;br /&gt;
&lt;br /&gt;
2. Learn AngularJS and Coffeescript, since the app.js is written in Coffeescript now.&lt;br /&gt;
&lt;br /&gt;
3. Learn Bootstrap, including the grid system, responsive design and etc.&lt;br /&gt;
&lt;br /&gt;
4. Read the code written by us, to know &lt;br /&gt;
&lt;br /&gt;
    a. how to pass data from Rails controller and view to AngularJS; &lt;br /&gt;
    b. how to pass data back to Rails view from AngularJS; &lt;br /&gt;
    c. how to convert JSON formatted data using in AngularJS to Rails hash and vice versa.&lt;br /&gt;
    d. how to present the data to Rails view&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD the following content to the config/application.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js&lt;br /&gt;
&lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;code&amp;gt; div ng-app='MPApp'&amp;lt;/code&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;br /&gt;
&lt;br /&gt;
=The specifics=&lt;br /&gt;
This section explains the very detailed actions and their results related to the 3 specific pages that were used to integrate AngularJS. Numerous snapshots are provided with the goal to make our approach very clear.&lt;br /&gt;
&lt;br /&gt;
== Login Page and Navigation Bar ==&lt;br /&gt;
Login procedure:&lt;br /&gt;
‘Login’ button clicked → auth_controller#login → auth_controller#after_login(user) → if user.role != ‘student’ → tree_display#drill → tree_display#list&amp;lt;br/&amp;gt;&lt;br /&gt;
If session[:menu] is defined, that is, when a user is logging in, the page will render the content of variable session[:menu].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
       &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
          :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
     &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
         :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
 &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each menu item in the nav bar, it is a dropdown menu now. For different level of dropdown menu, we apply different CSS style to it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% level += 1 %&amp;gt;&lt;br /&gt;
&amp;lt;% items.each do |item_id|&lt;br /&gt;
  item = session[:menu].get_item(item_id)&lt;br /&gt;
  selected = session[:menu].selected?(item.id)&lt;br /&gt;
  long_name = item.name.split(/\W/).collect{|word| word.capitalize}.join(' ')&lt;br /&gt;
%&amp;gt;&lt;br /&gt;
&amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown first-level&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% elsif level == 2 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown-submenu&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% else %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;lt;%= URI.encode(&amp;quot;/menu/#{item.name}&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;%= if item.children&lt;br /&gt;
        ' class=&amp;quot;daddy&amp;quot;'&lt;br /&gt;
      end %&amp;gt;title='&amp;lt;%= long_name %&amp;gt;'&amp;gt;&amp;lt;%= item.label.html_safe %&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
    &amp;lt;% if item.children -%&amp;gt;&lt;br /&gt;
    &amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu multi-level&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
    &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
      &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
    &amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Please also refer to app/assets/application.css.scss for further details.&lt;br /&gt;
&lt;br /&gt;
== Manage-course page ==&lt;br /&gt;
=== Design ===&lt;br /&gt;
After logging in, only the table frame is loaded into the page by rails. Then AngularJS takes over in the background and populate the content into the table. After all first-level content is populated into the table, in this case, all courses info belongs to the first level and their assignment is the second-level content.&lt;br /&gt;
&lt;br /&gt;
After all first level content is loaded into the table, the Angular controller starts to initialize POST request for second level content.&lt;br /&gt;
&lt;br /&gt;
In all, rendering the tree_display page is divided into 3 steps: &amp;lt;br&amp;gt;&lt;br /&gt;
1. render the table frame,  &amp;lt;br&amp;gt;&lt;br /&gt;
2. render the first level table content. &amp;lt;br&amp;gt;&lt;br /&gt;
3. fetch deeper level data. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the past, these 3 steps are done before rendering the page, which takes about 10-20 seconds. But now, it takes only 2-3 seconds to finish the first 2 steps, and 2 more seconds for the 3rd step.&lt;br /&gt;
&lt;br /&gt;
Moreover, the sorting and table record filtering is integrated into the table. No redirecting or re-rendering is needed for sorting or filtering, which was needed in the past.&lt;br /&gt;
&lt;br /&gt;
=== Code details ===&lt;br /&gt;
Pass Rails controller params to view in tree_display_controller#list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
angularParams = {}&lt;br /&gt;
angularParams[:search] = @search&lt;br /&gt;
angularParams[:show] = @show&lt;br /&gt;
angularParams[:child_nodes] = @child_nodes&lt;br /&gt;
angularParams[:sortvar] = @sortvar&lt;br /&gt;
angularParams[:sortorder] = @sortorder&lt;br /&gt;
angularParams[:user_id] = session[:user].id&lt;br /&gt;
angularParams[:nodeType] = 'FolderNode'&lt;br /&gt;
@angularParamsJSON = angularParams.to_json&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the view passes to AngularJS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-controller='TreeCtrl'&amp;gt;&lt;br /&gt;
&amp;lt;div ng-init=&amp;quot;init('&amp;lt;%= @angularParamsJSON %&amp;gt;')&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
AngularJS handles it, after all basic elements are loaded onto the page. Then AngularJS initializes a POST request for retrieving more data to populate the table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.angularParams = JSON.parse(value)&lt;br /&gt;
    $http.post('/tree_display/get_children_node_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.angularParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      $scope.tableContent = {}&lt;br /&gt;
      $scope.displayTableContent = {}&lt;br /&gt;
      $scope.lastLoadNum = {}&lt;br /&gt;
      $scope.typeList = []&lt;br /&gt;
      console.log data&lt;br /&gt;
      for nodeType, outerNode of data&lt;br /&gt;
        $scope.tableContent[nodeType] = []&lt;br /&gt;
        $scope.lastLoadNum[nodeType] = 0&lt;br /&gt;
        $scope.displayTableContent[nodeType] = []&lt;br /&gt;
        $scope.typeList.push nodeType&lt;br /&gt;
        # outerNode is the Assignments/Courses/Questionnaires&lt;br /&gt;
        for node in outerNode&lt;br /&gt;
          $scope.tableContent[nodeType].push node&lt;br /&gt;
          $scope.fetchCellContent(nodeType, node)&lt;br /&gt;
        $scope.getMoreContent(nodeType, 1)&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fetch table cell content recursively and put them into a hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.fetchCellContent = (nodeType, node) -&amp;gt;&lt;br /&gt;
    $scope.newParams = {}&lt;br /&gt;
    $scope.newParams[&amp;quot;sortvar&amp;quot;] = $scope.angularParams[&amp;quot;sortvar&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;sortorder&amp;quot;] = $scope.angularParams[&amp;quot;sortorder&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;search&amp;quot;] = $scope.angularParams[&amp;quot;search&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;show&amp;quot;] = $scope.angularParams[&amp;quot;show&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;user_id&amp;quot;] = $scope.angularParams[&amp;quot;user_id&amp;quot;]&lt;br /&gt;
    key = node.name + &amp;quot;|&amp;quot; + node.directory&lt;br /&gt;
    $scope.newParams[&amp;quot;key&amp;quot;] = key&lt;br /&gt;
    # console.log key&lt;br /&gt;
    if nodeType == 'Assignments'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'AssignmentNode'&lt;br /&gt;
    else if nodeType == 'Courses'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'CourseNode'&lt;br /&gt;
    else if nodeType == 'Questionnaires'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'FolderNode'&lt;br /&gt;
    else&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
    $scope.newParams[&amp;quot;child_nodes&amp;quot;] = node.nodeinfo&lt;br /&gt;
    $http.post('/tree_display/get_children_node_2_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.newParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      if data.length &amp;gt; 0&lt;br /&gt;
        for newNode in data&lt;br /&gt;
          if not $scope.allData[newNode.key]&lt;br /&gt;
            $scope.allData[newNode.key] = []&lt;br /&gt;
          $scope.display[newNode.key] = false&lt;br /&gt;
          $scope.allData[newNode.key].push newNode&lt;br /&gt;
          $scope.fetchCellContent(newNode.type, newNode)&lt;br /&gt;
&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After all data is fetched, the Rails view is able to presenting them onto the page!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;record in displayTableContent['Courses'] | filter:searchText | orderBy:predicate:reverse&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;tr ng-click=&amp;quot;showCellContent(record.name, record.directory)&amp;quot; class=&amp;quot;clickable-row&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
              &lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
          &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot; ng-if=&amp;quot;display[record.name+'|'+record.directory] &amp;amp;&amp;amp; allData[record.name+'|'+record.directory]&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;table class=&amp;quot;normal-table table table-bordered table-striped compact-table&amp;quot; ng-repeat=&amp;quot;cell in cellContent&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;tbody&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;: {{cell.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Directory&amp;lt;/b&amp;gt;: {{cell.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Creation Date&amp;lt;/b&amp;gt;: {{cell.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Modified Date&amp;lt;/b&amp;gt;: {{cell.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
              &amp;lt;/tbody&amp;gt;&lt;br /&gt;
            &amp;lt;/table&amp;gt;&lt;br /&gt;
          &amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
        &amp;lt;/tbody&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manage Users page ==&lt;br /&gt;
&lt;br /&gt;
===Design===&lt;br /&gt;
&lt;br /&gt;
Once logged in, choosing Manage/users option from the navbar, gets us routed to /users page which is defined in list.html.erb file. This file can be broken down to 5 constituents:&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users &amp;lt;br&amp;gt;&lt;br /&gt;
2) Paginating Users &amp;lt;br&amp;gt;&lt;br /&gt;
3) Searching Users &amp;lt;br&amp;gt;&lt;br /&gt;
4) Showing Users &amp;lt;br&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Details===&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users&lt;br /&gt;
Fetching users was challenging at first due to an extremely large number of user entries (total of 5300). Fetch of such large data produced a very long delay that was one of the major UX problems in legacy version of Expertiza. This problem has been solved with Angular by sending a post request that gets 300 users and then another post request which gets all the users. This approach provides a quick response and the first 300 users can be seen right away in the form of 3 pages (default set to 100 users per page). While the user is looking at the first couple of entries, the rest of the entries are fetched in the background. This allows for a fast response, full functionality as well as complete data.&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.getUsers = (fn) -&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    $http.post('/users/get_users_ng', {&lt;br /&gt;
      'fetchNumber': fn&lt;br /&gt;
    })&lt;br /&gt;
    .success((receivedUsers) -&amp;gt;&lt;br /&gt;
      console.log receivedUsers&lt;br /&gt;
      for user in receivedUsers&lt;br /&gt;
        $scope.users.push user&lt;br /&gt;
        $scope.user_display[user.object.id] = false&lt;br /&gt;
        $scope.editProfileVisible[user.object.id] = false&lt;br /&gt;
&lt;br /&gt;
      $scope.fetchNumber+=1&lt;br /&gt;
      console.log $scope.users.length&lt;br /&gt;
      console.log $scope.listSize&lt;br /&gt;
&lt;br /&gt;
      if $scope.users.length &amp;lt; $scope.listSize&lt;br /&gt;
        $scope.getUsers($scope.fetchNumber)&lt;br /&gt;
      )&lt;br /&gt;
&lt;br /&gt;
  $scope.getUserListSize = () -&amp;gt;&lt;br /&gt;
    $http.get('/users/get_users_list_ng')&lt;br /&gt;
    .success((listSize) -&amp;gt;&lt;br /&gt;
      $scope.listSize = listSize&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This process is initiated by init() command shown bellow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.user_display = {}&lt;br /&gt;
    $scope.editProfileVisible = {}&lt;br /&gt;
    if $scope.users.length == $scope.listSize&lt;br /&gt;
      return&lt;br /&gt;
    else if $scope.users.length == 0&lt;br /&gt;
      $scope.listSize = 0&lt;br /&gt;
      $scope.getUserListSize()&lt;br /&gt;
      $scope.fetchNumber = 0&lt;br /&gt;
    $scope.getUsers(($scope.fetchNumber))&lt;br /&gt;
    $scope.currentPage = 0&lt;br /&gt;
    $scope.pagination(50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The view resulting from this code structure can be seen bellow:&lt;br /&gt;
&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
2) Paginating Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to paginate users, a filter needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The startFrom:currentPage*pageSize portion of the filter calls the custom filter startFrom which simply splits the data to display based on the current page of pagination (currentPage), multiplied by the number of users to display (pageSize, which is set by the user selecting either All, 25, 50, 100, or 250).&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app.filter 'startFrom', -&amp;gt;&lt;br /&gt;
  (input, start) -&amp;gt;&lt;br /&gt;
    start = +start&lt;br /&gt;
    return input.slice start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The limitTo:pageSize is a built in angular filter that says to stop displaying users after pageSize of them have been displayed.&lt;br /&gt;
&lt;br /&gt;
The aforementioned pageSize is set by the user through a dropdown; This code tells the dropdown to set the default paginate value to 100 users per page, and upon an ng-change (user selecting a different value), the pagination method will be called in app.coffee, with the appropriate pageSize:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;label&amp;gt;Paginate By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;paginate&amp;quot; ng-init=&amp;quot;paginate='50'&amp;quot; ng-change=&amp;quot;pagination(paginate)&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;All&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;25&amp;quot;&amp;gt;25&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;50&amp;quot;&amp;gt;50&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;100&amp;quot;&amp;gt;100&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;250&amp;quot;&amp;gt;250&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in app.coffee, and it posts the pageSize to the set_page_size method in the users_controller, and then sets various variable values based on the results:&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.pagination = (ps) -&amp;gt;&lt;br /&gt;
    $http.post('/users/set_page_size', {&lt;br /&gt;
      'pageSize': ps&lt;br /&gt;
    })&lt;br /&gt;
    .success((value) -&amp;gt;&lt;br /&gt;
      $scope.pageSize = value[0]&lt;br /&gt;
      $scope.div = value[1]&lt;br /&gt;
      $scope.totalSize = value[2]&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is in users_controller and it takes in the user defined pageSize variable and then determines how many pages are required to divide the data into based off of the pageSize, then returns that variable, plus others:&lt;br /&gt;
&lt;br /&gt;
In app/controllers/user_controller:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def set_page_size&lt;br /&gt;
    ps = params[:pageSize].to_i&lt;br /&gt;
    user = session[:user]&lt;br /&gt;
    role = Role.find(user.role_id)&lt;br /&gt;
    all_users = User.order('name').where( ['role_id in (?) or id = ?', role.get_available_roles, user.id])&lt;br /&gt;
    users_length = all_users.length&lt;br /&gt;
    if ps == 0&lt;br /&gt;
      pageSize = users_length&lt;br /&gt;
    else&lt;br /&gt;
      pageSize = ps&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    div = (users_length/pageSize.to_f).ceil&lt;br /&gt;
    &lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: [pageSize, div, users_length]}&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once the number of pages and pageSize has been set, those numbers are then used to show the current and remaining pages to go along with the previous and next buttons:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;paginate-button&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-left&amp;quot; ng-disabled=&amp;quot;currentPage == 0&amp;quot; ng-click=&amp;quot;currentPage=currentPage-1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
  {{currentPage+1}}/{{div}}&lt;br /&gt;
  &amp;lt;button class=&amp;quot;glyphicon glyphicon-chevron-right&amp;quot; ng-disabled=&amp;quot;currentPage &amp;gt;= totalSize/pageSize - 1&amp;quot; ng-click=&amp;quot;currentPage=currentPage+1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/button&amp;gt;&lt;br /&gt;
 &amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) Searching Users&lt;br /&gt;
&lt;br /&gt;
[[File:Pag_src.png]]&lt;br /&gt;
&lt;br /&gt;
In order to search users, a filter also needs to be set in order to limit the number of users being shown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;user in users | filter:search | startFrom:currentPage*pageSize | limitTo:pageSize&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;tr ng-click=&amp;quot;showUser(user.object.id)&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.fullname}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.object.email}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.role}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.parent}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_submission}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.email_on_review_of_review}}&amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;td&amp;gt;{{user.leaderboard_privacy}}&amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;/tr&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The filter:search portion of this code simply applies the following filter criteria; the type of search is determined a dropdown (either search by any field, name, fullname, or email fields). Based on the dropdown selection, the correct search box will be shown, once that search box is show, the search criteria is set to correspond to the type of search specified by the dropdown:&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;pull-right form-group&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;form-inline&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label&amp;gt;Search By: &lt;br /&gt;
    &amp;lt;select class=&amp;quot;form-control&amp;quot; ng-model=&amp;quot;searchtype&amp;quot; ng-init=&amp;quot;searchtype='any'&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;any&amp;quot;&amp;gt;Any&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;name&amp;quot;&amp;gt;Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;fullname&amp;quot;&amp;gt;Full Name&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;email&amp;quot;&amp;gt;Email&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
  &amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'any'&amp;quot; ng-model=&amp;quot;search.object.$&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'name'&amp;quot; ng-model=&amp;quot;search.object.name&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'fullname'&amp;quot; ng-model=&amp;quot;search.object.fullname&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input class=&amp;quot;form-control&amp;quot; ng-hide=&amp;quot;searchtype != 'email'&amp;quot; ng-model=&amp;quot;search.object.email&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) Showing Users&lt;br /&gt;
Clicking on each user name in the table of users uncovers a template that shows the information about that specific user. This is accomplished in a very simple way by setting the profileVisible flag to true. The information about that specific user is extracted from displayedUser object provided by showUser() method from UsersPageCtrl controller in app.coffee file.&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-if=&amp;quot;profileVisible == true&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h1&amp;gt;&amp;lt;b&amp;gt;User: {{displayedUser.object.name}}&amp;lt;/b&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Full Name: &amp;lt;/b&amp;gt;{{displayedUser.object.fullname}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Email Address: &amp;lt;/b&amp;gt;{{displayedUser.object.email}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Role: &amp;lt;/b&amp;gt;{{displayedUser.role}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;showTable(true)&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-primary&amp;quot;&amp;gt;Back&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;editUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-success&amp;quot;&amp;gt;Edit&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;deleteUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-danger&amp;quot;&amp;gt;Delete&amp;lt;/button&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.showUser = (user_id) -&amp;gt;&lt;br /&gt;
    $scope.user_display[user_id] = !$scope.user_display[user_id]&lt;br /&gt;
    $scope.editProfileVisible[user_id] = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users&lt;br /&gt;
&lt;br /&gt;
Editing Users is implemented in a similar way as showing users. The template contains ng-if statement which allows us to display edit page for each user. editUser() method from UsersPageCtrl controller specified in app.coffee displays information of the displayedUser but only after the Save button is clicked it saves the information from displayedUsers into updatedUser variable. POST request with :id parameter is then sent to update method in users_controller of Rails, which then updates this user information in the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.editUser = (user) -&amp;gt;&lt;br /&gt;
    # $scope.showUser(false)&lt;br /&gt;
    $scope.editProfileVisible[user.object.id] = !$scope.editProfileVisible[user.object.id]&lt;br /&gt;
    $scope.updatedUser = user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97039</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97039"/>
		<updated>2015-05-03T18:39:20Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Guide for future students =&lt;br /&gt;
1. Learn how to integrate AngularJS into Rails, using Rails original routing system.&lt;br /&gt;
&lt;br /&gt;
2. Learn AngularJS and Coffeescript, since the app.js is written in Coffeescript now.&lt;br /&gt;
&lt;br /&gt;
3. Learn Bootstrap, including the grid system, responsive design and etc.&lt;br /&gt;
&lt;br /&gt;
4. Read the code written by us, to know &lt;br /&gt;
&lt;br /&gt;
    a. how to pass data from Rails controller and view to AngularJS; &lt;br /&gt;
    b. how to pass data back to Rails view from AngularJS; &lt;br /&gt;
    c. how to convert JSON formatted data using in AngularJS to Rails hash and vice versa.&lt;br /&gt;
    d. how to present the data to Rails view&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD the following content to the config/application.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js&lt;br /&gt;
&lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;code&amp;gt; div ng-app='MPApp'&amp;lt;/code&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;br /&gt;
&lt;br /&gt;
=The specifics=&lt;br /&gt;
This section explains the very detailed actions and their results related to the 3 specific pages that were used to integrate AngularJS. Numerous snapshots are provided with the goal to make our approach very clear.&lt;br /&gt;
&lt;br /&gt;
== Login Page and Navigation Bar ==&lt;br /&gt;
Login procedure:&lt;br /&gt;
‘Login’ button clicked → auth_controller#login → auth_controller#after_login(user) → if user.role != ‘student’ → tree_display#drill → tree_display#list&amp;lt;br/&amp;gt;&lt;br /&gt;
If session[:menu] is defined, that is, when a user is logging in, the page will render the content of variable session[:menu].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
       &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
          :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
     &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
         :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
 &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each menu item in the nav bar, it is a dropdown menu now. For different level of dropdown menu, we apply different CSS style to it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% level += 1 %&amp;gt;&lt;br /&gt;
&amp;lt;% items.each do |item_id|&lt;br /&gt;
  item = session[:menu].get_item(item_id)&lt;br /&gt;
  selected = session[:menu].selected?(item.id)&lt;br /&gt;
  long_name = item.name.split(/\W/).collect{|word| word.capitalize}.join(' ')&lt;br /&gt;
%&amp;gt;&lt;br /&gt;
&amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown first-level&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% elsif level == 2 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown-submenu&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% else %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;lt;%= URI.encode(&amp;quot;/menu/#{item.name}&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;%= if item.children&lt;br /&gt;
        ' class=&amp;quot;daddy&amp;quot;'&lt;br /&gt;
      end %&amp;gt;title='&amp;lt;%= long_name %&amp;gt;'&amp;gt;&amp;lt;%= item.label.html_safe %&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
    &amp;lt;% if item.children -%&amp;gt;&lt;br /&gt;
    &amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu multi-level&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
    &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
      &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
    &amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Please also refer to app/assets/application.css.scss for further details.&lt;br /&gt;
&lt;br /&gt;
== Manage-course page ==&lt;br /&gt;
=== Design ===&lt;br /&gt;
After logging in, only the table frame is loaded into the page by rails. Then AngularJS takes over in the background and populate the content into the table. After all first-level content is populated into the table, in this case, all courses info belongs to the first level and their assignment is the second-level content.&lt;br /&gt;
&lt;br /&gt;
After all first level content is loaded into the table, the Angular controller starts to initialize POST request for second level content.&lt;br /&gt;
&lt;br /&gt;
In all, rendering the tree_display page is divided into 3 steps: &amp;lt;br&amp;gt;&lt;br /&gt;
1. render the table frame,  &amp;lt;br&amp;gt;&lt;br /&gt;
2. render the first level table content. &amp;lt;br&amp;gt;&lt;br /&gt;
3. fetch deeper level data. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the past, these 3 steps are done before rendering the page, which takes about 10-20 seconds. But now, it takes only 2-3 seconds to finish the first 2 steps, and 2 more seconds for the 3rd step.&lt;br /&gt;
&lt;br /&gt;
Moreover, the sorting and table record filtering is integrated into the table. No redirecting or re-rendering is needed for sorting or filtering, which was needed in the past.&lt;br /&gt;
&lt;br /&gt;
=== Code details ===&lt;br /&gt;
Pass Rails controller params to view in tree_display_controller#list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
angularParams = {}&lt;br /&gt;
angularParams[:search] = @search&lt;br /&gt;
angularParams[:show] = @show&lt;br /&gt;
angularParams[:child_nodes] = @child_nodes&lt;br /&gt;
angularParams[:sortvar] = @sortvar&lt;br /&gt;
angularParams[:sortorder] = @sortorder&lt;br /&gt;
angularParams[:user_id] = session[:user].id&lt;br /&gt;
angularParams[:nodeType] = 'FolderNode'&lt;br /&gt;
@angularParamsJSON = angularParams.to_json&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the view passes to AngularJS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-controller='TreeCtrl'&amp;gt;&lt;br /&gt;
&amp;lt;div ng-init=&amp;quot;init('&amp;lt;%= @angularParamsJSON %&amp;gt;')&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
AngularJS handles it, after all basic elements are loaded onto the page. Then AngularJS initializes a POST request for retrieving more data to populate the table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.angularParams = JSON.parse(value)&lt;br /&gt;
    $http.post('/tree_display/get_children_node_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.angularParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      $scope.tableContent = {}&lt;br /&gt;
      $scope.displayTableContent = {}&lt;br /&gt;
      $scope.lastLoadNum = {}&lt;br /&gt;
      $scope.typeList = []&lt;br /&gt;
      console.log data&lt;br /&gt;
      for nodeType, outerNode of data&lt;br /&gt;
        $scope.tableContent[nodeType] = []&lt;br /&gt;
        $scope.lastLoadNum[nodeType] = 0&lt;br /&gt;
        $scope.displayTableContent[nodeType] = []&lt;br /&gt;
        $scope.typeList.push nodeType&lt;br /&gt;
        # outerNode is the Assignments/Courses/Questionnaires&lt;br /&gt;
        for node in outerNode&lt;br /&gt;
          $scope.tableContent[nodeType].push node&lt;br /&gt;
          $scope.fetchCellContent(nodeType, node)&lt;br /&gt;
        $scope.getMoreContent(nodeType, 1)&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fetch table cell content recursively and put them into a hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.fetchCellContent = (nodeType, node) -&amp;gt;&lt;br /&gt;
    $scope.newParams = {}&lt;br /&gt;
    $scope.newParams[&amp;quot;sortvar&amp;quot;] = $scope.angularParams[&amp;quot;sortvar&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;sortorder&amp;quot;] = $scope.angularParams[&amp;quot;sortorder&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;search&amp;quot;] = $scope.angularParams[&amp;quot;search&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;show&amp;quot;] = $scope.angularParams[&amp;quot;show&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;user_id&amp;quot;] = $scope.angularParams[&amp;quot;user_id&amp;quot;]&lt;br /&gt;
    key = node.name + &amp;quot;|&amp;quot; + node.directory&lt;br /&gt;
    $scope.newParams[&amp;quot;key&amp;quot;] = key&lt;br /&gt;
    # console.log key&lt;br /&gt;
    if nodeType == 'Assignments'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'AssignmentNode'&lt;br /&gt;
    else if nodeType == 'Courses'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'CourseNode'&lt;br /&gt;
    else if nodeType == 'Questionnaires'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'FolderNode'&lt;br /&gt;
    else&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
    $scope.newParams[&amp;quot;child_nodes&amp;quot;] = node.nodeinfo&lt;br /&gt;
    $http.post('/tree_display/get_children_node_2_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.newParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      if data.length &amp;gt; 0&lt;br /&gt;
        for newNode in data&lt;br /&gt;
          if not $scope.allData[newNode.key]&lt;br /&gt;
            $scope.allData[newNode.key] = []&lt;br /&gt;
          $scope.display[newNode.key] = false&lt;br /&gt;
          $scope.allData[newNode.key].push newNode&lt;br /&gt;
          $scope.fetchCellContent(newNode.type, newNode)&lt;br /&gt;
&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After all data is fetched, the Rails view is able to presenting them onto the page!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;record in displayTableContent['Courses'] | filter:searchText | orderBy:predicate:reverse&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;tr ng-click=&amp;quot;showCellContent(record.name, record.directory)&amp;quot; class=&amp;quot;clickable-row&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
              &lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
          &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot; ng-if=&amp;quot;display[record.name+'|'+record.directory] &amp;amp;&amp;amp; allData[record.name+'|'+record.directory]&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;table class=&amp;quot;normal-table table table-bordered table-striped compact-table&amp;quot; ng-repeat=&amp;quot;cell in cellContent&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;tbody&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;: {{cell.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Directory&amp;lt;/b&amp;gt;: {{cell.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Creation Date&amp;lt;/b&amp;gt;: {{cell.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Modified Date&amp;lt;/b&amp;gt;: {{cell.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
              &amp;lt;/tbody&amp;gt;&lt;br /&gt;
            &amp;lt;/table&amp;gt;&lt;br /&gt;
          &amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
        &amp;lt;/tbody&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manage Users page ==&lt;br /&gt;
&lt;br /&gt;
===Design===&lt;br /&gt;
&lt;br /&gt;
Once logged in, choosing Manage/users option from the navbar, gets us routed to /users page which is defined in list.html.erb file. This file can be broken down to 5 constituents:&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users &amp;lt;br&amp;gt;&lt;br /&gt;
2) Paginating Users &amp;lt;br&amp;gt;&lt;br /&gt;
3) Searching Users &amp;lt;br&amp;gt;&lt;br /&gt;
4) Showing Users &amp;lt;br&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Details===&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users&lt;br /&gt;
Fetching users was challenging at first due to an extremely large number of user entries (total of 5300). Fetch of such large data produced a very long delay that was one of the major UX problems in legacy version of Expertiza. This problem has been solved with Angular by sending a post request that gets 300 users and then another post request which gets all the users. This approach provides a quick response and the first 300 users can be seen right away in the form of 3 pages (default set to 100 users per page). While the user is looking at the first couple of entries, the rest of the entries are fetched in the background. This allows for a fast response, full functionality as well as complete data.&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.getUsers = (fn) -&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    $http.post('/users/get_users_ng', {&lt;br /&gt;
      'fetchNumber': fn&lt;br /&gt;
    })&lt;br /&gt;
    .success((receivedUsers) -&amp;gt;&lt;br /&gt;
      console.log receivedUsers&lt;br /&gt;
      for user in receivedUsers&lt;br /&gt;
        $scope.users.push user&lt;br /&gt;
        $scope.user_display[user.object.id] = false&lt;br /&gt;
        $scope.editProfileVisible[user.object.id] = false&lt;br /&gt;
&lt;br /&gt;
      $scope.fetchNumber+=1&lt;br /&gt;
      console.log $scope.users.length&lt;br /&gt;
      console.log $scope.listSize&lt;br /&gt;
&lt;br /&gt;
      if $scope.users.length &amp;lt; $scope.listSize&lt;br /&gt;
        $scope.getUsers($scope.fetchNumber)&lt;br /&gt;
      )&lt;br /&gt;
&lt;br /&gt;
  $scope.getUserListSize = () -&amp;gt;&lt;br /&gt;
    $http.get('/users/get_users_list_ng')&lt;br /&gt;
    .success((listSize) -&amp;gt;&lt;br /&gt;
      $scope.listSize = listSize&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This process is initiated by init() command shown bellow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.user_display = {}&lt;br /&gt;
    $scope.editProfileVisible = {}&lt;br /&gt;
    if $scope.users.length == $scope.listSize&lt;br /&gt;
      return&lt;br /&gt;
    else if $scope.users.length == 0&lt;br /&gt;
      $scope.listSize = 0&lt;br /&gt;
      $scope.getUserListSize()&lt;br /&gt;
      $scope.fetchNumber = 0&lt;br /&gt;
    $scope.getUsers(($scope.fetchNumber))&lt;br /&gt;
    $scope.currentPage = 0&lt;br /&gt;
    $scope.pagination(50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2) Paginating Users&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3) Searching Users&lt;br /&gt;
4) Showing Users&lt;br /&gt;
Clicking on each user name in the table of users uncovers a template that shows the information about that specific user. This is accomplished in a very simple way by setting the profileVisible flag to true. The information about that specific user is extracted from displayedUser object provided by showUser() method from UsersPageCtrl controller in app.coffee file.&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-if=&amp;quot;profileVisible == true&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h1&amp;gt;&amp;lt;b&amp;gt;User: {{displayedUser.object.name}}&amp;lt;/b&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Full Name: &amp;lt;/b&amp;gt;{{displayedUser.object.fullname}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Email Address: &amp;lt;/b&amp;gt;{{displayedUser.object.email}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Role: &amp;lt;/b&amp;gt;{{displayedUser.role}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;showTable(true)&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-primary&amp;quot;&amp;gt;Back&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;editUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-success&amp;quot;&amp;gt;Edit&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;deleteUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-danger&amp;quot;&amp;gt;Delete&amp;lt;/button&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.showUser = (user_id) -&amp;gt;&lt;br /&gt;
    $scope.user_display[user_id] = !$scope.user_display[user_id]&lt;br /&gt;
    $scope.editProfileVisible[user_id] = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users&lt;br /&gt;
&lt;br /&gt;
Editing Users is implemented in a similar way as showing users. The template contains ng-if statement which allows us to display edit page for each user. editUser() method from UsersPageCtrl controller specified in app.coffee displays information of the displayedUser but only after the Save button is clicked it saves the information from displayedUsers into updatedUser variable. POST request with :id parameter is then sent to update method in users_controller of Rails, which then updates this user information in the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.editUser = (user) -&amp;gt;&lt;br /&gt;
    # $scope.showUser(false)&lt;br /&gt;
    $scope.editProfileVisible[user.object.id] = !$scope.editProfileVisible[user.object.id]&lt;br /&gt;
    $scope.updatedUser = user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97038</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97038"/>
		<updated>2015-05-03T18:38:40Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Code Details */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Guide for future students =&lt;br /&gt;
1. Learn how to integrate AngularJS into Rails, using Rails original routing system.&lt;br /&gt;
&lt;br /&gt;
2. Learn AngularJS and Coffeescript, since the app.js is written in Coffeescript now.&lt;br /&gt;
&lt;br /&gt;
3. Learn Bootstrap, including the grid system, responsive design and etc.&lt;br /&gt;
&lt;br /&gt;
4. Read the code written by us, to know &lt;br /&gt;
&lt;br /&gt;
    a. how to pass data from Rails controller and view to AngularJS; &lt;br /&gt;
    b. how to pass data back to Rails view from AngularJS; &lt;br /&gt;
    c. how to convert JSON formatted data using in AngularJS to Rails hash and vice versa.&lt;br /&gt;
    d. how to present the data to Rails view&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD the following content to the config/application.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js&lt;br /&gt;
&lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;code&amp;gt; div ng-app='MPApp'&amp;lt;/code&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;br /&gt;
&lt;br /&gt;
=The specifics=&lt;br /&gt;
This section explains the very detailed actions and their results related to the 3 specific pages that were used to integrate AngularJS. Numerous snapshots are provided with the goal to make our approach very clear.&lt;br /&gt;
&lt;br /&gt;
== Login Page and Navigation Bar ==&lt;br /&gt;
Login procedure:&lt;br /&gt;
‘Login’ button clicked → auth_controller#login → auth_controller#after_login(user) → if user.role != ‘student’ → tree_display#drill → tree_display#list&amp;lt;br/&amp;gt;&lt;br /&gt;
If session[:menu] is defined, that is, when a user is logging in, the page will render the content of variable session[:menu].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
       &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
          :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
     &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
         :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
 &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each menu item in the nav bar, it is a dropdown menu now. For different level of dropdown menu, we apply different CSS style to it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% level += 1 %&amp;gt;&lt;br /&gt;
&amp;lt;% items.each do |item_id|&lt;br /&gt;
  item = session[:menu].get_item(item_id)&lt;br /&gt;
  selected = session[:menu].selected?(item.id)&lt;br /&gt;
  long_name = item.name.split(/\W/).collect{|word| word.capitalize}.join(' ')&lt;br /&gt;
%&amp;gt;&lt;br /&gt;
&amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown first-level&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% elsif level == 2 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown-submenu&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% else %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;lt;%= URI.encode(&amp;quot;/menu/#{item.name}&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;%= if item.children&lt;br /&gt;
        ' class=&amp;quot;daddy&amp;quot;'&lt;br /&gt;
      end %&amp;gt;title='&amp;lt;%= long_name %&amp;gt;'&amp;gt;&amp;lt;%= item.label.html_safe %&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
    &amp;lt;% if item.children -%&amp;gt;&lt;br /&gt;
    &amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu multi-level&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
    &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
      &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
    &amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Please also refer to app/assets/application.css.scss for further details.&lt;br /&gt;
&lt;br /&gt;
== Manage-course page ==&lt;br /&gt;
=== Design ===&lt;br /&gt;
After logging in, only the table frame is loaded into the page by rails. Then AngularJS takes over in the background and populate the content into the table. After all first-level content is populated into the table, in this case, all courses info belongs to the first level and their assignment is the second-level content.&lt;br /&gt;
&lt;br /&gt;
After all first level content is loaded into the table, the Angular controller starts to initialize POST request for second level content.&lt;br /&gt;
&lt;br /&gt;
In all, rendering the tree_display page is divided into 3 steps: &amp;lt;br&amp;gt;&lt;br /&gt;
1. render the table frame,  &amp;lt;br&amp;gt;&lt;br /&gt;
2. render the first level table content. &amp;lt;br&amp;gt;&lt;br /&gt;
3. fetch deeper level data. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the past, these 3 steps are done before rendering the page, which takes about 10-20 seconds. But now, it takes only 2-3 seconds to finish the first 2 steps, and 2 more seconds for the 3rd step.&lt;br /&gt;
&lt;br /&gt;
Moreover, the sorting and table record filtering is integrated into the table. No redirecting or re-rendering is needed for sorting or filtering, which was needed in the past.&lt;br /&gt;
&lt;br /&gt;
=== Code details ===&lt;br /&gt;
Pass Rails controller params to view in tree_display_controller#list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
angularParams = {}&lt;br /&gt;
angularParams[:search] = @search&lt;br /&gt;
angularParams[:show] = @show&lt;br /&gt;
angularParams[:child_nodes] = @child_nodes&lt;br /&gt;
angularParams[:sortvar] = @sortvar&lt;br /&gt;
angularParams[:sortorder] = @sortorder&lt;br /&gt;
angularParams[:user_id] = session[:user].id&lt;br /&gt;
angularParams[:nodeType] = 'FolderNode'&lt;br /&gt;
@angularParamsJSON = angularParams.to_json&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the view passes to AngularJS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-controller='TreeCtrl'&amp;gt;&lt;br /&gt;
&amp;lt;div ng-init=&amp;quot;init('&amp;lt;%= @angularParamsJSON %&amp;gt;')&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
AngularJS handles it, after all basic elements are loaded onto the page. Then AngularJS initializes a POST request for retrieving more data to populate the table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.angularParams = JSON.parse(value)&lt;br /&gt;
    $http.post('/tree_display/get_children_node_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.angularParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      $scope.tableContent = {}&lt;br /&gt;
      $scope.displayTableContent = {}&lt;br /&gt;
      $scope.lastLoadNum = {}&lt;br /&gt;
      $scope.typeList = []&lt;br /&gt;
      console.log data&lt;br /&gt;
      for nodeType, outerNode of data&lt;br /&gt;
        $scope.tableContent[nodeType] = []&lt;br /&gt;
        $scope.lastLoadNum[nodeType] = 0&lt;br /&gt;
        $scope.displayTableContent[nodeType] = []&lt;br /&gt;
        $scope.typeList.push nodeType&lt;br /&gt;
        # outerNode is the Assignments/Courses/Questionnaires&lt;br /&gt;
        for node in outerNode&lt;br /&gt;
          $scope.tableContent[nodeType].push node&lt;br /&gt;
          $scope.fetchCellContent(nodeType, node)&lt;br /&gt;
        $scope.getMoreContent(nodeType, 1)&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fetch table cell content recursively and put them into a hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.fetchCellContent = (nodeType, node) -&amp;gt;&lt;br /&gt;
    $scope.newParams = {}&lt;br /&gt;
    $scope.newParams[&amp;quot;sortvar&amp;quot;] = $scope.angularParams[&amp;quot;sortvar&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;sortorder&amp;quot;] = $scope.angularParams[&amp;quot;sortorder&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;search&amp;quot;] = $scope.angularParams[&amp;quot;search&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;show&amp;quot;] = $scope.angularParams[&amp;quot;show&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;user_id&amp;quot;] = $scope.angularParams[&amp;quot;user_id&amp;quot;]&lt;br /&gt;
    key = node.name + &amp;quot;|&amp;quot; + node.directory&lt;br /&gt;
    $scope.newParams[&amp;quot;key&amp;quot;] = key&lt;br /&gt;
    # console.log key&lt;br /&gt;
    if nodeType == 'Assignments'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'AssignmentNode'&lt;br /&gt;
    else if nodeType == 'Courses'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'CourseNode'&lt;br /&gt;
    else if nodeType == 'Questionnaires'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'FolderNode'&lt;br /&gt;
    else&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
    $scope.newParams[&amp;quot;child_nodes&amp;quot;] = node.nodeinfo&lt;br /&gt;
    $http.post('/tree_display/get_children_node_2_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.newParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      if data.length &amp;gt; 0&lt;br /&gt;
        for newNode in data&lt;br /&gt;
          if not $scope.allData[newNode.key]&lt;br /&gt;
            $scope.allData[newNode.key] = []&lt;br /&gt;
          $scope.display[newNode.key] = false&lt;br /&gt;
          $scope.allData[newNode.key].push newNode&lt;br /&gt;
          $scope.fetchCellContent(newNode.type, newNode)&lt;br /&gt;
&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After all data is fetched, the Rails view is able to presenting them onto the page!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;record in displayTableContent['Courses'] | filter:searchText | orderBy:predicate:reverse&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;tr ng-click=&amp;quot;showCellContent(record.name, record.directory)&amp;quot; class=&amp;quot;clickable-row&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
              &lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
          &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot; ng-if=&amp;quot;display[record.name+'|'+record.directory] &amp;amp;&amp;amp; allData[record.name+'|'+record.directory]&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;table class=&amp;quot;normal-table table table-bordered table-striped compact-table&amp;quot; ng-repeat=&amp;quot;cell in cellContent&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;tbody&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;: {{cell.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Directory&amp;lt;/b&amp;gt;: {{cell.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Creation Date&amp;lt;/b&amp;gt;: {{cell.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Modified Date&amp;lt;/b&amp;gt;: {{cell.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
              &amp;lt;/tbody&amp;gt;&lt;br /&gt;
            &amp;lt;/table&amp;gt;&lt;br /&gt;
          &amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
        &amp;lt;/tbody&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manage Users page ==&lt;br /&gt;
&lt;br /&gt;
===Design===&lt;br /&gt;
&lt;br /&gt;
Once logged in, choosing Manage/users option from the navbar, gets us routed to /users page which is defined in list.html.erb file. This file can be broken down to 5 constituents:&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users&lt;br /&gt;
2) Paginating Users&lt;br /&gt;
3) Searching Users&lt;br /&gt;
4) Showing Users&lt;br /&gt;
5) Editing and Deleting Users&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code Details===&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users&lt;br /&gt;
Fetching users was challenging at first due to an extremely large number of user entries (total of 5300). Fetch of such large data produced a very long delay that was one of the major UX problems in legacy version of Expertiza. This problem has been solved with Angular by sending a post request that gets 300 users and then another post request which gets all the users. This approach provides a quick response and the first 300 users can be seen right away in the form of 3 pages (default set to 100 users per page). While the user is looking at the first couple of entries, the rest of the entries are fetched in the background. This allows for a fast response, full functionality as well as complete data.&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.getUsers = (fn) -&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    $http.post('/users/get_users_ng', {&lt;br /&gt;
      'fetchNumber': fn&lt;br /&gt;
    })&lt;br /&gt;
    .success((receivedUsers) -&amp;gt;&lt;br /&gt;
      console.log receivedUsers&lt;br /&gt;
      for user in receivedUsers&lt;br /&gt;
        $scope.users.push user&lt;br /&gt;
        $scope.user_display[user.object.id] = false&lt;br /&gt;
        $scope.editProfileVisible[user.object.id] = false&lt;br /&gt;
&lt;br /&gt;
      $scope.fetchNumber+=1&lt;br /&gt;
      console.log $scope.users.length&lt;br /&gt;
      console.log $scope.listSize&lt;br /&gt;
&lt;br /&gt;
      if $scope.users.length &amp;lt; $scope.listSize&lt;br /&gt;
        $scope.getUsers($scope.fetchNumber)&lt;br /&gt;
      )&lt;br /&gt;
&lt;br /&gt;
  $scope.getUserListSize = () -&amp;gt;&lt;br /&gt;
    $http.get('/users/get_users_list_ng')&lt;br /&gt;
    .success((listSize) -&amp;gt;&lt;br /&gt;
      $scope.listSize = listSize&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This process is initiated by init() command shown bellow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.user_display = {}&lt;br /&gt;
    $scope.editProfileVisible = {}&lt;br /&gt;
    if $scope.users.length == $scope.listSize&lt;br /&gt;
      return&lt;br /&gt;
    else if $scope.users.length == 0&lt;br /&gt;
      $scope.listSize = 0&lt;br /&gt;
      $scope.getUserListSize()&lt;br /&gt;
      $scope.fetchNumber = 0&lt;br /&gt;
    $scope.getUsers(($scope.fetchNumber))&lt;br /&gt;
    $scope.currentPage = 0&lt;br /&gt;
    $scope.pagination(50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2) Paginating Users&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3) Searching Users&lt;br /&gt;
4) Showing Users&lt;br /&gt;
Clicking on each user name in the table of users uncovers a template that shows the information about that specific user. This is accomplished in a very simple way by setting the profileVisible flag to true. The information about that specific user is extracted from displayedUser object provided by showUser() method from UsersPageCtrl controller in app.coffee file.&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-if=&amp;quot;profileVisible == true&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h1&amp;gt;&amp;lt;b&amp;gt;User: {{displayedUser.object.name}}&amp;lt;/b&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Full Name: &amp;lt;/b&amp;gt;{{displayedUser.object.fullname}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Email Address: &amp;lt;/b&amp;gt;{{displayedUser.object.email}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Role: &amp;lt;/b&amp;gt;{{displayedUser.role}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;showTable(true)&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-primary&amp;quot;&amp;gt;Back&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;editUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-success&amp;quot;&amp;gt;Edit&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;deleteUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-danger&amp;quot;&amp;gt;Delete&amp;lt;/button&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.showUser = (user_id) -&amp;gt;&lt;br /&gt;
    $scope.user_display[user_id] = !$scope.user_display[user_id]&lt;br /&gt;
    $scope.editProfileVisible[user_id] = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users&lt;br /&gt;
&lt;br /&gt;
Editing Users is implemented in a similar way as showing users. The template contains ng-if statement which allows us to display edit page for each user. editUser() method from UsersPageCtrl controller specified in app.coffee displays information of the displayedUser but only after the Save button is clicked it saves the information from displayedUsers into updatedUser variable. POST request with :id parameter is then sent to update method in users_controller of Rails, which then updates this user information in the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.editUser = (user) -&amp;gt;&lt;br /&gt;
    # $scope.showUser(false)&lt;br /&gt;
    $scope.editProfileVisible[user.object.id] = !$scope.editProfileVisible[user.object.id]&lt;br /&gt;
    $scope.updatedUser = user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97037</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97037"/>
		<updated>2015-05-03T18:36:40Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Manage Users page */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Guide for future students =&lt;br /&gt;
1. Learn how to integrate AngularJS into Rails, using Rails original routing system.&lt;br /&gt;
&lt;br /&gt;
2. Learn AngularJS and Coffeescript, since the app.js is written in Coffeescript now.&lt;br /&gt;
&lt;br /&gt;
3. Learn Bootstrap, including the grid system, responsive design and etc.&lt;br /&gt;
&lt;br /&gt;
4. Read the code written by us, to know &lt;br /&gt;
&lt;br /&gt;
    a. how to pass data from Rails controller and view to AngularJS; &lt;br /&gt;
    b. how to pass data back to Rails view from AngularJS; &lt;br /&gt;
    c. how to convert JSON formatted data using in AngularJS to Rails hash and vice versa.&lt;br /&gt;
    d. how to present the data to Rails view&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD the following content to the config/application.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js&lt;br /&gt;
&lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;code&amp;gt; div ng-app='MPApp'&amp;lt;/code&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;br /&gt;
&lt;br /&gt;
=The specifics=&lt;br /&gt;
This section explains the very detailed actions and their results related to the 3 specific pages that were used to integrate AngularJS. Numerous snapshots are provided with the goal to make our approach very clear.&lt;br /&gt;
&lt;br /&gt;
== Login Page and Navigation Bar ==&lt;br /&gt;
Login procedure:&lt;br /&gt;
‘Login’ button clicked → auth_controller#login → auth_controller#after_login(user) → if user.role != ‘student’ → tree_display#drill → tree_display#list&amp;lt;br/&amp;gt;&lt;br /&gt;
If session[:menu] is defined, that is, when a user is logging in, the page will render the content of variable session[:menu].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
       &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
          :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
     &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul class=&amp;quot;nav navbar-nav&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;% if session[:menu] %&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish',&lt;br /&gt;
         :locals =&amp;gt; { items: session[:menu].get_menu(0), level: 0 } %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
 &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For each menu item in the nav bar, it is a dropdown menu now. For different level of dropdown menu, we apply different CSS style to it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% level += 1 %&amp;gt;&lt;br /&gt;
&amp;lt;% items.each do |item_id|&lt;br /&gt;
  item = session[:menu].get_item(item_id)&lt;br /&gt;
  selected = session[:menu].selected?(item.id)&lt;br /&gt;
  long_name = item.name.split(/\W/).collect{|word| word.capitalize}.join(' ')&lt;br /&gt;
%&amp;gt;&lt;br /&gt;
&amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown first-level&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% elsif level == 2 %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown-submenu&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% else %&amp;gt;&lt;br /&gt;
&amp;lt;li class=&amp;quot;dropdown&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;lt;%= URI.encode(&amp;quot;/menu/#{item.name}&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;%= if item.children&lt;br /&gt;
        ' class=&amp;quot;daddy&amp;quot;'&lt;br /&gt;
      end %&amp;gt;title='&amp;lt;%= long_name %&amp;gt;'&amp;gt;&amp;lt;%= item.label.html_safe %&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
    &amp;lt;% if item.children -%&amp;gt;&lt;br /&gt;
    &amp;lt;% if level == 1 %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu multi-level&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
    &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;dropdown-menu&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render :partial =&amp;gt; 'menu_items/suckerfish', :locals =&amp;gt; {:items =&amp;gt; item.children, :level =&amp;gt; level} %&amp;gt;&lt;br /&gt;
      &amp;lt;/ul&amp;gt;&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
    &amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;% end -%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Please also refer to app/assets/application.css.scss for further details.&lt;br /&gt;
&lt;br /&gt;
== Manage-course page ==&lt;br /&gt;
=== Design ===&lt;br /&gt;
After logging in, only the table frame is loaded into the page by rails. Then AngularJS takes over in the background and populate the content into the table. After all first-level content is populated into the table, in this case, all courses info belongs to the first level and their assignment is the second-level content.&lt;br /&gt;
&lt;br /&gt;
After all first level content is loaded into the table, the Angular controller starts to initialize POST request for second level content.&lt;br /&gt;
&lt;br /&gt;
In all, rendering the tree_display page is divided into 3 steps: &amp;lt;br&amp;gt;&lt;br /&gt;
1. render the table frame,  &amp;lt;br&amp;gt;&lt;br /&gt;
2. render the first level table content. &amp;lt;br&amp;gt;&lt;br /&gt;
3. fetch deeper level data. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the past, these 3 steps are done before rendering the page, which takes about 10-20 seconds. But now, it takes only 2-3 seconds to finish the first 2 steps, and 2 more seconds for the 3rd step.&lt;br /&gt;
&lt;br /&gt;
Moreover, the sorting and table record filtering is integrated into the table. No redirecting or re-rendering is needed for sorting or filtering, which was needed in the past.&lt;br /&gt;
&lt;br /&gt;
=== Code details ===&lt;br /&gt;
Pass Rails controller params to view in tree_display_controller#list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
angularParams = {}&lt;br /&gt;
angularParams[:search] = @search&lt;br /&gt;
angularParams[:show] = @show&lt;br /&gt;
angularParams[:child_nodes] = @child_nodes&lt;br /&gt;
angularParams[:sortvar] = @sortvar&lt;br /&gt;
angularParams[:sortorder] = @sortorder&lt;br /&gt;
angularParams[:user_id] = session[:user].id&lt;br /&gt;
angularParams[:nodeType] = 'FolderNode'&lt;br /&gt;
@angularParamsJSON = angularParams.to_json&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the view passes to AngularJS&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-controller='TreeCtrl'&amp;gt;&lt;br /&gt;
&amp;lt;div ng-init=&amp;quot;init('&amp;lt;%= @angularParamsJSON %&amp;gt;')&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
AngularJS handles it, after all basic elements are loaded onto the page. Then AngularJS initializes a POST request for retrieving more data to populate the table.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.angularParams = JSON.parse(value)&lt;br /&gt;
    $http.post('/tree_display/get_children_node_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.angularParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      $scope.tableContent = {}&lt;br /&gt;
      $scope.displayTableContent = {}&lt;br /&gt;
      $scope.lastLoadNum = {}&lt;br /&gt;
      $scope.typeList = []&lt;br /&gt;
      console.log data&lt;br /&gt;
      for nodeType, outerNode of data&lt;br /&gt;
        $scope.tableContent[nodeType] = []&lt;br /&gt;
        $scope.lastLoadNum[nodeType] = 0&lt;br /&gt;
        $scope.displayTableContent[nodeType] = []&lt;br /&gt;
        $scope.typeList.push nodeType&lt;br /&gt;
        # outerNode is the Assignments/Courses/Questionnaires&lt;br /&gt;
        for node in outerNode&lt;br /&gt;
          $scope.tableContent[nodeType].push node&lt;br /&gt;
          $scope.fetchCellContent(nodeType, node)&lt;br /&gt;
        $scope.getMoreContent(nodeType, 1)&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fetch table cell content recursively and put them into a hash&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.fetchCellContent = (nodeType, node) -&amp;gt;&lt;br /&gt;
    $scope.newParams = {}&lt;br /&gt;
    $scope.newParams[&amp;quot;sortvar&amp;quot;] = $scope.angularParams[&amp;quot;sortvar&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;sortorder&amp;quot;] = $scope.angularParams[&amp;quot;sortorder&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;search&amp;quot;] = $scope.angularParams[&amp;quot;search&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;show&amp;quot;] = $scope.angularParams[&amp;quot;show&amp;quot;]&lt;br /&gt;
    $scope.newParams[&amp;quot;user_id&amp;quot;] = $scope.angularParams[&amp;quot;user_id&amp;quot;]&lt;br /&gt;
    key = node.name + &amp;quot;|&amp;quot; + node.directory&lt;br /&gt;
    $scope.newParams[&amp;quot;key&amp;quot;] = key&lt;br /&gt;
    # console.log key&lt;br /&gt;
    if nodeType == 'Assignments'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'AssignmentNode'&lt;br /&gt;
    else if nodeType == 'Courses'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'CourseNode'&lt;br /&gt;
    else if nodeType == 'Questionnaires'&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = 'FolderNode'&lt;br /&gt;
    else&lt;br /&gt;
      $scope.newParams[&amp;quot;nodeType&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
    $scope.newParams[&amp;quot;child_nodes&amp;quot;] = node.nodeinfo&lt;br /&gt;
    $http.post('/tree_display/get_children_node_2_ng', {&lt;br /&gt;
      &amp;quot;angularParams&amp;quot;: $scope.newParams&lt;br /&gt;
      })&lt;br /&gt;
    .success((data) -&amp;gt;&lt;br /&gt;
      if data.length &amp;gt; 0&lt;br /&gt;
        for newNode in data&lt;br /&gt;
          if not $scope.allData[newNode.key]&lt;br /&gt;
            $scope.allData[newNode.key] = []&lt;br /&gt;
          $scope.display[newNode.key] = false&lt;br /&gt;
          $scope.allData[newNode.key].push newNode&lt;br /&gt;
          $scope.fetchCellContent(newNode.type, newNode)&lt;br /&gt;
&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After all data is fetched, the Rails view is able to presenting them onto the page!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;tbody ng-repeat=&amp;quot;record in displayTableContent['Courses'] | filter:searchText | orderBy:predicate:reverse&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;tr ng-click=&amp;quot;showCellContent(record.name, record.directory)&amp;quot; class=&amp;quot;clickable-row&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;{{record.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
            &amp;lt;td&amp;gt;&lt;br /&gt;
              &lt;br /&gt;
            &amp;lt;/td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
          &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot; ng-if=&amp;quot;display[record.name+'|'+record.directory] &amp;amp;&amp;amp; allData[record.name+'|'+record.directory]&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;table class=&amp;quot;normal-table table table-bordered table-striped compact-table&amp;quot; ng-repeat=&amp;quot;cell in cellContent&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;tbody&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;: {{cell.name}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Directory&amp;lt;/b&amp;gt;: {{cell.directory}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Creation Date&amp;lt;/b&amp;gt;: {{cell.creation_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr class=&amp;quot;no-cursor-tr no-color-tr&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Modified Date&amp;lt;/b&amp;gt;: {{cell.updated_date}}&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
              &amp;lt;/tbody&amp;gt;&lt;br /&gt;
            &amp;lt;/table&amp;gt;&lt;br /&gt;
          &amp;lt;/td&amp;gt;&lt;br /&gt;
          &amp;lt;/tr&amp;gt;&lt;br /&gt;
        &amp;lt;/tbody&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Manage Users page ==&lt;br /&gt;
&lt;br /&gt;
===Design===&lt;br /&gt;
&lt;br /&gt;
Once logged in, choosing Manage/users option from the navbar, gets us routed to /users page which is defined in list.html.erb file. This file can be broken down to 5 constituents:&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users&lt;br /&gt;
2) Paginating Users&lt;br /&gt;
3) Searching Users&lt;br /&gt;
4) Showing Users&lt;br /&gt;
5) Editing and Deleting Users&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Code Details===&lt;br /&gt;
&lt;br /&gt;
1) Fetching Users&lt;br /&gt;
Fetching users was challenging at first due to an extremely large number of user entries (total of 5300). Fetch of such large data produced a very long delay that was one of the major UX problems in legacy version of Expertiza. This problem has been solved with Angular by sending a post request that gets 300 users and then another post request which gets all the users. This approach provides a quick response and the first 300 users can be seen right away in the form of 3 pages (default set to 100 users per page). While the user is looking at the first couple of entries, the rest of the entries are fetched in the background. This allows for a fast response, full functionality as well as complete data.&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.getUsers = (fn) -&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    $http.post('/users/get_users_ng', {&lt;br /&gt;
      'fetchNumber': fn&lt;br /&gt;
    })&lt;br /&gt;
    .success((receivedUsers) -&amp;gt;&lt;br /&gt;
      console.log receivedUsers&lt;br /&gt;
      for user in receivedUsers&lt;br /&gt;
        $scope.users.push user&lt;br /&gt;
        $scope.user_display[user.object.id] = false&lt;br /&gt;
        $scope.editProfileVisible[user.object.id] = false&lt;br /&gt;
&lt;br /&gt;
      $scope.fetchNumber+=1&lt;br /&gt;
      console.log $scope.users.length&lt;br /&gt;
      console.log $scope.listSize&lt;br /&gt;
&lt;br /&gt;
      if $scope.users.length &amp;lt; $scope.listSize&lt;br /&gt;
        $scope.getUsers($scope.fetchNumber)&lt;br /&gt;
      )&lt;br /&gt;
&lt;br /&gt;
  $scope.getUserListSize = () -&amp;gt;&lt;br /&gt;
    $http.get('/users/get_users_list_ng')&lt;br /&gt;
    .success((listSize) -&amp;gt;&lt;br /&gt;
      $scope.listSize = listSize&lt;br /&gt;
      )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This process is initiated by init() command shown bellow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$scope.init = (value) -&amp;gt;&lt;br /&gt;
    $scope.user_display = {}&lt;br /&gt;
    $scope.editProfileVisible = {}&lt;br /&gt;
    if $scope.users.length == $scope.listSize&lt;br /&gt;
      return&lt;br /&gt;
    else if $scope.users.length == 0&lt;br /&gt;
      $scope.listSize = 0&lt;br /&gt;
      $scope.getUserListSize()&lt;br /&gt;
      $scope.fetchNumber = 0&lt;br /&gt;
    $scope.getUsers(($scope.fetchNumber))&lt;br /&gt;
    $scope.currentPage = 0&lt;br /&gt;
    $scope.pagination(50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2) Paginating Users&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3) Searching Users&lt;br /&gt;
4) Showing Users&lt;br /&gt;
Clicking on each user name in the table of users uncovers a template that shows the information about that specific user. This is accomplished in a very simple way by setting the profileVisible flag to true. The information about that specific user is extracted from displayedUser object provided by showUser() method from UsersPageCtrl controller in app.coffee file.&lt;br /&gt;
&lt;br /&gt;
In views/users/list.html.erb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div ng-if=&amp;quot;profileVisible == true&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h1&amp;gt;&amp;lt;b&amp;gt;User: {{displayedUser.object.name}}&amp;lt;/b&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Full Name: &amp;lt;/b&amp;gt;{{displayedUser.object.fullname}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Email Address: &amp;lt;/b&amp;gt;{{displayedUser.object.email}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Role: &amp;lt;/b&amp;gt;{{displayedUser.role}}&amp;lt;/h3&amp;gt;&lt;br /&gt;
  &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;showTable(true)&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-primary&amp;quot;&amp;gt;Back&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;editUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-success&amp;quot;&amp;gt;Edit&amp;lt;/button&amp;gt;&lt;br /&gt;
    &amp;lt;button ng-click=&amp;quot;deleteUser()&amp;quot; type=&amp;quot;button&amp;quot; class=&amp;quot;btn btn-danger&amp;quot;&amp;gt;Delete&amp;lt;/button&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In app/assets/javascripts/app.coffee:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  $scope.showUser = (user_id) -&amp;gt;&lt;br /&gt;
    $scope.user_display[user_id] = !$scope.user_display[user_id]&lt;br /&gt;
    $scope.editProfileVisible[user_id] = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
5) Editing and Deleting Users&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97021</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97021"/>
		<updated>2015-05-02T23:46:10Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle instal l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
to the config/application.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js, &lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;div ng-app='MPApp'&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;br /&gt;
&lt;br /&gt;
=The specifics=&lt;br /&gt;
This section explains the very detailed actions and their results related to the 3 specific pages that were used to integrate AngularJS. Numerous snapshots are provided with the goal to make our approach very clear.&lt;br /&gt;
&lt;br /&gt;
== Login Page ==&lt;br /&gt;
login&lt;br /&gt;
== Manage-course page ==&lt;br /&gt;
courses&lt;br /&gt;
== Manage Users page ==&lt;br /&gt;
users&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97020</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97020"/>
		<updated>2015-05-02T23:45:36Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle instal l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
to the config/application.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js, &lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;div ng-app='MPApp'&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;br /&gt;
&lt;br /&gt;
=The specifics=&lt;br /&gt;
This section explains the very detailed actions and their results related to the 3 specific pages that were used to integrate AngularJS. Numerous snapshots are provided with the goal to make our approach very clear.&lt;br /&gt;
&lt;br /&gt;
==Login Page==&lt;br /&gt;
&lt;br /&gt;
== Manage-course page ==&lt;br /&gt;
&lt;br /&gt;
== Manage Users page ==&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97019</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97019"/>
		<updated>2015-05-02T23:41:55Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Integration =&lt;br /&gt;
This section represent the cornerstone of this project. It consciously explains how Angular and Rails can be integrated into a powerful system capable of providing solid control over both the backend and frontend development of your application.&lt;br /&gt;
&lt;br /&gt;
== Steps to interconnect Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
These guidelines assume that you have a Rails project in place and that you are intending to add AngularJS to it now. Please follow the steps bellow:&lt;br /&gt;
&lt;br /&gt;
1. In the Gemfile, ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’, then REMOVE ‘gem turbolinks'&lt;br /&gt;
&lt;br /&gt;
2. run &amp;lt;pre&amp;gt; bundle instal l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Create a Bowerfile. It is used by AngularJS and it can be thought of as the Gemfile that Rails uses.&lt;br /&gt;
&lt;br /&gt;
4. In the Bowerfile, ADD asset ‘angular’ , asset ‘bootstrap-sass-official’, asset ‘angular-route’ AND asset ‘angular-boostrap’(for ui.bootstrap injection)&lt;br /&gt;
&lt;br /&gt;
5. run &amp;lt;pre&amp;gt; rake bower:install &amp;lt;/pre&amp;gt;. Bower installs dependencies in vender/assets/bower_components.&lt;br /&gt;
&lt;br /&gt;
6.  ADD&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
to the config/application.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js, &lt;br /&gt;
8. Rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. &lt;br /&gt;
&lt;br /&gt;
9. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
Since we are did not get to build a new website using AngularJS from scratch, it was a good idea to retain the routing system of Rails rather than implement it in AngularJS.&lt;br /&gt;
So, we added a new tag &amp;lt;div ng-app='MPApp'&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, named ‘MPApp’.&lt;br /&gt;
Then, for the home page app/views/content_pages/view.html.erb, we added a tag to make this page controlled by ‘testCtrl’, which was defined in app.coffee.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== AngularJS's point of view ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
Because it is not appropriate to let AngularJS to directly fetch data from the MySQL database, the only way we could load data was through a Rails controller. For example, it is possible to 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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
Instead of using the original Rails page, we decided to replace some forms and components using AngularJS directives, which enabled us to do some live modifications to the pages without loading.&lt;br /&gt;
&lt;br /&gt;
== Rails' point of view ==&lt;br /&gt;
The initial problem was how to provide entries from the database to AngularJS. We decided to create methods in Rails controller which will listen to the incoming AngulaJS and use a select statement to fetch a couple of entries from the database. These entries are then stored in a hash, converted to json and passed to AngularJS controller. AngularJS will then send another query request to Rails for the next set of entries. This strategy greatly reduces the loading time, making the time needed for representing the page kept at the minimum.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97018</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97018"/>
		<updated>2015-05-02T23:21:12Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Strategy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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 was to jumpstart this project by having all 4 team members work together on adding AngularJS to the Login page. Once the Login page was completed, we split in two groups. One group worked on implementing AngularJS on Manage-course page, while the other group worked on introducing AngularJS to Manage-User page.&lt;br /&gt;
The reasoning behind this strategy was that all of us working together on the Login page first allowed us to obtain some basic understanding of AngularJS and feel more comfortable using this impressively useful and powerful framework. We completed AngularJS constituents first by connecting some of the Rails controllers to AngularJS controllers and then, as a final step, we 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 a pretty straight-forward element of the project.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
Below are detailed explanations of essential constituents of this project.&lt;br /&gt;
&lt;br /&gt;
== AngularJS Implementation ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Database ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Integration of Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
Guidelines: &lt;br /&gt;
&lt;br /&gt;
a. ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’ and REMOVE ‘gem turbolinks’ from the Gemfile, THEN execute bundle install&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
c.  ADD&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
to the config/application.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
d. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js, &lt;br /&gt;
Then rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
So, we add a new tag &amp;lt;div ng-app='MPApp'&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, naming ‘MPApp’ in this case.&lt;br /&gt;
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.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97017</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97017"/>
		<updated>2015-05-02T19:37:03Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
Below are detailed explanations of essential constituents of this project.&lt;br /&gt;
&lt;br /&gt;
== AngularJS Implementation ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Database ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Integration of Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
Guidelines: &lt;br /&gt;
&lt;br /&gt;
a. ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’ and REMOVE ‘gem turbolinks’ from the Gemfile, THEN execute bundle install&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
c.  ADD&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
to the config/application.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
d. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js, &lt;br /&gt;
Then rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
So, we add a new tag &amp;lt;div ng-app='MPApp'&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, naming ‘MPApp’ in this case.&lt;br /&gt;
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.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97016</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97016"/>
		<updated>2015-05-02T19:36:36Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Strategy =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
Below are detailed explanations of essential constituents of this project.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== AngularJS Implementation ==&lt;br /&gt;
&lt;br /&gt;
1. Retrieving data from database&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Build custom directives&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Database ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Integration of Rails and AngularJS ==&lt;br /&gt;
&lt;br /&gt;
Guidelines: &lt;br /&gt;
&lt;br /&gt;
a. ADD gem ‘bower-rails’ AND gem ‘angular-rails-templates’ and REMOVE ‘gem turbolinks’ from the Gemfile, THEN execute bundle install&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
c.  ADD&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
config.assets.paths &amp;lt;&amp;lt; Rails.root.join(&amp;quot;vendor&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;bower_components&amp;quot;,&amp;quot;bootstrap-sass-official&amp;quot;,&amp;quot;assets&amp;quot;,&amp;quot;fonts&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
config.assets.precompile &amp;lt;&amp;lt; %r(.*.(?:eot|svg|ttf|woff|woff2)$) &lt;br /&gt;
to the config/application.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
d. REMOVE //= require turbolinks AND ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//= require angular/angular&lt;br /&gt;
//= require angular-route/angular-route&lt;br /&gt;
//= require angular-rails-templates&lt;br /&gt;
//= require angular-bootstrap &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to assets/javascripts/application.js, &lt;br /&gt;
Then rename assets/stylesheets/application.css to assets/stylesheets/application.css.scss. ADD &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets&amp;quot;; and&lt;br /&gt;
@import &amp;quot;bootstrap-sass-official/assets/stylesheets/bootstrap&amp;quot;; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to application.css.scss&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
So, we add a new tag &amp;lt;div ng-app='MPApp'&amp;gt; into the app/views/layout/application.html.erb to include all pages into the scope of our AngularJS app, naming ‘MPApp’ in this case.&lt;br /&gt;
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.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97015</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97015"/>
		<updated>2015-05-02T19:25:50Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= List of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
=Design Patterns=&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Structural Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;single bridge&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
[[File:E1526-1.png]]&lt;br /&gt;
&lt;br /&gt;
==Behavioral Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E1526-2.png]]&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97014</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97014"/>
		<updated>2015-05-02T19:25:35Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= List of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
=Design Patterns=&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Structural Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;single bridge&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
[[File:E1526-1.png]]&lt;br /&gt;
&lt;br /&gt;
==Behavioral Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E1526-2.png]]&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97013</id>
		<title>CSC/ECE 517 Spring 2015 E1526</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526&amp;diff=97013"/>
		<updated>2015-05-02T19:24:29Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: Created page with &amp;quot;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;  __TOC__  = Problem Statement =  Despite an amazing set of functionality Expertiza offers, there are n...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= List of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
=Design Patterns=&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Structural Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;single bridge&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
[[File:E1526-1.png]]&lt;br /&gt;
&lt;br /&gt;
==Behavioral Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E1526-2.png]]&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=97012</id>
		<title>CSC/ECE 517 Spring 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=97012"/>
		<updated>2015-05-02T19:23:30Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* FinalProject Report */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 17 WL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 5 ZX]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 6 TZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 4 RW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 7 SA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 9 RA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 14 RI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 1 DZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 20 HA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 3 RF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 12 LS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 13 MA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 2 WA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 21 QW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 23 MS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 10 GL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 27 VC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 22 SF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 15 SH]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 18 AS]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1502 wwj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1508 MRS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1504 IMV]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1505 xzl]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1509 lds]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1510 FLP]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1506 SYZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1504 AAC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1507 DG]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1502 GVJ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1503 EDT]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1503 RSA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1501 YWS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1501 OA]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Design Document==&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1526 MPRI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 S1503 LWJZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 S1524 FSZZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 M1503 EDTS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1529 GLDS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1525 TIAA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1522 Visualization]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1527 SWAR]]&lt;br /&gt;
&lt;br /&gt;
==FinalProject Report==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1526]]&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=97011</id>
		<title>CSC/ECE 517 Spring 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=97011"/>
		<updated>2015-05-02T19:22:29Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 17 WL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 5 ZX]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 6 TZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 4 RW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 7 SA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 9 RA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 14 RI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 1 DZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 20 HA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 3 RF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 12 LS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 13 MA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 2 WA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 21 QW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 23 MS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 10 GL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 27 VC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 22 SF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 15 SH]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 18 AS]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1502 wwj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1508 MRS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1504 IMV]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1505 xzl]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1509 lds]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1510 FLP]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1506 SYZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1504 AAC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1507 DG]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1502 GVJ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1503 EDT]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1503 RSA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1501 YWS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1501 OA]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Design Document==&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1526 MPRI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 S1503 LWJZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 S1524 FSZZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 M1503 EDTS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1529 GLDS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1525 TIAA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1522 Visualization]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1527 SWAR]]&lt;br /&gt;
&lt;br /&gt;
==FinalProject Report==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1526 MPRI]]&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96515</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96515"/>
		<updated>2015-04-08T01:26:59Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* 1. Replace Buttons and Links to Bootstrap styled Buttons */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
= Introduction to Expertiza =&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= List of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
=Design Patterns=&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Structural Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;single bridge&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Behavioral Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96514</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96514"/>
		<updated>2015-04-08T01:22:50Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* 2. Create new theme */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
= Introduction to Expertiza =&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= List of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
Numerous elements in the current version of Expertiza, like 'Back', are hyperlinks rather than buttons. Our goal is to replace this plain-styled text with color coded Bootstrap buttons.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
=Design Patterns=&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Structural Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;single bridge&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Behavioral Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96513</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96513"/>
		<updated>2015-04-08T01:18:19Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Design Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
= Introduction to Expertiza =&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= List of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
Numerous elements in the current version of Expertiza, like 'Back', are hyperlinks rather than buttons. Our goal is to replace this plain-styled text with color coded Bootstrap buttons.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
The theme of Expertiza looks primitive now, a new theme with fix menu on the top is much prefered.&lt;br /&gt;
&lt;br /&gt;
For example, the theme with fixed-top navigation bar on Virgin American website&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
=Design Patterns=&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Structural Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;single bridge&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Behavioral Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96512</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96512"/>
		<updated>2015-04-08T01:12:30Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
= Introduction to Expertiza =&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= List of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
Numerous elements in the current version of Expertiza, like 'Back', are hyperlinks rather than buttons. Our goal is to replace this plain-styled text with color coded Bootstrap buttons.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
The theme of Expertiza looks primitive now, a new theme with fix menu on the top is much prefered.&lt;br /&gt;
&lt;br /&gt;
For example, the theme with fixed-top navigation bar on Virgin American website&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
=Design Patterns=&lt;br /&gt;
&lt;br /&gt;
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 groups: structural and behavioral.&lt;br /&gt;
&lt;br /&gt;
==Structural Design Patterns==&lt;br /&gt;
Flyweight, a design pattern aiming to minimize the memory usage by sharring as much data as possible, is heavily implemented on the css and bootstrap side. We lean 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 conscise, while optimizing the memory needed to hold the code.&lt;br /&gt;
&lt;br /&gt;
Another structural design pattern that will, arguably, 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 as being the &amp;quot;single controller&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
Finally, the third structural design pattern that this project follows is Module pattern. Modules are one of the essential constructs of AngularJS framework and, hence, this project is bound to follow module pattern.&lt;br /&gt;
&lt;br /&gt;
==Behavioral Design Patterns==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Along the similar lines, Observer pattern is followed to efficiently handle query requests to a large database (the main culprit behind a 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 and are populating the page further. This approach greatly improves the user experience since it does not leave the user waiting empty-handed until the full query of the database has been completed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96413</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96413"/>
		<updated>2015-04-01T15:21:58Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Explanation of Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
= Introduction to Expertiza =&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= List of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
Numerous elements in the current version of Expertiza, like 'Back', are hyperlinks rather than buttons. Our goal is to replace this plain-styled text with color coded Bootstrap buttons.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
The theme of Expertiza looks primitive now, a new theme with fix menu on the top is much prefered.&lt;br /&gt;
&lt;br /&gt;
For example, the theme with fixed-top navigation bar on Virgin American website&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96412</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96412"/>
		<updated>2015-04-01T15:21:22Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
= Introduction to Expertiza =&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= Explanation of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
Numerous elements in the current version of Expertiza, like 'Back', are hyperlinks rather than buttons. Our goal is to replace this plain-styled text with color coded Bootstrap buttons.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
The theme of Expertiza looks primitive now, a new theme with fix menu on the top is much prefered.&lt;br /&gt;
&lt;br /&gt;
For example, the theme with fixed-top navigation bar on Virgin American website&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96411</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96411"/>
		<updated>2015-04-01T15:21:00Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Explanation of Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
= Introduction to Expertiza =&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
                                                         = Explanation of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
Numerous elements in the current version of Expertiza, like 'Back', are hyperlinks rather than buttons. Our goal is to replace this plain-styled text with color coded Bootstrap buttons.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
The theme of Expertiza looks primitive now, a new theme with fix menu on the top is much prefered.&lt;br /&gt;
&lt;br /&gt;
For example, the theme with fixed-top navigation bar on Virgin American website&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96410</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96410"/>
		<updated>2015-04-01T15:20:24Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
= Introduction to Expertiza =&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
= Explanation of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
Numerous elements in the current version of Expertiza, like 'Back', are hyperlinks rather than buttons. Our goal is to replace this plain-styled text with color coded Bootstrap buttons.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
The theme of Expertiza looks primitive now, a new theme with fix menu on the top is much prefered.&lt;br /&gt;
&lt;br /&gt;
For example, the theme with fixed-top navigation bar on Virgin American website&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96409</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96409"/>
		<updated>2015-04-01T15:20:09Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
= Introduction to Expertiza =&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Explanation of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
Numerous elements in the current version of Expertiza, like 'Back', are hyperlinks rather than buttons. Our goal is to replace this plain-styled text with color coded Bootstrap buttons.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
The theme of Expertiza looks primitive now, a new theme with fix menu on the top is much prefered.&lt;br /&gt;
&lt;br /&gt;
For example, the theme with fixed-top navigation bar on Virgin American website&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96408</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96408"/>
		<updated>2015-04-01T15:19:53Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
= Introduction to Expertiza =&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Explanation of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
Numerous elements in the current version of Expertiza, like 'Back', are hyperlinks rather than buttons. Our goal is to replace this plain-styled text with color coded Bootstrap buttons.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
The theme of Expertiza looks primitive now, a new theme with fix menu on the top is much prefered.&lt;br /&gt;
&lt;br /&gt;
For example, the theme with fixed-top navigation bar on Virgin American website&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96407</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96407"/>
		<updated>2015-04-01T15:17:53Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* 1. Replace Buttons and Links to Bootstrap styled Buttons */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1526. Responsive web design for Expertiza&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
= Introduction to Expertiza =&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
Despite an amazing set of functionality Expertiza offers, there are numerous parts of it that could use of 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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Explanation of Tasks =&lt;br /&gt;
Below are detailed explanations to the tasks listed in the description documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1. Replace Buttons and Links to Bootstrap styled Buttons ==&lt;br /&gt;
Numerous elements in the current version of Expertiza, like 'Back', are hyperlinks rather than buttons. Our goal is to replace this plain-styled text with color coded Bootstrap buttons.&lt;br /&gt;
&lt;br /&gt;
== 2. Create new theme ==&lt;br /&gt;
The theme of Expertiza looks primitive now, a new theme with fix menu on the top is much prefered.&lt;br /&gt;
&lt;br /&gt;
For example, the theme with fixed-top navigation bar on Virgin American website&lt;br /&gt;
&lt;br /&gt;
[[File:Picture4-2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 3. Auto hides contents on the dashboard for instructors ==&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-Course page|Manage-Course page]] for viewing the current design&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Better practice is on Virgin American’s website: https://www.virginamerica.com/book/rt/a1/sfo_bos/20150401_20150402&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture5.png]]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
[[File:Picture6.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Simplify Action Panel ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture7.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Offer Better UI for Managing Users ==&lt;br /&gt;
&lt;br /&gt;
Please refer to the later part of this article: [[#Manage-User page|Manage-User page]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 6. Make grades_view Responsive with Better Design ==&lt;br /&gt;
&lt;br /&gt;
Similar to the previous tasks, we will need to make it responsive. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Pages To Be Modified =&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
=='''Login Page'''==&lt;br /&gt;
[[File:Picture1.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. The webpage looks primitive.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-Course page'''==&lt;br /&gt;
[[File:Picture2.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Also, loading time can be reduced.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
3. Bootstrap will be applied for better user interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Manage-User page'''==&lt;br /&gt;
[[File:Picture3.png]]&lt;br /&gt;
&lt;br /&gt;
=== What's wrong with it ===&lt;br /&gt;
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!&lt;br /&gt;
&lt;br /&gt;
2. When clicking on the letter A-Z, redirections happen and the whole page is reloaded.&lt;br /&gt;
&lt;br /&gt;
=== What changes need to be made ===&lt;br /&gt;
1. Load only a given number of records to the view, such as 100 records, when accessing into this page for the first time.&lt;br /&gt;
&lt;br /&gt;
2. Using AngularJS to eliminate the redirections and page reloading for better UI performance.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96009</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96009"/>
		<updated>2015-03-30T01:22:19Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1526. Responsive web design for Expertiza '''&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
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.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96008</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96008"/>
		<updated>2015-03-30T01:17:08Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1526. Responsive web design for Expertiza '''&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The goal of this project is to add style to Expertiza by adding Bootstrap and AngularJS.&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96007</id>
		<title>CSC/ECE 517 Spring 2015 E1526 MPRI</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_E1526_MPRI&amp;diff=96007"/>
		<updated>2015-03-30T01:14:34Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: Created page with &amp;quot;'''E1526. Responsive web design for Expertiza '''  This page provides a description of the Expertiza based OSS project. This team project successfully refactored the Bookmark Mod...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1526. Responsive web design for Expertiza '''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This team project successfully refactored the Bookmark Model by removing the duplicate code, combining the methods, improving the search function, moving Bmapping model methods to their respective class, covering dependencies associated with changed segments and adding a User Interface for using bookmarks.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=96006</id>
		<title>CSC/ECE 517 Spring 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=96006"/>
		<updated>2015-03-30T01:12:26Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Final Project Design Document */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 17 WL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 5 ZX]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 6 TZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 4 RW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 7 SA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 9 RA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 14 RI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 1 DZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 20 HA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 3 RF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 12 LS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 13 MA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 2 WA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 21 QW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 23 MS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 10 GL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 27 VC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 22 SF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 15 SH]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 18 AS]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1502 wwj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1508 MRS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1504 IMV]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1505 xzl]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1509 lds]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1510 FLP]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1506 SYZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1504 AAC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1507 DG]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1502 GVJ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1503 EDT]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1503 RSA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1501 YWS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1501 OA]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Design Document==&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015 E1526 MPRI]]&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=96005</id>
		<title>CSC/ECE 517 Spring 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=96005"/>
		<updated>2015-03-30T01:11:10Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 17 WL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 5 ZX]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 6 TZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 4 RW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 7 SA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 9 RA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 14 RI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 1 DZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 20 HA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 3 RF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 12 LS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 13 MA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 2 WA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 21 QW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 23 MS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 10 GL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 27 VC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 22 SF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 15 SH]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 18 AS]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1502 wwj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1508 MRS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1504 IMV]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1505 xzl]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1509 lds]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1510 FLP]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1506 SYZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1504 AAC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1507 DG]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1502 GVJ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1503 EDT]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1503 RSA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1501 YWS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1501 OA]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Design Document==&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1504_IMV&amp;diff=96004</id>
		<title>CSC/ECE 517 Spring 2015/oss E1504 IMV</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1504_IMV&amp;diff=96004"/>
		<updated>2015-03-28T22:56:48Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* After Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1504. Refactoring the Bookmark Model'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This team project successfully refactored the Bookmark Model by removing the duplicate code, combining the methods, improving the search function, moving Bmapping model methods to their respective class, covering dependencies associated with changed segments and adding a User Interface for using bookmarks.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 bookmark.rb&lt;br /&gt;
 bmapping.rb&lt;br /&gt;
 bookmarks_controller.rb&lt;br /&gt;
 auth_controller.rb&lt;br /&gt;
 auth_helper.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The bookmark model and controller work together to create and maintain user specific bookmarks, which can be added to different topics. Moreover, the user that created a bookmark can use his privilege to edit it at a later point in time. As a functionality added for convenience, any user can search bookmarks by either users who created them or their bookmark tags.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;The search methods in bookmarks model are being used used on a very granular level. This led to redundancy in bookmarks search methods. These methods include &amp;lt;i&amp;gt;search_alltags_allusers, search_fortags_allusers, search_fortags_forusers, search_alltags_forusers&amp;lt;/i&amp;gt;. Hence duplicates in these methods are to be singled out. &amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Following the CRUD declaration in Ruby on Rails, where the method name should specify the pseudo use of itself,methods such as &amp;lt;i&amp;gt;add_new_bookmark&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;edit_this_bookmark&amp;lt;/i&amp;gt; have violate this naming convention. Therefore, we need to change the names of these two methods to &amp;lt;i&amp;gt;create&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt;, respectively. Upon changing the names, all the dependencies need to be updated, as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Refactor &amp;lt;i&amp;gt;add_topic_bookmark&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;add_this_bookmark&amp;lt;/i&amp;gt; by removing the repetitive code. These two methods differ only in 2 lines of code, which make it reasonable to merge them together into a single method that provides functionality of both individual methods.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Fix the bug in &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method where only bookmarks without &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; can be properly created. We add the functionality to this method to allow it to also create bookmarks with provided &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;.&lt;br /&gt;
   &amp;lt;li&amp;gt;Methods &amp;lt;i&amp;gt;add_bmapping&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; need to be moved to their appropriate model (Bmapping model) rather than reside in Bookmarks model. Completing this task involves checking the dependencies and updating the function calls for these methods, accordingly.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Add user interface for Bookmarks as this functionality has not been a part of Expertiza&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Create a functional tests suite covering the functionality of all the methods that have been changed by our team.&lt;br /&gt;
   &amp;lt;li&amp;gt;Create a Cucumber integration test to show the functionality of added user interface for Bookmarks.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
= Design Patterns Followed =&lt;br /&gt;
'''Single Responsibility Principle:'''&lt;br /&gt;
&lt;br /&gt;
As per Single Responsibility Principle, every class should have responsibility over a single part of functionality provided by software and that responsibility should be entirely encapsulated by the class. All the services and operations within the class should be aligned with that responsibility. &lt;br /&gt;
Following this principle, we found that methods &amp;lt;i&amp;gt; add_bmapping &amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt; add_bmapping_signuptopic &amp;lt;/i&amp;gt; were present in the Bookmark model, while they actually belong to Bmapping model. So we moved those methods to the Bmapping model and took care of all the dependencies. We created functional tests for these methods to prove that refactoring was successful.&lt;br /&gt;
&lt;br /&gt;
'''Polymorphism:'''&lt;br /&gt;
&lt;br /&gt;
We realized that the methods &amp;lt;i&amp;gt;search_fortags_allusers&amp;lt;/i&amp;gt;,&amp;lt;i&amp;gt;search_fortags_forusers&amp;lt;/i&amp;gt; could be combined into one method. Similarly, &amp;lt;i&amp;gt;search_alltags_allusers&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;search_alltags_forusers&amp;lt;/i&amp;gt; could be grouped together into a single method. The reason for this is because these methods, essentially, offer the same functionality, but using different parameters. So, we wrote a common method which takes parameters and, based on the parameters passed, it provides the required functionality.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==Bookmark Model==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| add_this_bookmark&lt;br /&gt;
| Added functionality of add_topic_bookmark&lt;br /&gt;
| To implement code reusability and remove repetitive code.&lt;br /&gt;
|-&lt;br /&gt;
| add_topic_bookmark &lt;br /&gt;
| Merged the functionality into add_this_bookmarks and deleted add_topic_bookmark&lt;br /&gt;
| To implement code reusability and remove repetitive code.&lt;br /&gt;
|-&lt;br /&gt;
| add_bookmark &lt;br /&gt;
| Added a line that checks whether topic_id has been provided in the request&lt;br /&gt;
| It allows creation of new Bmapping if no topic_id was given and removes the bug of searching for bookmark with nil topic_id later on&lt;br /&gt;
|-&lt;br /&gt;
| search_alltags_allusers&lt;br /&gt;
| |Merged search_alltags_allusers and search_alltags_foruser functions into search_alltags&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_alltags_foruser &lt;br /&gt;
| |Merged search_alltags_allusers and search_alltags_foruser functions into search_alltags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_fortags_allusers&lt;br /&gt;
| | Merged search_fortags_allusers and search_fortags_foruser functions into search_fortags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_fortags_foruser&lt;br /&gt;
| Merged search_fortags_allusers and search_fortags_foruser functions into search_fortags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| add_new_bookmark &lt;br /&gt;
| Changed the method name to &amp;quot;create&amp;quot;&lt;br /&gt;
| It is a much more meaningful and simpler name for a method that creates a new bookmark&lt;br /&gt;
|-&lt;br /&gt;
| edit_this_bookmark &lt;br /&gt;
| Changed the name to &amp;quot;edit&amp;quot;&lt;br /&gt;
| It is a much more appropriate name for a method that edits the bookmark it was called on&lt;br /&gt;
|-&lt;br /&gt;
| add_bmapping&lt;br /&gt;
| Moved to class 'Bmapping'&lt;br /&gt;
| This method helps in creating new bmapping. Hence it makes more sense if it belongs to bmapping class itself.&lt;br /&gt;
|-&lt;br /&gt;
| add_bmapping_signuptopic&lt;br /&gt;
| Moved to class 'Bmapping'&lt;br /&gt;
| This method helps in adding a signup topic to a newly created bmapping. Hence it makes more sense if it belongs to bmapping class itself.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Bookmark Controller==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| view_topic_bookmarks&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was not being accessed.&lt;br /&gt;
|-&lt;br /&gt;
| view_review_bookmarks&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was not being accessed.&lt;br /&gt;
|-&lt;br /&gt;
| view&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| edit_bookmark_form&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| create_tag_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| edit_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;edit_this_bookmark&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt;&lt;br /&gt;
| The method name has been refactored to &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt; as per the requirement&lt;br /&gt;
|-&lt;br /&gt;
| add_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;add_topic_bookmark&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;add_this_bookmark&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect method name, the method was inaccessible&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Views==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| bookmarks/_result.html.erb &lt;br /&gt;
| removed asctime from the below line&lt;br /&gt;
| Was throwing error&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/search_bookmarks.html.erb&lt;br /&gt;
| removed unused code&lt;br /&gt;
| not used &lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/view_bookmarks.html.erb&lt;br /&gt;
| Changed line to &amp;lt;%= link_to('Back', session[:comingFrom]) %&amp;gt;&lt;br /&gt;
| To make the back link work&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/_searchmine.html.erb&lt;br /&gt;
| changed line to&amp;lt;%= form_tag(:action =&amp;gt; &amp;quot;search_bookmarks&amp;quot;) do%&amp;gt;&lt;br /&gt;
| % was used instead of %= and it was throwing error&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/add_bookmark_form.html.erb&lt;br /&gt;
| &amp;lt;%= form_tag(:action =&amp;gt; &amp;quot;add_bookmark&amp;quot;, :method =&amp;gt; &amp;quot;post&amp;quot;) do %&amp;gt;&lt;br /&gt;
| % used instead of %= and it was not working&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/managing_bookmarks.html.erb&lt;br /&gt;
| added partials &lt;br /&gt;
| Nothing was there before to display&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| tree_display/list.html.erb&lt;br /&gt;
| added a link to Manage Bookmarks page&lt;br /&gt;
| This allows a user to see the link to Managing Bookmarks page as soon as the user logs in.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring add_this_bookmark and add_topic_bookmark ==&lt;br /&gt;
&lt;br /&gt;
The consistency of these two methods shows plenty of repetitive code. In order to effectively refactor these methods and reuse the code they both need, our team merged the two methods together by enabling add_this_bookmark method to handle creation of a bookmark when a topic id is provided (main functionality of add_topic_bookmark method). Once we implemented this change on add_this_bookmark method, we deleted add_topic_bookmark method as it became obsolete. Therefore, we retained the same functionality while reducing the method by 7 repetitive lines of code. &lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
&lt;br /&gt;
Please note that these two methods only differ in a single line of code (line 6 and 16) where line 6 takes an extra parameter (&amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 1:  def self.add_topic_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topicid)&lt;br /&gt;
 2:    # Check if the bookmark exists and add / edit based on that&lt;br /&gt;
 3:    bookmark_exists = check_bookmark_exists(b_url)&lt;br /&gt;
 4:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
 5:    if (!bookmark_exists || !bmapping_exists)&lt;br /&gt;
 6:      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
 7:    elsif (bmapping_exists)&lt;br /&gt;
 8:      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
 9:    end&lt;br /&gt;
10:  end&lt;br /&gt;
11:&lt;br /&gt;
12:  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
13:    bookmark_exists = check_bookmark_exists(b_url)&lt;br /&gt;
14:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
15:    if (!bookmark_exists || !bmapping_exists)&lt;br /&gt;
16:      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
17:    elsif (bmapping_exists)&lt;br /&gt;
18:      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
19:    end&lt;br /&gt;
20:  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 1:  #Adds bookmark with and without topic_id&lt;br /&gt;
 2:  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topic_id)&lt;br /&gt;
 3:    # first check existence of the given bookmark and bmapping name&lt;br /&gt;
 5:    bookmark_exists = check_bookmark_exists(b_url) &lt;br /&gt;
 6:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
 7:    if (!bookmark_exists || !bmapping_exists) # they don't exists, so create new ones&lt;br /&gt;
 8:      if(topic_id) # topic_id has been provided&lt;br /&gt;
 9:        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
10:      else # topic_id has not been provided&lt;br /&gt;
11:        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user, nil)&lt;br /&gt;
12:      end&lt;br /&gt;
13:    elsif (bmapping_exists) # if the bmapping already exists, edit it instead of creating a new one&lt;br /&gt;
14:      Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
15:    end&lt;br /&gt;
16:  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Fixing a bug in &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method ==&lt;br /&gt;
&lt;br /&gt;
Our team fixed the bug associate with &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; nil being provided to &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method (user has not specified &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;) when creating a bookmark. We include an if statement that calls &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; method only if the provided &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; is not nil. This change has been implemented on line 9 in the code block shown bellow.&lt;br /&gt;
&lt;br /&gt;
=== Before changes ===&lt;br /&gt;
Parts such as &amp;lt;b&amp;gt;bookmark_resource.nil?&amp;lt;/b&amp;gt; need to be refactored to a shorter version &amp;lt;b&amp;gt;!bookmark_resource&amp;lt;/b&amp;gt;. Similar opportunity to refactor comes up 2 more times within this code block (&amp;lt;b&amp;gt; !bmapping.nil? , !topic.nil?&amp;lt;/b&amp;gt;). We also need to change the first &amp;lt;i&amp;gt;if&amp;lt;/i&amp;gt; block to enable signup topic to be added only if topic_id does not already exists. Doing this will fix the bug of signup_topic overwriting an existing topic_id in case if topic was already created in the past.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if bookmark_resource.nil?&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = add_new_bookmark(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        # Add its association to the sign up topic&lt;br /&gt;
        add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if ( !bmapping.nil? )&lt;br /&gt;
          topic = SignUpTopic.find(topicid)&lt;br /&gt;
          if( !topic.nil? )&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            add_bmapping_signuptopic(topicid, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== After Changes ===&lt;br /&gt;
Once the changes described in the &amp;lt;i&amp;gt;Before Change&amp;lt;/i&amp;gt; section were carried out, the code looks cleaner, the bug with topic_id is removed and the code functions marvelously!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if !bookmark_resource # if bookmark resource is nil (does not exist)&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = create(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = Bmapping.add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        if(topic_id) # if topic_id was provided, add the signup topic&lt;br /&gt;
          # Add its association to the sign up topic if the topic was provided&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if (bmapping) # if bmapping exists (it is not nil), look it up and edit the bookmarks&lt;br /&gt;
          topic = SignUpTopic.find(topic_id)&lt;br /&gt;
          if(topic) # if topic exists (it is not nil) use it to edit bookmark&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            Bmapping.add_bmapping_signuptopic(topic_id, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = Bmapping.add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 3 : Refactoring search_fortags_allusers and search_fortags_forusers ==&lt;br /&gt;
&lt;br /&gt;
Both these methods contain almost the same code except for few conditional lines. search_fortags_allusers searches for all tags for all users whereas search_fortags_forusers searches only for those tags that belong to the user. The code for both these functions differed only in the query clause where at one place it checks for records returned for a specific user and at the other place, it does not have this check.&lt;br /&gt;
&lt;br /&gt;
===Before Changes: search_fortags_allusers function ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def  self.search_fortags_allusers(tags_array, order_by)&lt;br /&gt;
&lt;br /&gt;
      result_array = Array.new # returns this array&lt;br /&gt;
      ## find the tags associated with these tagnames&lt;br /&gt;
      @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      ## retreive mapping_ids taggeed with all of the word tags&lt;br /&gt;
      ## for every word, search for every bookmark that was tagged with that word. Then take the intersection of all the bmapping_ids&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
&lt;br /&gt;
        q_tuples = BmappingsTags.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
&lt;br /&gt;
        if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          temp_array = Array.new&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
          @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
      ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
      temp_result_records =  Bmapping.where([&amp;quot;id in (?)&amp;quot;, @q_tuples_with_all_tags])&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      if (order_by ==&amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
      ## for evey bmapping_id, create a hash, and push into the result_array&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] = result.user.name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id =?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes: search_fortags_foruser function===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def self.search_fortags_foruser(tags_array, this_user_id, order_by)&lt;br /&gt;
      #order by is in &amp;quot;most_popular&amp;quot; and &amp;quot;most_recent&amp;quot;&lt;br /&gt;
      result_array = Array.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## search for ids of the tags&lt;br /&gt;
      @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
        ##search for all qualifier tuples with b&lt;br /&gt;
        q_tuples = BmappingsTags.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
        #for q_t in q_tuples&lt;br /&gt;
        #end&lt;br /&gt;
&lt;br /&gt;
        if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          temp_array = Array.new&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
          @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
      temp_result_records =  Bmapping.where([&amp;quot;id in (?) and user_id = ?&amp;quot;, @q_tuples_with_all_tags,this_user_id ])&lt;br /&gt;
&lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      if (order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] =  User.find(this_user_id).name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id=?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The above two functions are merged into a single function named &amp;quot;search_fortags function&amp;quot; as shown below. If we want to search for specified tags for all users, the userid is passed as nil. If we want to search for the specified tags belonging to a particular userid, we pass that userid. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      ## searches for tspecified tags, among a specified user, orders them by most popular and the most recently added&lt;br /&gt;
    def self.search_fortags(tags_array, order_by,this_user_id)&lt;br /&gt;
      #order by is in &amp;quot;most_popular&amp;quot; and &amp;quot;most_recent&amp;quot;&lt;br /&gt;
      result_array = Array.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## search for ids of the tags&lt;br /&gt;
     @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
        ##search for all qualifier tuples with b&lt;br /&gt;
        q_tuples = BmappingsTag.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
        #if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          #first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        # else&lt;br /&gt;
        #   temp_array = Array.new&lt;br /&gt;
        #   for q_t in q_tuples&lt;br /&gt;
        #     temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
        #   end&lt;br /&gt;
        #   @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        # end&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      ##If the user id is passed, it will not be nil. So we use it in the query as shown below.&lt;br /&gt;
      if(this_user_id)&lt;br /&gt;
        ## now you have qualifer tuples with all the required bmapping ids and the requested userid- search for the req ones&lt;br /&gt;
        temp_result_records =  Bmapping.where([&amp;quot;id in (?) and user_id = ?&amp;quot;, @q_tuples_with_all_tags, this_user_id ])&lt;br /&gt;
      else&lt;br /&gt;
        ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
        temp_result_records =  Bmapping.where([&amp;quot;id in (?)&amp;quot;, @q_tuples_with_all_tags])&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      if (order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
     &lt;br /&gt;
&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] =  result.user.name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id=?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes:search_alltags_foruser function===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.search_alltags_foruser (the_userid, order_by)&lt;br /&gt;
        result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
        if(order_by == &amp;quot;most_recent&amp;quot; )&lt;br /&gt;
          ## find all the bmappings in this system, created by this user, order them by the date created.&lt;br /&gt;
          # For each tuple returned from the bmapping, generate a hash, containing the url, the specified user's name, date this mapping was made,&lt;br /&gt;
          ## title, and description provided by this user. Store these hashes sequentially in a array ad return the array&lt;br /&gt;
&lt;br /&gt;
          result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        elsif ( order_by == &amp;quot;most_popular&amp;quot;)&lt;br /&gt;
          ### retrieving the most popular records that this user.(The user need not be the discoverer). First retrieve the the user's bookmarks from the bmapping.&lt;br /&gt;
          ### order these records, based on the user_count of the url&lt;br /&gt;
          temp_result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid])&lt;br /&gt;
          ## order result records by result.user_count a.sort {|x,y| y &amp;lt;=&amp;gt; x }&lt;br /&gt;
          result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count}&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] =BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        return result_array&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes : search_alltags_allusers function ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.search_alltags_allusers(order_by)&lt;br /&gt;
      result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      if(order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        ## find all the records in the system, order them by the date created. Using Bmapping here. Returns mappings that where created most recently,&lt;br /&gt;
        ## the user that created this mapping, the title and description provided this user&lt;br /&gt;
        result_records = Bmapping.all(:order =&amp;gt;&amp;quot;date_created DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = result.user.name # displaying the newest owner of the bookmark,&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
          result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count ## number of people having this user in their repository&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
          tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
      elsif (order_by == &amp;quot;most_popular&amp;quot;)&lt;br /&gt;
        ## returns the url boomarked by the most number of users, the discoverer of that url, the title and description provided by the discoverer&lt;br /&gt;
        result_records = Bookmark.all(:order =&amp;gt;&amp;quot;user_count DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = User.find(result.discoverer_user_id).name&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.user_count&lt;br /&gt;
          b_u_mapping = Bmapping.where([&amp;quot;bookmark_id = ? and user_id = ?&amp;quot;, result.id, result.discoverer_user_id]).first&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = b_u_mapping.id&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = b_u_mapping.description&lt;br /&gt;
          result_hash[&amp;quot;title&amp;quot;] = b_u_mapping.title&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
          tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,b_u_mapping.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The above two functions were merged into a single function &amp;quot;search_alltags&amp;quot; as shown below. If we want to search for all tags for all users, the userid is passed as nil. If we want to search for all tags belonging to a particular userid, we pass that userid. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def self.search_alltags (the_userid, order_by)&lt;br /&gt;
&lt;br /&gt;
        result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
        if(order_by == &amp;quot;most_recent&amp;quot; )&lt;br /&gt;
          ## find all the bmappings in this system, created by this user, order them by the date created.&lt;br /&gt;
          # For each tuple returned from the bmapping, generate a hash, containing the url, the specified user's name, date this mapping was made,&lt;br /&gt;
          ## title, and description provided by this user. Store these hashes sequentially in a array ad return the array&lt;br /&gt;
 &lt;br /&gt;
          ## If no user id is passed, the search is for all the user ids&lt;br /&gt;
          if(!the_userid)&lt;br /&gt;
            ## find all the records in the system, order them by the date created. Using Bmapping here. Returns mappings that where created most recently,&lt;br /&gt;
            ## the user that created this mapping, the title and description provided this user&lt;br /&gt;
            &lt;br /&gt;
            result_records = Bmapping.all.order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          else&lt;br /&gt;
            result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          end&lt;br /&gt;
          &lt;br /&gt;
          #result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = result.user.name&lt;br /&gt;
            result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
        elsif ( order_by == &amp;quot;most_popular&amp;quot; and the_userid) ## Most popular tags for the supplied user&lt;br /&gt;
          ### retrieving the most popular records that this user.(The user need not be the discoverer). First retrieve the the user's bookmarks from the bmapping.&lt;br /&gt;
          ### order these records, based on the user_count of the url&lt;br /&gt;
          temp_result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid])&lt;br /&gt;
          ## order result records by result.user_count a.sort {|x,y| y &amp;lt;=&amp;gt; x }&lt;br /&gt;
          result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count}&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] =BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        elsif (order_by == &amp;quot;most_popular&amp;quot; and !the_userid) ## Most popular tags for all users&lt;br /&gt;
        ## returns the url boomarked by the most number of users, the discoverer of that url, the title and description provided by the discoverer&lt;br /&gt;
        result_records = Bookmark.all(:order =&amp;gt;&amp;quot;user_count DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = User.find(result.discoverer_user_id).name&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.user_count&lt;br /&gt;
          b_u_mapping = Bmapping.where([&amp;quot;bookmark_id = ? and user_id = ?&amp;quot;, result.id, result.discoverer_user_id]).first&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = b_u_mapping.id&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = b_u_mapping.description&lt;br /&gt;
          result_hash[&amp;quot;title&amp;quot;] = b_u_mapping.title&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
          tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,b_u_mapping.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        return result_array&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 4 : Refactoring &amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt; methods ==&lt;br /&gt;
&lt;br /&gt;
The methods ,&amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt;, add new bmapping to newly added bookmarks. These methods are initially served in bookmarks model. Ideally, they should be serving the bmapping model. &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; is a continuation to &amp;lt;i&amp;gt;add_bmapping&amp;lt;/i&amp;gt;. It adds signup topic to the newly created bmapping. Along with moving these methods from bookmarks model, the team had to check for dependencies for these methods in all corresponding models and take care of them.&lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
&lt;br /&gt;
Changes done to bmapping model. The new added code in this model has been moved from bookmarks model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Bmapping &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :bookmark&lt;br /&gt;
  has_many :bmappings_tags&lt;br /&gt;
  has_and_belongs_to_many :sign_up_topics&lt;br /&gt;
  has_many :ratings, :class_name =&amp;gt; &amp;quot;BmappingRatings&amp;quot;, :foreign_key =&amp;gt; &amp;quot;bmapping_id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  def cumulative_rating&lt;br /&gt;
    rating = 0.0&lt;br /&gt;
    count = 0&lt;br /&gt;
    self.ratings.each do |br|&lt;br /&gt;
      rating = rating + br.rating&lt;br /&gt;
      count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; 0&lt;br /&gt;
      return rating/count&lt;br /&gt;
    else&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Bmapping &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :bookmark&lt;br /&gt;
  has_many :bmappings_tags&lt;br /&gt;
  has_and_belongs_to_many :sign_up_topics&lt;br /&gt;
  has_many :ratings, :class_name =&amp;gt; &amp;quot;BmappingRatings&amp;quot;, :foreign_key =&amp;gt; &amp;quot;bmapping_id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  def cumulative_rating&lt;br /&gt;
    rating = 0.0&lt;br /&gt;
    count = 0&lt;br /&gt;
    self.ratings.each do |br|&lt;br /&gt;
      rating = rating + br.rating&lt;br /&gt;
      count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; 0&lt;br /&gt;
      return rating/count&lt;br /&gt;
    else&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # Add bookmark - user association with its meta fields&lt;br /&gt;
    def self.add_bmapping(bid, b_title, user_id, b_description,b_tags_text)&lt;br /&gt;
      bookmark_user_mapping = Bmapping.new&lt;br /&gt;
      bookmark_user_mapping.bookmark_id = bid&lt;br /&gt;
      bookmark_user_mapping.title = b_title&lt;br /&gt;
      bookmark_user_mapping.description = b_description&lt;br /&gt;
      bookmark_user_mapping.user_id =user_id&lt;br /&gt;
      current_timestamp = Time.now&lt;br /&gt;
      bookmark_user_mapping.date_created = current_timestamp&lt;br /&gt;
      bookmark_user_mapping.date_modified = current_timestamp&lt;br /&gt;
      bookmark_user_mapping.save&lt;br /&gt;
      # Add tags&lt;br /&gt;
      # tags come in as a text, separating them into a array&lt;br /&gt;
&lt;br /&gt;
      tag_array = BookmarksHelper.separate_tags(b_tags_text)&lt;br /&gt;
      for each_tag in tag_array&lt;br /&gt;
        # Look for each tag that is present in tags, if not make them, then make the BTU entry&lt;br /&gt;
        tag_tuple = Tag.where([&amp;quot;tagname = ?&amp;quot;,each_tag]).first&lt;br /&gt;
        if !tag_tuple # enter this block if tag_tuple is nil&lt;br /&gt;
          tag_tuple = Tag.new&lt;br /&gt;
          tag_tuple.tagname = each_tag&lt;br /&gt;
          tag_tuple.save&lt;br /&gt;
        end&lt;br /&gt;
        # Check if there is an entry for this tag, this user and this bookmark (via bmappings table)&lt;br /&gt;
        btu_tuple = BmappingsTag.where([ &amp;quot;tag_id = ? and bmapping_id = ?&amp;quot;, tag_tuple.id, bookmark_user_mapping.id] ).first&lt;br /&gt;
        if !btu_tuple # enter this block if btu_tuple is nil&lt;br /&gt;
          btu_tuple = BmappingsTag.new&lt;br /&gt;
          btu_tuple.tag_id = tag_tuple.id&lt;br /&gt;
          btu_tuple.bmapping_id = bookmark_user_mapping.id&lt;br /&gt;
          btu_tuple.save&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
        return bookmark_user_mapping.id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
      # Associate bmapping to the sign up topic&lt;br /&gt;
      def self.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        topic = SignUpTopic.find(topic_id)&lt;br /&gt;
        bmapping = Bmapping.find(bmappingid)&lt;br /&gt;
        unless (!topic &amp;amp;&amp;amp; !bmapping)&lt;br /&gt;
          topic.bmappings &amp;lt;&amp;lt; bmapping&lt;br /&gt;
          topic.save&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
The dependencies for these methods are present in only &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; method of bookmark model. As &amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt; methods support &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; in creating new bmapping to bookmarks,the dependencies lie only in &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; method. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if !bookmark_resource&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = add_new_bookmark(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        # Add its association to the sign up topic&lt;br /&gt;
        add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if (bmapping)&lt;br /&gt;
          topic = SignUpTopic.find(topicid)&lt;br /&gt;
          if(topic)&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            add_bmapping_signuptopic(topicid, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
  def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
    bookmark_resource = Bookmark.where([&amp;quot;url = ?&lt;br /&gt;
      &amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
    # Bookmark with the same url does not exists.&lt;br /&gt;
    if !bookmark_resource&lt;br /&gt;
      # Add the newly discovered bookmark&lt;br /&gt;
      bookmarkid = create(b_url,session_user.id)&lt;br /&gt;
      # Add its associations to a user&lt;br /&gt;
      bmappingid = Bmapping.add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
      if(topic_id)&lt;br /&gt;
        # Add its association to the sign up topic if the topic was provided&lt;br /&gt;
        Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
      end&lt;br /&gt;
      # Bookmark with the same url exists.&lt;br /&gt;
    else&lt;br /&gt;
      bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
      # Bookmark with the same user - bmapping exists.&lt;br /&gt;
      if (bmapping)&lt;br /&gt;
        topic = SignUpTopic.find(topic_id)&lt;br /&gt;
        if(topic)&lt;br /&gt;
          topic.bmappings.each do |mapping|&lt;br /&gt;
            if (mapping.id == bmapping.id)&lt;br /&gt;
              Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Signup Topic does not exists&lt;br /&gt;
        else&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmapping.id)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
      else&lt;br /&gt;
        # Increment user count for the existing bookmark&lt;br /&gt;
        bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
        bookmark_resource.save&lt;br /&gt;
        # Add its association with the user&lt;br /&gt;
        bmappingid = Bmapping.add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
        Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes manually=&lt;br /&gt;
&lt;br /&gt;
===User2 Role===&lt;br /&gt;
&lt;br /&gt;
In order to inspect the changes made to the bookmark mode manually, you can visit our deployed Expertiza at &amp;lt;b&amp;gt;[http://52.11.88.182:3000 Demo]&amp;lt;/b&amp;gt; and use the following credentials:&lt;br /&gt;
     &amp;lt;b&amp;gt;User Name: &amp;lt;/b&amp;gt; &amp;lt;i&amp;gt;user2&amp;lt;/i&amp;gt;&lt;br /&gt;
     &amp;lt;b&amp;gt;Password: &amp;lt;/b&amp;gt; &amp;lt;i&amp;gt; any password&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can notice in the credentials above, you can type in any password you wish in order to log in as user2. We have accomplished this by disabling the authentication and the reason behind it was to have an easily reachable user account for test and development purposes.&lt;br /&gt;
&lt;br /&gt;
The below screenshots demonstrate the working of search features .&lt;br /&gt;
&lt;br /&gt;
===Search for all tags for all users===&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot; http://localhost:3000/bookmarks/viewing_bookmarks&amp;quot; and click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:SearchAllTagsAllUsers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for all tags for user===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;  http://localhost:3000/bookmarks/managing_bookmarks &amp;quot;  to view all tags for the user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchAlltagsForUser.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for tags for all users===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;  http://localhost:3000/bookmarks/view_bookmarks  &amp;quot; , enter the tags separated by comma (example - tag1,tag2) and then click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchForTagsAllUsers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for tags for user===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;http://localhost:3000/bookmarks/managing_bookmarks&amp;quot; , enter the tags separated by comma (example - tag1,tag2) and then click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchForTagsForUser.png]]&lt;br /&gt;
&lt;br /&gt;
=Automated Tests=&lt;br /&gt;
&lt;br /&gt;
===Functional test suite===&lt;br /&gt;
&lt;br /&gt;
We have developed a suit of extensive unit tests covering all the functionality that we have add/modified in the forked version of Expertiza. The test suite consists of 9 tests providing 14 assertions that cover the functionality of all the method changes described in the former sections of this wiki page. The source code for these tests is stored in &amp;lt;i&amp;gt;test/models/bookmark_test.rb&amp;lt;/i&amp;gt; file. You can run this test suite by simply navigating to expertiza project directory and running command: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ruby -I test test/models/bookmark_test.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Integration (Cucumber) tests===&lt;br /&gt;
&lt;br /&gt;
In addition to functional tests, we have also provided a Cucumber test as an integration test. The goal of this test is to show that a user can access the &amp;lt;i&amp;gt;Manage Bookmarks&amp;lt;/i&amp;gt; page upon successful log in, proving that bookmarks view have been successfully integrated into expertiza system. The construct of this test can be found in following files:&lt;br /&gt;
&amp;lt;pre&amp;gt;features/bookmark.feature &lt;br /&gt;
features/step_definitions/bookmark_steps&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run this cucumber test, please navigate to expertiza project directory and run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rake cucumber&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/manish211/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://52.11.88.182:3000/ Demo link] - This might not be available after May of 2015&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1J0WUBtYV_MDhpEQ-50z8gXE-OrvVkpEaZxvn_9RCAsM/edit#heading=h.mo1zn1d9w38l The OSS project requirements doc (Spring 2015 - Expertiza)]&lt;br /&gt;
#[https://drive.google.com/a/ncsu.edu/file/d/0B49VkAq-KMtebXBILUlTQktBVnM/view?usp=sharing Demo of Test suite]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Single_responsibility_principle Single Responsibility Principle]&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1504_IMV&amp;diff=96003</id>
		<title>CSC/ECE 517 Spring 2015/oss E1504 IMV</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1504_IMV&amp;diff=96003"/>
		<updated>2015-03-28T22:54:43Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* After Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1504. Refactoring the Bookmark Model'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This team project successfully refactored the Bookmark Model by removing the duplicate code, combining the methods, improving the search function, moving Bmapping model methods to their respective class, covering dependencies associated with changed segments and adding a User Interface for using bookmarks.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 bookmark.rb&lt;br /&gt;
 bmapping.rb&lt;br /&gt;
 bookmarks_controller.rb&lt;br /&gt;
 auth_controller.rb&lt;br /&gt;
 auth_helper.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The bookmark model and controller work together to create and maintain user specific bookmarks, which can be added to different topics. Moreover, the user that created a bookmark can use his privilege to edit it at a later point in time. As a functionality added for convenience, any user can search bookmarks by either users who created them or their bookmark tags.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;The search methods in bookmarks model are being used used on a very granular level. This led to redundancy in bookmarks search methods. These methods include &amp;lt;i&amp;gt;search_alltags_allusers, search_fortags_allusers, search_fortags_forusers, search_alltags_forusers&amp;lt;/i&amp;gt;. Hence duplicates in these methods are to be singled out. &amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Following the CRUD declaration in Ruby on Rails, where the method name should specify the pseudo use of itself,methods such as &amp;lt;i&amp;gt;add_new_bookmark&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;edit_this_bookmark&amp;lt;/i&amp;gt; have violate this naming convention. Therefore, we need to change the names of these two methods to &amp;lt;i&amp;gt;create&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt;, respectively. Upon changing the names, all the dependencies need to be updated, as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Refactor &amp;lt;i&amp;gt;add_topic_bookmark&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;add_this_bookmark&amp;lt;/i&amp;gt; by removing the repetitive code. These two methods differ only in 2 lines of code, which make it reasonable to merge them together into a single method that provides functionality of both individual methods.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Fix the bug in &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method where only bookmarks without &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; can be properly created. We add the functionality to this method to allow it to also create bookmarks with provided &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;.&lt;br /&gt;
   &amp;lt;li&amp;gt;Methods &amp;lt;i&amp;gt;add_bmapping&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; need to be moved to their appropriate model (Bmapping model) rather than reside in Bookmarks model. Completing this task involves checking the dependencies and updating the function calls for these methods, accordingly.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Add user interface for Bookmarks as this functionality has not been a part of Expertiza&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Create a functional tests suite covering the functionality of all the methods that have been changed by our team.&lt;br /&gt;
   &amp;lt;li&amp;gt;Create a Cucumber integration test to show the functionality of added user interface for Bookmarks.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
= Design Patterns Followed =&lt;br /&gt;
'''Single Responsibility Principle:'''&lt;br /&gt;
&lt;br /&gt;
As per Single Responsibility Principle, every class should have responsibility over a single part of functionality provided by software and that responsibility should be entirely encapsulated by the class. All the services and operations within the class should be aligned with that responsibility. &lt;br /&gt;
Following this principle, we found that methods &amp;lt;i&amp;gt; add_bmapping &amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt; add_bmapping_signuptopic &amp;lt;/i&amp;gt; were present in the Bookmark model, while they actually belong to Bmapping model. So we moved those methods to the Bmapping model and took care of all the dependencies. We created functional tests for these methods to prove that refactoring was successful.&lt;br /&gt;
&lt;br /&gt;
'''Polymorphism:'''&lt;br /&gt;
&lt;br /&gt;
We realized that the methods &amp;lt;i&amp;gt;search_fortags_allusers&amp;lt;/i&amp;gt;,&amp;lt;i&amp;gt;search_fortags_forusers&amp;lt;/i&amp;gt; could be combined into one method. Similarly, &amp;lt;i&amp;gt;search_alltags_allusers&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;search_alltags_forusers&amp;lt;/i&amp;gt; could be grouped together into a single method. The reason for this is because these methods, essentially, offer the same functionality, but using different parameters. So, we wrote a common method which takes parameters and, based on the parameters passed, it provides the required functionality.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==Bookmark Model==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| add_this_bookmark&lt;br /&gt;
| Added functionality of add_topic_bookmark&lt;br /&gt;
| To implement code reusability and remove repetitive code.&lt;br /&gt;
|-&lt;br /&gt;
| add_topic_bookmark &lt;br /&gt;
| Merged the functionality into add_this_bookmarks and deleted add_topic_bookmark&lt;br /&gt;
| To implement code reusability and remove repetitive code.&lt;br /&gt;
|-&lt;br /&gt;
| add_bookmark &lt;br /&gt;
| Added a line that checks whether topic_id has been provided in the request&lt;br /&gt;
| It allows creation of new Bmapping if no topic_id was given and removes the bug of searching for bookmark with nil topic_id later on&lt;br /&gt;
|-&lt;br /&gt;
| search_alltags_allusers&lt;br /&gt;
| |Merged search_alltags_allusers and search_alltags_foruser functions into search_alltags&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_alltags_foruser &lt;br /&gt;
| |Merged search_alltags_allusers and search_alltags_foruser functions into search_alltags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_fortags_allusers&lt;br /&gt;
| | Merged search_fortags_allusers and search_fortags_foruser functions into search_fortags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_fortags_foruser&lt;br /&gt;
| Merged search_fortags_allusers and search_fortags_foruser functions into search_fortags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| add_new_bookmark &lt;br /&gt;
| Changed the method name to &amp;quot;create&amp;quot;&lt;br /&gt;
| It is a much more meaningful and simpler name for a method that creates a new bookmark&lt;br /&gt;
|-&lt;br /&gt;
| edit_this_bookmark &lt;br /&gt;
| Changed the name to &amp;quot;edit&amp;quot;&lt;br /&gt;
| It is a much more appropriate name for a method that edits the bookmark it was called on&lt;br /&gt;
|-&lt;br /&gt;
| add_bmapping&lt;br /&gt;
| Moved to class 'Bmapping'&lt;br /&gt;
| This method helps in creating new bmapping. Hence it makes more sense if it belongs to bmapping class itself.&lt;br /&gt;
|-&lt;br /&gt;
| add_bmapping_signuptopic&lt;br /&gt;
| Moved to class 'Bmapping'&lt;br /&gt;
| This method helps in adding a signup topic to a newly created bmapping. Hence it makes more sense if it belongs to bmapping class itself.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Bookmark Controller==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| view_topic_bookmarks&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was not being accessed.&lt;br /&gt;
|-&lt;br /&gt;
| view_review_bookmarks&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was not being accessed.&lt;br /&gt;
|-&lt;br /&gt;
| view&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| edit_bookmark_form&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| create_tag_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| edit_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;edit_this_bookmark&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt;&lt;br /&gt;
| The method name has been refactored to &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt; as per the requirement&lt;br /&gt;
|-&lt;br /&gt;
| add_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;add_topic_bookmark&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;add_this_bookmark&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect method name, the method was inaccessible&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Views==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| bookmarks/_result.html.erb &lt;br /&gt;
| removed asctime from the below line&lt;br /&gt;
| Was throwing error&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/search_bookmarks.html.erb&lt;br /&gt;
| removed unused code&lt;br /&gt;
| not used &lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/view_bookmarks.html.erb&lt;br /&gt;
| Changed line to &amp;lt;%= link_to('Back', session[:comingFrom]) %&amp;gt;&lt;br /&gt;
| To make the back link work&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/_searchmine.html.erb&lt;br /&gt;
| changed line to&amp;lt;%= form_tag(:action =&amp;gt; &amp;quot;search_bookmarks&amp;quot;) do%&amp;gt;&lt;br /&gt;
| % was used instead of %= and it was throwing error&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/add_bookmark_form.html.erb&lt;br /&gt;
| &amp;lt;%= form_tag(:action =&amp;gt; &amp;quot;add_bookmark&amp;quot;, :method =&amp;gt; &amp;quot;post&amp;quot;) do %&amp;gt;&lt;br /&gt;
| % used instead of %= and it was not working&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/managing_bookmarks.html.erb&lt;br /&gt;
| added partials &lt;br /&gt;
| Nothing was there before to display&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| tree_display/list.html.erb&lt;br /&gt;
| added a link to Manage Bookmarks page&lt;br /&gt;
| This allows a user to see the link to Managing Bookmarks page as soon as the user logs in.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring add_this_bookmark and add_topic_bookmark ==&lt;br /&gt;
&lt;br /&gt;
The consistency of these two methods shows plenty of repetitive code. In order to effectively refactor these methods and reuse the code they both need, our team merged the two methods together by enabling add_this_bookmark method to handle creation of a bookmark when a topic id is provided (main functionality of add_topic_bookmark method). Once we implemented this change on add_this_bookmark method, we deleted add_topic_bookmark method as it became obsolete. Therefore, we retained the same functionality while reducing the method by 7 repetitive lines of code. &lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
&lt;br /&gt;
Please note that these two methods only differ in a single line of code (line 6 and 16) where line 6 takes an extra parameter (&amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 1:  def self.add_topic_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topicid)&lt;br /&gt;
 2:    # Check if the bookmark exists and add / edit based on that&lt;br /&gt;
 3:    bookmark_exists = check_bookmark_exists(b_url)&lt;br /&gt;
 4:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
 5:    if (!bookmark_exists || !bmapping_exists)&lt;br /&gt;
 6:      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
 7:    elsif (bmapping_exists)&lt;br /&gt;
 8:      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
 9:    end&lt;br /&gt;
10:  end&lt;br /&gt;
11:&lt;br /&gt;
12:  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
13:    bookmark_exists = check_bookmark_exists(b_url)&lt;br /&gt;
14:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
15:    if (!bookmark_exists || !bmapping_exists)&lt;br /&gt;
16:      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
17:    elsif (bmapping_exists)&lt;br /&gt;
18:      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
19:    end&lt;br /&gt;
20:  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 1:  #Adds bookmark with and without topic_id&lt;br /&gt;
 2:  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topic_id)&lt;br /&gt;
 3:    # first check existence of the given bookmark and bmapping name&lt;br /&gt;
 5:    bookmark_exists = check_bookmark_exists(b_url) &lt;br /&gt;
 6:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
 7:    if (!bookmark_exists || !bmapping_exists) # they don't exists, so create new ones&lt;br /&gt;
 8:      if(topic_id) # topic_id has been provided&lt;br /&gt;
 9:        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
10:      else # topic_id has not been provided&lt;br /&gt;
11:        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user, nil)&lt;br /&gt;
12:      end&lt;br /&gt;
13:    elsif (bmapping_exists) # if the bmapping already exists, edit it instead of creating a new one&lt;br /&gt;
14:      Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
15:    end&lt;br /&gt;
16:  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Fixing a bug in &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method ==&lt;br /&gt;
&lt;br /&gt;
Our team fixed the bug associate with &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; nil being provided to &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method (user has not specified &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;) when creating a bookmark. We include an if statement that calls &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; method only if the provided &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; is not nil. This change has been implemented on line 9 in the code block shown bellow.&lt;br /&gt;
&lt;br /&gt;
=== Before changes ===&lt;br /&gt;
Parts such as &amp;lt;b&amp;gt;bookmark_resource.nil?&amp;lt;/b&amp;gt; need to be refactored to a shorter version &amp;lt;b&amp;gt;!bookmark_resource&amp;lt;/b&amp;gt;. Similar opportunity to refactor comes up 2 more times within this code block (&amp;lt;b&amp;gt; !bmapping.nil? , !topic.nil?&amp;lt;/b&amp;gt;). We also need to change the first &amp;lt;i&amp;gt;if&amp;lt;/i&amp;gt; block to enable signup topic to be added only if topic_id does not already exists. Doing this will fix the bug of signup_topic overwriting an existing topic_id in case if topic was already created in the past.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if bookmark_resource.nil?&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = add_new_bookmark(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        # Add its association to the sign up topic&lt;br /&gt;
        add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if ( !bmapping.nil? )&lt;br /&gt;
          topic = SignUpTopic.find(topicid)&lt;br /&gt;
          if( !topic.nil? )&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            add_bmapping_signuptopic(topicid, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== After Changes ===&lt;br /&gt;
Once the changes described in the &amp;lt;i&amp;gt;Before Change&amp;lt;/i&amp;gt; section were carried out, the code looks cleaner, the bug with topic_id is removed and the code functions marvelously!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if !bookmark_resource # if bookmark resource is nil (does not exist)&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = create(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = Bmapping.add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        if(topic_id) # if topic_id was provided, add the signup topic&lt;br /&gt;
          # Add its association to the sign up topic if the topic was provided&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if (bmapping) # if bmapping exists (it is not nil), look it up and edit the bookmarks&lt;br /&gt;
          topic = SignUpTopic.find(topic_id)&lt;br /&gt;
          if(topic) # if topic exists (it is not nil) use it to edit bookmark&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            Bmapping.add_bmapping_signuptopic(topic_id, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = Bmapping.add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 3 : Refactoring search_fortags_allusers and search_fortags_forusers ==&lt;br /&gt;
&lt;br /&gt;
Both these methods contain almost the same code except for few conditional lines. search_fortags_allusers searches for all tags for all users whereas search_fortags_forusers searches only for those tags that belong to the user. The code for both these functions differed only in the query clause where at one place it checks for records returned for a specific user and at the other place, it does not have this check.&lt;br /&gt;
&lt;br /&gt;
===Before Changes: search_fortags_allusers function ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def  self.search_fortags_allusers(tags_array, order_by)&lt;br /&gt;
&lt;br /&gt;
      result_array = Array.new # returns this array&lt;br /&gt;
      ## find the tags associated with these tagnames&lt;br /&gt;
      @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      ## retreive mapping_ids taggeed with all of the word tags&lt;br /&gt;
      ## for every word, search for every bookmark that was tagged with that word. Then take the intersection of all the bmapping_ids&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
&lt;br /&gt;
        q_tuples = BmappingsTags.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
&lt;br /&gt;
        if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          temp_array = Array.new&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
          @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
      ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
      temp_result_records =  Bmapping.where([&amp;quot;id in (?)&amp;quot;, @q_tuples_with_all_tags])&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      if (order_by ==&amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
      ## for evey bmapping_id, create a hash, and push into the result_array&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] = result.user.name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id =?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes: search_fortags_foruser function===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def self.search_fortags_foruser(tags_array, this_user_id, order_by)&lt;br /&gt;
      #order by is in &amp;quot;most_popular&amp;quot; and &amp;quot;most_recent&amp;quot;&lt;br /&gt;
      result_array = Array.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## search for ids of the tags&lt;br /&gt;
      @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
        ##search for all qualifier tuples with b&lt;br /&gt;
        q_tuples = BmappingsTags.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
        #for q_t in q_tuples&lt;br /&gt;
        #end&lt;br /&gt;
&lt;br /&gt;
        if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          temp_array = Array.new&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
          @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
      temp_result_records =  Bmapping.where([&amp;quot;id in (?) and user_id = ?&amp;quot;, @q_tuples_with_all_tags,this_user_id ])&lt;br /&gt;
&lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      if (order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] =  User.find(this_user_id).name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id=?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The above two functions are merged into a single function named &amp;quot;search_fortags function&amp;quot; as shown below. If we want to search for specified tags for all users, the userid is passed as nil. If we want to search for the specified tags belonging to a particular userid, we pass that userid. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      ## searches for tspecified tags, among a specified user, orders them by most popular and the most recently added&lt;br /&gt;
    def self.search_fortags(tags_array, order_by,this_user_id)&lt;br /&gt;
      #order by is in &amp;quot;most_popular&amp;quot; and &amp;quot;most_recent&amp;quot;&lt;br /&gt;
      result_array = Array.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## search for ids of the tags&lt;br /&gt;
     @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
        ##search for all qualifier tuples with b&lt;br /&gt;
        q_tuples = BmappingsTag.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
        #if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          #first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        # else&lt;br /&gt;
        #   temp_array = Array.new&lt;br /&gt;
        #   for q_t in q_tuples&lt;br /&gt;
        #     temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
        #   end&lt;br /&gt;
        #   @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        # end&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      ##If the user id is passed, it will not be nil. So we use it in the query as shown below.&lt;br /&gt;
      if(this_user_id)&lt;br /&gt;
        ## now you have qualifer tuples with all the required bmapping ids and the requested userid- search for the req ones&lt;br /&gt;
        temp_result_records =  Bmapping.where([&amp;quot;id in (?) and user_id = ?&amp;quot;, @q_tuples_with_all_tags, this_user_id ])&lt;br /&gt;
      else&lt;br /&gt;
        ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
        temp_result_records =  Bmapping.where([&amp;quot;id in (?)&amp;quot;, @q_tuples_with_all_tags])&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      if (order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
     &lt;br /&gt;
&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] =  result.user.name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id=?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes:search_alltags_foruser function===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.search_alltags_foruser (the_userid, order_by)&lt;br /&gt;
        result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
        if(order_by == &amp;quot;most_recent&amp;quot; )&lt;br /&gt;
          ## find all the bmappings in this system, created by this user, order them by the date created.&lt;br /&gt;
          # For each tuple returned from the bmapping, generate a hash, containing the url, the specified user's name, date this mapping was made,&lt;br /&gt;
          ## title, and description provided by this user. Store these hashes sequentially in a array ad return the array&lt;br /&gt;
&lt;br /&gt;
          result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        elsif ( order_by == &amp;quot;most_popular&amp;quot;)&lt;br /&gt;
          ### retrieving the most popular records that this user.(The user need not be the discoverer). First retrieve the the user's bookmarks from the bmapping.&lt;br /&gt;
          ### order these records, based on the user_count of the url&lt;br /&gt;
          temp_result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid])&lt;br /&gt;
          ## order result records by result.user_count a.sort {|x,y| y &amp;lt;=&amp;gt; x }&lt;br /&gt;
          result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count}&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] =BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        return result_array&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes : search_alltags_allusers function ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.search_alltags_allusers(order_by)&lt;br /&gt;
      result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      if(order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        ## find all the records in the system, order them by the date created. Using Bmapping here. Returns mappings that where created most recently,&lt;br /&gt;
        ## the user that created this mapping, the title and description provided this user&lt;br /&gt;
        result_records = Bmapping.all(:order =&amp;gt;&amp;quot;date_created DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = result.user.name # displaying the newest owner of the bookmark,&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
          result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count ## number of people having this user in their repository&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
          tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
      elsif (order_by == &amp;quot;most_popular&amp;quot;)&lt;br /&gt;
        ## returns the url boomarked by the most number of users, the discoverer of that url, the title and description provided by the discoverer&lt;br /&gt;
        result_records = Bookmark.all(:order =&amp;gt;&amp;quot;user_count DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = User.find(result.discoverer_user_id).name&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.user_count&lt;br /&gt;
          b_u_mapping = Bmapping.where([&amp;quot;bookmark_id = ? and user_id = ?&amp;quot;, result.id, result.discoverer_user_id]).first&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = b_u_mapping.id&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = b_u_mapping.description&lt;br /&gt;
          result_hash[&amp;quot;title&amp;quot;] = b_u_mapping.title&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
          tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,b_u_mapping.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The above two functions were merged into a single function &amp;quot;search_alltags&amp;quot; as shown below. If we want to search for all tags for all users, the userid is passed as nil. If we want to search for all tags belonging to a particular userid, we pass that userid. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def self.search_alltags (the_userid, order_by)&lt;br /&gt;
&lt;br /&gt;
        result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
        if(order_by == &amp;quot;most_recent&amp;quot; )&lt;br /&gt;
          ## find all the bmappings in this system, created by this user, order them by the date created.&lt;br /&gt;
          # For each tuple returned from the bmapping, generate a hash, containing the url, the specified user's name, date this mapping was made,&lt;br /&gt;
          ## title, and description provided by this user. Store these hashes sequentially in a array ad return the array&lt;br /&gt;
 &lt;br /&gt;
          ## If no user id is passed, the search is for all the user ids&lt;br /&gt;
          if(!the_userid)&lt;br /&gt;
            ## find all the records in the system, order them by the date created. Using Bmapping here. Returns mappings that where created most recently,&lt;br /&gt;
            ## the user that created this mapping, the title and description provided this user&lt;br /&gt;
            &lt;br /&gt;
            result_records = Bmapping.all.order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          else&lt;br /&gt;
            result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          end&lt;br /&gt;
          &lt;br /&gt;
          #result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = result.user.name&lt;br /&gt;
            result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
        elsif ( order_by == &amp;quot;most_popular&amp;quot; and the_userid) ## Most popular tags for the supplied user&lt;br /&gt;
          ### retrieving the most popular records that this user.(The user need not be the discoverer). First retrieve the the user's bookmarks from the bmapping.&lt;br /&gt;
          ### order these records, based on the user_count of the url&lt;br /&gt;
          temp_result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid])&lt;br /&gt;
          ## order result records by result.user_count a.sort {|x,y| y &amp;lt;=&amp;gt; x }&lt;br /&gt;
          result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count}&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] =BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        elsif (order_by == &amp;quot;most_popular&amp;quot; and !the_userid) ## Most popular tags for all users&lt;br /&gt;
        ## returns the url boomarked by the most number of users, the discoverer of that url, the title and description provided by the discoverer&lt;br /&gt;
        result_records = Bookmark.all(:order =&amp;gt;&amp;quot;user_count DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = User.find(result.discoverer_user_id).name&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.user_count&lt;br /&gt;
          b_u_mapping = Bmapping.where([&amp;quot;bookmark_id = ? and user_id = ?&amp;quot;, result.id, result.discoverer_user_id]).first&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = b_u_mapping.id&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = b_u_mapping.description&lt;br /&gt;
          result_hash[&amp;quot;title&amp;quot;] = b_u_mapping.title&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
          tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,b_u_mapping.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        return result_array&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 4 : Refactoring &amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt; methods ==&lt;br /&gt;
&lt;br /&gt;
The methods ,&amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt;, add new bmapping to newly added bookmarks. These methods are initially served in bookmarks model. Ideally, they should be serving the bmapping model. &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; is a continuation to &amp;lt;i&amp;gt;add_bmapping&amp;lt;/i&amp;gt;. It adds signup topic to the newly created bmapping. Along with moving these methods from bookmarks model, the team had to check for dependencies for these methods in all corresponding models and take care of them.&lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
&lt;br /&gt;
Changes done to bmapping model. The new added code in this model has been moved from bookmarks model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Bmapping &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :bookmark&lt;br /&gt;
  has_many :bmappings_tags&lt;br /&gt;
  has_and_belongs_to_many :sign_up_topics&lt;br /&gt;
  has_many :ratings, :class_name =&amp;gt; &amp;quot;BmappingRatings&amp;quot;, :foreign_key =&amp;gt; &amp;quot;bmapping_id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  def cumulative_rating&lt;br /&gt;
    rating = 0.0&lt;br /&gt;
    count = 0&lt;br /&gt;
    self.ratings.each do |br|&lt;br /&gt;
      rating = rating + br.rating&lt;br /&gt;
      count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; 0&lt;br /&gt;
      return rating/count&lt;br /&gt;
    else&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Bmapping &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :bookmark&lt;br /&gt;
  has_many :bmappings_tags&lt;br /&gt;
  has_and_belongs_to_many :sign_up_topics&lt;br /&gt;
  has_many :ratings, :class_name =&amp;gt; &amp;quot;BmappingRatings&amp;quot;, :foreign_key =&amp;gt; &amp;quot;bmapping_id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  def cumulative_rating&lt;br /&gt;
    rating = 0.0&lt;br /&gt;
    count = 0&lt;br /&gt;
    self.ratings.each do |br|&lt;br /&gt;
      rating = rating + br.rating&lt;br /&gt;
      count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; 0&lt;br /&gt;
      return rating/count&lt;br /&gt;
    else&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # Add bookmark - user association with its meta fields&lt;br /&gt;
    def self.add_bmapping(bid, b_title, user_id, b_description,b_tags_text)&lt;br /&gt;
      bookmark_user_mapping = Bmapping.new&lt;br /&gt;
      bookmark_user_mapping.bookmark_id = bid&lt;br /&gt;
      bookmark_user_mapping.title = b_title&lt;br /&gt;
      bookmark_user_mapping.description = b_description&lt;br /&gt;
      bookmark_user_mapping.user_id =user_id&lt;br /&gt;
      current_timestamp = Time.now&lt;br /&gt;
      bookmark_user_mapping.date_created = current_timestamp&lt;br /&gt;
      bookmark_user_mapping.date_modified = current_timestamp&lt;br /&gt;
      bookmark_user_mapping.save&lt;br /&gt;
      # Add tags&lt;br /&gt;
      # tags come in as a text, separating them into a array&lt;br /&gt;
&lt;br /&gt;
      tag_array = BookmarksHelper.separate_tags(b_tags_text)&lt;br /&gt;
      for each_tag in tag_array&lt;br /&gt;
        # Look for each tag that is present in tags, if not make them, then make the BTU entry&lt;br /&gt;
        tag_tuple = Tag.where([&amp;quot;tagname = ?&amp;quot;,each_tag]).first&lt;br /&gt;
        if tag_tuple.nil?&lt;br /&gt;
          tag_tuple = Tag.new&lt;br /&gt;
          tag_tuple.tagname = each_tag&lt;br /&gt;
          tag_tuple.save&lt;br /&gt;
        end&lt;br /&gt;
        # Check if there is an entry for this tag, this user and this bookmark (via bmappings table)&lt;br /&gt;
        btu_tuple = BmappingsTag.where([ &amp;quot;tag_id = ? and bmapping_id = ?&amp;quot;, tag_tuple.id, bookmark_user_mapping.id] ).first&lt;br /&gt;
        if btu_tuple.nil?&lt;br /&gt;
          btu_tuple = BmappingsTag.new&lt;br /&gt;
          btu_tuple.tag_id = tag_tuple.id&lt;br /&gt;
          btu_tuple.bmapping_id = bookmark_user_mapping.id&lt;br /&gt;
          btu_tuple.save&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
        return bookmark_user_mapping.id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
      # Associate bmapping to the sign up topic&lt;br /&gt;
      def self.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        topic = SignUpTopic.find(topic_id)&lt;br /&gt;
        bmapping = Bmapping.find(bmappingid)&lt;br /&gt;
        unless (topic.nil? &amp;amp;&amp;amp; bmapping.nil?)&lt;br /&gt;
          topic.bmappings &amp;lt;&amp;lt; bmapping&lt;br /&gt;
          topic.save&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
The dependencies for these methods are present in only &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; method of bookmark model. As &amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt; methods support &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; in creating new bmapping to bookmarks,the dependencies lie only in &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; method. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if !bookmark_resource&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = add_new_bookmark(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        # Add its association to the sign up topic&lt;br /&gt;
        add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if (bmapping)&lt;br /&gt;
          topic = SignUpTopic.find(topicid)&lt;br /&gt;
          if(topic)&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            add_bmapping_signuptopic(topicid, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
  def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
    bookmark_resource = Bookmark.where([&amp;quot;url = ?&lt;br /&gt;
      &amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
    # Bookmark with the same url does not exists.&lt;br /&gt;
    if !bookmark_resource&lt;br /&gt;
      # Add the newly discovered bookmark&lt;br /&gt;
      bookmarkid = create(b_url,session_user.id)&lt;br /&gt;
      # Add its associations to a user&lt;br /&gt;
      bmappingid = Bmapping.add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
      if(topic_id)&lt;br /&gt;
        # Add its association to the sign up topic if the topic was provided&lt;br /&gt;
        Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
      end&lt;br /&gt;
      # Bookmark with the same url exists.&lt;br /&gt;
    else&lt;br /&gt;
      bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
      # Bookmark with the same user - bmapping exists.&lt;br /&gt;
      if (bmapping)&lt;br /&gt;
        topic = SignUpTopic.find(topic_id)&lt;br /&gt;
        if(topic)&lt;br /&gt;
          topic.bmappings.each do |mapping|&lt;br /&gt;
            if (mapping.id == bmapping.id)&lt;br /&gt;
              Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Signup Topic does not exists&lt;br /&gt;
        else&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmapping.id)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
      else&lt;br /&gt;
        # Increment user count for the existing bookmark&lt;br /&gt;
        bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
        bookmark_resource.save&lt;br /&gt;
        # Add its association with the user&lt;br /&gt;
        bmappingid = Bmapping.add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
        Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes manually=&lt;br /&gt;
&lt;br /&gt;
===User2 Role===&lt;br /&gt;
&lt;br /&gt;
In order to inspect the changes made to the bookmark mode manually, you can visit our deployed Expertiza at &amp;lt;b&amp;gt;[http://52.11.88.182:3000 Demo]&amp;lt;/b&amp;gt; and use the following credentials:&lt;br /&gt;
     &amp;lt;b&amp;gt;User Name: &amp;lt;/b&amp;gt; &amp;lt;i&amp;gt;user2&amp;lt;/i&amp;gt;&lt;br /&gt;
     &amp;lt;b&amp;gt;Password: &amp;lt;/b&amp;gt; &amp;lt;i&amp;gt; any password&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can notice in the credentials above, you can type in any password you wish in order to log in as user2. We have accomplished this by disabling the authentication and the reason behind it was to have an easily reachable user account for test and development purposes.&lt;br /&gt;
&lt;br /&gt;
The below screenshots demonstrate the working of search features .&lt;br /&gt;
&lt;br /&gt;
===Search for all tags for all users===&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot; http://localhost:3000/bookmarks/viewing_bookmarks&amp;quot; and click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:SearchAllTagsAllUsers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for all tags for user===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;  http://localhost:3000/bookmarks/managing_bookmarks &amp;quot;  to view all tags for the user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchAlltagsForUser.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for tags for all users===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;  http://localhost:3000/bookmarks/view_bookmarks  &amp;quot; , enter the tags separated by comma (example - tag1,tag2) and then click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchForTagsAllUsers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for tags for user===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;http://localhost:3000/bookmarks/managing_bookmarks&amp;quot; , enter the tags separated by comma (example - tag1,tag2) and then click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchForTagsForUser.png]]&lt;br /&gt;
&lt;br /&gt;
=Automated Tests=&lt;br /&gt;
&lt;br /&gt;
===Functional test suite===&lt;br /&gt;
&lt;br /&gt;
We have developed a suit of extensive unit tests covering all the functionality that we have add/modified in the forked version of Expertiza. The test suite consists of 9 tests providing 14 assertions that cover the functionality of all the method changes described in the former sections of this wiki page. The source code for these tests is stored in &amp;lt;i&amp;gt;test/models/bookmark_test.rb&amp;lt;/i&amp;gt; file. You can run this test suite by simply navigating to expertiza project directory and running command: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ruby -I test test/models/bookmark_test.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Integration (Cucumber) tests===&lt;br /&gt;
&lt;br /&gt;
In addition to functional tests, we have also provided a Cucumber test as an integration test. The goal of this test is to show that a user can access the &amp;lt;i&amp;gt;Manage Bookmarks&amp;lt;/i&amp;gt; page upon successful log in, proving that bookmarks view have been successfully integrated into expertiza system. The construct of this test can be found in following files:&lt;br /&gt;
&amp;lt;pre&amp;gt;features/bookmark.feature &lt;br /&gt;
features/step_definitions/bookmark_steps&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run this cucumber test, please navigate to expertiza project directory and run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rake cucumber&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/manish211/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://52.11.88.182:3000/ Demo link] - This might not be available after May of 2015&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1J0WUBtYV_MDhpEQ-50z8gXE-OrvVkpEaZxvn_9RCAsM/edit#heading=h.mo1zn1d9w38l The OSS project requirements doc (Spring 2015 - Expertiza)]&lt;br /&gt;
#[https://drive.google.com/a/ncsu.edu/file/d/0B49VkAq-KMtebXBILUlTQktBVnM/view?usp=sharing Demo of Test suite]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Single_responsibility_principle Single Responsibility Principle]&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1504_IMV&amp;diff=96002</id>
		<title>CSC/ECE 517 Spring 2015/oss E1504 IMV</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1504_IMV&amp;diff=96002"/>
		<updated>2015-03-28T22:52:36Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* After Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1504. Refactoring the Bookmark Model'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This team project successfully refactored the Bookmark Model by removing the duplicate code, combining the methods, improving the search function, moving Bmapping model methods to their respective class, covering dependencies associated with changed segments and adding a User Interface for using bookmarks.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 bookmark.rb&lt;br /&gt;
 bmapping.rb&lt;br /&gt;
 bookmarks_controller.rb&lt;br /&gt;
 auth_controller.rb&lt;br /&gt;
 auth_helper.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The bookmark model and controller work together to create and maintain user specific bookmarks, which can be added to different topics. Moreover, the user that created a bookmark can use his privilege to edit it at a later point in time. As a functionality added for convenience, any user can search bookmarks by either users who created them or their bookmark tags.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;The search methods in bookmarks model are being used used on a very granular level. This led to redundancy in bookmarks search methods. These methods include &amp;lt;i&amp;gt;search_alltags_allusers, search_fortags_allusers, search_fortags_forusers, search_alltags_forusers&amp;lt;/i&amp;gt;. Hence duplicates in these methods are to be singled out. &amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Following the CRUD declaration in Ruby on Rails, where the method name should specify the pseudo use of itself,methods such as &amp;lt;i&amp;gt;add_new_bookmark&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;edit_this_bookmark&amp;lt;/i&amp;gt; have violate this naming convention. Therefore, we need to change the names of these two methods to &amp;lt;i&amp;gt;create&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt;, respectively. Upon changing the names, all the dependencies need to be updated, as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Refactor &amp;lt;i&amp;gt;add_topic_bookmark&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;add_this_bookmark&amp;lt;/i&amp;gt; by removing the repetitive code. These two methods differ only in 2 lines of code, which make it reasonable to merge them together into a single method that provides functionality of both individual methods.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Fix the bug in &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method where only bookmarks without &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; can be properly created. We add the functionality to this method to allow it to also create bookmarks with provided &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;.&lt;br /&gt;
   &amp;lt;li&amp;gt;Methods &amp;lt;i&amp;gt;add_bmapping&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; need to be moved to their appropriate model (Bmapping model) rather than reside in Bookmarks model. Completing this task involves checking the dependencies and updating the function calls for these methods, accordingly.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Add user interface for Bookmarks as this functionality has not been a part of Expertiza&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Create a functional tests suite covering the functionality of all the methods that have been changed by our team.&lt;br /&gt;
   &amp;lt;li&amp;gt;Create a Cucumber integration test to show the functionality of added user interface for Bookmarks.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
= Design Patterns Followed =&lt;br /&gt;
'''Single Responsibility Principle:'''&lt;br /&gt;
&lt;br /&gt;
As per Single Responsibility Principle, every class should have responsibility over a single part of functionality provided by software and that responsibility should be entirely encapsulated by the class. All the services and operations within the class should be aligned with that responsibility. &lt;br /&gt;
Following this principle, we found that methods &amp;lt;i&amp;gt; add_bmapping &amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt; add_bmapping_signuptopic &amp;lt;/i&amp;gt; were present in the Bookmark model, while they actually belong to Bmapping model. So we moved those methods to the Bmapping model and took care of all the dependencies. We created functional tests for these methods to prove that refactoring was successful.&lt;br /&gt;
&lt;br /&gt;
'''Polymorphism:'''&lt;br /&gt;
&lt;br /&gt;
We realized that the methods &amp;lt;i&amp;gt;search_fortags_allusers&amp;lt;/i&amp;gt;,&amp;lt;i&amp;gt;search_fortags_forusers&amp;lt;/i&amp;gt; could be combined into one method. Similarly, &amp;lt;i&amp;gt;search_alltags_allusers&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;search_alltags_forusers&amp;lt;/i&amp;gt; could be grouped together into a single method. The reason for this is because these methods, essentially, offer the same functionality, but using different parameters. So, we wrote a common method which takes parameters and, based on the parameters passed, it provides the required functionality.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==Bookmark Model==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| add_this_bookmark&lt;br /&gt;
| Added functionality of add_topic_bookmark&lt;br /&gt;
| To implement code reusability and remove repetitive code.&lt;br /&gt;
|-&lt;br /&gt;
| add_topic_bookmark &lt;br /&gt;
| Merged the functionality into add_this_bookmarks and deleted add_topic_bookmark&lt;br /&gt;
| To implement code reusability and remove repetitive code.&lt;br /&gt;
|-&lt;br /&gt;
| add_bookmark &lt;br /&gt;
| Added a line that checks whether topic_id has been provided in the request&lt;br /&gt;
| It allows creation of new Bmapping if no topic_id was given and removes the bug of searching for bookmark with nil topic_id later on&lt;br /&gt;
|-&lt;br /&gt;
| search_alltags_allusers&lt;br /&gt;
| |Merged search_alltags_allusers and search_alltags_foruser functions into search_alltags&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_alltags_foruser &lt;br /&gt;
| |Merged search_alltags_allusers and search_alltags_foruser functions into search_alltags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_fortags_allusers&lt;br /&gt;
| | Merged search_fortags_allusers and search_fortags_foruser functions into search_fortags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_fortags_foruser&lt;br /&gt;
| Merged search_fortags_allusers and search_fortags_foruser functions into search_fortags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| add_new_bookmark &lt;br /&gt;
| Changed the method name to &amp;quot;create&amp;quot;&lt;br /&gt;
| It is a much more meaningful and simpler name for a method that creates a new bookmark&lt;br /&gt;
|-&lt;br /&gt;
| edit_this_bookmark &lt;br /&gt;
| Changed the name to &amp;quot;edit&amp;quot;&lt;br /&gt;
| It is a much more appropriate name for a method that edits the bookmark it was called on&lt;br /&gt;
|-&lt;br /&gt;
| add_bmapping&lt;br /&gt;
| Moved to class 'Bmapping'&lt;br /&gt;
| This method helps in creating new bmapping. Hence it makes more sense if it belongs to bmapping class itself.&lt;br /&gt;
|-&lt;br /&gt;
| add_bmapping_signuptopic&lt;br /&gt;
| Moved to class 'Bmapping'&lt;br /&gt;
| This method helps in adding a signup topic to a newly created bmapping. Hence it makes more sense if it belongs to bmapping class itself.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Bookmark Controller==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| view_topic_bookmarks&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was not being accessed.&lt;br /&gt;
|-&lt;br /&gt;
| view_review_bookmarks&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was not being accessed.&lt;br /&gt;
|-&lt;br /&gt;
| view&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| edit_bookmark_form&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| create_tag_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| edit_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;edit_this_bookmark&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt;&lt;br /&gt;
| The method name has been refactored to &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt; as per the requirement&lt;br /&gt;
|-&lt;br /&gt;
| add_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;add_topic_bookmark&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;add_this_bookmark&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect method name, the method was inaccessible&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Views==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| bookmarks/_result.html.erb &lt;br /&gt;
| removed asctime from the below line&lt;br /&gt;
| Was throwing error&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/search_bookmarks.html.erb&lt;br /&gt;
| removed unused code&lt;br /&gt;
| not used &lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/view_bookmarks.html.erb&lt;br /&gt;
| Changed line to &amp;lt;%= link_to('Back', session[:comingFrom]) %&amp;gt;&lt;br /&gt;
| To make the back link work&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/_searchmine.html.erb&lt;br /&gt;
| changed line to&amp;lt;%= form_tag(:action =&amp;gt; &amp;quot;search_bookmarks&amp;quot;) do%&amp;gt;&lt;br /&gt;
| % was used instead of %= and it was throwing error&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/add_bookmark_form.html.erb&lt;br /&gt;
| &amp;lt;%= form_tag(:action =&amp;gt; &amp;quot;add_bookmark&amp;quot;, :method =&amp;gt; &amp;quot;post&amp;quot;) do %&amp;gt;&lt;br /&gt;
| % used instead of %= and it was not working&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/managing_bookmarks.html.erb&lt;br /&gt;
| added partials &lt;br /&gt;
| Nothing was there before to display&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| tree_display/list.html.erb&lt;br /&gt;
| added a link to Manage Bookmarks page&lt;br /&gt;
| This allows a user to see the link to Managing Bookmarks page as soon as the user logs in.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring add_this_bookmark and add_topic_bookmark ==&lt;br /&gt;
&lt;br /&gt;
The consistency of these two methods shows plenty of repetitive code. In order to effectively refactor these methods and reuse the code they both need, our team merged the two methods together by enabling add_this_bookmark method to handle creation of a bookmark when a topic id is provided (main functionality of add_topic_bookmark method). Once we implemented this change on add_this_bookmark method, we deleted add_topic_bookmark method as it became obsolete. Therefore, we retained the same functionality while reducing the method by 7 repetitive lines of code. &lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
&lt;br /&gt;
Please note that these two methods only differ in a single line of code (line 6 and 16) where line 6 takes an extra parameter (&amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 1:  def self.add_topic_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topicid)&lt;br /&gt;
 2:    # Check if the bookmark exists and add / edit based on that&lt;br /&gt;
 3:    bookmark_exists = check_bookmark_exists(b_url)&lt;br /&gt;
 4:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
 5:    if (!bookmark_exists || !bmapping_exists)&lt;br /&gt;
 6:      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
 7:    elsif (bmapping_exists)&lt;br /&gt;
 8:      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
 9:    end&lt;br /&gt;
10:  end&lt;br /&gt;
11:&lt;br /&gt;
12:  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
13:    bookmark_exists = check_bookmark_exists(b_url)&lt;br /&gt;
14:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
15:    if (!bookmark_exists || !bmapping_exists)&lt;br /&gt;
16:      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
17:    elsif (bmapping_exists)&lt;br /&gt;
18:      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
19:    end&lt;br /&gt;
20:  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 1:  #Adds bookmark with and without topic_id&lt;br /&gt;
 2:  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topic_id)&lt;br /&gt;
 3:    # first check existence of the given bookmark and bmapping name&lt;br /&gt;
 5:    bookmark_exists = check_bookmark_exists(b_url) &lt;br /&gt;
 6:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
 7:    if (!bookmark_exists || !bmapping_exists) # they don't exists, so create new ones&lt;br /&gt;
 8:      if(topic_id) # topic_id has been provided&lt;br /&gt;
 9:        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
10:      else # topic_id has not been provided&lt;br /&gt;
11:        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user, nil)&lt;br /&gt;
12:      end&lt;br /&gt;
13:    elsif (bmapping_exists) # if the bmapping already exists, edit it instead of creating a new one&lt;br /&gt;
14:      Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
15:    end&lt;br /&gt;
16:  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Fixing a bug in &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method ==&lt;br /&gt;
&lt;br /&gt;
Our team fixed the bug associate with &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; nil being provided to &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method (user has not specified &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;) when creating a bookmark. We include an if statement that calls &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; method only if the provided &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; is not nil. This change has been implemented on line 9 in the code block shown bellow.&lt;br /&gt;
&lt;br /&gt;
=== Before changes ===&lt;br /&gt;
Parts such as &amp;lt;b&amp;gt;bookmark_resource.nil?&amp;lt;/b&amp;gt; need to be refactored to a shorter version &amp;lt;b&amp;gt;!bookmark_resource&amp;lt;/b&amp;gt;. Similar opportunity to refactor comes up 2 more times within this code block (&amp;lt;b&amp;gt; !bmapping.nil? , !topic.nil?&amp;lt;/b&amp;gt;). We also need to change the first &amp;lt;i&amp;gt;if&amp;lt;/i&amp;gt; block to enable signup topic to be added only if topic_id does not already exists. Doing this will fix the bug of signup_topic overwriting an existing topic_id in case if topic was already created in the past.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if bookmark_resource.nil?&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = add_new_bookmark(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        # Add its association to the sign up topic&lt;br /&gt;
        add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if ( !bmapping.nil? )&lt;br /&gt;
          topic = SignUpTopic.find(topicid)&lt;br /&gt;
          if( !topic.nil? )&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            add_bmapping_signuptopic(topicid, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== After Changes ===&lt;br /&gt;
Once the changes described in the &amp;lt;i&amp;gt;Before Change&amp;lt;/i&amp;gt; section were carried out, the code looks cleaner, the bug with topic_id is removed and the code functions marvelously!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if !bookmark_resource # if bookmark resource is nil (does not exist)&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = create(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = Bmapping.add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        if(topic_id) # if topic_id was provided, add the signup topic&lt;br /&gt;
          # Add its association to the sign up topic if the topic was provided&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if (bmapping) # if bmapping exists (it is not nil), look it up and edit the bookmarks&lt;br /&gt;
          topic = SignUpTopic.find(topic_id)&lt;br /&gt;
          if(topic) # if topic exists (it is not nil) use it to edit bookmark&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            Bmapping.add_bmapping_signuptopic(topic_id, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = Bmapping.add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 3 : Refactoring search_fortags_allusers and search_fortags_forusers ==&lt;br /&gt;
&lt;br /&gt;
Both these methods contain almost the same code except for few conditional lines. search_fortags_allusers searches for all tags for all users whereas search_fortags_forusers searches only for those tags that belong to the user. The code for both these functions differed only in the query clause where at one place it checks for records returned for a specific user and at the other place, it does not have this check.&lt;br /&gt;
&lt;br /&gt;
===Before Changes: search_fortags_allusers function ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def  self.search_fortags_allusers(tags_array, order_by)&lt;br /&gt;
&lt;br /&gt;
      result_array = Array.new # returns this array&lt;br /&gt;
      ## find the tags associated with these tagnames&lt;br /&gt;
      @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      ## retreive mapping_ids taggeed with all of the word tags&lt;br /&gt;
      ## for every word, search for every bookmark that was tagged with that word. Then take the intersection of all the bmapping_ids&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
&lt;br /&gt;
        q_tuples = BmappingsTags.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
&lt;br /&gt;
        if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          temp_array = Array.new&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
          @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
      ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
      temp_result_records =  Bmapping.where([&amp;quot;id in (?)&amp;quot;, @q_tuples_with_all_tags])&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      if (order_by ==&amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
      ## for evey bmapping_id, create a hash, and push into the result_array&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] = result.user.name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id =?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes: search_fortags_foruser function===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def self.search_fortags_foruser(tags_array, this_user_id, order_by)&lt;br /&gt;
      #order by is in &amp;quot;most_popular&amp;quot; and &amp;quot;most_recent&amp;quot;&lt;br /&gt;
      result_array = Array.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## search for ids of the tags&lt;br /&gt;
      @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
        ##search for all qualifier tuples with b&lt;br /&gt;
        q_tuples = BmappingsTags.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
        #for q_t in q_tuples&lt;br /&gt;
        #end&lt;br /&gt;
&lt;br /&gt;
        if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          temp_array = Array.new&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
          @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
      temp_result_records =  Bmapping.where([&amp;quot;id in (?) and user_id = ?&amp;quot;, @q_tuples_with_all_tags,this_user_id ])&lt;br /&gt;
&lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      if (order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] =  User.find(this_user_id).name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id=?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The above two functions are merged into a single function named &amp;quot;search_fortags function&amp;quot; as shown below. If we want to search for specified tags for all users, the userid is passed as nil. If we want to search for the specified tags belonging to a particular userid, we pass that userid. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      ## searches for tspecified tags, among a specified user, orders them by most popular and the most recently added&lt;br /&gt;
    def self.search_fortags(tags_array, order_by,this_user_id)&lt;br /&gt;
      #order by is in &amp;quot;most_popular&amp;quot; and &amp;quot;most_recent&amp;quot;&lt;br /&gt;
      result_array = Array.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## search for ids of the tags&lt;br /&gt;
     @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
        ##search for all qualifier tuples with b&lt;br /&gt;
        q_tuples = BmappingsTag.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
        #if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          #first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        # else&lt;br /&gt;
        #   temp_array = Array.new&lt;br /&gt;
        #   for q_t in q_tuples&lt;br /&gt;
        #     temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
        #   end&lt;br /&gt;
        #   @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        # end&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      ##If the user id is passed, it will not be nil. So we use it in the query as shown below.&lt;br /&gt;
      if(this_user_id)&lt;br /&gt;
        ## now you have qualifer tuples with all the required bmapping ids and the requested userid- search for the req ones&lt;br /&gt;
        temp_result_records =  Bmapping.where([&amp;quot;id in (?) and user_id = ?&amp;quot;, @q_tuples_with_all_tags, this_user_id ])&lt;br /&gt;
      else&lt;br /&gt;
        ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
        temp_result_records =  Bmapping.where([&amp;quot;id in (?)&amp;quot;, @q_tuples_with_all_tags])&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      if (order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
     &lt;br /&gt;
&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] =  result.user.name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id=?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes:search_alltags_foruser function===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.search_alltags_foruser (the_userid, order_by)&lt;br /&gt;
        result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
        if(order_by == &amp;quot;most_recent&amp;quot; )&lt;br /&gt;
          ## find all the bmappings in this system, created by this user, order them by the date created.&lt;br /&gt;
          # For each tuple returned from the bmapping, generate a hash, containing the url, the specified user's name, date this mapping was made,&lt;br /&gt;
          ## title, and description provided by this user. Store these hashes sequentially in a array ad return the array&lt;br /&gt;
&lt;br /&gt;
          result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        elsif ( order_by == &amp;quot;most_popular&amp;quot;)&lt;br /&gt;
          ### retrieving the most popular records that this user.(The user need not be the discoverer). First retrieve the the user's bookmarks from the bmapping.&lt;br /&gt;
          ### order these records, based on the user_count of the url&lt;br /&gt;
          temp_result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid])&lt;br /&gt;
          ## order result records by result.user_count a.sort {|x,y| y &amp;lt;=&amp;gt; x }&lt;br /&gt;
          result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count}&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] =BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        return result_array&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes : search_alltags_allusers function ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.search_alltags_allusers(order_by)&lt;br /&gt;
      result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      if(order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        ## find all the records in the system, order them by the date created. Using Bmapping here. Returns mappings that where created most recently,&lt;br /&gt;
        ## the user that created this mapping, the title and description provided this user&lt;br /&gt;
        result_records = Bmapping.all(:order =&amp;gt;&amp;quot;date_created DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = result.user.name # displaying the newest owner of the bookmark,&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
          result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count ## number of people having this user in their repository&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
          tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
      elsif (order_by == &amp;quot;most_popular&amp;quot;)&lt;br /&gt;
        ## returns the url boomarked by the most number of users, the discoverer of that url, the title and description provided by the discoverer&lt;br /&gt;
        result_records = Bookmark.all(:order =&amp;gt;&amp;quot;user_count DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = User.find(result.discoverer_user_id).name&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.user_count&lt;br /&gt;
          b_u_mapping = Bmapping.where([&amp;quot;bookmark_id = ? and user_id = ?&amp;quot;, result.id, result.discoverer_user_id]).first&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = b_u_mapping.id&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = b_u_mapping.description&lt;br /&gt;
          result_hash[&amp;quot;title&amp;quot;] = b_u_mapping.title&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
          tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,b_u_mapping.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The above two functions were merged into a single function &amp;quot;search_alltags&amp;quot; as shown below. If we want to search for all tags for all users, the userid is passed as nil. If we want to search for all tags belonging to a particular userid, we pass that userid. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def self.search_alltags (the_userid, order_by)&lt;br /&gt;
&lt;br /&gt;
        result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
        if(order_by == &amp;quot;most_recent&amp;quot; )&lt;br /&gt;
          ## find all the bmappings in this system, created by this user, order them by the date created.&lt;br /&gt;
          # For each tuple returned from the bmapping, generate a hash, containing the url, the specified user's name, date this mapping was made,&lt;br /&gt;
          ## title, and description provided by this user. Store these hashes sequentially in a array ad return the array&lt;br /&gt;
 &lt;br /&gt;
          ## If no user id is passed, the search is for all the user ids&lt;br /&gt;
          if(the_userid == nil)&lt;br /&gt;
            ## find all the records in the system, order them by the date created. Using Bmapping here. Returns mappings that where created most recently,&lt;br /&gt;
            ## the user that created this mapping, the title and description provided this user&lt;br /&gt;
            &lt;br /&gt;
            result_records = Bmapping.all.order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          else&lt;br /&gt;
            result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          end&lt;br /&gt;
          &lt;br /&gt;
          #result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = result.user.name&lt;br /&gt;
            result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
        elsif ( order_by == &amp;quot;most_popular&amp;quot; and the_userid != nil) ## Most popular tags for the supplied user&lt;br /&gt;
          ### retrieving the most popular records that this user.(The user need not be the discoverer). First retrieve the the user's bookmarks from the bmapping.&lt;br /&gt;
          ### order these records, based on the user_count of the url&lt;br /&gt;
          temp_result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid])&lt;br /&gt;
          ## order result records by result.user_count a.sort {|x,y| y &amp;lt;=&amp;gt; x }&lt;br /&gt;
          result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count}&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] =BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        elsif (order_by == &amp;quot;most_popular&amp;quot; and the_userid == nil) ## Most popular tags for all users&lt;br /&gt;
        ## returns the url boomarked by the most number of users, the discoverer of that url, the title and description provided by the discoverer&lt;br /&gt;
        result_records = Bookmark.all(:order =&amp;gt;&amp;quot;user_count DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = User.find(result.discoverer_user_id).name&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.user_count&lt;br /&gt;
          b_u_mapping = Bmapping.where([&amp;quot;bookmark_id = ? and user_id = ?&amp;quot;, result.id, result.discoverer_user_id]).first&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = b_u_mapping.id&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = b_u_mapping.description&lt;br /&gt;
          result_hash[&amp;quot;title&amp;quot;] = b_u_mapping.title&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
          tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,b_u_mapping.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        return result_array&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 4 : Refactoring &amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt; methods ==&lt;br /&gt;
&lt;br /&gt;
The methods ,&amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt;, add new bmapping to newly added bookmarks. These methods are initially served in bookmarks model. Ideally, they should be serving the bmapping model. &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; is a continuation to &amp;lt;i&amp;gt;add_bmapping&amp;lt;/i&amp;gt;. It adds signup topic to the newly created bmapping. Along with moving these methods from bookmarks model, the team had to check for dependencies for these methods in all corresponding models and take care of them.&lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
&lt;br /&gt;
Changes done to bmapping model. The new added code in this model has been moved from bookmarks model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Bmapping &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :bookmark&lt;br /&gt;
  has_many :bmappings_tags&lt;br /&gt;
  has_and_belongs_to_many :sign_up_topics&lt;br /&gt;
  has_many :ratings, :class_name =&amp;gt; &amp;quot;BmappingRatings&amp;quot;, :foreign_key =&amp;gt; &amp;quot;bmapping_id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  def cumulative_rating&lt;br /&gt;
    rating = 0.0&lt;br /&gt;
    count = 0&lt;br /&gt;
    self.ratings.each do |br|&lt;br /&gt;
      rating = rating + br.rating&lt;br /&gt;
      count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; 0&lt;br /&gt;
      return rating/count&lt;br /&gt;
    else&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Bmapping &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :bookmark&lt;br /&gt;
  has_many :bmappings_tags&lt;br /&gt;
  has_and_belongs_to_many :sign_up_topics&lt;br /&gt;
  has_many :ratings, :class_name =&amp;gt; &amp;quot;BmappingRatings&amp;quot;, :foreign_key =&amp;gt; &amp;quot;bmapping_id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  def cumulative_rating&lt;br /&gt;
    rating = 0.0&lt;br /&gt;
    count = 0&lt;br /&gt;
    self.ratings.each do |br|&lt;br /&gt;
      rating = rating + br.rating&lt;br /&gt;
      count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; 0&lt;br /&gt;
      return rating/count&lt;br /&gt;
    else&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # Add bookmark - user association with its meta fields&lt;br /&gt;
    def self.add_bmapping(bid, b_title, user_id, b_description,b_tags_text)&lt;br /&gt;
      bookmark_user_mapping = Bmapping.new&lt;br /&gt;
      bookmark_user_mapping.bookmark_id = bid&lt;br /&gt;
      bookmark_user_mapping.title = b_title&lt;br /&gt;
      bookmark_user_mapping.description = b_description&lt;br /&gt;
      bookmark_user_mapping.user_id =user_id&lt;br /&gt;
      current_timestamp = Time.now&lt;br /&gt;
      bookmark_user_mapping.date_created = current_timestamp&lt;br /&gt;
      bookmark_user_mapping.date_modified = current_timestamp&lt;br /&gt;
      bookmark_user_mapping.save&lt;br /&gt;
      # Add tags&lt;br /&gt;
      # tags come in as a text, separating them into a array&lt;br /&gt;
&lt;br /&gt;
      tag_array = BookmarksHelper.separate_tags(b_tags_text)&lt;br /&gt;
      for each_tag in tag_array&lt;br /&gt;
        # Look for each tag that is present in tags, if not make them, then make the BTU entry&lt;br /&gt;
        tag_tuple = Tag.where([&amp;quot;tagname = ?&amp;quot;,each_tag]).first&lt;br /&gt;
        if tag_tuple.nil?&lt;br /&gt;
          tag_tuple = Tag.new&lt;br /&gt;
          tag_tuple.tagname = each_tag&lt;br /&gt;
          tag_tuple.save&lt;br /&gt;
        end&lt;br /&gt;
        # Check if there is an entry for this tag, this user and this bookmark (via bmappings table)&lt;br /&gt;
        btu_tuple = BmappingsTag.where([ &amp;quot;tag_id = ? and bmapping_id = ?&amp;quot;, tag_tuple.id, bookmark_user_mapping.id] ).first&lt;br /&gt;
        if btu_tuple.nil?&lt;br /&gt;
          btu_tuple = BmappingsTag.new&lt;br /&gt;
          btu_tuple.tag_id = tag_tuple.id&lt;br /&gt;
          btu_tuple.bmapping_id = bookmark_user_mapping.id&lt;br /&gt;
          btu_tuple.save&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
        return bookmark_user_mapping.id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
      # Associate bmapping to the sign up topic&lt;br /&gt;
      def self.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        topic = SignUpTopic.find(topic_id)&lt;br /&gt;
        bmapping = Bmapping.find(bmappingid)&lt;br /&gt;
        unless (topic.nil? &amp;amp;&amp;amp; bmapping.nil?)&lt;br /&gt;
          topic.bmappings &amp;lt;&amp;lt; bmapping&lt;br /&gt;
          topic.save&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
The dependencies for these methods are present in only &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; method of bookmark model. As &amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt; methods support &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; in creating new bmapping to bookmarks,the dependencies lie only in &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; method. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if !bookmark_resource&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = add_new_bookmark(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        # Add its association to the sign up topic&lt;br /&gt;
        add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if (bmapping)&lt;br /&gt;
          topic = SignUpTopic.find(topicid)&lt;br /&gt;
          if(topic)&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            add_bmapping_signuptopic(topicid, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
  def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
    bookmark_resource = Bookmark.where([&amp;quot;url = ?&lt;br /&gt;
      &amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
    # Bookmark with the same url does not exists.&lt;br /&gt;
    if !bookmark_resource&lt;br /&gt;
      # Add the newly discovered bookmark&lt;br /&gt;
      bookmarkid = create(b_url,session_user.id)&lt;br /&gt;
      # Add its associations to a user&lt;br /&gt;
      bmappingid = Bmapping.add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
      if(topic_id)&lt;br /&gt;
        # Add its association to the sign up topic if the topic was provided&lt;br /&gt;
        Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
      end&lt;br /&gt;
      # Bookmark with the same url exists.&lt;br /&gt;
    else&lt;br /&gt;
      bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
      # Bookmark with the same user - bmapping exists.&lt;br /&gt;
      if (bmapping)&lt;br /&gt;
        topic = SignUpTopic.find(topic_id)&lt;br /&gt;
        if(topic)&lt;br /&gt;
          topic.bmappings.each do |mapping|&lt;br /&gt;
            if (mapping.id == bmapping.id)&lt;br /&gt;
              Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Signup Topic does not exists&lt;br /&gt;
        else&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmapping.id)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
      else&lt;br /&gt;
        # Increment user count for the existing bookmark&lt;br /&gt;
        bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
        bookmark_resource.save&lt;br /&gt;
        # Add its association with the user&lt;br /&gt;
        bmappingid = Bmapping.add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
        Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes manually=&lt;br /&gt;
&lt;br /&gt;
===User2 Role===&lt;br /&gt;
&lt;br /&gt;
In order to inspect the changes made to the bookmark mode manually, you can visit our deployed Expertiza at &amp;lt;b&amp;gt;[http://52.11.88.182:3000 Demo]&amp;lt;/b&amp;gt; and use the following credentials:&lt;br /&gt;
     &amp;lt;b&amp;gt;User Name: &amp;lt;/b&amp;gt; &amp;lt;i&amp;gt;user2&amp;lt;/i&amp;gt;&lt;br /&gt;
     &amp;lt;b&amp;gt;Password: &amp;lt;/b&amp;gt; &amp;lt;i&amp;gt; any password&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can notice in the credentials above, you can type in any password you wish in order to log in as user2. We have accomplished this by disabling the authentication and the reason behind it was to have an easily reachable user account for test and development purposes.&lt;br /&gt;
&lt;br /&gt;
The below screenshots demonstrate the working of search features .&lt;br /&gt;
&lt;br /&gt;
===Search for all tags for all users===&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot; http://localhost:3000/bookmarks/viewing_bookmarks&amp;quot; and click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:SearchAllTagsAllUsers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for all tags for user===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;  http://localhost:3000/bookmarks/managing_bookmarks &amp;quot;  to view all tags for the user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchAlltagsForUser.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for tags for all users===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;  http://localhost:3000/bookmarks/view_bookmarks  &amp;quot; , enter the tags separated by comma (example - tag1,tag2) and then click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchForTagsAllUsers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for tags for user===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;http://localhost:3000/bookmarks/managing_bookmarks&amp;quot; , enter the tags separated by comma (example - tag1,tag2) and then click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchForTagsForUser.png]]&lt;br /&gt;
&lt;br /&gt;
=Automated Tests=&lt;br /&gt;
&lt;br /&gt;
===Functional test suite===&lt;br /&gt;
&lt;br /&gt;
We have developed a suit of extensive unit tests covering all the functionality that we have add/modified in the forked version of Expertiza. The test suite consists of 9 tests providing 14 assertions that cover the functionality of all the method changes described in the former sections of this wiki page. The source code for these tests is stored in &amp;lt;i&amp;gt;test/models/bookmark_test.rb&amp;lt;/i&amp;gt; file. You can run this test suite by simply navigating to expertiza project directory and running command: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ruby -I test test/models/bookmark_test.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Integration (Cucumber) tests===&lt;br /&gt;
&lt;br /&gt;
In addition to functional tests, we have also provided a Cucumber test as an integration test. The goal of this test is to show that a user can access the &amp;lt;i&amp;gt;Manage Bookmarks&amp;lt;/i&amp;gt; page upon successful log in, proving that bookmarks view have been successfully integrated into expertiza system. The construct of this test can be found in following files:&lt;br /&gt;
&amp;lt;pre&amp;gt;features/bookmark.feature &lt;br /&gt;
features/step_definitions/bookmark_steps&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run this cucumber test, please navigate to expertiza project directory and run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rake cucumber&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/manish211/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://52.11.88.182:3000/ Demo link] - This might not be available after May of 2015&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1J0WUBtYV_MDhpEQ-50z8gXE-OrvVkpEaZxvn_9RCAsM/edit#heading=h.mo1zn1d9w38l The OSS project requirements doc (Spring 2015 - Expertiza)]&lt;br /&gt;
#[https://drive.google.com/a/ncsu.edu/file/d/0B49VkAq-KMtebXBILUlTQktBVnM/view?usp=sharing Demo of Test suite]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Single_responsibility_principle Single Responsibility Principle]&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1504_IMV&amp;diff=96001</id>
		<title>CSC/ECE 517 Spring 2015/oss E1504 IMV</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1504_IMV&amp;diff=96001"/>
		<updated>2015-03-28T22:50:43Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* After Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1504. Refactoring the Bookmark Model'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This team project successfully refactored the Bookmark Model by removing the duplicate code, combining the methods, improving the search function, moving Bmapping model methods to their respective class, covering dependencies associated with changed segments and adding a User Interface for using bookmarks.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 bookmark.rb&lt;br /&gt;
 bmapping.rb&lt;br /&gt;
 bookmarks_controller.rb&lt;br /&gt;
 auth_controller.rb&lt;br /&gt;
 auth_helper.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The bookmark model and controller work together to create and maintain user specific bookmarks, which can be added to different topics. Moreover, the user that created a bookmark can use his privilege to edit it at a later point in time. As a functionality added for convenience, any user can search bookmarks by either users who created them or their bookmark tags.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;The search methods in bookmarks model are being used used on a very granular level. This led to redundancy in bookmarks search methods. These methods include &amp;lt;i&amp;gt;search_alltags_allusers, search_fortags_allusers, search_fortags_forusers, search_alltags_forusers&amp;lt;/i&amp;gt;. Hence duplicates in these methods are to be singled out. &amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Following the CRUD declaration in Ruby on Rails, where the method name should specify the pseudo use of itself,methods such as &amp;lt;i&amp;gt;add_new_bookmark&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;edit_this_bookmark&amp;lt;/i&amp;gt; have violate this naming convention. Therefore, we need to change the names of these two methods to &amp;lt;i&amp;gt;create&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt;, respectively. Upon changing the names, all the dependencies need to be updated, as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Refactor &amp;lt;i&amp;gt;add_topic_bookmark&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;add_this_bookmark&amp;lt;/i&amp;gt; by removing the repetitive code. These two methods differ only in 2 lines of code, which make it reasonable to merge them together into a single method that provides functionality of both individual methods.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Fix the bug in &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method where only bookmarks without &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; can be properly created. We add the functionality to this method to allow it to also create bookmarks with provided &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;.&lt;br /&gt;
   &amp;lt;li&amp;gt;Methods &amp;lt;i&amp;gt;add_bmapping&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; need to be moved to their appropriate model (Bmapping model) rather than reside in Bookmarks model. Completing this task involves checking the dependencies and updating the function calls for these methods, accordingly.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Add user interface for Bookmarks as this functionality has not been a part of Expertiza&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Create a functional tests suite covering the functionality of all the methods that have been changed by our team.&lt;br /&gt;
   &amp;lt;li&amp;gt;Create a Cucumber integration test to show the functionality of added user interface for Bookmarks.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
= Design Patterns Followed =&lt;br /&gt;
'''Single Responsibility Principle:'''&lt;br /&gt;
&lt;br /&gt;
As per Single Responsibility Principle, every class should have responsibility over a single part of functionality provided by software and that responsibility should be entirely encapsulated by the class. All the services and operations within the class should be aligned with that responsibility. &lt;br /&gt;
Following this principle, we found that methods &amp;lt;i&amp;gt; add_bmapping &amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt; add_bmapping_signuptopic &amp;lt;/i&amp;gt; were present in the Bookmark model, while they actually belong to Bmapping model. So we moved those methods to the Bmapping model and took care of all the dependencies. We created functional tests for these methods to prove that refactoring was successful.&lt;br /&gt;
&lt;br /&gt;
'''Polymorphism:'''&lt;br /&gt;
&lt;br /&gt;
We realized that the methods &amp;lt;i&amp;gt;search_fortags_allusers&amp;lt;/i&amp;gt;,&amp;lt;i&amp;gt;search_fortags_forusers&amp;lt;/i&amp;gt; could be combined into one method. Similarly, &amp;lt;i&amp;gt;search_alltags_allusers&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;search_alltags_forusers&amp;lt;/i&amp;gt; could be grouped together into a single method. The reason for this is because these methods, essentially, offer the same functionality, but using different parameters. So, we wrote a common method which takes parameters and, based on the parameters passed, it provides the required functionality.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==Bookmark Model==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| add_this_bookmark&lt;br /&gt;
| Added functionality of add_topic_bookmark&lt;br /&gt;
| To implement code reusability and remove repetitive code.&lt;br /&gt;
|-&lt;br /&gt;
| add_topic_bookmark &lt;br /&gt;
| Merged the functionality into add_this_bookmarks and deleted add_topic_bookmark&lt;br /&gt;
| To implement code reusability and remove repetitive code.&lt;br /&gt;
|-&lt;br /&gt;
| add_bookmark &lt;br /&gt;
| Added a line that checks whether topic_id has been provided in the request&lt;br /&gt;
| It allows creation of new Bmapping if no topic_id was given and removes the bug of searching for bookmark with nil topic_id later on&lt;br /&gt;
|-&lt;br /&gt;
| search_alltags_allusers&lt;br /&gt;
| |Merged search_alltags_allusers and search_alltags_foruser functions into search_alltags&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_alltags_foruser &lt;br /&gt;
| |Merged search_alltags_allusers and search_alltags_foruser functions into search_alltags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_fortags_allusers&lt;br /&gt;
| | Merged search_fortags_allusers and search_fortags_foruser functions into search_fortags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_fortags_foruser&lt;br /&gt;
| Merged search_fortags_allusers and search_fortags_foruser functions into search_fortags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| add_new_bookmark &lt;br /&gt;
| Changed the method name to &amp;quot;create&amp;quot;&lt;br /&gt;
| It is a much more meaningful and simpler name for a method that creates a new bookmark&lt;br /&gt;
|-&lt;br /&gt;
| edit_this_bookmark &lt;br /&gt;
| Changed the name to &amp;quot;edit&amp;quot;&lt;br /&gt;
| It is a much more appropriate name for a method that edits the bookmark it was called on&lt;br /&gt;
|-&lt;br /&gt;
| add_bmapping&lt;br /&gt;
| Moved to class 'Bmapping'&lt;br /&gt;
| This method helps in creating new bmapping. Hence it makes more sense if it belongs to bmapping class itself.&lt;br /&gt;
|-&lt;br /&gt;
| add_bmapping_signuptopic&lt;br /&gt;
| Moved to class 'Bmapping'&lt;br /&gt;
| This method helps in adding a signup topic to a newly created bmapping. Hence it makes more sense if it belongs to bmapping class itself.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Bookmark Controller==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| view_topic_bookmarks&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was not being accessed.&lt;br /&gt;
|-&lt;br /&gt;
| view_review_bookmarks&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was not being accessed.&lt;br /&gt;
|-&lt;br /&gt;
| view&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| edit_bookmark_form&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| create_tag_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| edit_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;edit_this_bookmark&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt;&lt;br /&gt;
| The method name has been refactored to &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt; as per the requirement&lt;br /&gt;
|-&lt;br /&gt;
| add_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;add_topic_bookmark&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;add_this_bookmark&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect method name, the method was inaccessible&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Views==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| bookmarks/_result.html.erb &lt;br /&gt;
| removed asctime from the below line&lt;br /&gt;
| Was throwing error&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/search_bookmarks.html.erb&lt;br /&gt;
| removed unused code&lt;br /&gt;
| not used &lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/view_bookmarks.html.erb&lt;br /&gt;
| Changed line to &amp;lt;%= link_to('Back', session[:comingFrom]) %&amp;gt;&lt;br /&gt;
| To make the back link work&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/_searchmine.html.erb&lt;br /&gt;
| changed line to&amp;lt;%= form_tag(:action =&amp;gt; &amp;quot;search_bookmarks&amp;quot;) do%&amp;gt;&lt;br /&gt;
| % was used instead of %= and it was throwing error&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/add_bookmark_form.html.erb&lt;br /&gt;
| &amp;lt;%= form_tag(:action =&amp;gt; &amp;quot;add_bookmark&amp;quot;, :method =&amp;gt; &amp;quot;post&amp;quot;) do %&amp;gt;&lt;br /&gt;
| % used instead of %= and it was not working&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/managing_bookmarks.html.erb&lt;br /&gt;
| added partials &lt;br /&gt;
| Nothing was there before to display&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| tree_display/list.html.erb&lt;br /&gt;
| added a link to Manage Bookmarks page&lt;br /&gt;
| This allows a user to see the link to Managing Bookmarks page as soon as the user logs in.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring add_this_bookmark and add_topic_bookmark ==&lt;br /&gt;
&lt;br /&gt;
The consistency of these two methods shows plenty of repetitive code. In order to effectively refactor these methods and reuse the code they both need, our team merged the two methods together by enabling add_this_bookmark method to handle creation of a bookmark when a topic id is provided (main functionality of add_topic_bookmark method). Once we implemented this change on add_this_bookmark method, we deleted add_topic_bookmark method as it became obsolete. Therefore, we retained the same functionality while reducing the method by 7 repetitive lines of code. &lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
&lt;br /&gt;
Please note that these two methods only differ in a single line of code (line 6 and 16) where line 6 takes an extra parameter (&amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 1:  def self.add_topic_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topicid)&lt;br /&gt;
 2:    # Check if the bookmark exists and add / edit based on that&lt;br /&gt;
 3:    bookmark_exists = check_bookmark_exists(b_url)&lt;br /&gt;
 4:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
 5:    if (!bookmark_exists || !bmapping_exists)&lt;br /&gt;
 6:      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
 7:    elsif (bmapping_exists)&lt;br /&gt;
 8:      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
 9:    end&lt;br /&gt;
10:  end&lt;br /&gt;
11:&lt;br /&gt;
12:  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
13:    bookmark_exists = check_bookmark_exists(b_url)&lt;br /&gt;
14:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
15:    if (!bookmark_exists || !bmapping_exists)&lt;br /&gt;
16:      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
17:    elsif (bmapping_exists)&lt;br /&gt;
18:      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
19:    end&lt;br /&gt;
20:  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 1:  #Adds bookmark with and without topic_id&lt;br /&gt;
 2:  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topic_id)&lt;br /&gt;
 3:    # first check existence of the given bookmark and bmapping name&lt;br /&gt;
 5:    bookmark_exists = check_bookmark_exists(b_url) &lt;br /&gt;
 6:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
 7:    if (!bookmark_exists || !bmapping_exists) # they don't exists, so create new ones&lt;br /&gt;
 8:      if(topic_id) # topic_id has been provided&lt;br /&gt;
 9:        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
10:      else # topic_id has not been provided&lt;br /&gt;
11:        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user, nil)&lt;br /&gt;
12:      end&lt;br /&gt;
13:    elsif (bmapping_exists) # if the bmapping already exists, edit it instead of creating a new one&lt;br /&gt;
14:      Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
15:    end&lt;br /&gt;
16:  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Fixing a bug in &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method ==&lt;br /&gt;
&lt;br /&gt;
Our team fixed the bug associate with &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; nil being provided to &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method (user has not specified &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;) when creating a bookmark. We include an if statement that calls &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; method only if the provided &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; is not nil. This change has been implemented on line 9 in the code block shown bellow.&lt;br /&gt;
&lt;br /&gt;
=== Before changes ===&lt;br /&gt;
Parts such as &amp;lt;b&amp;gt;bookmark_resource.nil?&amp;lt;/b&amp;gt; need to be refactored to a shorter version &amp;lt;b&amp;gt;!bookmark_resource&amp;lt;/b&amp;gt;. Similar opportunity to refactor comes up 2 more times within this code block (&amp;lt;b&amp;gt; !bmapping.nil? , !topic.nil?&amp;lt;/b&amp;gt;). We also need to change the first &amp;lt;i&amp;gt;if&amp;lt;/i&amp;gt; block to enable signup topic to be added only if topic_id does not already exists. Doing this will fix the bug of signup_topic overwriting an existing topic_id in case if topic was already created in the past.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if bookmark_resource.nil?&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = add_new_bookmark(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        # Add its association to the sign up topic&lt;br /&gt;
        add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if ( !bmapping.nil? )&lt;br /&gt;
          topic = SignUpTopic.find(topicid)&lt;br /&gt;
          if( !topic.nil? )&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            add_bmapping_signuptopic(topicid, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== After Changes ===&lt;br /&gt;
Once the changes described in the &amp;lt;i&amp;gt;Before Change&amp;lt;/i&amp;gt; section were carried out, the code looks cleaner, the bug with topic_id is removed and the code functions marvelously!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if !bookmark_resource # if bookmark resource is nil (does not exist)&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = create(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = Bmapping.add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        if(topic_id) # if topic_id was provided, add the signup topic&lt;br /&gt;
          # Add its association to the sign up topic if the topic was provided&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if (bmapping) # if bmapping exists (it is not nil), look it up and edit the bookmarks&lt;br /&gt;
          topic = SignUpTopic.find(topic_id)&lt;br /&gt;
          if(topic) # if topic exists (it is not nil) use it to edit bookmark&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            Bmapping.add_bmapping_signuptopic(topic_id, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = Bmapping.add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 3 : Refactoring search_fortags_allusers and search_fortags_forusers ==&lt;br /&gt;
&lt;br /&gt;
Both these methods contain almost the same code except for few conditional lines. search_fortags_allusers searches for all tags for all users whereas search_fortags_forusers searches only for those tags that belong to the user. The code for both these functions differed only in the query clause where at one place it checks for records returned for a specific user and at the other place, it does not have this check.&lt;br /&gt;
&lt;br /&gt;
===Before Changes: search_fortags_allusers function ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def  self.search_fortags_allusers(tags_array, order_by)&lt;br /&gt;
&lt;br /&gt;
      result_array = Array.new # returns this array&lt;br /&gt;
      ## find the tags associated with these tagnames&lt;br /&gt;
      @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      ## retreive mapping_ids taggeed with all of the word tags&lt;br /&gt;
      ## for every word, search for every bookmark that was tagged with that word. Then take the intersection of all the bmapping_ids&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
&lt;br /&gt;
        q_tuples = BmappingsTags.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
&lt;br /&gt;
        if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          temp_array = Array.new&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
          @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
      ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
      temp_result_records =  Bmapping.where([&amp;quot;id in (?)&amp;quot;, @q_tuples_with_all_tags])&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      if (order_by ==&amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
      ## for evey bmapping_id, create a hash, and push into the result_array&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] = result.user.name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id =?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes: search_fortags_foruser function===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def self.search_fortags_foruser(tags_array, this_user_id, order_by)&lt;br /&gt;
      #order by is in &amp;quot;most_popular&amp;quot; and &amp;quot;most_recent&amp;quot;&lt;br /&gt;
      result_array = Array.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## search for ids of the tags&lt;br /&gt;
      @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
        ##search for all qualifier tuples with b&lt;br /&gt;
        q_tuples = BmappingsTags.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
        #for q_t in q_tuples&lt;br /&gt;
        #end&lt;br /&gt;
&lt;br /&gt;
        if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          temp_array = Array.new&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
          @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
      temp_result_records =  Bmapping.where([&amp;quot;id in (?) and user_id = ?&amp;quot;, @q_tuples_with_all_tags,this_user_id ])&lt;br /&gt;
&lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      if (order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] =  User.find(this_user_id).name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id=?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The above two functions are merged into a single function named &amp;quot;search_fortags function&amp;quot; as shown below. If we want to search for specified tags for all users, the userid is passed as nil. If we want to search for the specified tags belonging to a particular userid, we pass that userid. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      ## searches for tspecified tags, among a specified user, orders them by most popular and the most recently added&lt;br /&gt;
    def self.search_fortags(tags_array, order_by,this_user_id)&lt;br /&gt;
      #order by is in &amp;quot;most_popular&amp;quot; and &amp;quot;most_recent&amp;quot;&lt;br /&gt;
      result_array = Array.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## search for ids of the tags&lt;br /&gt;
     @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
        ##search for all qualifier tuples with b&lt;br /&gt;
        q_tuples = BmappingsTag.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
        #if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          #first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        # else&lt;br /&gt;
        #   temp_array = Array.new&lt;br /&gt;
        #   for q_t in q_tuples&lt;br /&gt;
        #     temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
        #   end&lt;br /&gt;
        #   @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        # end&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      ##If the user id is passed, it will not be nil. So we use it in the query as shown below.&lt;br /&gt;
      if(this_user_id != nil)&lt;br /&gt;
        ## now you have qualifer tuples with all the required bmapping ids and the requested userid- search for the req ones&lt;br /&gt;
        temp_result_records =  Bmapping.where([&amp;quot;id in (?) and user_id = ?&amp;quot;, @q_tuples_with_all_tags, this_user_id ])&lt;br /&gt;
      else&lt;br /&gt;
        ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
        temp_result_records =  Bmapping.where([&amp;quot;id in (?)&amp;quot;, @q_tuples_with_all_tags])&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      if (order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
     &lt;br /&gt;
&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] =  result.user.name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id=?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes:search_alltags_foruser function===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.search_alltags_foruser (the_userid, order_by)&lt;br /&gt;
        result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
        if(order_by == &amp;quot;most_recent&amp;quot; )&lt;br /&gt;
          ## find all the bmappings in this system, created by this user, order them by the date created.&lt;br /&gt;
          # For each tuple returned from the bmapping, generate a hash, containing the url, the specified user's name, date this mapping was made,&lt;br /&gt;
          ## title, and description provided by this user. Store these hashes sequentially in a array ad return the array&lt;br /&gt;
&lt;br /&gt;
          result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        elsif ( order_by == &amp;quot;most_popular&amp;quot;)&lt;br /&gt;
          ### retrieving the most popular records that this user.(The user need not be the discoverer). First retrieve the the user's bookmarks from the bmapping.&lt;br /&gt;
          ### order these records, based on the user_count of the url&lt;br /&gt;
          temp_result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid])&lt;br /&gt;
          ## order result records by result.user_count a.sort {|x,y| y &amp;lt;=&amp;gt; x }&lt;br /&gt;
          result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count}&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] =BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        return result_array&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes : search_alltags_allusers function ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.search_alltags_allusers(order_by)&lt;br /&gt;
      result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      if(order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        ## find all the records in the system, order them by the date created. Using Bmapping here. Returns mappings that where created most recently,&lt;br /&gt;
        ## the user that created this mapping, the title and description provided this user&lt;br /&gt;
        result_records = Bmapping.all(:order =&amp;gt;&amp;quot;date_created DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = result.user.name # displaying the newest owner of the bookmark,&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
          result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count ## number of people having this user in their repository&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
          tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
      elsif (order_by == &amp;quot;most_popular&amp;quot;)&lt;br /&gt;
        ## returns the url boomarked by the most number of users, the discoverer of that url, the title and description provided by the discoverer&lt;br /&gt;
        result_records = Bookmark.all(:order =&amp;gt;&amp;quot;user_count DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = User.find(result.discoverer_user_id).name&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.user_count&lt;br /&gt;
          b_u_mapping = Bmapping.where([&amp;quot;bookmark_id = ? and user_id = ?&amp;quot;, result.id, result.discoverer_user_id]).first&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = b_u_mapping.id&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = b_u_mapping.description&lt;br /&gt;
          result_hash[&amp;quot;title&amp;quot;] = b_u_mapping.title&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
          tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,b_u_mapping.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The above two functions were merged into a single function &amp;quot;search_alltags&amp;quot; as shown below. If we want to search for all tags for all users, the userid is passed as nil. If we want to search for all tags belonging to a particular userid, we pass that userid. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def self.search_alltags (the_userid, order_by)&lt;br /&gt;
&lt;br /&gt;
        result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
        if(order_by == &amp;quot;most_recent&amp;quot; )&lt;br /&gt;
          ## find all the bmappings in this system, created by this user, order them by the date created.&lt;br /&gt;
          # For each tuple returned from the bmapping, generate a hash, containing the url, the specified user's name, date this mapping was made,&lt;br /&gt;
          ## title, and description provided by this user. Store these hashes sequentially in a array ad return the array&lt;br /&gt;
 &lt;br /&gt;
          ## If no user id is passed, the search is for all the user ids&lt;br /&gt;
          if(the_userid == nil)&lt;br /&gt;
            ## find all the records in the system, order them by the date created. Using Bmapping here. Returns mappings that where created most recently,&lt;br /&gt;
            ## the user that created this mapping, the title and description provided this user&lt;br /&gt;
            &lt;br /&gt;
            result_records = Bmapping.all.order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          else&lt;br /&gt;
            result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          end&lt;br /&gt;
          &lt;br /&gt;
          #result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = result.user.name&lt;br /&gt;
            result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
        elsif ( order_by == &amp;quot;most_popular&amp;quot; and the_userid != nil) ## Most popular tags for the supplied user&lt;br /&gt;
          ### retrieving the most popular records that this user.(The user need not be the discoverer). First retrieve the the user's bookmarks from the bmapping.&lt;br /&gt;
          ### order these records, based on the user_count of the url&lt;br /&gt;
          temp_result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid])&lt;br /&gt;
          ## order result records by result.user_count a.sort {|x,y| y &amp;lt;=&amp;gt; x }&lt;br /&gt;
          result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count}&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] =BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        elsif (order_by == &amp;quot;most_popular&amp;quot; and the_userid == nil) ## Most popular tags for all users&lt;br /&gt;
        ## returns the url boomarked by the most number of users, the discoverer of that url, the title and description provided by the discoverer&lt;br /&gt;
        result_records = Bookmark.all(:order =&amp;gt;&amp;quot;user_count DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = User.find(result.discoverer_user_id).name&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.user_count&lt;br /&gt;
          b_u_mapping = Bmapping.where([&amp;quot;bookmark_id = ? and user_id = ?&amp;quot;, result.id, result.discoverer_user_id]).first&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = b_u_mapping.id&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = b_u_mapping.description&lt;br /&gt;
          result_hash[&amp;quot;title&amp;quot;] = b_u_mapping.title&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
          tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,b_u_mapping.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        return result_array&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 4 : Refactoring &amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt; methods ==&lt;br /&gt;
&lt;br /&gt;
The methods ,&amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt;, add new bmapping to newly added bookmarks. These methods are initially served in bookmarks model. Ideally, they should be serving the bmapping model. &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; is a continuation to &amp;lt;i&amp;gt;add_bmapping&amp;lt;/i&amp;gt;. It adds signup topic to the newly created bmapping. Along with moving these methods from bookmarks model, the team had to check for dependencies for these methods in all corresponding models and take care of them.&lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
&lt;br /&gt;
Changes done to bmapping model. The new added code in this model has been moved from bookmarks model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Bmapping &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :bookmark&lt;br /&gt;
  has_many :bmappings_tags&lt;br /&gt;
  has_and_belongs_to_many :sign_up_topics&lt;br /&gt;
  has_many :ratings, :class_name =&amp;gt; &amp;quot;BmappingRatings&amp;quot;, :foreign_key =&amp;gt; &amp;quot;bmapping_id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  def cumulative_rating&lt;br /&gt;
    rating = 0.0&lt;br /&gt;
    count = 0&lt;br /&gt;
    self.ratings.each do |br|&lt;br /&gt;
      rating = rating + br.rating&lt;br /&gt;
      count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; 0&lt;br /&gt;
      return rating/count&lt;br /&gt;
    else&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Bmapping &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :bookmark&lt;br /&gt;
  has_many :bmappings_tags&lt;br /&gt;
  has_and_belongs_to_many :sign_up_topics&lt;br /&gt;
  has_many :ratings, :class_name =&amp;gt; &amp;quot;BmappingRatings&amp;quot;, :foreign_key =&amp;gt; &amp;quot;bmapping_id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  def cumulative_rating&lt;br /&gt;
    rating = 0.0&lt;br /&gt;
    count = 0&lt;br /&gt;
    self.ratings.each do |br|&lt;br /&gt;
      rating = rating + br.rating&lt;br /&gt;
      count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; 0&lt;br /&gt;
      return rating/count&lt;br /&gt;
    else&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # Add bookmark - user association with its meta fields&lt;br /&gt;
    def self.add_bmapping(bid, b_title, user_id, b_description,b_tags_text)&lt;br /&gt;
      bookmark_user_mapping = Bmapping.new&lt;br /&gt;
      bookmark_user_mapping.bookmark_id = bid&lt;br /&gt;
      bookmark_user_mapping.title = b_title&lt;br /&gt;
      bookmark_user_mapping.description = b_description&lt;br /&gt;
      bookmark_user_mapping.user_id =user_id&lt;br /&gt;
      current_timestamp = Time.now&lt;br /&gt;
      bookmark_user_mapping.date_created = current_timestamp&lt;br /&gt;
      bookmark_user_mapping.date_modified = current_timestamp&lt;br /&gt;
      bookmark_user_mapping.save&lt;br /&gt;
      # Add tags&lt;br /&gt;
      # tags come in as a text, separating them into a array&lt;br /&gt;
&lt;br /&gt;
      tag_array = BookmarksHelper.separate_tags(b_tags_text)&lt;br /&gt;
      for each_tag in tag_array&lt;br /&gt;
        # Look for each tag that is present in tags, if not make them, then make the BTU entry&lt;br /&gt;
        tag_tuple = Tag.where([&amp;quot;tagname = ?&amp;quot;,each_tag]).first&lt;br /&gt;
        if tag_tuple.nil?&lt;br /&gt;
          tag_tuple = Tag.new&lt;br /&gt;
          tag_tuple.tagname = each_tag&lt;br /&gt;
          tag_tuple.save&lt;br /&gt;
        end&lt;br /&gt;
        # Check if there is an entry for this tag, this user and this bookmark (via bmappings table)&lt;br /&gt;
        btu_tuple = BmappingsTag.where([ &amp;quot;tag_id = ? and bmapping_id = ?&amp;quot;, tag_tuple.id, bookmark_user_mapping.id] ).first&lt;br /&gt;
        if btu_tuple.nil?&lt;br /&gt;
          btu_tuple = BmappingsTag.new&lt;br /&gt;
          btu_tuple.tag_id = tag_tuple.id&lt;br /&gt;
          btu_tuple.bmapping_id = bookmark_user_mapping.id&lt;br /&gt;
          btu_tuple.save&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
        return bookmark_user_mapping.id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
      # Associate bmapping to the sign up topic&lt;br /&gt;
      def self.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        topic = SignUpTopic.find(topic_id)&lt;br /&gt;
        bmapping = Bmapping.find(bmappingid)&lt;br /&gt;
        unless (topic.nil? &amp;amp;&amp;amp; bmapping.nil?)&lt;br /&gt;
          topic.bmappings &amp;lt;&amp;lt; bmapping&lt;br /&gt;
          topic.save&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
The dependencies for these methods are present in only &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; method of bookmark model. As &amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt; methods support &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; in creating new bmapping to bookmarks,the dependencies lie only in &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; method. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if !bookmark_resource&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = add_new_bookmark(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        # Add its association to the sign up topic&lt;br /&gt;
        add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if (bmapping)&lt;br /&gt;
          topic = SignUpTopic.find(topicid)&lt;br /&gt;
          if(topic)&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            add_bmapping_signuptopic(topicid, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
  def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
    bookmark_resource = Bookmark.where([&amp;quot;url = ?&lt;br /&gt;
      &amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
    # Bookmark with the same url does not exists.&lt;br /&gt;
    if !bookmark_resource&lt;br /&gt;
      # Add the newly discovered bookmark&lt;br /&gt;
      bookmarkid = create(b_url,session_user.id)&lt;br /&gt;
      # Add its associations to a user&lt;br /&gt;
      bmappingid = Bmapping.add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
      if(topic_id)&lt;br /&gt;
        # Add its association to the sign up topic if the topic was provided&lt;br /&gt;
        Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
      end&lt;br /&gt;
      # Bookmark with the same url exists.&lt;br /&gt;
    else&lt;br /&gt;
      bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
      # Bookmark with the same user - bmapping exists.&lt;br /&gt;
      if (bmapping)&lt;br /&gt;
        topic = SignUpTopic.find(topic_id)&lt;br /&gt;
        if(topic)&lt;br /&gt;
          topic.bmappings.each do |mapping|&lt;br /&gt;
            if (mapping.id == bmapping.id)&lt;br /&gt;
              Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Signup Topic does not exists&lt;br /&gt;
        else&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmapping.id)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
      else&lt;br /&gt;
        # Increment user count for the existing bookmark&lt;br /&gt;
        bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
        bookmark_resource.save&lt;br /&gt;
        # Add its association with the user&lt;br /&gt;
        bmappingid = Bmapping.add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
        Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes manually=&lt;br /&gt;
&lt;br /&gt;
===User2 Role===&lt;br /&gt;
&lt;br /&gt;
In order to inspect the changes made to the bookmark mode manually, you can visit our deployed Expertiza at &amp;lt;b&amp;gt;[http://52.11.88.182:3000 Demo]&amp;lt;/b&amp;gt; and use the following credentials:&lt;br /&gt;
     &amp;lt;b&amp;gt;User Name: &amp;lt;/b&amp;gt; &amp;lt;i&amp;gt;user2&amp;lt;/i&amp;gt;&lt;br /&gt;
     &amp;lt;b&amp;gt;Password: &amp;lt;/b&amp;gt; &amp;lt;i&amp;gt; any password&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can notice in the credentials above, you can type in any password you wish in order to log in as user2. We have accomplished this by disabling the authentication and the reason behind it was to have an easily reachable user account for test and development purposes.&lt;br /&gt;
&lt;br /&gt;
The below screenshots demonstrate the working of search features .&lt;br /&gt;
&lt;br /&gt;
===Search for all tags for all users===&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot; http://localhost:3000/bookmarks/viewing_bookmarks&amp;quot; and click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:SearchAllTagsAllUsers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for all tags for user===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;  http://localhost:3000/bookmarks/managing_bookmarks &amp;quot;  to view all tags for the user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchAlltagsForUser.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for tags for all users===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;  http://localhost:3000/bookmarks/view_bookmarks  &amp;quot; , enter the tags separated by comma (example - tag1,tag2) and then click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchForTagsAllUsers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for tags for user===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;http://localhost:3000/bookmarks/managing_bookmarks&amp;quot; , enter the tags separated by comma (example - tag1,tag2) and then click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchForTagsForUser.png]]&lt;br /&gt;
&lt;br /&gt;
=Automated Tests=&lt;br /&gt;
&lt;br /&gt;
===Functional test suite===&lt;br /&gt;
&lt;br /&gt;
We have developed a suit of extensive unit tests covering all the functionality that we have add/modified in the forked version of Expertiza. The test suite consists of 9 tests providing 14 assertions that cover the functionality of all the method changes described in the former sections of this wiki page. The source code for these tests is stored in &amp;lt;i&amp;gt;test/models/bookmark_test.rb&amp;lt;/i&amp;gt; file. You can run this test suite by simply navigating to expertiza project directory and running command: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ruby -I test test/models/bookmark_test.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Integration (Cucumber) tests===&lt;br /&gt;
&lt;br /&gt;
In addition to functional tests, we have also provided a Cucumber test as an integration test. The goal of this test is to show that a user can access the &amp;lt;i&amp;gt;Manage Bookmarks&amp;lt;/i&amp;gt; page upon successful log in, proving that bookmarks view have been successfully integrated into expertiza system. The construct of this test can be found in following files:&lt;br /&gt;
&amp;lt;pre&amp;gt;features/bookmark.feature &lt;br /&gt;
features/step_definitions/bookmark_steps&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run this cucumber test, please navigate to expertiza project directory and run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rake cucumber&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/manish211/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://52.11.88.182:3000/ Demo link] - This might not be available after May of 2015&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1J0WUBtYV_MDhpEQ-50z8gXE-OrvVkpEaZxvn_9RCAsM/edit#heading=h.mo1zn1d9w38l The OSS project requirements doc (Spring 2015 - Expertiza)]&lt;br /&gt;
#[https://drive.google.com/a/ncsu.edu/file/d/0B49VkAq-KMtebXBILUlTQktBVnM/view?usp=sharing Demo of Test suite]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Single_responsibility_principle Single Responsibility Principle]&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1504_IMV&amp;diff=96000</id>
		<title>CSC/ECE 517 Spring 2015/oss E1504 IMV</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1504_IMV&amp;diff=96000"/>
		<updated>2015-03-28T22:49:18Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Before Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1504. Refactoring the Bookmark Model'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This team project successfully refactored the Bookmark Model by removing the duplicate code, combining the methods, improving the search function, moving Bmapping model methods to their respective class, covering dependencies associated with changed segments and adding a User Interface for using bookmarks.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 bookmark.rb&lt;br /&gt;
 bmapping.rb&lt;br /&gt;
 bookmarks_controller.rb&lt;br /&gt;
 auth_controller.rb&lt;br /&gt;
 auth_helper.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The bookmark model and controller work together to create and maintain user specific bookmarks, which can be added to different topics. Moreover, the user that created a bookmark can use his privilege to edit it at a later point in time. As a functionality added for convenience, any user can search bookmarks by either users who created them or their bookmark tags.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;The search methods in bookmarks model are being used used on a very granular level. This led to redundancy in bookmarks search methods. These methods include &amp;lt;i&amp;gt;search_alltags_allusers, search_fortags_allusers, search_fortags_forusers, search_alltags_forusers&amp;lt;/i&amp;gt;. Hence duplicates in these methods are to be singled out. &amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Following the CRUD declaration in Ruby on Rails, where the method name should specify the pseudo use of itself,methods such as &amp;lt;i&amp;gt;add_new_bookmark&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;edit_this_bookmark&amp;lt;/i&amp;gt; have violate this naming convention. Therefore, we need to change the names of these two methods to &amp;lt;i&amp;gt;create&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt;, respectively. Upon changing the names, all the dependencies need to be updated, as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Refactor &amp;lt;i&amp;gt;add_topic_bookmark&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;add_this_bookmark&amp;lt;/i&amp;gt; by removing the repetitive code. These two methods differ only in 2 lines of code, which make it reasonable to merge them together into a single method that provides functionality of both individual methods.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Fix the bug in &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method where only bookmarks without &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; can be properly created. We add the functionality to this method to allow it to also create bookmarks with provided &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;.&lt;br /&gt;
   &amp;lt;li&amp;gt;Methods &amp;lt;i&amp;gt;add_bmapping&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; need to be moved to their appropriate model (Bmapping model) rather than reside in Bookmarks model. Completing this task involves checking the dependencies and updating the function calls for these methods, accordingly.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Add user interface for Bookmarks as this functionality has not been a part of Expertiza&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Create a functional tests suite covering the functionality of all the methods that have been changed by our team.&lt;br /&gt;
   &amp;lt;li&amp;gt;Create a Cucumber integration test to show the functionality of added user interface for Bookmarks.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
= Design Patterns Followed =&lt;br /&gt;
'''Single Responsibility Principle:'''&lt;br /&gt;
&lt;br /&gt;
As per Single Responsibility Principle, every class should have responsibility over a single part of functionality provided by software and that responsibility should be entirely encapsulated by the class. All the services and operations within the class should be aligned with that responsibility. &lt;br /&gt;
Following this principle, we found that methods &amp;lt;i&amp;gt; add_bmapping &amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt; add_bmapping_signuptopic &amp;lt;/i&amp;gt; were present in the Bookmark model, while they actually belong to Bmapping model. So we moved those methods to the Bmapping model and took care of all the dependencies. We created functional tests for these methods to prove that refactoring was successful.&lt;br /&gt;
&lt;br /&gt;
'''Polymorphism:'''&lt;br /&gt;
&lt;br /&gt;
We realized that the methods &amp;lt;i&amp;gt;search_fortags_allusers&amp;lt;/i&amp;gt;,&amp;lt;i&amp;gt;search_fortags_forusers&amp;lt;/i&amp;gt; could be combined into one method. Similarly, &amp;lt;i&amp;gt;search_alltags_allusers&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;search_alltags_forusers&amp;lt;/i&amp;gt; could be grouped together into a single method. The reason for this is because these methods, essentially, offer the same functionality, but using different parameters. So, we wrote a common method which takes parameters and, based on the parameters passed, it provides the required functionality.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==Bookmark Model==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| add_this_bookmark&lt;br /&gt;
| Added functionality of add_topic_bookmark&lt;br /&gt;
| To implement code reusability and remove repetitive code.&lt;br /&gt;
|-&lt;br /&gt;
| add_topic_bookmark &lt;br /&gt;
| Merged the functionality into add_this_bookmarks and deleted add_topic_bookmark&lt;br /&gt;
| To implement code reusability and remove repetitive code.&lt;br /&gt;
|-&lt;br /&gt;
| add_bookmark &lt;br /&gt;
| Added a line that checks whether topic_id has been provided in the request&lt;br /&gt;
| It allows creation of new Bmapping if no topic_id was given and removes the bug of searching for bookmark with nil topic_id later on&lt;br /&gt;
|-&lt;br /&gt;
| search_alltags_allusers&lt;br /&gt;
| |Merged search_alltags_allusers and search_alltags_foruser functions into search_alltags&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_alltags_foruser &lt;br /&gt;
| |Merged search_alltags_allusers and search_alltags_foruser functions into search_alltags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_fortags_allusers&lt;br /&gt;
| | Merged search_fortags_allusers and search_fortags_foruser functions into search_fortags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_fortags_foruser&lt;br /&gt;
| Merged search_fortags_allusers and search_fortags_foruser functions into search_fortags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| add_new_bookmark &lt;br /&gt;
| Changed the method name to &amp;quot;create&amp;quot;&lt;br /&gt;
| It is a much more meaningful and simpler name for a method that creates a new bookmark&lt;br /&gt;
|-&lt;br /&gt;
| edit_this_bookmark &lt;br /&gt;
| Changed the name to &amp;quot;edit&amp;quot;&lt;br /&gt;
| It is a much more appropriate name for a method that edits the bookmark it was called on&lt;br /&gt;
|-&lt;br /&gt;
| add_bmapping&lt;br /&gt;
| Moved to class 'Bmapping'&lt;br /&gt;
| This method helps in creating new bmapping. Hence it makes more sense if it belongs to bmapping class itself.&lt;br /&gt;
|-&lt;br /&gt;
| add_bmapping_signuptopic&lt;br /&gt;
| Moved to class 'Bmapping'&lt;br /&gt;
| This method helps in adding a signup topic to a newly created bmapping. Hence it makes more sense if it belongs to bmapping class itself.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Bookmark Controller==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| view_topic_bookmarks&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was not being accessed.&lt;br /&gt;
|-&lt;br /&gt;
| view_review_bookmarks&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was not being accessed.&lt;br /&gt;
|-&lt;br /&gt;
| view&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| edit_bookmark_form&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| create_tag_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| edit_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;edit_this_bookmark&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt;&lt;br /&gt;
| The method name has been refactored to &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt; as per the requirement&lt;br /&gt;
|-&lt;br /&gt;
| add_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;add_topic_bookmark&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;add_this_bookmark&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect method name, the method was inaccessible&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Views==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| bookmarks/_result.html.erb &lt;br /&gt;
| removed asctime from the below line&lt;br /&gt;
| Was throwing error&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/search_bookmarks.html.erb&lt;br /&gt;
| removed unused code&lt;br /&gt;
| not used &lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/view_bookmarks.html.erb&lt;br /&gt;
| Changed line to &amp;lt;%= link_to('Back', session[:comingFrom]) %&amp;gt;&lt;br /&gt;
| To make the back link work&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/_searchmine.html.erb&lt;br /&gt;
| changed line to&amp;lt;%= form_tag(:action =&amp;gt; &amp;quot;search_bookmarks&amp;quot;) do%&amp;gt;&lt;br /&gt;
| % was used instead of %= and it was throwing error&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/add_bookmark_form.html.erb&lt;br /&gt;
| &amp;lt;%= form_tag(:action =&amp;gt; &amp;quot;add_bookmark&amp;quot;, :method =&amp;gt; &amp;quot;post&amp;quot;) do %&amp;gt;&lt;br /&gt;
| % used instead of %= and it was not working&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/managing_bookmarks.html.erb&lt;br /&gt;
| added partials &lt;br /&gt;
| Nothing was there before to display&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| tree_display/list.html.erb&lt;br /&gt;
| added a link to Manage Bookmarks page&lt;br /&gt;
| This allows a user to see the link to Managing Bookmarks page as soon as the user logs in.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring add_this_bookmark and add_topic_bookmark ==&lt;br /&gt;
&lt;br /&gt;
The consistency of these two methods shows plenty of repetitive code. In order to effectively refactor these methods and reuse the code they both need, our team merged the two methods together by enabling add_this_bookmark method to handle creation of a bookmark when a topic id is provided (main functionality of add_topic_bookmark method). Once we implemented this change on add_this_bookmark method, we deleted add_topic_bookmark method as it became obsolete. Therefore, we retained the same functionality while reducing the method by 7 repetitive lines of code. &lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
&lt;br /&gt;
Please note that these two methods only differ in a single line of code (line 6 and 16) where line 6 takes an extra parameter (&amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 1:  def self.add_topic_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topicid)&lt;br /&gt;
 2:    # Check if the bookmark exists and add / edit based on that&lt;br /&gt;
 3:    bookmark_exists = check_bookmark_exists(b_url)&lt;br /&gt;
 4:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
 5:    if (!bookmark_exists || !bmapping_exists)&lt;br /&gt;
 6:      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
 7:    elsif (bmapping_exists)&lt;br /&gt;
 8:      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
 9:    end&lt;br /&gt;
10:  end&lt;br /&gt;
11:&lt;br /&gt;
12:  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
13:    bookmark_exists = check_bookmark_exists(b_url)&lt;br /&gt;
14:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
15:    if (!bookmark_exists || !bmapping_exists)&lt;br /&gt;
16:      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
17:    elsif (bmapping_exists)&lt;br /&gt;
18:      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
19:    end&lt;br /&gt;
20:  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 1:  #Adds bookmark with and without topic_id&lt;br /&gt;
 2:  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topic_id)&lt;br /&gt;
 3:    # first check existence of the given bookmark and bmapping name&lt;br /&gt;
 5:    bookmark_exists = check_bookmark_exists(b_url) &lt;br /&gt;
 6:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
 7:    if (!bookmark_exists || !bmapping_exists) # they don't exists, so create new ones&lt;br /&gt;
 8:      if(topic_id) # topic_id has been provided&lt;br /&gt;
 9:        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
10:      else # topic_id has not been provided&lt;br /&gt;
11:        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user, nil)&lt;br /&gt;
12:      end&lt;br /&gt;
13:    elsif (bmapping_exists) # if the bmapping already exists, edit it instead of creating a new one&lt;br /&gt;
14:      Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
15:    end&lt;br /&gt;
16:  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Fixing a bug in &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method ==&lt;br /&gt;
&lt;br /&gt;
Our team fixed the bug associate with &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; nil being provided to &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method (user has not specified &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;) when creating a bookmark. We include an if statement that calls &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; method only if the provided &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; is not nil. This change has been implemented on line 9 in the code block shown bellow.&lt;br /&gt;
&lt;br /&gt;
=== Before changes ===&lt;br /&gt;
Parts such as &amp;lt;b&amp;gt;bookmark_resource.nil?&amp;lt;/b&amp;gt; need to be refactored to a shorter version &amp;lt;b&amp;gt;!bookmark_resource&amp;lt;/b&amp;gt;. Similar opportunity to refactor comes up 2 more times within this code block (&amp;lt;b&amp;gt; !bmapping.nil? , !topic.nil?&amp;lt;/b&amp;gt;). We also need to change the first &amp;lt;i&amp;gt;if&amp;lt;/i&amp;gt; block to enable signup topic to be added only if topic_id does not already exists. Doing this will fix the bug of signup_topic overwriting an existing topic_id in case if topic was already created in the past.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if bookmark_resource.nil?&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = add_new_bookmark(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        # Add its association to the sign up topic&lt;br /&gt;
        add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if ( !bmapping.nil? )&lt;br /&gt;
          topic = SignUpTopic.find(topicid)&lt;br /&gt;
          if( !topic.nil? )&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            add_bmapping_signuptopic(topicid, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== After Changes ===&lt;br /&gt;
Once the changes described in the &amp;lt;i&amp;gt;Before Change&amp;lt;/i&amp;gt; section were carried out, the code looks cleaner, the bug with topic_id is removed and the code functions marvelously!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if !bookmark_resource # if bookmark resource is nil (does not exist)&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = create(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = Bmapping.add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        if(topic_id) # if topic_id was provided, add the signup topic&lt;br /&gt;
          # Add its association to the sign up topic if the topic was provided&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if (bmapping) # if bmapping exists (it is not nil), look it up and edit the bookmarks&lt;br /&gt;
          topic = SignUpTopic.find(topic_id)&lt;br /&gt;
          if(topic) # if topic exists (it is not nil) use it to edit bookmark&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            Bmapping.add_bmapping_signuptopic(topic_id, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = Bmapping.add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 3 : Refactoring search_fortags_allusers and search_fortags_forusers ==&lt;br /&gt;
&lt;br /&gt;
Both these methods contain almost the same code except for few conditional lines. search_fortags_allusers searches for all tags for all users whereas search_fortags_forusers searches only for those tags that belong to the user. The code for both these functions differed only in the query clause where at one place it checks for records returned for a specific user and at the other place, it does not have this check.&lt;br /&gt;
&lt;br /&gt;
===Before Changes: search_fortags_allusers function ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def  self.search_fortags_allusers(tags_array, order_by)&lt;br /&gt;
&lt;br /&gt;
      result_array = Array.new # returns this array&lt;br /&gt;
      ## find the tags associated with these tagnames&lt;br /&gt;
      @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      ## retreive mapping_ids taggeed with all of the word tags&lt;br /&gt;
      ## for every word, search for every bookmark that was tagged with that word. Then take the intersection of all the bmapping_ids&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
&lt;br /&gt;
        q_tuples = BmappingsTags.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
&lt;br /&gt;
        if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          temp_array = Array.new&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
          @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
      ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
      temp_result_records =  Bmapping.where([&amp;quot;id in (?)&amp;quot;, @q_tuples_with_all_tags])&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      if (order_by ==&amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
      ## for evey bmapping_id, create a hash, and push into the result_array&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] = result.user.name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id =?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes: search_fortags_foruser function===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def self.search_fortags_foruser(tags_array, this_user_id, order_by)&lt;br /&gt;
      #order by is in &amp;quot;most_popular&amp;quot; and &amp;quot;most_recent&amp;quot;&lt;br /&gt;
      result_array = Array.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## search for ids of the tags&lt;br /&gt;
      @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
        ##search for all qualifier tuples with b&lt;br /&gt;
        q_tuples = BmappingsTags.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
        #for q_t in q_tuples&lt;br /&gt;
        #end&lt;br /&gt;
&lt;br /&gt;
        if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          temp_array = Array.new&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
          @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
      temp_result_records =  Bmapping.where([&amp;quot;id in (?) and user_id = ?&amp;quot;, @q_tuples_with_all_tags,this_user_id ])&lt;br /&gt;
&lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      if (order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] =  User.find(this_user_id).name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id=?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The above two functions are merged into a single function named &amp;quot;search_fortags function&amp;quot; as shown below. If we want to search for specified tags for all users, the userid is passed as nil. If we want to search for the specified tags belonging to a particular userid, we pass that userid. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      ## searches for tspecified tags, among a specified user, orders them by most popular and the most recently added&lt;br /&gt;
    def self.search_fortags(tags_array, order_by,this_user_id)&lt;br /&gt;
      #order by is in &amp;quot;most_popular&amp;quot; and &amp;quot;most_recent&amp;quot;&lt;br /&gt;
      result_array = Array.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## search for ids of the tags&lt;br /&gt;
     @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
        ##search for all qualifier tuples with b&lt;br /&gt;
        q_tuples = BmappingsTag.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
        #if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          #first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        # else&lt;br /&gt;
        #   temp_array = Array.new&lt;br /&gt;
        #   for q_t in q_tuples&lt;br /&gt;
        #     temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
        #   end&lt;br /&gt;
        #   @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        # end&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      ##If the user id is passed, it will not be nil. So we use it in the query as shown below.&lt;br /&gt;
      if(this_user_id != nil)&lt;br /&gt;
        ## now you have qualifer tuples with all the required bmapping ids and the requested userid- search for the req ones&lt;br /&gt;
        temp_result_records =  Bmapping.where([&amp;quot;id in (?) and user_id = ?&amp;quot;, @q_tuples_with_all_tags, this_user_id ])&lt;br /&gt;
      else&lt;br /&gt;
        ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
        temp_result_records =  Bmapping.where([&amp;quot;id in (?)&amp;quot;, @q_tuples_with_all_tags])&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      if (order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
     &lt;br /&gt;
&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] =  result.user.name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id=?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes:search_alltags_foruser function===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.search_alltags_foruser (the_userid, order_by)&lt;br /&gt;
        result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
        if(order_by == &amp;quot;most_recent&amp;quot; )&lt;br /&gt;
          ## find all the bmappings in this system, created by this user, order them by the date created.&lt;br /&gt;
          # For each tuple returned from the bmapping, generate a hash, containing the url, the specified user's name, date this mapping was made,&lt;br /&gt;
          ## title, and description provided by this user. Store these hashes sequentially in a array ad return the array&lt;br /&gt;
&lt;br /&gt;
          result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        elsif ( order_by == &amp;quot;most_popular&amp;quot;)&lt;br /&gt;
          ### retrieving the most popular records that this user.(The user need not be the discoverer). First retrieve the the user's bookmarks from the bmapping.&lt;br /&gt;
          ### order these records, based on the user_count of the url&lt;br /&gt;
          temp_result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid])&lt;br /&gt;
          ## order result records by result.user_count a.sort {|x,y| y &amp;lt;=&amp;gt; x }&lt;br /&gt;
          result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count}&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] =BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        return result_array&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes : search_alltags_allusers function ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.search_alltags_allusers(order_by)&lt;br /&gt;
      result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      if(order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        ## find all the records in the system, order them by the date created. Using Bmapping here. Returns mappings that where created most recently,&lt;br /&gt;
        ## the user that created this mapping, the title and description provided this user&lt;br /&gt;
        result_records = Bmapping.all(:order =&amp;gt;&amp;quot;date_created DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = result.user.name # displaying the newest owner of the bookmark,&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
          result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count ## number of people having this user in their repository&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
          tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
      elsif (order_by == &amp;quot;most_popular&amp;quot;)&lt;br /&gt;
        ## returns the url boomarked by the most number of users, the discoverer of that url, the title and description provided by the discoverer&lt;br /&gt;
        result_records = Bookmark.all(:order =&amp;gt;&amp;quot;user_count DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = User.find(result.discoverer_user_id).name&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.user_count&lt;br /&gt;
          b_u_mapping = Bmapping.where([&amp;quot;bookmark_id = ? and user_id = ?&amp;quot;, result.id, result.discoverer_user_id]).first&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = b_u_mapping.id&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = b_u_mapping.description&lt;br /&gt;
          result_hash[&amp;quot;title&amp;quot;] = b_u_mapping.title&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
          tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,b_u_mapping.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The above two functions were merged into a single function &amp;quot;search_alltags&amp;quot; as shown below. If we want to search for all tags for all users, the userid is passed as nil. If we want to search for all tags belonging to a particular userid, we pass that userid. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def self.search_alltags (the_userid, order_by)&lt;br /&gt;
&lt;br /&gt;
        result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
        if(order_by == &amp;quot;most_recent&amp;quot; )&lt;br /&gt;
          ## find all the bmappings in this system, created by this user, order them by the date created.&lt;br /&gt;
          # For each tuple returned from the bmapping, generate a hash, containing the url, the specified user's name, date this mapping was made,&lt;br /&gt;
          ## title, and description provided by this user. Store these hashes sequentially in a array ad return the array&lt;br /&gt;
 &lt;br /&gt;
          ## If no user id is passed, the search is for all the user ids&lt;br /&gt;
          if(the_userid == nil)&lt;br /&gt;
            ## find all the records in the system, order them by the date created. Using Bmapping here. Returns mappings that where created most recently,&lt;br /&gt;
            ## the user that created this mapping, the title and description provided this user&lt;br /&gt;
            &lt;br /&gt;
            result_records = Bmapping.all.order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          else&lt;br /&gt;
            result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          end&lt;br /&gt;
          &lt;br /&gt;
          #result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = result.user.name&lt;br /&gt;
            result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
        elsif ( order_by == &amp;quot;most_popular&amp;quot; and the_userid != nil) ## Most popular tags for the supplied user&lt;br /&gt;
          ### retrieving the most popular records that this user.(The user need not be the discoverer). First retrieve the the user's bookmarks from the bmapping.&lt;br /&gt;
          ### order these records, based on the user_count of the url&lt;br /&gt;
          temp_result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid])&lt;br /&gt;
          ## order result records by result.user_count a.sort {|x,y| y &amp;lt;=&amp;gt; x }&lt;br /&gt;
          result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count}&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] =BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        elsif (order_by == &amp;quot;most_popular&amp;quot; and the_userid == nil) ## Most popular tags for all users&lt;br /&gt;
        ## returns the url boomarked by the most number of users, the discoverer of that url, the title and description provided by the discoverer&lt;br /&gt;
        result_records = Bookmark.all(:order =&amp;gt;&amp;quot;user_count DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = User.find(result.discoverer_user_id).name&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.user_count&lt;br /&gt;
          b_u_mapping = Bmapping.where([&amp;quot;bookmark_id = ? and user_id = ?&amp;quot;, result.id, result.discoverer_user_id]).first&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = b_u_mapping.id&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = b_u_mapping.description&lt;br /&gt;
          result_hash[&amp;quot;title&amp;quot;] = b_u_mapping.title&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
          tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,b_u_mapping.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        return result_array&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 4 : Refactoring &amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt; methods ==&lt;br /&gt;
&lt;br /&gt;
The methods ,&amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt;, add new bmapping to newly added bookmarks. These methods are initially served in bookmarks model. Ideally, they should be serving the bmapping model. &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; is a continuation to &amp;lt;i&amp;gt;add_bmapping&amp;lt;/i&amp;gt;. It adds signup topic to the newly created bmapping. Along with moving these methods from bookmarks model, the team had to check for dependencies for these methods in all corresponding models and take care of them.&lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
&lt;br /&gt;
Changes done to bmapping model. The new added code in this model has been moved from bookmarks model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Bmapping &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :bookmark&lt;br /&gt;
  has_many :bmappings_tags&lt;br /&gt;
  has_and_belongs_to_many :sign_up_topics&lt;br /&gt;
  has_many :ratings, :class_name =&amp;gt; &amp;quot;BmappingRatings&amp;quot;, :foreign_key =&amp;gt; &amp;quot;bmapping_id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  def cumulative_rating&lt;br /&gt;
    rating = 0.0&lt;br /&gt;
    count = 0&lt;br /&gt;
    self.ratings.each do |br|&lt;br /&gt;
      rating = rating + br.rating&lt;br /&gt;
      count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; 0&lt;br /&gt;
      return rating/count&lt;br /&gt;
    else&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Bmapping &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :bookmark&lt;br /&gt;
  has_many :bmappings_tags&lt;br /&gt;
  has_and_belongs_to_many :sign_up_topics&lt;br /&gt;
  has_many :ratings, :class_name =&amp;gt; &amp;quot;BmappingRatings&amp;quot;, :foreign_key =&amp;gt; &amp;quot;bmapping_id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  def cumulative_rating&lt;br /&gt;
    rating = 0.0&lt;br /&gt;
    count = 0&lt;br /&gt;
    self.ratings.each do |br|&lt;br /&gt;
      rating = rating + br.rating&lt;br /&gt;
      count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; 0&lt;br /&gt;
      return rating/count&lt;br /&gt;
    else&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # Add bookmark - user association with its meta fields&lt;br /&gt;
    def self.add_bmapping(bid, b_title, user_id, b_description,b_tags_text)&lt;br /&gt;
      bookmark_user_mapping = Bmapping.new&lt;br /&gt;
      bookmark_user_mapping.bookmark_id = bid&lt;br /&gt;
      bookmark_user_mapping.title = b_title&lt;br /&gt;
      bookmark_user_mapping.description = b_description&lt;br /&gt;
      bookmark_user_mapping.user_id =user_id&lt;br /&gt;
      current_timestamp = Time.now&lt;br /&gt;
      bookmark_user_mapping.date_created = current_timestamp&lt;br /&gt;
      bookmark_user_mapping.date_modified = current_timestamp&lt;br /&gt;
      bookmark_user_mapping.save&lt;br /&gt;
      # Add tags&lt;br /&gt;
      # tags come in as a text, separating them into a array&lt;br /&gt;
&lt;br /&gt;
      tag_array = BookmarksHelper.separate_tags(b_tags_text)&lt;br /&gt;
      for each_tag in tag_array&lt;br /&gt;
        # Look for each tag that is present in tags, if not make them, then make the BTU entry&lt;br /&gt;
        tag_tuple = Tag.where([&amp;quot;tagname = ?&amp;quot;,each_tag]).first&lt;br /&gt;
        if tag_tuple.nil?&lt;br /&gt;
          tag_tuple = Tag.new&lt;br /&gt;
          tag_tuple.tagname = each_tag&lt;br /&gt;
          tag_tuple.save&lt;br /&gt;
        end&lt;br /&gt;
        # Check if there is an entry for this tag, this user and this bookmark (via bmappings table)&lt;br /&gt;
        btu_tuple = BmappingsTag.where([ &amp;quot;tag_id = ? and bmapping_id = ?&amp;quot;, tag_tuple.id, bookmark_user_mapping.id] ).first&lt;br /&gt;
        if btu_tuple.nil?&lt;br /&gt;
          btu_tuple = BmappingsTag.new&lt;br /&gt;
          btu_tuple.tag_id = tag_tuple.id&lt;br /&gt;
          btu_tuple.bmapping_id = bookmark_user_mapping.id&lt;br /&gt;
          btu_tuple.save&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
        return bookmark_user_mapping.id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
      # Associate bmapping to the sign up topic&lt;br /&gt;
      def self.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        topic = SignUpTopic.find(topic_id)&lt;br /&gt;
        bmapping = Bmapping.find(bmappingid)&lt;br /&gt;
        unless (topic.nil? &amp;amp;&amp;amp; bmapping.nil?)&lt;br /&gt;
          topic.bmappings &amp;lt;&amp;lt; bmapping&lt;br /&gt;
          topic.save&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
The dependencies for these methods are present in only &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; method of bookmark model. As &amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt; methods support &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; in creating new bmapping to bookmarks,the dependencies lie only in &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; method. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if !bookmark_resource&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = add_new_bookmark(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        # Add its association to the sign up topic&lt;br /&gt;
        add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if (bmapping)&lt;br /&gt;
          topic = SignUpTopic.find(topicid)&lt;br /&gt;
          if(topic)&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            add_bmapping_signuptopic(topicid, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
  def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
    bookmark_resource = Bookmark.where([&amp;quot;url = ?&lt;br /&gt;
      &amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
    # Bookmark with the same url does not exists.&lt;br /&gt;
    if bookmark_resource.nil?&lt;br /&gt;
      # Add the newly discovered bookmark&lt;br /&gt;
      bookmarkid = create(b_url,session_user.id)&lt;br /&gt;
      # Add its associations to a user&lt;br /&gt;
      bmappingid = Bmapping.add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
      if(!topic_id.nil?)&lt;br /&gt;
        # Add its association to the sign up topic if the topic was provided&lt;br /&gt;
        Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
      end&lt;br /&gt;
      # Bookmark with the same url exists.&lt;br /&gt;
    else&lt;br /&gt;
      bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
      # Bookmark with the same user - bmapping exists.&lt;br /&gt;
      if ( !bmapping.nil? )&lt;br /&gt;
        topic = SignUpTopic.find(topic_id)&lt;br /&gt;
        if( !topic.nil? )&lt;br /&gt;
          topic.bmappings.each do |mapping|&lt;br /&gt;
            if (mapping.id == bmapping.id)&lt;br /&gt;
              Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Signup Topic does not exists&lt;br /&gt;
        else&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmapping.id)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
      else&lt;br /&gt;
        # Increment user count for the existing bookmark&lt;br /&gt;
        bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
        bookmark_resource.save&lt;br /&gt;
        # Add its association with the user&lt;br /&gt;
        bmappingid = Bmapping.add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
        Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes manually=&lt;br /&gt;
&lt;br /&gt;
===User2 Role===&lt;br /&gt;
&lt;br /&gt;
In order to inspect the changes made to the bookmark mode manually, you can visit our deployed Expertiza at &amp;lt;b&amp;gt;[http://52.11.88.182:3000 Demo]&amp;lt;/b&amp;gt; and use the following credentials:&lt;br /&gt;
     &amp;lt;b&amp;gt;User Name: &amp;lt;/b&amp;gt; &amp;lt;i&amp;gt;user2&amp;lt;/i&amp;gt;&lt;br /&gt;
     &amp;lt;b&amp;gt;Password: &amp;lt;/b&amp;gt; &amp;lt;i&amp;gt; any password&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can notice in the credentials above, you can type in any password you wish in order to log in as user2. We have accomplished this by disabling the authentication and the reason behind it was to have an easily reachable user account for test and development purposes.&lt;br /&gt;
&lt;br /&gt;
The below screenshots demonstrate the working of search features .&lt;br /&gt;
&lt;br /&gt;
===Search for all tags for all users===&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot; http://localhost:3000/bookmarks/viewing_bookmarks&amp;quot; and click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:SearchAllTagsAllUsers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for all tags for user===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;  http://localhost:3000/bookmarks/managing_bookmarks &amp;quot;  to view all tags for the user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchAlltagsForUser.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for tags for all users===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;  http://localhost:3000/bookmarks/view_bookmarks  &amp;quot; , enter the tags separated by comma (example - tag1,tag2) and then click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchForTagsAllUsers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for tags for user===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;http://localhost:3000/bookmarks/managing_bookmarks&amp;quot; , enter the tags separated by comma (example - tag1,tag2) and then click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchForTagsForUser.png]]&lt;br /&gt;
&lt;br /&gt;
=Automated Tests=&lt;br /&gt;
&lt;br /&gt;
===Functional test suite===&lt;br /&gt;
&lt;br /&gt;
We have developed a suit of extensive unit tests covering all the functionality that we have add/modified in the forked version of Expertiza. The test suite consists of 9 tests providing 14 assertions that cover the functionality of all the method changes described in the former sections of this wiki page. The source code for these tests is stored in &amp;lt;i&amp;gt;test/models/bookmark_test.rb&amp;lt;/i&amp;gt; file. You can run this test suite by simply navigating to expertiza project directory and running command: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ruby -I test test/models/bookmark_test.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Integration (Cucumber) tests===&lt;br /&gt;
&lt;br /&gt;
In addition to functional tests, we have also provided a Cucumber test as an integration test. The goal of this test is to show that a user can access the &amp;lt;i&amp;gt;Manage Bookmarks&amp;lt;/i&amp;gt; page upon successful log in, proving that bookmarks view have been successfully integrated into expertiza system. The construct of this test can be found in following files:&lt;br /&gt;
&amp;lt;pre&amp;gt;features/bookmark.feature &lt;br /&gt;
features/step_definitions/bookmark_steps&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run this cucumber test, please navigate to expertiza project directory and run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rake cucumber&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/manish211/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://52.11.88.182:3000/ Demo link] - This might not be available after May of 2015&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1J0WUBtYV_MDhpEQ-50z8gXE-OrvVkpEaZxvn_9RCAsM/edit#heading=h.mo1zn1d9w38l The OSS project requirements doc (Spring 2015 - Expertiza)]&lt;br /&gt;
#[https://drive.google.com/a/ncsu.edu/file/d/0B49VkAq-KMtebXBILUlTQktBVnM/view?usp=sharing Demo of Test suite]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Single_responsibility_principle Single Responsibility Principle]&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1504_IMV&amp;diff=95999</id>
		<title>CSC/ECE 517 Spring 2015/oss E1504 IMV</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_E1504_IMV&amp;diff=95999"/>
		<updated>2015-03-27T17:07:44Z</updated>

		<summary type="html">&lt;p&gt;Ikopas: /* Design Patterns Followed */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1504. Refactoring the Bookmark Model'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This team project successfully refactored the Bookmark Model by removing the duplicate code, combining the methods, improving the search function, moving Bmapping model methods to their respective class, covering dependencies associated with changed segments and adding a User Interface for using bookmarks.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a large project developed as a combined effort of students and faculty using the [http://rubyonrails.org/ Ruby on Rails] framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the [http://www.ncsu.edu/ NCSU] [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment] (LITRE) program, the NCSU [http://ofd.ncsu.edu/teaching-learning/ Faculty Center for Teaching and Learning], the NCSU [http://stem.ncsu.edu/ STEM] Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 bookmark.rb&lt;br /&gt;
 bmapping.rb&lt;br /&gt;
 bookmarks_controller.rb&lt;br /&gt;
 auth_controller.rb&lt;br /&gt;
 auth_helper.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The bookmark model and controller work together to create and maintain user specific bookmarks, which can be added to different topics. Moreover, the user that created a bookmark can use his privilege to edit it at a later point in time. As a functionality added for convenience, any user can search bookmarks by either users who created them or their bookmark tags.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;The search methods in bookmarks model are being used used on a very granular level. This led to redundancy in bookmarks search methods. These methods include &amp;lt;i&amp;gt;search_alltags_allusers, search_fortags_allusers, search_fortags_forusers, search_alltags_forusers&amp;lt;/i&amp;gt;. Hence duplicates in these methods are to be singled out. &amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Following the CRUD declaration in Ruby on Rails, where the method name should specify the pseudo use of itself,methods such as &amp;lt;i&amp;gt;add_new_bookmark&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;edit_this_bookmark&amp;lt;/i&amp;gt; have violate this naming convention. Therefore, we need to change the names of these two methods to &amp;lt;i&amp;gt;create&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt;, respectively. Upon changing the names, all the dependencies need to be updated, as well.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Refactor &amp;lt;i&amp;gt;add_topic_bookmark&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;add_this_bookmark&amp;lt;/i&amp;gt; by removing the repetitive code. These two methods differ only in 2 lines of code, which make it reasonable to merge them together into a single method that provides functionality of both individual methods.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Fix the bug in &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method where only bookmarks without &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; can be properly created. We add the functionality to this method to allow it to also create bookmarks with provided &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;.&lt;br /&gt;
   &amp;lt;li&amp;gt;Methods &amp;lt;i&amp;gt;add_bmapping&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; need to be moved to their appropriate model (Bmapping model) rather than reside in Bookmarks model. Completing this task involves checking the dependencies and updating the function calls for these methods, accordingly.&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Add user interface for Bookmarks as this functionality has not been a part of Expertiza&amp;lt;/li&amp;gt;&lt;br /&gt;
   &amp;lt;li&amp;gt;Create a functional tests suite covering the functionality of all the methods that have been changed by our team.&lt;br /&gt;
   &amp;lt;li&amp;gt;Create a Cucumber integration test to show the functionality of added user interface for Bookmarks.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
= Design Patterns Followed =&lt;br /&gt;
'''Single Responsibility Principle:'''&lt;br /&gt;
&lt;br /&gt;
As per Single Responsibility Principle, every class should have responsibility over a single part of functionality provided by software and that responsibility should be entirely encapsulated by the class. All the services and operations within the class should be aligned with that responsibility. &lt;br /&gt;
Following this principle, we found that methods &amp;lt;i&amp;gt; add_bmapping &amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt; add_bmapping_signuptopic &amp;lt;/i&amp;gt; were present in the Bookmark model, while they actually belong to Bmapping model. So we moved those methods to the Bmapping model and took care of all the dependencies. We created functional tests for these methods to prove that refactoring was successful.&lt;br /&gt;
&lt;br /&gt;
'''Polymorphism:'''&lt;br /&gt;
&lt;br /&gt;
We realized that the methods &amp;lt;i&amp;gt;search_fortags_allusers&amp;lt;/i&amp;gt;,&amp;lt;i&amp;gt;search_fortags_forusers&amp;lt;/i&amp;gt; could be combined into one method. Similarly, &amp;lt;i&amp;gt;search_alltags_allusers&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;search_alltags_forusers&amp;lt;/i&amp;gt; could be grouped together into a single method. The reason for this is because these methods, essentially, offer the same functionality, but using different parameters. So, we wrote a common method which takes parameters and, based on the parameters passed, it provides the required functionality.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==Bookmark Model==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| add_this_bookmark&lt;br /&gt;
| Added functionality of add_topic_bookmark&lt;br /&gt;
| To implement code reusability and remove repetitive code.&lt;br /&gt;
|-&lt;br /&gt;
| add_topic_bookmark &lt;br /&gt;
| Merged the functionality into add_this_bookmarks and deleted add_topic_bookmark&lt;br /&gt;
| To implement code reusability and remove repetitive code.&lt;br /&gt;
|-&lt;br /&gt;
| add_bookmark &lt;br /&gt;
| Added a line that checks whether topic_id has been provided in the request&lt;br /&gt;
| It allows creation of new Bmapping if no topic_id was given and removes the bug of searching for bookmark with nil topic_id later on&lt;br /&gt;
|-&lt;br /&gt;
| search_alltags_allusers&lt;br /&gt;
| |Merged search_alltags_allusers and search_alltags_foruser functions into search_alltags&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_alltags_foruser &lt;br /&gt;
| |Merged search_alltags_allusers and search_alltags_foruser functions into search_alltags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_fortags_allusers&lt;br /&gt;
| | Merged search_fortags_allusers and search_fortags_foruser functions into search_fortags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| search_fortags_foruser&lt;br /&gt;
| Merged search_fortags_allusers and search_fortags_foruser functions into search_fortags function&lt;br /&gt;
| Duplicate code present in both the functions. They differed only with the usage of parameters passed.&lt;br /&gt;
|-&lt;br /&gt;
| add_new_bookmark &lt;br /&gt;
| Changed the method name to &amp;quot;create&amp;quot;&lt;br /&gt;
| It is a much more meaningful and simpler name for a method that creates a new bookmark&lt;br /&gt;
|-&lt;br /&gt;
| edit_this_bookmark &lt;br /&gt;
| Changed the name to &amp;quot;edit&amp;quot;&lt;br /&gt;
| It is a much more appropriate name for a method that edits the bookmark it was called on&lt;br /&gt;
|-&lt;br /&gt;
| add_bmapping&lt;br /&gt;
| Moved to class 'Bmapping'&lt;br /&gt;
| This method helps in creating new bmapping. Hence it makes more sense if it belongs to bmapping class itself.&lt;br /&gt;
|-&lt;br /&gt;
| add_bmapping_signuptopic&lt;br /&gt;
| Moved to class 'Bmapping'&lt;br /&gt;
| This method helps in adding a signup topic to a newly created bmapping. Hence it makes more sense if it belongs to bmapping class itself.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Bookmark Controller==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| view_topic_bookmarks&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was not being accessed.&lt;br /&gt;
|-&lt;br /&gt;
| view_review_bookmarks&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was not being accessed.&lt;br /&gt;
|-&lt;br /&gt;
| view&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| edit_bookmark_form&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| create_tag_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;Bmappingstags&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;Bmappingstag&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect class name, the function was inaccessible.&lt;br /&gt;
|-&lt;br /&gt;
| edit_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;edit_this_bookmark&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt;&lt;br /&gt;
| The method name has been refactored to &amp;lt;i&amp;gt;edit&amp;lt;/i&amp;gt; as per the requirement&lt;br /&gt;
|-&lt;br /&gt;
| add_bookmark&lt;br /&gt;
| Renamed &amp;lt;i&amp;gt;add_topic_bookmark&amp;lt;/i&amp;gt; to &amp;lt;i&amp;gt;add_this_bookmark&amp;lt;/i&amp;gt;&lt;br /&gt;
| Due to incorrect method name, the method was inaccessible&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Views==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| bookmarks/_result.html.erb &lt;br /&gt;
| removed asctime from the below line&lt;br /&gt;
| Was throwing error&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/search_bookmarks.html.erb&lt;br /&gt;
| removed unused code&lt;br /&gt;
| not used &lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/view_bookmarks.html.erb&lt;br /&gt;
| Changed line to &amp;lt;%= link_to('Back', session[:comingFrom]) %&amp;gt;&lt;br /&gt;
| To make the back link work&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/_searchmine.html.erb&lt;br /&gt;
| changed line to&amp;lt;%= form_tag(:action =&amp;gt; &amp;quot;search_bookmarks&amp;quot;) do%&amp;gt;&lt;br /&gt;
| % was used instead of %= and it was throwing error&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/add_bookmark_form.html.erb&lt;br /&gt;
| &amp;lt;%= form_tag(:action =&amp;gt; &amp;quot;add_bookmark&amp;quot;, :method =&amp;gt; &amp;quot;post&amp;quot;) do %&amp;gt;&lt;br /&gt;
| % used instead of %= and it was not working&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| bookmarks/managing_bookmarks.html.erb&lt;br /&gt;
| added partials &lt;br /&gt;
| Nothing was there before to display&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| tree_display/list.html.erb&lt;br /&gt;
| added a link to Manage Bookmarks page&lt;br /&gt;
| This allows a user to see the link to Managing Bookmarks page as soon as the user logs in.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring add_this_bookmark and add_topic_bookmark ==&lt;br /&gt;
&lt;br /&gt;
The consistency of these two methods shows plenty of repetitive code. In order to effectively refactor these methods and reuse the code they both need, our team merged the two methods together by enabling add_this_bookmark method to handle creation of a bookmark when a topic id is provided (main functionality of add_topic_bookmark method). Once we implemented this change on add_this_bookmark method, we deleted add_topic_bookmark method as it became obsolete. Therefore, we retained the same functionality while reducing the method by 7 repetitive lines of code. &lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
&lt;br /&gt;
Please note that these two methods only differ in a single line of code (line 6 and 16) where line 6 takes an extra parameter (&amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 1:  def self.add_topic_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topicid)&lt;br /&gt;
 2:    # Check if the bookmark exists and add / edit based on that&lt;br /&gt;
 3:    bookmark_exists = check_bookmark_exists(b_url)&lt;br /&gt;
 4:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
 5:    if (!bookmark_exists || !bmapping_exists)&lt;br /&gt;
 6:      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
 7:    elsif (bmapping_exists)&lt;br /&gt;
 8:      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
 9:    end&lt;br /&gt;
10:  end&lt;br /&gt;
11:&lt;br /&gt;
12:  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
13:    bookmark_exists = check_bookmark_exists(b_url)&lt;br /&gt;
14:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
15:    if (!bookmark_exists || !bmapping_exists)&lt;br /&gt;
16:      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
17:    elsif (bmapping_exists)&lt;br /&gt;
18:      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
19:    end&lt;br /&gt;
20:  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 1:  #Adds bookmark with and without topic_id&lt;br /&gt;
 2:  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topic_id)&lt;br /&gt;
 3:    # first check existence of the given bookmark and bmapping name&lt;br /&gt;
 5:    bookmark_exists = check_bookmark_exists(b_url) &lt;br /&gt;
 6:    bmapping_exists = check_bmapping_exists(b_url,session_user)&lt;br /&gt;
 7:    if (!bookmark_exists || !bmapping_exists) # they don't exists, so create new ones&lt;br /&gt;
 8:      if(topic_id) # topic_id has been provided&lt;br /&gt;
 9:        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
10:      else # topic_id has not been provided&lt;br /&gt;
11:        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user, nil)&lt;br /&gt;
12:      end&lt;br /&gt;
13:    elsif (bmapping_exists) # if the bmapping already exists, edit it instead of creating a new one&lt;br /&gt;
14:      Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
15:    end&lt;br /&gt;
16:  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Fixing a bug in &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method ==&lt;br /&gt;
&lt;br /&gt;
Our team fixed the bug associate with &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; nil being provided to &amp;lt;i&amp;gt;add_bookmark&amp;lt;/i&amp;gt; method (user has not specified &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt;) when creating a bookmark. We include an if statement that calls &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; method only if the provided &amp;lt;i&amp;gt;topic_id&amp;lt;/i&amp;gt; is not nil. This change has been implemented on line 9 in the code block shown bellow.&lt;br /&gt;
&lt;br /&gt;
=== Before changes ===&lt;br /&gt;
Parts such as &amp;lt;b&amp;gt;bookmark_resource.nil?&amp;lt;/b&amp;gt; need to be refactored to a shorter version &amp;lt;b&amp;gt;!bookmark_resource&amp;lt;/b&amp;gt;. Similar opportunity to refactor comes up 2 more times within this code block (&amp;lt;b&amp;gt; !bmapping.nil? , !topic.nil?&amp;lt;/b&amp;gt;). We also need to change the first &amp;lt;i&amp;gt;if&amp;lt;/i&amp;gt; block to enable signup topic to be added only if topic_id does not already exists. Doing this will fix the bug of signup_topic overwriting an existing topic_id in case if topic was already created in the past.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if bookmark_resource.nil?&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = add_new_bookmark(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        # Add its association to the sign up topic&lt;br /&gt;
        add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if ( !bmapping.nil? )&lt;br /&gt;
          topic = SignUpTopic.find(topicid)&lt;br /&gt;
          if( !topic.nil? )&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            add_bmapping_signuptopic(topicid, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== After Changes ===&lt;br /&gt;
Once the changes described in the &amp;lt;i&amp;gt;Before Change&amp;lt;/i&amp;gt; section were carried out, the code looks cleaner, the bug with topic_id is removed and the code functions marvelously!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if !bookmark_resource # if bookmark resource is nil (does not exist)&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = create(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = Bmapping.add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        if(topic_id) # if topic_id was provided, add the signup topic&lt;br /&gt;
          # Add its association to the sign up topic if the topic was provided&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if (bmapping) # if bmapping exists (it is not nil), look it up and edit the bookmarks&lt;br /&gt;
          topic = SignUpTopic.find(topic_id)&lt;br /&gt;
          if(topic) # if topic exists (it is not nil) use it to edit bookmark&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            Bmapping.add_bmapping_signuptopic(topic_id, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = Bmapping.add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 3 : Refactoring search_fortags_allusers and search_fortags_forusers ==&lt;br /&gt;
&lt;br /&gt;
Both these methods contain almost the same code except for few conditional lines. search_fortags_allusers searches for all tags for all users whereas search_fortags_forusers searches only for those tags that belong to the user. The code for both these functions differed only in the query clause where at one place it checks for records returned for a specific user and at the other place, it does not have this check.&lt;br /&gt;
&lt;br /&gt;
===Before Changes: search_fortags_allusers function ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def  self.search_fortags_allusers(tags_array, order_by)&lt;br /&gt;
&lt;br /&gt;
      result_array = Array.new # returns this array&lt;br /&gt;
      ## find the tags associated with these tagnames&lt;br /&gt;
      @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      ## retreive mapping_ids taggeed with all of the word tags&lt;br /&gt;
      ## for every word, search for every bookmark that was tagged with that word. Then take the intersection of all the bmapping_ids&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
&lt;br /&gt;
        q_tuples = BmappingsTags.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
&lt;br /&gt;
        if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          temp_array = Array.new&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
          @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
      ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
      temp_result_records =  Bmapping.where([&amp;quot;id in (?)&amp;quot;, @q_tuples_with_all_tags])&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      if (order_by ==&amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
      ## for evey bmapping_id, create a hash, and push into the result_array&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] = result.user.name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id =?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes: search_fortags_foruser function===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def self.search_fortags_foruser(tags_array, this_user_id, order_by)&lt;br /&gt;
      #order by is in &amp;quot;most_popular&amp;quot; and &amp;quot;most_recent&amp;quot;&lt;br /&gt;
      result_array = Array.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## search for ids of the tags&lt;br /&gt;
      @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
        ##search for all qualifier tuples with b&lt;br /&gt;
        q_tuples = BmappingsTags.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
        #for q_t in q_tuples&lt;br /&gt;
        #end&lt;br /&gt;
&lt;br /&gt;
        if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          temp_array = Array.new&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
          @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
      temp_result_records =  Bmapping.where([&amp;quot;id in (?) and user_id = ?&amp;quot;, @q_tuples_with_all_tags,this_user_id ])&lt;br /&gt;
&lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      if (order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] =  User.find(this_user_id).name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id=?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The above two functions are merged into a single function named &amp;quot;search_fortags function&amp;quot; as shown below. If we want to search for specified tags for all users, the userid is passed as nil. If we want to search for the specified tags belonging to a particular userid, we pass that userid. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      ## searches for tspecified tags, among a specified user, orders them by most popular and the most recently added&lt;br /&gt;
    def self.search_fortags(tags_array, order_by,this_user_id)&lt;br /&gt;
      #order by is in &amp;quot;most_popular&amp;quot; and &amp;quot;most_recent&amp;quot;&lt;br /&gt;
      result_array = Array.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      ## search for ids of the tags&lt;br /&gt;
     @tags = BookmarksHelper.find_tags(tags_array)&lt;br /&gt;
&lt;br /&gt;
      @q_tuples_with_all_tags = Array.new&lt;br /&gt;
      first_time = &amp;quot;true&amp;quot;&lt;br /&gt;
      for each_tag in @tags&lt;br /&gt;
        ##search for all qualifier tuples with b&lt;br /&gt;
        q_tuples = BmappingsTag.where([&amp;quot;tag_id = ?&amp;quot;, each_tag])&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
        #if first_time == &amp;quot;true&amp;quot;&lt;br /&gt;
          for q_t in q_tuples&lt;br /&gt;
            @q_tuples_with_all_tags &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          #first_time = &amp;quot;false&amp;quot;&lt;br /&gt;
        # else&lt;br /&gt;
        #   temp_array = Array.new&lt;br /&gt;
        #   for q_t in q_tuples&lt;br /&gt;
        #     temp_array &amp;lt;&amp;lt; q_t.bmapping_id&lt;br /&gt;
        #   end&lt;br /&gt;
        #   @q_tuples_with_all_tags = @q_tuples_with_all_tags &amp;amp; temp_array ## returns the items  common to both arrays&lt;br /&gt;
        # end&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      ##If the user id is passed, it will not be nil. So we use it in the query as shown below.&lt;br /&gt;
      if(this_user_id != nil)&lt;br /&gt;
        ## now you have qualifer tuples with all the required bmapping ids and the requested userid- search for the req ones&lt;br /&gt;
        temp_result_records =  Bmapping.where([&amp;quot;id in (?) and user_id = ?&amp;quot;, @q_tuples_with_all_tags, this_user_id ])&lt;br /&gt;
      else&lt;br /&gt;
        ## now you have qualifer tuples with all the required bmapping ids - search for the req ones&lt;br /&gt;
        temp_result_records =  Bmapping.where([&amp;quot;id in (?)&amp;quot;, @q_tuples_with_all_tags])&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      ## organize these tuples in the order of most earliest, most popular&lt;br /&gt;
      result_records = Array.new&lt;br /&gt;
      if (order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.date_created &amp;lt;=&amp;gt; x.date_created}&lt;br /&gt;
      else&lt;br /&gt;
        result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count }&lt;br /&gt;
      end&lt;br /&gt;
     &lt;br /&gt;
&lt;br /&gt;
      for result in result_records&lt;br /&gt;
        result_hash = Hash.new&lt;br /&gt;
        result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
        result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
        result_hash[&amp;quot;user&amp;quot;] =  result.user.name&lt;br /&gt;
        result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
        result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
        result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
        result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
        ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
        ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
        ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
        tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id=?&amp;quot;,result.id])&lt;br /&gt;
        tag_array = Array.new&lt;br /&gt;
        for tag_fetch in tag_fetchs&lt;br /&gt;
          tag_array &amp;lt;&amp;lt;  Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
        end&lt;br /&gt;
        result_hash[&amp;quot;tags&amp;quot;]  = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
        result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes:search_alltags_foruser function===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.search_alltags_foruser (the_userid, order_by)&lt;br /&gt;
        result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
        if(order_by == &amp;quot;most_recent&amp;quot; )&lt;br /&gt;
          ## find all the bmappings in this system, created by this user, order them by the date created.&lt;br /&gt;
          # For each tuple returned from the bmapping, generate a hash, containing the url, the specified user's name, date this mapping was made,&lt;br /&gt;
          ## title, and description provided by this user. Store these hashes sequentially in a array ad return the array&lt;br /&gt;
&lt;br /&gt;
          result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        elsif ( order_by == &amp;quot;most_popular&amp;quot;)&lt;br /&gt;
          ### retrieving the most popular records that this user.(The user need not be the discoverer). First retrieve the the user's bookmarks from the bmapping.&lt;br /&gt;
          ### order these records, based on the user_count of the url&lt;br /&gt;
          temp_result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid])&lt;br /&gt;
          ## order result records by result.user_count a.sort {|x,y| y &amp;lt;=&amp;gt; x }&lt;br /&gt;
          result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count}&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] =BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        return result_array&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes : search_alltags_allusers function ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.search_alltags_allusers(order_by)&lt;br /&gt;
      result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      if(order_by == &amp;quot;most_recent&amp;quot;)&lt;br /&gt;
        ## find all the records in the system, order them by the date created. Using Bmapping here. Returns mappings that where created most recently,&lt;br /&gt;
        ## the user that created this mapping, the title and description provided this user&lt;br /&gt;
        result_records = Bmapping.all(:order =&amp;gt;&amp;quot;date_created DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = result.user.name # displaying the newest owner of the bookmark,&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
          result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count ## number of people having this user in their repository&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
          tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
      elsif (order_by == &amp;quot;most_popular&amp;quot;)&lt;br /&gt;
        ## returns the url boomarked by the most number of users, the discoverer of that url, the title and description provided by the discoverer&lt;br /&gt;
        result_records = Bookmark.all(:order =&amp;gt;&amp;quot;user_count DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = User.find(result.discoverer_user_id).name&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.user_count&lt;br /&gt;
          b_u_mapping = Bmapping.where([&amp;quot;bookmark_id = ? and user_id = ?&amp;quot;, result.id, result.discoverer_user_id]).first&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = b_u_mapping.id&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = b_u_mapping.description&lt;br /&gt;
          result_hash[&amp;quot;title&amp;quot;] = b_u_mapping.title&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
          tag_fetchs = BmappingsTags.where([&amp;quot;bmapping_id = ?&amp;quot;,b_u_mapping.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      return result_array&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The above two functions were merged into a single function &amp;quot;search_alltags&amp;quot; as shown below. If we want to search for all tags for all users, the userid is passed as nil. If we want to search for all tags belonging to a particular userid, we pass that userid. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def self.search_alltags (the_userid, order_by)&lt;br /&gt;
&lt;br /&gt;
        result_array = Array.new #going to append all the results into this array&lt;br /&gt;
&lt;br /&gt;
        if(order_by == &amp;quot;most_recent&amp;quot; )&lt;br /&gt;
          ## find all the bmappings in this system, created by this user, order them by the date created.&lt;br /&gt;
          # For each tuple returned from the bmapping, generate a hash, containing the url, the specified user's name, date this mapping was made,&lt;br /&gt;
          ## title, and description provided by this user. Store these hashes sequentially in a array ad return the array&lt;br /&gt;
 &lt;br /&gt;
          ## If no user id is passed, the search is for all the user ids&lt;br /&gt;
          if(the_userid == nil)&lt;br /&gt;
            ## find all the records in the system, order them by the date created. Using Bmapping here. Returns mappings that where created most recently,&lt;br /&gt;
            ## the user that created this mapping, the title and description provided this user&lt;br /&gt;
            &lt;br /&gt;
            result_records = Bmapping.all.order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          else&lt;br /&gt;
            result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          end&lt;br /&gt;
          &lt;br /&gt;
          #result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid]).order(&amp;quot;date_created DESC&amp;quot;).limit(20)&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = result.user.name&lt;br /&gt;
            result_hash[&amp;quot;created_at&amp;quot;] = result.date_created&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
        elsif ( order_by == &amp;quot;most_popular&amp;quot; and the_userid != nil) ## Most popular tags for the supplied user&lt;br /&gt;
          ### retrieving the most popular records that this user.(The user need not be the discoverer). First retrieve the the user's bookmarks from the bmapping.&lt;br /&gt;
          ### order these records, based on the user_count of the url&lt;br /&gt;
          temp_result_records = Bmapping.where([&amp;quot; user_id = ?&amp;quot;, the_userid])&lt;br /&gt;
          ## order result records by result.user_count a.sort {|x,y| y &amp;lt;=&amp;gt; x }&lt;br /&gt;
          result_records = temp_result_records.sort {|x,y| y.bookmark.user_count &amp;lt;=&amp;gt; x.bookmark.user_count}&lt;br /&gt;
          for result in result_records&lt;br /&gt;
            result_hash = Hash.new&lt;br /&gt;
            result_hash[&amp;quot;url&amp;quot;] = result.bookmark.url&lt;br /&gt;
            result_hash[&amp;quot;id&amp;quot;] = result.id&lt;br /&gt;
            result_hash[&amp;quot;user&amp;quot;] = User.find(the_userid).name&lt;br /&gt;
            result_hash[&amp;quot;title&amp;quot;] = result.title&lt;br /&gt;
            result_hash[&amp;quot;description&amp;quot;] = result.description&lt;br /&gt;
            result_hash[&amp;quot;copied_by&amp;quot;] = result.bookmark.user_count&lt;br /&gt;
            ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
            ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
            ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
            tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,result.id])&lt;br /&gt;
            tag_array = Array.new&lt;br /&gt;
            for tag_fetch in tag_fetchs&lt;br /&gt;
              tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
            end&lt;br /&gt;
            result_hash[&amp;quot;tags&amp;quot;] =BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
            result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
          end&lt;br /&gt;
        elsif (order_by == &amp;quot;most_popular&amp;quot; and the_userid == nil) ## Most popular tags for all users&lt;br /&gt;
        ## returns the url boomarked by the most number of users, the discoverer of that url, the title and description provided by the discoverer&lt;br /&gt;
        result_records = Bookmark.all(:order =&amp;gt;&amp;quot;user_count DESC&amp;quot;, :limit =&amp;gt;20)&lt;br /&gt;
        for result in result_records&lt;br /&gt;
          ## for each tuple returned by the query above, create a new hash, store the values appropriately, and append into the return_array&lt;br /&gt;
          result_hash = Hash.new&lt;br /&gt;
          result_hash[&amp;quot;url&amp;quot;] = result.url&lt;br /&gt;
          result_hash[&amp;quot;user&amp;quot;] = User.find(result.discoverer_user_id).name&lt;br /&gt;
          result_hash[&amp;quot;copied_by&amp;quot;] = result.user_count&lt;br /&gt;
          b_u_mapping = Bmapping.where([&amp;quot;bookmark_id = ? and user_id = ?&amp;quot;, result.id, result.discoverer_user_id]).first&lt;br /&gt;
          result_hash[&amp;quot;id&amp;quot;] = b_u_mapping.id&lt;br /&gt;
          result_hash[&amp;quot;description&amp;quot;] = b_u_mapping.description&lt;br /&gt;
          result_hash[&amp;quot;title&amp;quot;] = b_u_mapping.title&lt;br /&gt;
          ## now retrieving tags for this user-bookmak mapping&lt;br /&gt;
          ## first retrieve all the tag_ids mapped to the BMapping id. Then retrieve all the tag names of the tag_ids picked up.&lt;br /&gt;
          ## Append all these into a comma separated string, and push them onto the hash&lt;br /&gt;
&lt;br /&gt;
          tag_fetchs = BmappingsTag.where([&amp;quot;bmapping_id = ?&amp;quot;,b_u_mapping.id])&lt;br /&gt;
          tag_array = Array.new&lt;br /&gt;
          for tag_fetch in tag_fetchs&lt;br /&gt;
            tag_array &amp;lt;&amp;lt; Tag.find(tag_fetch.tag_id).tagname&lt;br /&gt;
          end&lt;br /&gt;
          result_hash[&amp;quot;tags&amp;quot;] = BookmarksHelper.join_tags(tag_array)&lt;br /&gt;
          result_array &amp;lt;&amp;lt; result_hash&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        return result_array&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 4 : Refactoring &amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt; methods ==&lt;br /&gt;
&lt;br /&gt;
The methods ,&amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt;, add new bmapping to newly added bookmarks. These methods are initially served in bookmarks model. Ideally, they should be serving the bmapping model. &amp;lt;i&amp;gt;add_bmapping_signuptopic&amp;lt;/i&amp;gt; is a continuation to &amp;lt;i&amp;gt;add_bmapping&amp;lt;/i&amp;gt;. It adds signup topic to the newly created bmapping. Along with moving these methods from bookmarks model, the team had to check for dependencies for these methods in all corresponding models and take care of them.&lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
&lt;br /&gt;
Changes done to bmapping model. The new added code in this model has been moved from bookmarks model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Bmapping &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :bookmark&lt;br /&gt;
  has_many :bmappings_tags&lt;br /&gt;
  has_and_belongs_to_many :sign_up_topics&lt;br /&gt;
  has_many :ratings, :class_name =&amp;gt; &amp;quot;BmappingRatings&amp;quot;, :foreign_key =&amp;gt; &amp;quot;bmapping_id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  def cumulative_rating&lt;br /&gt;
    rating = 0.0&lt;br /&gt;
    count = 0&lt;br /&gt;
    self.ratings.each do |br|&lt;br /&gt;
      rating = rating + br.rating&lt;br /&gt;
      count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; 0&lt;br /&gt;
      return rating/count&lt;br /&gt;
    else&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Bmapping &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :bookmark&lt;br /&gt;
  has_many :bmappings_tags&lt;br /&gt;
  has_and_belongs_to_many :sign_up_topics&lt;br /&gt;
  has_many :ratings, :class_name =&amp;gt; &amp;quot;BmappingRatings&amp;quot;, :foreign_key =&amp;gt; &amp;quot;bmapping_id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  def cumulative_rating&lt;br /&gt;
    rating = 0.0&lt;br /&gt;
    count = 0&lt;br /&gt;
    self.ratings.each do |br|&lt;br /&gt;
      rating = rating + br.rating&lt;br /&gt;
      count = count + 1&lt;br /&gt;
    end&lt;br /&gt;
    if count &amp;gt; 0&lt;br /&gt;
      return rating/count&lt;br /&gt;
    else&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # Add bookmark - user association with its meta fields&lt;br /&gt;
    def self.add_bmapping(bid, b_title, user_id, b_description,b_tags_text)&lt;br /&gt;
      bookmark_user_mapping = Bmapping.new&lt;br /&gt;
      bookmark_user_mapping.bookmark_id = bid&lt;br /&gt;
      bookmark_user_mapping.title = b_title&lt;br /&gt;
      bookmark_user_mapping.description = b_description&lt;br /&gt;
      bookmark_user_mapping.user_id =user_id&lt;br /&gt;
      current_timestamp = Time.now&lt;br /&gt;
      bookmark_user_mapping.date_created = current_timestamp&lt;br /&gt;
      bookmark_user_mapping.date_modified = current_timestamp&lt;br /&gt;
      bookmark_user_mapping.save&lt;br /&gt;
      # Add tags&lt;br /&gt;
      # tags come in as a text, separating them into a array&lt;br /&gt;
&lt;br /&gt;
      tag_array = BookmarksHelper.separate_tags(b_tags_text)&lt;br /&gt;
      for each_tag in tag_array&lt;br /&gt;
        # Look for each tag that is present in tags, if not make them, then make the BTU entry&lt;br /&gt;
        tag_tuple = Tag.where([&amp;quot;tagname = ?&amp;quot;,each_tag]).first&lt;br /&gt;
        if tag_tuple.nil?&lt;br /&gt;
          tag_tuple = Tag.new&lt;br /&gt;
          tag_tuple.tagname = each_tag&lt;br /&gt;
          tag_tuple.save&lt;br /&gt;
        end&lt;br /&gt;
        # Check if there is an entry for this tag, this user and this bookmark (via bmappings table)&lt;br /&gt;
        btu_tuple = BmappingsTag.where([ &amp;quot;tag_id = ? and bmapping_id = ?&amp;quot;, tag_tuple.id, bookmark_user_mapping.id] ).first&lt;br /&gt;
        if btu_tuple.nil?&lt;br /&gt;
          btu_tuple = BmappingsTag.new&lt;br /&gt;
          btu_tuple.tag_id = tag_tuple.id&lt;br /&gt;
          btu_tuple.bmapping_id = bookmark_user_mapping.id&lt;br /&gt;
          btu_tuple.save&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
        return bookmark_user_mapping.id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
      # Associate bmapping to the sign up topic&lt;br /&gt;
      def self.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
        topic = SignUpTopic.find(topic_id)&lt;br /&gt;
        bmapping = Bmapping.find(bmappingid)&lt;br /&gt;
        unless (topic.nil? &amp;amp;&amp;amp; bmapping.nil?)&lt;br /&gt;
          topic.bmappings &amp;lt;&amp;lt; bmapping&lt;br /&gt;
          topic.save&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Before Changes===&lt;br /&gt;
The dependencies for these methods are present in only &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; method of bookmark model. As &amp;lt;i&amp;gt;add_bmapping and add_bmapping_signuptopic&amp;lt;/i&amp;gt; methods support &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; in creating new bmapping to bookmarks,the dependencies lie only in &amp;lt;i&amp;gt; add_bookmark &amp;lt;/i&amp;gt; method. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
    def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)&lt;br /&gt;
      bookmark_resource = Bookmark.where([&amp;quot;url = ?&amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
      # Bookmark with the same url does not exists.&lt;br /&gt;
      if bookmark_resource.nil?&lt;br /&gt;
        # Add the newly discovered bookmark&lt;br /&gt;
        bookmarkid = add_new_bookmark(b_url,session_user.id)&lt;br /&gt;
        # Add its associations to a user&lt;br /&gt;
        bmappingid = add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
        # Add its association to the sign up topic&lt;br /&gt;
        add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with the same url exists.&lt;br /&gt;
      else&lt;br /&gt;
        bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
        # Bookmark with the same user - bmapping exists.&lt;br /&gt;
        if ( !bmapping.nil? )&lt;br /&gt;
          topic = SignUpTopic.find(topicid)&lt;br /&gt;
          if( !topic.nil? )&lt;br /&gt;
            topic.bmappings.each do |mapping|&lt;br /&gt;
              if (mapping.id == bmapping.id)&lt;br /&gt;
                Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            # Signup Topic does not exists&lt;br /&gt;
          else&lt;br /&gt;
            add_bmapping_signuptopic(topicid, bmapping.id)&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
        else&lt;br /&gt;
          # Increment user count for the existing bookmark&lt;br /&gt;
          bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
          bookmark_resource.save&lt;br /&gt;
          # Add its association with the user&lt;br /&gt;
          bmappingid = add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
          add_bmapping_signuptopic(topicid, bmappingid)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Adds a bookmark and its various associations&lt;br /&gt;
  def self.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)&lt;br /&gt;
    bookmark_resource = Bookmark.where([&amp;quot;url = ?&lt;br /&gt;
      &amp;quot;,b_url]).first&lt;br /&gt;
&lt;br /&gt;
    # Bookmark with the same url does not exists.&lt;br /&gt;
    if bookmark_resource.nil?&lt;br /&gt;
      # Add the newly discovered bookmark&lt;br /&gt;
      bookmarkid = create(b_url,session_user.id)&lt;br /&gt;
      # Add its associations to a user&lt;br /&gt;
      bmappingid = Bmapping.add_bmapping(bookmarkid, b_title, session_user.id, b_description,b_tags_text )&lt;br /&gt;
      if(!topic_id.nil?)&lt;br /&gt;
        # Add its association to the sign up topic if the topic was provided&lt;br /&gt;
        Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
      end&lt;br /&gt;
      # Bookmark with the same url exists.&lt;br /&gt;
    else&lt;br /&gt;
      bmapping = Bmapping.where(bookmark_id: bookmark_resource.id, user_id: session_user.id).first&lt;br /&gt;
      # Bookmark with the same user - bmapping exists.&lt;br /&gt;
      if ( !bmapping.nil? )&lt;br /&gt;
        topic = SignUpTopic.find(topic_id)&lt;br /&gt;
        if( !topic.nil? )&lt;br /&gt;
          topic.bmappings.each do |mapping|&lt;br /&gt;
            if (mapping.id == bmapping.id)&lt;br /&gt;
              Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          # Signup Topic does not exists&lt;br /&gt;
        else&lt;br /&gt;
          Bmapping.add_bmapping_signuptopic(topic_id, bmapping.id)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        # Bookmark with same user - bmapping does not exists.&lt;br /&gt;
      else&lt;br /&gt;
        # Increment user count for the existing bookmark&lt;br /&gt;
        bookmark_resource.user_count = bookmark_resource.user_count + 1&lt;br /&gt;
        bookmark_resource.save&lt;br /&gt;
        # Add its association with the user&lt;br /&gt;
        bmappingid = Bmapping.add_bmapping(bookmark_resource.id, b_title, session_user.id, b_description,b_tags_text)&lt;br /&gt;
        Bmapping.add_bmapping_signuptopic(topic_id, bmappingid)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes manually=&lt;br /&gt;
&lt;br /&gt;
===User2 Role===&lt;br /&gt;
&lt;br /&gt;
In order to inspect the changes made to the bookmark mode manually, you can visit our deployed Expertiza at &amp;lt;b&amp;gt;[http://52.11.88.182:3000 Demo]&amp;lt;/b&amp;gt; and use the following credentials:&lt;br /&gt;
     &amp;lt;b&amp;gt;User Name: &amp;lt;/b&amp;gt; &amp;lt;i&amp;gt;user2&amp;lt;/i&amp;gt;&lt;br /&gt;
     &amp;lt;b&amp;gt;Password: &amp;lt;/b&amp;gt; &amp;lt;i&amp;gt; any password&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can notice in the credentials above, you can type in any password you wish in order to log in as user2. We have accomplished this by disabling the authentication and the reason behind it was to have an easily reachable user account for test and development purposes.&lt;br /&gt;
&lt;br /&gt;
The below screenshots demonstrate the working of search features .&lt;br /&gt;
&lt;br /&gt;
===Search for all tags for all users===&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot; http://localhost:3000/bookmarks/viewing_bookmarks&amp;quot; and click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:SearchAllTagsAllUsers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for all tags for user===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;  http://localhost:3000/bookmarks/managing_bookmarks &amp;quot;  to view all tags for the user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchAlltagsForUser.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for tags for all users===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;  http://localhost:3000/bookmarks/view_bookmarks  &amp;quot; , enter the tags separated by comma (example - tag1,tag2) and then click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchForTagsAllUsers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Search for tags for user===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Visit the url &amp;quot;http://localhost:3000/bookmarks/managing_bookmarks&amp;quot; , enter the tags separated by comma (example - tag1,tag2) and then click on search button to view the results&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:searchForTagsForUser.png]]&lt;br /&gt;
&lt;br /&gt;
=Automated Tests=&lt;br /&gt;
&lt;br /&gt;
===Functional test suite===&lt;br /&gt;
&lt;br /&gt;
We have developed a suit of extensive unit tests covering all the functionality that we have add/modified in the forked version of Expertiza. The test suite consists of 9 tests providing 14 assertions that cover the functionality of all the method changes described in the former sections of this wiki page. The source code for these tests is stored in &amp;lt;i&amp;gt;test/models/bookmark_test.rb&amp;lt;/i&amp;gt; file. You can run this test suite by simply navigating to expertiza project directory and running command: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ruby -I test test/models/bookmark_test.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Integration (Cucumber) tests===&lt;br /&gt;
&lt;br /&gt;
In addition to functional tests, we have also provided a Cucumber test as an integration test. The goal of this test is to show that a user can access the &amp;lt;i&amp;gt;Manage Bookmarks&amp;lt;/i&amp;gt; page upon successful log in, proving that bookmarks view have been successfully integrated into expertiza system. The construct of this test can be found in following files:&lt;br /&gt;
&amp;lt;pre&amp;gt;features/bookmark.feature &lt;br /&gt;
features/step_definitions/bookmark_steps&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run this cucumber test, please navigate to expertiza project directory and run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rake cucumber&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/manish211/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://52.11.88.182:3000/ Demo link] - This might not be available after May of 2015&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1J0WUBtYV_MDhpEQ-50z8gXE-OrvVkpEaZxvn_9RCAsM/edit#heading=h.mo1zn1d9w38l The OSS project requirements doc (Spring 2015 - Expertiza)]&lt;br /&gt;
#[https://drive.google.com/a/ncsu.edu/file/d/0B49VkAq-KMtebXBILUlTQktBVnM/view?usp=sharing Demo of Test suite]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Single_responsibility_principle Single Responsibility Principle]&lt;/div&gt;</summary>
		<author><name>Ikopas</name></author>
	</entry>
</feed>