Commit bc8376ab by Ooh-Ao

linker success

parent 03e89323
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { map, catchError } from 'rxjs/operators'; // Removed tap
import { MenuItemsWidget } from '../models/m-menuitems-widget.model';
......@@ -55,9 +55,14 @@ export class MMenuitemsWidgetService {
* @param itemId The itemId of the MenuItemsWidget to delete.
* @returns An Observable indicating success.
*/
deleteLinkedWidget(itemId: string): Observable<any> {
// Assuming DELETE /mmenuitems-widget expects itemId as a query parameter
return this.http.delete<any>(this.baseUrl, { params: { itemId } }).pipe(
deleteLinkedWidget(menuItem: MenuItemsWidget): Observable<any> {
const options = {
headers: new HttpHeaders({
"Content-Type": "application/json",
}),
body: menuItem
};
return this.http.delete<any>(this.baseUrl, options).pipe(
catchError(error => {
console.error('Error deleting linked widget:', error);
throw error; // Re-throw to propagate error
......
......@@ -147,7 +147,7 @@ export class DatasetWidgetLinkerComponent implements OnInit {
}
this.selectedDatasetId = event.value;
console.log('Dataset selection changed. New ID:', this.selectedDatasetId);
this.clearPreview();
if (this.selectedDatasetId) {
this.loadLinkedWidgetsForDataset(this.selectedDatasetId);
......@@ -209,7 +209,7 @@ export class DatasetWidgetLinkerComponent implements OnInit {
// Persist the changes to the backend
this.mMenuitemsWidgetService.saveLinkedWidget(this.widgetToPreview!).subscribe(() => {
this.notificationService.success('Success', 'Configuration saved successfully!');
// Re-trigger the data fetch in the state service to get fresh data
this.dashboardStateService.selectDataset(this.selectedDatasetId!);
......@@ -224,7 +224,7 @@ export class DatasetWidgetLinkerComponent implements OnInit {
removeWidget(widget: MenuItemsWidget, event: MouseEvent): void {
event.stopPropagation();
if (confirm('Are you sure you want to unlink this widget?')) {
this.mMenuitemsWidgetService.deleteLinkedWidget(widget.itemId).subscribe(() => {
this.mMenuitemsWidgetService.deleteLinkedWidget(widget).subscribe(() => {
this.notificationService.success('Success', 'Widget unlinked successfully!');
if (this.widgetToPreview?.itemId === widget.itemId) {
this.clearPreview();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment