Skip to content

Commit eafc519

Browse files
committed
feat: add base services
1 parent 27c5bdf commit eafc519

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3133
-38
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Editor configuration, see https://editorconfig.org
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[*.md]
11+
max_line_length = off
12+
trim_trailing_whitespace = false

zeppelin-frontend/src/.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
8+
# dependencies
9+
/node_modules
10+
11+
# profiling files
12+
chrome-profiler-events.json
13+
speed-measure-plugin.json
14+
15+
# IDEs and editors
16+
/.idea
17+
.project
18+
.classpath
19+
.c9/
20+
*.launch
21+
.settings/
22+
*.sublime-workspace
23+
24+
# IDE - VSCode
25+
.vscode/*
26+
!.vscode/settings.json
27+
!.vscode/tasks.json
28+
!.vscode/launch.json
29+
!.vscode/extensions.json
30+
31+
# misc
32+
/.sass-cache
33+
/connect.lock
34+
/coverage
35+
/libpeerconnection.log
36+
npm-debug.log
37+
yarn-error.log
38+
testem.log
39+
/typings
40+
41+
# System Files
42+
.DS_Store
43+
Thumbs.db
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './public-api';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './public-api';
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { OnDestroy } from '@angular/core';
2+
import { Subscriber } from 'rxjs';
3+
4+
import { MessageReceiveDataTypeMap, ReceiveArgumentsType } from '@zeppelin/sdk';
5+
import { MessageService } from '@zeppelin/services';
6+
7+
export class MessageListenersManager implements OnDestroy {
8+
__zeppelinMessageListeners__: Array<() => void>;
9+
__zeppelinMessageListeners$__ = new Subscriber();
10+
constructor(public messageService: MessageService) {
11+
if (this.__zeppelinMessageListeners__) {
12+
this.__zeppelinMessageListeners__.forEach(fn => fn.apply(this));
13+
}
14+
}
15+
16+
ngOnDestroy(): void {
17+
this.__zeppelinMessageListeners$__.unsubscribe();
18+
this.__zeppelinMessageListeners$__ = null;
19+
}
20+
}
21+
22+
export function MessageListener<K extends keyof MessageReceiveDataTypeMap>(op: K) {
23+
return function(
24+
target: MessageListenersManager,
25+
propertyKey: string,
26+
descriptor: TypedPropertyDescriptor<ReceiveArgumentsType<K>>
27+
) {
28+
const oldValue = descriptor.value as ReceiveArgumentsType<K>;
29+
30+
const fn = function() {
31+
// tslint:disable:no-invalid-this
32+
this.__zeppelinMessageListeners$__.add(
33+
this.messageService.receive(op).subscribe(data => {
34+
oldValue.apply(this, [data]);
35+
})
36+
);
37+
};
38+
39+
if (!target.__zeppelinMessageListeners__) {
40+
target.__zeppelinMessageListeners__ = [fn];
41+
} else {
42+
target.__zeppelinMessageListeners__.push(fn);
43+
}
44+
45+
return descriptor;
46+
};
47+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './message-listener';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './message-listener';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Injectable } from '@angular/core';
2+
3+
@Injectable({
4+
providedIn: 'root'
5+
})
6+
export class BaseUrlService {
7+
getPort() {
8+
let port = Number(location.port);
9+
if (!port) {
10+
port = 80;
11+
if (location.protocol === 'https:') {
12+
port = 443;
13+
}
14+
}
15+
return port;
16+
}
17+
18+
getWebsocketUrl() {
19+
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
20+
return `${wsProtocol}//${location.hostname}:${this.getPort()}${this.skipTrailingSlash(location.pathname)}/ws`;
21+
}
22+
23+
getBase() {
24+
return `${location.protocol}//${location.hostname}:${this.getPort()}${location.pathname}`;
25+
}
26+
27+
getRestApiBase() {
28+
return this.skipTrailingSlash(this.getBase()) + '/api';
29+
}
30+
31+
skipTrailingSlash(path) {
32+
return path.replace(/\/$/, '');
33+
}
34+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './public-api';
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { HttpClient } from '@angular/common/http';
2+
import { Injectable } from '@angular/core';
3+
4+
import {
5+
CreateInterpreterRepositoryForm,
6+
Interpreter,
7+
InterpreterMap,
8+
InterpreterPropertyTypes,
9+
InterpreterRepository
10+
} from '@zeppelin/interfaces';
11+
import { InterpreterItem } from '@zeppelin/sdk';
12+
13+
import { BaseRest } from './base-rest';
14+
import { BaseUrlService } from './base-url.service';
15+
16+
@Injectable({
17+
providedIn: 'root'
18+
})
19+
export class InterpreterService extends BaseRest {
20+
constructor(baseUrlService: BaseUrlService, private http: HttpClient) {
21+
super(baseUrlService);
22+
}
23+
24+
getRepositories() {
25+
return this.http.get<InterpreterRepository[]>(this.restUrl`/interpreter/repository`);
26+
}
27+
28+
addRepository(repo: CreateInterpreterRepositoryForm) {
29+
return this.http.post(this.restUrl`/interpreter/repository`, repo);
30+
}
31+
32+
removeRepository(repoId: string) {
33+
return this.http.delete(this.restUrl`/interpreter/repository/${repoId}`);
34+
}
35+
36+
getInterpretersSetting() {
37+
return this.http.get<Interpreter[]>(this.restUrl`/interpreter/setting`);
38+
}
39+
40+
getAvailableInterpreters() {
41+
return this.http.get<InterpreterMap>(this.restUrl`/interpreter`);
42+
}
43+
44+
getAvailableInterpreterPropertyTypes() {
45+
return this.http.get<InterpreterPropertyTypes[]>(this.restUrl`/interpreter/property/types`);
46+
}
47+
48+
addInterpreterSetting(interpreter: Interpreter) {
49+
return this.http.post<Interpreter>(this.restUrl`/interpreter/setting`, interpreter);
50+
}
51+
52+
updateInterpreter(interpreter: Interpreter) {
53+
const { option, properties, dependencies } = interpreter;
54+
return this.http.put<Interpreter>(this.restUrl`/interpreter/setting/${interpreter.name}`, {
55+
option,
56+
properties,
57+
dependencies
58+
});
59+
}
60+
61+
restartInterpreter(interpreterId: string, noteId: string) {
62+
return this.http.put<InterpreterItem>(this.restUrl`/interpreter/setting/restart/${interpreterId}`, { noteId });
63+
}
64+
65+
removeInterpreterSetting(settingId: string) {
66+
return this.http.delete(this.restUrl`/interpreter/setting/${settingId}`);
67+
}
68+
69+
restartInterpreterSetting(settingId: string) {
70+
return this.http.put(this.restUrl`/interpreter/setting/restart/${settingId}`, null);
71+
}
72+
}

0 commit comments

Comments
 (0)