mongo_browser 0.2.0.rc2 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. data/.gitignore +3 -1
  2. data/.rspec +1 -1
  3. data/.travis.yml +6 -1
  4. data/CHANGELOG.md +15 -0
  5. data/{grunt.js → Gruntfile.js} +10 -8
  6. data/Procfile +1 -0
  7. data/README.md +44 -2
  8. data/Rakefile +1 -12
  9. data/app/assets/images/ajax-loader.gif +0 -0
  10. data/app/assets/javascripts/app/controllers/{breadcrumbs.js.coffee → breadcrumbs_controller.js.coffee} +4 -7
  11. data/app/assets/javascripts/app/controllers/collections/index_controller.js.coffee +38 -0
  12. data/app/assets/javascripts/app/controllers/collections/stats_controller.js.coffee +17 -0
  13. data/app/assets/javascripts/app/controllers/{databases.js.coffee → databases/index_controller.js.coffee} +11 -15
  14. data/app/assets/javascripts/app/controllers/databases/stats_controller.js.coffee +15 -0
  15. data/app/assets/javascripts/app/controllers/documents/index_controller.js.coffee +54 -0
  16. data/app/assets/javascripts/app/controllers/documents/show_controller.js.coffee +38 -0
  17. data/app/assets/javascripts/app/controllers/main_controller.js.coffee +15 -0
  18. data/app/assets/javascripts/app/controllers/servers/show_controller.js.coffee +17 -0
  19. data/app/assets/javascripts/app/directives.js.coffee +23 -0
  20. data/app/assets/javascripts/app/filters.js.coffee +14 -1
  21. data/app/assets/javascripts/app/modules/alerts.js.coffee +58 -0
  22. data/app/assets/javascripts/app/modules/pager.js.coffee +2 -2
  23. data/app/assets/javascripts/app/modules/spinner.js.coffee +29 -0
  24. data/app/assets/javascripts/app/modules/table_filter.js.coffee +4 -4
  25. data/app/assets/javascripts/app/resources.js.coffee +14 -8
  26. data/app/assets/javascripts/app/services.js.coffee +11 -33
  27. data/app/assets/javascripts/application.js.coffee +62 -34
  28. data/app/assets/javascripts/application.test.js.coffee +5 -0
  29. data/app/assets/javascripts/compiled_templates.js.coffee +1 -0
  30. data/app/assets/javascripts/vendor.js.coffee +0 -1
  31. data/app/assets/stylesheets/application.css.scss +36 -18
  32. data/{public/index.html → app/views/index.erb} +8 -8
  33. data/bin/mongo_browser +2 -13
  34. data/config.ru +3 -1
  35. data/lib/mongo_browser.rb +1 -0
  36. data/lib/mongo_browser/api.rb +11 -0
  37. data/lib/mongo_browser/api/collections.rb +34 -0
  38. data/lib/mongo_browser/api/databases.rb +32 -0
  39. data/lib/mongo_browser/api/documents.rb +37 -0
  40. data/lib/mongo_browser/api/mongo.rb +41 -0
  41. data/lib/mongo_browser/application.rb +8 -174
  42. data/lib/mongo_browser/application/development.rb +32 -0
  43. data/lib/mongo_browser/cli.rb +48 -0
  44. data/lib/mongo_browser/entities.rb +43 -0
  45. data/lib/mongo_browser/models/collection.rb +7 -12
  46. data/lib/mongo_browser/models/document.rb +5 -1
  47. data/lib/mongo_browser/models/pager.rb +22 -9
  48. data/lib/mongo_browser/version.rb +1 -1
  49. data/mongo_browser.gemspec +22 -15
  50. data/package.json +30 -0
  51. data/public/ng/templates/alerts.html +6 -0
  52. data/public/ng/templates/collections/index.html +39 -0
  53. data/public/ng/templates/collections/stats.html +18 -0
  54. data/public/ng/templates/databases/index.html +35 -0
  55. data/public/ng/templates/databases/stats.html +18 -0
  56. data/public/ng/templates/documents/index.html +40 -0
  57. data/public/ng/templates/documents/show.html +17 -0
  58. data/{app/assets → public/ng}/templates/pager.html +0 -0
  59. data/{app/assets/templates/server_info.html → public/ng/templates/server/show.html} +1 -1
  60. data/{app/assets → public/ng}/templates/table_filter.html +0 -0
  61. data/script/ci_all +5 -1
  62. data/script/ci_e2e +5 -2
  63. data/script/ci_javascripts +1 -1
  64. data/script/ci_rspec +1 -1
  65. data/spec/javascripts/app/controllers/{breadcrumbs_spec.js.coffee → breadcrumbs_controller_spec.js.coffee} +1 -1
  66. data/spec/javascripts/app/controllers/collections/index_controller_spec.js.coffee +95 -0
  67. data/spec/javascripts/app/controllers/collections/stats_controller_spec.js.coffee +34 -0
  68. data/spec/javascripts/app/controllers/databases/index_controller_spec.js.coffee +93 -0
  69. data/spec/javascripts/app/controllers/databases/stats_controller_spec.js.coffee +30 -0
  70. data/spec/javascripts/app/controllers/documents/index_controller_spec.js.coffee +108 -0
  71. data/spec/javascripts/app/controllers/documents/show_controller_spec.js.coffee +94 -0
  72. data/spec/javascripts/app/controllers/{main_spec.js.coffee → main_controller_spec.js.coffee} +2 -2
  73. data/spec/javascripts/app/controllers/{server_info_spec.js.coffee → server/show_controller_spec.js.coffee} +5 -6
  74. data/spec/javascripts/app/directives_spec.js.coffee +108 -24
  75. data/spec/javascripts/app/filters_spec.js.coffee +31 -5
  76. data/spec/javascripts/app/modules/alerts_spec.js.coffee +138 -0
  77. data/spec/javascripts/app/modules/dialogs_spec.js.coffee +1 -2
  78. data/spec/javascripts/app/modules/pager_spec.js.coffee +0 -1
  79. data/spec/javascripts/app/modules/spinner_spec.js.coffee +65 -0
  80. data/spec/javascripts/app/modules/table_filter_spec.js.coffee +9 -9
  81. data/spec/javascripts/app/resources_spec.js.coffee +99 -0
  82. data/spec/javascripts/app/services_spec.js.coffee +31 -71
  83. data/spec/javascripts/config/{testacular-e2e.conf.js → karma-e2e.conf.js} +1 -1
  84. data/spec/javascripts/config/{testacular.conf.js → karma.conf.js} +2 -3
  85. data/spec/javascripts/e2e/collection_stats_scenario.js.coffee +12 -0
  86. data/spec/javascripts/e2e/collections_scenario.js.coffee +59 -20
  87. data/spec/javascripts/e2e/database_stats_scenario.js.coffee +11 -0
  88. data/spec/javascripts/e2e/databases_scenario.js.coffee +37 -36
  89. data/spec/javascripts/e2e/document_show_scenario.js.coffee +31 -0
  90. data/spec/javascripts/e2e/documents_pagination_scenario.js.coffee +33 -0
  91. data/spec/javascripts/e2e/documents_scenario.js.coffee +43 -4
  92. data/spec/javascripts/e2e/server_info_scenario.js.coffee +8 -2
  93. data/spec/javascripts/helpers/mocks.js.coffee +2 -0
  94. data/spec/javascripts/helpers_e2e/dsl.js.coffee +20 -0
  95. data/spec/javascripts/lib/angular-mocks.js +64 -16
  96. data/spec/javascripts/lib/angular-scenario.js +724 -561
  97. data/spec/javascripts/runner.html +5 -5
  98. data/spec/lib/api/collections_spec.rb +62 -0
  99. data/spec/lib/api/databases_spec.rb +58 -0
  100. data/spec/lib/api/documents_spec.rb +135 -0
  101. data/spec/lib/api/mongo_spec.rb +27 -0
  102. data/spec/lib/cli_spec.rb +19 -0
  103. data/spec/lib/entities_spec.rb +39 -0
  104. data/spec/lib/models/collection_spec.rb +16 -10
  105. data/spec/lib/models/database_spec.rb +4 -4
  106. data/spec/lib/models/document_spec.rb +5 -5
  107. data/spec/lib/models/pager_spec.rb +20 -11
  108. data/spec/spec_helper.rb +7 -15
  109. data/spec/support/api_example_group.rb +45 -0
  110. data/spec/support/fixtures.rb +10 -6
  111. data/spec/support/matchers/expose.rb +18 -0
  112. data/vendor/assets/javascripts/angular/angular-bootstrap.js +1 -1
  113. data/vendor/assets/javascripts/angular/angular-resource.js +78 -56
  114. data/vendor/assets/javascripts/angular/angular-sanitize.js +3 -1
  115. data/vendor/assets/javascripts/angular/angular.js +720 -404
  116. metadata +323 -183
  117. data/app/assets/javascripts/app.js.coffee +0 -8
  118. data/app/assets/javascripts/app/controllers.js.coffee +0 -2
  119. data/app/assets/javascripts/app/controllers/alerts.js.coffee +0 -12
  120. data/app/assets/javascripts/app/controllers/collections.js.coffee +0 -40
  121. data/app/assets/javascripts/app/controllers/documents.js.coffee +0 -49
  122. data/app/assets/javascripts/app/controllers/main.js.coffee +0 -10
  123. data/app/assets/javascripts/app/controllers/server_info.js.coffee +0 -14
  124. data/app/assets/javascripts/templates.js.coffee +0 -1
  125. data/app/assets/javascripts/templates/.gitkeep +0 -0
  126. data/app/assets/templates/collections.html +0 -53
  127. data/app/assets/templates/databases.html +0 -32
  128. data/app/assets/templates/documents.html +0 -45
  129. data/config-e2e.ru +0 -20
  130. data/spec/features/collections_list_spec.rb +0 -64
  131. data/spec/features/documents_list_spec.rb +0 -139
  132. data/spec/features/server_info_spec.rb +0 -23
  133. data/spec/javascripts/app/controllers/alerts_spec.js.coffee +0 -36
  134. data/spec/javascripts/app/controllers/collections_spec.js.coffee +0 -78
  135. data/spec/javascripts/app/controllers/databases_spec.js.coffee +0 -55
  136. data/spec/javascripts/app/controllers/documents_spec.js.coffee +0 -62
  137. data/spec/javascripts/helpers_e2e/app_element.js.coffee +0 -6
  138. data/spec/support/feature_example_group.rb +0 -53
  139. data/spec/support/matchers/have_flash_message.rb +0 -16
  140. data/spec/support/mongod.rb +0 -91
  141. data/spec/support/mongodb.conf +0 -47
data/.gitignore CHANGED
@@ -12,5 +12,7 @@ Gemfile.lock
12
12
  *.iml
13
13
  *.gem
14
14
 
15
+ node_modules
16
+
15
17
  # ignore compiled templates
16
- app/assets/javascripts/templates/*.js
18
+ app/assets/javascripts/compiled_templates
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --colour
2
- --format documentation
2
+ --format progress
@@ -2,9 +2,14 @@ language: ruby
2
2
 
3
3
  rvm:
4
4
  - 1.9.3
5
+ - 2.0.0
6
+
7
+ services:
8
+ - mongodb
5
9
 
6
10
  before_script:
7
- - "npm install -g grunt testacular@canary --quiet"
11
+ - "npm install -g grunt-cli karma"
12
+ - "npm install grunt"
8
13
  - "export DISPLAY=:99.0"
9
14
  - "sh -e /etc/init.d/xvfb start"
10
15
 
@@ -0,0 +1,15 @@
1
+ # mongo_browser changelog
2
+
3
+ ## 0.2.5 (07/15/2013)
4
+
5
+ * feature: refreshing the document page #99
6
+ * feature: better CLI runner #103
7
+ * add `execjs` and `therubyracer` into `Gemfile`
8
+ * add missing license information #105
9
+
10
+ ## 0.2.1 (01/15/2013)
11
+
12
+ * feature: redirect and set alert message whe a document has not been found
13
+ * feature: display global spinner for http requests
14
+ * cleanup coffeescript code for controllers
15
+ * many other minor bugfixea and improvements
@@ -3,13 +3,13 @@ module.exports = function(grunt) {
3
3
  grunt.initConfig({
4
4
  watch: {
5
5
  templates: {
6
- files: 'app/assets/templates/*.html',
7
- tasks: 'html2js:directives'
6
+ files: "public/ng/templates/**/*.html",
7
+ tasks: "html2js:directives"
8
8
  }
9
9
  },
10
10
 
11
11
  html2js: {
12
- directives: ['app/assets/templates/*.html']
12
+ directives: ["public/ng/templates/**/*.html"]
13
13
  }
14
14
  });
15
15
 
@@ -19,18 +19,20 @@ module.exports = function(grunt) {
19
19
  return content.replace(/"/g, '\\"').replace(/\n/g, '" +\n "');
20
20
  };
21
21
 
22
- grunt.registerMultiTask('html2js', 'Generate js version of html template.', function() {
22
+ grunt.registerMultiTask("html2js", "Generate js version of html template.", function() {
23
23
  var files = grunt._watch_changed_files || grunt.file.expand(this.data);
24
24
 
25
25
  files.forEach(function(file) {
26
- var parts = file.split("/");
27
- var name = parts[parts.length - 1];
26
+ var parts = file.split("/").slice(3);
27
+ var name = parts.join("/");
28
28
 
29
- grunt.file.write("app/assets/javascripts/templates/" + name + '.js', grunt.template.process(TPL, {
29
+ var data = {
30
30
  file: file,
31
31
  path: "/ng/templates/" + file.split("/").pop(),
32
32
  content: escapeContent(grunt.file.read(file))
33
- }));
33
+ };
34
+ var content = grunt.template.process(TPL, { data: data });
35
+ grunt.file.write("app/assets/javascripts/compiled_templates/" + name + ".js", content);
34
36
  });
35
37
  });
36
38
  };
@@ -0,0 +1 @@
1
+ thin: bundle exec thin start -R config.ru -e development -p 4000
data/README.md CHANGED
@@ -1,24 +1,64 @@
1
1
  # MongoBrowser
2
2
 
3
3
  [![Build status](https://secure.travis-ci.org/lucassus/mongo_browser.png)](http://travis-ci.org/lucassus/mongo_browser)
4
+ [![Coverage Status](https://coveralls.io/repos/lucassus/mongo_browser/badge.png?branch=master)](https://coveralls.io/r/lucassus/mongo_browser)
4
5
  [![Dependency Status](https://gemnasium.com/lucassus/mongo_browser.png)](http://gemnasium.com/lucassus/mongo_browser)
6
+ [![Gem Version](https://badge.fury.io/rb/mongo_browser.png)](http://badge.fury.io/rb/mongo_browser)
5
7
  [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/lucassus/mongo_browser)
6
8
 
7
9
  Simple but powerful tool for managing mongodb databases
8
10
 
9
11
  Install the gem:
10
12
 
11
- $ gem install mongo_browser
13
+ gem install mongo_browser
12
14
 
13
15
  ## Usage
14
16
 
15
17
  Run the application
16
18
 
17
- $ mongo_browser
19
+ mongo_browser start
18
20
 
19
21
  Application will be available by default at http://localhost:5678
20
22
  In order to run it on custom port number pass the `--port` option with selected port.
21
23
 
24
+ ## Getting started with the development
25
+
26
+ ```
27
+ bundle install
28
+ sudo npm install -g grunt grunt-cli karma
29
+ ```
30
+
31
+ The main goal of this project is to achieve the highest testability with 100% code coverage.
32
+
33
+ In order to execute rspec scenarios for backend just execute:
34
+
35
+ rspec spec
36
+
37
+ ### Running frontend specs
38
+
39
+ #### Inside the console
40
+
41
+ * `./script/ci_javascript` will execute jasmine specs
42
+ * `./script/ci_e2e` will execute angularjs e2e scenarios
43
+
44
+ #### Inside the browser
45
+
46
+ Run thin in the test environment:
47
+
48
+ thin start -R config.ru -e test -p 3001
49
+
50
+ or
51
+ foreman start
52
+
53
+ Navigate to the one of the following url:
54
+
55
+ * [http://localhost:3001/jasmine](http://localhost:3001/jasmine) will execute jasmine specs
56
+ * [http://localhost:3001/e2e](http://localhost:3001/e2e) will execute angularjs e2e scenarios
57
+
58
+ ### Continuous integration
59
+
60
+ All specs (backend + frontend) could be executed with the following command `./script/ci_all`
61
+
22
62
  ## Contributing
23
63
 
24
64
  1. Fork it
@@ -26,3 +66,5 @@ In order to run it on custom port number pass the `--port` option with selected
26
66
  3. Commit your changes (`git commit -am 'Add some feature'`)
27
67
  4. Push to the branch (`git push origin my-new-feature`)
28
68
  5. Create new Pull Request
69
+
70
+ This software is licensed under the MIT License.
data/Rakefile CHANGED
@@ -28,8 +28,6 @@ require 'rake/clean'
28
28
 
29
29
  require 'rake/testtask'
30
30
 
31
- require 'cucumber'
32
- require 'cucumber/rake/task'
33
31
  gem 'rdoc' # we need the installed RDoc gem, not the system one
34
32
  require 'rdoc/task'
35
33
 
@@ -37,19 +35,10 @@ include Rake::DSL
37
35
 
38
36
  Bundler::GemHelper.install_tasks
39
37
 
40
-
41
38
  Rake::TestTask.new do |t|
42
39
  t.pattern = 'test/tc_*.rb'
43
40
  end
44
41
 
45
-
46
- CUKE_RESULTS = 'results.html'
47
- CLEAN << CUKE_RESULTS
48
- Cucumber::Rake::Task.new(:features) do |t|
49
- t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
50
- t.fork = false
51
- end
52
-
53
42
  Rake::RDocTask.new do |rd|
54
43
 
55
44
  rd.main = "README.rdoc"
@@ -57,4 +46,4 @@ Rake::RDocTask.new do |rd|
57
46
  rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
58
47
  end
59
48
 
60
- task :default => [:test,:features]
49
+ task :default => [:test]
@@ -1,9 +1,7 @@
1
- module = angular.module("mb.controllers")
2
-
3
1
  # TODO find better solution for breadcrumbs
4
- class BreadcrumbsController
2
+ class BreadcrumbsCtrl
3
+ @$inject = ["$rootScope", "$scope"]
5
4
  constructor: (@$rootScope, @$scope) ->
6
-
7
5
  @$scope.showDatabase = => @$scope.dbName
8
6
  @$scope.showCollection = => @$scope.collectionName
9
7
 
@@ -20,6 +18,5 @@ class BreadcrumbsController
20
18
  dbName: @$scope.dbName
21
19
  name: @$scope.collectionName
22
20
 
23
- BreadcrumbsController.$inject = ["$rootScope", "$scope"]
24
-
25
- module.controller "breadcrumbs", BreadcrumbsController
21
+ angular.module("mb")
22
+ .controller("breadcrumbs", BreadcrumbsCtrl)
@@ -0,0 +1,38 @@
1
+ class CollectionsIndexCtrl
2
+ @$inject = ["$scope", "$routeParams", "Collection", "confirmationDialog", "alerts"]
3
+ constructor: (@$scope, $routeParams, @Collection, @confirmationDialog, @alerts) ->
4
+ @loading = false
5
+ { @dbName } = $routeParams
6
+
7
+ # Scope variables
8
+ @$scope.dbName = @dbName
9
+ @$scope.filterValue = ""
10
+
11
+ # Scope methods
12
+ @$scope.isLoading = => @loading
13
+ @$scope.delete = (collection) => @deleteWithConfirmation(collection)
14
+
15
+ @fetchCollections()
16
+
17
+ fetchCollections: ->
18
+ @loading = true
19
+ params = dbName: @dbName
20
+ @$scope.collections = @Collection.query(params, @onLoadComplete)
21
+
22
+ onLoadComplete: (data) =>
23
+ @$scope.collections = data
24
+ @loading = false
25
+
26
+ deleteWithConfirmation: (collection) ->
27
+ @confirmationDialog
28
+ message: "Deleting #{collection.name}. Are you sure?"
29
+ onOk: => @delete(collection)
30
+
31
+ delete: (data) ->
32
+ collection = new @Collection(data)
33
+ collection.$delete =>
34
+ @alerts.info("Collection #{data.name} has been deleted.")
35
+ @fetchCollections()
36
+
37
+ angular.module("mb")
38
+ .controller("collections.index", CollectionsIndexCtrl)
@@ -0,0 +1,17 @@
1
+ class CollectionsStatsCtrl
2
+ @$inject = ["$scope", "$routeParams", "Collection"]
3
+ constructor: (@$scope, $routeParams, Collection) ->
4
+ { @dbName, @collectionName } = $routeParams
5
+
6
+ @$scope.dbName = @dbName
7
+ @$scope.collectionName = @collectionName
8
+
9
+ @collection = new Collection(dbName: @dbName, name: @collectionName)
10
+ @fetchStats()
11
+
12
+ fetchStats: ->
13
+ @collection.$stats (data) =>
14
+ @$scope.stats = data
15
+
16
+ angular.module("mb")
17
+ .controller("collections.stats", CollectionsStatsCtrl)
@@ -1,17 +1,17 @@
1
- module = angular.module("mb.controllers")
2
-
3
- class DatabasesController
1
+ class DatabasesIndexCtrl
2
+ @$inject = ["$scope", "Database", "confirmationDialog", "alerts"]
4
3
  constructor: (@$scope, @Database, @confirmationDialog, @alerts) ->
5
4
  @loading = false
6
- @fetchDatabases()
7
5
 
8
6
  # Scope variables
9
7
  @$scope.filterValue = ""
10
8
 
11
9
  # Scope methods
12
- @$scope.isLoading = -> @loading
10
+ @$scope.isLoading = => @loading
13
11
  @$scope.delete = (database) => @dropWithConfirmation(database)
14
12
 
13
+ @fetchDatabases()
14
+
15
15
  fetchDatabases: ->
16
16
  @loading = true
17
17
  @Database.query(@onLoadComplete)
@@ -25,15 +25,11 @@ class DatabasesController
25
25
  message: "Deleting #{database.name}. Are you sure?"
26
26
  onOk: => @drop(database)
27
27
 
28
- drop: (database) ->
29
- resource = new @Database()
30
- params = id: database.name
31
-
32
- resource.$delete params, =>
33
- @alerts.info("Database #{database.name} has been deleted.")
28
+ drop: (data) ->
29
+ database = new @Database(data)
30
+ database.$delete =>
31
+ @alerts.info("Database #{data.name} has been deleted.")
34
32
  @fetchDatabases()
35
33
 
36
- DatabasesController.$inject = ["$scope",
37
- "Database", "confirmationDialog", "alerts"]
38
-
39
- module.controller "databases", DatabasesController
34
+ angular.module("mb")
35
+ .controller("databases.index", DatabasesIndexCtrl)
@@ -0,0 +1,15 @@
1
+ class DatabasesStatsCtrl
2
+ @$inject = ["$scope", "$routeParams", "Database"]
3
+ constructor: (@$scope, $routeParams, Database) ->
4
+ { @dbName } = $routeParams
5
+ @$scope.dbName = @dbName
6
+
7
+ @database = new Database(name: @dbName)
8
+ @fetchStats()
9
+
10
+ fetchStats: ->
11
+ @database.$stats (data) =>
12
+ @$scope.stats = data
13
+
14
+ angular.module("mb")
15
+ .controller("databases.stats", DatabasesStatsCtrl)
@@ -0,0 +1,54 @@
1
+ class DocumentsIndexCtrl
2
+ @$inject = ["$scope", "$routeParams", "$location",
3
+ "Document", "confirmationDialog", "alerts"]
4
+ constructor: (@$scope, $routeParams, $location, @Document, @confirmationDialog, @alerts) ->
5
+ @loading = false
6
+ { @dbName, @collectionName } = $routeParams
7
+
8
+ # Scope variables
9
+ @$scope.dbName = @dbName
10
+ @$scope.collectionName = @collectionName
11
+
12
+ @$scope.page = parseInt($location.search().page || 1)
13
+
14
+ # Scope methods
15
+ @$scope.delete = (document) => @deleteWithConfirmation(document)
16
+ @$scope.isLoading = => @loading
17
+ @$scope.showDocuments = => @$scope.size > 0
18
+
19
+ @$scope.$watch "page", (page) =>
20
+ if page > 1
21
+ $location.search("page", page)
22
+ else
23
+ $location.search("page", null)
24
+
25
+ @fetchDocuments(page)
26
+
27
+ fetchDocuments: (page = 1) ->
28
+ @loading = true
29
+
30
+ params = dbName: @dbName, collectionName: @collectionName, page: page
31
+ @Document.query(params, @onLoadComplete)
32
+
33
+ onLoadComplete: (data) =>
34
+ @$scope.documents = data.documents
35
+ @$scope.page = data.page
36
+ @$scope.totalPages = data.totalPages
37
+ @$scope.size = data.size
38
+
39
+ @loading = false
40
+
41
+ deleteWithConfirmation: (document) ->
42
+ @confirmationDialog
43
+ message: "Are you sure?"
44
+ onOk: => @delete(document)
45
+
46
+ delete: (data) ->
47
+ params = dbName: @dbName, collectionName: @collectionName, id: data.id
48
+ document = new @Document(params)
49
+ document.$delete =>
50
+ @alerts.info("Document #{data.id} has been deleted.")
51
+ @fetchDocuments()
52
+
53
+ angular.module("mb")
54
+ .controller("documents.index", DocumentsIndexCtrl)
@@ -0,0 +1,38 @@
1
+ class DocumentsShowCtrl
2
+ @$inject = ["$scope", "$routeParams", "$location", "Document", "alerts"]
3
+ constructor: ($scope, $routeParams, @$location, Document, @alerts) ->
4
+ @loading = false
5
+
6
+ { @dbName, @collectionName, @id } = $routeParams
7
+ @document = new Document(dbName: @dbName, collectionName: @collectionName, id: @id)
8
+
9
+ # Scope variables
10
+ $scope.dbName = @dbName
11
+ $scope.collectionName = @collectionName
12
+ $scope.document = @document
13
+
14
+ # Scope methods
15
+ $scope.isLoading = => @loading
16
+ $scope.refresh = => @refreshDocument()
17
+
18
+ @fetchDocument =>
19
+ @loading = false
20
+
21
+ fetchDocument: (onSuccess = ->) ->
22
+ @loading = true
23
+ @document.$get(onSuccess, @handleNotFoundDocument)
24
+
25
+ refreshDocument: ->
26
+ @fetchDocument =>
27
+ @loading = false
28
+ @alerts.info("Document was refreshed")
29
+
30
+ # Redirects to the collection page
31
+ # alert.error will be set by the `httpErrorsInterceptor`
32
+ handleNotFoundDocument: (response) =>
33
+ return unless response.status is 404
34
+ # TODO use filter here
35
+ @$location.path("/databases/#{@dbName}/collections/#{@collectionName}/documents")
36
+
37
+ angular.module("mb")
38
+ .controller("documents.show", DocumentsShowCtrl)
@@ -0,0 +1,15 @@
1
+ class MainCtrl
2
+ @$inject = ["$scope", "$http"]
3
+ constructor: (@$scope, @$http) ->
4
+ @fetchVersion()
5
+
6
+ @$scope.showEnvironment = =>
7
+ @$scope.environment != "production"
8
+
9
+ fetchVersion: ->
10
+ @$http.get("/api/version").success (data) =>
11
+ @$scope.appVersion = data.version
12
+ @$scope.environment = data.environment
13
+
14
+ angular.module("mb")
15
+ .controller("main", MainCtrl)