Mforns has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/177005

Change subject: [WIP] Read configuration from mediawiki pages
......................................................................

[WIP] Read configuration from mediawiki pages

Bug: T70448
Change-Id: I66504b66126decdc0e7794ee6955f544674de811
---
M bower.json
M package.json
M src/app/apis/config-api.js
M src/app/config.js
M src/app/require.config.js
M test/app/apis.js
6 files changed, 77 insertions(+), 39 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/analytics/dashiki 
refs/changes/05/177005/1

diff --git a/bower.json b/bower.json
index ea0d674..964c199 100644
--- a/bower.json
+++ b/bower.json
@@ -12,7 +12,8 @@
     "moment": "^2.7.0",
     "knockout-projections": "~1.1.0-pre",
     "URIjs": "~1.13.2",
-    "typeahead.js":"~0.10.5",
-    "semantic": "~0.19.0"
+    "typeahead.js": "~0.10.5",
+    "semantic": "~0.19.0",
+    "mediawiki-storage": "~0.0.0"
   }
 }
diff --git a/package.json b/package.json
index 7f4d6f4..f997da5 100644
--- a/package.json
+++ b/package.json
@@ -4,24 +4,24 @@
   "devDependencies": {
     "chalk": "~0.4.0",
     "deeply": "~0.1.0",
+    "del": "~0.1.3",
     "event-stream": "~3.1.0",
     "gulp": "^3.8.5",
     "gulp-concat": "~2.2.0",
     "gulp-html-replace": "~1.0.0",
     "gulp-jshint": "~1.8.0",
+    "gulp-rename": "~1.2.0",
     "gulp-replace": "~0.4.0",
     "gulp-requirejs-bundler": "^0.1.1",
+    "gulp-rev": "~1.1.0",
     "gulp-uglify": "~0.2.1",
     "karma": "^0.12.15",
     "karma-chrome-launcher": "^0.1.3",
-    "karma-jasmine": "^0.1.5",
+    "karma-jasmine": "^0.2.2",
     "karma-requireglobal-preprocessor": "0.0.0",
     "karma-requirejs": "^0.2.1",
     "karma-sinon": "^1.0.3",
     "requirejs": "^2.1.11",
-    "sinon": "^1.10.3",
-    "gulp-rev": "~1.1.0",
-    "gulp-rename": "~1.2.0",
-    "del": "~0.1.3"
+    "sinon": "^1.10.3"
   }
 }
diff --git a/src/app/apis/config-api.js b/src/app/apis/config-api.js
index 49da83a..04038c9 100644
--- a/src/app/apis/config-api.js
+++ b/src/app/apis/config-api.js
@@ -2,17 +2,14 @@
  * This module returns an instance of an object that knows how to
  * Talk to the configurationAPI.
  *
- * Configuration files now reside in wikimetrics but we are planning to move 
them
- * to mediawiki.
- * Encapsulating configuration requests on this object separates the 
wikimetricsAPI
- * as a data provider and the wikimetricsAPI as a (temporary) config provider.
+ * Configuration files now reside in mediawiki.
+ * To get them, this module uses mediawiki-storage library.
  */
-define(['config'], function (siteConfig) {
+define(['config', 'mediawiki-storage'], function (siteConfig, 
mediawikiStorage) {
     'use strict';
 
     function ConfigApi(config) {
-        this.root = config.configApi.endpoint;
-        this.config = config;
+        this.config = config.configApi;
     }
 
     // only fetch certain things once per app life and keep their promise
@@ -21,16 +18,28 @@
 
     /**
      * Retrieves the default selections for metrics and projects
+     *
+     * Parameters
+     *   callback : a function to pass returned data to
+     *              (note you can just pass an observable here)
+     *
+     * Returns
+     *   a jquery promise to the default project and metric config
      **/
     ConfigApi.prototype.getDefaultDashboard = function (callback) {
 
         if (!promiseDefaults) {
-            promiseDefaults = 
this._getJSON(this.config.configApi.urlDefaultDashboard);
+            promiseDefaults = mediawikiStorage.get({
+                host: this.config.endpoint,
+                pageName: this.config.defaultDashboardPage
+            });
         }
         return promiseDefaults.done(callback);
     };
 
     /**
+     * Retrieves the available metrics configuration
+     *
      * Parameters
      *   callback : a function to pass returned data to
      *              (note you can just pass an observable here)
@@ -43,20 +52,12 @@
     ConfigApi.prototype.getCategorizedMetrics = function (callback) {
 
         if (!promiseMetrics) {
-            promiseMetrics = 
this._getJSON(this.config.configApi.urlCategorizedMetrics);
+            promiseMetrics = mediawikiStorage.get({
+                host: this.config.endpoint,
+                pageName: this.config.categorizedMetricsPage
+            });
         }
         return promiseMetrics.done(callback);
-    };
-
-    /**
-     * Returns
-     *   a promise to the url passed in
-     **/
-    ConfigApi.prototype._getJSON = function (url) {
-        return $.ajax({
-            dataType: 'json',
-            url: url
-        });
     };
 
     return new ConfigApi(siteConfig);
diff --git a/src/app/config.js b/src/app/config.js
index 3525f79..844993d 100644
--- a/src/app/config.js
+++ b/src/app/config.js
@@ -6,14 +6,12 @@
 
     return {
 
-        // Temporarily we are getting config from wikimetrics
-        // but the confiApi will be switched to mediawiki in the future
+        // indicates which mediawiki host and pages contain the configuration
         configApi: {
-            endpoint: 'metrics-staging.wmflabs.org',
-            urlCategorizedMetrics: 
'https://metrics-staging.wmflabs.org/static/public/datafiles/available-metrics.json',
-            //using stubs to iron any blockers with pageviews
-            //urlCategorizedMetrics: 
'https://metrics.wmflabs.org/static/public/datafiles/available-metrics.json',
-            urlDefaultDashboard: 
'https://metrics.wmflabs.org/static/public/datafiles/defaultDashboard.json'
+            endpoint: 'meta.wikimedia.org',
+            // next two fields are mediawiki page names
+            categorizedMetricsPage: 'Dashiki:CategorizedMetrics',
+            defaultDashboardPage: 'Dashiki:DefaultDashboard'
         },
 
         // format are specified per API for now, in the future they can be 
specified per metric if needed
diff --git a/src/app/require.config.js b/src/app/require.config.js
index 606d5bb..1afcce3 100644
--- a/src/app/require.config.js
+++ b/src/app/require.config.js
@@ -16,6 +16,7 @@
         'topojson'              : 'bower_modules/topojson/topojson',
         'moment'                : 'bower_modules/moment/moment',
         'semantic-dropdown'     : 
'bower_modules/semantic/build/uncompressed/modules/dropdown',
+        'mediawiki-storage'     : 
'bower_modules/mediawiki-storage/dist/mediawiki-storage',
         // NOTE: if you want functions like uri.expand, you must include both
         // URI and URITemplate like define(['uri/URI', 'uri/URITemplate'] ...
         // because URITemplate modifies URI when it's parsed
diff --git a/test/app/apis.js b/test/app/apis.js
index 6180389..903ee21 100644
--- a/test/app/apis.js
+++ b/test/app/apis.js
@@ -1,4 +1,6 @@
-define(['config', 'wikimetricsApi', 'configApi', 'jquery'], function 
(siteConfig, wikimetrics, configApi, $) {
+define([
+    'config', 'wikimetricsApi', 'configApi', 'mediawiki-storage', 'jquery'
+], function (siteConfig, wikimetrics, configApi, mediawikiStorage, $) {
 
     describe('Wikimetrics API', function () {
 
@@ -42,9 +44,44 @@
             getJSONStub.restore();
         });
 
-        it('should get metrics configuration', function () {
-            configApi.getCategorizedMetrics();
-            
expect($.ajax.getCalls()[0].args[0].url).toBe(siteConfig.configApi.urlCategorizedMetrics);
+        it('should get metrics configuration', function (done) {
+            var config = siteConfig.configApi;
+            var result = {'metrics': 'configuration'};
+
+            var deferred = new $.Deferred();
+            deferred.resolve(result);
+
+            sinon.stub(mediawikiStorage, 'get', function (options) {
+                expect(options.host).toBe(config.endpoint);
+                expect(options.pageName).toBe(config.categorizedMetricsPage);
+                return deferred.promise();
+            });
+
+            configApi.getCategorizedMetrics(function (returned) {
+                expect(returned).toBe(result);
+                mediawikiStorage.get.restore();
+                done();
+            });
+        });
+
+        it('should get dashboard configuration', function (done) {
+            var config = siteConfig.configApi;
+            var result = {'dashboard': 'configuration'};
+
+            var deferred = new $.Deferred();
+            deferred.resolve(result);
+
+            sinon.stub(mediawikiStorage, 'get', function (options) {
+                expect(options.host).toBe(config.endpoint);
+                expect(options.pageName).toBe(config.defaultDashboardPage);
+                return deferred.promise();
+            });
+
+            configApi.getDefaultDashboard(function (returned) {
+                expect(returned).toBe(result);
+                mediawikiStorage.get.restore();
+                done();
+            });
         });
     });
-});
\ No newline at end of file
+});

-- 
To view, visit https://gerrit.wikimedia.org/r/177005
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I66504b66126decdc0e7794ee6955f544674de811
Gerrit-PatchSet: 1
Gerrit-Project: analytics/dashiki
Gerrit-Branch: master
Gerrit-Owner: Mforns <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to