@@ -142,25 +142,51 @@ export default class TaskStore {
142142 }
143143
144144 getCheckedKeys ( projectId : string ) : string [ ] {
145- function condition ( task : TaskModel ) : boolean {
146- return task . checked ;
145+ const condition = ( task : TaskModel ) => task . checked ;
146+
147+ return this . getTaskKeysByCondition ( projectId , condition ) ;
148+ }
149+
150+ getExpandedKeys ( projectId : string ) : string [ ] {
151+ const condition = ( task : TaskModel ) => task . expanded ;
152+
153+ return this . getTaskKeysByCondition ( projectId , condition ) ;
154+ }
155+
156+ checkTasks ( projectId : string , taskIds : string [ ] ) {
157+ function checkTaskFn ( task : TaskModel , taskIds : string [ ] ) {
158+ task . checked = taskIds . includes ( task . key ) ;
147159 }
148160
149161 if ( Array . isArray ( this . tasks [ projectId ] ) ) {
150- return TreeModelStoreHelper . getFlatItemsRecursive (
151- this . tasks [ projectId ] ,
152- condition
153- ) . map ( ( task ) => task . key ) ;
162+ this . checkTasksRecursive ( this . tasks [ projectId ] , taskIds , checkTaskFn ) ;
154163 }
155- return [ ] ;
164+ this . tasksService . save ( this . tasks ) ;
165+ GaService . event ( EEventCategory . Tasks , ETasksEvents . Check ) ;
156166 }
157167
158- checkTasks ( projectId : string , taskIds : string [ ] ) {
168+ tasksMarkExpanded ( projectId : string , taskIds : string [ ] ) {
169+ function markExpanded ( task : TaskModel , taskIds : string [ ] ) {
170+ task . expanded = taskIds . includes ( task . key ) ;
171+ }
172+
159173 if ( Array . isArray ( this . tasks [ projectId ] ) ) {
160- this . checkTasksRecursive ( this . tasks [ projectId ] , taskIds ) ;
174+ this . checkTasksRecursive ( this . tasks [ projectId ] , taskIds , markExpanded ) ;
161175 }
162176 this . tasksService . save ( this . tasks ) ;
163- GaService . event ( EEventCategory . Tasks , ETasksEvents . Check ) ;
177+ }
178+
179+ private getTaskKeysByCondition (
180+ projectId : string ,
181+ condition : ( task : TaskModel ) => boolean
182+ ) {
183+ if ( Array . isArray ( this . tasks [ projectId ] ) ) {
184+ return TreeModelStoreHelper . getFlatItemsRecursive (
185+ this . tasks [ projectId ] ,
186+ condition
187+ ) . map ( ( task ) => task . key ) ;
188+ }
189+ return [ ] ;
164190 }
165191
166192 private findAndSetActiveTask ( ) {
@@ -181,11 +207,15 @@ export default class TaskStore {
181207 return TreeModelStoreHelper . getItemRecursive ( tasks , condition ) ;
182208 }
183209
184- private checkTasksRecursive ( tasks : TaskModel [ ] , taskIds : string [ ] ) {
210+ private checkTasksRecursive (
211+ tasks : TaskModel [ ] ,
212+ taskIds : string [ ] ,
213+ fn : ( task : TaskModel , taskIds : string [ ] ) => void
214+ ) {
185215 tasks . forEach ( ( task ) => {
186- task . checked = taskIds . includes ( task . key ) ;
216+ fn ( task , taskIds ) ;
187217 if ( Array . isArray ( task . children ) ) {
188- this . checkTasksRecursive ( task . children , taskIds ) ;
218+ this . checkTasksRecursive ( task . children , taskIds , fn ) ;
189219 }
190220 } ) ;
191221 }
0 commit comments