Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export class MyComponent extends AsyncHandler {
- Supports multiple locales (see `app.locales` in settings)
- Service worker support for PWA functionality (production builds)
- Custom localization support via `public/assets/locale`, **TranslatePipe** and **LocaleService**. `en-AU.json` is the fallback locale
- Use **IconComponent** for icons
- Use **IconComponent** for icons. The default icon font is a subset of the icons in the source. After you add icons, run `bun config/icon-subset.ts` (needs `pip install fonttools brotli`). An icon that is not in the subset still shows, but it loads the full 420 KB font
- `src/index.html` has a splash that shows until the app loads. Lighthouse measures its title as the largest contentful paint, so keep the title larger than the content of the first page
- Use `feat/*`, `fix/*`, `perf/*`, or `refactor/*` for branch names

## Code styles
Expand Down
6 changes: 3 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions config/icon-subset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Make the subset of the Material Symbols Rounded font that the app uses.
*
* The full font is about 420 KB. The app uses a few hundred of its icons, so
* the first page load gets a small subset font. IconComponent switches to the
* full font for names that are not in the subset (e.g. icons from server
* settings), so a missing name costs a download, not a broken icon.
*
* Run this when you add icons: `bun config/icon-subset.ts`
* It needs fontTools: `pip install fonttools brotli`
*/
import { $, Glob } from 'bun';

const FONT = 'src/fonts/material-symbols-rounded.woff2';
const SUBSET = 'src/fonts/material-symbols-rounded-subset.woff2';
const NAMES = 'src/app/ui/icon-subset.ts';

/** Names of the glyphs in the full font */
async function fontGlyphs() {
const out =
await $`python3 -c ${'import sys; from fontTools.ttLib import TTFont; print("\\n".join(TTFont(sys.argv[1]).getGlyphOrder()))'} ${FONT}`.text();
return new Set(out.split('\n').filter(Boolean));
}

/** Words in the source that could be icon names */
async function sourceWords() {
const words = new Set<string>();
// Text inside icon elements, e.g. <icon>add</icon> or <icon>{{ a ? 'b' : 'c' }}</icon>
const icon_tags =
/<(?:icon|app-icon)\b[^>]*>([\s\S]*?)<\/(?:icon|app-icon)>/g;
// Icon objects and inputs, e.g. { content: 'add' } or icon: 'add'
const icon_props = /\b(?:content|icon)\s*:\s*['"`]([a-z0-9_]+)['"`]/g;
for await (const file of new Glob('src/app/**/*.ts').scan()) {
if (file.includes('/mocks/')) continue;
const text = await Bun.file(file).text();
for (const [, inner] of text.matchAll(icon_tags)) {
for (const [word] of inner.matchAll(/[a-z0-9_]+/g)) words.add(word);
}
for (const [, word] of text.matchAll(icon_props)) words.add(word);
}
return words;
}

const glyphs = await fontGlyphs();
// Single letters and digits are glyphs too, but not icons
const icons = [...(await sourceWords())]
.filter((w) => w.length > 1 && glyphs.has(w))
.sort();
// Letters and digits are the input of the icon ligatures
const text = 'abcdefghijklmnopqrstuvwxyz0123456789_';
// No layout closure, so only the ligatures of the kept icons stay
await $`python3 -m fontTools.subset ${FONT} --output-file=${SUBSET} --flavor=woff2 --text=${text} --glyphs=${icons.join(',')} --layout-features=rlig --no-layout-closure --no-hinting --desubroutinize`;
await Bun.write(
NAMES,
`// Generated by config/icon-subset.ts. Do not edit.\n\n/** Icons in the subset icon font */\nexport const ICON_SUBSET: ReadonlySet<string> = new Set(${JSON.stringify(icons, null, 4).replace(/"/g, "'")});\n`,
);
await $`bunx prettier --write ${NAMES}`.quiet();
console.log(
`${icons.length} icons, ${(Bun.file(SUBSET).size / 1024).toFixed(1)} KB`,
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@angular/language-service": "22.2.3",
"@angular/material": "22.2.4",
"@eslint/js": "^9.8.0",
"@fontsource-variable/fira-code": "^5.3.0",
"@fontsource-variable/roboto": "^5.3.0",
"@nx/angular": "23.3.0",
"@nx/devkit": "23.3.0",
Expand Down Expand Up @@ -70,7 +71,6 @@
"eslint": "^9.8.0",
"eslint-config-prettier": "^10.0.0",
"eslint-plugin-playwright": "^1.6.2",
"firacode": "^6.2.0",
"git-describe": "^4.1.1",
"jiti": "2.4.2",
"js-yaml": "^4.1.1",
Expand Down
2 changes: 1 addition & 1 deletion project.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"./node_modules/@fontsource-variable/roboto/index.css",
"./node_modules/@fontsource-variable/roboto/wght-italic.css",
"./src/fonts/material-symbols.css",
"./node_modules/firacode/distr/fira_code.css",
"./node_modules/@fontsource-variable/fira-code/index.css",
"./src/styles.css",
"./src/material-theme.scss"
]
Expand Down
21 changes: 21 additions & 0 deletions public/llms.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# PlaceOS Backoffice

> Backoffice is the administration app of PlaceOS, a building automation platform. Administrators use it to manage the systems, modules, drivers, zones, triggers, domains and users of a PlaceOS instance. All pages need a PlaceOS account with admin or support access.

The app has no public content. Use the documentation and the API references below to learn about PlaceOS and Backoffice.

## Documentation

- [Backoffice overview](https://docs.placeos.com/placeos/overview/backoffice/): What Backoffice is and what each section does
- [PlaceOS overview](https://docs.placeos.com/placeos/overview/): The parts of PlaceOS and how they connect
- [Add a domain](https://docs.placeos.com/placeos/how-to/backoffice/add-domain/): Set up a new domain in Backoffice
- [PlaceOS reference](https://docs.placeos.com/placeos/reference/): Reference material for PlaceOS

## API

- [PlaceOS REST API](https://placeos.github.io/rest-api-swagger-ui/): The engine API that Backoffice uses
- [Staff API](https://placeos.github.io/staff-api-swagger-ui/): The API for bookings, events and staff

## Optional

- [Source code](https://github.com/PlaceOS/backoffice): The Backoffice repository on GitHub
2 changes: 2 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow:
21 changes: 6 additions & 15 deletions src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ function browserOnline() {
} @error {}
}
} @else {
<div
loader
class="absolute inset-0 z-50 flex items-center justify-center"
>
<!-- The splash from index.html shows behind the progress bar -->
<div class="absolute inset-0 z-50">
<div
class="border-base-300 absolute bottom-2 left-1/2 w-[24rem] -translate-x-1/2 overflow-hidden rounded-full border shadow"
>
Expand Down Expand Up @@ -135,17 +133,6 @@ function browserOnline() {
} @error {}
}
`,
styles: [
`
[loader] {
background-image: linear-gradient(
to right,
#c62828 0%,
#ef5350 100%
);
}
`,
],
imports: [
GlobalBannerComponent,
RouterOutlet,
Expand Down Expand Up @@ -228,6 +215,10 @@ export class AppComponent implements OnInit {
// TranslatePipe is pure, so load translations before the shell renders
await this._initLocale();
this.loading.set(false);
// Remove it late. Chrome does not record the paint of an element
// removed soon after it shows, which makes it miss the splash as
// the largest contentful paint.
document.getElementById('app-splash')?.remove();
this._router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
this.simple.set(this._router.url.includes('mqtt'));
Expand Down
13 changes: 13 additions & 0 deletions src/app/common/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ export function getItemWithKeys(
return null;
}

/**
* Move an array item from one index to another, in place.
* Same as `moveItemInArray` in `@angular/cdk/drag-drop`. State services use
* this copy, so pages that use them do not load the drag and drop code.
*/
export function moveItemInArray<T>(array: T[], from: number, to: number) {
const clamp = (i: number) => Math.max(0, Math.min(i, array.length - 1));
from = clamp(from);
to = clamp(to);
if (from === to) return;
array.splice(to, 0, ...array.splice(from, 1));
}

/**
* Remove duplicates from the given array
* @param array List of items to remove duplicates from
Expand Down
19 changes: 13 additions & 6 deletions src/app/common/item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import {
HashMap,
Identity,
} from '../common/types';
import { BulkItemModalComponent } from '../overlays/bulk-item-modal/bulk-item-modal.component';
import {
CONFIRM_METADATA,
// Modals load on demand to keep them out of the first page load
import type {
ConfirmModalComponent,
ConfirmModalData,
} from '../overlays/confirm-modal.component';
import { DuplicateModalComponent } from '../overlays/duplicate-modal.component';
import { BackofficeUsersService } from '../users/users.service';
import { ACTIONS, ItemActions } from './actions';
import { AsyncHandler } from './async-handler.class';
Expand Down Expand Up @@ -302,9 +300,12 @@ export class ActiveItemService extends AsyncHandler {
);
}

public bulkAdd() {
public async bulkAdd() {
if (!this.canMutate(2)) return;
const actions = this.actions;
const { BulkItemModalComponent } = await import(
'../overlays/bulk-item-modal/bulk-item-modal.component'
);
this._settings.post('disable_uploads', true);
const ref = this._dialog.open(BulkItemModalComponent, {
height: 'auto',
Expand Down Expand Up @@ -383,6 +384,9 @@ export class ActiveItemService extends AsyncHandler {
// Resolved lazily, only if the user enables the option — a cascade
// plan walks the whole zone subtree, which is not free.
let plan: CascadePlan | null = null;
const { CONFIRM_METADATA, ConfirmModalComponent } = await import(
'../overlays/confirm-modal.component'
);
const ref = this._dialog.open<ConfirmModalComponent, ConfirmModalData>(
ConfirmModalComponent,
{
Expand Down Expand Up @@ -591,10 +595,13 @@ export class ActiveItemService extends AsyncHandler {
});
}

public duplicate() {
public async duplicate() {
if (!this.canCopy(true)) return;
const item = this._active_item();
if (item) {
const { DuplicateModalComponent } = await import(
'../overlays/duplicate-modal.component'
);
const ref = this._dialog.open(DuplicateModalComponent, {
data: {
item: item as PlaceResource,
Expand Down
28 changes: 18 additions & 10 deletions src/app/systems/system-about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,24 @@ import { SystemStateService } from './system-state.service';
}
<hr class="text-base-300 my-4" />
@let other_settings_value = other_settings();
@if (item()?.settings && other_settings_value) {
<section>
<a-settings-form
[id]="item()?.id"
[merge]="true"
[settings]="item()?.settings"
[merge_settings]="other_settings_value || []"
/>
</section>
} @else {
<!-- The settings editor is large, so it loads with the settings -->
@defer (on immediate) {
@if (item()?.settings && other_settings_value) {
<section>
<a-settings-form
[id]="item()?.id"
[merge]="true"
[settings]="item()?.settings"
[merge_settings]="other_settings_value || []"
/>
</section>
} @else {
<div class="flex flex-col items-center justify-center p-8">
<mat-spinner class="mb-4" [diameter]="32" />
<p>{{ 'SYSTEMS.LOADING_SETTINGS' | translate }}</p>
</div>
}
} @placeholder {
<div class="flex flex-col items-center justify-center p-8">
<mat-spinner class="mb-4" [diameter]="32" />
<p>{{ 'SYSTEMS.LOADING_SETTINGS' | translate }}</p>
Expand Down
39 changes: 22 additions & 17 deletions src/app/systems/system-state.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { moveItemInArray } from '@angular/cdk/drag-drop';
import { computed, inject, resource, Service, signal } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import {
Expand Down Expand Up @@ -30,7 +29,7 @@ import {
import { calculateModuleIndex } from '../common/api';
import { AsyncHandler } from '../common/async-handler.class';
import { PlaceDebugService } from '../common/debug.service';
import { escapeHtml, unique } from '../common/general';
import { escapeHtml, moveItemInArray, unique } from '../common/general';
import { openedTabs } from '../common/opened-tabs';
import {
isSubsystemUser,
Expand All @@ -43,16 +42,18 @@ import { reportLoadError } from '../common/load-error';
import { notifyError, notifySuccess } from '../common/notifications';
import { waitForDialog } from '../common/signals';
import { HashMap, Identity } from '../common/types';
import {
ConfirmModalData,
openConfirmModal,
} from '../overlays/confirm-modal.component';
import {
// Modals load on demand to keep them out of the first page load
import type { ConfirmModalData } from '../overlays/confirm-modal.component';
import type {
SelectItemModalComponent,
SelectItemModalData,
} from '../overlays/select-item-modal.component';
import { ViewResponseModalComponent } from '../overlays/view-response-modal.component';
import { SystemTriggerFormComponent } from './system-trigger-form.component';

/** Load the item picker modal */
async function selectItemModal() {
const m = await import('../overlays/select-item-modal.component');
return m.SelectItemModalComponent;
}

@Service()
export class SystemStateService extends AsyncHandler {
Expand Down Expand Up @@ -394,7 +395,7 @@ export class SystemStateService extends AsyncHandler {
const ref = this._dialog.open<
SelectItemModalComponent,
SelectItemModalData
>(SelectItemModalComponent, {
>(await selectItemModal(), {
data: {
service_name: 'module to system',
query_fn: (_) =>
Expand Down Expand Up @@ -431,7 +432,7 @@ export class SystemStateService extends AsyncHandler {
const ref = this._dialog.open<
SelectItemModalComponent,
SelectItemModalData
>(SelectItemModalComponent, {
>(await selectItemModal(), {
data: {
service_name: 'Triggers',
query_fn: (_) =>
Expand Down Expand Up @@ -466,6 +467,9 @@ export class SystemStateService extends AsyncHandler {

public async editTrigger(trigger: PlaceTrigger) {
if (this.item() && trigger) {
const { SystemTriggerFormComponent } = await import(
'./system-trigger-form.component'
);
const ref = this._dialog.open(SystemTriggerFormComponent, {
data: {
item: trigger,
Expand Down Expand Up @@ -776,16 +780,17 @@ export class SystemStateService extends AsyncHandler {
}

/** View Results of the execute */
private viewDetails(content: unknown) {
this._dialog.open<ViewResponseModalComponent>(
ViewResponseModalComponent,
{
data: { content },
},
private async viewDetails(content: unknown) {
const { ViewResponseModalComponent } = await import(
'../overlays/view-response-modal.component'
);
this._dialog.open(ViewResponseModalComponent, { data: { content } });
}

private async confirm(data: ConfirmModalData) {
const { openConfirmModal } = await import(
'../overlays/confirm-modal.component'
);
return openConfirmModal(data, this._dialog);
}

Expand Down
Loading
Loading