Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@fils /iodputil.dart
Last active Dec 21, 2015

Working on Dart and polymer via http calls
library iodputil;
import 'dart:html';
import "dart:json";
class iodputil {
String encodeComponent(String component) {
if (component == null) return component;
return component.replaceAll(':', '%3A')
.replaceAll('/', '%2F')
.replaceAll('?', '%3F')
.replaceAll('=', '%3D')
.replaceAll('&', '%26')
.replaceAll(' ', '%20')
.replaceAll('}', '%7D')
.replaceAll('{', '%7B')
.replaceAll('#', '%23')
.replaceAll('(', '%28')
.replaceAll(')', '%29');
<!DOCTYPE html>
<link rel="import" href="xjanusleg.html">
<h5>Test of facet call 2</h5>
<div class="container">
<template id="leg_template" bind>
<janus-leg id="janus_leg"></janus-leg>
<script type="application/dart" src="select_app.dart"></script>
<!-- for this next line to work, your pubspec.yaml file must have a dependency on 'browser' -->
<script src="packages/polymer/boot.js"></script>
import 'dart:html';
import 'package:mdv/mdv.dart' as mdv;
import 'package:fancy_syntax/syntax.dart';
import 'package:observe/observe.dart';
main() {
// mdv.initialize();
//TemplateElement.syntax['fancy'] = new FancySyntax();
var template = query('#leg_template');
template.bindingDelegate = new FancySyntax();
//query("#leg_template").fruits = ['apples', 'oranges', 'pears'];
import 'dart:html';
import 'dart:json' as json;
import 'package:polymer/polymer.dart';
import './iodputil.dart';
class JanusLegComponent extends PolymerElement with ObservableMixin {
@observable String serverResponse = 'Calling server';
@observable List legs = ['apples', 'oranges', 'pears'];
HttpRequest request;
// void init() {
// query('#fruitlist').model = fruits;
// List fruits = toObservable([]);
// query('#fruitlist').model = fruits;
// fruits = ['apples', 'oranges', 'pears'];
// }
void onUpdate() {
iodputil iou = new iodputil();
String k1 = null;
k1 = iou.encodeComponent("""
PREFIX qb: <>
PREFIX iodp: <>
PREFIX janus: <>
PREFIX sdmx-dimension: <>
SELECT DISTINCT ?leg count(?slice) as ?count
?slice qb:sliceStructure ?sliceKey .
?sliceKey iodp:leg ?leg .
var callURl = "$k1";
request.onReadyStateChange.listen(onData);'GET', callURl);
void onData(_) {
if (request.readyState == HttpRequest.DONE &&
request.status == 200) {
// Data saved OK.
serverResponse = 'Server Sez: ' + request.responseText;
} else if (request.readyState == HttpRequest.DONE &&
request.status == 0) {
// Status is 0...most likely the server isn't running.
serverResponse = 'No server';
<!DOCTYPE html>
<polymer-element name="janus-leg" attributes="legs">
<p>The facet: {{ serverResponse }}</p>
<select style="height:200px;width:200px" bind-value="legs" id="janusqueryitems" multiple="multiple">
<template id="leg" repeat>
<script type="application/dart" src="xjanusleg.dart"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.