You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@submarine.apache.org by ji...@apache.org on 2020/08/16 04:05:13 UTC

[submarine] branch master updated: SUBMARINE-591. [WEB] Update notebook component in workbench

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

jiwq pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/submarine.git


The following commit(s) were added to refs/heads/master by this push:
     new 3936998  SUBMARINE-591. [WEB] Update notebook component in workbench
3936998 is described below

commit 393699828a7890d596a75c3de9d66098766da190
Author: kobe860219 <ko...@gmail.com>
AuthorDate: Thu Aug 13 17:27:55 2020 +0800

    SUBMARINE-591. [WEB] Update notebook component in workbench
    
    ### What is this PR for?
    * Update notebook fronted page of workbench for future work.
    * Remove monaco editor module.
    
    ### What type of PR is it?
    [Feature]
    
    ### Todos
    
    ### What is the Jira issue?
    https://issues.apache.org/jira/browse/SUBMARINE-591
    
    ### How should this be tested?
    https://travis-ci.org/github/kobe860219/submarine/builds/717530321
    
    ### Screenshots (if appropriate)
    ![notebook](https://user-images.githubusercontent.com/48027290/90119140-c4319d80-dd8b-11ea-978e-1d8703675235.gif)
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: kobe860219 <ko...@gmail.com>
    
    Closes #377 from kobe860219/SUBMARINE-591 and squashes the following commits:
    
    c6436a1 [kobe860219] SUBMARINE-591. [WEB] Update notebook component in workbench
    80928d2 [kobe860219] Update 2
    a1767cf [kobe860219] Prettier code
    705e430 [kobe860219] First time update notebook page.
---
 submarine-workbench/workbench-web-ng/package.json  |   1 -
 .../workbench-web-ng/src/app/app.module.ts         |   4 +-
 .../workbench/notebook/notebook.component.html     | 226 ++++++++++++++-------
 .../workbench/notebook/notebook.component.scss     |  37 +++-
 .../pages/workbench/notebook/notebook.component.ts | 107 ++++++----
 .../pages/workbench/notebook/notebook.module.ts    |  10 +-
 6 files changed, 256 insertions(+), 129 deletions(-)

diff --git a/submarine-workbench/workbench-web-ng/package.json b/submarine-workbench/workbench-web-ng/package.json
index 72b3a6b..ff2be35 100644
--- a/submarine-workbench/workbench-web-ng/package.json
+++ b/submarine-workbench/workbench-web-ng/package.json
@@ -28,7 +28,6 @@
     "lodash": "^4.17.19",
     "md5": "^2.2.1",
     "ng-zorro-antd": "8.1.2",
-    "ngx-monaco-editor": "^8.0.0",
     "rxjs": "~6.4.0",
     "tslib": "^1.10.0",
     "zone.js": "~0.9.1"
diff --git a/submarine-workbench/workbench-web-ng/src/app/app.module.ts b/submarine-workbench/workbench-web-ng/src/app/app.module.ts
index ef596da..64acdb4 100644
--- a/submarine-workbench/workbench-web-ng/src/app/app.module.ts
+++ b/submarine-workbench/workbench-web-ng/src/app/app.module.ts
@@ -30,7 +30,6 @@ import { zh_CN, NgZorroAntdModule, NZ_I18N } from 'ng-zorro-antd';
 import { AppRoutingModule } from './app-routing.module';
 import { AppComponent } from './app.component';
 import { IconsProviderModule } from './icons-provider.module';
-import { MonacoEditorModule } from 'ngx-monaco-editor';
 
 registerLocaleData(zh);
 
@@ -43,8 +42,7 @@ registerLocaleData(zh);
     NgZorroAntdModule,
     FormsModule,
     HttpClientModule,
-    BrowserAnimationsModule,
-    MonacoEditorModule.forRoot()
+    BrowserAnimationsModule
   ],
   providers: [{ provide: NZ_I18N, useValue: zh_CN }, LocalStorageService],
   bootstrap: [AppComponent]
diff --git a/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.component.html b/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.component.html
index edd8276..2c98b7e 100644
--- a/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.component.html
+++ b/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.component.html
@@ -16,78 +16,160 @@
   ~ specific language governing permissions and limitations
   ~ under the License.
   -->
-
-<div id="notebookDiv" *ngIf="!isEditing">
-  <div id="searchRegin" align="right">
-    <form nz-form [nzLayout]="'inline'" [formGroup]="searchForm">
-      <nz-form-item>
-        <nz-form-label>Notebook Name</nz-form-label>
-        <nz-form-control>
-          <input nz-input placeholder="Notebook name..." formControlName="notebookName" />
-        </nz-form-control>
-      </nz-form-item>
-      <nz-form-item>
-        <nz-form-control>
-          <button id="searchBtn" nz-button nzType="primary">
-            <i nz-icon nzType="search"></i>
-            Query
-          </button>
-          <button id="newBtn" nz-button nzType="primary" style="margin-left: 8px;">
-            <i nz-icon nzType="plus"></i>
-            New Notebook
-          </button>
-        </nz-form-control>
-      </nz-form-item>
-    </form>
-  </div>
-  <div id="notebookTable">
-    <nz-table #notebookListTable [nzData]="notebookList">
-      <thead>
-        <tr>
-          <th>Name</th>
-          <th>Creator</th>
-          <th>Create Time</th>
-          <th>Action</th>
-        </tr>
-      </thead>
-      <tbody>
-        <tr *ngFor="let notebook of notebookListTable.data; let i; of: index">
-          <td>{{ notebook.name }}</td>
-          <td>{{ notebook.createBy }}</td>
-          <td>{{ notebook.createTime }}</td>
-          <td>
-            <a id="edit{{ i }}" (click)="edit(notebook)">
-              <i nz-icon nzType="edit" nzTheme="outline"></i>
-              Edit
-            </a>
-            <nz-divider nzType="vertical"></nz-divider>
-            <a id="delete{{ i }}">
-              <i nz-icon nzType="delete" nzTheme="outline"></i>
-              Delete
-            </a>
-          </td>
-        </tr>
-      </tbody>
-    </nz-table>
+<nz-layout style="margin: -24px -24px 16px;">
+  <nz-layout class="inner-layout">
+    <div id="notebookOuter">
+      <nz-breadcrumb>
+        <nz-breadcrumb-item>
+          <a [routerLink]="['/', 'workbench', 'home']">Home</a>
+        </nz-breadcrumb-item>
+        <nz-breadcrumb-item>
+          <a [routerLink]="['/', 'workbench', 'notebook']">Notebook</a>
+        </nz-breadcrumb-item>
+      </nz-breadcrumb>
+      <div>
+        <br />
+        <h2>Notebook</h2>
+        <nz-content>Apache submarine support jupyter notebook.</nz-content>
+        <br />
+      </div>
+    </div>
+  </nz-layout>
+  <div id="notebookDiv">
+    <div nz-row>
+      <div nz-col nzSpan="12">
+        <label style="font-size: large; color: black;">Namespaces :</label>
+        <nz-select style="margin-left: 5px; width: 240px;" [(ngModel)]="currentNamespaces">
+          <nz-option
+            *ngFor="let namespaces of namespacesList"
+            [nzValue]="namespaces"
+            [nzLabel]="namespaces"
+          ></nz-option>
+        </nz-select>
+      </div>
+      <div nz-col nzSpan="12" align="right">
+        <nz-input-group nzSearch style="width: 300px; margin-right: 5px;" [nzAddOnAfter]="suffixIconButton">
+          <input type="text" nz-input placeholder="input search text" />
+        </nz-input-group>
+        <ng-template #suffixIconButton>
+          <button nz-button nzType="primary" nzSearch><i nz-icon nzType="search"></i></button>
+        </ng-template>
+        <button id="btnNewNotebook" nz-button nzType="primary" style="margin-right: 5px;" (click)="isVisible = true">
+          <i nz-icon nzType="plus"></i>
+          New Notebook
+        </button>
+        <button id="btnDelNotebook" nz-button nzType="primary">
+          <i nz-icon nzType="delete"></i>
+          Delete
+        </button>
+      </div>
+    </div>
+    <div>
+      <nz-table style="padding-top: 5px;" #basicTable [nzData]="notebookList">
+        <thead>
+          <tr>
+            <th>
+              <label nz-checkbox [(ngModel)]="checked" (ngModelChange)="selectAllNotebook()"></label>
+            </th>
+            <th nzWidth="120px">Status</th>
+            <th>Name</th>
+            <th>Age</th>
+            <th>Environment</th>
+            <th>CPU</th>
+            <th>GPU</th>
+            <th>Memory</th>
+            <th>Action</th>
+          </tr>
+        </thead>
+        <tbody>
+          <tr *ngFor="let data of basicTable.data; let i = index">
+            <td>
+              <label nz-checkbox [(ngModel)]="checkedList[i]"></label>
+            </td>
+            <td>
+              <nz-tag [nzColor]="statusColor[data.status]">{{ data.status }}</nz-tag>
+            </td>
+            <td>
+              <a>{{ data.name }}</a>
+            </td>
+            <td>{{ data.age }}</td>
+            <td>{{ data.environment }}</td>
+            <td>{{ data.cpu }}</td>
+            <td>{{ data.gpu }}</td>
+            <td>{{ data.memory }}</td>
+            <td>
+              <a nz-dropdown [nzDropdownMenu]="menu">
+                More
+                <i nz-icon nzType="down"></i>
+              </a>
+              <nz-dropdown-menu #menu="nzDropdownMenu">
+                <ul nz-menu nzSelectable>
+                  <li nz-menu-item (click)="runNotebook(data)">Run</li>
+                  <li nz-menu-item (click)="stopNotebook(data)">Stop</li>
+                </ul>
+              </nz-dropdown-menu>
+            </td>
+          </tr>
+        </tbody>
+      </nz-table>
+    </div>
   </div>
-</div>
+</nz-layout>
 
-<div *ngIf="isEditing">
-  <div style="background-color: white;">
-    <button id="btnRun" class="actionBar" nz-button nzType="primary">
-      <i nz-icon nzType="caret-right" nzTheme="outline"></i>
-      Run
-    </button>
-    <button id="btnSave" class="actionBar" nz-button nzType="primary" (click)="saveNotebook()">
-      <i nz-icon nzType="save" nzTheme="outline"></i>
-      Save
-    </button>
-    <button id="btnDelete" class="actionBar" nz-button nzType="danger">
-      <i nz-icon nzType="delete" nzTheme="outline"></i>
-      Delete
-    </button>
-  </div>
-  <div style="margin-top: 5px; background-color: white; height: 500px;">
-    <ngx-monaco-editor [options]="editorOptions" [(ngModel)]="code" style="height: 500px;"></ngx-monaco-editor>
+<nz-modal
+  [(nzVisible)]="isVisible"
+  nzTitle="Create Notebook"
+  [(nzCancelText)]="cancelText"
+  [(nzOkText)]="okText"
+  [nzOkLoading]="isOkLoading"
+  (nzOnCancel)="isVisible = false"
+  (nzOnOk)="isVisible = false"
+  [nzWidth]="700"
+>
+  <div>
+    <form [formGroup]="notebookForm">
+      <div class="newNotebookForm">
+        <label for="notebookName">
+          <span class="red-star">*</span>
+          Notebook Name :
+        </label>
+        <input nz-input type="text" name="notebookName" id="notebookName" formControlName="notebookName" required />
+      </div>
+      <div class="newNotebookForm">
+        <label for="namespaces">
+          <span class="red-star">*</span>
+          Namespaces :
+        </label>
+        <input nz-input type="text" name="namespaces" id="namespaces" formControlName="namespaces" />
+      </div>
+      <div class="newNotebookForm">
+        <label for="environment">
+          <span class="red-star">*</span>
+          Environment :
+        </label>
+        <input nz-input type="text" name="environment" id="environment" formControlName="environment" />
+      </div>
+      <div class="newNotebookForm">
+        <label for="cpu">
+          <span class="red-star">*</span>
+          CPU :
+        </label>
+        <input nz-input type="text" name="cpu" id="cpu" formControlName="cpu" />
+      </div>
+      <div class="newNotebookForm">
+        <label for="gpu">
+          <span class="red-star">*</span>
+          GPU :
+        </label>
+        <input nz-input type="text" name="gpu" id="gpu" formControlName="gpu" />
+      </div>
+      <div class="newNotebookForm">
+        <label for="memory">
+          <span class="red-star">*</span>
+          Memory :
+        </label>
+        <input nz-input type="text" name="memory" id="memory" formControlName="memory" />
+      </div>
+    </form>
   </div>
-</div>
+</nz-modal>
diff --git a/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.component.scss b/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.component.scss
index 1c7e06c..201a781 100644
--- a/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.component.scss
+++ b/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.component.scss
@@ -17,14 +17,35 @@
  * under the License.
  */
 
-#searchRegin {
+#notebookOuter{
     background-color: white;
-}
+    padding-left: 30px;
+    padding-top: 20px;
+ }
 
-#notebookTable {
-    background-color: white;
-}
+ #notebookDiv{
+     margin: 10px;
+     background-color: white;
+     padding: 10px;
+     overflow: auto;
+ }
+ .red-star {
+     color: red;
+ }
 
-.actionBar {
-    margin: 10px;
-}
+ .newNotebookForm {
+    display: flex;
+   align-items: center;
+   margin-bottom: 1.5rem;
+   & label {
+      flex: 0 0 25%;
+      text-align: right;
+      font-weight: 500;
+      &:not(:last-child) {
+         margin-right: 1.5rem;
+      }
+   }
+   & input {
+      flex: 0 0 48%;
+   }
+ }
\ No newline at end of file
diff --git a/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.component.ts b/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.component.ts
index ba3cf1a..712b914 100644
--- a/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.component.ts
+++ b/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.component.ts
@@ -18,8 +18,7 @@
  */
 
 import { Component, OnInit } from '@angular/core';
-import { FormBuilder, FormGroup, Validators } from '@angular/forms';
-import { NzMessageService } from 'ng-zorro-antd/message';
+import { FormControl, FormGroup, Validators } from '@angular/forms';
 
 @Component({
   selector: 'submarine-notebook',
@@ -27,49 +26,85 @@ import { NzMessageService } from 'ng-zorro-antd/message';
   styleUrls: ['./notebook.component.scss']
 })
 export class NotebookComponent implements OnInit {
-  isEditing = false;
-  notebookList = [{ name: 'Notebook', createTime: '2020-05-16 20:00:00', createBy: 'Someone' }];
+  // Checkbox
+  checkedList: boolean[] = [];
+  checked: boolean = false;
 
-  //search
-  notebookName: string = '';
-  searchForm: FormGroup;
+  // New notebook modal
+  cancelText = 'Cancel';
+  okText = 'Create';
+  isVisible = false;
 
-  //editor
-  editorOptions = { theme: 'vs-dark', language: 'python' };
-  code: string = `from tensorflow.examples.tutorials.mnist import input_data
-  import numpy as np
-  
-  mnist = input_data.read_data_sets("MNIST_data/", one_hot = True)
-  x_train = mnist.train.images
-  y_train = mnist.train.labels
-  x_test = mnist.test.images
-  y_test = mnist.test.labels
-  
-  print(x_train.shape)
-  print(y_train.shape)
-  print(x_test.shape)
-  print(y_test.shape)
-  print("---")
-  
-  #print(x_train[1, :])
-  print(np.argmax(y_train[1, :]))`;
+  // New notebook(form)
+  notebookForm: FormGroup;
 
-  constructor(private fb: FormBuilder, private message: NzMessageService) {}
+  // Mock Data
+  namespacesList = ['namespaces1', 'namespaces2'];
+  currentNamespaces = this.namespacesList[0];
+  notebookList = [
+    {
+      status: 'Running',
+      name: 'Notebook1',
+      age: '35 mins',
+      environment: 'image1',
+      cpu: '2',
+      gpu: '1',
+      memory: '512 MB',
+      volumes: 'volumes1'
+    },
+    {
+      status: 'Stop',
+      name: 'Notebook2',
+      age: '40 mins',
+      environment: 'image2',
+      cpu: '4',
+      gpu: '4',
+      memory: '1024 MB',
+      volumes: 'volumes2'
+    }
+  ];
 
-  ngOnInit() {
-    this.message.warning('Notebook is in developing', { nzDuration: 5000 });
+  constructor() {}
+
+  statusColor: { [key: string]: string } = {
+    Running: 'green',
+    Stop: 'blue'
+  };
 
-    this.searchForm = this.fb.group({
-      notebookName: [this.notebookName]
+  ngOnInit() {
+    this.notebookForm = new FormGroup({
+      notebookName: new FormControl(null, [Validators.required]),
+      namespaces: new FormControl(this.currentNamespaces, [Validators.required]),
+      environment: new FormControl('env1', [Validators.required]),
+      cpu: new FormControl(null, [Validators.required]),
+      gpu: new FormControl(null, [Validators.required]),
+      memory: new FormControl(null, [Validators.required])
     });
+    this.checkedList = [];
+    for (let i = 0; i < this.notebookList.length; i++) {
+      this.checkedList.push(false);
+    }
   }
 
-  edit(notebook) {
-    this.isEditing = true;
+  selectAllNotebook() {
+    for (let i = 0; i < this.checkedList.length; i++) {
+      this.checkedList[i] = this.checked;
+    }
   }
 
-  saveNotebook() {
-    this.isEditing = false;
-    this.message.success('Save notebook success!');
+  // TODO(kobe860219): Make a notebook run
+  runNotebook(data) {
+    data.status = 'Running';
   }
+
+  // TODO(kobe860219): Stop a running notebook
+  stopNotebook(data) {
+    data.status = 'Stop';
+  }
+
+  // TODO(kobe860219): Create new notebook
+  createNotebook() {}
+
+  // TODO(kobe860219): Delete notebook
+  deleteNotebook() {}
 }
diff --git a/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.module.ts b/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.module.ts
index a16ba05..6f2c732 100644
--- a/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.module.ts
+++ b/submarine-workbench/workbench-web-ng/src/app/pages/workbench/notebook/notebook.module.ts
@@ -22,18 +22,10 @@ import { NgModule } from '@angular/core';
 import { NotebookComponent } from './notebook.component';
 import { NotebookRoutingModule } from './notebook-routing.module';
 import { FormsModule, ReactiveFormsModule } from '@angular/forms';
-import { MonacoEditorModule } from 'ngx-monaco-editor';
 import { NgZorroAntdModule } from 'ng-zorro-antd';
 
 @NgModule({
   declarations: [NotebookComponent],
-  imports: [
-    CommonModule,
-    NotebookRoutingModule,
-    MonacoEditorModule,
-    FormsModule,
-    ReactiveFormsModule,
-    NgZorroAntdModule
-  ]
+  imports: [CommonModule, NotebookRoutingModule, FormsModule, ReactiveFormsModule, NgZorroAntdModule]
 })
 export class NotebookModule {}


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@submarine.apache.org
For additional commands, e-mail: dev-help@submarine.apache.org