export class SheetContentComponent implements OnInit {
constructor(protected databaseService: DatabaseService,
private dataService: DataService,
protected projectService: ProjectService) {
}
protected widgetType = WidgetType;
protected project: Project;
protected currentDashboardId: string;
protected user: User;
protected currentSheetId: string;
protected widgetPosition: GridsterItem;
protected currentWidgetId: string;
protected dashboard: Array<GridsterItem>;
ngOnInit(): void {
this.options = {
gridType: GridType.Fit,
displayGrid: DisplayGrid.Always,
compactType: CompactType.None,
margin: 10,
outerMargin: true,
minCols: 50,
maxCols: 200,
minRows: 50,
maxRows: 100,
pushItems: true,
pushDirections: {north: true, east: true, south: true, west: true},
pushResizeItems: true,
swap: true,
draggable: {
enabled: true,
stop: function (event, $element, widget) {
console.log("dragable");
this.saveInDatabase($element.el.id, event, 'position');
}
},
resizable: {
enabled: true,
stop: function (event, $element, widget) {
console.log("resizeable");
this.saveInDatabase($element.el.id, event, 'position');
}
}
};
}
/**
* This method saves the selected options into the database.
* @param widgetId the id of the widget to save
* @param value the value
* @param field the field where to store
*/
protected saveInDatabase(widgetId: string, value, field: string): void {
this.databaseService.updateDocument(this.databaseService.WIDGETSCOLLECTION, widgetId, new Fieldvalue(field, value))
.subscribe(result => {
}, error => {
console.log('Error updating database entry ', error);
});
}
<gridster #dashboardgrid [options]="options" class="widget-container" >
<gridster-item *ngFor="let widget of list" id="widget.id" [id]="widget.id" [item]="widget.position" class="gridster- design" (mouseup)="enablePointer(widget.id)">
<!-->more html stuff<-->
</gridster-item>
</gridster>