Import statements in ES2015 - ecmascript-6

Are there any ways I could execute the import inline? See example below:
import $ from 'jquery';
import dt from 'datatables.net-bs';
import dtbuttons from 'datatables.net-buttons-bs';
import csv from 'datatables.net-buttons/js/buttons.html5.js';
// Attach the plugin - Could this be done inline in the import statments above?
dt(window,$);
dtbuttons(window,$);
csv(window,$);
Larsi

It is not possible with import statement. You can do it with different module loader. For example it is possible with node's built-in require:
import $ from 'jquery';
require('datatables.net-bs')(window, $);
require('datatables.net-buttons-bs')(window,$);
require('datatables.net-buttons/js/buttons.html5.js')(window,$);

Related

Convert plain text / wiki syntax to HTML with Jira ScriptRunner (show bullet points, checkmark smileys, etc.)

I am trying to retrieve the text of the most recent comment I typed in a JIRA issue page, here is a screenshot of the most recent comment I typed:
I am using this code in the Jira script runner to retrieve the last comment I have typed in:
import com.atlassian.jira.component.ComponentAccessor
import java.text.SimpleDateFormat
import com.opensymphony.util.TextUtils
import com.atlassian.jira.issue.comments.*
import org.w3c.dom.*;
import javax.xml.parsers.*;
import groovy.xml.*
import grrovy.util.*;
import org.xml.sax.InputSource;
import java.io.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
def commentManager = ComponentAccessor.getCommentManager()
Comment comment = commentManager.getLastComment (issue)
if(comment != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MMM/yy HH:mm", Locale.ENGLISH)
def body = comment.body //.replaceAll("[\r\n]+","\n")
body= """<div style="max-height:100px; overflow:auto;" title="${comment.authorFullName} added last comment - ${dateFormat.format(comment.created)}">
<span style="white-space: pre-wrap;">${TextUtils.htmlEncode(body)}</span>
</div>"""
return body
}
The output of the code above is the following:
I would like the output to be displayed as in its original format meaning, I would like the bullet points to appear, the smiley to appear and the green checkmark to appear as well. I don't want to see the stars and the code color and the smiley abbreviation :) I would like the output to look like the following:
How can I fix this?
You need to render wiki-syntax source to HTML output and use existing wiki renderer.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.RendererManager
import com.atlassian.jira.issue.fields.renderer.JiraRendererPlugin
import com.atlassian.jira.issue.fields.renderer.IssueRenderContext
RendererManager rendererManager = ComponentAccessor.getComponentOfType(RendererManager.class);
JiraRendererPlugin renderer = rendererManager.getRendererForType("atlassian-wiki-renderer");
String lastComment = "* 1\n* 2\n* 3:)\n* {color:#FF0000}(/){color}"
return renderer.render(lastComment, null)

Initialization Error for Junit in Eclipse

I have configured Cucumber Maven project and getting Initialization error while executing my RunTest.java file:
package annotation;
import org.junit.runner.RunWith;
import cucumber.junit.Cucumber;
#RunWith(Cucumber.class)
#Cucumber.Options(format = {"pretty", "html:target/cucumber"})
public class RunTest { }
I had included hamcrest-library files too but still I don't know what I have left out.
Use the below code instead...
package annotation;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(plugin = { "pretty", "html:target/cucumber" })
public class RunTest {
}
Two import statements were wrong. Cucumber.Options was not correct it is CucumberOptions. format is now deprecated, use plugin.

'xdom is not defined' error within autopulous-xdom2jso

I have imported below packages in my service, which I use for SOAP-API processing.
"autopulous-xdom": "~0.0.12"
"autopulous-xdom2jso": "^0.0.12"
I am trying to use these with below lines at top of my service.ts
import 'autopulous-xdom/xdom.js';
import 'autopulous-xdom2jso/xdom2jso.js';
import convert = xdom2jso.convert;
import {Injectable} from '#angular/core';
#Injectable()
export class SoapService {
constructor() {}
}
I get no errors on compiling and building. But while running the application in browser, I get below error.
Has anyone worked with xdom2jso and xdom? Please help.
I got no responses and all I could do was fork and raise a PR myself into autopulous-xdom2jso.
See my fix here: https://github.com/autopulous/xdom2jso/pull/2

How to troubleshoot es6 module dependencies?

I am developing a React & Reflux app, which is bundled by webpack with babel-loader (v6), and I am experiencing es6 modules dependencies issues
For example, I have a component that use the reflux .connect() mixin :
import MyStore from '../stores/my-store';
const Component = React.createClass({
mixins: [Reflux.connect(MyStore)]
});
When I import all modules individually in each file like this, everything's fine.
I then tried to improve my code by using deconstructed import statements :
...in a component :
//import One from '../js/one';
//import Two from '../js/two';
//import Three from '../js/three';
import { One, Two, Three } from '../js'; // Instead
...and in js/index.js :
import One from './one';
import Two from './two';
import Three from './three';
export { One, Two, Three };
App source code files are more concise using the above technique, because I can import all components in one import line.
But when I use this, some dependencies end up beeing undefined when I use them
If I use the same updated example...
//import MyStore from '../stores/my-store';
import { MyStore } from '../stores'; // Instead
const Component = React.createClass({
mixins: [Reflux.connect(MyStore)]
});
...MyStore parameter ends up undefined in Reflux.connect method.
I tried to troubleshoot in the debugger, but I'm not really aware of what's going on with the __webpack_require__(xxx) statements in the generated bundle. There must be a circular dependency that babel-loader or webpack require could not figure out when there are the index.js files re-exporting individual modules.
Do you know any tool that can help me figure this out? I tried madge but it does not work with es6 modules, and I could not find anything that would tell me where anything is wrong
In order to get extended info about build, run:
webpack --profile --display-modules --display-reasons
It will give you bunch of information for optimisation/profiling.
import statement is used to import functions, objects or primitives that have been exported from an external module.
As per MDN doc, you can import the Modules not the directory.
import name from "module-name";
import * as name from "module-name";
import { member } from "module-name";
import { member as alias } from "module-name";
import { member1 , member2 } from "module-name";
import { member1 , member2 as alias2 , [...] } from "module-name";
import defaultMember, { member [ , [...] ] } from "module-name";
import defaultMember, * as alias from "module-name";
import defaultMember from "module-name";
import "module-name";
Reference URL:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
http://es6-features.org/#ValueExportImport
https://github.com/lukehoban/es6features#modules
http://www.2ality.com/2014/09/es6-modules-final.html
As a workaround keep one file as base.js and include all your 3 files.

convert criteria object to list in mysql db

When i am using oracle database the following query is executed perfectly in hibernate.But i am trying to using mysql db means it doesn't work it throws an following Exception "Source Not Found Exception " in the detail of 'source attachment does not contain the source for the file mysqlIO.class'.
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.Criterion;
import com.hibernatehelper.HibernatePlugin;
import com.cir.hibernatebean.CIRMTradeCopiesSlab;
Criteria cr = sesInsert.createCriteria(CIRMTradeCopiesSlab.class);
//cr.add(Restrictions.eq("mtcsbrncode","MDS"));
Criterion criterion = Restrictions.eq("mtcsbrncode", "MDS");
cr.add(criterion);
List AgentRecList=cr.list();