From b276fa118370f77ecb484a5186e81a69d5fa2e7d Mon Sep 17 00:00:00 2001
From: phantomjinx
Date: Wed, 17 Jan 2018 11:41:08 +0000
Subject: [PATCH 1/2] Modify the npm start script for running the app
* package.json
* Replace the development server start command with a cli start script
* start.sh
* Can start server through either node or ng
* Use npm start for production node execution
* Use npm start -- -d for starting using 'ng serve'
* server.js
* Scaffold the angular compiled artefacts in the dist/ directory as static
files in express to allow them to be server through node.
---
ngapp/README.md | 6 +++++-
ngapp/package.json | 3 ++-
ngapp/server.js | 15 +++++++++++++++
ngapp/start.sh | 32 ++++++++++++++++++++++++++++++++
4 files changed, 54 insertions(+), 2 deletions(-)
create mode 100644 ngapp/server.js
create mode 100755 ngapp/start.sh
diff --git a/ngapp/README.md b/ngapp/README.md
index e66b7bea..d68ff074 100644
--- a/ngapp/README.md
+++ b/ngapp/README.md
@@ -2,9 +2,13 @@
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.3.2.
+## Running with [Nodejs](https://nodejs.org)
+
+Execute `npm start` to serve the Angular app using nodejs. Navigate to `http://localhost:8080`. This command is meant for production and the files in the `dist` directory will have to be recompiled for code changes to be displayed.
+
## Development server
-Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
+Execute `npm start -- -d` for a development server. Navigate to `http://localhost:8080/`. The app will automatically reload if you change any of the source files.
## Code scaffolding
diff --git a/ngapp/package.json b/ngapp/package.json
index e5a1630c..1a902473 100644
--- a/ngapp/package.json
+++ b/ngapp/package.json
@@ -4,8 +4,8 @@
"license": "MIT",
"scripts": {
"ng": "ng",
- "start": "ng serve --host 0.0.0.0 --port 8080 --disable-host-check",
"build": "ng build",
+ "start": "./start.sh",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
@@ -23,6 +23,7 @@
"@angular/router": "^4.4.6",
"@swimlane/ngx-datatable": "^11.1.5",
"core-js": "^2.4.1",
+ "express": "^4.16.2",
"ng2-codemirror": "^1.1.3",
"ngx-bootstrap": "^1.9.3",
"patternfly": "^3.31.0",
diff --git a/ngapp/server.js b/ngapp/server.js
new file mode 100644
index 00000000..15ea47ab
--- /dev/null
+++ b/ngapp/server.js
@@ -0,0 +1,15 @@
+var express = require("express");
+var bodyParser = require("body-parser");
+
+var app = express();
+app.use(bodyParser.json());
+
+// Create link to Angular build directory
+var distDir = __dirname + "/dist/";
+app.use(express.static(distDir));
+
+// Initialize the app.
+var server = app.listen(process.env.PORT || 8080, function () {
+ var port = server.address().port;
+ console.log("App now running on port", port);
+});
diff --git a/ngapp/start.sh b/ngapp/start.sh
new file mode 100755
index 00000000..05fa3cc9
--- /dev/null
+++ b/ngapp/start.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+#################
+#
+# Show help and exit
+#
+#################
+function show_help {
+ echo "Usage: $0 [-d] [-h]"
+ echo "-d: run in development mode"
+ echo ""
+ echo "To passthrough additional arguments, enter '--' followed by the extra arguments"
+ exit 1
+}
+
+#
+# Determine the command line options
+#
+while getopts ":d" opt;
+do
+ case $opt in
+ d) DEV=1 ;;
+ h) show_help ;;
+ esac
+done
+shift "$(expr $OPTIND - 1)"
+
+if [ "${DEV}" == "1" ]; then
+ ng serve --host 0.0.0.0 --port 8080 --disable-host-check
+else
+ ng build && node ./server.js
+fi
From 1bb974925b0e5f652c8e97778c38c975a92aec45 Mon Sep 17 00:00:00 2001
From: phantomjinx
Date: Thu, 18 Jan 2018 13:21:11 +0000
Subject: [PATCH 2/2] TEIIDTOOLS-307: Connects BTL to the teiid-komodo in
Openshift
* environment/*
* Centralises references to komodoEngine and komodoRestVersion constants
* Removes references to host and port as these are now accessible using
api.service
* api.service.ts
* Provides method for fetching the base url of the application
* app-settings.service.ts
* Fetches the user profile from teiid-komodo, providing BTL with the user
details including their workspace.
---
ngapp/src/app/core/api.service.ts | 18 +++--
ngapp/src/app/core/app-settings.service.ts | 90 +++++++++++++++++-----
ngapp/src/environments/environment.prod.ts | 16 +++-
ngapp/src/environments/environment.ts | 16 +++-
4 files changed, 108 insertions(+), 32 deletions(-)
diff --git a/ngapp/src/app/core/api.service.ts b/ngapp/src/app/core/api.service.ts
index f2fb54cc..0abff1ea 100644
--- a/ngapp/src/app/core/api.service.ts
+++ b/ngapp/src/app/core/api.service.ts
@@ -29,20 +29,26 @@ export abstract class ApiService {
protected appSettings: AppSettingsService;
protected logger: LoggerService;
- constructor( appSettings: AppSettingsService, logger: LoggerService ) {
+ constructor( appSettings: AppSettingsService, logger: LoggerService) {
this.appSettings = appSettings;
this.logger = logger;
}
/**
- * Get the Auth RequestOptions
- * TODO: User and password are currently hardcoded to the DSB kit server credentials (dsbUser | 1demo-user1)
+ * @returns the base url of the application
+ */
+ protected getBaseUrl(): string {
+ return window.location.protocol + '://' + window.location.hostname;
+ }
+
+ /**
+ * Get the Auth RequestOptions if any
+ * Note: Since usage of the oauth-proxy no additional auth request options are necessary
+ *
* @returns {RequestOptions}
*/
protected getAuthRequestOptions(): RequestOptions {
- const userPasswordStr = this.appSettings.getKomodoUser() + ":" + this.appSettings.getKomodoUserPassword();
- const headers = new Headers({ "Authorization": "Basic " + btoa(userPasswordStr) });
- return new RequestOptions({ headers });
+ return this.appSettings.getAuthRequestOptions();
}
/**
diff --git a/ngapp/src/app/core/app-settings.service.ts b/ngapp/src/app/core/app-settings.service.ts
index d6d95b04..37244b78 100644
--- a/ngapp/src/app/core/app-settings.service.ts
+++ b/ngapp/src/app/core/app-settings.service.ts
@@ -16,7 +16,12 @@
*/
import { Injectable } from "@angular/core";
+import { Http, Headers, RequestOptions, Response } from "@angular/http";
+import { LoggerService } from "@core/logger.service";
import { LayoutType } from "@shared/layout-type.enum";
+import { Observable } from "rxjs/Observable";
+import { ErrorObservable } from "rxjs/observable/ErrorObservable";
+import { environment } from "@environments/environment";
@Injectable()
export class AppSettingsService {
@@ -30,20 +35,24 @@ export class AppSettingsService {
public readonly GIT_REPO_PATH_KEY = "repo-path-property";
public readonly GIT_REPO_FILE_PATH_KEY = "file-path-property";
- private readonly komodoRoot = "tko:komodo/tko:workspace";
-
- // TODO: temporary location for user and password
- private readonly komodoUser = "dsbUser";
- private readonly komodoUserPassword = "1demo-user1";
-
// Map to maintain the target git repository properties
private readonly gitRepoProperties: Map;
+ private static readonly userProfileUrl = environment.komodoServiceUrl + "/userProfile";
+
// page layouts
private svcPageLayout: LayoutType = LayoutType.CARD;
private connPageLayout: LayoutType = LayoutType.CARD;
- constructor() {
+ private http: Http;
+ private logger: LoggerService;
+
+ private userProfile: Object;
+
+ constructor(http: Http, logger: LoggerService) {
+ this.http = http;
+ this.logger = logger;
+
// TODO: The git repository properties will be picked up based on the Openshift install location
this.gitRepoProperties = new Map();
this.gitRepoProperties.set(this.GIT_REPO_PATH_KEY, "https://github.com/GIT_USER/GIT_REPO");
@@ -52,30 +61,75 @@ export class AppSettingsService {
this.gitRepoProperties.set(this.GIT_REPO_PASSWORD_KEY, "MY_PASS");
this.gitRepoProperties.set(this.GIT_REPO_AUTHOR_NAME_KEY, "MY_USER");
this.gitRepoProperties.set(this.GIT_REPO_AUTHOR_EMAIL_KEY, "USER@SOMEWHERE.COM");
+
+ //
+ // Do a call to fetch the user profile on init of service.
+ // The fetchProfile method returns an observable
+ // which we subscribe to and on completion assigns the variable
+ // values accordingly
+ //
+ this.fetchUserProfile().subscribe(
+ (profile) => {
+ this.userProfile = profile;
+ },
+ (error) => {
+ this.logger.error( "[fetchUserProfile] Error: %o", error );
+ });
}
- /*
- * Get the komodo workspace path for the current user
- * @returns {string} the komodo workspace path
+ private handleError(error: Response): ErrorObservable {
+ this.logger.error( this.constructor.name + "::handleError" );
+ return Observable.throw(error);
+ }
+
+ private fetchUserProfile(): Observable