Skip to content

Commit 83af673

Browse files
author
wg102
committed
feat: Add env variable to set language of the notebook server
Change Miscellanous Options to toggable Advanced Options Add select to choose language Add validation for language format
1 parent 0fba437 commit 83af673

File tree

8 files changed

+114
-18
lines changed

8 files changed

+114
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
<div class="group-wrapper" [formGroup]="parentForm">
2-
<h3>
2+
<input id="collapsible" class="toggle-advanced-options" type="checkbox">
3+
<label for="collapsible" class="lbl-toggle-advanced-options">
34
<fa-icon [icon]="['fas', 'cogs']" class="check"></fa-icon>
4-
{{ "formAdvancedOptions.h3MiscSettings" | translate }}
5-
</h3>
6-
<p>
7-
{{ "formAdvancedOptions.txtMiscSettings" | translate }}
8-
</p>
9-
10-
<mat-slide-toggle formControlName="shm">
11-
{{ "formAdvancedOptions.toggleSharedMemory" | translate }}
12-
</mat-slide-toggle>
5+
{{ "formAdvancedOptions.h3AdvancedSettings" | translate }}
6+
</label>
7+
<div class="collapsible-content">
8+
<div class="content-inner">
9+
<mat-slide-toggle formControlName="shm" class="matSpacing">
10+
{{ "formAdvancedOptions.toggleSharedMemory" | translate }}
11+
</mat-slide-toggle>
12+
<mat-form-field class="wide" appearance="outline">
13+
<mat-label>{{ "formAdvancedOptions.lblSystemLanguage" | translate }}</mat-label>
14+
<mat-select matNativeControl formControlName="language">
15+
<mat-option *ngFor="let v of languageList" [value]="v.id">
16+
{{ v.label | translate }}
17+
</mat-option>
18+
</mat-select>
19+
</mat-form-field>
20+
</div>
21+
</div>
1322
</div>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,60 @@
11
mat-slide-toggle {
22
margin-bottom: 0.6rem;
33
}
4+
5+
//Simulate the h3 heading for the title
6+
.lbl-toggle-advanced-options{
7+
color: rgba(0, 0, 0, 0.54);
8+
display: block;
9+
font-size: 1.17em;
10+
margin-block-start: 1em;
11+
margin-block-end: 1em;
12+
margin-inline-start: 0px;
13+
margin-inline-end: 0px;
14+
font-weight: bold;
15+
16+
transition: all 0.25s ease-out;
17+
cursor: pointer;
18+
}
19+
// Have the + sign
20+
.lbl-toggle-advanced-options::after {
21+
content: '\02795'; /* Unicode character for "plus" sign (+) */
22+
font-size: 0.8em;
23+
float: right;
24+
margin-left: 0.5em;
25+
transition: transform .2s ease-out;
26+
}
27+
// Have the - sign
28+
.toggle-advanced-options:checked + .lbl-toggle-advanced-options::after {
29+
content: "\2796"; /* Unicode character for "minus" sign (-) */
30+
}
31+
//Hide the checkbox
32+
.toggle-advanced-options[type='checkbox']{
33+
display: none;
34+
}
35+
.collapsible-content {
36+
max-height: 0px;
37+
overflow: hidden;
38+
transition: max-height .25s ease-in-out;
39+
}
40+
41+
.toggle-advanced-options:checked + .lbl-toggle-advanced-options + .collapsible-content {
42+
max-height: 100vh;
43+
}
44+
45+
.toggle-advanced-options:checked + .lbl-toggle-advanced-options {
46+
border-bottom-right-radius: 0;
47+
border-bottom-left-radius: 0;
48+
}
49+
50+
.collapsible-content .content-inner {
51+
border: 1px solid rgba(224, 224, 224, 0.45);
52+
border-bottom-left-radius: 7px;
53+
border-bottom-right-radius: 7px;
54+
padding: .5rem 1rem;
55+
}
56+
57+
.matSpacing {
58+
padding: 0.6em 0em;
59+
}
60+

frontend/src/app/resource-form/form-advanced-options/form-advanced-options.component.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component, OnInit, Input } from "@angular/core";
22
import { FormGroup } from "@angular/forms";
3+
import {TranslateService} from "@ngx-translate/core";
34

45
@Component({
56
selector: "app-form-advanced-options",
@@ -11,8 +12,14 @@ import { FormGroup } from "@angular/forms";
1112
})
1213
export class FormAdvancedOptionsComponent implements OnInit {
1314
@Input() parentForm: FormGroup;
15+
languageList = [
16+
{'id':'en', 'label':'formAdvancedOptions.lblEnglish'},
17+
{'id':'fr', 'label':'formAdvancedOptions.lblFrench'}
18+
];
1419

15-
constructor() {}
20+
constructor(private translate: TranslateService) {}
1621

17-
ngOnInit() {}
22+
ngOnInit() {
23+
this.parentForm.controls.language.setValue(this.translate.defaultLang);
24+
}
1825
}

frontend/src/app/utils/common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function getFormDefaults(): FormGroup {
3030
datavols: fb.array([]),
3131
shm: [true, []],
3232
configurations: [[], []],
33+
language: ['', [Validators.required]],
3334
});
3435
}
3536

frontend/src/assets/i18n/en.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@
4848
"deleteDialogNo": "Cancel"
4949
},
5050
"formAdvancedOptions": {
51-
"h3MiscSettings": "Miscellaneous Settings",
52-
"txtMiscSettings": "Other possible settings to be applied to the Notebook Server.",
53-
"toggleSharedMemory": "Enable Shared Memory"
51+
"h3AdvancedSettings": "Advanced Settings",
52+
"toggleSharedMemory": "Enable Shared Memory",
53+
"lblSystemLanguage":"System language",
54+
"lblEnglish": "English",
55+
"lblFrench": "Français"
5456
},
5557
"formConfiguration": {
5658
"h3Configuration": "Configurations",

frontend/src/assets/i18n/fr.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@
4848
"deleteDialogNo": "Annuler"
4949
},
5050
"formAdvancedOptions": {
51-
"h3MiscSettings": "Paramètres divers",
52-
"txtMiscSettings": "Autres paramètres pouvant être appliqué au serveur bloc-notes.",
53-
"toggleSharedMemory": "Activer la mémoire partagée"
51+
"h3AdvancedSettings": "Paramètres avancés",
52+
"toggleSharedMemory": "Activer la mémoire partagée",
53+
"lblSystemLanguage":"Langue du système",
54+
"lblEnglish": "English",
55+
"lblFrench": "Français"
5456
},
5557
"formConfiguration": {
5658
"h3Configuration": "Configurations",

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ k8s.io/apimachinery v0.18.6/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCk
363363
k8s.io/apimachinery v0.18.8 h1:jimPrycCqgx2QPearX3to1JePz7wSbVLq+7PdBTTwQ0=
364364
k8s.io/apimachinery v0.18.8/go.mod h1:6sQd+iHEqmOtALqOFjSWp2KZ9F0wlU/nWm0ZgsYWMig=
365365
k8s.io/apimachinery v0.19.2 h1:5Gy9vQpAGTKHPVOh5c4plE274X8D/6cuEiTO2zve7tc=
366+
k8s.io/apimachinery v0.20.1 h1:LAhz8pKbgR8tUwn7boK+b2HZdt7MiTu2mkYtFMUjTRQ=
366367
k8s.io/client-go v0.18.6 h1:I+oWqJbibLSGsZj8Xs8F0aWVXJVIoUHWaaJV3kUN/Zw=
367368
k8s.io/client-go v0.18.6/go.mod h1:/fwtGLjYMS1MaM5oi+eXhKwG+1UHidUEXRh6cNsdO0Q=
368369
k8s.io/code-generator v0.0.0-20200403215918-804a58607501/go.mod h1:UZPlxqFoDEMYYDJksMKLFggA4nK5Y3Nni//sVQggki4=

notebooks.go

+17
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package main
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"io/ioutil"
89
"log"
910
"net/http"
11+
"regexp"
1012
"sort"
1113
"strings"
1214

@@ -23,6 +25,7 @@ import (
2325
const DefaultServiceAccountName string = "default-editor"
2426
const SharedMemoryVolumeName string = "dshm"
2527
const SharedMemoryVolumePath string = "/dev/shm"
28+
const EnvKfLanguage string = "KF_LANG"
2629

2730
type volumetype string
2831

@@ -61,6 +64,7 @@ type newnotebookrequest struct {
6164
DataVolumes []volumerequest `json:"datavols"`
6265
EnableSharedMemory bool `json:"shm"`
6366
Configurations []string `json:"configurations"`
67+
Language string `json:"language"`
6468
}
6569

6670
type notebookresponse struct {
@@ -471,6 +475,19 @@ func (s *server) NewNotebook(w http.ResponseWriter, r *http.Request) {
471475
}
472476
}
473477

478+
//Add Language
479+
//Validate that the language format is valid (language[_territory])
480+
match, err := regexp.MatchString("^[[:alpha:]]{2}(_[[:alpha:]]{2})?$", req.Language)
481+
if (err != nil || !match) {
482+
var errLanguageFormat = errors.New("Error: the value of KF_LANG environment variable ('" + req.Language + "') is not a valid format (e.g 'en', 'en_US', ...)")
483+
s.error(w, r, errLanguageFormat)
484+
return
485+
}
486+
notebook.Spec.Template.Spec.Containers[0].Env = append(notebook.Spec.Template.Spec.Containers[0].Env, corev1.EnvVar{
487+
Name: EnvKfLanguage,
488+
Value: req.Language,
489+
})
490+
474491
log.Printf("creating notebook %q for %q", notebook.ObjectMeta.Name, namespace)
475492

476493
// Submit the notebook to the API server

0 commit comments

Comments
 (0)