1.0.4 • Published 5 days ago

@yuuvis/widget-grid v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
5 days ago

@yuuvis/widget-grid

Library for creating custom dashboards. Applications can use the provided WidgetGridRegistry to register widgets that then could be configured and placed by the user.

Usage

Import YuvWidgetGridModule into your app module:

import { YuvWidgetGridModule } from "@yuuvis/widget-grid";

@NgModule({
  imports: [YuvWidgetGridModule],
  bootstrap: [AppComponent],
})
export class AppModule {}

Add widget grid component to your template:

<!-- app.component.html -->
<yuv-widget-grid
  [gridItemConfig]="gridItemConfig"
  [editMode]="editMode"
  (gridItemEvent)="onGridEvent($event)"
  (gridChange)="onGridChange($event)"
></yuv-widget-grid>
InputTypeDescription
gridItemConfigWidgetGridItemConfig[]Array of widget grid items that will be rendered as tiles in the grid.
editModebooleanEnables/disables widget grids edit mode where you can move widgets around, resize or configure them
OutputemitsDescription
gridChangeWidgetGridItemConfig[]Emitted every time the configuration of the widget grid changes. If you for example enter edit mode and restructure your grid, those changes will be emitted here. You may then persist this config somewhere.
gridItemEventGridItemEventEvents emitted by the grids widgets. In order to communicate with your app, widgets can use those events. Fire them in the widget catch them here.

Workspaces

Beside a 'standalone' grid you could also use yuv-widget-grid-workspaces. This component handles multiple widget grids in so called workspaces.

<yuv-widget-grid-workspaces
  [workspaceConfig]="workspaceConfig"
  (gridItemEvent)="onGridEvent($event)"
  (configChange)="onWorkspacesConfigChange($event)"
></yuv-widget-grid-workspaces>
InputTypeDescription
workspaceConfigWidgetGridWorkspaceConfigConfiguration describing the current workspaces setup.
optionsWidgetGridWorkspaceOptionsOptions for setting up the workspaces component. May contain translations or custom labels as well as configurations for a workspace's widget grid.
OutputemitsDescription
configChangeWidgetGridWorkspaceConfigEmitted every time the workspace configuration changes.
gridItemEventGridItemEventEvents emitted by the grids widgets. In order to communicate with your app, widgets can use those events. Fire them in the widget catch them here.

Interfaces

export interface WidgetGridWorkspaceConfig {
  currentWorkspace?: string;
  workspaces: Array<WidgetGridWorkspace>;
}

export interface WidgetGridWorkspace {
  id: string;
  label: string;
  grid: WidgetGridItemConfig[];
}

export interface WidgetGridWorkspaceOptions {
  gridConfig?: Partial<WidgetGridConfig>;
}

export interface WidgetGridConfig {
  rows?: number;
  columns?: number;
  gap?: number;
}

export interface WidgetGridItemConfig extends GridsterItem {
  id: string;
  widgetName: string;
  widgetConfig: any;
}

export interface GridItemEvent {
  action: string;
  data: any;
}

Batteries (almost) not included

The widget grid is designed to be filled with custom widgets that fit your personal needs. But there are two widgets that are coming with the library. One is a simple To-Do list and the other one is a Picture widget. When playing around with this library you may want to try them out and continue from there.

// register the two "baked in" widgets 
this.widgetGridRegistry.registerGridWidgets([
  {
    name: "yuv.widget.picture",
    label: "Just a picture",
    setupComponent: PictureWidgetSetupComponent,
    widgetComponent: PictureWidgetComponent,
  },
  {
    name: "yuv.widget.todo",
    label: "Todo list",
    setupComponent: TodoWidgetSetupComponent,
    widgetComponent: TodoWidgetComponent,
  },
]);

Register widgets

Widgets are components that implement the IWidgetComponent interface. They then have to be registered using the WidgetGridRegistry:

// app.component.ts
ngOnInit(): void {
    this.widgetGridRegistry.registerGridWidget({
      label: 'Widget One',
      name: 'app.custom.widget.one',
      widgetComponent: WidgetOneComponent,
    });
    // widget with setup component
    this.widgetGridRegistry.registerGridWidget({
      label: 'Widget Two (with setup)',
      name: 'app.custom.widget.two',
      widgetComponent: WidgetTwoComponent,
      setupComponent: WidgetTwoSetupComponent,
    });
}

As you see in the example, widgets could also have a setup component. If your widget needs some kind of configuration, you can provide the component to set this up.

i18n

Labels used by the widget grid library can be replaced by custom ones. This could be used for internationalization. Once the user changes the language in your app you can use the widgetGridRegistry service to setup new labels:

this.widgetGridRegistry.updateWidgetGridLabels({
  workspacesEmptyMessage: "Bisher gibt es keine Arbeitsbereiche",
  newWorkspaceDefaultLabel: "Neuer Arbeitsbereich",
  workspaceRemoveConfirmMessage:
    'Soll der Arbeitsbereich "{{name}}" wirklich gelöscht werden?',
  workspaceEditDone: "Fertig",
});

You could also use this function to manage the labels of your custom widgets. Just call updateWidgetGridLabels({...}) with your key/value pairs and you are done. Inside your widgets subscribe to the labels$ observable from the WidgetGridRegistry service and use the values emitted there.

those are the default labels:

// yuv-widget-grid
{
  // headline of the widget picker
  widgetPickerTitle: 'Widgets',
  // label for the noop component (the component rendered when the widget configured is not registered)
  noopWidgetLabel: 'Not found',
  save: 'Save',
  cancel: 'Cancel',
}

// yuv-widget-grid-workspaces also adds the following keys and labels
{
  // shown when no workspace has been created so far
  workspacesEmptyMessage: 'No workspace so far.',
  // label of a newly created workspace
  newWorkspaceDefaultLabel: 'New Workspace',
  // confirm message when a user tries to delete a workspace
  workspaceRemoveConfirmMessage: 'Are you sure you want to remove "{{name}}"?',
  // label of the button that ends editing a workspace
  workspaceEditDone: 'Apply',
  confirm: 'OK',
}

You might also want to change the labels of your registered widgets once the user changes the apps language. This could be done by calling updateRegisteredWidgetsLabels()on the WidgetGridRegistry service:

this.widgetGridRegistry.updateRegisteredWidgetsLabels({
  "app.custom.widget.one": "Widget Nr.1",
  "app.custom.widget.two": "Widget Nr.2 (mit Setup)",
});
1.0.4

5 days ago

1.0.3

17 days ago

2.0.5

25 days ago

2.0.4

2 months ago

2.0.3

2 months ago

2.0.2

2 months ago

2.0.1

2 months ago

2.0.0

3 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

6 months ago

0.4.5

9 months ago

0.4.4

9 months ago

0.4.6

8 months ago

0.4.3

10 months ago

0.4.1

11 months ago

0.4.2

11 months ago

0.3.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.18

1 year ago

0.1.15

1 year ago

0.1.14

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago