(function (angular) {
    'use strict';

    //// JavaScript Code ////
    function tagsFilterCtrl($scope,$rootScope,Constants,$location) {
        /*jshint validthis:true */
        var vm = this;
        vm.maxTags = 10;

        function setTagState(name,stateVal) {
            for (var f=0; f < $scope.projectStatus.tag_info.length ; f++) {
                if ($scope.projectStatus.tag_info[f].immutable.name === name) {
                    $scope.projectStatus.tag_info[f].state = stateVal;
                }
            }
        }

        vm.initTagsFromQueryString = function() {
            var queryStringObject = $location.search();
            var shouldRefresh = false;
            for (var j=0; j < $scope.projectStatus.tag_info.length ; j++) {
                $scope.projectStatus.tag_info[j].state = 0;
            }
            if (angular.isDefined(queryStringObject.tagsOn)) {
                shouldRefresh = true;
                var array = queryStringObject.tagsOn.split(',');
                for (var i=0; i < array.length; i++) {
                    setTagState(array[i],1);
                }
            }
            if (angular.isDefined(queryStringObject.tagsOff)) {
                shouldRefresh = true;
                var array2 = queryStringObject.tagsOff.split(',');
                for (var i1=0; i1 < array2.length; i1++) {
                    setTagState(array2[i1],2);
                }
            }
            return shouldRefresh;
        };

        vm.initTagsFromQueryString();

        vm.updateTags = function() {
            var on = [], off = [];
            for (var i=0; i < $scope.projectStatus.tag_info.length ; i++) {
                if ($scope.projectStatus.tag_info[i].state === 1) {
                    on.push($scope.projectStatus.tag_info[i].immutable.name);
                } else if ($scope.projectStatus.tag_info[i].state === 2) {
                    off.push($scope.projectStatus.tag_info[i].immutable.name);
                }
            }
            $location.search('tagsOn',on.join(','));
            $location.search('tagsOff',off.join(','));
            $rootScope.$emit(Constants.EVENTS.TAGS_CHANGED);
        };

        vm.hasSelectedTags = function() {
            for (var i=0; i < $scope.projectStatus.tag_info.length ; i++) {
                if ($scope.projectStatus.tag_info[i].state === 1) {
                    return true;
                }
            }
           return false;
        };
        vm.clearSelectedTags = function() {
            for (var i=0; i < $scope.projectStatus.tag_info.length ; i++) {
                $scope.projectStatus.tag_info[i].state = 0;
            }
            vm.updateTags();
        };
    }


    //// Angular Code ////
    angular.module('codeine').controller('tagsFilterCtrl', tagsFilterCtrl);

})(angular);
@@ -1990,32 +1990,69 @@
 %7D%0A            %7D%0A
+            if (on.length %3E 0) %7B%0A    
             $loc
@@ -2073,16 +2073,17 @@
 tagsOn',
+ 
 on.join(
@@ -2081,32 +2081,155 @@
  on.join(','));%0A
+            %7D else %7B%0A                $location.search('tagsOn', null);%0A            %7D%0A            if (off.length %3E 0) %7B%0A    
             $loc
@@ -2251,16 +2251,17 @@
 agsOff',
+ 
 off.join
@@ -2260,32 +2260,118 @@
 off.join(','));%0A
+            %7D else %7B%0A                $location.search('tagsOff', null);%0A            %7D%0A
             $roo

remove tags-on/off if empty