@@ -2,28 +2,27 @@ import { derived, get, writable, type Writable } from 'svelte/store';
2
2
import { getTarget } from '../utilities/generic' ;
3
3
import { activitiesGrid , constraintsGrid , schedulingGrid , simulationGrid , updateGrid } from '../utilities/grid' ;
4
4
5
- /* Stores . */
5
+ /* Writeable . */
6
6
7
- /**
8
- * Current user-defined view.
9
- */
10
7
export const view : Writable < View | null > = writable ( null ) ;
11
8
12
- /**
13
- * Current user-defined layout.
14
- */
15
9
export const viewLayout : Writable < Grid | null > = writable ( null ) ;
16
10
17
- /**
18
- * Formatted JSON string of the current view.
19
- */
20
- export const viewText = derived ( view , $view => ( $view ? JSON . stringify ( $view , null , 2 ) : '' ) ) ;
11
+ export const selectedLayerId : Writable < number | null > = writable ( null ) ;
12
+
13
+ export const selectedRowId : Writable < number | null > = writable ( null ) ;
21
14
22
15
export const selectedTimelineId : Writable < number | null > = writable ( null ) ;
23
16
17
+ export const selectedYAxisId : Writable < number | null > = writable ( null ) ;
18
+
19
+ /* Derived. */
20
+
21
+ export const viewDefinitionText = derived ( view , $view => ( $view ? JSON . stringify ( $view . definition , null , 2 ) : '' ) ) ;
22
+
24
23
export const selectedTimeline = derived ( [ view , selectedTimelineId ] , ( [ $view , $selectedTimelineId ] ) => {
25
24
if ( $view !== null && $selectedTimelineId !== null ) {
26
- for ( const timeline of $view . plan . timelines ) {
25
+ for ( const timeline of $view . definition . plan . timelines ) {
27
26
if ( timeline && timeline . id === $selectedTimelineId ) {
28
27
return timeline ;
29
28
}
@@ -32,8 +31,6 @@ export const selectedTimeline = derived([view, selectedTimelineId], ([$view, $se
32
31
return null ;
33
32
} ) ;
34
33
35
- export const selectedRowId : Writable < number | null > = writable ( null ) ;
36
-
37
34
export const selectedRow = derived ( [ selectedTimeline , selectedRowId ] , ( [ $selectedTimeline , $selectedRowId ] ) => {
38
35
if ( $selectedTimeline !== null ) {
39
36
for ( const row of $selectedTimeline . rows ) {
@@ -45,8 +42,6 @@ export const selectedRow = derived([selectedTimeline, selectedRowId], ([$selecte
45
42
return null ;
46
43
} ) ;
47
44
48
- export const selectedYAxisId : Writable < number | null > = writable ( null ) ;
49
-
50
45
export const selectedYAxis = derived ( [ selectedRow , selectedYAxisId ] , ( [ $selectedRow , $selectedYAxisId ] ) => {
51
46
if ( $selectedRow !== null ) {
52
47
for ( const yAxis of $selectedRow . yAxes ) {
@@ -58,8 +53,6 @@ export const selectedYAxis = derived([selectedRow, selectedYAxisId], ([$selected
58
53
return null ;
59
54
} ) ;
60
55
61
- export const selectedLayerId : Writable < number | null > = writable ( null ) ;
62
-
63
56
export const selectedLayer = derived ( [ selectedRow , selectedLayerId ] , ( [ $selectedRow , $selectedLayerId ] ) => {
64
57
if ( $selectedRow !== null ) {
65
58
for ( const layer of $selectedRow . layers ) {
@@ -71,85 +64,89 @@ export const selectedLayer = derived([selectedRow, selectedLayerId], ([$selected
71
64
return null ;
72
65
} ) ;
73
66
74
- /* Action Functions. */
75
-
76
- export const viewActions = {
77
- setLayout ( title : string ) {
78
- let layout : Grid ;
79
-
80
- if ( title === 'Activities' ) {
81
- layout = activitiesGrid ;
82
- } else if ( title === 'Constraints' ) {
83
- layout = constraintsGrid ;
84
- } else if ( title === 'Scheduling' ) {
85
- layout = schedulingGrid ;
86
- } else if ( title === 'Simulation' ) {
87
- layout = simulationGrid ;
88
- } else if ( title === 'View' ) {
89
- const viewGrid = get ( viewLayout ) ;
90
- layout = viewGrid ;
91
- } else {
92
- layout = activitiesGrid ;
93
- }
67
+ /* Helper Functions. */
68
+
69
+ export function viewSetLayout ( title : string ) {
70
+ let layout : Grid ;
71
+
72
+ if ( title === 'Activities' ) {
73
+ layout = activitiesGrid ;
74
+ } else if ( title === 'Constraints' ) {
75
+ layout = constraintsGrid ;
76
+ } else if ( title === 'Scheduling' ) {
77
+ layout = schedulingGrid ;
78
+ } else if ( title === 'Simulation' ) {
79
+ layout = simulationGrid ;
80
+ } else if ( title === 'View' ) {
81
+ const viewGrid = get ( viewLayout ) ;
82
+ layout = viewGrid ;
83
+ } else {
84
+ layout = activitiesGrid ;
85
+ }
94
86
95
- view . update ( currentView => ( {
96
- ...currentView ,
87
+ view . update ( currentView => ( {
88
+ ...currentView ,
89
+ definition : {
90
+ ...currentView . definition ,
97
91
plan : {
98
- ...currentView . plan ,
92
+ ...currentView . definition . plan ,
99
93
layout,
100
94
} ,
101
- } ) ) ;
102
- } ,
103
-
104
- setSelectedRow ( rowId : number | null ) : void {
105
- selectedRowId . set ( rowId ) ;
106
- const currentRow = get ( selectedRow ) ;
107
-
108
- if ( currentRow ) {
109
- const firstLayer = currentRow . layers [ 0 ] ;
110
- if ( firstLayer ) {
111
- selectedLayerId . set ( firstLayer . id ) ;
112
- } else {
113
- selectedLayerId . set ( null ) ;
114
- }
95
+ } ,
96
+ } ) ) ;
97
+ }
98
+
99
+ export function viewSetSelectedRow ( rowId : number | null ) : void {
100
+ selectedRowId . set ( rowId ) ;
101
+ const currentRow = get ( selectedRow ) ;
102
+
103
+ if ( currentRow ) {
104
+ const firstLayer = currentRow . layers [ 0 ] ;
105
+ if ( firstLayer ) {
106
+ selectedLayerId . set ( firstLayer . id ) ;
107
+ } else {
108
+ selectedLayerId . set ( null ) ;
109
+ }
115
110
116
- const firstYAxis = currentRow . yAxes [ 0 ] ;
117
- if ( firstYAxis ) {
118
- selectedYAxisId . set ( firstYAxis . id ) ;
119
- } else {
120
- selectedYAxisId . set ( null ) ;
121
- }
111
+ const firstYAxis = currentRow . yAxes [ 0 ] ;
112
+ if ( firstYAxis ) {
113
+ selectedYAxisId . set ( firstYAxis . id ) ;
122
114
} else {
123
- selectedRowId . set ( null ) ;
115
+ selectedYAxisId . set ( null ) ;
124
116
}
125
- } ,
117
+ } else {
118
+ selectedRowId . set ( null ) ;
119
+ }
120
+ }
126
121
127
- setSelectedTimeline ( timelineId : number | null ) : void {
128
- selectedTimelineId . set ( timelineId ) ;
129
- const currentTimeline = get ( selectedTimeline ) ;
122
+ export function viewSetSelectedTimeline ( timelineId : number | null ) : void {
123
+ selectedTimelineId . set ( timelineId ) ;
124
+ const currentTimeline = get ( selectedTimeline ) ;
130
125
131
- if ( currentTimeline ) {
132
- const firstRow = currentTimeline . rows [ 0 ] ;
126
+ if ( currentTimeline ) {
127
+ const firstRow = currentTimeline . rows [ 0 ] ;
133
128
134
- if ( firstRow ) {
135
- viewActions . setSelectedRow ( firstRow . id ) ;
136
- }
129
+ if ( firstRow ) {
130
+ viewSetSelectedRow ( firstRow . id ) ;
137
131
}
138
- } ,
132
+ }
133
+ }
139
134
140
- updateLayer ( event : Event ) {
141
- event . stopPropagation ( ) ;
142
- const { name : prop , value } = getTarget ( event ) ;
135
+ export function viewUpdateLayer ( event : Event ) {
136
+ event . stopPropagation ( ) ;
137
+ const { name : prop , value } = getTarget ( event ) ;
143
138
144
- const timelineId = get < number | null > ( selectedTimelineId ) ;
145
- const rowId = get < number | null > ( selectedRowId ) ;
146
- const layerId = get < number | null > ( selectedLayerId ) ;
139
+ const timelineId = get < number | null > ( selectedTimelineId ) ;
140
+ const rowId = get < number | null > ( selectedRowId ) ;
141
+ const layerId = get < number | null > ( selectedLayerId ) ;
147
142
148
- view . update ( currentView => ( {
149
- ...currentView ,
143
+ view . update ( currentView => ( {
144
+ ...currentView ,
145
+ definition : {
146
+ ...currentView . definition ,
150
147
plan : {
151
- ...currentView . plan ,
152
- timelines : currentView . plan . timelines . map ( timeline => {
148
+ ...currentView . definition . plan ,
149
+ timelines : currentView . definition . plan . timelines . map ( timeline => {
153
150
if ( timeline && timeline . id === timelineId ) {
154
151
return {
155
152
...timeline ,
@@ -175,28 +172,34 @@ export const viewActions = {
175
172
return timeline ;
176
173
} ) ,
177
174
} ,
178
- } ) ) ;
179
- } ,
180
-
181
- updateLayout ( id : number , prop : string , value : any ) {
182
- view . update ( currentView => ( {
183
- ...currentView ,
175
+ } ,
176
+ } ) ) ;
177
+ }
178
+
179
+ export function viewUpdateLayout ( id : number , prop : string , value : any ) {
180
+ view . update ( currentView => ( {
181
+ ...currentView ,
182
+ definition : {
183
+ ...currentView . definition ,
184
184
plan : {
185
- ...currentView . plan ,
186
- layout : updateGrid ( currentView . plan . layout , id , prop , value ) ,
185
+ ...currentView . definition . plan ,
186
+ layout : updateGrid ( currentView . definition . plan . layout , id , prop , value ) ,
187
187
} ,
188
- } ) ) ;
189
- } ,
190
-
191
- updateRow ( prop : string , value : any , timelineId ?: number , rowId ?: number ) {
192
- timelineId = timelineId ?? get < number | null > ( selectedTimelineId ) ;
193
- rowId = rowId ?? get < number | null > ( selectedRowId ) ;
194
-
195
- view . update ( currentView => ( {
196
- ...currentView ,
188
+ } ,
189
+ } ) ) ;
190
+ }
191
+
192
+ export function viewUpdateRow ( prop : string , value : any , timelineId ?: number , rowId ?: number ) {
193
+ timelineId = timelineId ?? get < number | null > ( selectedTimelineId ) ;
194
+ rowId = rowId ?? get < number | null > ( selectedRowId ) ;
195
+
196
+ view . update ( currentView => ( {
197
+ ...currentView ,
198
+ definition : {
199
+ ...currentView . definition ,
197
200
plan : {
198
- ...currentView . plan ,
199
- timelines : currentView . plan . timelines . map ( timeline => {
201
+ ...currentView . definition . plan ,
202
+ timelines : currentView . definition . plan . timelines . map ( timeline => {
200
203
if ( timeline && timeline . id === timelineId ) {
201
204
return {
202
205
...timeline ,
@@ -214,17 +217,20 @@ export const viewActions = {
214
217
return timeline ;
215
218
} ) ,
216
219
} ,
217
- } ) ) ;
218
- } ,
220
+ } ,
221
+ } ) ) ;
222
+ }
219
223
220
- updateTimeline ( prop : string , value : any , timelineId ?: number ) {
221
- timelineId = timelineId ?? get < number | null > ( selectedTimelineId ) ;
224
+ export function viewUpdateTimeline ( prop : string , value : any , timelineId ?: number ) {
225
+ timelineId = timelineId ?? get < number | null > ( selectedTimelineId ) ;
222
226
223
- view . update ( currentView => ( {
224
- ...currentView ,
227
+ view . update ( currentView => ( {
228
+ ...currentView ,
229
+ definition : {
230
+ ...currentView . definition ,
225
231
plan : {
226
- ...currentView . plan ,
227
- timelines : currentView . plan . timelines . map ( timeline => {
232
+ ...currentView . definition . plan ,
233
+ timelines : currentView . definition . plan . timelines . map ( timeline => {
228
234
if ( timeline && timeline . id === timelineId ) {
229
235
return {
230
236
...timeline ,
@@ -234,19 +240,22 @@ export const viewActions = {
234
240
return timeline ;
235
241
} ) ,
236
242
} ,
237
- } ) ) ;
238
- } ,
239
-
240
- updateYAxis ( prop : string , value : any ) {
241
- const timelineId = get < number | null > ( selectedTimelineId ) ;
242
- const rowId = get < number | null > ( selectedRowId ) ;
243
- const yAxisId = get < number | null > ( selectedYAxisId ) ;
244
-
245
- view . update ( currentView => ( {
246
- ...currentView ,
243
+ } ,
244
+ } ) ) ;
245
+ }
246
+
247
+ export function viewUpdateYAxis ( prop : string , value : any ) {
248
+ const timelineId = get < number | null > ( selectedTimelineId ) ;
249
+ const rowId = get < number | null > ( selectedRowId ) ;
250
+ const yAxisId = get < number | null > ( selectedYAxisId ) ;
251
+
252
+ view . update ( currentView => ( {
253
+ ...currentView ,
254
+ definition : {
255
+ ...currentView . definition ,
247
256
plan : {
248
- ...currentView . plan ,
249
- timelines : currentView . plan . timelines . map ( timeline => {
257
+ ...currentView . definition . plan ,
258
+ timelines : currentView . definition . plan . timelines . map ( timeline => {
250
259
if ( timeline && timeline . id === timelineId ) {
251
260
return {
252
261
...timeline ,
@@ -275,6 +284,6 @@ export const viewActions = {
275
284
return timeline ;
276
285
} ) ,
277
286
} ,
278
- } ) ) ;
279
- } ,
280
- } ;
287
+ } ,
288
+ } ) ) ;
289
+ }
0 commit comments