Providing Poor man's dashboard app communication - javascript

I realize you are coming up with a way for panels to communicate. Until that time, I was thinking I could get some basic communication going with a preference object.
But how do I find a unique ID for the dashboard where an app resides?
In case there might be a better solution than sharing info via a preference object, let me describe the specific problem we want to solve: Certain projects within our project structure represent "programs" for which we want to display a "metrics dashboard"-- that dashboard would consist of multiple apps on a shared dashboard. But programs are not at consistent levels in the rally project hierarchy, and we only have about four programs though we have many many rally projects.
Because of this, I'd like this code metrics dashboard to be one page in Rally, which can easily switch between the various programs we have. I would prefer not to use the project hierarchy to do this, because we have a lot of projects, and its time consuming and tricky to find and select the programs.

I hacked at the sample to create an example of an app that can pass events between two panels.
This is very unsupported at this time and we reserve the right to break it whenever we want without any warning.
That being said you can see the current unsupported way to get an Apps ID and if you make two copies of this App you can see in your console the results of the Apps communicating on the global Rally message bus.
You can find the gist of it here
<!DOCTYPE html>
<html>
<head>
<title>My Custom App</title>
<!--Include SDK-->
<script type="text/javascript" src="/apps/2.0p/sdk.js"></script>
<!--App code-->
<script type="text/javascript">
Rally.onReady(function() {
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
mixins:['Rally.Messageable'],
launch: function() {
var brokenInTheFutureIdThatWillWorkForNow = Ext.Object.fromQueryString(window.location.href);
window.parent.Rally.Messages.subscribe("test",function(){console.error(brokenInTheFutureIdThatWillWorkForNow.panelOid,arguments);});
window.parent.Rally.Messages.publish("test",brokenInTheFutureIdThatWillWorkForNow.panelOid);
//Write app code here
}
});
Rally.launchApp('CustomApp', {
name: 'My Custom App'
});
});
</script>
<!--App styles-->
<style type="text/css">
.app {
/* Add app styles here */
}
</style>
</head>
<body class="myApp">
</body>
</html>

Related

How to resolve type name conflict from two separate Javascript libraries?

Let me start by saying that I'm primarily a C# programmer who only extremely rarely ventures into JavaScript.
I can write myself some JS code as long as its mostly plain. I can handle jQuery and the odd self-sufficient 3rd-party library, but couldn't code myself out of a wet paper bag when React, Angular, Bootstrap and others enter the scene. I'm also not used to using npm or any other similar package manager.
It was never really my job nor interest, so I never went there. Whenever I code some JS, I reference the required JS files in my <script> tags and then use them as directly as possible.
I'm currently creating a very simple proof of concept web app which will have its client parts rebuilt by competent people sooner or later. But in the mean time I have to provide the bare-bones functionality that will serve as a rough guideline for the next team to take over, whenever that might be.
I've picked two libraries that each seem easy to use and get the job done, when used separately. But when I try to use them together on the same page, I run into a problem: they both use the same name for their main type, and I can't seem to disambiguate between them.
These are the libraries:
JSON Editor
JSON Schema Form Builder
They both declare a type named JSONEditor, which I can use as long as I don't reference both of the libraries at once.
So far I've tried to solve this by using modules and import-ing the type using different names, but it didn't work... I got a bunch of errors in the console about "import not found" and "e is not defined", which makes me think I'm tackling this wrong.
How would I solve this using plain JS if possible?
UPDATE: As suggested, I'm providing a minimal example that demonstrates my use:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test Page</title>
<link href="/lib/jsoneditor/jsoneditor.min.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="container">
<div id="editor" style="width: 300px; height: 200px;"></div>
<div id="form"></div>
</div>
<!--library 1: https://github.com/josdejong/jsoneditor -->
<script src="/lib/jsoneditor/jsoneditor.min.js"></script>
<!--library 2: https://github.com/jdorn/json-editor -->
<script src="/lib/jsonform/jsonform.min.js"></script>
<script>
// Library 1: The JSON code editor.
var editor = new JSONEditor(document.getElementById("editor"), { mode: "code" });
// Library 2: The form builder.
var form = new JSONEditor(document.getElementById("form"), {
ajax: true,
schema: {
$ref: "/api/describe/service/test"
}
});
</script>
</body>
</html>
If I comment out the use of one library (whichever), the other works as expected and the content is displayed at the respective target <div>. But if I try both at once, as shown above, nothing is displayed, and the following error is output to console:
Uncaught TypeError: t is undefined
This happens at the var editor = new JSONEditor line, which makes me think that the type from the second library overwrites the first and causes the problem.
This is understandable to me and isn't the issue per-se. The issue is that I don't know how to import the two JSONEditor types so that they can be referenced separately.
The maintainer of the code editor (JSON Editor, not JSON Schema Form Builder) has addressed and closed an issue about exactly this in the past: https://github.com/josdejong/jsoneditor/issues/270
His recommended solution is something like the following:
<script src="assets/jsoneditor/dist/jsoneditor.min.js"></script>
<script>
var JSONEditorA = JSONEditor;
</script>
<script src="assets/json-editor/dist/jsoneditor.min.js"></script>
<script>
var JSONEditorB = JSONEditor;
</script>
If you must use script tags this is probably the way to go.

Dojo: Swapping two different views in a Single Page Application

I´m new to dojo and I´m want to do the following:
Pretend you have a single page application but you have two views, which are built up totally different. One view is e.g. a startpage which would just fill the Bordercontainer-center. The second view would rather look like a standard webapp, with a header in the Bordercontainer-top, a menu in Bordercontainer-left and some content in Bordercontainer-center.
If the index.html (single page app) is now called I want the startpage to appeare first. There should be an onclick-event in it. With this event the views should change. This means the startpage disappears and the second webapp-view is shown.
What would be the best way to implement this?
I thought of using two Bordercontainers.
The first Bordercontainer would contain the startpage in the region center.
The second Bordercontainer would contain the webapp-view (top, left, center).
Would it now be possible to swap the center region from the frist Bordercontainer in a way that the startpage get´s swaped with the second Bordercontainer? Would this be a way how to solve my approach?
If yes I would need some kind of controller which would swap the view.
Could I solve this with using dojo.wire?
Or is there a straight forward approach in dojo, which I have not found yet?
If there is a small example or tutorial out there, it would be great to receive a link to it.
Thx for every hint.
You should take a look at dojox/mobile (http://dojotoolkit.org/reference-guide/1.10/dojox/mobile.html) it has support for what you are trying to do. You could also look at dojox/app (http://dojotoolkit.org/reference-guide/1.10/dojox/app.html or http://dojotoolkit.org/documentation/tutorials/1.9/dojox_app/contactsList/) to see if that gives you what you need.
I tried the following code:
require([
"dijit/form/Button"
], function() {
changeView = function(idShow, idHide) {
var showView = dojo.byId(idShow);
var showHide = dojo.byId(idHide);
if (showView.style.display == 'block') {
showView.style.display = 'none';
showHide.style.display = 'block';
} else {
showView.style.display = 'block';
showHide.style.display = 'none';
}
};
});
#view1 {
display: block;
}
#view2 {
display: none;
}
<html>
<head>
<title>Change View</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/resources/dojo.css">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dijit/themes/tundra/tundra.css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js" data-dojo-config="isDebug: true, parseOnLoad: true"></script>
</head>
<body class="tundra">
<div id="view1">
View1
<br>
<button dojoType="Button" widgetId="view1Button" onClick="changeView('view2', 'view1');">Change to View2</button>
</div>
<div id="view2">
View2
<br>
<button dojoType="Button" widgetId="view2Button" onClick="changeView('view1', 'view2');">Change to View1</button>
</div>
</body>
</html>
This lets me change the view with onclick and css and a little js.
I think this is one of the various ways you mentioned, for solving my approach. But what I think I´m missing now is to combine my function changeView with dojo - somehow.
What would be the right way to combine dojo and the function changeView now?
Would I write a dojo modul with a define and then work with it in my html and calling it with require?
Or generally.. for a dojo-beginner.
If I need javascript code for my app, is there a straight forward way to combine this with dojo?
e.g. with any kind of approuch
Look an see what dojo has to solve the approch
Write JS code, if there is no suitable dojo modul/function yet
Think about seperating the JS code it into modules
Write the modules in dojo with define
Use the modules in the app by calling them with require
Would this be a proper way for programming in dojo?
The question is more a general "howto glue JS and dojo together" to write webapps and use the advantages of dojo.
Thx in advance.

Inject script for i18n in Angular app

I would like to use i18n and i10n in my Angular app.
If I understood correctly I can inject a script into my index.html and the changes regarding the language will change on the fly. I tested it and it works when I added manually the script and refresh the page.
Unfortunately, I am trying to inject the script for the right language on the fly.
I created a button and I want to add Portuguese language script on the click button.
app.controller('appController', ['$scope', '$route', 'UserTopBarWidget',
function($scope, $route, UserTopBarWidgetService){
$scope.topBarWidget = UserTopBarWidget;
$scope.topBarWidget.loadTopBarWidget();
}
}]);
In this file I just load the service I created called UserTopBarWidget.
The UserTopBarWidget:
app.service('UserTopBarWidgetService', function($http){
this.loadTopBarWidget = function(){
//loading something
};
this.loadPortugueseLanguage = function(){
var locale = "pt-pt";
$.getScript("https://code.angularjs.org/1.2.16/i18n/angular-locale_" + locale + ".js");
}
});
I have a page html called index.html and inject to it my html files:
index.html:
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="../common/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="../common/css/style.css" />
<title></title>
</head>
<body ng-controller="AppCtrl">
<div id="container" ng-view></div>
</body>
</html>
The injected html:
<button type="button" id="searchButton" class="btn btn-default" ng-click="topBarWidget.loadPortugueseLanguage()">Portugese</button>
<h2>{{date | date: 'fullDate' }}</h2>
<h2>{{money | currency}}</h2>
The answer I get :
Tuesday, June 10, 2014
$500.00
I would like to see it in Portuguese.
What am I doing wrong?
Question
There is no way in pure angular to dynamically change locale so far, you can only do it on bootstrap level but there is a few projects that implement this functionality. This one is particularly good IMHO
https://github.com/lgalfaso/angular-dynamic-locale
There are two possible solutions to your problem really.
One is to use angular-dynamic-locale as #maurycy already explained. It's not the cleanest solution I can think of, but it's better than nothing.
The other possible solution is to create your own using other specialized i18n library like iLib for example.
Why would you ever want to do that?
Well, built-in AngularJS i18n routines does not allow for handling other calendars, time zones and formatting percents. These are serious drawbacks. The fact, that you cannot override a Formatting Locale based on user profile (or you can, but forgot about web site caching) is another.
I recommend using custom iLib-based solution (I used to recommend Globalize but after recent changes it seems a bit useless) combined with angular-translate for User Interface translation and built-in angular-locale for handling plural forms (at the time of writing angular-translate does not handle it particularly well).

Trying to add Qooxdoo widgets in html page

As a proof of concept I would like to show the some Qooxdoo widgets (which i find pretty nice) in a very simple index.html file.
Here I try to show a button :
<head>
<title>Title</title>
<script type="text/javascript" src="http://demo.qooxdoo.org/3.5/framework/q-3.5.min.js"></script>
<script>
var button = new qx.ui.form.Button("Hello...");
this.getRoot().add(button, {left: 30, top: 20});
</script>
</head>
If I run the above I get this :
Uncaught ReferenceError: qx is not defined
Is my library link correct? Or is it even possible to link qooxdoo javascript in a HTML file? We already have a large established javascript application, and we would like to just drop in qooxdoo widgets that we like. Not sure if that is possible though.
You are including the qx.Website library and try to use qx.Desktop widgets. That ain't gonna work. Either you choose qx.Desktop and use the inline app approach [1] or you use the qx.Website widgets [2].
[1] http://manual.qooxdoo.org/current/pages/development/skeletons.html#inline
[2] http://demo.qooxdoo.org/devel/website-api/index.html#Accordion

In Rally: Can I map custom task states to existing Task states in a Rally Task Board (similar to Kanban for user stories)?

What would it take to create a TASK card board with mappable states like Rally's existing Kanban board supports.
I would like to add one or two custom task states: like "ready to merge" and "unit test complete". The existing task board doesn't support this feature.
I played with the card board code using the Rally 2.0 SDK (preview) and was able to quickly display tasks in custom state columns, but the mapping is where I got lost, as I am unsure how to map these custom states to the default Defined/In-Process/Completed states. I was curious if you had any pointers as to what triggers or components to use for state mapping.
I know there can be some opposition to additional task states, but in some engineering firms, where coding is closely tied to tasks, additional states can make sense at the task level.
First let me give you some caveats.
Your mappings will only work for this specific board and any other view. So the changes can get out of sync fairly easily.
Here is some code that should do what you are expecting. You can get gist for it here
https://gist.github.com/2926610
<!DOCTYPE html>
<html>
<head>
<title>My Custom App</title>
<!--Include SDK-->
<script type="text/javascript" src="https://rally1.rallydev.com/apps/2.0p/sdk.js"></script>
<!--App code-->
<script type="text/javascript">
Rally.onReady(function() {
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
mappedToField:"State",
mappedFromField:"Mapme",
fieldNameMap:{
a:"Defined",
b:"Defined",
c:"In-Progress",
d:"In-Progress",
e:"Completed"
},
launch: function() {
this.add({
xtype:'rallycardboard',
types:['task'],
attribute: this.mappedFromField,
listeners:{
beforecarddroppedsave:function(cardboard, card) {
//map the new state from on this card to the new state
var newState = this.fieldNameMap[card.record.get(this.mappedFromField)];
card.record.set(this.mappedToField, newState);
},
scope:this
}
});
}
});
Rally.launchApp('CustomApp', {
name: 'My Custom App'
});
});
</script>
</head>
<body class="myApp">
</body>
</html>

Categories

Resources