issue #24200: load versions into client from datasource
authorSteve Hackbarth <stephenhackbarth@gmail.com>
Tue, 29 Jul 2014 19:20:10 +0000 (15:20 -0400)
committerSteve Hackbarth <stephenhackbarth@gmail.com>
Tue, 29 Jul 2014 19:20:10 +0000 (15:20 -0400)
enyo-client/application/source/ext/session.js
enyo-client/application/source/preliminaries.js
node-datasource/main.js

index 46cef52..65a80c2 100644 (file)
@@ -22,6 +22,8 @@ white:true*/
     },
 
     _didValidateSession: function (payload, callback) {
+      var coreVersion;
+
       if (payload.code === 1) {
         // If this is a valid session acquisition, go ahead
         // and store the database config details in
@@ -30,10 +32,28 @@ white:true*/
         this.setConfig(payload);
         this.setDetails(payload.data);
 
-        if (payload.version && XT.setVersion) {
+        if (payload.versions && XT.setVersion) {
           // announce to the client what our version is, if we have
           // a way of doing it.
-          XT.setVersion(payload.version);
+
+          _.each(payload.versions,  function (version, extensionName) {
+            // default to the core version (temp until all core extensions are in npm)
+            if (extensionName === "core") {
+              coreVersion = version;
+              extensionName = "";
+            } else if (version === "none") {
+              version = coreVersion;
+            }
+
+            var aboutVersionLabel = XT.app.$.postbooks.$.navigator.$.aboutVersion,
+              versionText = extensionName + " " + "_version".loc().toLowerCase() + " " + version;
+
+            if (aboutVersionLabel.getContent()) {
+              versionText = aboutVersionLabel.getContent() + "<br>" + versionText;
+            }
+
+            aboutVersionLabel.setContent(versionText);
+          });
         }
 
         // Start the client loading process.
index 813e23f..9e75865 100644 (file)
@@ -26,20 +26,8 @@ XT = typeof XT !== 'undefined' ? XT : {};
   };
 
   XT.setVersion = function (version, qualifier) {
-    // default to the core version
-    version = version || XT.session.config.version;
-
-    var aboutVersionLabel = XT.app.$.postbooks.$.navigator.$.aboutVersion,
-      versionText = "_version".loc() + " " + version;
-
-    if (qualifier) {
-      versionText = ("_" + qualifier).loc() + " " + versionText;
-    }
-    if (aboutVersionLabel.getContent()) {
-      versionText = aboutVersionLabel.getContent() + "<br>" + versionText;
-    }
-
-    aboutVersionLabel.setContent(versionText);
+    XT.log("XT.setVersion is now deprecated. The app now reads extension versions from " +
+      "package.json or manifest.js (" + qualifier + ")");
   };
 
 }());
index 25801b5..6896e0a 100755 (executable)
@@ -114,9 +114,14 @@ var app;
     var extensionLocation = extension.location === "npm" ? extension.location : extension.location + "/source";
     useClientDir(extensionLocation + "/" + extension.name + "/client", X.path.join(getExtensionDir(extension), "client"));
   };
-  var loadExtensionRoutes = function (extension) {
+  var loadExtensionServerside = function (extension) {
+    var packagePath = X.path.join(getExtensionDir(extension), "package.json");
+    var packageJson = X.fs.existsSync(packagePath) ? require(packagePath) : undefined;
     var manifest = JSON.parse(X.fs.readFileSync(X.path.join(getExtensionDir(extension),
         "database/source/manifest.js")));
+    var version = packageJson ? packageJson.version : manifest.version;
+    X.versions[extension.name] = version || "none"; // XXX the "none" is temporary until we have core extensions in npm
+
     _.each(manifest.routes || [], function (routeDetails) {
       var verb = (routeDetails.verb || "all").toLowerCase(),
         func = require(X.path.join(getExtensionDir(extension),
@@ -149,7 +154,7 @@ var app;
           return;
         }
         useClientDir("/client", "../enyo-client/application");
-        _.each(results, loadExtensionRoutes);
+        _.each(results, loadExtensionServerside);
         _.each(results, loadExtensionClientside);
       }
     });
@@ -168,11 +173,9 @@ var app;
  */
 
 var packageJson = X.fs.readFileSync("../package.json");
-try {
-  X.version = JSON.parse(packageJson).version;
-} catch (error) {
-
-}
+X.versions = {
+  core: JSON.parse(packageJson).version
+};
 
 /**
  * Module dependencies.
@@ -638,10 +641,9 @@ io.of('/clientsock').authorization(function (handshakeData, callback) {
           data: session.passport.user,
           code: 1,
           debugging: X.options.datasource.debugging,
-          biAvailable: _.isObject(X.options.biServer) && !_.isEmpty(X.options.biServer),
           emailAvailable: _.isString(X.options.datasource.smtpHost) && X.options.datasource.smtpHost !== "",
           printAvailable: _.isString(X.options.datasource.printer) && X.options.datasource.printer !== "",
-          version: X.version
+          versions: X.versions
         });
       callback(callbackObj);
     }, data && data.payload);