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
4 changes: 2 additions & 2 deletions src/app/admin/api-keys/api-keys.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Clipboard } from '@angular/cdk/clipboard';

import { Component, OnInit, inject } from '@angular/core';
import { i18n } from '../../common/locale.service';
import { notifyInfo } from '../../common/notifications';
import { notifySuccess } from '../../common/notifications';
import { IconComponent } from '../../ui/icon.component';
import { DateFromPipe } from '../../ui/pipes/date-from.pipe';
import { SimpleTableComponent } from '../../ui/simple-table.component';
Expand Down Expand Up @@ -244,6 +244,6 @@ export class AdminAPIKeysComponent implements OnInit {
const key = this.last_key();
if (!key?.x_api_key) return;
this._clipboard.copy(key.x_api_key);
notifyInfo(i18n('ADMIN.APP_KEYS_COPIED'));
notifySuccess(i18n('ADMIN.APP_KEYS_COPIED'));
}
}
19 changes: 10 additions & 9 deletions src/app/admin/database-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { readError } from '../common/errors';
import { downloadFile, jsonToCsv, parseCSV } from '../common/general';
import {
notifyError,
notifyInfo,
notifySuccess,
notifyWarn,
} from '../common/notifications';
Expand Down Expand Up @@ -289,7 +290,7 @@ export class PlaceDatabaseDetailsComponent
this._watchMqttStatus();
} catch (err) {
if ((err as Response)?.status === 409) {
notifyWarn('An MQTT re-sync is already running.');
notifyInfo('An MQTT re-sync is already running.');
this._loadMqttStatus();
} else {
notifyError(
Expand Down Expand Up @@ -426,7 +427,7 @@ export class PlaceDatabaseDetailsComponent

private async importZoneTree(zones: ZoneTreeExportItem[]) {
if (!(zones instanceof Array) || !zones.length) {
notifyWarn('Invalid zone tree CSV file.');
notifyError('Invalid zone tree CSV file.');
return;
}
const pending = zones.filter((zone) => !!zone.id);
Expand Down Expand Up @@ -485,12 +486,12 @@ export class PlaceDatabaseDetailsComponent
return;
}
const skipped = pending.length - created;
notifySuccess(
`Imported ${created} zones.${
skipped
? ` Skipped ${skipped} zones with circular parent ids.`
: ''
}`,
);
if (skipped) {
notifyWarn(
`Imported ${created} zones. Skipped ${skipped} zones with circular parent ids.`,
);
} else {
notifySuccess(`Imported ${created} zones.`);
}
}
}
4 changes: 2 additions & 2 deletions src/app/admin/details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit, inject, signal } from '@angular/core';
import { apiEndpoint, get } from '@placeos/ts-client';

import { VERSION } from '../../env/version';
import { notifyError, notifyInfo } from '../common/notifications';
import { notifyError, notifySuccess } from '../common/notifications';
import {
ChangelogModalComponent,
ChangelogModalData,
Expand Down Expand Up @@ -239,7 +239,7 @@ export class PlaceDetailsComponent implements OnInit {

public copy(name: string, content: string) {
copyToClipboard(content);
notifyInfo(i18n('ADMIN.COPIED', { name }));
notifySuccess(i18n('ADMIN.COPIED', { name }));
}

public async loadApiDetails() {
Expand Down
4 changes: 2 additions & 2 deletions src/app/admin/resource-imports.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { escapeHtml } from '../common/general';
import { i18n } from '../common/locale.service';
import {
notifyError,
notifyInfo,
notifySuccess,
notifyWarn,
} from '../common/notifications';
import { collectPages } from '../common/support-access';
import { openConfirmModal } from '../overlays/confirm-modal.component';
Expand Down Expand Up @@ -208,7 +208,7 @@ export class ResourceImportsComponent implements OnInit {
const list = this.resource_list();
const missing = list.filter((_) => !_.imported);
if (!missing.length) {
return notifyWarn(i18n('ADMIN.RESOURCE_IMPORTS_ALL_WARNING'));
return notifyInfo(i18n('ADMIN.RESOURCE_IMPORTS_ALL_WARNING'));
}
const resp = await openConfirmModal(
{
Expand Down
8 changes: 2 additions & 6 deletions src/app/admin/upload-library.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import { AsyncHandler } from '../common/async-handler.class';
import { readError } from '../common/errors';
import { escapeHtml } from '../common/general';
import { i18n } from '../common/locale.service';
import {
notifyError,
notifyInfo,
notifySuccess,
} from '../common/notifications';
import { notifyError, notifySuccess } from '../common/notifications';
import { UploadsService } from '../common/uploads.service';
import { confirmAndRun } from '../overlays/confirm-modal.component';
import { FormFieldComponent } from '../ui/controls/form-field.component';
Expand Down Expand Up @@ -337,7 +333,7 @@ export class UploadLibraryComponent extends AsyncHandler implements OnInit {
this._clipboard.copy(
`${location.protocol}//${location.host}/api/engine/v2/uploads/${upload.id}/url`,
);
notifyInfo(`Copied upload URL to clipboard.`);
notifySuccess(`Copied upload URL to clipboard.`);
}

/** Upload the image to the cloud */
Expand Down
8 changes: 8 additions & 0 deletions src/app/common/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export interface Toast {
on_action: () => void;
}

/*
* Which toast to use:
* - `notifySuccess`: the action the user asked for is done, e.g. saved or copied
* - `notifyInfo`: nothing changed or there is nothing to do, e.g. no update available
* - `notifyWarn`: the action is done, but with a problem the user must know about
* - `notifyError`: the action failed or was stopped
*/

/** Most toasts on screen at once. Older toasts are removed first */
export const MAX_TOASTS = 3;
/** Time a toast stays on screen. Errors stay until dismissed */
Expand Down
4 changes: 2 additions & 2 deletions src/app/domains/domain-applications.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PlaceApplication, PlaceDomain } from '@placeos/ts-client';

import { copyToClipboard } from '../common/general';
import { i18n } from '../common/locale.service';
import { notifyInfo } from '../common/notifications';
import { notifySuccess } from '../common/notifications';
import { HashMap } from '../common/types';
import { ProgressBarComponent } from '../ui/controls/progress-bar.component';
import { TooltipDirective } from '../ui/controls/tooltip.directive';
Expand Down Expand Up @@ -220,7 +220,7 @@ export class DomainApplicationsComponent {
public copySecret(item: PlaceApplication) {
this.setShowSecret(item.id, false);
copyToClipboard(item.secret);
notifyInfo(i18n('DOMAINS.COPIED_SECRET'));
notifySuccess(i18n('DOMAINS.COPIED_SECRET'));
}

public setShowSecret(id: string, value: boolean): void {
Expand Down
6 changes: 3 additions & 3 deletions src/app/domains/domain-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { form, FormField } from '@angular/forms/signals';
import { addDomain, PlaceDomain, updateDomain } from '@placeos/ts-client';
import { mergeFormItem, onSaveHotkey, submitFormDialog } from '../common/forms';
import { i18n } from '../common/locale.service';
import { notifyWarn } from '../common/notifications';
import { notifyError } from '../common/notifications';
import { DialogEvent } from '../common/types';
import { isValidDomain } from '../common/validation';
import { ChipListComponent } from '../ui/controls/chip-list.component';
Expand Down Expand Up @@ -224,14 +224,14 @@ export class DomainFormComponent {

/**
* Update the email domains from the chip list.
* New items that are not valid domains are dropped with a warning.
* New items that are not valid domains are dropped with an error.
*/
public setEmailDomains(list: string[]) {
const current = this.formModel().email_domains;
const email_domains = list.filter(
(item) => current.includes(item) || isValidDomain(item),
);
if (email_domains.length < list.length) notifyWarn('Invalid email');
if (email_domains.length < list.length) notifyError('Invalid email');
this.formModel.update((value) => ({ ...value, email_domains }));
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/drivers/driver-about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AsyncPipe } from '@angular/common';
import { Component, inject } from '@angular/core';
import { RouterModule } from '@angular/router';
import { i18n } from '../common/locale.service';
import { notifyInfo } from '../common/notifications';
import { notifySuccess } from '../common/notifications';
import { SpinnerComponent } from '../ui/controls/spinner.component';
import { TooltipDirective } from '../ui/controls/tooltip.directive';
import { SettingsFormComponent } from '../ui/forms/settings-form.component';
Expand Down Expand Up @@ -202,6 +202,6 @@ export class DriverAboutComponent {
public readonly item = this._service.item;
public copyCommit(): void {
this._clipboard.copy(this.item()?.commit || '');
notifyInfo(i18n('COMMON.COMMIT_HASH_COPIED'));
notifySuccess(i18n('COMMON.COMMIT_HASH_COPIED'));
}
}
8 changes: 6 additions & 2 deletions src/app/drivers/driver-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
import { describeError } from '../common/errors';
import { ActiveItemService } from '../common/item.service';
import { reportLoadError } from '../common/load-error';
import { notifyError, notifySuccess } from '../common/notifications';
import {
notifyError,
notifyInfo,
notifySuccess,
} from '../common/notifications';
import { collectPages } from '../common/support-access';
import { Identity } from '../common/types';
import { openConfirmModal } from '../overlays/confirm-modal.component';
Expand Down Expand Up @@ -92,7 +96,7 @@ export class DriverStateService {

public async updateDriver() {
const item = this._state.active_item as PlaceDriver;
if (!item.update_available) return notifyError('No update available.');
if (!item.update_available) return notifyInfo('No update available.');
const details = await openConfirmModal(
{
title: `Update Driver`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class BulkItemModalComponent<
*/
public handleList(data: HashMap<unknown>[], is_mapped = false): void {
if (!data.length) {
notifyWarn('No rows were found in the uploaded file.');
notifyError('No rows were found in the uploaded file.');
return;
}
if (is_mapped) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/overlays/bulk-item-modal/csv-upload.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, input, output, signal } from '@angular/core';

import { downloadFile, jsonToCsv, parseCSV } from '../../common/general';
import { notifyError, notifyWarn } from '../../common/notifications';
import { notifyError } from '../../common/notifications';
import { HashMap } from '../../common/types';
import { SpinnerComponent } from '../../ui/controls/spinner.component';
import { IconComponent } from '../../ui/icon.component';
Expand Down Expand Up @@ -152,7 +152,7 @@ export class CsvUploadComponent {
const list = parseCSV(data, seperator) || [];
this.loading = false;
if (!list.length) {
notifyWarn('No rows were found in the uploaded file.');
notifyError('No rows were found in the uploaded file.');
return;
}
this.list.emit(list);
Expand Down
10 changes: 3 additions & 7 deletions src/app/overlays/confirm-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import { DIALOG_DATA, Dialog, DialogRef } from '@angular/cdk/dialog';
import { lastValueFrom } from 'rxjs';
import { describeError, readError } from '../common/errors';
import { i18n } from '../common/locale.service';
import {
notifyError,
notifyInfo,
notifySuccess,
} from '../common/notifications';
import { notifyError, notifySuccess } from '../common/notifications';
import { waitForEvent } from '../common/signals';
import { ApplicationIcon, DialogEvent } from '../common/types';
import { DialogCloseDirective } from '../ui/controls/dialog';
Expand Down Expand Up @@ -594,7 +590,7 @@ export class ConfirmModalComponent implements OnInit {
/** Copy a single resource id to the clipboard */
public copyId(id: string) {
this._clipboard.copy(id);
notifyInfo(i18n('COMMON.COPIED_ID'));
notifySuccess(i18n('COMMON.COPIED_ID'));
}

/** Copy the whole receipt as TSV, for pasting into a ticket */
Expand All @@ -606,7 +602,7 @@ export class ConfirmModalComponent implements OnInit {
(receipt.failed || []).length +
(receipt.skipped || []).length;
this._clipboard.copy(receiptToTsv(receipt));
notifyInfo(i18n('CASCADE.RECEIPT_COPIED', { count }, count));
notifySuccess(i18n('CASCADE.RECEIPT_COPIED', { count }, count));
}

/** User confirmation of the content of the modal */
Expand Down
4 changes: 2 additions & 2 deletions src/app/systems/system-triggers.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, computed, inject, model } from '@angular/core';
import { PlaceTrigger } from '@placeos/ts-client';
import { copyToClipboard, unique } from '../common/general';
import { notifyInfo } from '../common/notifications';
import { notifySuccess } from '../common/notifications';

import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
Expand Down Expand Up @@ -248,7 +248,7 @@ export class SystemTriggersComponent {
copyToClipboard(
`${location.origin}/api/engine/v2/webhook/${t.id}/notify?secret=${t.webhook_secret}`,
);
notifyInfo(i18n('SYSTEMS.COPIED_WEBHOOK'));
notifySuccess(i18n('SYSTEMS.COPIED_WEBHOOK'));
};
// The service reloads the trigger list after each change
public readonly editTrigger = (t) => this._service.editTrigger(t);
Expand Down
21 changes: 21 additions & 0 deletions src/app/ui/controls/toast-outlet.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ import {
ViewContainerRef,
} from '@angular/core';
import { dismissToast, Toast, toasts } from '../../common/notifications';
import { ApplicationIcon } from '../../common/types';
import { IconComponent } from '../icon.component';

/** Icon for each toast type. Other types use the info icon */
const TOAST_ICONS: Readonly<Record<string, ApplicationIcon>> = {
success: { content: 'done' },
info: { content: 'info' },
error: { content: 'error' },
warn: { content: 'warning' },
warning: { content: 'warning' },
pending: { content: 'pending' },
};

/**
* Shows the toasts made with `notify()` and its variants.
Expand All @@ -32,6 +44,9 @@ import { dismissToast, Toast, toasts } from '../../common/notifications';
[class]="toast.type"
animate.leave="toast-leave"
>
<div class="toast-icon">
<icon [icon]="iconFor(toast.type)" />
</div>
<span class="toast-message">{{ toast.message }}</span>
@if (toast.action) {
<button type="button" (click)="act(toast)">
Expand All @@ -43,6 +58,7 @@ import { dismissToast, Toast, toasts } from '../../common/notifications';
</div>
</ng-template>
`,
imports: [IconComponent],
})
export class ToastOutletComponent {
private readonly _overlay = inject(Overlay);
Expand Down Expand Up @@ -89,6 +105,11 @@ export class ToastOutletComponent {
inject(DestroyRef).onDestroy(() => this._overlay_ref.dispose());
}

/** Icon to show at the start of a toast of the given type */
public iconFor(type: string) {
return TOAST_ICONS[type] ?? TOAST_ICONS['info'];
}

public act(toast: Toast) {
toast.on_action();
dismissToast(toast.id);
Expand Down
4 changes: 2 additions & 2 deletions src/app/ui/custom-fields/image-list-field.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';

import { AsyncHandler } from '../../common/async-handler.class';
import { unique } from '../../common/general';
import { notifyInfo } from '../../common/notifications';
import { notifySuccess } from '../../common/notifications';
import { UploadDetails } from '../../common/uploads';
import { UploadsService } from '../../common/uploads.service';
import { AuthenticatedImageDirective } from '../authenticated-image.directive';
Expand Down Expand Up @@ -280,7 +280,7 @@ export class ImageListFieldComponent

public copyLink(url: string) {
this._clipboard.copy(url);
notifyInfo('Copied image URL to clipboard');
notifySuccess('Copied image URL to clipboard');
}

public viewImage(_url: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class ExecuteMethodFieldComponent implements ControlValueAccessor {
});
if (failed) return;
notifySuccess(
'Command successful executed.\nView Response?',
'Command successfully executed.\nView Response?',
'View',
() => this.viewDetails(result),
);
Expand Down
4 changes: 2 additions & 2 deletions src/app/ui/item-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PlaceDriverRole } from '@placeos/ts-client';
import { downloadFile, jsonToCsv } from '../common/general';
import { ActiveItemService } from '../common/item.service';
import { i18n } from '../common/locale.service';
import { notifyInfo } from '../common/notifications';
import { notifySuccess } from '../common/notifications';
import { MENU_POSITIONS } from './controls/overlay';
import { TooltipDirective } from './controls/tooltip.directive';
import { IconComponent } from './icon.component';
Expand Down Expand Up @@ -245,7 +245,7 @@ export class ItemDetailsComponent {

public readonly copyID = () => {
this._clipboard.copy(this.item()?.id || '');
notifyInfo(i18n('COMMON.COPIED_ID'));
notifySuccess(i18n('COMMON.COPIED_ID'));
};

/** Open modal to edit the active item */
Expand Down
Loading
Loading