+
Error during the deserialization of {{data}} as {{contentType}}
`,
+ directives: [ALFRESCO_DATATABLE_DIRECTIVES]
+})
+export class WebscriptComponent {
+
+ @Input()
+ scriptPath: string;
+
+ @Input()
+ scriptArgs: any;
+
+ @Input()
+ contextRoot: string = 'alfresco';
+
+ @Input()
+ servicePath: string = 'service';
+
+ @Input()
+ contentType: string = 'TEXT';
+
+ data: any = undefined;
+
+ show: boolean = false;
+
+ /**
+ * Constructor
+ * @param auth
+ */
+ constructor(public authService: AlfrescoAuthenticationService) {
+
+ }
+
+ ngOnChanges(changes) {
+ this.clean();
+
+ return new Promise((resolve, reject) => {
+ this.authService.getAlfrescoApi().webScript.executeWebScript('GET', this.scriptPath, this.scriptArgs, this.contextRoot, this.servicePath).then((data) => {
+ if (this.contentType === 'JSON') {
+ this.show = this.showDataAsJSON(data);
+ } else if (this.contentType === 'DATATABLE') {
+ this.show = this.showDataAsDataTable(data);
+ } else {
+ this.show = this.showDataAsHTML(data);
+ }
+ resolve();
+ }, function (error) {
+ console.log('Error' + error);
+ reject();
+ });
+ });
+ }
+
+ /**
+ * Parserize and show the data id data is a JSON
+ *
+ * @param data
+ *
+ * @retutns boolean true if the component is able to Show the data as JSON
+ */
+ showDataAsJSON(data: any) {
+ let jsonShow = true;
+ try {
+ this.data = JSON.stringify(data);
+ let wrapper = document.getElementById('webscript-data');
+ wrapper.innerHTML = this.data;
+ } catch (e) {
+ jsonShow = false;
+ }
+
+ return jsonShow;
+ }
+
+ /**
+ * Parserize and show the data id data is a html/xml
+ *
+ * @param data
+ *
+ * @retutns boolean true if the component is able to Show the data as html/xml
+ */
+ showDataAsHTML(data: any) {
+ let htmlShow = false;
+ let domParser = new DOMParser();
+
+ if (domParser.parseFromString(data, 'text/xml')) {
+ let wrapper = document.getElementById('webscript-data');
+ wrapper.innerHTML = data;
+ this.data = data;
+ htmlShow = true;
+ }
+
+ return htmlShow;
+ }
+
+ /**
+ * show the data in a ng2-alfresco-datatable
+ *
+ * @param data
+ *
+ * @retutns boolean true if the component is able to Show the data as datatable
+ */
+ showDataAsDataTable(data: any) {
+ let datatableShow = true;
+ try {
+ if (!data.schema) {
+ data.schema = ObjectDataTableAdapter.generationSchema(data[0]);
+ }
+ if (data.schema && data.schema.length > 0) {
+ this.data = new ObjectDataTableAdapter(data.data, data.schema);
+ } else {
+ datatableShow = false;
+ }
+ } catch (e) {
+ datatableShow = false;
+ }
+
+ return datatableShow;
+ }
+
+ clean() {
+ let wrapper = document.getElementById('webscript-data');
+ wrapper.innerHTML = '';
+ this.data = undefined;
+ }
+
+ isDataTableCOntent() {
+ return this.contentType === 'DATATABLE' && this.show;
+ }
+}
diff --git a/ng2-components/ng2-alfresco-webscript/tsconfig.json b/ng2-components/ng2-alfresco-webscript/tsconfig.json
new file mode 100644
index 0000000000..e4d2ae201a
--- /dev/null
+++ b/ng2-components/ng2-alfresco-webscript/tsconfig.json
@@ -0,0 +1,27 @@
+{
+ "compilerOptions": {
+ "target": "es5",
+ "module": "system",
+ "moduleResolution": "node",
+ "emitDecoratorMetadata": true,
+ "experimentalDecorators": true,
+ "sourceMap": true,
+ "removeComments": true,
+ "declaration": true,
+ "noLib": false,
+ "allowUnreachableCode": false,
+ "allowUnusedLabels": false,
+ "noImplicitAny": false,
+ "noImplicitReturns": false,
+ "noImplicitUseStrict": false,
+ "noFallthroughCasesInSwitch": true,
+ "outDir": "dist"
+ },
+ "exclude": [
+ "demo",
+ "node_modules",
+ "typings/main",
+ "typings/main.d.ts",
+ "dist"
+ ]
+}
diff --git a/ng2-components/ng2-alfresco-webscript/tslint.json b/ng2-components/ng2-alfresco-webscript/tslint.json
new file mode 100644
index 0000000000..ba706079f4
--- /dev/null
+++ b/ng2-components/ng2-alfresco-webscript/tslint.json
@@ -0,0 +1,121 @@
+{
+ "rules": {
+ "align": [
+ true,
+ "parameters",
+ "statements"
+ ],
+ "ban": false,
+ "class-name": true,
+ "comment-format": [
+ true,
+ "check-space"
+ ],
+ "curly": true,
+ "eofline": true,
+ "forin": true,
+ "indent": [
+ true,
+ "spaces"
+ ],
+ "interface-name": false,
+ "jsdoc-format": true,
+ "label-position": true,
+ "label-undefined": true,
+ "max-line-length": [
+ true,
+ 180
+ ],
+ "member-ordering": [
+ true,
+ "static-before-instance",
+ "variables-before-functions"
+ ],
+ "no-any": false,
+ "no-arg": true,
+ "no-bitwise": false,
+ "no-conditional-assignment": true,
+ "no-consecutive-blank-lines": false,
+ "no-console": [
+ true,
+ "debug",
+ "info",
+ "time",
+ "timeEnd",
+ "trace"
+ ],
+ "no-construct": true,
+ "no-constructor-vars": false,
+ "no-debugger": true,
+ "no-duplicate-key": true,
+ "no-duplicate-variable": true,
+ "no-empty": false,
+ "no-eval": true,
+ "no-inferrable-types": false,
+ "no-internal-module": true,
+ "no-require-imports": true,
+ "no-shadowed-variable": true,
+ "no-switch-case-fall-through": true,
+ "no-trailing-whitespace": true,
+ "no-unreachable": true,
+ "no-unused-expression": true,
+ "no-unused-variable": true,
+ "no-use-before-declare": true,
+ "no-var-keyword": true,
+ "no-var-requires": true,
+ "object-literal-sort-keys": false,
+ "one-line": [
+ true,
+ "check-open-brace",
+ "check-catch",
+ "check-else",
+ "check-whitespace"
+ ],
+ "quotemark": [
+ true,
+ "single",
+ "avoid-escape"
+ ],
+ "radix": true,
+ "semicolon": true,
+ "switch-default": true,
+ "trailing-comma": [
+ true,
+ {
+ "multiline": "never",
+ "singleline": "never"
+ }
+ ],
+ "triple-equals": [
+ true,
+ "allow-null-check"
+ ],
+ "typedef": false,
+ "typedef-whitespace": [
+ true,
+ {
+ "call-signature": "nospace",
+ "index-signature": "nospace",
+ "parameter": "nospace",
+ "property-declaration": "nospace",
+ "variable-declaration": "nospace"
+ }
+ ],
+ "use-strict": false,
+ "variable-name": [
+ true,
+ "check-format",
+ "allow-leading-underscore",
+ "ban-keywords"
+ ],
+ "whitespace": [
+ true,
+ "check-branch",
+ "check-operator",
+ "check-separator",
+ "check-type",
+ "check-module",
+ "check-decl"
+ ]
+ }
+}
diff --git a/ng2-components/ng2-alfresco-webscript/typings.json b/ng2-components/ng2-alfresco-webscript/typings.json
new file mode 100644
index 0000000000..7e0e18568d
--- /dev/null
+++ b/ng2-components/ng2-alfresco-webscript/typings.json
@@ -0,0 +1,7 @@
+{
+ "globalDependencies": {
+ "core-js": "registry:dt/core-js#0.0.0+20160317120654",
+ "jasmine": "registry:dt/jasmine#2.2.0+20160505161446",
+ "node": "registry:dt/node#4.0.0+20160509154515"
+ }
+}