From 2238f0db0f99da6d711031f46df48494e22de85c Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Mon, 15 Apr 2013 11:59:20 +0200 Subject: [PATCH] Frontend: The Documentation of the Applications can now be accessed per application. And If there is an error useful info is printed --- html/admin/js/routers/router.js | 11 ++++------ html/admin/js/templates/navigationView.ejs | 1 - html/admin/js/views/appDocumentationView.js | 18 +++++++--------- html/admin/js/views/foxxActiveListView.js | 1 - html/admin/js/views/foxxActiveView.js | 8 ++++++- js/apps/aardvark/aardvark.js | 24 +++++++++++++++++---- js/apps/aardvark/manifest.json | 3 ++- js/apps/aardvark/repositories/foxxes.js | 9 ++------ js/apps/aardvark/repositories/swagger.js | 12 +++++++++++ 9 files changed, 55 insertions(+), 32 deletions(-) diff --git a/html/admin/js/routers/router.js b/html/admin/js/routers/router.js index 1dcc7ea595..f3b991ab23 100644 --- a/html/admin/js/routers/router.js +++ b/html/admin/js/routers/router.js @@ -18,7 +18,7 @@ $(document).ready(function() { "application/available/:key" : "applicationInstall", "applications/installed" : "applicationsInstalled", "applications/available" : "applicationsAvailable", - "applications/documentation" : "applicationsDocumentation", + "application/documentation/:key" : "appDocumentation", "graph" : "graph" }, @@ -223,12 +223,9 @@ $(document).ready(function() { }, - - applicationsDocumentation: function() { - if (this.appDocuView === undefined) { - this.appDocuView = new window.AppDocumentationView(); - } - this.appDocuView.render(); + appDocumentation: function(key) { + var docuView = new window.AppDocumentationView({key: key}); + docuView.render(); this.naviView.selectMenuItem('applications-menu'); } diff --git a/html/admin/js/templates/navigationView.ejs b/html/admin/js/templates/navigationView.ejs index 530b87847b..62b2cce877 100644 --- a/html/admin/js/templates/navigationView.ejs +++ b/html/admin/js/templates/navigationView.ejs @@ -14,7 +14,6 @@
  • Collections
  • AQL Editor
  • diff --git a/html/admin/js/views/appDocumentationView.js b/html/admin/js/views/appDocumentationView.js index f2d8d96295..d67af3406c 100644 --- a/html/admin/js/views/appDocumentationView.js +++ b/html/admin/js/views/appDocumentationView.js @@ -5,25 +5,23 @@ window.AppDocumentationView = Backbone.View.extend({ initialize: function() { this.swaggerUi = new SwaggerUi({ - discoveryUrl:"../aardvark/docus", + discoveryUrl:"../aardvark/docu/" + this.options.key, apiKey: false, dom_id:"swagger-ui-container", supportHeaderParams: true, supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch', 'head'], onComplete: function(swaggerApi, swaggerUi){ - if(console) { - console.log("Loaded SwaggerUI") - console.log(swaggerApi); - console.log(swaggerUi); - } $('pre code').each(function(i, e) {hljs.highlightBlock(e)}); }, onFailure: function(data) { - if(console) { - console.log("Unable to Load SwaggerUI"); - console.log(data); - } + var div = document.createElement("div"), + strong = document.createElement("strong"); + strong.appendChild(document.createTextNode("Sorry the code is not documented properly")); + div.appendChild(strong); + div.appendChild(document.createElement("br")); + div.appendChild(document.createTextNode(JSON.stringify(data))); + $("#swagger-ui-container").append(div); }, docExpansion: "none" }); diff --git a/html/admin/js/views/foxxActiveListView.js b/html/admin/js/views/foxxActiveListView.js index 018446064f..ba326335e8 100644 --- a/html/admin/js/views/foxxActiveListView.js +++ b/html/admin/js/views/foxxActiveListView.js @@ -18,7 +18,6 @@ var FoxxActiveListView = Backbone.View.extend({ self.render(); }, error: function() { - console.log("Erroreoror!!"); } }); this.render(); diff --git a/html/admin/js/views/foxxActiveView.js b/html/admin/js/views/foxxActiveView.js index e4d62224eb..34c738de62 100644 --- a/html/admin/js/views/foxxActiveView.js +++ b/html/admin/js/views/foxxActiveView.js @@ -4,7 +4,8 @@ window.FoxxActiveView = Backbone.View.extend({ template: new EJS({url: 'js/templates/foxxActiveView.ejs'}), events: { - 'click .icon-edit': 'editFoxx' + 'click .icon-edit': 'editFoxx', + 'click' : 'showDocu' }, initialize: function(){ @@ -15,6 +16,11 @@ window.FoxxActiveView = Backbone.View.extend({ event.stopPropagation(); window.App.navigate("application/installed/" + encodeURIComponent(this.model.get("_key")), {trigger: true}); }, + + showDocu: function(event) { + event.stopPropagation(); + window.App.navigate("application/documentation/" + encodeURIComponent(this.model.get("_key")), {trigger: true}); + }, render: function(){ $(this.el).html(this.template.render(this.model)); diff --git a/js/apps/aardvark/aardvark.js b/js/apps/aardvark/aardvark.js index 5670888cd5..d5c66bce22 100644 --- a/js/apps/aardvark/aardvark.js +++ b/js/apps/aardvark/aardvark.js @@ -93,7 +93,14 @@ app.get("/foxxes/thumbnail/:app", function (req, res) { res.transformations = [ "base64decode" ]; res.body = repositories.foxxes.thumbnail(req.params("app")); - }); + }).pathParam("app", { + description: "The appname which is used to identify the foxx in the list of available foxxes.", + dataType: "string", + required: true, + allowMultiple: false + }).nickname("thumbnails") + .summary("Get the thumbnail of a foxx.") + .notes("Used to request the thumbnail of the given Foxx in order to display it on the screen."); app.get('/foxxes', function (req, res) { @@ -109,13 +116,22 @@ .notes("This function simply returns the list of all running" + " foxxes and supplies the paths for the swagger documentation"); - app.get('/docus/*', function(req, res) { + app.get("/docu/:key",function (req, res) { + var subPath = req.path.substr(0,req.path.lastIndexOf("[")-1), + key = req.params("key"), + path = "http://" + req.headers.host + subPath + "/" + key + "/"; + res.json(repositories.docus.listOne(path, key)); + }).nickname("swaggers") + .summary("List documentation of all foxxes.") + .notes("This function simply returns one specific" + + " foxx and supplies the paths for the swagger documentation"); + + + app.get('/docu/:key/*', function(req, res) { var mountPoint = ""; require("underscore").each(req.suffix, function(part) { mountPoint += "/" + part; }); - - //require("console").log(JSON.stringify(req)); res.json(repositories.docus.show(mountPoint)) }).pathParam("appname", { description: "The mount point of the App the documentation should be requested for", diff --git a/js/apps/aardvark/manifest.json b/js/apps/aardvark/manifest.json index a410cdec09..19b0013294 100644 --- a/js/apps/aardvark/manifest.json +++ b/js/apps/aardvark/manifest.json @@ -4,5 +4,6 @@ "apps": { "/": "aardvark.js" - } + }, + "lib": "." } diff --git a/js/apps/aardvark/repositories/foxxes.js b/js/apps/aardvark/repositories/foxxes.js index 53f54a5a3d..963945b698 100644 --- a/js/apps/aardvark/repositories/foxxes.js +++ b/js/apps/aardvark/repositories/foxxes.js @@ -66,18 +66,13 @@ return thumb; }, - install: function (name, mount, version) { - require("console").log(name); - require("console").log(mount); - require("console").log(version); - - + install: function (name, mount, version) { return foxxmanager.installApp(name, mount, version); }, // Define the functionality to uninstall an installed foxx uninstall: function (key) { - return Foxx.uninstallApp(key); + return foxxmanager.uninstallApp(key); }, // Define the functionality to deactivate an installed foxx. diff --git a/js/apps/aardvark/repositories/swagger.js b/js/apps/aardvark/repositories/swagger.js index 7b94cf51fa..9163866220 100644 --- a/js/apps/aardvark/repositories/swagger.js +++ b/js/apps/aardvark/repositories/swagger.js @@ -62,8 +62,20 @@ return result; }, + listOne: function(basePath, key) { + var result = {}, + res = db._collection("_aal").document(key); + result.swaggerVersion = "1.1"; + result.basePath = basePath; + result.apis = [ + {path: res.mount} + ]; + return result; + }, + // Get details of one specific installed foxx. show: function(appname) { + require("console").log(appname); var result = {}, apis = [], pathes,