Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Minor cleanup for controllers.

  • Loading branch information...
commit eaa41b01b6e5bef1e88375db20fd57aac56ffc40 1 parent 8c376cf
@lucassus authored
View
5 app/assets/javascripts/app/controllers/collections/index_controller.js.coffee
@@ -4,9 +4,10 @@ class CollectionsIndexController
@$inject = ["$scope", "$routeParams", "Collection", "confirmationDialog", "alerts"]
constructor: (@$scope, $routeParams, @Collection, @confirmationDialog, @alerts) ->
@loading = false
+ { @dbName } = $routeParams
# Scope variables
- @$scope.dbName = $routeParams.dbName
+ @$scope.dbName = @dbName
@$scope.filterValue = ""
# Scope methods
@@ -17,7 +18,7 @@ class CollectionsIndexController
fetchCollections: ->
@loading = true
- params = dbName: @$scope.dbName
+ params = dbName: @dbName
@$scope.collections = @Collection.query(params, @onLoadComplete)
onLoadComplete: (data) =>
View
8 app/assets/javascripts/app/controllers/collections/stats_controller.js.coffee
@@ -3,10 +3,12 @@ module = angular.module("mb.controllers")
class CollectionsStatsController
@$inject = ["$scope", "$routeParams", "Collection"]
constructor: (@$scope, $routeParams, Collection) ->
- @$scope.dbName = $routeParams.dbName
- @$scope.collectionName = $routeParams.collectionName
+ { @dbName, @collectionName } = $routeParams
- @collection = new Collection(dbName: @$scope.dbName, name: @$scope.collectionName)
+ @$scope.dbName = @dbName
+ @$scope.collectionName = @collectionName
+
+ @collection = new Collection(dbName: @dbName, name: @collectionName)
@fetchStats()
fetchStats: ->
View
5 app/assets/javascripts/app/controllers/databases/stats_controller.js.coffee
@@ -3,9 +3,10 @@ module = angular.module("mb.controllers")
class DatabasesStatsController
@$inject = ["$scope", "$routeParams", "Database"]
constructor: (@$scope, $routeParams, Database) ->
- @$scope.dbName = $routeParams.dbName
+ { @dbName } = $routeParams
+ @$scope.dbName = @dbName
- @database = new Database(name: @$scope.dbName)
+ @database = new Database(name: @dbName)
@fetchStats()
fetchStats: ->
View
9 app/assets/javascripts/app/controllers/documents/index_controller.js.coffee
@@ -5,10 +5,11 @@ class DocumentsIndexController
"Document", "confirmationDialog", "alerts"]
constructor: (@$scope, $routeParams, $location, @Document, @confirmationDialog, @alerts) ->
@loading = false
+ { @dbName, @collectionName } = $routeParams
# Scope variables
- @$scope.dbName = $routeParams.dbName
- @$scope.collectionName = $routeParams.collectionName
+ @$scope.dbName = @dbName
+ @$scope.collectionName = @collectionName
@$scope.page = parseInt($location.search().page || 1)
@@ -28,7 +29,7 @@ class DocumentsIndexController
fetchDocuments: (page = 1) ->
@loading = true
- params = dbName: @$scope.dbName, collectionName: @$scope.collectionName, page: page
+ params = dbName: @dbName, collectionName: @collectionName, page: page
@Document.query(params, @onLoadComplete)
onLoadComplete: (data) =>
@@ -45,7 +46,7 @@ class DocumentsIndexController
onOk: => @delete(document)
delete: (data) ->
- params = dbName: @$scope.dbName, collectionName: @$scope.collectionName, id: data.id
+ params = dbName: @dbName, collectionName: @collectionName, id: data.id
document = new @Document(params)
document.$delete =>
@alerts.info("Document #{data.id} has been deleted.")
View
17 app/assets/javascripts/app/controllers/documents/show_controller.js.coffee
@@ -2,23 +2,24 @@ module = angular.module("mb.controllers")
class DocumentsShowController
@$inject = ["$scope", "$routeParams", "Document"]
- constructor: (@$scope, $routeParams, @Document) ->
+ constructor: ($scope, $routeParams, Document) ->
@loading = false
+ { @dbName, @collectionName, @id } = $routeParams
+ @document = new Document(dbName: @dbName, collectionName: @collectionName, id: @id)
+
# Scope variables
- @$scope.dbName = $routeParams.dbName
- @$scope.collectionName = $routeParams.collectionName
- @$scope.id = $routeParams.id
+ $scope.dbName = @dbName
+ $scope.collectionName = @collectionName
+ $scope.document = @document
# Scope methods
- @$scope.isLoading = => @loading
+ $scope.isLoading = => @loading
@fetchDocument()
fetchDocument: ->
@loading = true
- @$scope.document = new @Document(dbName: @$scope.dbName, collectionName: @$scope.collectionName, id: @$scope.id, data: {})
- @$scope.document.$get =>
- @loading = false
+ @document.$get => @loading = false
module.controller "documents.show", DocumentsShowController
View
9 app/assets/javascripts/app/controllers/main_controller.js.coffee
@@ -3,11 +3,14 @@ module = angular.module("mb.controllers")
class MainController
@$inject = ["$scope", "$http"]
constructor: (@$scope, @$http) ->
- @$http.get("/api/version.json").success (data) =>
- @$scope.appVersion = data.version
- @$scope.environment = data.environment
+ @fetchVersion()
@$scope.showEnvironment = =>
@$scope.environment != "production"
+ fetchVersion: ->
+ @$http.get("/api/version.json").success (data) =>
+ @$scope.appVersion = data.version
+ @$scope.environment = data.environment
+
module.controller "main", MainController
View
19 spec/javascripts/app/controllers/documents/show_controller_spec.js.coffee
@@ -19,10 +19,10 @@ describe "documents show controller", ->
$httpBackend = $injector.get("$httpBackend")
$httpBackend.whenGET("/api/databases/test_database/collections/test_collection/documents/document_id.json")
- .respond([])
+ .respond({})
$scope = $rootScope.$new()
- controller = $controller "documents.index",
+ controller = $controller "documents.show",
$scope: $scope
$scope.$digest()
@@ -31,3 +31,18 @@ describe "documents show controller", ->
afterEach ->
$httpBackend.verifyNoOutstandingExpectation()
$httpBackend.verifyNoOutstandingRequest()
+
+ describe "$scope", ->
+ it "assigns variables from $routeParams", ->
+ expect($scope.dbName).toEqual("test_database")
+ expect($scope.collectionName).toEqual("test_collection")
+
+ # TODO create a macro / shared examples
+ describe "$scope.isLoading", ->
+ it "returns true when the resouce it loading", ->
+ controller.loading = true
+ expect($scope.isLoading()).toBeTruthy()
+
+ it "otherwise returns false", ->
+ controller.loading = false
+ expect($scope.isLoading()).toBeFalsy()
Please sign in to comment.
Something went wrong with that request. Please try again.