 'use strict'
 
 class DomainsCtrl
-  constructor: (@scope, @window, @interval, @DomainsFcty, @MostCommonViolationsFcty, @WebSocketFcty, @NamedRouteService, @localStorage, @gettextCatalog) ->
+  constructor: (@scope, @window, @interval, @filter, @DomainsFcty, @MostCommonViolationsFcty, @WebSocketFcty, @NamedRouteService, @localStorage, @gettextCatalog) ->
     @domainsVisible = false
     @groupsVisible = true
     @mostFrequentVisible = false
 
     @storage = @localStorage
     @prefsFilter = @storage.prefsFilter
-    @order = 'is_active'
+    @order = '-is_active'
     @order_options = [
-      {text: @gettextCatalog.getString('sort by'), order:'is_active'},
-      {text: @gettextCatalog.getString('pages'), order:'details.pageCount'},
-      {text: @gettextCatalog.getString('violations'), order:'details.violationCount'},
-      {text: @gettextCatalog.getString('error %'), order:'details.errorPercentage'},
-      {text: @gettextCatalog.getString('avg resp time'), order:'details.averageResponseTime'}]
-    @order_select = @order_options[0]
+      {text: @gettextCatalog.getString('is active'), order:'-is_active'},
+      {text: @gettextCatalog.getString('pages'), order:'-details.pageCount'},
+      {text: @gettextCatalog.getString('violations'), order:'-details.violationCount'},
+      {text: @gettextCatalog.getString('error %'), order:'-details.errorPercentage'},
+      {text: @gettextCatalog.getString('avg resp time'), order:'-details.averageResponseTime'}]
+    @order_select = {text: @gettextCatalog.getString('is active'), order:'-is_active'}
 
     @getDomainData()
     @getMostCommonViolations()



angular.module('holmesApp')
  .controller 'DomainsCtrl', ($scope, $window, $interval, DomainsFcty, MostCommonViolationsFcty, WebSocketFcty, $NamedRouteService, $localStorage, gettextCatalog) ->

    $scope.model = new DomainsCtrl($scope, $window, $interval, DomainsFcty, MostCommonViolationsFcty, WebSocketFcty, $NamedRouteService, $localStorage, gettextCatalog)

    for domain in @domainList
      domain.details = _.find domainsDetails, {id: domain.id}

    @domains = @filter('orderBy')(@domainList,  @order)

    @loadedDomains = @domains.length

