From 2bcf976252e7a715034d19d418048da31317b7cc Mon Sep 17 00:00:00 2001 From: Damith Date: Fri, 19 Feb 2016 19:46:44 +0530 Subject: [PATCH] Added dashboard hostname fix --- .../jaggery/config/common-scripts.jag | 25 +++ .../resources/jaggery/config/designer.json | 71 ++++---- .../resources/jaggery/config/index.js | 160 ++++++++++++++++++ modules/distribution/src/assembly/bin.xml | 20 +++ 4 files changed, 243 insertions(+), 33 deletions(-) create mode 100644 modules/distribution/repository/resources/jaggery/config/common-scripts.jag create mode 100644 modules/distribution/repository/resources/jaggery/config/index.js diff --git a/modules/distribution/repository/resources/jaggery/config/common-scripts.jag b/modules/distribution/repository/resources/jaggery/config/common-scripts.jag new file mode 100644 index 00000000..84217799 --- /dev/null +++ b/modules/distribution/repository/resources/jaggery/config/common-scripts.jag @@ -0,0 +1,25 @@ +<% +var log = new Log(); +var process = require('process'); +//TODO: fix carbon module and use it +var httpPort = process.getProperty('mgt.transport.http.port'); +var httpsPort = process.getProperty('mgt.transport.https.port'); +if(!urlDomain && !userDomain){ + urlDomain = 'carbon.super'; +} + +%> + \ No newline at end of file diff --git a/modules/distribution/repository/resources/jaggery/config/designer.json b/modules/distribution/repository/resources/jaggery/config/designer.json index 6acd9d2f..ad994357 100644 --- a/modules/distribution/repository/resources/jaggery/config/designer.json +++ b/modules/distribution/repository/resources/jaggery/config/designer.json @@ -1,37 +1,42 @@ { - "store": { - "type": "fs" - }, - "authentication": { - "activeMethod": "basic", - "methods": { - "sso": { - "attributes": { - "issuer": "portal", - "identityProviderURL": "https://localhost:9443/samlsso", - "responseSigningEnabled": "false", - "acs": "https://localhost:9444/portal/acs", - "identityAlias": "wso2carbon", - "useTenantKey": false + "store": { + "type": "fs" + }, + "authentication": { + "activeMethod": "basic", + "methods": { + "sso": { + "attributes": { + "issuer": "portal", + "identityProviderURL": "https://localhost:9443/samlsso", + "responseSigningEnabled": "false", + "acs": "https://localhost:9444/portal/acs", + "identityAlias": "wso2carbon", + "useTenantKey": false + } + }, + "basic": { + "attributes": {} + } } - }, - "basic": { - "attributes": {} - } + }, + "designers": [ + "Internal/everyone" + ], + "tenantPrefix": "/t", + "shareStore": false, + "theme": "basic", + "cacheTimeoutSeconds": "5", + "cacheSizeBytes": "1073741824", + "defaultDashboardRedirect": false, + "isCreateGadgetEnable": true, + "oauth": { + "username": "admin", + "password": "admin" + }, + "host": { + "hostname": "localhost", + "port": "", + "protocol": "" } - }, - "designers": [ - "Internal/everyone" - ], - "tenantPrefix": "/t", - "shareStore": false, - "theme": "basic", - "cacheTimeoutSeconds": "5", - "cacheSizeBytes": "1073741824", - "defaultDashboardRedirect": false, - "isCreateGadgetEnable": true, - "oauth": { - "username": "admin", - "password": "admin" - } } diff --git a/modules/distribution/repository/resources/jaggery/config/index.js b/modules/distribution/repository/resources/jaggery/config/index.js new file mode 100644 index 00000000..33ddc0da --- /dev/null +++ b/modules/distribution/repository/resources/jaggery/config/index.js @@ -0,0 +1,160 @@ +(function () { + + var gadgetPrefix = (osapi.container.GadgetHolder.IFRAME_ID_PREFIX_ = 'sandbox-'); + + var containerPrefix = 'gadget-'; + + var gadgets = {}; + + var server = ues.global.server; + + var resolveURI = ues.dashboards.resolveURI; + + var context = ues.global.context; + + var host = ues.global.host; + + var resolveGadgetURL = function (uri) { + uri = resolveURI(uri); + if (uri.match(/^https?:\/\//i)) { + return uri; + } + uri = uri.replace(/^(..\/)*/i, ''); + + var hostname = host.hostname ? host.hostname : window.location.hostname, + port = host.port ? host.port : window.location.port, + protocol = host.protocol ? (host.protocol + ":") : window.location.protocol; + + return protocol + '//' + hostname + ":" + port + context + '/' + uri; + }; + + var subscribeForClient = ues.hub.subscribeForClient; + + var containerId = function (id) { + return containerPrefix + id; + }; + + var gadgetId = function (id) { + return gadgetPrefix + containerPrefix + id; + }; + + ues.hub.subscribeForClient = function (container, topic, conSubId) { + var clientId = container.getClientID(); + var data = gadgets[clientId]; + if (!data) { + return subscribeForClient.apply(ues.hub, [container, topic, conSubId]); + } + var component = data.component; + var channel = component.id + '.' + topic; + console.log('subscribing container:%s topic:%s, channel:%s by %s', clientId, topic, channel); + return subscribeForClient.apply(ues.hub, [container, channel, conSubId]); + }; + + var component = (ues.plugins.components['gadget'] = {}); + + var hasCustomUserPrefView = function (metadata, comp) { + if(metadata.views.hasOwnProperty('settings')){ + comp.hasCustomUserPrefView= true; + } + }; + + var hasCustomFullView = function (metadata, comp) { + if(metadata.views.hasOwnProperty('full')){ + comp.hasCustomFullView= true; + } + }; + + var loadLocalizedTitle = function (styles, comp) { + var userLang = navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage || navigator.browserLanguage); + var locale_titles = comp.content.locale_titles || {}; + styles.title = locale_titles[userLang] || comp.content.title; + comp.content.locale_titles = locale_titles || {}; + }; + + component.create = function (sandbox, comp, hub, done) { + var content = comp.content, + url = resolveGadgetURL(content.data.url), + settings = content.settings || {}, + styles = content.styles || {}, + options = content.options || (content.options = {}); + ues.gadgets.preload(url, function (err, metadata) { + var pref, + name, + option, + params = {}, + prefs = metadata.userPrefs; + + for (pref in prefs) { + if (prefs.hasOwnProperty(pref)) { + pref = prefs[pref]; + name = pref.name; + option = options[name] || {}; + options[name] = { + type: option.type || pref.dataType, + title: option.title || pref.displayName, + value: option.value || pref.defaultValue, + options: option.options || pref.orderedEnumValues, + required: option.required || pref.required + }; + params[name] = option.value; + } + } + + loadLocalizedTitle(styles, comp); + var cid = containerId(comp.id), + gid = gadgetId(comp.id); + + sandbox.find('.ues-component-title').text(styles.title); + + if (styles.borders) { + sandbox.removeClass('ues-borderless'); + } else { + sandbox.addClass('ues-borderless'); + } + + var titlePositon = 'ues-component-title-' + (styles.titlePosition || 'left'); + + sandbox.find('.ues-component-header') + .removeClass('ues-component-title-left ues-component-title-center ues-component-title-right') + .addClass(titlePositon); + + if (ues.global.dbType === 'default') { + hasCustomUserPrefView(metadata, comp); + hasCustomFullView(metadata, comp); + } + + var container = $('
').attr('id', cid); + sandbox.find('.ues-component-body').html(container); + + var renderParams = {}; + renderParams[osapi.container.RenderParam.HEIGHT] = sandbox.closest('.ues-component-box').height() - 66; + renderParams[osapi.container.RenderParam.VIEW] = comp.viewOption || 'home'; + + var site = ues.gadgets.render(container, url, params, renderParams); + gadgets[gid] = { + component: comp, + site: site + }; + done(false, comp); + }); + }; + + component.update = function (sandbox, comp, hub, done) { + component.destroy(sandbox, comp, hub, function (err) { + if (err) { + throw err; + } + component.create(sandbox, comp, hub, done); + }); + }; + + component.destroy = function (sandbox, comp, hub, done) { + var gid = gadgetId(comp.id); + var data = gadgets[gid]; + var site = data.site; + ues.gadgets.remove(site.getId()); + $('.ues-component-box-gadget', sandbox).remove(); + done(false); + }; + +}()); \ No newline at end of file diff --git a/modules/distribution/src/assembly/bin.xml b/modules/distribution/src/assembly/bin.xml index e8698c6f..8d52a402 100644 --- a/modules/distribution/src/assembly/bin.xml +++ b/modules/distribution/src/assembly/bin.xml @@ -351,6 +351,8 @@ **/configs/designer.json + **/controllers/includes/common-scripts.jag + **/extensions/components/gadget/index.js **/js/VizGrammar.min.js **/templates/gadgets/igviz/js/VizGrammar.min.js @@ -692,6 +694,24 @@ 644 + + + repository/resources/jaggery/config/common-scripts.jag + ${pom.artifactId}-${pom.version}/repository/deployment/server/jaggeryapps/portal/controllers/includes + + true + 644 + + + + + repository/resources/jaggery/config/index.js + ${pom.artifactId}-${pom.version}/repository/deployment/server/jaggeryapps/portal/extensions/components/gadget + + true + 644 + +