This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch STREAMPIPES-145
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit db5372f7f708504fc4d5a594df9a885a26d8e43e
Author: Dominik Riemer <[email protected]>
AuthorDate: Thu Jul 2 10:10:12 2020 +0200

    [STREAMPIPES-145] Migrate code input static property
---
 ui/package.json                                    |   3 +-
 ui/src/app/connect/connect.module.ts               |   5 +-
 .../static-code-input.component.html               |  34 +++++++
 .../static-code-input.component.scss               |  22 +++++
 .../static-code-input.component.ts                 | 106 +++++++++++++++++++++
 .../static-property.component.html                 |   7 ++
 .../static-properties/static-property.component.ts |   6 +-
 ui/src/scss/sp/buttons.scss                        |   1 +
 8 files changed, 181 insertions(+), 3 deletions(-)

diff --git a/ui/package.json b/ui/package.json
index 9d78215..e7d1bbc 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -29,6 +29,7 @@
     "@angular/router": "9.0.5",
     "@angular/upgrade": "9.0.5",
     "@asymmetrik/ngx-leaflet": "6.0.1",
+    "@ctrl/ngx-codemirror": "3.1.3",
     "@danielmoncada/angular-datetime-picker": "9.2.0",
     "@fortawesome/fontawesome-free": "5.12.1",
     "@ngui/datetime-picker": "0.16.2",
@@ -66,7 +67,7 @@
     "angularjs-datetime-picker": "0.1.16",
     "bootstrap": "3.3.4",
     "calendar-heatmap-graph": "0.0.14",
-    "codemirror": "5.53.2",
+    "codemirror": "5.55.0",
     "core-js": "2.5.3",
     "dagre": "0.8.4",
     "datatables.net": "1.10.20",
diff --git a/ui/src/app/connect/connect.module.ts 
b/ui/src/app/connect/connect.module.ts
index 3003ca0..e9aa0dd 100644
--- a/ui/src/app/connect/connect.module.ts
+++ b/ui/src/app/connect/connect.module.ts
@@ -92,7 +92,8 @@ import {xsService} from "../NS/XS.service";
 import {MatSliderModule} from "@angular/material/slider";
 import { QuillModule } from 'ngx-quill'
 import {MatChipsModule} from "@angular/material/chips";
-
+import {StaticCodeInputComponent} from 
"./static-properties/static-code-input/static-code-input.component";
+import { CodemirrorModule } from '@ctrl/ngx-codemirror';
 
 @NgModule({
     imports: [
@@ -100,6 +101,7 @@ import {MatChipsModule} from "@angular/material/chips";
         FormsModule,
         ReactiveFormsModule,
         CommonModule,
+        CodemirrorModule,
         FlexLayoutModule,
         MatGridListModule,
         CustomMaterialModule,
@@ -154,6 +156,7 @@ import {MatChipsModule} from "@angular/material/chips";
         StaticAlternativesComponent,
         StaticCollectionComponent,
         StaticColorPickerComponent,
+        StaticCodeInputComponent,
         PipelineElementRuntimeInfoComponent
     ],
     providers: [
diff --git 
a/ui/src/app/connect/static-properties/static-code-input/static-code-input.component.html
 
b/ui/src/app/connect/static-properties/static-code-input/static-code-input.component.html
new file mode 100644
index 0000000..2572c55
--- /dev/null
+++ 
b/ui/src/app/connect/static-properties/static-code-input/static-code-input.component.html
@@ -0,0 +1,34 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  ~
+  -->
+
+<div fxFlex="100" fxLayout="column">
+    <div flex="100" layout="row" layout-align="start center">
+        <button mat-button mat-raised-button color="primary" 
class="small-button" (click)="resetCode()"
+                style="margin-right:10px;margin-bottom:10px;">Reset code 
template
+        </button>
+    </div>
+    <div fxFlex="100" fxLayout="row">
+
+        <ngx-codemirror style="width:100%;"
+                [(ngModel)]="staticProperty.value"
+                [options]="editorOptions">
+
+        </ngx-codemirror>
+
+    </div>
+</div>
\ No newline at end of file
diff --git 
a/ui/src/app/connect/static-properties/static-code-input/static-code-input.component.scss
 
b/ui/src/app/connect/static-properties/static-code-input/static-code-input.component.scss
new file mode 100644
index 0000000..8a0ce57
--- /dev/null
+++ 
b/ui/src/app/connect/static-properties/static-code-input/static-code-input.component.scss
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+::ng-deep.CodeMirror-lint-tooltip {
+  z-index: 1001;
+}
\ No newline at end of file
diff --git 
a/ui/src/app/connect/static-properties/static-code-input/static-code-input.component.ts
 
b/ui/src/app/connect/static-properties/static-code-input/static-code-input.component.ts
new file mode 100644
index 0000000..dc60fd7
--- /dev/null
+++ 
b/ui/src/app/connect/static-properties/static-code-input/static-code-input.component.ts
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import {AbstractStaticPropertyRenderer} from 
"../base/abstract-static-property";
+import {
+  CodeInputStaticProperty,
+  CollectionStaticProperty
+} from "../../../core-model/gen/streampipes-model";
+import {AbstractValidatedStaticPropertyRenderer} from 
"../base/abstract-validated-static-property";
+import {AfterViewInit, Component, OnInit, ViewChild} from "@angular/core";
+
+import CodeMirror from 'codemirror';
+import 'codemirror/mode/javascript/javascript';
+import 'codemirror/addon/edit/closebrackets';
+import 'codemirror/addon/hint/show-hint';
+import 'codemirror/addon/hint/javascript-hint';
+import 'codemirror/addon/lint/javascript-lint';
+import 'codemirror/addon/lint/lint';
+import {JSHINT} from 'jshint';
+
+(<any>window).JSHINT = JSHINT;
+
+@Component({
+  selector: 'app-static-code-input',
+  templateUrl: './static-code-input.component.html',
+  styleUrls: ['./static-code-input.component.scss']
+})
+export class StaticCodeInputComponent
+    extends AbstractValidatedStaticPropertyRenderer<CodeInputStaticProperty> 
implements OnInit, AfterViewInit {
+
+  editorOptions = {
+    mode: "javascript",
+    autoRefresh: true,
+    theme: 'dracula',
+    autoCloseBrackets: true,
+    lineNumbers: true,
+    lineWrapping: true,
+    gutters: ["CodeMirror-lint-markers"],
+    lint: true,
+    extraKeys: {
+      "Ctrl-Space": "autocomplete"
+    }
+  };
+
+
+  constructor() {
+    super();
+  }
+
+  ngOnInit() {
+    if (!this.staticProperty.value || this.staticProperty.value === "") {
+      this.staticProperty.value = this.staticProperty.codeTemplate;
+    }
+
+  }
+
+  ngAfterViewInit() {
+    this.enableCodeHints();
+  }
+
+  onStatusChange(status: any) {
+  }
+
+  onValueChange(value: any) {
+  }
+
+  resetCode() {
+    this.staticProperty.value = this.staticProperty.codeTemplate;
+  };
+
+  enableCodeHints() {
+    var jsHint = CodeMirror.hint.javascript;
+    CodeMirror.hint.javascript = (cm) => {
+      let cursor = cm.getCursor();
+      let token = cm.getTokenAt(cursor);
+      let inner = {from: cm.getCursor(), to: cm.getCursor(), list: []};
+      let previousCursor = {line: cursor.line, ch: (cursor.ch - 1), sticky: 
null}
+      let previousToken = cm.getTokenAt(previousCursor);
+      if (token.string === "." && previousToken.string === "event") {
+        this.eventSchemas[0].eventProperties.forEach(ep => {
+          inner.list.unshift(ep.runtimeName);
+        })
+      } else {
+        inner = jsHint(cm);
+      }
+      return inner;
+    };
+  }
+
+
+}
\ No newline at end of file
diff --git 
a/ui/src/app/connect/static-properties/static-property.component.html 
b/ui/src/app/connect/static-properties/static-property.component.html
index a1b8339..d46cdfc 100644
--- a/ui/src/app/connect/static-properties/static-property.component.html
+++ b/ui/src/app/connect/static-properties/static-property.component.html
@@ -23,6 +23,13 @@
             <mat-hint 
class="description">{{staticProperty.description}}</mat-hint>
         </div>
         <div fxFlex="60">
+            <app-static-code-input 
*ngIf="isCodeInputStaticProperty(staticProperty)"
+                                   [staticProperty]="staticProperty"
+                                   [parentForm]="parentForm"
+                                   [eventSchemas]="eventSchemas"
+                                   (updateEmitter)="emitUpdate($event)">
+            </app-static-code-input>
+
             <app-static-secret-input 
*ngIf="isSecretStaticProperty(staticProperty)"
                                      [staticProperty]="staticProperty"
                                      [parentForm]="parentForm"
diff --git a/ui/src/app/connect/static-properties/static-property.component.ts 
b/ui/src/app/connect/static-properties/static-property.component.ts
index c160a1a..398100e 100644
--- a/ui/src/app/connect/static-properties/static-property.component.ts
+++ b/ui/src/app/connect/static-properties/static-property.component.ts
@@ -23,7 +23,7 @@ import {xsService} from '../../NS/XS.service';
 import {StaticPropertyUtilService} from './static-property-util.service';
 import {ConfigurationInfo} from "../model/message/ConfigurationInfo";
 import {
-  AnyStaticProperty,
+  AnyStaticProperty, CodeInputStaticProperty,
   CollectionStaticProperty,
   ColorPickerStaticProperty,
   EventSchema,
@@ -85,6 +85,10 @@ export class StaticPropertyComponent implements OnInit {
 
   }
 
+  isCodeInputStaticProperty(val) {
+    return val instanceof CodeInputStaticProperty;
+  }
+
   isFreeTextStaticProperty(val) {
     return val instanceof FreeTextStaticProperty;
   }
diff --git a/ui/src/scss/sp/buttons.scss b/ui/src/scss/sp/buttons.scss
index dfc690c..5fa9803 100644
--- a/ui/src/scss/sp/buttons.scss
+++ b/ui/src/scss/sp/buttons.scss
@@ -80,6 +80,7 @@
     padding: 0.25em 0.75em;
     font-size: 0.8em;
     max-height: 20px;
+    line-height: 10px;
 }
 
 .mat-raised-button.mat-primary:hover:enabled {

Reply via email to