+
Error during the deserialization of {{data}} as {{contentType}}
`,
+ directives: [ALFRESCO_DATATABLE_DIRECTIVES, CONTEXT_MENU_DIRECTIVES],
+ providers: [CONTEXT_MENU_PROVIDERS]
+})
+export class WebscriptComponent {
+
+ @Input()
+ scriptPath: string;
+
+ @Input()
+ scriptArgs: any;
+
+ @Input()
+ contextRoot: string = 'alfresco';
+
+ @Input()
+ servicePath: string = 'service';
+
+ @Input()
+ contentType: string = 'TEXT';
+
+ @Output()
+ onSuccess = new EventEmitter();
+
+ 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);
+ }
+
+ this.onSuccess.emit(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.generateSchema(data.data);
+ }
+ 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"
+ }
+}
diff --git a/scripts/npm-clean.sh b/scripts/npm-clean.sh
index 7bfe5ff60e..59ca1b7635 100755
--- a/scripts/npm-clean.sh
+++ b/scripts/npm-clean.sh
@@ -9,7 +9,8 @@ for PACKAGE in \
ng2-alfresco-login \
ng2-alfresco-search \
ng2-alfresco-upload \
- ng2-alfresco-viewer
+ ng2-alfresco-viewer \
+ ng2-alfresco-webscript
do
echo "====== clean component: ${PACKAGE} ====="
cd "$DIR/../ng2-components/${PACKAGE}"
diff --git a/scripts/npm-link-demo-shell.sh b/scripts/npm-link-demo-shell.sh
index 300327b4ad..22da9d98be 100755
--- a/scripts/npm-link-demo-shell.sh
+++ b/scripts/npm-link-demo-shell.sh
@@ -20,12 +20,20 @@ npm link ng2-alfresco-core
npm link ng2-alfresco-datatable
npm link
+#LINK WEBSCRIPT
+echo "====== linking component: ng2-alfresco-webscript ====="
+cd "$DIR/../ng2-components/ng2-alfresco-webscript"
+npm link ng2-alfresco-core
+npm link ng2-alfresco-datatable
+npm link
+
#LINK ALL THE OTHERS COMPONENTS
for PACKAGE in \
ng2-alfresco-login \
ng2-alfresco-search \
ng2-alfresco-upload \
- ng2-alfresco-viewer
+ ng2-alfresco-viewer \
+ ng2-alfresco-webscript
do
DESTDIR="$DIR/../ng2-components/${PACKAGE}"
echo "====== linking component: ${PACKAGE} ====="
@@ -44,7 +52,8 @@ for PACKAGE in \
ng2-alfresco-login \
ng2-alfresco-search \
ng2-alfresco-upload \
- ng2-alfresco-viewer
+ ng2-alfresco-viewer \
+ ng2-alfresco-webscript
do
DESTDIR="$DIR/../ng2-components/${PACKAGE}"
echo "====== demo shell linking: ${PACKAGE} ====="
diff --git a/scripts/npm-publish.sh b/scripts/npm-publish.sh
index 42a263a6b2..9591b8ba48 100755
--- a/scripts/npm-publish.sh
+++ b/scripts/npm-publish.sh
@@ -11,7 +11,8 @@ for PACKAGE in \
ng2-alfresco-login \
ng2-alfresco-search \
ng2-alfresco-upload \
- ng2-alfresco-viewer
+ ng2-alfresco-viewer \
+ ng2-alfresco-webscript
do
DESTDIR="$DIR/../ng2-components/${PACKAGE}"
echo "====== PUBLISHING: ${DESTDIR} ====="
diff --git a/scripts/update-version.sh b/scripts/update-version.sh
index 168e5bf685..609350a64f 100755
--- a/scripts/update-version.sh
+++ b/scripts/update-version.sh
@@ -21,7 +21,8 @@ for PACKAGE in \
ng2-alfresco-login \
ng2-alfresco-search \
ng2-alfresco-upload \
- ng2-alfresco-viewer
+ ng2-alfresco-viewer \
+ ng2-alfresco-webscript
do
DESTDIR="$DIR/../ng2-components/${PACKAGE}"
echo "====== UPDATE VERSION of ${PACKAGE} to ${VERSION} version in all the package.json ======"
@@ -35,7 +36,8 @@ for PACKAGE in \
ng2-alfresco-login \
ng2-alfresco-search \
ng2-alfresco-upload \
- ng2-alfresco-viewer
+ ng2-alfresco-viewer \
+ ng2-alfresco-webscript
do
DESTDIR="$DIR/../ng2-components/${PACKAGE}"
echo "====== UPDATE VERSION OF ${PACKAGE} to ${VERSION} version ======"