Skip to content

Commit 54f0b96

Browse files
committed
Use ?script=true for editor page
API now requires ?script=true to fetch worker code. Added resolveWithScript for editor route.
1 parent 58cca03 commit 54f0b96

5 files changed

Lines changed: 33 additions & 9 deletions

File tree

bun.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openworkers-dash",
3-
"version": "1.2.4",
3+
"version": "1.4.0",
44
"license": "MIT",
55
"scripts": {
66
"ng": "ng",
@@ -36,7 +36,7 @@
3636
"@angular/build": "^21.1.1",
3737
"@angular/cli": "~21.1.1",
3838
"@angular/compiler-cli": "^21.1.1",
39-
"@openworkers/api-types": "1.2.1",
39+
"@openworkers/api-types": "^1.4.0",
4040
"@openworkers/workers-types": "^0.1.7",
4141
"@tailwindcss/postcss": "4.1.17",
4242
"@types/jasmine": "6.0.0",

src/app/modules/worker/pages/worker-edit/worker-edit.page.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ export default class WorkerEditPage implements OnInit, OnDestroy {
9595
);
9696

9797
this.theme$ = themeService.theme$;
98-
this.script = new FormControl(this.worker.script);
98+
this.script = new FormControl(this.worker.script!);
9999
this.options.theme = this.theme = themeService.isDark() ? 'vs-dark' : 'vs';
100-
this.options.language = this.worker.language;
100+
this.options.language = this.worker.language ?? undefined;
101101

102102
const env = this.worker.environment;
103103
let environmentId = env?.id ?? null;
@@ -107,7 +107,7 @@ export default class WorkerEditPage implements OnInit, OnDestroy {
107107
log.debug('Worker changed', worker);
108108
if (worker.script !== this.script.value) {
109109
log.debug('Script changed');
110-
this.script.setValue(worker.script);
110+
this.script.setValue(worker.script!);
111111
}
112112

113113
if (worker.environment?.id !== environmentId) {

src/app/modules/worker/worker.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { ActivatedRouteSnapshot } from '@angular/router';
2424
// Editor is not child of WorkerRootComponent because it needs to be full page
2525
{
2626
path: ':id/edit',
27-
resolve: { worker: (route: ActivatedRouteSnapshot) => inject(WorkersService).resolve(route) },
27+
resolve: { worker: (route: ActivatedRouteSnapshot) => inject(WorkersService).resolveWithScript(route) },
2828
canActivate: [UUIDGuard],
2929
loadComponent: () => import('./pages/worker-edit/worker-edit.page')
3030
},

src/app/services/workers.service.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { HttpClient } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
3-
import { map, mergeMap } from 'rxjs';
3+
import { ActivatedRouteSnapshot } from '@angular/router';
4+
import { first, map, mergeMap } from 'rxjs';
45
import type { IWorker, IWorkerCreateInput, IWorkerUpdateInput } from '@openworkers/api-types';
56
import { ResourceService } from './resource.service';
67

@@ -13,6 +14,29 @@ export class WorkersService extends ResourceService<IWorker, IWorkerCreateInput,
1314
super(http, 'workers');
1415
}
1516

17+
/**
18+
* Fetch worker with script included (for editor page).
19+
*/
20+
findByIdWithScript(id: string) {
21+
return this.http.get<IWorker>(`/api/v1/workers/${id}`, { params: { script: 'true' } }).pipe(
22+
map((data) => this.cacheAndWatch(data)),
23+
mergeMap((data) => data.asObservable())
24+
);
25+
}
26+
27+
/**
28+
* Resolver for editor page (includes script).
29+
*/
30+
resolveWithScript(route: ActivatedRouteSnapshot) {
31+
const id = route.paramMap.get('id');
32+
33+
if (!id) {
34+
throw new Error('Missing id');
35+
}
36+
37+
return this.findByIdWithScript(id).pipe(first());
38+
}
39+
1640
createCron(workerId: string, value: string) {
1741
return this.http.post<IWorker>(`/api/v1/workers/${workerId}/crons`, { expression: value }).pipe(
1842
map((data) => this.cacheAndWatch(data)),

0 commit comments

Comments
 (0)