@@ -44,13 +44,15 @@ export class DashboardComponent {
4444
4545 dashboard : DashboardModel | null = null ;
4646
47+ tasks : TaskModel [ ] = [ ] ; // different by dashboard.task because they may be filtered
48+
4749 onTopTaskIdList : number [ ] = [ ] ;
4850
4951 creationForm = new FormGroup ( {
5052 name : new FormControl ( '' , [ Validators . required ] ) ,
5153 description : new FormControl ( '' ) ,
5254 priority : new FormControl ( '' , [ Validators . required ] ) ,
53- selfAssigned : new FormControl ( false , [ Validators . required ] )
55+ selfAssigned : new FormControl ( false )
5456 } ) ;
5557
5658 constructor ( private dashboardService : DashboardService , public authService : AuthService , private taskService : TaskService ) {
@@ -113,9 +115,12 @@ export class DashboardComponent {
113115 this . dashboardService . getData ( ) . then ( ( response ) => {
114116 response . subscribe ( {
115117 next : ( value : DashboardModel | null ) => {
116- if ( value ) {
118+ if ( ! ! value ) {
117119 this . dashboard = value ;
118120
121+ // set effective task
122+ this . tasks = [ ...this . dashboard . tasks ] ;
123+
119124 // set default id index if it is not setted
120125 if ( ! this . taskStatusIdIndex )
121126 this . taskStatusIdIndex = this . dashboard . default_task_status_id ;
@@ -175,10 +180,10 @@ export class DashboardComponent {
175180
176181 getAllTaskBasedOnStatusId ( taskStatusId : number | undefined ) : TaskModel [ ] | null {
177182
178- if ( ! this . dashboard || ! taskStatusId )
183+ if ( ! this . tasks || ! taskStatusId )
179184 return null ;
180185
181- let tasksBasedOnStatusId = this . dashboard ! . tasks . filter ( task => task !== undefined && task . task_status_id === taskStatusId ) ;
186+ let tasksBasedOnStatusId = this . tasks . filter ( task => task !== undefined && task . task_status_id === taskStatusId ) ;
182187
183188 if ( ! tasksBasedOnStatusId )
184189 return null ;
@@ -246,26 +251,24 @@ export class DashboardComponent {
246251 }
247252
248253 removeTask ( taskId : number ) {
249- if ( ! this . dashboard ?. tasks )
254+ if ( ! this . tasks )
250255 return ;
251256
252- this . dashboard . tasks = this . dashboard . tasks . filter ( t => t . id != taskId ) ;
257+ this . tasks = this . tasks . filter ( t => t . id != taskId ) ;
253258 }
254259
255260 updateTask ( managedTask : UpdateTaskModel ) {
256- if ( ! this . dashboard ?. tasks )
261+ if ( ! this . tasks )
257262 return ;
258263
259- for ( let index = 0 ; index < this . dashboard . tasks . length ; index ++ ) {
260- const element = this . dashboard . tasks [ index ] ;
264+ for ( let index = 0 ; index < this . tasks . length ; index ++ ) {
265+ const element = this . tasks [ index ] ;
261266
262267 if ( element . id == managedTask . target )
263- this . dashboard . tasks [ index ] = managedTask . new ;
268+ this . tasks [ index ] = managedTask . new ;
264269
265270 }
266271
267- console . log ( this . dashboard . tasks ) ;
268-
269272 }
270273
271274 newTask ( ) {
@@ -296,7 +299,10 @@ export class DashboardComponent {
296299 response . subscribe ( {
297300 next : ( task ) => {
298301
299- this . creationForm . reset ( ) ;
302+ if ( ! ! task ) {
303+ this . creationForm . reset ( ) ;
304+
305+ }
300306
301307 // self assign
302308 if ( selfAssigned ) {
@@ -309,7 +315,7 @@ export class DashboardComponent {
309315 this . taskService . find ( task . id ) . then ( ( respose ) => {
310316 respose . subscribe ( {
311317 next : ( t ) => {
312- this . dashboard ?. tasks . push ( t ) ;
318+ this . tasks . push ( t ) ;
313319
314320 }
315321 } )
@@ -323,7 +329,7 @@ export class DashboardComponent {
323329
324330 } else { // append immediatly task
325331
326- this . dashboard ?. tasks . push ( task ) ;
332+ this . tasks . push ( task ) ;
327333 }
328334 }
329335 } )
0 commit comments