Updating ues-patch and member-details-filter.js to get rid of timeout
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/12110f4b Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/12110f4b Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/12110f4b Branch: refs/heads/stratos-4.1.x Commit: 12110f4b83b3f40a487808a386312137e167e5d7 Parents: b67418d Author: Thanuja <[email protected]> Authored: Wed Nov 11 15:28:57 2015 +0530 Committer: gayangunarathne <[email protected]> Committed: Thu Nov 12 15:07:27 2015 +0530 ---------------------------------------------------------------------- .../js/member-details-filter.js | 30 ++- .../metering-dashboard/ues-patch/README.md | 2 +- .../metering-dashboard/ues-patch/dashboard.jag | 130 +++++------- .../ues-patch/ues-dashboards.js | 211 ------------------- .../metering-dashboard/ues-patch/ues-gadgets.js | 175 +++++++++++++++ .../metering-dashboard/ues-patch/ues-pubsub.js | 20 +- 6 files changed, 247 insertions(+), 321 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/12110f4b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberDetailsFilter/Member_Details_Filter/js/member-details-filter.js ---------------------------------------------------------------------- diff --git a/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberDetailsFilter/Member_Details_Filter/js/member-details-filter.js b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberDetailsFilter/Member_Details_Filter/js/member-details-filter.js index bbc4312..6f36e4d 100644 --- a/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberDetailsFilter/Member_Details_Filter/js/member-details-filter.js +++ b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberDetailsFilter/Member_Details_Filter/js/member-details-filter.js @@ -24,24 +24,20 @@ var clusterId; $(document).ready(function () { loadApplication(); - setTimeout(function () { - if (applicationId != null) { - loadCluster(applicationId); - $('#' + window.frameElement.id).ready(function () { - $(this).contents().find('body').contents().find('#application-filter').val(applicationId); - publish(); - }); - } - }, 2000); + if (applicationId != null) { + loadCluster(applicationId); + $('#' + window.frameElement.id).ready(function () { + $(this).contents().find('body').contents().find('#application-filter').val(applicationId); + publish(); + }); + } - setTimeout(function () { - if (clusterId != null) { - $('#' + window.frameElement.id).ready(function () { - $(this).contents().find('body').contents().find('#cluster-filter').val(clusterId); - publish(); - }); - } - }, 3000); + if (clusterId != null) { + $('#' + window.frameElement.id).ready(function () { + $(this).contents().find('body').contents().find('#cluster-filter').val(clusterId); + publish(); + }); + } }); http://git-wip-us.apache.org/repos/asf/stratos/blob/12110f4b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/README.md ---------------------------------------------------------------------- diff --git a/extensions/das/modules/artifacts/metering-dashboard/ues-patch/README.md b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/README.md index 69e065c..2bafefa 100644 --- a/extensions/das/modules/artifacts/metering-dashboard/ues-patch/README.md +++ b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/README.md @@ -4,5 +4,5 @@ dashboard url and publish the values to gadgets. You can find the related UES product jira here: https://wso2.org/jira/browse/UES-582 Please follow below steps to apply the patch locally: -1. Copy 'ues-dashboard.js' and 'ues-pubsub.js' files to <DAS-HOME>/repository/deployment/server/jaggeryapps/portal/js/ folder. +1. Copy 'ues-gadgets.js' and 'ues-pubsub.js' files to <DAS-HOME>/repository/deployment/server/jaggeryapps/portal/js/ folder. 2. Copy 'dashboard.jag' file to <DAS-HOME>/repository/deployment/server/jaggeryapps/portal/theme/templates/ folder. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/12110f4b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/dashboard.jag ---------------------------------------------------------------------- diff --git a/extensions/das/modules/artifacts/metering-dashboard/ues-patch/dashboard.jag b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/dashboard.jag index 32e926c..a738418 100644 --- a/extensions/das/modules/artifacts/metering-dashboard/ues-patch/dashboard.jag +++ b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/dashboard.jag @@ -67,25 +67,18 @@ if (!user) { <div class="collapse navbar-collapse horizontal-bar"> <ul class="nav navbar-nav"> - <% if (dashboard.pages.length >= 2) { %> + <% if(dashboard.pages.length >= 2) { %> <li - <% - if (dashboard.landing === pageId) { %> + <% if(dashboard.landing === pageId) { %> class="active" - <% - } - %>> - <a href="<%=dbRoot%>?isAnonView=<%=isAnonView - %>"><%= - i18n.localize("home") - %></a> - </li> - <% -} %> + <% } %>> + <a href="<%=dbRoot%>?isAnonView=<%=isAnonView%>"><%= i18n.localize("home")%></a> + </li> + <% } %> <% pages.forEach(function (page) { - if (isAnonView || !user) { + if(isAnonView || !user) { if (page.isanon) { // Anonymous viewing. So render only anonymous pages links. renderPageLink(page); @@ -98,79 +91,53 @@ pages.forEach(function (page) { function renderPageLink(page) { if (dashboard.landing !== page.id) { %> <li - <% - if (page.id === pageId) { %> + <% if (page.id === pageId) { %> class="active" - <% - } - %>> - <a href="<%=dbRoot%><%=page.id%>?isAnonView=<%=isAnonView%>"> <%=page.title - %></a> - </li> - <% - } + <% } %>> + <a href="<%=dbRoot%><%=page.id%>?isAnonView=<%=isAnonView%>"> <%=page.title%></a> + </li> + <% } };%> </ul> <ul class="nav navbar-nav navbar-right"> <% if (user) { - if (user.isEditor) { - %> - <li> - <a class="ues-copy" href="<%=dbRoot - %>?editor=true"> - <span class="fw-stack"> - <i class="fw fw-ring fw-stack-2x"></i> - <i class="fw fw-settings fw-stack-1x"></i> - </span> - <%= - i18n.localize("edit.button") - %> - </a> - </li> - <% - } else { - %> - <li> - <a class="ues-copy" href="<%=dbRoot - %>?custom=true"> - <span class="fw-stack"> - <i class="fw fw-ring fw-stack-2x"></i> - <i class="fw fw-settings fw-stack-1x"></i> - </span> - <%= - i18n.localize("personalize") - %> - </a> - </li> - <% - } - %> - <li> - <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> - <%= - user ? user.username : "anon" - %> <span class="caret"></span> - </a> - <ul class="dropdown-menu" role="menu"> - <li><a href="<%=urlPrefix%>logout?destination=<%=dest - %>"> - <%= - i18n.localize("logout.lable") - %> - </a></li> - </ul> - </li> - <% -} else { - %> - <li><a href="<%=urlPrefix%>login-controller?destination=<%=dest - %>"> - <%= - i18n.localize("login.lable") - %> + if (user.isEditor) { %> + <li> + <a class="ues-copy" href="<%=dbRoot%>?editor=true"> + <span class="fw-stack"> + <i class="fw fw-ring fw-stack-2x"></i> + <i class="fw fw-settings fw-stack-1x"></i> + </span> + <%= i18n.localize("edit.button")%> + </a> + </li> + <% } else + {%> + <li> + <a class="ues-copy" href="<%=dbRoot%>?custom=true"> + <span class="fw-stack"> + <i class="fw fw-ring fw-stack-2x"></i> + <i class="fw fw-settings fw-stack-1x"></i> + </span> + <%= i18n.localize("personalize")%> + </a> + </li> + <% } %> + <li> + <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> + <%= user? user.username : "anon" %> <span class="caret"></span> + </a> + <ul class="dropdown-menu" role="menu"> + <li><a href="<%=urlPrefix%>logout?destination=<%=dest%>"> + <%= i18n.localize("logout.lable")%> </a></li> - <% -} %> + </ul> + </li> + <% } else { %> + <li><a href="<%=urlPrefix%>login-controller?destination=<%=dest%>"> + <%= i18n.localize("login.lable")%> + </a></li> + <% } %> </ul> </div> <!--/.nav-collapse --> @@ -259,6 +226,7 @@ function renderPageLink(page) { <% include('/controllers/includes/dashboard-scripts.jag'); %> <script src="<%=urlPrefix%>js/ues-gadgets.js"></script> <script src="<%=urlPrefix%>js/ues-dashboards.js"></script> +<script src="<%=urlPrefix%>js/ues-pubsub.js"></script> <script src="<%=urlPrefix%>extensions/components/gadget/index.js"></script> <script src="<%=urlPrefix%>extensions/components/widget/index.js"></script> <script src="<%=urlPrefix%>extensions/uris/local/index.js"></script> http://git-wip-us.apache.org/repos/asf/stratos/blob/12110f4b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-dashboards.js ---------------------------------------------------------------------- diff --git a/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-dashboards.js b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-dashboards.js deleted file mode 100644 index 69fd4ed..0000000 --- a/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-dashboards.js +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -(function () { - - var findPlugin = function (type) { - var plugin = ues.plugins.components[type]; - if (!plugin) { - throw 'ues dashboard plugin for ' + type + ' cannot be found'; - } - return plugin; - }; - - - var createComponent = function (container, component, done) { - var type = component.content.type; - var plugin = findPlugin(type); - var sandboxId = component.id; - //(component.viewOption? component.id+"_full" : component.id ); - var sandbox = $('<div id="' + sandboxId + '" data-component-id="' + component.id + '" class="ues-component"></div>'); - sandbox.appendTo(container); - plugin.create(sandbox, component, ues.hub, done); - }; - - var updateComponent = function (component, done) { - var plugin = findPlugin(component.content.type); - var container = $('#' + component.id); - plugin.update(container, component, ues.hub, done); - }; - - var destroyComponent = function (component, done) { - var plugin = findPlugin(component.content.type); - var container = $('#' + component.id); - plugin.destroy(container, component, ues.hub, done); - }; - - var componentId = function (clientId) { - return clientId.split('-').pop(); - }; - - var wirings; - - var publishForClient = ues.hub.publishForClient; - ues.hub.publishForClient = function (container, topic, data) { - console.log('publishing data container:%s, topic:%s, data:%j', container.getClientID(), topic, data); - var clientId = componentId(container.getClientID()); - var channels = wirings[clientId + '.' + topic]; - if (!channels) { - return; - } - channels.forEach(function (channel) { - publishForClient.apply(ues.hub, [container, channel, data]); - }); - }; - - //overriding publish method - var publish = ues.hub.publish; - ues.hub.publish = function (topic, data){ - $(".container").find('.ues-component').each(function () { - var id = $(this).attr('id'); - var channel = id + "." + topic; - console.log(channel); - publish.apply(ues.hub, [channel, data]); - }); - }; - - var wires = function (page, pageType) { - var content = page.content[pageType]; - var area; - var blocks; - var wirez = {}; - - var wire = function (wirez, id, listeners) { - var event; - var listener; - for (event in listeners) { - if (listeners.hasOwnProperty(event)) { - listener = listeners[event]; - if (!listener.on) { - continue; - } - listener.on.forEach(function (notifier) { - var channel = notifier.from + '.' + notifier.event; - var wire = wirez[channel] || (wirez[channel] = []); - wire.push(id + '.' + event); - }); - } - } - }; - - for (area in content) { - if (content.hasOwnProperty(area)) { - blocks = content[area]; - blocks.forEach(function (block) { - var listeners = block.content.listen; - if (!listeners) { - return; - } - wire(wirez, block.id, listeners); - }); - } - } - console.log(wirez); - return wirez; - }; - - var setDocumentTitle = function (dashboard, page) { - document.title = dashboard.title + ' | ' + page.title; - }; - - var renderPage = function (element, dashboard, page, pageType, done) { - setDocumentTitle(dashboard, page); - wirings = wires(page, pageType); - var container; - var area; - var layout = $(page.layout.content); - var content = page.content[pageType]; - element.html(layout); - for (area in content) { - if (content.hasOwnProperty(area)) { - container = $('#' + area, layout); - content[area].forEach(function (options) { - createComponent(container, options, function (err) { - if (err) { - console.error(err); - } - }); - }); - } - } - if (!done) { - return; - } - done(); - }; - - var findPage = function (dashboard, id) { - var i; - var page; - var pages = dashboard.pages; - var length = pages.length; - for (i = 0; i < length; i++) { - page = pages[i]; - if (page.id === id) { - return page; - } - } - }; - - var renderDashboard = function (element, dashboard, name, pageType, done) { - name = name || dashboard.landing; - var page = findPage(dashboard, name); - if (!page) { - throw 'requested page : ' + name + ' cannot be found'; - } - renderPage(element, dashboard, page, pageType, done); - }; - - var rewireDashboard = function (page, pageType) { - wirings = wires(page, pageType); - }; - - var resolveURI = function (uri) { - var index = uri.indexOf('://'); - var scheme = uri.substring(0, index); - var uriPlugin = ues.plugins.uris[scheme]; - if (!uriPlugin) { - return uri; - } - var path = uri.substring(index + 3); - return uriPlugin(path); - }; - - ues.components = { - create: createComponent, - update: updateComponent, - destroy: destroyComponent - }; - - ues.dashboards = { - render: renderDashboard, - rewire: rewireDashboard, - findPage: findPage, - resolveURI: resolveURI - }; - - ues.assets = {}; - - ues.plugins = { - assets: {}, - components: {}, - uris: {} - }; - -}()); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/12110f4b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-gadgets.js ---------------------------------------------------------------------- diff --git a/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-gadgets.js b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-gadgets.js new file mode 100644 index 0000000..11d64bc --- /dev/null +++ b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-gadgets.js @@ -0,0 +1,175 @@ +(function () { + var registry = {}; + var username = null; + //search overridden configs through ues.configs object + var configs = function (configs, args) { + var find = function (o, args) { + var pop = args.shift(); + if (typeof o !== 'object' || !o[pop]) { + return null; + } + if (!args.length) { + return o[pop]; + } + return find(o[pop], args); + }; + return find(configs, args); + }; + + var extend = function (options, extended) { + var name; + for (name in extended) { + if (extended.hasOwnProperty(name)) { + options[name] = extended[name]; + } + } + }; + + var merge = function (options) { + var args = Array.prototype.slice.call(arguments, 1); + var extended = configs(ues.configs, args); + if (!extended) { + return options; + } + return extended ? extend(options, extended) : options; + }; + + var params = {}; + params[osapi.container.ContainerConfig.RENDER_DEBUG] = true; + merge(params, 'container'); + + //opensocial container for the DOM + var container = new osapi.container.Container(params); + + //Gadget renderer + var render = function (sandbox, url, prefs, params, done) { + var options = {}; + options[osapi.container.RenderParam.WIDTH] = '100%'; + options[osapi.container.RenderParam.USER_PREFS] = prefs; + options[osapi.container.RenderParam.HEIGHT] = sandbox.height(); + extend(options, params); + sandbox = (sandbox instanceof jQuery) ? sandbox : $(sandbox); + if (!sandbox.length) { + return; + } + var site = container.newGadgetSite(sandbox[0]); + container.navigateGadget(site, url, {}, options, function (metadata) { + if (metadata.error) { + done ? done(metadata.error) : console.log(metadata.error); + return; + } + registry[site.getId()] = site; + if (done) { + done(false, metadata); + } + }); + return site; + }; + + var preload = function (url, done) { + container.preloadGadget(url, function (data) { + var metadata = data[url]; + done(metadata.error, metadata); + }); + }; + + var remove = function (id) { + container.closeGadget(registry[id]); + delete registry[id]; + }; + + //Initializing OpenAjax ManagedHub + var hub = new OpenAjax.hub.ManagedHub({ + onSubscribe: function (topic, container) { + readRequestParam(); + if(topic.indexOf("token-channel") !=-1){ + if(username){ + ues.hub.publish("token-channel", username); + }else{ + + jQuery.ajax({ + url: '/portal/apis/user', + type: 'get', + dataType: "json", + success: function (data) { + username = data.username; + ues.hub.publish("token-channel", username); + }, + error: function (msg) { + ues.hub.publish("token-channel", null); + } + }); + } + } + var fn = configs(ues.configs, ['hub', 'subscribe']); + return fn ? fn(topic, container) : true; + }, + onUnsubscribe: function (topic, container) { + var fn = configs(ues.configs, ['hub', 'unsubscribe']); + return fn ? fn(topic, container) : true; + }, + onPublish: function (topic, data, from, to) { + /*var clientId = to.getClientID(); + var sub = subscriptions[clientId]; + var container = ues.hub.getContainer(clientId); + container.sendToClient(topic, data, sub.conSubId);*/ + var fn = configs(ues.configs, ['hub', 'publish']); + return fn ? fn(topic, data, from, to) : true; + } + }); + + var inlineContainer = new OpenAjax.hub.InlineContainer(hub, 'ues', { + Container: { + onSecurityAlert: function (source, alertType) { + //Handle client-side security alerts + }, + onConnect: function (container) { + //Called when client connects + }, + onDisconnect: function (container) { + //Called when client disconnects + } + } + } + ); + + var client = new OpenAjax.hub.InlineHubClient({ + HubClient: { + onSecurityAlert: function (source, alertType) { + } + }, + InlineHubClient: { + container: inlineContainer + } + }); + + // Linking ManagedHub with opensocial pubsub2 + gadgets.pubsub2router.init({ + hub: hub + }); + /* + var Hub = function (client) { + + }; + + Hub.prototype.on = function () { + + }; + + Hub.prototype.once = function () { + + }; + + Hub.prototype.off = function () { + + };*/ + + ues.hub = hub; + ues.container = container; + ues.client = client; + ues.gadgets = { + render: render, + preload: preload, + remove: remove + }; +}()); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/12110f4b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-pubsub.js ---------------------------------------------------------------------- diff --git a/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-pubsub.js b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-pubsub.js index 373531d..9f70f6c 100644 --- a/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-pubsub.js +++ b/extensions/das/modules/artifacts/metering-dashboard/ues-patch/ues-pubsub.js @@ -17,23 +17,21 @@ * under the License. * */ -var applicationId; -var clusterId; + var vars; -$(document).ready(function () { + +function readRequestParam(){ var query = window.location.search.substring(1); vars = query.split("&"); - applicationId = getRequestParam('applicationId'); - clusterId = getRequestParam('clusterId'); + var applicationId = getRequestParam('applicationId'); + var clusterId = getRequestParam('clusterId'); - setTimeout(function () { - var data = {applicationId: applicationId, clusterId: clusterId}; - console.log("Publishing request params: " + JSON.stringify(data)); - ues.hub.publish("request-params",data); - }, 2000); + var data = {applicationId: applicationId, clusterId: clusterId}; + console.log("Publishing request params: " + JSON.stringify(data)); + ues.hub.publish("request-params",data); +} -}); function getRequestParam(variable) { for (var i = 0; i < vars.length; i++) {
