Skip to content

Commit 50efb81

Browse files
committed
Convert some classes to TypeScript
1 parent dbc3003 commit 50efb81

File tree

5 files changed

+67
-68
lines changed

5 files changed

+67
-68
lines changed

src/components/cylc/workspace/lumino-widget.js renamed to src/components/cylc/workspace/lumino-widget.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { Widget } from '@lumino/widgets'
1919
import { eventBus } from '@/services/eventBus'
20+
import { type Message } from '@lumino/messaging'
2021

2122
/**
2223
* This is a valid Lumino widget, that contains only a dummy div
@@ -31,33 +32,33 @@ import { eventBus } from '@/services/eventBus'
3132
export default class LuminoWidget extends Widget {
3233
/**
3334
* Create a LuminoWidget object.
34-
* @param {string} id - unique ID of the widget
35-
* @param {string} name - text displayed in the widget tab
36-
* @param {boolean} closable - flag that controls whether the tab can be
37-
* closed or not
35+
* @param id - unique ID of the widget
36+
* @param name - text displayed in the widget tab
37+
* @param closable - flag that controls whether the tab can be closed or not
3838
*/
39-
constructor (id, name, closable = true) {
39+
constructor (
40+
id: string,
41+
public name: string,
42+
public readonly closable: boolean = true
43+
) {
4044
super({ node: LuminoWidget.createNode(id) })
4145
this.id = id
42-
this.name = name
43-
this.closable = closable
4446
// classes and flags
4547
this.setFlag(Widget.Flag.DisallowLayout)
4648
this.addClass('content')
4749
}
4850

4951
/**
5052
* Return a dummy div to be used as parent for the Vue component element.
51-
* @param {string} id - widget id
52-
* @return {HTMLElement}
53+
* @param id - widget id
5354
*/
54-
static createNode (id) {
55+
static createNode (id: string): HTMLElement {
5556
const div = document.createElement('div')
5657
div.setAttribute('id', id)
5758
return div
5859
}
5960

60-
onBeforeAttach (msg) {
61+
onBeforeAttach (msg: Message) {
6162
// Set tab title as this is not handled automatically for some reason.
6263
// NOTE: We do this in the onBeforeAttach hook rather than in the constructor
6364
// because the constructor does not get called when we restore layout to the
@@ -76,13 +77,13 @@ export default class LuminoWidget extends Widget {
7677
// super.onActivateRequest(msg)
7778
// }
7879

79-
onCloseRequest (msg) {
80+
onCloseRequest (msg: Message) {
8081
// Emit an event so that the Vue component knows that it needs to be removed too
8182
eventBus.emit('lumino:deleted', this.id)
8283
super.onCloseRequest(msg)
8384
}
8485

85-
onAfterShow (msg) {
86+
onAfterShow (msg: Message) {
8687
// Emit an event so that the Vue component knows that this widget is visible again
8788
eventBus.emit(`lumino:show:${this.id}`)
8889
super.onAfterShow(msg)

src/model/Alert.model.js renamed to src/model/Alert.model.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717

1818
/** Alert model */
1919
export class Alert {
20-
/**
21-
* @param {Error|string} err - original thrown error to log if possible, or an error message.
22-
* @param {string} color - color of the displayed alert.
23-
* @param {?string} msg - a custom message to display in the alert instead of err.
24-
*/
25-
constructor (err, color, msg = null) {
26-
this.err = err
20+
/** The text content of the displayed alert. */
21+
text: string | Error
22+
23+
constructor (
24+
/** Original thrown error to log if possible, or an error message. */
25+
public err: Error | string,
26+
/** Color of the displayed alert. */
27+
public color: string,
28+
/** A custom message to display in the alert instead of err. */
29+
msg?: string
30+
) {
2731
this.text = msg || err
28-
this.color = color
2932
}
3033
}

src/model/User.model.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/model/User.model.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
export default class User {
19+
constructor (
20+
/** The authenticated user (full info only available when authenticated
21+
* via the hub) */
22+
public username: string,
23+
/** User groups */
24+
public groups: string[],
25+
/** Date when the user was created */
26+
public created: string,
27+
/** Whether the user is an administrator or not */
28+
public admin: boolean,
29+
/** Server URL */
30+
public server: string,
31+
/** UIS owner (the user whose workflows we are looking at) (this might not
32+
* be the authenticated user for multi-user setups) */
33+
public owner: string,
34+
/** List of permissions */
35+
public permissions: string[],
36+
public mode: 'single user' | 'multi user',
37+
/** User initials */
38+
public initials: string
39+
) {
40+
this.server ||= '?' // server can be unset
41+
}
42+
}
File renamed without changes.

0 commit comments

Comments
 (0)