Skip to content

Commit dbe05d8

Browse files
committed
Custom versions
1 parent af10cc7 commit dbe05d8

File tree

2 files changed

+121
-32
lines changed

2 files changed

+121
-32
lines changed
+74-25
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,50 @@
1+
<span class="font-bold text-lg">Downloaded versions</span>
2+
<ul>
3+
@for (version of byondService.versions; track version[0]) {
4+
<li class="[&:not(:last-child)]:mb-2">
5+
<span class="mr-2">
6+
{{ version[0] }}
7+
@if (version[0] === byondService.activeVersion) {
8+
(Active)
9+
} @else {
10+
({{ statusToMessage[version[1]] }})
11+
}
12+
</span>
13+
@if (version[0] !== byondService.activeVersion) {
14+
<button
15+
tuiButton
16+
appearance="primary"
17+
size="xs"
18+
(click)="byondService.load(version[0], true)"
19+
class="mr-1.5"
20+
>
21+
Set active
22+
</button>
23+
}
24+
<button
25+
tuiButton
26+
appearance="secondary-destructive"
27+
size="xs"
28+
(click)="byondService.deleteVersion(version[0])"
29+
>
30+
Delete
31+
</button>
32+
</li>
33+
} @empty {
34+
<li>No versions</li>
35+
}
36+
</ul>
37+
38+
<span class="font-bold text-lg">Latest versions</span>
139
@if (byondService.latestVersion | async; as latestVersions) {
240
<p>
341
Latest stable: <span class="font-bold">{{ latestVersions.stable }}</span>
442
<button
543
tuiButton
644
size="xs"
745
(click)="byondService.getVersion(latestVersions.stable)"
46+
class="ml-2"
47+
[disabled]="byondService.versions.has(latestVersions.stable)"
848
>
949
Fetch
1050
</button>
@@ -16,6 +56,8 @@
1656
tuiButton
1757
size="xs"
1858
(click)="byondService.getVersion(latestVersions.beta)"
59+
class="ml-2"
60+
[disabled]="byondService.versions.has(latestVersions.beta)"
1961
>
2062
Fetch
2163
</button>
@@ -25,29 +67,36 @@
2567
Loading latest version...
2668
}
2769

28-
<ul>
29-
@for (version of byondService.versions; track version[0]) {
30-
{{ version[0] }}
31-
@if (version[0] === byondService.activeVersion) {
32-
(Active)
33-
} @else {
34-
({{ statusToMessage[version[1]] }})
35-
<button
36-
tuiButton
37-
appearance="primary"
38-
size="xs"
39-
(click)="byondService.setActive(version[0])"
40-
>
41-
Set active
42-
</button>
43-
}
44-
<button
45-
tuiButton
46-
appearance="secondary-destructive"
47-
size="xs"
48-
(click)="byondService.deleteVersion(version[0])"
70+
<span class="font-bold text-lg">Custom version</span>
71+
<form
72+
(ngSubmit)="this.byondService.getVersion(resolveVersion())"
73+
[formGroup]="this.form"
74+
class="flex flex-row"
75+
>
76+
<div class="flex-grow" tuiGroup>
77+
<tui-input-number
78+
[step]="1"
79+
decimal="never"
80+
formControlName="major"
81+
tuiTextfieldSize="s"
4982
>
50-
Delete
51-
</button>
52-
}
53-
</ul>
83+
Major version
84+
</tui-input-number>
85+
<tui-input-number
86+
[step]="1"
87+
decimal="never"
88+
formControlName="minor"
89+
tuiTextfieldSize="s"
90+
>
91+
Minor version
92+
</tui-input-number>
93+
</div>
94+
<button
95+
[disabled]="byondService.versions.has(resolveVersion())"
96+
class="ml-2"
97+
size="s"
98+
tuiButton
99+
>
100+
Fetch
101+
</button>
102+
</form>
+47-7
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,67 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
22
import { ByondService, VersionStatus } from '../../../vm/byond.service';
33
import { AsyncPipe } from '@angular/common';
4-
import { TuiButtonModule, TuiLoaderModule } from '@taiga-ui/core';
5-
import { TuiBadgeModule } from '@taiga-ui/kit';
4+
import {
5+
TuiButtonModule,
6+
TuiGroupModule,
7+
TuiLoaderModule,
8+
TuiTextfieldControllerModule,
9+
} from '@taiga-ui/core';
10+
import { TuiBadgeModule, TuiInputNumberModule } from '@taiga-ui/kit';
11+
import {
12+
FormControl,
13+
NonNullableFormBuilder,
14+
ReactiveFormsModule,
15+
} from '@angular/forms';
616

717
@Component({
818
selector: 'app-panel-byond',
919
standalone: true,
10-
imports: [AsyncPipe, TuiLoaderModule, TuiButtonModule, TuiBadgeModule],
20+
imports: [
21+
AsyncPipe,
22+
TuiLoaderModule,
23+
TuiButtonModule,
24+
TuiBadgeModule,
25+
TuiInputNumberModule,
26+
ReactiveFormsModule,
27+
TuiGroupModule,
28+
TuiTextfieldControllerModule,
29+
],
1130
templateUrl: './byond.component.html',
1231
styleUrl: './byond.component.scss',
1332
})
14-
export default class ByondPanel {
33+
export default class ByondPanel implements OnInit {
1534
// noinspection JSUnusedGlobalSymbols
1635
static title = 'BYOND versions';
1736

18-
constructor(protected byondService: ByondService) {}
37+
protected form;
38+
39+
constructor(
40+
protected byondService: ByondService,
41+
formBuilder: NonNullableFormBuilder,
42+
) {
43+
this.form = formBuilder.group({
44+
major: new FormControl(0),
45+
minor: new FormControl(0),
46+
});
47+
}
48+
49+
ngOnInit(): void {
50+
this.byondService.latestVersion.then(({ stable }) => {
51+
const [major, minor] = stable.split('.').map((x) => parseInt(x));
52+
this.form.setControl('major', new FormControl(major));
53+
this.form.setControl('minor', new FormControl(minor));
54+
});
55+
}
56+
57+
protected resolveVersion() {
58+
return `${this.form.value.major}.${this.form.value.minor}`;
59+
}
1960

2061
protected statusToMessage: Record<VersionStatus, string> = {
2162
[VersionStatus.Fetching]: 'Downloading...',
2263
[VersionStatus.Fetched]: 'Downloaded',
2364
[VersionStatus.Loading]: 'Loading...',
24-
[VersionStatus.Extracting]: 'Extracting...',
2565
[VersionStatus.Loaded]: 'Loaded',
2666
};
2767
}

0 commit comments

Comments
 (0)