Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
portal-apps-manage
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
angular
portal-apps-manage
Commits
80a409fc
Commit
80a409fc
authored
Sep 08, 2025
by
Ooh-Ao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save
parent
ddc61c27
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
4 deletions
+103
-4
dashboard-management.component.ts
...ge/dashboard-management/dashboard-management.component.ts
+11
-1
widget-state.service.ts
src/app/portal-manage/services/widget-state.service.ts
+41
-0
syncfusion-datagrid-widget.component.ts
...n-datagrid-widget/syncfusion-datagrid-widget.component.ts
+51
-3
No files found.
src/app/portal-manage/dashboard-management/dashboard-management.component.ts
View file @
80a409fc
...
@@ -14,6 +14,7 @@ import { MenuItemsWidget } from '../models/m-menuitems-widget.model';
...
@@ -14,6 +14,7 @@ import { MenuItemsWidget } from '../models/m-menuitems-widget.model';
import
{
DashboardDataService
}
from
'../services/dashboard-data.service'
;
import
{
DashboardDataService
}
from
'../services/dashboard-data.service'
;
import
{
MMenuitemsWidgetService
}
from
'../services/m-menuitems-widget.service'
;
import
{
MMenuitemsWidgetService
}
from
'../services/m-menuitems-widget.service'
;
import
{
DashboardStateService
,
SelectedDataset
}
from
'../services/dashboard-state.service'
;
import
{
DashboardStateService
,
SelectedDataset
}
from
'../services/dashboard-state.service'
;
import
{
WidgetStateService
}
from
'../services/widget-state.service'
;
// Import WidgetStateService
import
{
WidgetConfigComponent
}
from
'./widget-config/widget-config.component'
;
import
{
WidgetConfigComponent
}
from
'./widget-config/widget-config.component'
;
...
@@ -100,6 +101,7 @@ export class DashboardManagementComponent implements OnInit {
...
@@ -100,6 +101,7 @@ export class DashboardManagementComponent implements OnInit {
private
dashboardDataService
:
DashboardDataService
,
private
dashboardDataService
:
DashboardDataService
,
private
mMenuitemsWidgetService
:
MMenuitemsWidgetService
,
private
mMenuitemsWidgetService
:
MMenuitemsWidgetService
,
private
dashboardStateService
:
DashboardStateService
,
private
dashboardStateService
:
DashboardStateService
,
private
widgetStateService
:
WidgetStateService
,
// Inject WidgetStateService
private
dialog
:
MatDialog
,
private
dialog
:
MatDialog
,
private
notificationService
:
NotificationService
private
notificationService
:
NotificationService
)
{
}
)
{
}
...
@@ -261,11 +263,19 @@ export class DashboardManagementComponent implements OnInit {
...
@@ -261,11 +263,19 @@ export class DashboardManagementComponent implements OnInit {
const
dashboardToSave
=
JSON
.
parse
(
JSON
.
stringify
(
this
.
dashboardData
));
const
dashboardToSave
=
JSON
.
parse
(
JSON
.
stringify
(
this
.
dashboardData
));
if
(
dashboardToSave
.
widgets
)
{
if
(
dashboardToSave
.
widgets
)
{
const
allWidgetStates
=
this
.
widgetStateService
.
getAllWidgetStates
();
// Get all current widget states
dashboardToSave
.
widgets
.
forEach
((
widget
:
WidgetModel
)
=>
{
dashboardToSave
.
widgets
.
forEach
((
widget
:
WidgetModel
)
=>
{
if
(
widget
.
config
&&
typeof
widget
.
config
===
'object'
)
{
if
(
widget
.
config
&&
typeof
widget
.
config
===
'object'
)
{
widget
.
config
=
JSON
.
stringify
(
widget
.
config
);
widget
.
config
=
JSON
.
stringify
(
widget
.
config
);
}
}
// Add stringify for perspective
// Update perspective from WidgetStateService if available
const
currentPerspective
=
allWidgetStates
.
get
(
widget
.
widgetId
);
if
(
currentPerspective
!==
undefined
)
{
// Check for undefined to allow nulls
widget
.
perspective
=
currentPerspective
;
}
// Ensure perspective is stringified if it's an object (though it should be string from getWidgetState)
if
(
widget
.
perspective
&&
typeof
widget
.
perspective
===
'object'
)
{
if
(
widget
.
perspective
&&
typeof
widget
.
perspective
===
'object'
)
{
widget
.
perspective
=
JSON
.
stringify
(
widget
.
perspective
);
widget
.
perspective
=
JSON
.
stringify
(
widget
.
perspective
);
}
}
...
...
src/app/portal-manage/services/widget-state.service.ts
0 → 100644
View file @
80a409fc
import
{
Injectable
}
from
'@angular/core'
;
export
interface
StatefulWidget
{
widgetId
:
string
;
getWidgetState
():
string
|
null
;
}
@
Injectable
({
providedIn
:
'root'
})
export
class
WidgetStateService
{
private
registeredWidgets
=
new
Map
<
string
,
StatefulWidget
>
();
constructor
()
{
}
registerWidget
(
widgetId
:
string
,
widget
:
StatefulWidget
):
void
{
this
.
registeredWidgets
.
set
(
widgetId
,
widget
);
console
.
log
(
`Widget
${
widgetId
}
registered.`
);
}
unregisterWidget
(
widgetId
:
string
):
void
{
this
.
registeredWidgets
.
delete
(
widgetId
);
console
.
log
(
`Widget
${
widgetId
}
unregistered.`
);
}
getWidgetState
(
widgetId
:
string
):
string
|
null
{
const
widget
=
this
.
registeredWidgets
.
get
(
widgetId
);
if
(
widget
)
{
return
widget
.
getWidgetState
();
}
return
null
;
}
getAllWidgetStates
():
Map
<
string
,
string
|
null
>
{
const
allStates
=
new
Map
<
string
,
string
|
null
>
();
this
.
registeredWidgets
.
forEach
((
widget
,
widgetId
)
=>
{
allStates
.
set
(
widgetId
,
widget
.
getWidgetState
());
});
return
allStates
;
}
}
src/app/portal-manage/widgets/syncfusion-datagrid-widget/syncfusion-datagrid-widget.component.ts
View file @
80a409fc
import
{
Component
,
ViewChild
}
from
'@angular/core'
;
import
{
Component
,
ViewChild
,
OnInit
,
OnDestroy
}
from
'@angular/core'
;
import
{
CommonModule
}
from
'@angular/common'
;
import
{
CommonModule
}
from
'@angular/common'
;
import
{
GridModule
,
PageService
,
SortService
,
FilterService
,
GroupService
,
ToolbarService
,
ExcelExportService
,
PdfExportService
,
GridComponent
,
ToolbarItems
,
SearchSettingsModel
,
GroupSettingsModel
,
FilterSettingsModel
,
SelectionSettingsModel
,
AggregateService
,
ColumnMenuService
,
DetailRowService
,
ReorderService
,
EditService
,
ColumnMenuClickEventArgs
,
PdfExportProperties
,
ExcelExportProperties
,
LoadingIndicatorModel
,
Column
,
SearchService
}
from
'@syncfusion/ej2-angular-grids'
;
import
{
GridModule
,
PageService
,
SortService
,
FilterService
,
GroupService
,
ToolbarService
,
ExcelExportService
,
PdfExportService
,
GridComponent
,
ToolbarItems
,
SearchSettingsModel
,
GroupSettingsModel
,
FilterSettingsModel
,
SelectionSettingsModel
,
AggregateService
,
ColumnMenuService
,
DetailRowService
,
ReorderService
,
EditService
,
ColumnMenuClickEventArgs
,
PdfExportProperties
,
ExcelExportProperties
,
LoadingIndicatorModel
,
Column
,
SearchService
}
from
'@syncfusion/ej2-angular-grids'
;
import
{
ClickEventArgs
}
from
'@syncfusion/ej2-navigations'
;
import
{
ClickEventArgs
}
from
'@syncfusion/ej2-navigations'
;
...
@@ -6,6 +6,7 @@ import { DataManager, Query } from '@syncfusion/ej2-data';
...
@@ -6,6 +6,7 @@ import { DataManager, Query } from '@syncfusion/ej2-data';
import
{
DashboardStateService
}
from
'../../services/dashboard-state.service'
;
import
{
DashboardStateService
}
from
'../../services/dashboard-state.service'
;
import
{
BaseWidgetComponent
}
from
'../base-widget.component'
;
import
{
BaseWidgetComponent
}
from
'../base-widget.component'
;
import
{
L10n
,
setCulture
}
from
'@syncfusion/ej2-base'
;
// For L10n
import
{
L10n
,
setCulture
}
from
'@syncfusion/ej2-base'
;
// For L10n
import
{
WidgetStateService
,
StatefulWidget
}
from
'../../services/widget-state.service'
;
// Import WidgetStateService
setCulture
(
'th-TH'
);
setCulture
(
'th-TH'
);
...
@@ -54,9 +55,11 @@ L10n.load({
...
@@ -54,9 +55,11 @@ L10n.load({
providers
:
[
PageService
,
SortService
,
FilterService
,
GroupService
,
ToolbarService
,
ExcelExportService
,
PdfExportService
,
AggregateService
,
ColumnMenuService
,
DetailRowService
,
ReorderService
,
EditService
,
SearchService
],
providers
:
[
PageService
,
SortService
,
FilterService
,
GroupService
,
ToolbarService
,
ExcelExportService
,
PdfExportService
,
AggregateService
,
ColumnMenuService
,
DetailRowService
,
ReorderService
,
EditService
,
SearchService
],
templateUrl
:
'./syncfusion-datagrid-widget.component.html'
,
templateUrl
:
'./syncfusion-datagrid-widget.component.html'
,
})
})
export
class
SyncfusionDatagridWidgetComponent
extends
BaseWidgetComponent
{
export
class
SyncfusionDatagridWidgetComponent
extends
BaseWidgetComponent
implements
OnInit
,
OnDestroy
,
StatefulWidget
{
@
ViewChild
(
'grid'
)
public
grid
:
GridComponent
;
@
ViewChild
(
'grid'
)
public
grid
:
GridComponent
;
public
widgetId
:
string
;
// Added widgetId property
public
data
:
DataManager
=
new
DataManager
([]);
public
data
:
DataManager
=
new
DataManager
([]);
public
columns
:
any
[]
=
[];
public
columns
:
any
[]
=
[];
public
pageSettings
:
Object
=
{
pageSize
:
10
};
public
pageSettings
:
Object
=
{
pageSize
:
10
};
...
@@ -78,10 +81,28 @@ export class SyncfusionDatagridWidgetComponent extends BaseWidgetComponent {
...
@@ -78,10 +81,28 @@ export class SyncfusionDatagridWidgetComponent extends BaseWidgetComponent {
public
showColumnMenu
:
boolean
;
public
showColumnMenu
:
boolean
;
public
allowMultiSorting
:
boolean
;
public
allowMultiSorting
:
boolean
;
constructor
(
protected
override
dashboardStateService
:
DashboardStateService
)
{
constructor
(
protected
override
dashboardStateService
:
DashboardStateService
,
private
widgetStateService
:
WidgetStateService
// Inject WidgetStateService
)
{
super
(
dashboardStateService
);
super
(
dashboardStateService
);
}
}
override
ngOnInit
():
void
{
// Added override
super
.
ngOnInit
();
// Call parent's ngOnInit
if
(
this
.
config
&&
this
.
config
.
widgetId
)
{
this
.
widgetId
=
this
.
config
.
widgetId
;
// Initialize widgetId
this
.
widgetStateService
.
registerWidget
(
this
.
widgetId
,
this
);
}
}
override
ngOnDestroy
():
void
{
// Added override
super
.
ngOnDestroy
();
// Call parent's ngOnDestroy
if
(
this
.
config
&&
this
.
config
.
widgetId
)
{
this
.
widgetStateService
.
unregisterWidget
(
this
.
config
.
widgetId
);
}
}
applyInitialConfig
():
void
{
applyInitialConfig
():
void
{
this
.
title
=
this
.
config
.
title
||
'Data Grid'
;
this
.
title
=
this
.
config
.
title
||
'Data Grid'
;
this
.
columns
=
this
.
config
.
columns
||
[];
this
.
columns
=
this
.
config
.
columns
||
[];
...
@@ -112,6 +133,33 @@ export class SyncfusionDatagridWidgetComponent extends BaseWidgetComponent {
...
@@ -112,6 +133,33 @@ export class SyncfusionDatagridWidgetComponent extends BaseWidgetComponent {
this
.
allowReordering
=
this
.
config
.
allowReordering
!==
undefined
?
this
.
config
.
allowReordering
:
true
;
this
.
allowReordering
=
this
.
config
.
allowReordering
!==
undefined
?
this
.
config
.
allowReordering
:
true
;
this
.
showColumnMenu
=
this
.
config
.
showColumnMenu
!==
undefined
?
this
.
config
.
showColumnMenu
:
true
;
this
.
showColumnMenu
=
this
.
config
.
showColumnMenu
!==
undefined
?
this
.
config
.
showColumnMenu
:
true
;
this
.
allowMultiSorting
=
this
.
config
.
allowMultiSorting
!==
undefined
?
this
.
config
.
allowMultiSorting
:
true
;
this
.
allowMultiSorting
=
this
.
config
.
allowMultiSorting
!==
undefined
?
this
.
config
.
allowMultiSorting
:
true
;
// Apply saved perspective if available
if
(
this
.
config
.
perspective
&&
this
.
grid
)
{
this
.
setWidgetState
(
this
.
config
.
perspective
);
}
}
/**
* Returns the current state of the Syncfusion Grid.
* This state can be used to restore the grid's perspective (sorting, filtering, grouping, etc.).
* @returns A JSON string representing the grid's state.
*/
getWidgetState
():
string
|
null
{
if
(
this
.
grid
)
{
return
this
.
grid
.
getPersistData
();
}
return
null
;
}
/**
* Applies a previously saved state to the Syncfusion Grid.
* @param state A JSON string representing the grid's state.
*/
setWidgetState
(
state
:
string
):
void
{
if
(
this
.
grid
&&
state
)
{
(
this
.
grid
as
any
).
setPersistData
(
state
);
// Cast to any
}
}
}
onDataUpdate
(
data
:
any
[]):
void
{
onDataUpdate
(
data
:
any
[]):
void
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment