Skip to content

Commit

Permalink
#6423 fix missed baseUrl TODO; BeakerxApi => BeakerXApi; fix NaN show…
Browse files Browse the repository at this point in the history
…ing when changing heap size to empty string
  • Loading branch information
piorek committed Feb 2, 2018
1 parent 5b2965e commit 9c5a685
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 34 deletions.
7 changes: 7 additions & 0 deletions js/notebook/src/tree-lab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import BeakerXTreeWidget from './tree/TreeWidget';
import BeakerXApi from "./tree/BeakerXApi";

export default {
BeakerXTreeWidget: BeakerXTreeWidget,
BeakerXApi: BeakerXApi,
}
16 changes: 10 additions & 6 deletions js/notebook/src/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@
*/

define([
'require'
'require',
'base/js/namespace'
], function(
require
require,
Jupyter
) {
"use strict";

var $ = require('jquery');
var Widget = require('@phosphor/widgets').Widget;

function load() {
var $ = require('jquery');
var Widget = require('@phosphor/widgets').Widget;
var base_url = (Jupyter.notebook_list || Jupyter.notebook).base_url;
var BeakerXTreeWidget = require('./tree/TreeWidget').default;

var bxWidget = new BeakerXTreeWidget();
var BeakerxApi = require('./tree/BeakerXApi').default;
var bxWidget = new BeakerXTreeWidget(new BeakerxApi(base_url));

Widget.attach(bxWidget, $('.tab-content').get(0));
$('#tabs').append(
Expand Down
6 changes: 3 additions & 3 deletions js/notebook/src/tree/BannerWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as $ from 'jquery';
import { Widget } from "@phosphor/widgets";
import BeakerxApi from "./BeakerxApi";
import BeakerXApi from "./BeakerXApi";

export default class BannerWidget extends Widget {

Expand Down Expand Up @@ -60,9 +60,9 @@ export default class BannerWidget extends Widget {
</div>
`;

constructor() {
constructor(api: BeakerXApi) {
super();
BeakerxApi
api
.getVersion()
.then((version) => {
this.buildWidget(version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/

import * as $ from "jquery";
// import { PageConfig } from "@jupyterlab/coreutils";

const baseUrl = '/'; //PageConfig.getBaseUrl(); TODO
const apiUrl = `${baseUrl}beakerx/`;

export interface IDefaultJVMOptions {
heap_GB: number;
Expand All @@ -42,12 +38,19 @@ function getCookie(name) {
return r ? r[1] : void 0;
}

export default class BeakerxApi {
export default class BeakerXApi {

private apiUrl: string;

public static getApiUrl(endpoint: string): string {
return `${apiUrl}${endpoint}`;
constructor(baseUrl: string = '/') {
this.apiUrl = `${baseUrl}beakerx/`;
}
public static getVersion(): Promise<string> {

public getApiUrl(endpoint: string): string {
return `${this.apiUrl}${endpoint}`;
}

public getVersion(): Promise<string> {

return new Promise((resolve, reject) => {
$.ajax(this.getApiUrl('version'), {
Expand All @@ -62,7 +65,7 @@ export default class BeakerxApi {
});
}

public static loadSettings(): Promise<IApiSettingsResponse> {
public loadSettings(): Promise<IApiSettingsResponse> {
return new Promise((resolve, reject) => {
$.ajax(this.getApiUrl('settings'), {
success: (data, status) => {
Expand All @@ -76,7 +79,7 @@ export default class BeakerxApi {
});
}

public static saveSettings(data): Promise<any> {
public saveSettings(data): Promise<any> {
return new Promise<IApiSettingsResponse>((resolve, reject) => {

$.ajax(this.getApiUrl('settings'), {
Expand Down
2 changes: 1 addition & 1 deletion js/notebook/src/tree/JVMOptions/Messages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Message } from "@phosphor/messaging";
import {
IDefaultJVMOptions, IOtherJVMOptions, IPropertiesJVMOptions
} from "../BeakerxApi";
} from "../BeakerXApi";

export namespace Messages {

Expand Down
2 changes: 1 addition & 1 deletion js/notebook/src/tree/JVMOptions/OtherOptionsWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as $ from "jquery";
import * as _ from "underscore";
import { Widget } from "@phosphor/widgets";
import { MessageLoop, Message } from "@phosphor/messaging";
import { IOtherJVMOptions } from "../BeakerxApi";
import { IOtherJVMOptions } from "../BeakerXApi";
import { Messages } from "./Messages";
import OtherOptionsChangedMessage = Messages.OtherOptionsChangedMessage;

Expand Down
2 changes: 1 addition & 1 deletion js/notebook/src/tree/JVMOptions/PropertiesWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Widget } from "@phosphor/widgets";
import { MessageLoop, Message } from "@phosphor/messaging";
import { Messages } from "./Messages";
import PropertiesOptionsChangedMessage = Messages.PropertiesOptionsChangedMessage;
import { IPropertiesJVMOptions } from "../BeakerxApi";
import { IPropertiesJVMOptions } from "../BeakerXApi";

export class PropertiesWidget extends Widget {

Expand Down
14 changes: 8 additions & 6 deletions js/notebook/src/tree/JVMOptionsWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import { DefaultOptionsModel, DefaultOptionsWidget } from "./JVMOptions/DefaultO
import { OtherOptionsModel, OtherOptionsWidget } from "./JVMOptions/OtherOptionsWidget";
import { PropertiesModel, PropertiesWidget } from "./JVMOptions/PropertiesWidget";
import { SyncIndicatorWidget } from "./JVMOptions/SyncIndicatorWidget";
import BeakerxApi, {
import BeakerXApi, {
IApiSettingsResponse, IDefaultJVMOptions, IJVMOptions, IOtherJVMOptions,
IPropertiesJVMOptions
} from "./BeakerxApi";
} from "./BeakerXApi";
import { Messages } from "./JVMOptions/Messages";

export default class JVMOptionsWidget extends Panel {
Expand All @@ -39,7 +39,7 @@ export default class JVMOptionsWidget extends Panel {
</style>
`;

constructor() {
constructor(api: BeakerXApi) {
super();

this.addClass('beakerx_container');
Expand All @@ -50,6 +50,7 @@ export default class JVMOptionsWidget extends Panel {
let propertiesWidget = new PropertiesWidget();

this._model = new JvmOptionsModel(
api,
new DefaultOptionsModel(defaultOptionsWidget),
new PropertiesModel(propertiesWidget),
new OtherOptionsModel(otherOptionsWidget),
Expand Down Expand Up @@ -109,6 +110,7 @@ export default class JVMOptionsWidget extends Panel {
class JvmOptionsModel {

constructor(
private api: BeakerXApi,
private defaultOptionsModel: DefaultOptionsModel,
private propertiesOptionsModel: PropertiesModel,
private otherOptionsModel: OtherOptionsModel,
Expand All @@ -119,7 +121,7 @@ class JvmOptionsModel {
private _options: IApiSettingsResponse;

public setDefaultOptions(options: IDefaultJVMOptions): void {
this._options.jvm_options.heap_GB = parseFloat(`${ options.heap_GB }`);
this._options.jvm_options.heap_GB = options.heap_GB;
}
public setOtherOptions(options: IOtherJVMOptions): void {
this._options.jvm_options.other = options;
Expand All @@ -131,7 +133,7 @@ class JvmOptionsModel {
public load() {
this.syncWidget.onSyncStart();

BeakerxApi.loadSettings()
this.api.loadSettings()
.then((data: IApiSettingsResponse) => {
this._options = data;

Expand Down Expand Up @@ -168,7 +170,7 @@ class JvmOptionsModel {

this.syncWidget.showResult(this.buildResult(payload.jvm_options));

BeakerxApi.saveSettings({ beakerx: payload })
this.api.saveSettings({ beakerx: payload })
.then(() => {

setTimeout(() => {
Expand Down
11 changes: 6 additions & 5 deletions js/notebook/src/tree/TreeWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import BannerWidget from "./BannerWidget";
import JVMOptionsWidget from "./JVMOptionsWidget";
import * as $ from "jquery";
import {Message} from "@phosphor/messaging";
import BeakerXApi from "./BeakerXApi";

export default class BeakerXTreeWidget extends Panel {

Expand All @@ -32,24 +33,24 @@ export default class BeakerXTreeWidget extends Panel {
}
</style>
`;
constructor() {
constructor(api: BeakerXApi) {
super();

this.id = 'beakerx-tree';
this.addClass('tab-pane');
this.setupTitle();
this.createWidgetContent();
this.createWidgetContent(api);
}

private setupTitle() {
this.title.label = 'BeakerX';
this.title.closable = true;
}

private createWidgetContent() {
this.addWidget(new BannerWidget());
private createWidgetContent(api: BeakerXApi) {
this.addWidget(new BannerWidget(api));
this.addWidget(new Widget({ node: document.createElement('br') }));
this.addWidget(new JVMOptionsWidget());
this.addWidget(new JVMOptionsWidget(api));
}

onAfterAttach(msg: Message): void {
Expand Down
2 changes: 1 addition & 1 deletion js/notebook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ module.exports = [
plugins: plugins
},
{// BeakerXTree JupyterLab bundle
entry: './src/tree/TreeWidget.ts',
entry: './src/tree-lab.ts',
output: {
filename: 'tree.js',
path: path.resolve(__dirname, '../lab/lib/'),
Expand Down

0 comments on commit 9c5a685

Please sign in to comment.